Checks if blocksy theme is enabled before loading plugin.

This commit is contained in:
mateuswetah 2021-02-27 21:52:11 -03:00
parent 26482f9f5b
commit 32e8f10d5e
6 changed files with 74 additions and 20 deletions

View File

@ -18,21 +18,31 @@ if (! defined('WP_DEBUG') ) {
const BLOCKSY_TAINACAN_VERSION = '0.1.0';
const BLOCKSY_TAINACAN_IS_PLUGIN = false;
$plugin_root_url = BLOCKSY_TAINACAN_IS_PLUGIN ? plugin_dir_url(__FILE__) : get_stylesheet_directory_uri();
/* Tools to define our next constants */
require 'utils.php';
$plugin_root_url = blocksy_tainacan_get_plugin_dir_url();
define('BLOCKSY_TAINACAN_PLUGIN_URL_PATH', $plugin_root_url);
$plugin_root_dir = BLOCKSY_TAINACAN_IS_PLUGIN ? plugin_dir_path(__FILE__) : get_stylesheet_directory() ;
$plugin_root_dir = blocksy_tainacan_get_plugin_dir_path();
define('BLOCKSY_TAINACAN_PLUGIN_DIR_PATH', $plugin_root_dir);
/* Basic styles and script enqueues */
require BLOCKSY_TAINACAN_PLUGIN_DIR_PATH . '/inc/enqueues.php';
$blocksy_tainacan_is_blocksy_activated = blocksy_tainacan_is_blocksy_activated();
define('BLOCKSY_TAINACAN_IS_BLOCKSY_ACTIVATED', $blocksy_tainacan_is_blocksy_activated);
/* Template redirection necessary only if in a plugin */
if ( BLOCKSY_TAINACAN_IS_PLUGIN ) {
require BLOCKSY_TAINACAN_PLUGIN_DIR_PATH . '/inc/plugin.php';
}
/* This should only be used if in the child theme or if is a plugin and blocksy theme is installed */
if (!BLOCKSY_TAINACAN_IS_PLUGIN || (BLOCKSY_TAINACAN_IS_BLOCKSY_ACTIVATED && BLOCKSY_TAINACAN_IS_PLUGIN) ) {
/* Requires several settings, functions and helpers */
require BLOCKSY_TAINACAN_PLUGIN_DIR_PATH . '/inc/integration.php';
require BLOCKSY_TAINACAN_PLUGIN_DIR_PATH . '/inc/customizer.php';
require BLOCKSY_TAINACAN_PLUGIN_DIR_PATH . '/inc/navigation.php';
/* Basic styles and script enqueues */
require BLOCKSY_TAINACAN_PLUGIN_DIR_PATH . '/inc/enqueues.php';
/* Template redirection necessary only if in a plugin */
if ( BLOCKSY_TAINACAN_IS_PLUGIN ) {
require BLOCKSY_TAINACAN_PLUGIN_DIR_PATH . '/inc/plugin.php';
}
/* Requires several settings, functions and helpers */
require BLOCKSY_TAINACAN_PLUGIN_DIR_PATH . '/inc/integration.php';
require BLOCKSY_TAINACAN_PLUGIN_DIR_PATH . '/inc/customizer.php';
require BLOCKSY_TAINACAN_PLUGIN_DIR_PATH . '/inc/navigation.php';
}

View File

@ -148,13 +148,13 @@ if ( !function_exists('blocksy_tainacan_the_content_for_items') ) {
// 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 get_template_part( 'tainacan/item-single-page' );
return blocksy_tainacan_get_template_part( 'tainacan/item-single-page' );
}
}
return $content;
}
}
add_filter( 'the_content', 'blocksy_tainacan_the_content_for_items');
add_filter( 'the_content', 'blocksy_tainacan_the_content_for_items', 11);
?>

View File

@ -3,7 +3,7 @@
/**
* Enqueues styles and scripts
* Some JS files here are only necessary for Tainacan Item pages
*/
*/
function blocksy_tainacan_enqueue_scripts() {
// First, we enqueue parent theme styles

View File

@ -4,7 +4,7 @@
* Uses Template redirect for setting the proper template to items
* archives on Tainacan pages
*/
if ( !function_exists('blocksy_tainacan_archive_templates_redirects') )
if ( !function_exists('blocksy_tainacan_archive_templates_redirects') ) {
function blocksy_tainacan_archive_templates_redirects() {
global $wp_query;
if (is_post_type_archive()) {
@ -43,7 +43,7 @@ add_action('template_redirect', 'blocksy_tainacan_archive_templates_redirects');
* Uses Template redirect for setting the proper template to items
* archives on Tainacan pages
*/
if ( !function_exists('blocksy_tainacan_update_extensions_paths') )
if ( !function_exists('blocksy_tainacan_update_extensions_paths') ) {
function blocksy_tainacan_update_extensions_paths($paths) {
var_dump($paths);
return $paths;

View File

@ -33,13 +33,13 @@ if ($page_structure_type == 'type-gm' || $page_structure_type == 'type-mg') {
<div class="<?php echo 'tainacan-item-single tainacan-item-single--layout-'. $page_structure_type ?>" style="<?php echo $template_columns_style ?>">
<?php
get_template_part( 'template-parts/tainacan-item-single-document' );
blocksy_tainacan_get_template_part( 'template-parts/tainacan-item-single-document' );
do_action( 'blocksy-tainacan-single-item-after-document' );
get_template_part( 'template-parts/tainacan-item-single-attachments' );
blocksy_tainacan_get_template_part( 'template-parts/tainacan-item-single-attachments' );
do_action( 'blocksy-tainacan-single-item-after-attachments' );
get_template_part( 'template-parts/tainacan-item-single-metadata' );
blocksy_tainacan_get_template_part( 'template-parts/tainacan-item-single-metadata' );
do_action( 'blocksy-tainacan-single-item-after-metadata' );
?>
</div>

44
utils.php Normal file
View File

@ -0,0 +1,44 @@
<?php
/**
* Checks is the current activate theme is blocksy
*/
if ( !function_exists('blocksy_tainacan_is_blocksy_activated') ) {
function blocksy_tainacan_is_blocksy_activated() {
$theme = wp_get_theme();
$is_correct_theme = strpos( $theme->get_stylesheet(), 'blocksy' ) !== false;
$is_child_theme = $theme->parent() !== 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;
}
return $is_correct_theme && !$is_child_theme && !$another_theme_in_preview;
}
}
/**
* Checks is the current activate theme is blocksy
*/
if ( !function_exists('blocksy_tainacan_get_plugin_dir_url') ) {
function blocksy_tainacan_get_plugin_dir_url() {
return BLOCKSY_TAINACAN_IS_PLUGIN ? plugin_dir_url(__FILE__) : get_stylesheet_directory_uri();
}
}
/**
* Checks is the current activate theme is blocksy
*/
if ( !function_exists('blocksy_tainacan_get_plugin_dir_path') ) {
function blocksy_tainacan_get_plugin_dir_path() {
return BLOCKSY_TAINACAN_IS_PLUGIN ? plugin_dir_path(__FILE__) : get_stylesheet_directory();
}
}
/**
* Manages correct template location in plugin
*/
if ( !function_exists('blocksy_tainacan_get_template_part') ) {
function blocksy_tainacan_get_template_part($path) {
return BLOCKSY_TAINACAN_IS_PLUGIN ? include(BLOCKSY_TAINACAN_PLUGIN_DIR_PATH . '/' . $path . '.php') : get_template_part($path);
}
}