blocksy-tainacan/tainacan-blocksy/inc/customizer.php

166 lines
5.4 KiB
PHP
Raw Normal View History

2021-02-23 02:09:46 +00:00
<?php
/**
* 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) {
2021-02-23 02:09:46 +00:00
$options['tainacan_repository_items_list'] = blc_call_fnc(
2021-02-23 02:09:46 +00:00
[
'fnc' => 'blocksy_get_options',
2021-02-23 02:09:46 +00:00
'default' => 'array'
],
TAINACAN_BLOCKSY_PLUGIN_DIR_PATH . '/inc/options/archives/tainacan-repository-items.php',
2021-02-23 02:09:46 +00:00
[], false
);
$options['tainacan_terms_items_list'] = blc_call_fnc(
2021-02-23 02:09:46 +00:00
[
'fnc' => 'blocksy_get_options',
2021-02-23 02:09:46 +00:00
'default' => 'array'
],
TAINACAN_BLOCKSY_PLUGIN_DIR_PATH . '/inc/options/archives/tainacan-terms-items.php',
2021-02-23 02:09:46 +00:00
[], false
);
return $options;
}
}
add_filter( 'blocksy_extensions_customizer_options', 'tainacan_blocksy_add_repository_and_terms_items_options_panel' );
2021-02-23 02:09:46 +00:00
/**
* Adds extra customizer options to items single page template
*/
if ( !function_exists('tainacan_blocksy_custom_post_types_single_options') ) {
function tainacan_blocksy_custom_post_types_single_options( $options, $post_type, $post_type_object ) {
2021-02-23 02:09:46 +00:00
// This should only happen if we have Tainacan plugin installed
if ( defined ('TAINACAN_VERSION') ) {
$collections_post_types = \Tainacan\Repositories\Repository::get_collections_db_identifiers();
if ( in_array($post_type, $collections_post_types) ) {
// Change the section title in the customizer
$options['title'] = sprintf(
__('Item from %s', 'tainacan-blocksy'),
2021-02-23 02:09:46 +00:00
$post_type_object->labels->name
);
// Extra options to the single item template
$item_extra_options = blocksy_get_options(TAINACAN_BLOCKSY_PLUGIN_DIR_PATH . '/inc/options/posts/tainacan-item-single.php', [
2021-02-23 02:09:46 +00:00
'post_type' => $post_type_object,
'is_general_cpt' => true
], false);
if ( is_array($item_extra_options) ) {
array_splice(
$options['options'][$post_type . '_single_section_options']['inner-options'][0],
1,
0,
$item_extra_options
);
}
}
}
return $options;
}
}
add_filter( 'blocksy:custom_post_types:single-options', 'tainacan_blocksy_custom_post_types_single_options', 10, 3 );
2021-02-23 02:09:46 +00:00
/**
* Adds extra customizer options to items single page template
*/
if ( !function_exists('tainacan_blocksy_custom_post_types_archive_options') ) {
function tainacan_blocksy_custom_post_types_archive_options( $options, $post_type, $post_type_object ) {
2021-02-23 02:09:46 +00:00
// This should only happen if we have Tainacan plugin installed
if ( defined ('TAINACAN_VERSION') ) {
$collections_post_types = \Tainacan\Repositories\Repository::get_collections_db_identifiers();
if ( in_array($post_type, $collections_post_types) ) {
// Change the section title in the customizer
$options['title'] = sprintf(
__('Items list from %s', 'tainacan-blocksy'),
2021-02-23 02:09:46 +00:00
$post_type_object->labels->name
);
// Extra options to the archive items list
$items_extra_options = blocksy_get_options(TAINACAN_BLOCKSY_PLUGIN_DIR_PATH . '/inc/options/posts/tainacan-item-archive.php', [
2021-02-23 02:09:46 +00:00
'prefix' => $post_type_object->name,
'is_general_cpt' => true
], false);
if ( is_array($items_extra_options) ) {
$options['options'][$post_type . '_section_options']['inner-options'] = $items_extra_options;
}
2021-07-13 22:28:10 +00:00
// We also do some changes on the Collections
} else if ( $post_type == 'tainacan-collection' ) {
// Change the section title in the customizer
$options['title'] = __('Tainacan collections list', 'tainacan-blocksy');
return $options;
// And taxonomies
} else if ( $post_type == 'tainacan-taxonomy' ) {
// Change the section title in the customizer
$options['title'] = __('Tainacan taxonomies list', 'tainacan-blocksy');
return $options;
2021-02-23 02:09:46 +00:00
}
}
2021-02-23 02:09:46 +00:00
return $options;
}
}
add_filter( 'blocksy:custom_post_types:archive-options', 'tainacan_blocksy_custom_post_types_archive_options', 10, 3 );
2021-02-23 02:09:46 +00:00
/**
* Removes tainacan metadatum and filters from the custom metadata options in the customizer controller.
*/
if ( !function_exists('tainacan_blocksy_custom_post_types_supported_list') ) {
function tainacan_blocksy_custom_post_types_supported_list( $potential_post_types ) {
2021-02-23 02:09:46 +00:00
// This should only happen if we have Tainacan plugin installed
if ( defined ('TAINACAN_VERSION') ) {
return array_filter( $potential_post_types, function($post_type) {
return !in_array($post_type, [ 'tainacan-metadatum', 'tainacan-filter' ]);
});
}
return $potential_post_types;
}
}
add_filter( 'blocksy:custom_post_types:supported_list', 'tainacan_blocksy_custom_post_types_supported_list', 10 );
2021-02-23 02:09:46 +00:00
/**
2021-11-20 15:54:06 +00:00
* Renders the single item page with a custom template that will use most of Blocksy features
2021-02-23 02:09:46 +00:00
*/
if ( !function_exists('tainacan_blocksy_the_content_for_items') ) {
function tainacan_blocksy_the_content_for_items( $content ) {
2021-02-23 02:09:46 +00:00
// 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 tainacan_blocksy_get_template_part( 'tainacan/item-single-page' );
2021-02-23 02:09:46 +00:00
}
}
2021-02-23 02:09:46 +00:00
return $content;
}
}
add_filter( 'the_content', 'tainacan_blocksy_the_content_for_items', 11);
2021-02-23 02:09:46 +00:00
?>