Admin Controller
The Admin_Controller class lets you customize the WordPress admin editor on a per-template or per-post-type basis. You can hide unwanted metaboxes (excerpt, editor, comments, etc.) and set up post-save redirects — all from a simple configuration array.
Key Features
Section titled “Key Features”- Hide metaboxes: Remove unwanted UI elements from the editor screen
- Post-save redirects: Redirect to a custom URL after saving a post (static or dynamic)
- Multiple match types: Apply rules by template name, post type, post ID, or custom condition
- Dual removal strategy: Uses both
remove_meta_box()and CSS injection for reliability - Gutenberg compatible: Removes editor support early enough for Gutenberg to respect it
Parameters
Section titled “Parameters”- identifier (string): The value to match against — template filename, post type slug, or post ID.
- match_type (string): How to match:
'template','post_type','post_id', or'condition'. - hide_elements (array): Elements to hide from the admin screen.
- redirect (string|callable): URL or callback for redirect after save.
- condition (callable): Optional custom condition that must return
truefor rules to apply.
Hideable Elements
Section titled “Hideable Elements”| Value | What it hides |
|---|---|
excerpt | Excerpt metabox |
thumbnail / featured_image | Featured image metabox |
editor | The WordPress editor (classic or Gutenberg) |
custom_fields | Custom fields metabox |
comments | Comments metabox |
slug | Slug/permalink editor |
author | Author metabox |
revisions | Revisions metabox |
page_attributes | Page attributes (template, order) |
trackbacks | Trackbacks metabox |
categories | Categories metabox |
tags | Tags metabox |
01. Hide Editor for a Page Template
Section titled “01. Hide Editor for a Page Template”When using only ACF Flexible Content on a page, hide the default WordPress editor:
<?php// In functions/project/config/admin-controller_config.php
return [ [ 'identifier' => 'page-modules.php', 'match_type' => 'template', 'hide_elements' => ['editor'], ],];02. Redirect After Save
Section titled “02. Redirect After Save”After saving a post of a specific type, redirect the user back to the post list:
<?php[ 'identifier' => 'testimonial', 'match_type' => 'post_type', 'redirect' => 'edit.php?post_type=testimonial',],03. Dynamic Redirect with Callback
Section titled “03. Dynamic Redirect with Callback”Redirect to different locations based on post data:
<?php[ 'identifier' => 'resource', 'match_type' => 'post_type', 'redirect' => function ($post_id, $post) { $type = get_the_terms($post_id, 'resource_type'); if ($type && $type[0]->slug === 'case-study') { return 'edit.php?post_type=resource&resource_type=case-study'; } return 'edit.php?post_type=resource'; },],04. Conditional Hiding
Section titled “04. Conditional Hiding”Apply rules only when a custom condition is met:
<?php[ 'identifier' => 'post', 'match_type' => 'post_type', 'condition' => function ($post_id, $post) { return get_post_meta($post_id, 'use_minimal_editor', true) === '1'; }, 'hide_elements' => ['excerpt', 'comments', 'author'],],05. Combined: Hide + Redirect
Section titled “05. Combined: Hide + Redirect”<?php[ 'identifier' => 'page-landing.php', 'match_type' => 'template', 'hide_elements' => ['editor', 'excerpt', 'comments'], 'redirect' => 'edit.php?post_type=page',],Configuration Details
Section titled “Configuration Details”identifier(string): Template name (e.g.,'page-modules.php'), post type slug (e.g.,'resource'), or post ID (e.g.,'42').match_type(string): Determines howidentifieris matched:template: Matches the_wp_page_templatepost metapost_type: Matches the post’s typepost_id: Matches a specific post IDcondition: Uses only theconditioncallback (ignoresidentifier)
hide_elements(array): List of element strings to hide.redirect(string|callable): Static URL string orfunction($post_id, $post)returning a URL.condition(callable): A function receiving($post_id, $post)that must returntrue. Can be combined with other match types for additional filtering.
Knowledge Check
Test your understanding of this section
Loading questions...