Last active
December 22, 2015 14:09
-
-
Save robneu/6484157 to your computer and use it in GitHub Desktop.
Sometimes you might want to create a custom page template that is built entirely using widgets. This can give your content a lot of flexibility for the end user; however, it could also be confusing. If you're not using the standard WordPress editor at all in your template, you should disable it and explain why it has been removed. This code will…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* If your theme or plugin has a page template that | |
* uses widgets to build the layout, users might be | |
* confused as to why the standard editor doesn't | |
* work as expected. This will disable the editor | |
* and introduce a notice explaining its absence. | |
* | |
* @author FAT Media <http://youneedfat.com> | |
* @copyright Copyright (c) 2013, FAT Media, LLC | |
* @license GPL-2.0+ | |
*/ | |
/** | |
* Perform a check to see whether or not a | |
* widgeted page template is being used. | |
* | |
* @todo Replace prefix with theme or plugin name | |
* @return bool | |
*/ | |
function prefix_using_widgeted_template() { | |
// Store all the widgeted templates | |
$widgeted_templates = array( 'your-template.php' ); | |
foreach ( $widgeted_templates as $template ) { | |
// Return true for all widgeted templates | |
if ( get_page_template_slug( $_REQUEST['post'] ) === $template ) | |
return true; | |
} | |
// Return false for other templates. | |
return false; | |
} | |
add_action( 'admin_init', 'prefix_remove_widgeted_editor' ); | |
/** | |
* Check to make sure a widgeted page template is | |
* selected and then disable the default WordPress editor. | |
* | |
* @todo Replace prefix with theme or plugin name | |
*/ | |
function prefix_remove_widgeted_editor() { | |
// Return early if a widgeted template isn't selected. | |
if ( ! prefix_using_widgeted_template() ) | |
return; | |
// Disable the standard WordPress editor. | |
remove_post_type_support( 'page', 'editor' ); | |
} | |
add_action( 'admin_notices', 'prefix_widgeted_admin_notice' ); | |
/** | |
* Check to make sure a widgeted page template is | |
* selected and then show a notice about the editor | |
* being disabled. | |
* | |
* @todo Replace prefix with theme or plugin name | |
* @todo Replace 'text-domain' with theme or plugin text domain | |
*/ | |
function prefix_widgeted_admin_notice() { | |
// Return early if a widgeted template isn't selected. | |
if ( ! prefix_using_widgeted_template() ) | |
return; | |
// Display a notice to users about the widgeted template. | |
echo '<div class="updated"><p>'; | |
printf ( | |
__( 'The normal editor is disabled because you\'re using a widgeted page template. You need to <a href="%s">use widgets</a> to edit this page.', 'text-domain' ), | |
'widgets.php' | |
); | |
echo '</p></div>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment