PluginProbe ʕ •ᴥ•ʔ
ShopPress – Shop Builder for Elementor and WooCommerce / trunk
ShopPress – Shop Builder for Elementor and WooCommerce vtrunk
shop-press / Modules / AdminMessage.php
shop-press / Modules Last commit date
VariationSwatches 1 week ago Wishlist 1 week ago AdminMessage.php 1 week ago AjaxSearch.php 1 week ago Backorder.php 1 week ago CatalogMode.php 1 year ago Compare.php 1 week ago DefaultTemplates.php 2 years ago FlashSalesCountdown.php 1 year ago MenuCart.php 4 months ago MobilePanel.php 1 week ago MultiStep.php 1 year ago Notifications.php 1 week ago QuickView.php 1 week ago RecentlyViewedProducts.php 1 year ago RenameLabel.php 4 months ago Shopify.php 1 year ago SingleAjaxAddToCart.php 1 week ago SizeChart.php 1 week ago StickyAddToCart.php 1 week ago
AdminMessage.php
288 lines
1 <?php
2 /**
3 * Display admin message.
4 *
5 * @package ShopPress
6 */
7
8 namespace ShopPress\Modules;
9
10 defined( 'ABSPATH' ) || exit;
11
12 class AdminMessage {
13 /**
14 * Constructor.
15 *
16 * @since 1.0.0
17 */
18 public function __construct() {
19
20 if ( ! is_admin() ) {
21 return;
22 }
23
24 $this->add_message_option();
25 $this->hooks();
26 }
27
28 /**
29 * Instance of this class.
30 *
31 * @since 1.0.0
32 */
33 public static $instance;
34
35 /**
36 * Provides access to a single instance of a module using the singleton pattern.
37 *
38 * @since 1.0.0
39 *
40 * @return object
41 */
42 public static function get_instance() {
43 if ( self::$instance === null ) {
44 self::$instance = new self();
45 }
46 return self::$instance;
47 }
48
49 /**
50 * Hooks.
51 *
52 * @since 1.0.0
53 */
54 private function hooks() {
55
56 if ( ! $this->check_installed_plugins() === true ) {
57 add_action( 'admin_notices', array( $this, 'message_content' ) );
58 add_action( 'shoppress/admin/before_dashboard', array( $this, 'message_content' ) );
59 }
60
61 if ( ! is_active_shoppress_pro() ) {
62 // add_action( 'admin_notices', array( $this, 'go_pro_message_content' ) );
63 }
64
65 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
66 add_action( 'wp_ajax_shoppress_admin_message', array( $this, 'shoppress_admin_message' ) );
67 }
68
69 /**
70 * enqueue styles.
71 *
72 * @since 1.0.0
73 */
74 public function enqueue_styles() {
75 wp_enqueue_style( 'sp-admin-message' );
76 wp_enqueue_script( 'sp-admin-message' );
77
78 wp_localize_script(
79 'sp-admin-message',
80 'shoppressMessage',
81 array(
82 'ajax_url' => admin_url( 'admin-ajax.php' ),
83 'nonce' => wp_create_nonce( 'shoppress_message' ),
84 )
85 );
86 }
87
88 /**
89 * Add shoppress_message option.
90 *
91 * @since 1.0.0
92 */
93 private function add_message_option() {
94
95 if ( $this->check_option() === false ) {
96 add_option( 'shoppress_message', true );
97 }
98
99 if ( $this->check_option_pro() === false ) {
100 add_option( 'shoppress_message_pro', true );
101 }
102 }
103
104 /**
105 * Check shoppress_message option.
106 *
107 * @since 1.0.0
108 */
109 private function check_option() {
110 $option = get_option( 'shoppress_message' );
111
112 if ( $option ) {
113 return true;
114 }
115
116 return false;
117 }
118
119 /**
120 * Check shoppress_message_pro option.
121 *
122 * @since 1.0.0
123 */
124 private function check_option_pro() {
125 $option = get_option( 'shoppress_message_pro' );
126
127 if ( $option ) {
128 return true;
129 }
130
131 return false;
132 }
133
134 /**
135 * Check current page.
136 *
137 * @since 1.0.0
138 */
139 private function check_current_page() {
140 $screen = get_current_screen();
141
142 if ( $screen->id == 'dashboard' || $screen->id == 'themes' || $screen->id == 'plugins' || $screen->id == 'toplevel_page_shoppress' ) {
143 return true;
144 }
145
146 return false;
147 }
148
149 /**
150 * Check if both WooCommerce and Elementor are installed.
151 *
152 * @since 1.0.0
153 */
154 private function check_installed_plugins() {
155
156 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
157 require_once ABSPATH . '/wp-admin/includes/plugin.php';
158 }
159
160 return ( in_array( 'woocommerce/woocommerce.php', (array) get_option( 'active_plugins', array() ), true ) || is_plugin_active_for_network( 'woocommerce/woocommerce.php' ) );
161 }
162
163 /**
164 * Returns elementor install or activate link.
165 *
166 * @since 1.0.0
167 */
168 private function get_elementor_link() {
169 $link = '';
170
171 if ( file_exists( WP_PLUGIN_DIR . '/elementor/elementor.php' ) ) {
172 $link = wp_nonce_url( 'plugins.php?action=activate&plugin=elementor/elementor.php&plugin_status=all&paged=1', 'activate-plugin_elementor/elementor.php' );
173 } else {
174 $link = wp_nonce_url( 'update.php?action=install-plugin&plugin=elementor', 'install-plugin_elementor' );
175 }
176
177 return $link;
178 }
179
180 /**
181 * Returns WooCommerce install or activate link.
182 *
183 * @since 1.0.0
184 */
185 private function get_woocommerce_link() {
186 $link = '';
187
188 if ( file_exists( WP_PLUGIN_DIR . '/woocommerce/woocommerce.php' ) ) {
189 $link = wp_nonce_url( 'plugins.php?action=activate&plugin=woocommerce/woocommerce.php&plugin_status=all&paged=1', 'activate-plugin_woocommerce/woocommerce.php' );
190 } else {
191 $link = wp_nonce_url( 'update.php?action=install-plugin&plugin=woocommerce', 'install-plugin_woocommerce' );
192 }
193
194 return $link;
195 }
196
197 /**
198 * Message content.
199 *
200 * @since 1.0.0
201 */
202 public function message_content() {
203
204 if ( ! $this->check_current_page() || $this->check_option() === false ) {
205 return;
206 }
207 ?>
208
209 <div class="shoppress-plugin-requires sp-message" data-message="plugins">
210 <div class="box-img">
211 <img src="<?php echo esc_url( SHOPPRESS_URL ); ?>public/images/logo/ic_shoppress.svg"
212 alt="Get Plugin Requires"/>
213 </div>
214 <div class="box-content">
215 <div>
216 <h3>Recommended Plugins</h3>
217 <p>The <b>ShopPress</b> plugin requires installation of WooCommerce first.</p>
218 <div class="box-install">
219 <?php if ( ! class_exists( 'WooCommerce' ) ) : ?>
220 <a href="<?php echo esc_url( $this->get_woocommerce_link() ); ?>">Install WooCommerce</a>
221 <?php endif; ?>
222 </div>
223 </div>
224 </div>
225 <button type="button" class="notice-dismiss sp-message-close">
226 </button>
227 </div>
228
229 <?php
230 }
231
232 /**
233 * Go Pro message content.
234 *
235 * @since 1.0.0
236 */
237 public function go_pro_message_content() {
238
239 if ( ! $this->check_current_page() || $this->check_option_pro() === false ) {
240 return;
241 }
242
243 ?>
244 <div class="shoppress-plugin-requires sp-go-pro" data-message="pro">
245 <div class="box-img">
246 <img src="<?php echo esc_url( SHOPPRESS_URL ); ?>public/images/logo/ic_shoppress.svg"
247 alt="Get ShopPress by upgrading to Pro version"/>
248 </div>
249 <div class="box-content">
250 <div>
251 <h3>Unlock all the Powerful Features</h3>
252 <p>Get full access to all advanced features of ShopPress by upgrading to Pro version right away.</p>
253 <div class="box-install">
254 <a href="https://webnus.net/shoppress/">Go Premium</a>
255 </div>
256 </div>
257 </div>
258 <button type="button" class="notice-dismiss sp-pro-close">
259 </button>
260 </div>
261 <?php
262 }
263
264 /**
265 * Update shoppress_message option.
266 *
267 * @since 1.0.0
268 */
269 public function shoppress_admin_message() {
270 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'shoppress_message' ) ) {
271 die( 'Wrong nonce!' );
272 }
273
274 $msgData = isset( $_POST['msgData'] ) ? sanitize_text_field( wp_unslash( $_POST['msgData'] ) ) : '';
275 $msgPro = isset( $_POST['msgPro'] ) ? sanitize_text_field( wp_unslash( $_POST['msgPro'] ) ) : '';
276
277 if ( $msgData === 'plugins' ) {
278 update_option( 'shoppress_message', false );
279 }
280
281 if ( $msgPro === 'pro' ) {
282 update_option( 'shoppress_message_pro', false );
283 }
284
285 wp_die();
286 }
287 }
288