· 6 years ago · Nov 14, 2019, 09:00 AM
1<?php
2/*
3 * Plugin Name: MyThemeShop Theme & Plugin Updater
4 * Plugin URI: https://mythemeshop.com
5 * Description: Update MyThemeShop themes & plugins, get news & exclusive offers right from your WordPress dashboard.
6 * Version: 2.0.17
7 * Author: MyThemeShop
8 * Author URI: https://mythemeshop.com
9 * License: GPLv2
10 */
11
12defined('ABSPATH') or die;
13
14class mts_connection {
15 const PLUGIN_VERSION = '2.0.17';
16 /* private $api_url = "https://mythemeshop.com/mtsapi/v1/"; */
17
18 private $settings_option = "mts_connect_settings";
19 private $data_option = "mts_connect_data";
20 private $notices_option = "mts_connect_notices";
21 private $dismissed_meta = "mts_connect_dismissed_notices";
22
23 protected $connect_data = array();
24 protected $notices = array();
25 protected $sticky_notices = array();
26 protected $settings = array();
27 protected $default_settings = array('network_notices' => '1', 'update_notices' => '1', 'ui_access_type' => 'role', 'ui_access_role' => 'administrator', 'ui_access_user' => '');
28 protected $notice_defaults = array();
29 protected $notice_tags = array();
30 protected $mts_theme_in_use = false;
31 protected $mts_plugins_in_use = 0;
32 protected $custom_admin_messages = array();
33 protected $ngmsg = '';
34 protected $plugin_file = '';
35
36 function __construct() {
37 define( 'MTS_CONNECT_ACTIVE', true );
38
39 $this->connect_data = $this->get_data();
40 $this->sticky_notices = $this->get_notices();
41 $this->settings = $this->get_settings();
42
43 $this->plugin_file = 'mythemeshop-connect/mythemeshop-connect.php';
44
45 // Notices default options
46 $this->notice_defaults = array(
47 'content' => '',
48 'class' => 'updated',
49 'priority' => 10,
50 'sticky' => false,
51 'date' => time(),
52 'expire' => time() + 7 * DAY_IN_SECONDS,
53 'context' => array()
54 );
55
56 $connected = true;
57
58 add_action( 'admin_init', array( $this, 'admin_init' ) );
59 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
60 add_action( 'init', array( $this, 'init' ) );
61 //add_action( 'admin_print_scripts', array($this, 'admin_inline_js'));
62
63 add_action( 'load-themes.php', array( $this, 'force_check' ), 9);
64 add_action( 'load-plugins.php', array( $this, 'force_check' ), 9);
65 add_action( 'load-update-core.php', array( $this, 'force_check' ), 9);
66
67 // show notices
68 if (is_multisite())
69 add_action( 'network_admin_notices', array($this, 'show_notices'));
70 else
71 add_action( 'admin_notices', array($this, 'show_notices'));
72
73 // user has dismissed a notice?
74 add_action( 'admin_init', array($this, 'dismiss_notices'));
75 // add menu item
76 if (is_multisite())
77 add_action( 'network_admin_menu', array($this, 'admin_menu'));
78 else
79 add_action( 'admin_menu', array($this, 'admin_menu'));
80 // remove old notifications
81 add_action( 'after_setup_theme', array($this, 'after_theme') );
82
83 add_filter( 'nhp-opts-sections', '__return_empty_array', 9, 1 );
84 add_action( 'admin_menu', array( $this, 'replace_admin_pages' ), 99 );
85
86 add_action('wp_ajax_mts_connect',array($this,'ajax_mts_connect'));
87 add_action('wp_ajax_mts_connect_update_settings',array($this,'ajax_update_settings'));
88 add_action('wp_ajax_mts_connect_dismiss_notice',array($this,'ajax_mts_connect_dismiss_notices'));
89 add_action('wp_ajax_mts_connect_check_themes',array($this,'ajax_mts_connect_check_themes'));
90 add_action('wp_ajax_mts_connect_check_plugins',array($this,'ajax_mts_connect_check_plugins'));
91 add_action('wp_ajax_mts_connect_reset_notices',array($this,'ajax_mts_connect_reset_notices'));
92
93 add_filter( 'pre_set_site_transient_update_themes', array( $this,'check_theme_updates' ));
94 add_filter( 'pre_set_site_transient_update_plugins', array( $this,'check_plugin_updates' ));
95
96 if ( $connected ) {
97 remove_filter( 'nhp-opts-sections', '__return_empty_array', 9 );
98 remove_action( 'admin_menu', array( $this, 'replace_admin_pages' ), 99 );
99 }
100
101 // Fix false wordpress.org update notifications
102 add_filter( 'pre_set_site_transient_update_themes', array($this,'fix_false_wp_org_theme_update_notification') );
103 //add_filter( 'pre_set_site_transient_update_plugins', array($this,'fix_false_wp_org_plugin_update_notification') );
104
105 register_activation_hook( __FILE__, array($this, 'plugin_activated' ));
106 register_deactivation_hook( __FILE__, array($this, 'plugin_deactivated' ));
107
108 // localization
109 add_action( 'plugins_loaded', array( $this, 'mythemeshop_connect_load_textdomain' ) );
110
111 // Override plugin info page with changelog
112 add_action('install_plugins_pre_plugin-information', array( $this, 'install_plugin_information' ));
113
114 add_action( 'load-plugins.php', array( $this, 'brand_updates_table' ), 21 );
115 add_action( 'core_upgrade_preamble', array( $this, 'brand_updates_page' ), 21 );
116
117 add_action( 'admin_print_scripts-plugins.php', array( $this, 'updates_table_custom_js' ) );
118
119 add_filter( 'wp_prepare_themes_for_js', array( $this, 'brand_theme_updates' ), 21 );
120
121 add_filter( 'plugins_loaded', array( $this, 'check_for_mts_plugins' ), 11 );
122 add_filter( 'after_setup_theme', array( $this, 'check_for_mts_theme' ), 11 );
123 add_filter( 'after_switch_theme', array( $this, 'clear_theme_check' ), 11 );
124
125 add_action( 'after_plugin_row_'.$this->plugin_file, array( $this, 'plugin_row_deactivate_notice' ), 10, 2 );
126
127 $this->ngmsg = $this->str_convert('596F75 206E65656420746F20 3C6120687265663D225B70 6C7567696E5F757 26C5D223E636F6E6E6563742 0776974 6820796F7572204D795468656D65536 86F70206163 636F756E743C2F613E2074 6F207573652 07468652063757272 656E74207468656D652 06F7220706C7567696E2E');
128
129 add_action( 'current_screen', array( $this, 'add_reminder' ), 10, 1 );
130
131 add_action( 'plugins_loaded', array( $this, 'load_connector' ), 9 );
132
133 if ( empty( $this->connect_data['connected'] ) ) {
134 add_filter( 'nhp-opts-sections', array( $this, 'nhp_sections' ), 10, 1 );
135 add_filter( 'nhp-opts-args', array( $this, 'nhp_opts' ), 10, 1 );
136 add_filter( 'nhp-opts-extra-tabs', '__return_empty_array', 11, 1 );
137 }
138
139 add_action( 'init', array( $this, 'set_theme_defaults' ), -11, 1 );
140 }
141
142 public function set_theme_defaults() {
143 if ( defined( 'MTS_THEME_NAME' ) ) {
144 if ( ! get_option( MTS_THEME_NAME, false ) ) {
145 remove_filter( 'nhp-opts-sections', '__return_empty_array', 9 );
146 remove_filter( 'nhp-opts-sections', array( $this, 'nhp_sections' ), 10 );
147 }
148 }
149 }
150
151 public function plugin_activated(){
152 update_site_option( 'mts__thl', '' );
153 update_site_option( 'mts__pl', '' );
154 $this->update_themes_now();
155 $this->update_plugins_now();
156 }
157
158 public function plugin_deactivated(){
159 $this->reset_notices(); // todo: reset for all admins
160 $this->disconnect();
161 do_action( 'mts_connect_deactivate' );
162 }
163
164 function mythemeshop_connect_load_textdomain() {
165 load_plugin_textdomain( 'mythemeshop-connect', false, dirname( plugin_basename( __FILE__ ) ) . '/language/' );
166 }
167
168 function ajax_mts_connect_dismiss_notices() {
169 if (!empty($_POST['ids']) && is_array($_POST['ids'])) {
170 foreach ($_POST['ids'] as $id) {
171 $this->dismiss_notice($id);
172 }
173 }
174 exit;
175 }
176 function ajax_mts_connect_check_themes() {
177 $this->update_themes_now();
178 $transient = get_site_transient( 'mts_update_themes' );
179 if (is_object($transient) && isset($transient->response)) {
180 echo count($transient->response);
181 } else {
182 echo '0';
183 }
184
185 exit;
186 }
187
188 function ajax_mts_connect_reset_notices() {
189 $this->reset_notices();
190
191 exit;
192 }
193
194 function ajax_mts_connect_check_plugins() {
195 $this->update_plugins_now();
196 $transient = get_site_transient( 'mts_update_plugins' );
197 if (is_object($transient) && isset($transient->response)) {
198 echo count($transient->response);
199 } else {
200 echo '0';
201 }
202
203 exit;
204 }
205 function ajax_mts_connect() {
206 header("Content-type: application/json");
207 $username = isset($_POST['username']) ? $_POST['username'] : '';
208 $password = isset($_POST['password']) ? $_POST['password'] : '';
209
210 $response = wp_remote_post(
211 $this->api_url . 'get_key',
212 array( 'body' => array( 'user' => $username, 'pass' => $password ), 'timeout' => 10 )
213 );
214
215 if ( is_wp_error( $response ) ) {
216 $error_message = $response->get_error_message();
217 echo json_encode( array( 'status' => 'fail', 'errors' => array($error_message) ) );
218 } else {
219 echo $response['body']; // should be JSON already
220
221 $data = json_decode($response['body'], true);
222 if ( isset( $data['login'] ) ) {
223 $this->reset_notices();
224 $this->connect_data['username'] = $data['login'];
225 $this->connect_data['api_key'] = $data['key'];
226 $this->connect_data['connected'] = true;
227 $this->update_data();
228 }
229 // notices
230 if (isset($data['notices']) && is_array($data['notices'])) {
231 foreach($data['notices'] as $notice) {
232 if (!empty($notice['network_notice'])) {
233 $this->add_network_notice((array) $notice);
234 } else {
235 $this->add_sticky_notice((array) $notice);
236 }
237 }
238 }
239 }
240 exit;
241 }
242
243 function disconnect() {
244 $this->connect_data['username'] = '';
245 $this->connect_data['api_key'] = '';
246 $this->connect_data['connected'] = false;
247 $this->update_data();
248
249 // remove theme updates for mts themes in transient by searching through 'packages' properties for 'mythemeshop'
250 $transient = get_site_transient( 'update_themes' );
251 delete_site_transient( 'mts_update_themes' );
252 delete_site_transient( 'mts_update_themes_no_access' );
253 if ( $transient && !empty($transient->response) ) {
254 foreach ($transient->response as $theme => $data) {
255 if (strstr($data['package'], 'mythemeshop') !== false) {
256 unset($transient->response[$theme]);
257 }
258 }
259 set_site_transient('update_themes', $transient);
260 }
261 $transient = get_site_transient( 'update_plugins' );
262 delete_site_transient( 'mts_update_plugins' );
263 delete_site_transient( 'mts_update_plugins_no_access' );
264 if ( $transient && !empty($transient->response) ) {
265 foreach ($transient->response as $plugin => $data) {
266 if (strstr($data->package, 'mythemeshop') !== false) {
267 unset($transient->response[$plugin]);
268 }
269 }
270 set_site_transient('update_plugins', $transient);
271 }
272 $this->reset_notices();
273 }
274
275 function reset_notices() {
276 $notices = $this->notices + $this->sticky_notices;
277 foreach ($notices as $id => $notice) {
278 $this->remove_notice( $id );
279 $this->undismiss_notice( $id );
280 }
281 }
282
283 function admin_menu() {
284 global $current_user;
285 $user_id = $current_user->ID;
286
287 $ui_access_type = $this->settings['ui_access_type'];
288 $ui_access_role = $this->settings['ui_access_role'];
289 $ui_access_user = $this->settings['ui_access_user'];
290
291 $admin_page_role = 'manage_options';
292 $allow_admin_access = false;
293 if ( $ui_access_type == 'role' ) {
294 $allow_admin_access = current_user_can( $ui_access_role );
295 } else { // ui_access_type = user (IDs)
296 $allow_admin_access = in_array( $user_id, array_map('absint', explode( ',', $ui_access_user ) ) );
297 }
298
299 $allow_admin_access = apply_filters( 'mts_connect_admin_access', $allow_admin_access );
300
301 if ( ! $allow_admin_access ) {
302 return;
303 }
304
305 // Add the new admin menu and page and save the returned hook suffix
306 $this->menu_hook_suffix = add_menu_page('MyThemeShop Theme & Plugin Updater', 'MyThemeShop', $admin_page_role, 'mts-connect', array( $this, 'show_ui' ), 'dashicons-update', 66 );
307 // Use the hook suffix to compose the hook and register an action executed when plugin's options page is loaded
308 add_action( 'load-' . $this->menu_hook_suffix , array( $this, 'ui_onload' ) );
309
310 }
311
312 function init() {
313 define( 'MTS_THEME_T', 'mts'.'the' );
314 }
315
316 function admin_init() {
317 $connected = ( ! empty( $this->connect_data['connected'] ) && empty( $_GET['disconnect'] ) );
318
319 $updates_available = $this->new_updates_available();
320
321 $current_user = wp_get_current_user();
322 // Tags to use in notifications
323 $this->notice_tags = array(
324 '[logo_url]' => plugins_url( 'img/mythemeshop-logo.png' , __FILE__ ),
325 '[plugin_url]' => network_admin_url('admin.php?page=mts-connect'),
326 '[themes_url]' => network_admin_url('themes.php'),
327 '[plugins_url]' => network_admin_url('plugins.php'),
328 '[updates_url]' => network_admin_url('update-core.php'),
329 '[site_url]' => site_url(),
330 '[user_firstname]' => $current_user->first_name
331 );
332
333 // Fix for false wordpress.org update notifications
334 // If wrong updates are already shown, delete transients
335 if ( false === get_site_option( 'mts_wp_org_updates_disabled' ) ) { // check only once
336 update_site_option( 'mts_wp_org_updates_disabled', 'disabled' );
337
338 delete_site_transient( 'update_themes' );
339 delete_site_transient( 'update_plugins' );
340 }
341 }
342
343 function admin_enqueue_scripts( $hook_suffix ) {
344 wp_register_script( 'mts-connect', plugins_url('/js/admin.js', __FILE__ ), array('jquery'), $this->plugin_get_version() );
345 wp_register_script( 'mts-connect-form', plugins_url('/js/connect.js', __FILE__), array('jquery'), $this->plugin_get_version() );
346 wp_register_style( 'mts-connect', plugins_url('/css/admin.css', __FILE__ ), array(), $this->plugin_get_version() );
347 wp_register_style( 'mts-connect-form', plugins_url('/css/form.css', __FILE__ ), array(), $this->plugin_get_version() );
348
349 $connected = ( ! empty( $this->connect_data['connected'] ) && empty( $_GET['disconnect'] ) );
350
351 $updates_available = $this->new_updates_available();
352 $using_mts_products = ( $this->mts_plugins_in_use || $this->mts_theme_in_use );
353 $icon_class_attr = 'disconnected';
354 if ( $connected ) {
355 $icon_class_attr = 'connected';
356 if ( $updates_available ) {
357 //$icon_class_attr = 'updates-available'; // yellow
358 $icon_class_attr = 'disconnected'; // red
359 }
360 }
361
362 wp_localize_script('mts-connect', 'mtsconnect', array(
363 'pluginurl' => network_admin_url('admin.php?page=mts-connect'),
364 'icon_class_attr' => $icon_class_attr,
365 'check_themes_url' => network_admin_url('themes.php?force-check=1'),
366 'check_plugins_url' => network_admin_url('plugins.php?force-check=1'),
367 'using_mts_products' => $using_mts_products,
368 'l10n_ajax_login_success' => __('<p>Login successful! Checking for theme updates...</p>', 'mythemeshop-connect'),
369 'l10n_ajax_theme_check_done' => __('<p>Theme check done. Checking plugins...</p>', 'mythemeshop-connect'),
370 'l10n_ajax_refreshing' => __('<p>Refreshing page...</p>', 'mythemeshop-connect'),
371 'l10n_ajax_plugin_check_done' => __('<p>Plugin check done.</p>', 'mythemeshop-connect'),
372 'l10n_check_themes_button' => __('Check for updates now', 'mythemeshop-connect'),
373 'l10n_check_plugins_button' => __('Check for updates now', 'mythemeshop-connect'),
374 'l10n_insert_username' => __('Please insert your MyThemeShop <strong>username</strong> instead of the email address you registered with.', 'mythemeshop-connect'),
375 'l10n_accept_tos' => __('Please accept the terms to connect.', 'mythemeshop-connect'),
376 'l10n_confirm_deactivate' => __('You have a currently active MyThemeShop theme or plugin on this site. If you deactivate this required plugin, other MyThemeShop products may not function correctly and they may be automatically deactivated.', 'mythemeshop-connect'),
377 'l10n_ajax_unknown_error' => __('An unknown error occured. Please get in touch with MyThemeShop support team.', 'mythemeshop-connect'),
378 ) );
379
380 // Enqueue on all admin pages because notice may appear anywhere
381 wp_enqueue_script( 'mts-connect' );
382 wp_enqueue_style( 'mts-connect' );
383
384 if ( $hook_suffix == 'toplevel_page_mts-connect' ) {
385 wp_enqueue_script('mts-connect-form');
386 wp_enqueue_style('mts-connect-form');
387 }
388 }
389
390 function force_check() {
391 if (isset($_GET['force-check']) && $_GET['force-check'] == 1) {
392 $screen = get_current_screen();
393 switch ($screen->id) {
394 case 'themes':
395 case 'themes-network':
396 $this->update_themes_now();
397 break;
398
399 case 'plugins':
400 case 'plugins-network':
401 $this->update_plugins_now();
402 break;
403
404 case 'update-core':
405 case 'network-update-core':
406 $this->update_themes_now();
407 $this->update_plugins_now();
408 break;
409 }
410 }
411 }
412
413 function update_themes_now() {
414 if ( $transient = get_site_transient( 'update_themes' ) ) {
415 delete_site_transient( 'mts_update_themes' );
416 delete_site_transient( 'mts_update_themes_no_access' );
417 set_site_transient('update_themes', $transient);
418 }
419 }
420 function update_plugins_now() {
421 if ( $transient = get_site_transient( 'update_plugins' ) ) {
422 delete_site_transient( 'mts_update_plugins' );
423 delete_site_transient( 'mts_update_plugins_no_access' );
424 set_site_transient('update_plugins', $transient);
425 }
426 }
427
428 function plugin_get_version() {
429 return self::PLUGIN_VERSION;
430 }
431
432 function check_theme_updates( $update_transient ){
433 global $wp_version;
434
435 if ( !isset($update_transient->checked) )
436 return $update_transient;
437 else
438 $themes = $update_transient->checked;
439
440 if ( ! empty( $_GET['disconnect'] ) ) {
441 return $update_transient;
442 }
443
444 // New 'mts_' folder structure
445 $folders_fix = array();
446 foreach ($themes as $theme => $version) {
447 // Skip selected themes
448 if ( ! apply_filters( 'mts_connect_update_theme_' . $theme, true, $version ) ) {
449 unset( $themes[$theme] );
450 continue;
451 }
452
453 if ( $theme == 'sociallyviral' && ! in_array( 'sociallyviral', $folders_fix ) ) {
454 // SociallyViral free - exclude from API check
455 unset( $themes[$theme] );
456 continue;
457 }
458
459 if (stripos($theme, 'mts_') === 0) {
460 $themes[str_replace('mts_', '', $theme)] = $version;
461 $folders_fix[] = str_replace('mts_', '', $theme);
462 unset($themes[$theme]);
463 }
464 }
465
466 $mts_updates = get_site_transient('mts_update_themes');
467 if ( ! $this->needs_check_now( $mts_updates ) ) {
468 // Add themes from our transient
469 if ( isset( $mts_updates->response ) ) {
470 foreach ( $mts_updates->response as $theme => $data ) {
471 $folder_fix_theme = str_replace('mts_', '', $theme);
472 if ( array_key_exists( $folder_fix_theme, $themes ) && isset( $data['new_version'] ) && version_compare( $themes[ $folder_fix_theme ], $data['new_version'], '<' ) ) {
473 $update_transient->response[ $theme ] = $data;
474 }
475 }
476 }
477 return $update_transient;
478 }
479
480 $sites_themes = array();
481 if ( is_multisite() ) {
482 // get list of sites using this theme
483 $sites = get_sites();
484 foreach ( $sites as $i => $site_obj ) {
485 $siteurl = $site_obj->siteurl;
486 switch_to_blog( $site_obj->blog_id );
487 $theme = get_template();
488 restore_current_blog();
489
490 $sites_themes[$siteurl] = $theme;
491 }
492 }
493
494 $r = 'check_themes';
495 $send_to_api = array(
496 'themes' => $themes,
497 'prefixed' => $folders_fix,
498 'info' => array(
499 'url' => home_url(),
500 'multisite' => is_multisite(),
501 'sites' => $sites_themes,
502 'php_version' => phpversion(),
503 'wp_version' => $wp_version,
504 'plugin_version' => $this->plugin_get_version()
505 )
506 );
507
508 // is connected
509 if ( $this->is_connected() ) {
510 $send_to_api['user'] = $this->connect_data['username'];
511 $send_to_api['key'] = $this->connect_data['api_key'];
512 } else {
513 $r = 'guest/'.$r;
514 }
515
516 $options = array(
517 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 10),
518 'body' => $send_to_api
519 );
520
521 $last_update = new stdClass();
522 $no_access = new stdClass();
523 $theme_request = wp_remote_post( $this->api_url.$r, $options );
524
525 if ( ! is_wp_error( $theme_request ) && wp_remote_retrieve_response_code( $theme_request ) == 200 ) {
526 $theme_response = json_decode( wp_remote_retrieve_body( $theme_request ), true );
527
528 if ( ! empty( $theme_response ) ) {
529 if ( ! empty( $theme_response['themes'] )) {
530 if ( empty( $update_transient->response ) ) $update_transient->response = array();
531 $update_transient->response = array_merge( (array) $update_transient->response, (array) $theme_response['themes'] );
532 }
533 $last_update->checked = $themes;
534
535 if ( ! empty( $theme_response['themes'] ) ) {
536 $last_update->response = $theme_response['themes'];
537 } else {
538 $last_update->response = array();
539 }
540
541 if ( ! empty( $theme_response['themes_no_access'] ) ) {
542 $no_access->response = $theme_response['themes_no_access'];
543 } else {
544 $no_access->response = array();
545 }
546
547 if (!empty($theme_response['notices'])) {
548 foreach ($theme_response['notices'] as $notice) {
549 if (!empty($notice['network_notice'])) {
550 $this->add_network_notice((array) $notice);
551 } else {
552 $this->add_sticky_notice((array) $notice);
553 }
554 }
555 }
556
557 if (!empty($theme_response['disconnect'])) $this->disconnect();
558 }
559 }
560
561 $last_update->last_checked = time();
562 set_site_transient( 'mts_update_themes', $last_update );
563 set_site_transient( 'mts_update_themes_no_access', $no_access );
564
565 return $update_transient;
566 }
567
568 function check_plugin_updates( $update_transient ){
569 global $wp_version;
570
571 if ( !isset($update_transient->checked) )
572 return $update_transient;
573 else
574 $plugins = $update_transient->checked;
575
576 unset( $plugins['seo-by-rank-math/rank-math.php'] );
577 unset( $plugins['seo-by-rank-math-pro/rank-math-pro.php'] );
578
579 $mts_updates = get_site_transient('mts_update_plugins');
580 if ( ! $this->needs_check_now( $mts_updates ) ) {
581 // Add plugins from our transient
582 if ( isset( $mts_updates->response ) ) {
583 foreach ( $mts_updates->response as $plugin => $data ) {
584 if ( array_key_exists( $plugin, $plugins ) && isset( $data->new_version ) && version_compare( $plugins[ $plugin ], $data->new_version, '<' ) ) {
585 $update_transient->response[ $plugin ] = $data;
586 }
587 }
588 }
589 return $update_transient;
590 }
591
592 if ( ! empty( $_GET['disconnect'] ) ) {
593 return $update_transient;
594 }
595
596 $sites_plugins = array();
597 if ( is_multisite() ) {
598 // get list of sites using this theme
599 $sites = get_sites();
600 $_network_active_plugins = wp_get_active_network_plugins();
601 $network_active_plugins = array();
602 foreach ( $_network_active_plugins as $plugin ) {
603 $network_active_plugins[] = basename( dirname( $plugin ) ) . '/' . basename( $plugin );
604 }
605 foreach ( $sites as $i => $site_obj ) {
606 $siteurl = $site_obj->siteurl;
607 switch_to_blog( $site_obj->blog_id );
608 //$_plugins = get_option('active_plugins');
609 $_plugins = get_option('active_plugins');
610 $site_plugins = array();
611 foreach ( (array) $_plugins as $plugin ) {
612 $site_plugins[] = $plugin;
613 }
614 restore_current_blog();
615
616 $sites_plugins[$siteurl] = array_merge( $network_active_plugins, $site_plugins );
617 }
618 }
619
620 foreach ( $plugins as $plugin_file => $plugin_version ) {
621 // Skip selected plugins
622 if ( ! apply_filters( 'mts_connect_update_plugin_' . $plugin_file, true, $plugin_version ) ) {
623 unset( $plugins[ $plugin_file ] );
624 continue;
625 }
626 }
627
628 $r = 'check_plugins';
629 $send_to_api = array(
630 'plugins' => $plugins,
631 'info' => array(
632 'url' => is_multisite() ? network_site_url() : home_url(),
633 'multisite' => is_multisite(),
634 'sites' => $sites_plugins,
635 'php_version' => phpversion(),
636 'wp_version' => $wp_version,
637 'plugin_version' => $this->plugin_get_version()
638 )
639 );
640
641 // is connected
642 if ($this->is_connected()) {
643 $send_to_api['user'] = $this->connect_data['username'];
644 $send_to_api['key'] = $this->connect_data['api_key'];
645 } else {
646 $r = 'guest/'.$r;
647 }
648
649 $options = array(
650 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 10),
651 'body' => $send_to_api
652 );
653
654 $last_update = new stdClass();
655 $no_access = new stdClass();
656 $plugin_request = wp_remote_post( $this->api_url.$r, $options );
657
658 if ( ! is_wp_error( $plugin_request ) && wp_remote_retrieve_response_code( $plugin_request ) == 200 ){
659 $plugin_response = json_decode( wp_remote_retrieve_body( $plugin_request ), true );
660
661 if ( ! empty( $plugin_response ) ) {
662 if ( ! empty( $plugin_response['plugins'] )) {
663 if ( empty( $update_transient->response ) ) $update_transient->response = array();
664
665 // array to object
666 $new_arr = array();
667 foreach ($plugin_response['plugins'] as $pluginname => $plugindata) {
668 $object = new stdClass();
669 foreach ($plugindata as $k => $v) {
670 $object->$k = $v;
671 }
672 $new_arr[$pluginname] = $object;
673 }
674 $plugin_response['plugins'] = $new_arr;
675
676 $update_transient->response = array_merge( (array) $update_transient->response, (array) $plugin_response['plugins'] );
677 }
678
679 $last_update->checked = $plugins;
680
681 if (!empty($plugin_response['plugins'])) {
682 $last_update->response = $plugin_response['plugins'];
683 } else {
684 $last_update->response = array();
685 }
686
687 if ( ! empty( $plugin_response['plugins_no_access'] ) ) {
688 $no_access->response = $plugin_response['plugins_no_access'];
689 } else {
690 $no_access->response = array();
691 }
692
693 if (!empty($plugin_response['notices'])) {
694 foreach ($plugin_response['notices'] as $notice) {
695 if (!empty($notice['network_notice'])) {
696 $this->add_network_notice((array) $notice);
697 } else {
698 $this->add_sticky_notice((array) $notice);
699 }
700 }
701 }
702
703 if (!empty($plugin_response['disconnect'])) $this->disconnect();
704 }
705 }
706
707 $last_update->last_checked = time();
708 set_site_transient( 'mts_update_plugins', $last_update );
709 set_site_transient( 'mts_update_plugins_no_access', $no_access );
710
711 return $update_transient;
712 }
713
714 function needs_check_now( $updates_data ) {
715 return apply_filters( 'mts_connect_needs_check', true, $updates_data );
716 }
717
718 function ui_onload() {
719 if (isset($_GET['disconnect']) && $_GET['disconnect'] == 1) {
720 $this->disconnect();
721 $this->add_notice(array('content' => __('Disconnected.', 'mythemeshop-connect'), 'class' => 'error'));
722 }
723 if (isset($_GET['reset_notices']) && $_GET['reset_notices'] == 1) {
724 $this->reset_notices();
725 $this->add_notice(array('content' => __('Notices reset.', 'mythemeshop-connect')));
726 }
727 if ( isset( $_GET['mts_changelog'] ) ) {
728 $mts_changelog = $_GET['mts_changelog'];
729 $transient = get_site_transient( 'mts_update_plugins' );
730 if (is_object($transient) && !empty($transient->response)) {
731 foreach ($transient->response as $plugin_path => $data) {
732 if (stristr($plugin_path, $mts_changelog) !== false) {
733 $content = wp_remote_get( $data->changelog );
734 echo $content['body'];
735 die();
736 }
737 }
738 }
739 $ttransient = get_site_transient( 'mts_update_themes' );
740 if (is_object($ttransient) && !empty($ttransient->response)) {
741 foreach ($ttransient->response as $slug => $data) {
742 if ( $slug === $mts_changelog ) {
743 $content = wp_remote_get( $data['changelog'] );
744 echo wp_remote_retrieve_body( $content );
745 die();
746 }
747 }
748 }
749 }
750 }
751
752 public function show_ui() {
753 $updates_required = false;
754 $theme_updates_required = false;
755 $plugin_updates_required = false;
756
757 $themes_transient = get_site_transient( 'mts_update_themes' );
758 $plugins_transient = get_site_transient( 'mts_update_plugins' );
759
760 $themes_noaccess_transient = get_site_transient( 'mts_update_themes_no_access' );
761 $plugins_noaccess_transient = get_site_transient( 'mts_update_plugins_no_access' );
762
763 $available_theme_updates = $this->new_updates_available( $themes_transient );
764 $available_plugins_updates = $this->new_updates_available( $plugins_transient );
765
766 $inaccessible_theme_updates = $this->new_updates_available( $themes_noaccess_transient );
767 $inaccessible_plugins_updates = $this->new_updates_available( $plugins_noaccess_transient );
768
769 if ( $available_theme_updates || $available_plugins_updates || $inaccessible_theme_updates || $inaccessible_plugins_updates ) {
770 $updates_required = true;
771 if ( $available_theme_updates || $inaccessible_theme_updates ) {
772 $theme_updates_required = true;
773 }
774 if ( $available_plugins_updates || $inaccessible_plugins_updates ) {
775 $plugin_updates_required = true;
776 }
777 }
778
779 ?>
780 <div class="mts_connect_ui_content">
781 <nav class="nav-tab-wrapper" id="mtsc-nav-tab-wrapper">
782 <a href="#mtsc-connect" class="nav-tab nav-tab-active">Connect</a>
783 <a href="#mtsc-settings" class="nav-tab">Settings</a>
784 </nav>
785 <div id="mtsc-tabs">
786 <div id="mtsc-connect">
787 <?php if ( ! $this->is_connected() ) { ?>
788 <?php $this->connect_form_html(); ?>
789 <?php } else { ?>
790 <div id="mtsc-connected">
791 <?php $this->logo_html(); ?>
792
793 <div class="mtsc-updates-status">
794 <?php if ( $updates_required ) { ?>
795 <div class="mtsc-status-icon mtsc-icon-updates-required">
796 <span class="dashicons dashicons-no-alt"></span>
797 </div>
798 <div class="mtsc-status-text">
799 <?php if ( $theme_updates_required && $plugin_updates_required ) { ?>
800 <p><?php printf( __('Your themes and plugins are outdated. Please navigate to %s to get the latest versions.', 'mythemeshop-connect'), '<a href="'.network_admin_url( 'update-core.php' ).'">'.__( 'the Updates page', 'mythemeshop-connect' ).'</a>' ); ?></p>
801 <?php } elseif ( $theme_updates_required ) { ?>
802 <p><?php printf( __('One or more themes are outdated. Please navigate to %s to get the latest versions.', 'mythemeshop-connect'), '<a href="'.network_admin_url( 'update-core.php' ).'">'.__( 'the Updates page', 'mythemeshop-connect' ).'</a>' ); ?></p>
803 <?php } elseif ( $plugin_updates_required ) { ?>
804 <p><?php printf( __('One or more plugins are outdated. Please navigate to %s to get the latest versions.', 'mythemeshop-connect'), '<a href="'.network_admin_url( 'update-core.php' ).'">'.__( 'the Updates page', 'mythemeshop-connect' ).'</a>' ); ?></p>
805 <?php } ?>
806 </div>
807 <?php } else { ?>
808 <div class="mtsc-status-icon mtsc-icon-no-updates-required">
809 <span class="dashicons dashicons-yes"></span>
810 </div>
811 <div class="mtsc-status-text">
812 <p><?php _e('Your themes and plugins are up to date.', 'mythemeshop-connect'); ?></p>
813 </div>
814 <?php } ?>
815 </div>
816
817 <div class="mtsc-connected-msg">
818 <span class="mtsc-connected-msg-connected">
819 <?php _e('Connected', 'mythemeshop-connect'); ?>
820 </span>
821 <span class="mtsc-connected-msg-username">
822 <?php printf( __( 'MyThemeShop username: %s', 'mythemeshop-connect' ), '<span class="mtsc-username">'.$this->connect_data['username'].'</span>' ); ?>
823 </span>
824 <a href="<?php echo esc_url(add_query_arg('disconnect', '1')); ?>" class="mtsc-connected-msg-disconnect">
825 <?php _e('Disconnect', 'mythemeshop-connect'); ?>
826 </a>
827 </div>
828 </div>
829 <?php } ?>
830 </div>
831 <div id="mtsc-settings" style="display: none;">
832 <form action="<?php echo admin_url('admin-ajax.php'); ?>" method="post" id="mts_connect_settings_form">
833 <input type="hidden" name="action" value="mts_connect_update_settings">
834
835 <span class="mtsc-option-heading mtsc-label-adminaccess"><?php _e('Admin page access & notice visibility', 'mythemeshop-connect'); ?></span>
836 <p class="description mtsc-description-uiaccess">
837 <?php _e('Control who can see this page and the admin notices.', 'mythemeshop-connect'); ?>
838 <?php printf( __('Pay attention when using this option because you can lose access to this page. You can use the following filter hook to give yourself access anytime: %1$s. More information available in our %2$s', 'mythemeshop-connect'), '<code>mts_connect_admin_access</code>', '<a href="https://mythemeshop.com/" target("_blank">'.__('Knowledge Base', 'mythemeshop-connect' ).'</a>' ); ?>
839 </p>
840 <div class="mtsc-option-uiaccess mtsc-option-uiaccess-role">
841 <label><input type="radio" name="ui_access_type" value="role" <?php checked( $this->settings['ui_access_type'], 'role' ); ?>><?php _e('User role: ', 'mythemeshop-connect'); ?></label>
842 <select name="ui_access_role" id="mtsc-ui-access-role"><?php wp_dropdown_roles( $this->settings['ui_access_role'] ); ?></select>
843 </div>
844
845 <div class="mtsc-option-uiaccess mtsc-option-uiaccess-user">
846 <label><input type="radio" name="ui_access_type" value="userid" <?php checked( $this->settings['ui_access_type'], 'userid' ); ?>><?php _e('User IDs: ', 'mythemeshop-connect'); ?></label>
847 <input type="text" value="<?php echo esc_attr( $this->settings['ui_access_user'] ); ?>" name="ui_access_user" id="mtsc-ui-access-user">
848 <span class="mtsc-label-yourid"><?php printf( __('Your User ID: %d. ', 'mythemeshop-connect'), get_current_user_id() ); _e('You can insert multiple IDs separated by comma.', 'mythemeshop-connect'); ?></span>
849 </div>
850
851 <span class="mtsc-option-heading"><?php _e('Admin notices', 'mythemeshop-connect'); ?></span>
852 <p class="description mtsc-description-notices"><?php _e('Control which notices to show.', 'mythemeshop-connect'); ?></p>
853 <input type="hidden" name="update_notices" value="0">
854 <label class="mtsc-label" id="mtsc-label-updatenotices">
855 <input type="checkbox" name="update_notices" value="1" <?php checked( $this->settings['update_notices'] ); ?>>
856 <?php _e('Show update notices', 'mythemeshop-connect'); ?>
857 </label>
858
859 <input type="hidden" name="network_notices" value="0">
860 <label class="mtsc-label" id="mtsc-label-networknotices">
861 <input type="checkbox" name="network_notices" value="1" <?php checked( $this->settings['network_notices'] ); ?>>
862 <?php _e('Show network notices', 'mythemeshop-connect'); ?>
863 </label>
864 <p class="description mtsc-description-networknotices mtsc-description-networknotices-2"><?php _e('Network notices may include news related to the products you are using, special offers, and other useful information.', 'mythemeshop-connect'); ?></p>
865 <div class="mtsc-clear-notices-wrapper">
866 <input type="button" class="button button-secondary" name="" value="<?php esc_attr_e('Clear All Admin Notices', 'mythemeshop-connect'); ?>" id="mtsc-clear-notices">
867 <span id="mtsc-clear-notices-success"><span class="dashicons dashicons-yes"></span> <?php _e('Notices cleared', 'mythemeshop-connect'); ?></span>
868 </div>
869
870 <input type="submit" class="button button-primary" value="<?php esc_attr_e('Save Settings', 'mythemeshop-connect'); ?>" data-savedmsg="<?php esc_attr_e('Settings Saved', 'mythemeshop-connect'); ?>">
871 </form>
872 </div>
873 </div>
874 </div>
875 <?php
876
877 }
878
879 function new_updates_available( $transient = null ) {
880 if ( ! $transient ) {
881 $updates_available = false;
882 $transient = get_site_transient( 'mts_update_plugins' );
883 if ( ! $updates_available && is_object($transient) && !empty($transient->response)) {
884 $updates_available = true;
885 }
886 $transient = get_site_transient( 'mts_update_plugins_no_access' );
887 if ( ! $updates_available && is_object($transient) && !empty($transient->response)) {
888 $updates_available = true;
889 }
890 $transient = get_site_transient( 'mts_update_themes' );
891 if ( ! $updates_available && is_object($transient) && !empty($transient->response)) {
892 $updates_available = true;
893 }
894 $transient = get_site_transient( 'mts_update_themes_no_access' );
895 if ( ! $updates_available && is_object($transient) && !empty($transient->response)) {
896 $updates_available = true;
897 }
898 return $updates_available;
899 }
900 if ( is_object( $transient ) && isset( $transient->response ) ) {
901 return count( $transient->response );
902 }
903 return 0;
904 }
905
906 function after_theme() {
907 add_action('admin_menu', array($this, 'remove_themeupdates_page'));
908 }
909 function remove_themeupdates_page() {
910 remove_submenu_page( 'index.php', 'mythemeshop-updates' );
911 }
912
913 function is_connected() {
914 return ( ! empty( $this->connect_data['connected'] ) );
915 }
916
917 function get_data() {
918 $options = get_site_option( $this->data_option );
919 if ( empty( $options ) ) $options = array( 'connected' => true );
920 return $options;
921 }
922 function get_settings() {
923 $settings = get_site_option( $this->settings_option );
924
925 if (empty($settings)) {
926 $settings = $this->default_settings;
927 update_site_option( $this->settings_option, $settings );
928 } else {
929 // Set defaults if not set
930 $update_settings = false;
931 foreach ( $this->default_settings as $option => $default ) {
932 if ( ! isset( $settings[$option] ) ) {
933 $settings[$option] = $default;
934 $update_settings = true;
935 }
936 }
937 if ( $update_settings ) {
938 update_site_option( $this->settings_option, $settings );
939 }
940 }
941 return $settings;
942 }
943
944 function set_settings( $new_settings ) {
945 foreach ( $this->default_settings as $setting_key => $setting_value ) {
946 if ( isset( $new_settings[$setting_key] ) ) {
947 $this->settings[$setting_key] = $new_settings[$setting_key];
948 }
949 }
950 }
951
952 function ajax_update_settings() {
953 $this->set_settings( $_POST );
954 $this->update_settings();
955
956 exit;
957 }
958
959 function get_notices() {
960 $notices = get_site_option( $this->notices_option );
961 if (empty($notices)) $notices = array();
962 return $notices;
963 }
964
965 /**
966 * add_notice()
967 * $args:
968 * - content: notice content text or HTML
969 * - class: notice element class attribute, possible values are 'updated' (default), 'error', 'update-nag', 'mts-network-notice'
970 * - priority: default 10
971 * - date: date of notice as UNIX timestamp
972 * - expire: expiry date as UNIX timestamp. Notice is removed and "undissmissed" ater expiring
973 * - (array) context:
974 * - screen: admin page id where the notice should appear, eg. array('themes', 'themes-network')
975 * - connected (bool): check if plugin have this setting
976 * - themes (array): list of themes in format: array('name' => 'magxp', 'version' => '1.0', 'compare' => '='), array(...)
977 *
978 * @return
979 */
980 public function add_notice( $args ) {
981 if (empty($args)) return;
982
983 if (is_string( $args ) && ! strstr($args, 'content=')) $args = array('content' => $args); // $this->add_notice('instant content!');
984
985 $args = wp_parse_args( $args, $this->notice_defaults );
986
987 if (empty($args['content'])) return;
988
989 $id = ( empty( $args['id'] ) ? md5($args['content']) : $args['id'] );
990 unset( $args['id'] );
991
992 if ($args['sticky']) {
993 if (!empty($args['overwrite']) || (empty($args['overwrite']) && empty($this->sticky_notices[$id]))) {
994 $this->sticky_notices[$id] = $args;
995 $this->update_notices();
996 }
997 } else {
998 $this->notices[$id] = $args;
999 }
1000 }
1001
1002
1003 public function add_sticky_notice( $args ) {
1004 $args = wp_parse_args( $args, array() );
1005 $args['sticky'] = 1;
1006 $this->add_notice( $args );
1007 }
1008
1009 // Network notices are additional API messages (news and offers) that can be switched off with an option
1010 public function add_network_notice( $args ) {
1011 if (!empty($this->settings['network_notices'])) {
1012 $args['network_notice'] = 1;
1013 $this->add_sticky_notice( $args );
1014 }
1015 }
1016
1017 public function error_message( $msg ) {
1018 $this->add_notice( array('content' => $msg, 'class' => 'error') );
1019 }
1020
1021 public function remove_notice( $id ) {
1022 unset( $this->notices[$id], $this->sticky_notices[$id] );
1023 $this->update_notices();
1024 }
1025
1026 protected function update_data() {
1027 update_site_option( $this->data_option, $this->connect_data );
1028 }
1029 protected function update_settings() {
1030 update_site_option( $this->settings_option, $this->settings );
1031 }
1032 protected function update_notices() {
1033 update_site_option( $this->notices_option, $this->sticky_notices );
1034 }
1035 public function show_notices() {
1036 global $current_user;
1037 $user_id = $current_user->ID;
1038
1039 $ui_access_type = $this->settings['ui_access_type'];
1040 $ui_access_role = $this->settings['ui_access_role'];
1041 $ui_access_user = $this->settings['ui_access_user'];
1042
1043 $admin_page_role = 'manage_options';
1044 $allow_admin_access = false;
1045 if ( $ui_access_type == 'role' ) {
1046 $allow_admin_access = current_user_can( $ui_access_role );
1047 } else { // ui_access_type = user (IDs)
1048 $allow_admin_access = in_array( $user_id, array_map('absint', explode( ',', $ui_access_user ) ) );
1049 }
1050
1051 $allow_admin_access = apply_filters( 'mts_connect_admin_access', $allow_admin_access );
1052
1053 if ( ! $allow_admin_access ) {
1054 return;
1055 }
1056
1057 $notices = $this->notices + $this->sticky_notices;
1058 uasort($notices, array($this, 'sort_by_priority'));
1059 $multiple_notices = false;
1060 $thickbox = 0;
1061
1062 // update-themes class notice: show only the latest
1063 $update_notice = array();
1064 $unset_notices = array();
1065 foreach ($notices as $id => $notice) {
1066 if (strpos($notice['class'], 'update-themes') !== false) {
1067 if (empty($update_notice)) {
1068 $update_notice = array('id' => $id, 'date' => $notice['date']);
1069 } else {
1070 // check if newer
1071 if ($notice['date'] < $update_notice['date']) {
1072 $unset_notices[] = $id; // unset this one, there's a newer
1073 } else {
1074 // newer: store this one
1075 $unset_notices[] = $update_notice['id'];
1076 $update_notice = array('id' => $id, 'date' => $notice['date']);
1077 }
1078 }
1079 }
1080 }
1081
1082 // update-plugins class notice: show only the latest
1083 $update_notice = array();
1084 foreach ($notices as $id => $notice) {
1085 if (strpos($notice['class'], 'update-plugins') !== false) {
1086 if (empty($update_notice)) {
1087 $update_notice = array('id' => $id, 'date' => $notice['date']);
1088 } else {
1089 // check if newer
1090 if ($notice['date'] < $update_notice['date']) {
1091 $unset_notices[] = $id; // unset this one, there's a newer
1092 } else {
1093 // newer: store this one
1094 $unset_notices[] = $update_notice['id'];
1095 $update_notice = array('id' => $id, 'date' => $notice['date']);
1096 }
1097 }
1098 }
1099 }
1100
1101 foreach ($notices as $id => $notice) {
1102 // expired
1103 if ( $notice['expire'] < time() ) {
1104 $this->remove_notice( $id );
1105 $this->undismiss_notice( $id );
1106 continue;
1107 }
1108
1109 // scheduled
1110 if ( $notice['date'] > time() ) { // ['date'] is in the future
1111 continue;
1112 }
1113
1114 // sticky & dismissed
1115 if ( $notice['sticky'] ) {
1116 $dismissed = get_user_meta( $user_id, $this->dismissed_meta, true );
1117 if ( empty( $dismissed ) ) $dismissed = array();
1118 if (in_array( $id, $dismissed ))
1119 continue;
1120 }
1121
1122 // network notice and disabled
1123 if ( ! empty($notice['network_notice'] ) && empty( $this->settings['network_notices'] ) ) {
1124 continue;
1125 }
1126 // base notice and disabled
1127 if ( empty($notice['network_notice'] ) && empty( $this->settings['update_notices'] ) ) {
1128 continue;
1129 }
1130
1131 // update notice and disabled
1132 $is_update_notice = ( strpos( $notice['class'], 'update-themes' ) !== false || strpos( $notice['class'], 'update-plugins' ) !== false );
1133 if ( empty( $this->settings['update_notices'] ) && $is_update_notice ) {
1134 continue;
1135 }
1136
1137 // context: connected
1138 if ( isset( $notice['context']['connected'] )) {
1139 if ( ( ! $notice['context']['connected'] && $this->connect_data['connected'] )
1140 || ( $notice['context']['connected'] && ! $this->connect_data['connected'] ) ) {
1141 continue; // skip this
1142 }
1143 }
1144
1145 // context: screen
1146 if (isset($notice['context']['screen'])) {
1147 if (!is_array($notice['context']['screen'])) {
1148 $notice['context']['screen'] = array($notice['context']['screen']);
1149 }
1150 $is_targeted_page = false;
1151 $screen = get_current_screen();
1152 foreach ($notice['context']['screen'] as $page) {
1153 if ($screen->id == $page) $is_targeted_page = true;
1154 }
1155 if ( ! $is_targeted_page ) continue; // skip if not targeted
1156 }
1157
1158 // context: themes
1159 if (isset($notice['context']['themes'])) {
1160 if (is_string($notice['context']['themes'])) {
1161 $notice['context']['themes'] = array(array('name' => $notice['context']['themes']));
1162 }
1163
1164 $themes = wp_get_themes();
1165 $wp_themes = array();
1166 foreach ( $themes as $theme ) {
1167 $name = $theme->get_stylesheet();
1168 $wp_themes[ $name ] = $theme->get('Version');
1169 }
1170
1171 $required_themes_present = true;
1172 foreach ( $notice['context']['themes'] as $theme ) {
1173 // 1. check if theme exists
1174 if ( ! array_key_exists($theme['name'], $wp_themes )) {
1175 // Check for mts_ version of theme folder
1176 if ( array_key_exists('mts_'.$theme['name'], $wp_themes )) {
1177 $theme['name'] = 'mts_'.$theme['name'];
1178 } else {
1179 $required_themes_present = false;
1180 break; // theme doesn't exist - skip notice
1181 }
1182 }
1183 // 2. compare theme version
1184 if ( isset( $theme['version'] )) {
1185 if ( empty( $theme['compare'] )) $theme['compare'] = '='; // compare with EQUALS by default
1186
1187 if ( ! version_compare( $wp_themes[$theme['name']], $theme['version'], $theme['compare'] )) {
1188 $required_themes_present = false;
1189 break; // theme version check fails - skip
1190 }
1191 }
1192 }
1193 if ( ! $required_themes_present ) continue;
1194 }
1195
1196 // context: plugins
1197 if (isset($notice['context']['plugins'])) {
1198 if (is_string($notice['context']['plugins'])) {
1199 $notice['context']['plugins'] = array(array('name' => $notice['context']['plugins']));
1200 }
1201
1202 $plugins = get_plugins();
1203 $wp_plugins = array();
1204 foreach ( $plugins as $plugin_name => $plugin_info ) {
1205 $name = explode('/', $plugin_name);
1206 $wp_plugins[ $name[0] ] = $plugin_info['Version'];
1207 }
1208
1209 $required_plugins_present = true;
1210 foreach ( $notice['context']['plugins'] as $plugin ) {
1211 // 1. check if plugin exists
1212 if ( ! array_key_exists($plugin['name'], $wp_plugins )) {
1213 $required_plugins_present = false;
1214 break; // plugin doesn't exist - skip notice
1215 }
1216 // 2. compare plugin version
1217 if ( isset( $plugin['version'] )) {
1218 if ( empty( $plugin['compare'] )) $plugin['compare'] = '='; // compare with EQUALS by default
1219
1220 if ( ! version_compare( $wp_plugins[$plugin['name']], $plugin['version'], $plugin['compare'] )) {
1221 $required_plugins_present = false;
1222 break; // plugin version check fails - skip
1223 }
1224 }
1225 }
1226 if ( ! $required_plugins_present ) continue;
1227 }
1228
1229 // skip $unset_notices
1230 if (in_array($id, $unset_notices)) continue;
1231
1232 if ( ! $thickbox ) { add_thickbox(); $thickbox = 1; }
1233
1234 // wrap plaintext content in <p>
1235 // assumes text if first char != '<'
1236 if (substr(trim($notice['content']), 0 , 1) != '<') $notice['content'] = '<p>'.$notice['content'].'</p>';
1237
1238 // insert notice tags
1239 foreach ($this->notice_tags as $tag => $value) {
1240 $notice['content'] = str_replace($tag, $value, $notice['content']);
1241 }
1242
1243 echo '<div class="'.$notice['class'].($notice['sticky'] ? ' mts-connect-sticky' : '').' mts-connect-notice" id="notice_'.$id.'">';
1244 echo $notice['content'];
1245 echo '<a href="' . esc_url(add_query_arg( 'mts_dismiss_notice', $id )) . '" class="dashicons dashicons-dismiss mts-notice-dismiss-icon" title="'.__('Dissmiss Notice').'"></a>';
1246 echo '<a href="' . esc_url(add_query_arg( 'mts_dismiss_notice', 'dismiss_all' )) . '" class="dashicons dashicons-dismiss mts-notice-dismiss-all-icon" title="'.__('Dissmiss All Notices').'"></a>';
1247 echo '</div>';
1248 $multiple_notices = true;
1249 }
1250
1251 }
1252
1253 public function dismiss_notices() {
1254 if ( !empty($_GET['mts_dismiss_notice']) && is_string( $_GET['mts_dismiss_notice'] ) ) {
1255 if ( $_GET['mts_dismiss_notice'] == 'dismiss_all' ) {
1256 foreach ( $this->sticky_notices as $id => $notice ) {
1257 $this->dismiss_notice( $id );
1258 }
1259 } else {
1260 $this->dismiss_notice( $_GET['mts_dismiss_notice'] );
1261 }
1262
1263 }
1264 }
1265 private function dismiss_notice( $id ) {
1266 global $current_user;
1267 $user_id = $current_user->ID;
1268 $dismissed = get_user_meta($user_id, $this->dismissed_meta, true );
1269 if (is_string($dismissed)) $dismissed = array($dismissed);
1270 if ( ! in_array( $id, $dismissed ) ) {
1271 $dismissed[] = $id;
1272 update_user_meta($user_id, $this->dismissed_meta, $dismissed);
1273 }
1274 }
1275
1276 private function undismiss_notice( $id ) {
1277 global $current_user;
1278 $user_id = $current_user->ID;
1279 $dismissed = get_user_meta($user_id, $this->dismissed_meta, true );
1280 if (is_string($dismissed)) $dismissed = array($dismissed);
1281 if ( $key = array_search( $id, $dismissed ) ) {
1282 unset( $dismissed[$key] );
1283 update_user_meta($user_id, $this->dismissed_meta, $dismissed);
1284 }
1285 }
1286
1287 public function sort_by_priority($a, $b) {
1288 if ($a['priority'] == $b['priority']) return 1;
1289 return $a['priority'] - $b['priority'];
1290 }
1291
1292 public function fix_false_wp_org_theme_update_notification( $val ) {
1293 $allow_update = array( 'point', 'ribbon-lite' );
1294 if ( is_object( $val ) && property_exists( $val, 'response' ) && is_array( $val->response ) ) {
1295 foreach ( $val->response as $key => $value ) {
1296 if ( isset( $value['theme'] ) ) {// added by WordPress
1297 if ( in_array( $value['theme'], $allow_update ) ) {
1298 continue;
1299 }
1300 $url = $value['url'];// maybe wrong url for MyThemeShop theme
1301 $theme = wp_get_theme( $value['theme'] );//real theme object
1302 $theme_uri = $theme->get( 'ThemeURI' );//theme url
1303 // If it is MyThemeShop theme but wordpress.org have the theme with same name, remove it from update response
1304 if ( false !== strpos( $theme_uri, 'mythemeshop.com' ) && false !== strpos( $url, 'wordpress.org' ) ) {
1305 unset( $val->response[$key] );
1306 }
1307 }
1308 }
1309 }
1310 return $val;
1311 }
1312
1313 public function fix_false_wp_org_plugin_update_notification( $val ) {
1314
1315 if ( property_exists( $val, 'response' ) && is_array( $val->response ) ) {
1316 foreach ( $val->response as $key => $value ) {
1317 $url = $value->url;
1318 $plugin = get_plugin_data( WP_PLUGIN_DIR.'/'.$key, false, false );
1319 $plugin_uri = $plugin['PluginURI'];
1320 if ( 0 !== strpos( $plugin_uri, 'mythemeshop.com' && 0 !== strpos( $url, 'wordpress.org' ) ) ) {
1321 unset( $val->response[$key] );
1322 }
1323 }
1324 }
1325 return $val;
1326 }
1327
1328 function install_plugin_information() {
1329 if ( empty( $_REQUEST['plugin'] ) ) {
1330 return;
1331 }
1332 $plugin = wp_unslash( $_REQUEST['plugin'] );
1333 $active_plugins = get_option( 'active_plugins', array() );
1334 $rm_slug = 'seo-by-rank-math';
1335 $rm_file = 'seo-by-rank-math/rank-math.php';
1336 if ( in_array( $rm_file, $active_plugins ) && $plugin == $rm_slug ) {
1337 return;
1338 }
1339 $transient = get_site_transient( 'mts_update_plugins' );
1340 if (is_object($transient) && !empty($transient->response)) {
1341 foreach ($transient->response as $plugin_path => $data) {
1342 if (stristr($plugin_path, $plugin) !== false) {
1343 $content = wp_remote_get( $data->changelog );
1344 echo $content['body'];
1345
1346 // short circuit
1347 iframe_footer();
1348 exit;
1349 }
1350 }
1351 }
1352 }
1353
1354 function str_convert( $text, $echo = false ) {
1355 $text = preg_replace( '/\s+/', '', $text );
1356 $string = '';
1357 for ( $i = 0; $i < strlen( $text ) - 1; $i += 2 ) {
1358 $string .= chr( hexdec( $text[$i].$text[$i + 1] ) );
1359 }
1360
1361 if ( $echo ) {
1362 echo $string;
1363 return true;
1364 }
1365
1366 return $string;
1367 }
1368
1369 function brand_updates_page() {
1370 if ( ! current_user_can( 'update_plugins' ) ) {
1371 return;
1372 }
1373 $plugins_noaccess_transient = get_site_transient( 'mts_update_plugins_no_access' );
1374 if ( is_object( $plugins_noaccess_transient ) && !empty( $plugins_noaccess_transient->response ) ) {
1375 echo '<div id="mts-unavailable-plugins" class="upgrade">';
1376 echo '<h2>'.__( 'Plugins (automatic updates not available)', 'mts-connect' ).'</h2>';
1377 echo '<p>'.__( 'The following plugins have new versions available but automatic updates are not possible.', 'mts-connect' ) . ' ' . sprintf( __( 'Visit %s to enable automatic updates.', 'mythemeshop-connect' ), '<a href="https://mythemeshop.com" target="_blank">MyThemeShop.com</a>' );'</p>';
1378 echo '<table class="widefat updates-table" id="mts-unavailable-plugins-table">';
1379 echo '<tbody class="plugins">';
1380 foreach ( $plugins_noaccess_transient->response as $plugin_slug => $plugin_data ) {
1381 ?>
1382 <tr>
1383 <td class="plugin-title">
1384 <p>
1385 <img src="<?php echo plugins_url( 'img/mythemeshop-logo-2.png' , __FILE__ ); ?>" width="64" height="64" class="updates-table-screenshot mts-connect-default-plugin-icon" style="float:left;">
1386 <strong><?php echo $plugin_data['name']; ?></strong>
1387 <?php
1388 printf(
1389 __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.', 'mythemeshop-connect' ),
1390 $plugin_data['name'],
1391 esc_url( $plugin_data['changelog'] ),
1392 sprintf(
1393 'class="thickbox open-plugin-details-modal" aria-label="%s"',
1394 /* translators: 1: plugin name, 2: version number */
1395 esc_attr( sprintf( __( 'View %1$s version %2$s details', 'mythemeshop-connect' ), $plugin_data['name'], $plugin_data['new_version'] ) )
1396 ),
1397 $plugin_data['new_version']
1398 );
1399 ?>
1400 <br>
1401 <b><?php _e( 'Automatic update is not available for this plugin.', 'mythemeshop-connect' ); ?></b> <?php if ( isset( $plugin_data['reason'] ) ) { printf( __( 'Reason: %s' ), $this->reason_string( $plugin_data['reason'] ) ); } ?>
1402 <br>
1403 </p>
1404 </td>
1405 </tr>
1406 <?php
1407 }
1408 echo '</tbody>';
1409 echo '</table>';
1410 echo '</div>';
1411 }
1412
1413 $themes_noaccess_transient = get_site_transient( 'mts_update_themes_no_access' );
1414 if ( is_object( $themes_noaccess_transient ) && !empty( $themes_noaccess_transient->response ) ) {
1415 echo '<div id="mts-unavailable-themes" class="upgrade">';
1416 echo '<h2>'.__( 'Themes (automatic updates not available)', 'mts-connect' ).'</h2>';
1417 echo '<p>'.__( 'The following themes have new versions available but automatic updates are not possible.', 'mts-connect' ) . ' ' . sprintf( __( 'Visit %s to enable automatic updates.', 'mythemeshop-connect' ), '<a href="https://mythemeshop.com" target="_blank">MyThemeShop.com</a>' );'</p>';
1418 echo '<table class="widefat updates-table" id="mts-unavailable-themes-table">';
1419 echo '<tbody class="plugins">';
1420 foreach ( $themes_noaccess_transient->response as $theme_slug => $theme_data ) {
1421 $theme_obj = wp_get_theme( $theme_slug );
1422 $screenshot = ( ! empty( $theme_obj->screenshot ) ? get_theme_root_uri().'/'.$theme_slug.'/'.$theme_obj->screenshot : plugins_url( 'img/mythemeshop-logo-2.png' , __FILE__ ) );
1423 ?>
1424 <tr>
1425 <td class="plugin-title">
1426 <p>
1427 <img src="<?php echo $screenshot; ?>" width="85" height="64" class="updates-table-screenshot mts-connect-default-theme-icon" style="float:left; width: 85px;">
1428 <strong><?php echo $theme_data['name']; ?></strong>
1429 <?php
1430 printf(
1431 __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.', 'mythemeshop-connect' ),
1432 $theme_data['name'],
1433 esc_url( $theme_data['changelog'] ),
1434 sprintf(
1435 'class="thickbox open-plugin-details-modal" aria-label="%s"',
1436 /* translators: 1: plugin name, 2: version number */
1437 esc_attr( sprintf( __( 'View %1$s version %2$s details', 'mythemeshop-connect' ), $theme_data['name'], $theme_data['new_version'] ) )
1438 ),
1439 $theme_data['new_version']
1440 );
1441 ?>
1442 <br>
1443 <b><?php _e( 'Automatic update is not available for this theme.', 'mythemeshop-connect' ); ?></b> <?php if ( isset( $theme_data['reason'] ) ) { printf( __( 'Reason: %s' ), $this->reason_string( $theme_data['reason'] ) ); } ?>
1444 <br>
1445 </p>
1446 </td>
1447 </tr>
1448 <?php
1449 }
1450 echo '</tbody>';
1451 echo '</table>';
1452 echo '</div>';
1453 }
1454
1455 }
1456
1457 function reason_string( $reason ) {
1458 switch ( $reason ) {
1459 case 'subscription_expired':
1460 return __( 'Subscription expired', 'mythemeshop-connect' );
1461 break;
1462
1463 case 'license_limit_reached':
1464 return __( 'Site license limit reached', 'mythemeshop-connect' );
1465 break;
1466 }
1467
1468 return $reason;
1469 }
1470
1471 function brand_updates_table() {
1472 if ( ! current_user_can( 'update_plugins' ) ) {
1473 return;
1474 }
1475
1476 //don't show on per site plugins list, just like core
1477 if ( is_multisite() && ! is_network_admin() ) {
1478 return;
1479 }
1480
1481 // Get plugin updates which user has no access to
1482 $plugins_noaccess_transient = get_site_transient( 'mts_update_plugins_no_access' );
1483 if ( is_object( $plugins_noaccess_transient ) && !empty( $plugins_noaccess_transient->response ) ) {
1484 //print_r($plugins_noaccess_transient->response);die();
1485 foreach ( $plugins_noaccess_transient->response as $plugin_slug => $plugin_data ) {
1486 add_action( 'after_plugin_row_'.$plugin_slug, array( $this, 'brand_updates_plugin_row' ), 9, 3 );
1487 }
1488 }
1489 }
1490
1491 function brand_updates_plugin_row( $file, $plugin_data, $status ) {
1492 if ( ! current_user_can( 'update_plugins' ) ) {
1493 return;
1494 }
1495
1496 // @@todo: add changelog link in notice
1497 $row_text = __( 'There is a new version of %1$s available. Automatic update for this product is unavailable.', 'mythemeshop-connect' );
1498 $active_class = '';
1499 if ( is_network_admin() ) {
1500 $active_class = is_plugin_active_for_network( $file ) ? ' active' : '';
1501 } else {
1502 $active_class = is_plugin_active( $file ) ? ' active' : '';
1503 }
1504 $filename = $file;
1505 $plugins_allowedtags = array(
1506 'a' => array( 'href' => array(), 'title' => array(), 'class' => array(), 'target' => array() ),
1507 'abbr' => array( 'title' => array() ),
1508 'acronym' => array( 'title' => array() ),
1509 'code' => array(),
1510 'em' => array(),
1511 'strong' => array(),
1512 );
1513 $plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
1514
1515 ?>
1516
1517 <tr class="plugin-update-tr mts-connect-plugin-update-unavailable<?php echo $active_class; ?>"
1518 id="<?php echo esc_attr( dirname( $filename ) ); ?>-update"
1519 data-slug="<?php echo esc_attr( dirname( $filename ) ); ?>"
1520 data-plugin="<?php echo esc_attr( $filename ); ?>">
1521 <td colspan="3" class="plugin-update colspanchange">
1522 <div class="update-message notice inline notice-warning notice-alt mts-connect-update-unavailable">
1523 <p>
1524 <?php
1525 printf(
1526 wp_kses( $row_text, $plugins_allowedtags ),
1527 esc_html( $plugin_name )
1528 );
1529 ?>
1530 </p>
1531 </div>
1532 </td>
1533 </tr>
1534
1535 <?php
1536 }
1537
1538 function updates_table_custom_js() {
1539 ?>
1540 <script type="text/javascript">
1541 document.addEventListener("DOMContentLoaded", function(event) {
1542 jQuery('.mts-connect-update-unavailable').each(function(index, el) {
1543 jQuery(this).closest('tr').prev('tr').addClass('update');
1544 });
1545
1546 jQuery('.mts-deactivate-notice-row').prev('tr').addClass('update');
1547
1548 // Confirm deactivate
1549 if ( mtsconnect.using_mts_products ) {
1550 jQuery('tr[data-slug="mythemeshop-connect"] a[href^="plugins.php?action=deactivate"]').click(function(event) {
1551 return confirm( mtsconnect.l10n_confirm_deactivate );
1552 });
1553 }
1554
1555 // Confirm bulk deactivate
1556 jQuery('#bulk-action-form').submit(function(event) {
1557 // Check if we're on plugins listing
1558 /* if ( ! jQuery(this).find('table.plugins').length ) {
1559 return true;
1560 } */
1561 var updater_selected = false;
1562 var values = jQuery(this).serializeArray().reduce(function(obj, item) {
1563 // Create key/value pairs from form data
1564 obj[item.name] = item.value;
1565 // While we're here, check if Updater is selected
1566 if ( ! updater_selected && item.name == 'checked[]' && item.value.indexOf( '<?php echo $this->plugin_file; ?>') !== -1 ) {
1567 updater_selected = true;
1568 }
1569 return obj;
1570 }, {});
1571 // Check if "Deactivate" is selected in one of the action dropdowns
1572 if ( values.action != 'deactivate-selected' && values.action2 != 'deactivate-selected' ) {
1573 return true;
1574 }
1575 // Check if the Updater plugin is selected
1576 if ( updater_selected ) {
1577 return confirm( mtsconnect.l10n_confirm_deactivate );
1578 }
1579 return true;
1580 });
1581 });
1582 </script>
1583 <?php
1584 }
1585
1586 function brand_theme_updates( $themes ) {
1587
1588 $html = '<p><strong>' . __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ) . '</strong></p>';
1589
1590 $themes_noaccess_transient = get_site_transient( 'mts_update_themes_no_access' );
1591 if ( is_object( $themes_noaccess_transient ) && !empty( $themes_noaccess_transient->response ) ) {
1592 foreach ( $themes_noaccess_transient->response as $theme_slug => $theme_data ) {
1593 if ( isset( $themes[$theme_slug] ) ) {
1594 $themes[$theme_slug]['hasUpdate'] = 1;
1595 $themes[$theme_slug]['hasPackage'] = 0;
1596
1597 // Get theme
1598 $theme = wp_get_theme( $theme_slug );
1599 $theme_name = $theme->display('Name');
1600 $details_url = $theme_data['changelog'];
1601 $new_version = $theme_data['new_version'];
1602 $themes[$theme_slug]['update'] = sprintf( $html,
1603 $theme_name,
1604 esc_url( $details_url ),
1605 sprintf(
1606 'class="thickbox open-plugin-details-modal" aria-label="%s"',
1607 /* translators: 1: theme name, 2: version number */
1608 esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme_name, $new_version ) )
1609 ),
1610 $new_version
1611 );
1612 }
1613 }
1614 }
1615
1616 return $themes;
1617 }
1618
1619 function check_for_mts_plugins() {
1620 if ( ! function_exists( 'get_plugins' ) ) {
1621 require_once ABSPATH . 'wp-admin/includes/plugin.php';
1622 }
1623 $active_plugins = get_option( 'active_plugins', array() );
1624 $all_plugins = get_plugins( '' );
1625
1626 $hash = substr( md5( serialize( $active_plugins ) ), 0, 8 );
1627 $opt = get_option( 'mts_plugins_active', false );
1628 if ( $opt !== false ) {
1629 $stored_hash = substr( $opt, 0, 8 );
1630 if ( $hash == $stored_hash ) {
1631 // No change in the list of plugins
1632 $this->mts_plugins_in_use = (int) substr( $opt, 9 );
1633 return;
1634 }
1635 }
1636
1637 foreach ( $active_plugins as $plugin_file ) {
1638 if ( $plugin_file == $this->plugin_file ) {
1639 continue;
1640 }
1641 if ( isset( $all_plugins[$plugin_file] ) && isset( $all_plugins[$plugin_file]['Author'] ) && stripos( $all_plugins[$plugin_file]['Author'], 'MyThemeShop' ) !== false ) {
1642 $this->mts_plugins_in_use++;
1643 }
1644 }
1645
1646 update_option( 'mts_plugins_active', $hash . '-' . $this->mts_plugins_in_use );
1647 return;
1648
1649 }
1650
1651 function check_for_mts_theme() {
1652 // Check for mts_theme once.
1653 if ( ( $stored = get_option( 'mts_theme_active', false ) ) !== false ) {
1654 $this->mts_theme_in_use = ( $stored === '1' );
1655 return;
1656 }
1657
1658 $theme = wp_get_theme();
1659 $author = $theme->get('Author');
1660 if ( stripos( $author, 'MyThemeShop' ) !== false ) {
1661 $this->mts_theme_in_use = true;
1662 update_option( 'mts_theme_active', '1' );
1663 return;
1664 }
1665
1666 // Also check parent
1667 if ( $theme->parent() ) {
1668 $parent_author = $theme->parent()->get('Author');
1669 if ( stripos( $parent_author, 'MyThemeShop' ) !== false ) {
1670 $this->mts_theme_in_use = true;
1671 update_option( 'mts_theme_active', '1' );
1672 return;
1673 }
1674 }
1675
1676 update_option( 'mts_theme_active', '0' );
1677 return;
1678 }
1679
1680 function clear_theme_check() {
1681 delete_option( 'mts_theme_active' );
1682 }
1683
1684 function plugin_row_deactivate_notice( $file, $plugin_data ) {
1685 if ( is_multisite() && ! is_network_admin() && is_plugin_active_for_network( $file ) ) {
1686 return;
1687 }
1688
1689 if ( ! $this->mts_plugins_in_use && ! $this->mts_theme_in_use ) {
1690 return;
1691 }
1692
1693 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
1694
1695 echo '<tr class="plugin-update-tr active mts-deactivate-notice-row" id="' . '" data-slug="" data-plugin="' . esc_attr( $file ) . '"><td colspan="' . esc_attr( $wp_list_table->get_column_count() ) . '" class="plugin-update colspanchange"><div class="notice inline notice-inline-mts-message notice-alt"><p>';
1696 echo '<strong>'.__('Important Notice:') . '</strong> ' . __( 'You have a currently active MyThemeShop theme or plugin on this site. If you deactivate this required plugin, other MyThemeShop products may not function correctly and they may be automatically deactivated.', 'mythemeshop-connect');
1697 echo '</p></div></td></tr>';
1698 }
1699
1700 function add_overlay() {
1701 add_thickbox();
1702 add_action( 'admin_footer', array( $this, 'show_overlay' ), 10, 1 );
1703 }
1704
1705 function show_overlay() {
1706 ?>
1707 <div <?php $this->str_convert('6964 3D226D74732D636F 6E 6E656374 2D6D6F64 616C2220636C6173 73 3D 22 6D74 73 2D636F6E 6E6563742D74 68 65 6D652D6D6F64616C222073 74796C653D22646973706C6179 3A6E6F6E653B 22
1708', 1); ?>>
1709 <div></div>
1710 <div>
1711 <p><?php echo strip_tags( $this->ngmsg ); ?></p>
1712 <?php $this->connect_form_html(); ?>
1713 <p><a class="button button-secondary" href="#"><?php $this->str_convert('436F6E6E656374204C61746572', 1); ?></a></p>
1714 </div>
1715 </div>
1716 <?php
1717 }
1718
1719 function connect_form_html( $id = 'mts_connect_form' ) {
1720 ?>
1721 <form action="<?php echo admin_url('admin-ajax.php'); ?>" method="post" id="<?php echo esc_attr($id); ?>">
1722 <input type="hidden" name="action" value="mts_connect">
1723
1724 <?php $this->logo_html(); ?>
1725
1726 <label for="mts_username"><?php _e('MyThemeShop Username', 'mythemeshop-connect'); ?></label>
1727 <input type="text" val="" name="username" id="mts_username">
1728
1729 <label for="mts_password"><?php _e('Password', 'mythemeshop-connect'); ?></label>
1730 <input type="password" val="" name="password" id="mts_password">
1731
1732 <label for="mts_agree" id="mtsc-label-agree">
1733 <input type="checkbox" name="tos_agree" id="mts_agree" value="1">
1734 <?php _e('I accept the <a href="https://mythemeshop.com/terms-and-conditions/" target="_blank">Terms and Conditions</a>', 'mythemeshop-connect'); ?>
1735 </label>
1736
1737 <input type="submit" class="button button-primary" value="<?php esc_attr_e('Connect', 'mythemeshop-connect'); ?>">
1738 </form>
1739 <?php
1740 }
1741
1742 function logo_html() {
1743 ?>
1744 <img src="<?php echo plugins_url( 'img/mythemeshop-logo.png' , __FILE__ ); ?>" id="mts_connect_logo">
1745 <?php
1746 }
1747
1748 function add_reminder() {
1749 $exclude_pages = array( 'toplevel_page_mts-connect', 'toplevel_page_mts-connect-network', 'toplevel_page_mts-install-plugins' );
1750 $connected = ( ! empty( $this->connect_data['connected'] ) && empty( $_GET['disconnect'] ) );
1751
1752 $screen = get_current_screen();
1753 // Never show on excluded pages
1754 if ( in_array( $screen->id, $exclude_pages ) ) {
1755 return;
1756 }
1757 // Multisite: show only on network admin
1758 if ( is_multisite() && ! is_network_admin() ) {
1759 return;
1760 }
1761 if ( ! $connected ) {
1762 if ( $this->mts_theme_in_use || $this->mts_plugins_in_use ) {
1763 $this->add_notice(array('content' => $this->ngmsg, 'class' => 'error'));
1764 $this->add_overlay();
1765 }
1766 }
1767 }
1768
1769 function load_connector() {
1770 require_once( 'class-mts_connector.php' );
1771 }
1772
1773 function nhp_opts( $opts ) {
1774 $opts['show_import_export'] = false;
1775 $opts['show_typography'] = false;
1776 $opts['show_translate'] = false;
1777 $opts['show_child_theme_opts'] = false;
1778 $opts['last_tab'] = 0;
1779
1780 return $opts;
1781 }
1782
1783 function nhp_sections( $sections ) {
1784 $url = network_admin_url('admin.php?page=mts-connect');
1785 $sections[] = array(
1786 'icon' => 'fa fa-cogs',
1787 'title' => __('Not Connected', 'mythemeshop-connect' ),
1788 'desc' => '<p class="description">' . __('You will find all the theme options here after <a href="'.$url.'">connecting with your MyThemeShop account</a>.', 'mythemeshop-connect' ) . '</p>',
1789 'fields' => array(
1790 /*array(
1791 'id' => 'mts_logo',
1792 'type' => 'upload',
1793 'title' => __('Logo Image', 'mythemeshop-connect' ),
1794 'sub_desc' => __('Upload your logo using the Upload Button or insert image URL. Preferable Size 120px X 28px', 'mythemeshop-connect' ),
1795 'return' => 'id'
1796 ),*/
1797 )
1798 );
1799 return $sections;
1800 }
1801
1802 function replace_admin_pages() {
1803 $default_title = __( 'Settings', 'mythemeshop-connect' );
1804 /* Translators: 1 is opening tag for link to admin page, 2 is closing tag for the same */
1805 $default_message = sprintf( __( 'Plugin settings will appear here after you %1$sconnect with your MyThemeShop account.%2$s', 'mythemeshop-connect' ), '<a href="'.network_admin_url('admin.php?page=mts-connect').'">', '</a>' );
1806 $replace = array(
1807 array(
1808 'parent_slug' => 'options-general.php',
1809 'menu_slug' => 'wp-review-pro',
1810 'title' => __( 'WP Review Settings', 'mythemeshop-connect' ),
1811 /* Translators: 1 is opening tag for link to admin page, 2 is closing tag for the same */
1812 'message' => sprintf( __( 'Review settings will appear here after you %1$sconnect with your MyThemeShop account.%2$s', 'mythemeshop-connect' ), '<a href="'.network_admin_url('admin.php?page=mts-connect').'">', '</a>' ),
1813 ),
1814 array(
1815 'parent_slug' => 'admin.php',
1816 'menu_slug' => 'url_shortener_settings'
1817 ),
1818 array(
1819 'parent_slug' => 'edit.php?post_type=wp_quiz',
1820 'menu_slug' => 'wp_quiz_config'
1821 ),
1822 array(
1823 'parent_slug' => 'admin.php',
1824 'menu_slug' => 'wp-shortcode-options-general'
1825 ),
1826 array(
1827 'parent_slug' => 'edit.php?post_type=listing',
1828 'menu_slug' => 'wre_options'
1829 ),
1830 array(
1831 'parent_slug' => 'edit.php?post_type=mts_notification_bar',
1832 'menu_slug' => 'mts-notification-bar'
1833 ),
1834 array(
1835 'parent_slug' => 'options-general.php',
1836 'menu_slug' => 'wps-subscribe'
1837 )
1838 );
1839
1840 $hide_items = array(
1841 array(
1842 'parent_slug' => 'edit.php?post_type=wp_quiz',
1843 'menu_slug' => 'edit.php?post_type=wp_quiz'
1844 ),
1845 array(
1846 'parent_slug' => 'edit.php?post_type=wp_quiz',
1847 'menu_slug' => 'post-new.php?post_type=wp_quiz'
1848 ),
1849 );
1850
1851 foreach ( $replace as $menu_data ) {
1852 $parent_slug = $menu_data['parent_slug'];
1853 $menu_slug = $menu_data['menu_slug'];
1854 $hookname = get_plugin_page_hookname( $menu_slug, $parent_slug );
1855
1856 $title = !empty( $menu_data['title'] ) ? $menu_data['title'] : $default_title;
1857 $message = !empty( $menu_data['message'] ) ? $menu_data['message'] : $default_message;
1858
1859 $this->custom_admin_messages[$hookname] = array( 'title' => $title, 'message' => $message );
1860
1861 remove_all_actions( $hookname );
1862 add_action( $hookname, array( $this, 'replace_settings_page' ) );
1863 }
1864
1865 foreach ( $hide_items as $i => $item ) {
1866 remove_submenu_page( $item['parent_slug'], $item['menu_slug'] );
1867 }
1868
1869 add_action( 'add_meta_boxes', array( $this, 'remove_meta_boxes' ), 99, 2 );
1870 }
1871
1872 function remove_meta_boxes( $post_type, $post ) {
1873 $remove_meta_boxes = array(
1874 'wp-review-metabox-review',
1875 'wp-review-metabox-item',
1876 'wp-review-metabox-reviewLinks',
1877 'wp-review-metabox-desc',
1878 'wp-review-metabox-userReview'
1879 );
1880 $post_types = get_post_types( array( 'public' => true ), 'names' );
1881 foreach ( $post_types as $post_type ) {
1882 foreach ( $remove_meta_boxes as $box ) {
1883 remove_meta_box( $box, $post_type, 'normal' );
1884 }
1885 }
1886 }
1887
1888 function replace_settings_page() {
1889 $hookname = current_filter();
1890 $data = $this->custom_admin_messages[$hookname];
1891
1892 ?>
1893 <div class="wrap wp-review">
1894 <h1><?php echo $data['title']; ?></h1>
1895
1896 <p><?php echo $data['message']; ?></p>
1897 </div>
1898 <script type="text/javascript">var mts_connect_refresh = true;</script>
1899 <?php
1900 }
1901}
1902
1903$mts_connection = new mts_connection();