PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.2.7
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.2.7
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / inc / modules / auto-external-links / class-auto-external-links.php

class-auto-external-links.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 2.2.7, at inc/modules/auto-external-links/class-auto-external-links.php

144 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Auto External Links.
5 *
6 * @package Merchant
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 /**
14 * Auto External Links Class.
15 *
16 */
17 class Merchant_Auto_External_Links extends Merchant_Add_Module {
18
19 /**
20 * Module ID.
21 *
22 */
23 const MODULE_ID = 'auto-external-links';
24
25 /**
26 * Is module preview.
27 *
28 */
29 public static $is_module_preview = false;
30
31 /**
32 * Constructor.
33 *
34 */
35 public function __construct() {
36 parent::__construct();
37
38 // Module section.
39 $this->module_section = 'improve-experience';
40
41 // Module id.
42 $this->module_id = self::MODULE_ID;
43
44 // Module default settings.
45 $this->module_default_settings = array();
46
47 // Module data.
48 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
49
50 // Module options path.
51 $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
52
53 // Is module preview page.
54 if ( is_admin() && parent::is_module_settings_page() ) {
55 self::$is_module_preview = true;
56
57 // Enqueue admin styles.
58 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
59
60 // Admin preview box.
61 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
62 }
63
64 if ( ! Merchant_Modules::is_module_active( self::MODULE_ID ) ) {
65 return;
66 }
67
68 // Return early if it's on admin but not in the respective module settings page.
69 if ( is_admin() && ! parent::is_module_settings_page() ) {
70 return;
71 }
72
73 // Enqueue scripts.
74 add_action( 'merchant_enqueue_after_main_css_js', array( $this, 'enqueue_scripts' ) );
75 }
76
77 /**
78 * Admin enqueue CSS.
79 *
80 * @return void
81 */
82 public function admin_enqueue_css() {
83 $page = ( ! empty( $_GET['page'] ) ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
84 $module = ( ! empty( $_GET['module'] ) ) ? sanitize_text_field( wp_unslash( $_GET['module'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
85
86 if ( 'merchant' === $page && self::MODULE_ID === $module ) {
87 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
88 }
89 }
90
91 /**
92 * Admin Enqueue scripts.
93 *
94 * @return void
95 */
96 public function enqueue_scripts() {
97
98 // Register and enqueue the main module script.
99 wp_enqueue_script( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/auto-external-links.min.js', array(), MERCHANT_VERSION, true );
100 }
101
102 /**
103 * Render admin preview
104 *
105 * @param Merchant_Admin_Preview $preview
106 * @param string $module
107 *
108 * @return Merchant_Admin_Preview
109 */
110 public function render_admin_preview( $preview, $module ) {
111 if ( self::MODULE_ID === $module ) {
112 ob_start();
113 self::admin_preview_content();
114 $content = ob_get_clean();
115
116 // HTML.
117 $preview->set_html( $content );
118
119 }
120
121 return $preview;
122 }
123
124 /**
125 * Admin preview content.
126 *
127 * @return void
128 */
129 public function admin_preview_content() {
130 ?>
131
132 <div class="mrc-auto-external-links-preview">
133 <img src="<?php echo esc_url( MERCHANT_URI . 'inc/modules/' . self::MODULE_ID . '/admin/images/preview-auto-external-links.png' ); ?>" />
134 </div>
135
136 <?php
137 }
138 }
139
140 // Initialize the module.
141 add_action( 'init', function() {
142 Merchant_Modules::create_module( new Merchant_Auto_External_Links() );
143 } );
144