Fixes post navigation function not bewing redeclared when using plugin.

This commit is contained in:
mateuswetah 2021-03-07 18:27:41 -03:00
parent bb71302a2d
commit cefebd6db5
1 changed files with 39 additions and 10 deletions

View File

@ -316,6 +316,14 @@ if ( !function_exists('blocksy_tainacan_item_navigation') ) {
} }
} }
/**
* The following has to happen on hook plugins_loaded because the parent theme
* has already declared the function in the plugin lifecycle, somehting that
* is not necessary if on a child theme.
*/
if (BLOCKSY_TAINACAN_IS_PLUGIN) {
function blocksy_tainacan_after_theme_setup() {
/** /**
* Overrides parent theme blocksy post navigation logic to handle items navigation * Overrides parent theme blocksy post navigation logic to handle items navigation
*/ */
@ -333,6 +341,27 @@ function blocksy_post_navigation() {
} }
return blocksy_default_post_navigation(); return blocksy_default_post_navigation();
} }
}
add_action( 'plugins_loaded', 'blocksy_tainacan_after_theme_setup' );
} else {
/**
* Overrides parent theme blocksy post navigation logic to handle items navigation
*/
function blocksy_post_navigation() {
// This should only happen if we have Tainacan plugin installed
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) && is_singular() && in_the_loop() && is_main_query() ) {
return blocksy_tainacan_item_navigation();
}
}
return blocksy_default_post_navigation();
}
}
/** /**
* Uses Blocksy filter to customize the related posts logic on Tainacan Items page. (NOT IN USE YET) * Uses Blocksy filter to customize the related posts logic on Tainacan Items page. (NOT IN USE YET)