| 1 |
<?php |
| 2 |
|
| 3 |
namespace RadiusTheme\SB\Modules\VariationGallery; |
| 4 |
|
| 5 |
use RadiusTheme\SB\Helpers\Fns; |
| 6 |
use RadiusTheme\SB\Traits\SingletonTrait; |
| 7 |
|
| 8 |
// Do not allow directly accessing this file. |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit( 'This script cannot be accessed directly.' ); |
| 11 |
} |
| 12 |
/** |
| 13 |
* Variation Swatches |
| 14 |
*/ |
| 15 |
final class VariationGalleryInit { |
| 16 |
|
| 17 |
/** |
| 18 |
* SingleTon |
| 19 |
*/ |
| 20 |
use SingletonTrait; |
| 21 |
|
| 22 |
/** |
| 23 |
* Asset Handle |
| 24 |
* |
| 25 |
* @var string |
| 26 |
*/ |
| 27 |
private $handle = 'rtsb-variation-gallery'; |
| 28 |
|
| 29 |
/** |
| 30 |
* Constructor. |
| 31 |
* |
| 32 |
* @return void |
| 33 |
*/ |
| 34 |
private function __construct() { |
| 35 |
$already_active = Fns::check_plugin_active( 'woo-product-variation-gallery/woo-product-variation-gallery.php' ); |
| 36 |
if ( ! $already_active ) { |
| 37 |
$this->handle = Fns::optimized_handle( $this->handle ); |
| 38 |
$this->scripts(); |
| 39 |
$this->init(); |
| 40 |
do_action( 'rtsb/variation/gallery/init' ); |
| 41 |
} |
| 42 |
} |
| 43 |
/** |
| 44 |
* Initialize Functionality. |
| 45 |
* |
| 46 |
* @return void |
| 47 |
*/ |
| 48 |
private function scripts() { |
| 49 |
add_action( 'wp_enqueue_scripts', [ $this, 'frontend_assets' ], 20 ); |
| 50 |
add_action( 'admin_enqueue_scripts', [ $this, 'register_backend_assets' ], 1 ); |
| 51 |
} |
| 52 |
/** |
| 53 |
* Initialize Functionality. |
| 54 |
* |
| 55 |
* @return void |
| 56 |
*/ |
| 57 |
private function init() { |
| 58 |
GalleryAdmin::instance(); |
| 59 |
GalleryFrontEnd::instance(); |
| 60 |
} |
| 61 |
/** |
| 62 |
* Assets. |
| 63 |
* |
| 64 |
* @return void |
| 65 |
*/ |
| 66 |
public function frontend_assets() { |
| 67 |
// Enqueue assets. |
| 68 |
$this->handle = Fns::enqueue_module_assets( |
| 69 |
$this->handle, |
| 70 |
'variation-gallery', |
| 71 |
[ |
| 72 |
'context' => ( function_exists( 'rtsbpro' ) && rtsb()->has_pro() ) ? rtsbpro() : rtsb(), |
| 73 |
'version' => rtsb()->has_pro() ? RTSBPRO_VERSION : RTSB_VERSION, |
| 74 |
] |
| 75 |
); |
| 76 |
$this->frontend_dynamic_css(); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* @return void |
| 81 |
*/ |
| 82 |
private function frontend_dynamic_css() { |
| 83 |
$options = GalleryFns::get_options(); |
| 84 |
$dynamic_css = ':root{'; |
| 85 |
$dynamic_css .= '}'; |
| 86 |
if ( ! empty( $dynamic_css ) ) { |
| 87 |
wp_add_inline_style( $this->handle, $dynamic_css ); |
| 88 |
} |
| 89 |
} |
| 90 |
/** |
| 91 |
* Assets. |
| 92 |
* |
| 93 |
* @return void |
| 94 |
*/ |
| 95 |
public function register_backend_assets() { |
| 96 |
global $post; |
| 97 |
$current_screen = get_current_screen(); |
| 98 |
$screen_id = $current_screen ? $current_screen->id : ''; |
| 99 |
// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict |
| 100 |
if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) { |
| 101 |
$ajaxurl = admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE ); |
| 102 |
} else { |
| 103 |
$ajaxurl = admin_url( 'admin-ajax.php' ); |
| 104 |
} |
| 105 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 106 |
if ( ( 'product' === sanitize_text_field( wp_unslash( $_GET['post_type'] ?? '' ) ) && isset( $_GET['taxonomy'] ) ) || 'product' === $screen_id ) { |
| 107 |
wp_register_style( 'rtsb-variation-gallery-admin', rtsb()->get_assets_uri( 'css/backend/variation-gallery-admin.css' ), '', '1.0' ); |
| 108 |
wp_register_script( 'rtsb-variation-gallery-admin', rtsb()->get_assets_uri( 'js/backend/variation-gallery-admin.js' ), '', '1.0', true ); |
| 109 |
wp_enqueue_script( 'rtsb-variation-gallery-admin' ); |
| 110 |
wp_enqueue_style( 'rtsb-variation-gallery-admin' ); |
| 111 |
wp_localize_script( |
| 112 |
'rtsb-variation-gallery-admin', |
| 113 |
'rtsbVgParams', |
| 114 |
[ |
| 115 |
'ajaxurl' => esc_url( $ajaxurl ), |
| 116 |
'media_title' => esc_html__( 'Choose an Image', 'shopbuilder' ), |
| 117 |
'button_title' => esc_html__( 'Use Image', 'shopbuilder' ), |
| 118 |
'add_media' => esc_html__( 'Add Media', 'shopbuilder' ), |
| 119 |
'add_video' => esc_html__( 'Add Video', 'shopbuilder' ), |
| 120 |
'sure_txt' => esc_html__( 'Are you sure to delete?', 'shopbuilder' ), |
| 121 |
] |
| 122 |
); |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
|