From e24b10afffe436fa47bdd065e1a79a6b47eb5c5e Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Thu, 27 May 2021 22:51:51 -0300 Subject: [PATCH] Improves child theme detection for when in customizer --- tainacan-blocksy/inc/customizer.php | 4 ++-- tainacan-blocksy/inc/plugin.php | 6 +++--- tainacan-blocksy/utils.php | 19 +++++++++++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/tainacan-blocksy/inc/customizer.php b/tainacan-blocksy/inc/customizer.php index 3616c25..ff8ebd8 100644 --- a/tainacan-blocksy/inc/customizer.php +++ b/tainacan-blocksy/inc/customizer.php @@ -3,6 +3,7 @@ /** * Adds Tainacan repository and term items list to settings on customizer. */ + if ( !function_exists('tainacan_blocksy_add_repository_and_terms_items_options_panel') ) { function tainacan_blocksy_add_repository_and_terms_items_options_panel($options) { @@ -23,7 +24,6 @@ if ( !function_exists('tainacan_blocksy_add_repository_and_terms_items_options_p TAINACAN_BLOCKSY_PLUGIN_DIR_PATH . '/inc/options/archives/tainacan-terms-items.php', [], false ); - return $options; } } @@ -101,7 +101,7 @@ if ( !function_exists('tainacan_blocksy_custom_post_types_archive_options') ) { } } } - + return $options; } } diff --git a/tainacan-blocksy/inc/plugin.php b/tainacan-blocksy/inc/plugin.php index aec5194..c005f2b 100644 --- a/tainacan-blocksy/inc/plugin.php +++ b/tainacan-blocksy/inc/plugin.php @@ -13,8 +13,8 @@ if ( !function_exists('tainacan_blocksy_archive_templates_redirects') ) { $current_post_type = get_post_type(); if (in_array($current_post_type, $collections_post_types)) { - - if (is_post_type_archive()) { + + if (is_post_type_archive()) { include( TAINACAN_BLOCKSY_PLUGIN_DIR_PATH . '/tainacan/archive-items.php' ); exit; } @@ -37,7 +37,7 @@ if ( !function_exists('tainacan_blocksy_archive_templates_redirects') ) { } } -add_action('template_redirect', 'tainacan_blocksy_archive_templates_redirects'); +add_action('template_redirect', 'tainacan_blocksy_archive_templates_redirects', 2, 0); /** * Uses Template redirect for setting the proper template to items diff --git a/tainacan-blocksy/utils.php b/tainacan-blocksy/utils.php index 0d24e1f..0cc0ab4 100644 --- a/tainacan-blocksy/utils.php +++ b/tainacan-blocksy/utils.php @@ -1,22 +1,29 @@ get_stylesheet(), 'blocksy' ) !== false; - $is_child_theme_of_blocksy = FALSE; + $is_child_theme_of_blocksy = false; if ($theme->parent() !== false) $is_child_theme_of_blocksy = strpos( $theme->get_template(), 'blocksy' ) !== false; - $another_theme_in_preview = false; - if ( (isset( $_REQUEST['theme'] ) && strpos( strtolower( $_REQUEST['theme'] ), 'blocksy' ) === false || isset( $_REQUEST['customize_theme'] ) && strpos( strtolower( $_REQUEST['customize_theme'] ), 'blocksy' ) === false) && strpos( $_SERVER['REQUEST_URI'], 'customize' ) !== false ) { - $another_theme_in_preview = true; + if ( isset($_SERVER['REQUEST_URI']) && strpos( $_SERVER['REQUEST_URI'], 'customize' ) !== false ) { + $preview_theme_slug = isset( $_REQUEST['theme'] ) ? strtolower($_REQUEST['theme']) : ( isset( $_REQUEST['customize_theme'] ) ? strtolower($_REQUEST['customize_theme']) : ''); + + $preview_theme = wp_get_theme($preview_theme_slug); + $is_correct_theme = strpos( $preview_theme->get_stylesheet(), 'blocksy' ) !== false; + + $is_child_theme_of_blocksy = false; + if ($preview_theme->parent() !== false) + $is_child_theme_of_blocksy = strpos( $preview_theme->get_template(), 'blocksy' ) !== false; } - return ($is_correct_theme || $is_child_theme_of_blocksy) && !$another_theme_in_preview; + + return $is_correct_theme || $is_child_theme_of_blocksy; } }