PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.6
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.6
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 1.6, at inc/modules/auto-external-links/class-auto-external-links.php

153 lines 3.8 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 // Mount preview url.
48 $preview_url = site_url( '/' );
49
50 if ( function_exists( 'wc_get_page_id' ) ) {
51 $preview_url = get_permalink( wc_get_page_id( 'shop' ) );
52 }
53
54 // Module data.
55 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
56 $this->module_data[ 'preview_url' ] = $preview_url;
57
58 // Module options path.
59 $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
60
61 // Is module preview page.
62 if ( is_admin() && parent::is_module_settings_page() ) {
63 self::$is_module_preview = true;
64
65 // Enqueue admin styles.
66 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
67
68 // Admin preview box.
69 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
70 }
71
72 if ( ! Merchant_Modules::is_module_active( self::MODULE_ID ) ) {
73 return;
74 }
75
76 // Return early if it's on admin but not in the respective module settings page.
77 if ( is_admin() && ! parent::is_module_settings_page() ) {
78 return;
79 }
80
81 // Enqueue scripts.
82 add_action( 'merchant_enqueue_after_main_css_js', array( $this, 'enqueue_scripts' ) );
83 }
84
85 /**
86 * Admin enqueue CSS.
87 *
88 * @return void
89 */
90 public function admin_enqueue_css() {
91 $page = ( ! empty( $_GET['page'] ) ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
92 $module = ( ! empty( $_GET['module'] ) ) ? sanitize_text_field( wp_unslash( $_GET['module'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
93
94 if ( 'merchant' === $page && self::MODULE_ID === $module ) {
95 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
96 }
97 }
98
99 /**
100 * Admin Enqueue scripts.
101 *
102 * @return void
103 */
104 public function enqueue_scripts() {
105
106 // Register and enqueue the main module script.
107 wp_enqueue_script( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/auto-external-links.min.js', array(), MERCHANT_VERSION, true );
108 }
109
110 /**
111 * Render admin preview
112 *
113 * @param Merchant_Admin_Preview $preview
114 * @param string $module
115 *
116 * @return Merchant_Admin_Preview
117 */
118 public function render_admin_preview( $preview, $module ) {
119 if ( self::MODULE_ID === $module ) {
120 ob_start();
121 self::admin_preview_content();
122 $content = ob_get_clean();
123
124 // HTML.
125 $preview->set_html( $content );
126
127 }
128
129 return $preview;
130 }
131
132 /**
133 * Admin preview content.
134 *
135 * @return void
136 */
137 public function admin_preview_content() {
138 ?>
139
140 <div class="mrc-auto-external-links-preview">
141 <img src="<?php echo esc_url( MERCHANT_URI . 'inc/modules/' . self::MODULE_ID . '/admin/images/preview-auto-external-links.png' ); ?>" />
142 </div>
143
144 <?php
145 }
146
147 }
148
149 // Initialize the module.
150 add_action( 'init', function() {
151 new Merchant_Auto_External_Links();
152 } );
153