| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Product Audio |
| 5 |
* |
| 6 |
* @package Merchant |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Product audio class. |
| 15 |
* |
| 16 |
*/ |
| 17 |
class Merchant_Product_Audio extends Merchant_Add_Module { |
| 18 |
|
| 19 |
/** |
| 20 |
* Module ID. |
| 21 |
* |
| 22 |
*/ |
| 23 |
const MODULE_ID = 'product-audio'; |
| 24 |
|
| 25 |
/** |
| 26 |
* Is module preview. |
| 27 |
* |
| 28 |
*/ |
| 29 |
public static $is_module_preview = false; |
| 30 |
|
| 31 |
/** |
| 32 |
* Initialize the module's option group definitions. |
| 33 |
* |
| 34 |
* @return array<int, array<string, mixed>> Array of option group arrays. |
| 35 |
*/ |
| 36 |
protected function init_option_groups() { |
| 37 |
return require MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php'; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Constructor. |
| 42 |
* |
| 43 |
*/ |
| 44 |
public function __construct() { |
| 45 |
|
| 46 |
// Module id. |
| 47 |
$this->module_id = self::MODULE_ID; |
| 48 |
|
| 49 |
// WooCommerce only. |
| 50 |
$this->wc_only = true; |
| 51 |
|
| 52 |
// Parent construct. |
| 53 |
parent::__construct(); |
| 54 |
|
| 55 |
// Module section. |
| 56 |
$this->module_section = 'improve-experience'; |
| 57 |
|
| 58 |
// Module data. |
| 59 |
$this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ]; |
| 60 |
|
| 61 |
// AI prompt examples. |
| 62 |
$this->ai_examples = array( |
| 63 |
'blurb' => esc_html__( 'See what AI can do for your product audio, from setting a featured track on a product to building an audio gallery or switching on autoplay.', 'merchant' ), |
| 64 |
'prompts' => array( |
| 65 |
esc_html__( 'Explore the abilities WPVibe gives you access to, then set the featured audio on the Midnight Jazz Vinyl product so it plays in place of the featured image on the shop and archive pages', 'merchant' ), |
| 66 |
esc_html__( 'Check what abilities you have available through WPVibe, then add an audio gallery to the Midnight Jazz Vinyl product with a few preview tracks and position it before the image gallery', 'merchant' ), |
| 67 |
esc_html__( 'Look at your available WPVibe abilities, then turn on autoplay so the audio player starts on its own for shoppers', 'merchant' ), |
| 68 |
esc_html__( 'See what abilities WPVibe exposes, then enable the shortcode option so I can place the product audio player manually with [merchant_module_product_audio]', 'merchant' ), |
| 69 |
), |
| 70 |
); |
| 71 |
|
| 72 |
// Module options path. |
| 73 |
$this->module_options_path = MERCHANT_DIR . 'inc/modules/product-audio/admin/options.php'; |
| 74 |
|
| 75 |
// Is module preview page. |
| 76 |
if ( is_admin() && parent::is_module_settings_page() ) { |
| 77 |
self::$is_module_preview = true; |
| 78 |
|
| 79 |
// Enqueue admin styles. |
| 80 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) ); |
| 81 |
|
| 82 |
// Render module essencial instructions before the module page body content. |
| 83 |
add_action( 'merchant_admin_after_module_page_page_header', array( $this, 'admin_module_essencial_instructions' ) ); |
| 84 |
|
| 85 |
// Admin preview box. |
| 86 |
add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 ); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Admin enqueue CSS. |
| 92 |
* |
| 93 |
* @return void |
| 94 |
*/ |
| 95 |
public function admin_enqueue_css() { |
| 96 |
if ( parent::is_module_settings_page()) { |
| 97 |
wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/product-audio.min.css', array(), MERCHANT_VERSION ); |
| 98 |
wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION ); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Render module essencial instructions. |
| 104 |
* |
| 105 |
* @return void |
| 106 |
*/ |
| 107 |
public function admin_module_essencial_instructions() { ?> |
| 108 |
<div class="merchant-module-page-settings"> |
| 109 |
<div class="merchant-module-page-setting-box merchant-module-page-setting-box-style-2"> |
| 110 |
<div class="merchant-module-page-setting-fields"> |
| 111 |
<div class="merchant-module-page-setting-field merchant-module-page-setting-field-content"> |
| 112 |
<div class="merchant-module-page-setting-field-inner"> |
| 113 |
<div class="merchant-tag-pre-orders"> |
| 114 |
<i class="dashicons dashicons-info"></i> |
| 115 |
<p><?php echo esc_html__( 'Once this module is enabled new options to upload audio files will appear under the admin product edit page. This means you have to edit and upload the audio file for each product in your store.', 'merchant' ); ?> <?php printf( '<a href="%s" target="_blank">%s</a>', esc_url( admin_url( 'edit.php?post_type=product' ) ), esc_html__( 'View All Products', 'merchant' ) ); ?></p> |
| 116 |
</div> |
| 117 |
</div> |
| 118 |
</div> |
| 119 |
</div> |
| 120 |
</div> |
| 121 |
</div> |
| 122 |
|
| 123 |
<?php |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* Render admin preview |
| 128 |
* |
| 129 |
* @param Merchant_Admin_Preview $preview |
| 130 |
* @param string $module |
| 131 |
* |
| 132 |
* @return Merchant_Admin_Preview |
| 133 |
*/ |
| 134 |
public function render_admin_preview( $preview, $module ) { |
| 135 |
if ( self::MODULE_ID === $module ) { |
| 136 |
ob_start(); |
| 137 |
self::admin_preview_content(); |
| 138 |
$content = ob_get_clean(); |
| 139 |
|
| 140 |
// HTML. |
| 141 |
$preview->set_html( $content ); |
| 142 |
} |
| 143 |
|
| 144 |
return $preview; |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Admin preview content. |
| 149 |
* |
| 150 |
* @return void |
| 151 |
*/ |
| 152 |
public function admin_preview_content() { ?> |
| 153 |
|
| 154 |
<div class="mrc-product-audio-preview"> |
| 155 |
<img alt="product audio" src="<?php echo esc_url( MERCHANT_URI . 'inc/modules/product-audio/admin/images/preview-product-audio.png' ); ?>" /> |
| 156 |
</div> |
| 157 |
|
| 158 |
<?php |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
// Initialize the module. |
| 163 |
add_action( 'init', function() { |
| 164 |
Merchant_Modules::create_module(new Merchant_Product_Audio()); |
| 165 |
} ); |
| 166 |
|