@@ -33,18 +33,25 @@ class Templates {
3333 */
3434 public function __construct () {
3535 global $ pagenow ;
36+
3637 if ( ( 'post.php ' === $ pagenow || 'post-new.php ' === $ pagenow ) && \Redux_Enable_Gutenberg::$ is_disabled ) {
38+
3739 // We don't want to add templates unless it's a gutenberg page.
3840 return ;
3941 }
4042
43+ if ( ! $ this ->is_gutenberg_page () ) {
44+ return ;
45+ }
46+
4147 // Include ReduxTemplates default template without wrapper.
4248 add_filter ( 'template_include ' , array ( $ this , 'template_include ' ) );
4349 // Override the default content-width when using Redux templates so the template doesn't look like crao.
4450 add_action ( 'wp ' , array ( $ this , 'modify_template_content_width ' ) );
4551
4652 // Add ReduxTemplates supported Post type in page template.
4753 $ post_types = get_post_types ();
54+
4855 if ( ! empty ( $ post_types ) ) {
4956 foreach ( $ post_types as $ post_type ) {
5057 add_filter ( "theme_ {$ post_type }_templates " , array ( $ this , 'add_templates ' ) );
@@ -55,6 +62,31 @@ public function __construct() {
5562
5663 }
5764
65+ /**
66+ * Is Gutenburg loaded via WordPress core.
67+ *
68+ * @return bool
69+ */
70+ public function is_gutenberg_page (): bool {
71+ if ( function_exists ( 'is_gutenberg_page ' ) && is_gutenberg_page () ) {
72+ // The Gutenberg plugin is on.
73+ return true ;
74+ }
75+
76+ if ( ! function_exists ( 'get_current_screen ' ) ) {
77+ require_once ABSPATH . '/wp-admin/includes/screen.php ' ;
78+ }
79+
80+ $ current_screen = get_current_screen ();
81+
82+ if ( method_exists ( $ current_screen , 'is_block_editor ' ) && $ current_screen ->is_block_editor () ) {
83+ // Gutenberg page on 5+.
84+ return true ;
85+ }
86+
87+ return false ;
88+ }
89+
5890 /**
5991 * Add the redux-template class to the admin body if a redux-templates page type is selected.
6092 *
@@ -63,9 +95,11 @@ public function __construct() {
6395 * @since 4.1.19
6496 * @return string
6597 */
66- public function add_body_class ( $ classes ) {
98+ public function add_body_class ( $ classes ): string {
6799 global $ post ;
100+
68101 $ screen = get_current_screen ();
102+
69103 if ( 'post ' === $ screen ->base && get_current_screen ()->is_block_editor () ) {
70104 $ check = get_post_meta ( $ post ->ID , '_wp_page_template ' , true );
71105 if ( strpos ( $ check , 'redux-templates_ ' ) !== false ) {
0 commit comments