-
-
Save billerickson/529bb94ca3aeb45fe875cbedcc3ec4f2 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Disable Editor | |
* | |
* @package ClientName | |
* @author Bill Erickson | |
* @since 1.0.0 | |
* @license GPL-2.0+ | |
**/ | |
/** | |
* Templates and Page IDs without editor | |
* | |
*/ | |
function ea_disable_editor( $id = false ) { | |
$excluded_templates = array( | |
'templates/modules.php', | |
'templates/contact.php' | |
); | |
$excluded_ids = array( | |
// get_option( 'page_on_front' ) | |
); | |
if( empty( $id ) ) | |
return false; | |
$id = intval( $id ); | |
$template = get_page_template_slug( $id ); | |
return in_array( $id, $excluded_ids ) || in_array( $template, $excluded_templates ); | |
} | |
/** | |
* Disable Gutenberg by template | |
* | |
*/ | |
function ea_disable_gutenberg( $can_edit, $post_type ) { | |
if( ! ( is_admin() && !empty( $_GET['post'] ) ) ) | |
return $can_edit; | |
if( ea_disable_editor( $_GET['post'] ) ) | |
$can_edit = false; | |
return $can_edit; | |
} | |
add_filter( 'gutenberg_can_edit_post_type', 'ea_disable_gutenberg', 10, 2 ); | |
add_filter( 'use_block_editor_for_post_type', 'ea_disable_gutenberg', 10, 2 ); | |
/** | |
* Disable Classic Editor by template | |
* | |
*/ | |
function ea_disable_classic_editor() { | |
$screen = get_current_screen(); | |
if( 'page' !== $screen->id || ! isset( $_GET['post']) ) | |
return; | |
if( ea_disable_editor( $_GET['post'] ) ) { | |
remove_post_type_support( 'page', 'editor' ); | |
} | |
} | |
add_action( 'admin_head', 'ea_disable_classic_editor' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it possible to add some comments to explain what the code is doing as i read it? I'm trying to figure out how to add my templates or post ID's and am not really understanding the code above, or if i can extend it myself to give me admin UI editing choices for it.