Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. /**
  2. * Disable Editor
  3. *
  4. **/
  5.  
  6. /**
  7. * Templates and Page IDs without editor
  8. *
  9. */
  10. function ea_disable_editor( $id = false ) {
  11.  
  12. $excluded_templates = array(
  13. 'template-new_product.php'
  14. );
  15.  
  16. $excluded_ids = array(
  17. // get_option( 'page_on_front' )
  18. );
  19.  
  20. if( empty( $id ) )
  21. return false;
  22.  
  23. $id = intval( $id );
  24. $template = get_page_template_slug( $id );
  25.  
  26. return in_array( $id, $excluded_ids ) || in_array( $template, $excluded_templates );
  27. }
  28.  
  29. /**
  30. * Disable Gutenberg by template
  31. *
  32. */
  33. function ea_disable_gutenberg( $can_edit, $post_type ) {
  34.  
  35. if( ! ( is_admin() && !empty( $_GET['post'] ) ) )
  36. return $can_edit;
  37.  
  38. if( ea_disable_editor( $_GET['post'] ) )
  39. $can_edit = false;
  40.  
  41. return $can_edit;
  42.  
  43. }
  44. add_filter( 'gutenberg_can_edit_post_type', 'ea_disable_gutenberg', 10, 2 );
  45. add_filter( 'use_block_editor_for_post_type', 'ea_disable_gutenberg', 10, 2 );
  46.  
  47. /**
  48. * Disable Classic Editor by template
  49. *
  50. */
  51. function ea_disable_classic_editor() {
  52.  
  53. $screen = get_current_screen();
  54. if( 'page' !== $screen->id || ! isset( $_GET['post']) )
  55. return;
  56.  
  57. if( ea_disable_editor( $_GET['post'] ) ) {
  58. remove_post_type_support( 'page', 'editor' );
  59. }
  60.  
  61. }
  62. add_action( 'admin_head', 'ea_disable_classic_editor' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement