2021-02-28 00:52:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2021-05-28 01:51:51 +00:00
|
|
|
* Checks if the current activate theme is either blocksy, a child theme of blocksy or one of them in a customizer preview
|
2021-02-28 00:52:11 +00:00
|
|
|
*/
|
2021-04-14 17:40:23 +00:00
|
|
|
if ( !function_exists('tainacan_blocksy_is_blocksy_activated') ) {
|
|
|
|
function tainacan_blocksy_is_blocksy_activated() {
|
2021-02-28 00:52:11 +00:00
|
|
|
$theme = wp_get_theme();
|
|
|
|
$is_correct_theme = strpos( $theme->get_stylesheet(), 'blocksy' ) !== false;
|
2021-03-09 01:38:09 +00:00
|
|
|
|
2021-05-28 01:51:51 +00:00
|
|
|
$is_child_theme_of_blocksy = false;
|
2021-03-09 01:38:09 +00:00
|
|
|
if ($theme->parent() !== false)
|
|
|
|
$is_child_theme_of_blocksy = strpos( $theme->get_template(), 'blocksy' ) !== false;
|
|
|
|
|
2021-05-28 01:51:51 +00:00
|
|
|
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;
|
2021-02-28 00:52:11 +00:00
|
|
|
}
|
2021-05-28 01:51:51 +00:00
|
|
|
|
|
|
|
return $is_correct_theme || $is_child_theme_of_blocksy;
|
2021-02-28 00:52:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-30 12:37:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets version of current theme
|
|
|
|
*/
|
|
|
|
if ( !function_exists('tainacan_blocksy_get_theme_version') ) {
|
|
|
|
function tainacan_blocksy_get_theme_version() {
|
|
|
|
|
|
|
|
if ( tainacan_blocksy_is_blocksy_activated() ) {
|
|
|
|
$theme = wp_get_theme();
|
|
|
|
|
|
|
|
$is_child_theme_of_blocksy = FALSE;
|
|
|
|
|
|
|
|
if ($theme->parent() !== false)
|
|
|
|
$is_child_theme_of_blocksy = strpos( $theme->get_template(), 'blocksy' ) !== false;
|
|
|
|
|
|
|
|
return $is_child_theme_of_blocksy ? $theme->parent()->get('Version') : $theme->get('Version');
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-28 00:52:11 +00:00
|
|
|
/**
|
2021-03-09 01:38:09 +00:00
|
|
|
* Gets plugin or theme directory URL
|
2021-02-28 00:52:11 +00:00
|
|
|
*/
|
2021-04-14 17:40:23 +00:00
|
|
|
if ( !function_exists('tainacan_blocksy_get_plugin_dir_url') ) {
|
|
|
|
function tainacan_blocksy_get_plugin_dir_url() {
|
|
|
|
return !TAINACAN_BLOCKSY_IS_CHILD_THEME ? plugin_dir_url(__FILE__) : get_stylesheet_directory_uri();
|
2021-02-28 00:52:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-09 01:38:09 +00:00
|
|
|
* Gets plugin or theme directory path
|
2021-02-28 00:52:11 +00:00
|
|
|
*/
|
2021-04-14 17:40:23 +00:00
|
|
|
if ( !function_exists('tainacan_blocksy_get_plugin_dir_path') ) {
|
|
|
|
function tainacan_blocksy_get_plugin_dir_path() {
|
|
|
|
return !TAINACAN_BLOCKSY_IS_CHILD_THEME ? plugin_dir_path(__FILE__) : get_stylesheet_directory();
|
2021-02-28 00:52:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manages correct template location in plugin
|
|
|
|
*/
|
2021-04-14 17:40:23 +00:00
|
|
|
if ( !function_exists('tainacan_blocksy_get_template_part') ) {
|
|
|
|
function tainacan_blocksy_get_template_part($path) {
|
2021-04-29 20:13:03 +00:00
|
|
|
if (!TAINACAN_BLOCKSY_IS_CHILD_THEME) {
|
|
|
|
include(TAINACAN_BLOCKSY_PLUGIN_DIR_PATH . '/' . $path . '.php');
|
|
|
|
return; // Should not return this, as include contains boolean
|
|
|
|
} else
|
|
|
|
return get_template_part($path);
|
2021-02-28 00:52:11 +00:00
|
|
|
}
|
|
|
|
}
|