| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* Blocksy theme compatibility layer |
| 8 |
*/ |
| 9 |
if ( ! class_exists( 'Merchant_Blocksy_Theme' ) ) { |
| 10 |
class Merchant_Blocksy_Theme { |
| 11 |
|
| 12 |
/** |
| 13 |
* Constructor. |
| 14 |
*/ |
| 15 |
public function __construct() { |
| 16 |
add_action( 'wp_enqueue_scripts', array( $this, 'styles' ) ); |
| 17 |
add_action( 'init', array( $this, 'product_video_module' ) ); |
| 18 |
add_action( 'init', array( $this, 'product_audio_module' ) ); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Load compatibility styles if the Blocksy theme is installed and active. |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public function styles() { |
| 27 |
if ( ! merchant_is_blocksy_active() ) { |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
wp_enqueue_style( |
| 32 |
'merchant-blocksy-compatibility', |
| 33 |
MERCHANT_URI . 'assets/css/compatibility/blocksy/style.min.css', |
| 34 |
array(), |
| 35 |
MERCHANT_VERSION |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Handle with all required compatibility with 'Product Video' module. |
| 41 |
* |
| 42 |
* @return void |
| 43 |
*/ |
| 44 |
public function product_video_module() { |
| 45 |
if ( ! merchant_is_blocksy_active() ) { |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
if ( ! Merchant_Modules::is_module_active( 'product-video' ) ) { |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
// Removes the theme's default product image on archive pages. |
| 54 |
add_filter( 'theme_mod_woo_card_layout', function($mod_settings){ |
| 55 |
global $post; |
| 56 |
|
| 57 |
if ( ! isset( $post ) ) { |
| 58 |
return $mod_settings; |
| 59 |
} |
| 60 |
|
| 61 |
$has_featured_video = get_post_meta( $post->ID, '_merchant_enable_featured_video', true ); |
| 62 |
if ( ! $has_featured_video ) { |
| 63 |
return $mod_settings; |
| 64 |
} |
| 65 |
|
| 66 |
foreach( $mod_settings as $index => $setting ) { |
| 67 |
if ( isset( $setting['id'] ) && $setting['id'] === 'product_image' ) { |
| 68 |
$mod_settings[$index]['enabled'] = false; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
return $mod_settings; |
| 73 |
} ); |
| 74 |
|
| 75 |
// Replaces the theme's default image gallery with the default from WooCommerce. |
| 76 |
add_filter( 'blocksy:woocommerce:product-view:use-default', '__return_true' ); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Handle with all required compatibility with 'Product Audio' module. |
| 81 |
* |
| 82 |
* @return void |
| 83 |
*/ |
| 84 |
public function product_audio_module() { |
| 85 |
if ( ! merchant_is_blocksy_active() ) { |
| 86 |
return; |
| 87 |
} |
| 88 |
|
| 89 |
if ( ! Merchant_Modules::is_module_active( 'product-audio' ) ) { |
| 90 |
return; |
| 91 |
} |
| 92 |
|
| 93 |
// Removes the theme's default product image on archive pages. |
| 94 |
add_filter( 'theme_mod_woo_card_layout', function($mod_settings){ |
| 95 |
global $post; |
| 96 |
|
| 97 |
if ( ! isset( $post ) ) { |
| 98 |
return $mod_settings; |
| 99 |
} |
| 100 |
|
| 101 |
$has_featured_audio = get_post_meta( $post->ID, '_merchant_enable_featured_audio', true ); |
| 102 |
if ( ! $has_featured_audio ) { |
| 103 |
return $mod_settings; |
| 104 |
} |
| 105 |
|
| 106 |
foreach( $mod_settings as $index => $setting ) { |
| 107 |
if ( isset( $setting['id'] ) && $setting['id'] === 'product_image' ) { |
| 108 |
$mod_settings[$index]['enabled'] = false; |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
return $mod_settings; |
| 113 |
} ); |
| 114 |
|
| 115 |
// Replaces the theme's default image gallery with the default from WooCommerce. |
| 116 |
add_filter( 'blocksy:woocommerce:product-view:use-default', '__return_true' ); |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* The class object can be accessed with "global $blocksy_compatibility", to allow removing actions. |
| 122 |
* Improving Third-party integrations. |
| 123 |
*/ |
| 124 |
$merchant_blocksy_compatibility = new Merchant_Blocksy_Theme(); |
| 125 |
} |
| 126 |
|