Skip to content
This repository was archived by the owner on Dec 2, 2022. It is now read-only.

Commit 4110d43

Browse files
committed
#217 - Redux templates loading on post types with no block editor.
Signed-off-by: Kevin Provance <kevin.provance@gmail.com>
1 parent 61263ad commit 4110d43

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Redux Changelog
22

3+
## 4.1.28 RC
4+
* Fixed: #217 - Redux templates loading on post types with no block editor.
5+
36
## 4.1.27
47
* Fixed: Image select not selecting default value.
58
* Modified: #209 - Link color field overridden by theme. Added 'important' arg to the output array to fix. See sample config.

redux-templates/classes/class-templates.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)