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

162 lines 4.3 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 * 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 parent::__construct();
46
47 // Module section.
48 $this->module_section = 'improve-experience';
49
50 // Module id.
51 $this->module_id = self::MODULE_ID;
52
53 // Module default settings.
54 $this->module_default_settings = array();
55
56 // Module data.
57 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
58
59 // AI prompt examples.
60 $this->ai_examples = array(
61 'blurb' => esc_html__( 'See what AI can do for your external links, from opening them all in a new browser tab to turning that behavior back off.', 'merchant' ),
62 'prompts' => array(
63 esc_html__( 'Explore the abilities WPVibe gives you access to, then turn on Auto External Links so every external link opens in a new browser tab', 'merchant' ),
64 esc_html__( 'Check what abilities you have available through WPVibe, then turn Auto External Links back off so external links open in the same tab', 'merchant' ),
65 ),
66 );
67
68 // Module options path.
69 $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
70
71 // Is module preview page.
72 if ( is_admin() && parent::is_module_settings_page() ) {
73 self::$is_module_preview = true;
74
75 // Enqueue admin styles.
76 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
77
78 // Admin preview box.
79 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
80 }
81
82 if ( ! Merchant_Modules::is_module_active( self::MODULE_ID ) ) {
83 return;
84 }
85
86 // Return early if it's on admin but not in the respective module settings page.
87 if ( is_admin() && ! parent::is_module_settings_page() ) {
88 return;
89 }
90
91 // Enqueue scripts.
92 add_action( 'merchant_enqueue_after_main_css_js', array( $this, 'enqueue_scripts' ) );
93 }
94
95 /**
96 * Admin enqueue CSS.
97 *
98 * @return void
99 */
100 public function admin_enqueue_css() {
101 $page = ( ! empty( $_GET['page'] ) ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
102 $module = ( ! empty( $_GET['module'] ) ) ? sanitize_text_field( wp_unslash( $_GET['module'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
103
104 if ( 'merchant' === $page && self::MODULE_ID === $module ) {
105 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
106 }
107 }
108
109 /**
110 * Admin Enqueue scripts.
111 *
112 * @return void
113 */
114 public function enqueue_scripts() {
115
116 // Register and enqueue the main module script.
117 wp_enqueue_script( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/auto-external-links.min.js', array(), MERCHANT_VERSION, true );
118 }
119
120 /**
121 * Render admin preview
122 *
123 * @param Merchant_Admin_Preview $preview
124 * @param string $module
125 *
126 * @return Merchant_Admin_Preview
127 */
128 public function render_admin_preview( $preview, $module ) {
129 if ( self::MODULE_ID === $module ) {
130 ob_start();
131 self::admin_preview_content();
132 $content = ob_get_clean();
133
134 // HTML.
135 $preview->set_html( $content );
136
137 }
138
139 return $preview;
140 }
141
142 /**
143 * Admin preview content.
144 *
145 * @return void
146 */
147 public function admin_preview_content() {
148 ?>
149
150 <div class="mrc-auto-external-links-preview">
151 <img src="<?php echo esc_url( MERCHANT_URI . 'inc/modules/' . self::MODULE_ID . '/admin/images/preview-auto-external-links.png' ); ?>" />
152 </div>
153
154 <?php
155 }
156 }
157
158 // Initialize the module.
159 add_action( 'init', function() {
160 Merchant_Modules::create_module( new Merchant_Auto_External_Links() );
161 } );
162