I’ve refactored the plugin code and moved into UI cleaning.
The problem
In its basic form Route Pages, as its name states, will generate a page (a post or a custom post type), for each route the developer has decided should be a generating one and the site administrator will be able to see that page or post among the pages or posts he can manage and add to menus.
While many of the primary and meta values still apply many do not make sense and I’d like that to be clear to the administrator. Removing them.
Hooks!
I will start cleaning the single post edit screen and will use the page generated by the this code as a guideline
RoutePages_GeneratingRoute::get('one', function(
echo "Welcome to page one.";
))->shouldGenerate('page')->withTitle('One');
on the site the page will appear among the other pages and will have an edit screen identical to any other page I’ve gone hook-hunting through slow-motion WordPress runs and found my hooks in the /wp-admin/edit-form-advanced.php
file; or, rather, before that’s included.
Had I gone the easy way of adding route-generated posts as a custom post type then adding and removing post supports would be a breeze. I’ve, of course, gone the hard way and chose to create real pages for each route.
In the above mentioned file, /wp-admin/edit-form-advanced.php
, there are many calls to the post_type_supports
function; sadly that’s post type based and not single post based.
Disabling post supports
Since I plan to have many interventions to do here and there I’ve created a class dealing just with this screen, RoutePages_UIController_EditFormAdvanced
, and made it hook in the main plugin class
// file RoutePages.php
/**
* Hook into actions and filters here
*
*/
public function hook()
{
$uiController = new RoutePages_UIController_EditFormAdvanced();
$uiController->hook();
}
The RoutePages_UIController_EditFormAdvanced
class defines its own hook method
public function hook()
{
$this->f->add_filter('posts_selection', array($this, 'filterPostSupports'));
}
public function filterPostSupports()
{
global $post;
if ($this->pageManager->isAGeneratedPost($post)) {
$supports = $this->options->getSupportsBlacklistFor($post);
foreach ($supports as $feature) {
$this->f->remove_post_type_support($post->post_type, $feature);
}
}
}
and the list of post supports to remove comes from a method in the RoutePages_Options
class
public function getSupportsBlacklistFor($post){
$defaults = array('editor', 'revisions', 'page-attributes', 'post-formats', 'comments');
$supports = apply_filters(RoutePages::FILTER_POST_SUPPORTS_BLACKLIST, $defaults, $post);
if (!is_array($supports)) {
$supports = $defaults;
}
return $supports;
}
that is just a wrapper around any function the plugin will use to get its “options”. The result is somewhat satisfying and will need some more research on my side with a look into the remove_meta_box
function to get the work done and really remove all the unused post edit controls.
Next
I will add another filter to narrow down meta boxes even further and will change/replace the title input with a non-interactive control.