Checks Blocksy version before adopting global enqueue strategy.

This commit is contained in:
mateuswetah 2021-04-30 09:37:24 -03:00
parent 632f8ef670
commit fc649f80bc
3 changed files with 53 additions and 7 deletions

View File

@ -30,6 +30,9 @@ define('TAINACAN_BLOCKSY_PLUGIN_DIR_PATH', $plugin_root_dir);
$tainacan_blocksy_is_blocksy_activated = tainacan_blocksy_is_blocksy_activated();
define('TAINACAN_BLOCKSY_IS_BLOCKSY_ACTIVATED', $tainacan_blocksy_is_blocksy_activated);
$tainacan_blocksy_theme_version = tainacan_blocksy_get_theme_version();
define('TAINACAN_BLOCKSY_BLOCKSY_THEME_VERSION', $tainacan_blocksy_theme_version);
/* This should only be used if we're in the child theme or if is a plugin and blocksy theme is installed */
if ( TAINACAN_BLOCKSY_IS_CHILD_THEME || ( TAINACAN_BLOCKSY_IS_BLOCKSY_ACTIVATED && !TAINACAN_BLOCKSY_IS_CHILD_THEME ) ) {

View File

@ -29,13 +29,33 @@ add_action( 'wp_enqueue_scripts', 'tainacan_blocksy_enqueue_scripts' );
/**
* Now, some dynamic css that is generated using blocksy dynamic css logic
*/
add_action('blocksy:global-dynamic-css:enqueue', function ($args) {
blocksy_theme_get_dynamic_styles(array_merge([
'path' => TAINACAN_BLOCKSY_PLUGIN_DIR_PATH . '/inc/global.php',
'chunk' => 'global',
'forced_call' => true
], $args));
}, 10, 3);
if ( TAINACAN_BLOCKSY_BLOCKSY_THEME_VERSION !== NULL && ( version_compare(TAINACAN_BLOCKSY_BLOCKSY_THEME_VERSION, '1.7.9') <= 0 ) ) {
add_action('blocksy:global-dynamic-css:enqueue', function ($args) {
blocksy_theme_get_dynamic_styles(array_merge([
'path' => TAINACAN_BLOCKSY_PLUGIN_DIR_PATH . '/inc/global.php',
'chunk' => 'global',
'forced_call' => true
], $args));
}, 10, 3);
} else {
add_action('blocksy:global-dynamic-css:enqueue:inline', function ($args) {
if ( defined ('TAINACAN_VERSION') ) {
$collections_post_types = \Tainacan\Repositories\Repository::get_collections_db_identifiers();
$post_type = get_post_type();
// Check if we're inside the main loop in a single Post.
if ( in_array($post_type, $collections_post_types) ) {
blocksy_theme_get_dynamic_styles(array_merge([
'path' => TAINACAN_BLOCKSY_PLUGIN_DIR_PATH . '/inc/global.php',
'chunk' => 'global',
'forced_call' => true
], $args));
}
}
}, 10, 3);
}
/**
* Enqueues front-end CSS for the items page fixed filters logic.

View File

@ -20,6 +20,29 @@ if ( !function_exists('tainacan_blocksy_is_blocksy_activated') ) {
}
}
/**
* 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;
}
}
}
/**
* Gets plugin or theme directory URL
*/