diff --git a/composer.json b/composer.json index ee19b65..93f78a9 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "minimum-stability": "stable", "require": { "php": ">=7.4", - "appsero/client": "dev-develop" + "appsero/client": "^2.0.4" }, "require-dev": { "wp-coding-standards/wpcs": "*", diff --git a/composer.lock b/composer.lock index c064528..2d7b272 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "39ebbf6ec49797df6515e298fe8a1c71", + "content-hash": "1e5fcd10f0881a86c53978b1b5f4b83e", "packages": [ { "name": "appsero/client", - "version": "dev-develop", + "version": "v2.0.4", "source": { "type": "git", "url": "https://github.com/Appsero/client.git", - "reference": "3b68f17ac29d56d14a78cc4817c4b80f692e4e3a" + "reference": "12ff65b9770286d21edf314e7acfcd26fdde3315" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Appsero/client/zipball/3b68f17ac29d56d14a78cc4817c4b80f692e4e3a", - "reference": "3b68f17ac29d56d14a78cc4817c4b80f692e4e3a", + "url": "https://api.github.com/repos/Appsero/client/zipball/12ff65b9770286d21edf314e7acfcd26fdde3315", + "reference": "12ff65b9770286d21edf314e7acfcd26fdde3315", "shasum": "" }, "require": { @@ -31,7 +31,6 @@ "tareq1988/wp-php-cs-fixer": "dev-master", "wp-coding-standards/wpcs": "dev-develop" }, - "default-branch": true, "type": "library", "autoload": { "psr-4": { @@ -57,9 +56,9 @@ ], "support": { "issues": "https://github.com/Appsero/client/issues", - "source": "https://github.com/Appsero/client/tree/develop" + "source": "https://github.com/Appsero/client/tree/v2.0.4" }, - "time": "2023-10-11T09:13:55+00:00" + "time": "2024-11-25T05:58:23+00:00" } ], "packages-dev": [ @@ -413,28 +412,28 @@ }, { "name": "phpcompatibility/phpcompatibility-paragonie", - "version": "1.3.2", + "version": "1.3.3", "source": { "type": "git", "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", - "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26" + "reference": "293975b465e0e709b571cbf0c957c6c0a7b9a2ac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", - "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/293975b465e0e709b571cbf0c957c6c0a7b9a2ac", + "reference": "293975b465e0e709b571cbf0c957c6c0a7b9a2ac", "shasum": "" }, "require": { "phpcompatibility/php-compatibility": "^9.0" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "paragonie/random_compat": "dev-master", "paragonie/sodium_compat": "dev-master" }, "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." }, "type": "phpcodesniffer-standard", @@ -464,22 +463,37 @@ ], "support": { "issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues", + "security": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/security/policy", "source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie" }, - "time": "2022-10-25T01:46:02+00:00" + "funding": [ + { + "url": "https://github.com/PHPCompatibility", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-04-24T21:30:46+00:00" }, { "name": "phpcompatibility/phpcompatibility-wp", - "version": "2.1.4", + "version": "2.1.5", "source": { "type": "git", "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", - "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5" + "reference": "01c1ff2704a58e46f0cb1ca9d06aee07b3589082" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", - "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/01c1ff2704a58e46f0cb1ca9d06aee07b3589082", + "reference": "01c1ff2704a58e46f0cb1ca9d06aee07b3589082", "shasum": "" }, "require": { @@ -487,10 +501,10 @@ "phpcompatibility/phpcompatibility-paragonie": "^1.0" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7" + "dealerdirect/phpcodesniffer-composer-installer": "^1.0" }, "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." }, "type": "phpcodesniffer-standard", @@ -519,9 +533,24 @@ ], "support": { "issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues", + "security": "https://github.com/PHPCompatibility/PHPCompatibilityWP/security/policy", "source": "https://github.com/PHPCompatibility/PHPCompatibilityWP" }, - "time": "2022-10-24T09:00:36+00:00" + "funding": [ + { + "url": "https://github.com/PHPCompatibility", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-04-24T21:37:59+00:00" }, { "name": "phpcsstandards/phpcsextra", @@ -603,22 +632,22 @@ }, { "name": "phpcsstandards/phpcsutils", - "version": "1.0.9", + "version": "1.0.12", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", - "reference": "908247bc65010c7b7541a9551e002db12e9dae70" + "reference": "87b233b00daf83fb70f40c9a28692be017ea7c6c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/908247bc65010c7b7541a9551e002db12e9dae70", - "reference": "908247bc65010c7b7541a9551e002db12e9dae70", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/87b233b00daf83fb70f40c9a28692be017ea7c6c", + "reference": "87b233b00daf83fb70f40c9a28692be017ea7c6c", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", "php": ">=5.4", - "squizlabs/php_codesniffer": "^3.8.0 || 4.0.x-dev@dev" + "squizlabs/php_codesniffer": "^3.10.0 || 4.0.x-dev@dev" }, "require-dev": { "ext-filter": "*", @@ -687,7 +716,7 @@ "type": "open_collective" } ], - "time": "2023-12-08T14:50:00+00:00" + "time": "2024-05-20T13:34:27+00:00" }, { "name": "psr/container", @@ -739,16 +768,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.8.0", + "version": "3.11.1", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7" + "reference": "19473c30efe4f7b3cd42522d0b2e6e7f243c6f87" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/5805f7a4e4958dbb5e944ef1e6edae0a303765e7", - "reference": "5805f7a4e4958dbb5e944ef1e6edae0a303765e7", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/19473c30efe4f7b3cd42522d0b2e6e7f243c6f87", + "reference": "19473c30efe4f7b3cd42522d0b2e6e7f243c6f87", "shasum": "" }, "require": { @@ -758,11 +787,11 @@ "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" }, "bin": [ - "bin/phpcs", - "bin/phpcbf" + "bin/phpcbf", + "bin/phpcs" ], "type": "library", "extra": { @@ -815,7 +844,7 @@ "type": "open_collective" } ], - "time": "2023-12-08T12:32:31+00:00" + "time": "2024-11-16T12:02:36+00:00" }, { "name": "symfony/console", @@ -1728,16 +1757,16 @@ }, { "name": "wp-coding-standards/wpcs", - "version": "3.0.1", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", - "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1" + "reference": "9333efcbff231f10dfd9c56bb7b65818b4733ca7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/b4caf9689f1a0e4a4c632679a44e638c1c67aff1", - "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/9333efcbff231f10dfd9c56bb7b65818b4733ca7", + "reference": "9333efcbff231f10dfd9c56bb7b65818b4733ca7", "shasum": "" }, "require": { @@ -1746,16 +1775,16 @@ "ext-tokenizer": "*", "ext-xmlreader": "*", "php": ">=5.4", - "phpcsstandards/phpcsextra": "^1.1.0", - "phpcsstandards/phpcsutils": "^1.0.8", - "squizlabs/php_codesniffer": "^3.7.2" + "phpcsstandards/phpcsextra": "^1.2.1", + "phpcsstandards/phpcsutils": "^1.0.10", + "squizlabs/php_codesniffer": "^3.9.0" }, "require-dev": { "php-parallel-lint/php-console-highlighter": "^1.0.0", "php-parallel-lint/php-parallel-lint": "^1.3.2", "phpcompatibility/php-compatibility": "^9.0", "phpcsstandards/phpcsdevtools": "^1.2.0", - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0" }, "suggest": { "ext-iconv": "For improved results", @@ -1786,18 +1815,16 @@ }, "funding": [ { - "url": "https://opencollective.com/thewpcc/contribute/wp-php-63406", + "url": "https://opencollective.com/php_codesniffer", "type": "custom" } ], - "time": "2023-09-14T07:06:09+00:00" + "time": "2024-03-25T16:39:00+00:00" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "appsero/client": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/dependencies/Appsero/Client.php b/dependencies/Appsero/Client.php index cc5b36e..8756dae 100644 --- a/dependencies/Appsero/Client.php +++ b/dependencies/Appsero/Client.php @@ -14,7 +14,7 @@ class Client { * * @var string */ - public $version = '1.2.5'; + public $version = '2.0.4'; /** * Hash identifier of the plugin @@ -85,13 +85,6 @@ class Client { */ private $insights; - /** - * The Object of Updater Class - * - * @var object - */ - private $updater; - /** * The Object of License Class * @@ -137,21 +130,21 @@ public function insights() { /** * Initialize plugin/theme updater * - * @return WeDevs\DokanMigrator\Dependencies\Appsero\Updater + * @return void */ public function updater() { - if ( ! class_exists( __NAMESPACE__ . '\Updater' ) ) { - require_once __DIR__ . '/Updater.php'; + // do not show update notice on ajax request and rest api request + if ( wp_doing_ajax() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) { + return; } - // if already instantiated, return the cached one - if ( $this->updater ) { - return $this->updater; - } + // show deprecated notice + _deprecated_function( __CLASS__ . '::updater', '2.0', '\WeDevs\DokanMigrator\Dependencies\Appsero\Updater::init($client);, for more details please visit: https://appsero.com/docs/appsero-developers-guide/appsero-client/appsero-sdk-updater-changes/' ); - $this->updater = new Updater( $this ); - - return $this->updater; + // initialize the new updater + if ( method_exists( '\WeDevs\DokanMigrator\Dependencies\Appsero\Updater', 'init' ) ) { + \WeDevs\DokanMigrator\Dependencies\Appsero\Updater::init( $this ); + } } /** @@ -198,7 +191,7 @@ protected function set_basename_and_slug() { require_once ABSPATH . 'wp-admin/includes/plugin.php'; - $plugin_data = get_plugin_data( $this->file ); + $plugin_data = get_plugin_data( $this->file, false, false ); $this->project_version = $plugin_data['Version']; $this->type = 'plugin'; diff --git a/dependencies/Appsero/Insights.php b/dependencies/Appsero/Insights.php index 0d57911..c862425 100644 --- a/dependencies/Appsero/Insights.php +++ b/dependencies/Appsero/Insights.php @@ -9,8 +9,7 @@ * No personal information is being tracked by this class, only general settings, active plugins, environment details * and admin email. */ -class Insights -{ +class Insights { /** * The notice text @@ -20,7 +19,7 @@ class Insights public $notice; /** - * Wheather to the notice or not + * Whether to show the notice or not * * @var bool */ @@ -31,7 +30,7 @@ class Insights * * @var array */ - protected $extra_data = []; + protected $extra_data = array(); /** * AppSero\Client @@ -41,6 +40,8 @@ class Insights protected $client; /** + * Whether to include plugin data + * * @var bool */ private $plugin_data = false; @@ -48,16 +49,16 @@ class Insights /** * Initialize the class * - * @param null $name - * @param null $file + * @param mixed $client Client object or string. + * @param string $name Name of the plugin/theme. + * @param string $file Main plugin file path. */ - public function __construct($client, $name = null, $file = null) - { - if (is_string($client) && !empty($name) && !empty($file)) { - $client = new Client($client, $name, $file); + public function __construct( $client, $name = null, $file = null ) { + if ( is_string( $client ) && ! empty( $name ) && ! empty( $file ) ) { + $client = new Client( $client, $name, $file ); } - if (is_object($client) && is_a($client, 'WeDevs\DokanMigrator\Dependencies\Appsero\Client')) { + if ( is_object( $client ) && is_a( $client, 'WeDevs\DokanMigrator\Dependencies\Appsero\Client' ) ) { $this->client = $client; } } @@ -65,10 +66,9 @@ public function __construct($client, $name = null, $file = null) /** * Don't show the notice * - * @return \self + * @return self */ - public function hide_notice() - { + public function hide_notice() { $this->show_notice = false; return $this; @@ -77,10 +77,9 @@ public function hide_notice() /** * Add plugin data if needed * - * @return \self + * @return self */ - public function add_plugin_data() - { + public function add_plugin_data() { $this->plugin_data = true; return $this; @@ -89,12 +88,11 @@ public function add_plugin_data() /** * Add extra data if needed * - * @param array $data + * @param array $data Extra data. * - * @return \self + * @return self */ - public function add_extra($data = []) - { + public function add_extra( $data = array() ) { $this->extra_data = $data; return $this; @@ -103,12 +101,11 @@ public function add_extra($data = []) /** * Set custom notice text * - * @param string $text + * @param string $text Custom notice text. * - * @return \self + * @return self */ - public function notice($text = '') - { + public function notice( $text = '' ) { $this->notice = $text; return $this; @@ -119,11 +116,10 @@ public function notice($text = '') * * @return void */ - public function init() - { - if ($this->client->type === 'plugin') { + public function init() { + if ( 'plugin' === $this->client->type ) { $this->init_plugin(); - } elseif ($this->client->type === 'theme') { + } elseif ( 'theme' === $this->client->type ) { $this->init_theme(); } } @@ -133,12 +129,11 @@ public function init() * * @return void */ - public function init_theme() - { + public function init_theme() { $this->init_common(); - add_action('switch_theme', [$this, 'deactivation_cleanup']); - add_action('switch_theme', [$this, 'theme_deactivated'], 12, 3); + add_action( 'switch_theme', array( $this, 'deactivation_cleanup' ) ); + add_action( 'switch_theme', array( $this, 'theme_deactivated' ), 12, 3 ); } /** @@ -146,21 +141,14 @@ public function init_theme() * * @return void */ - public function init_plugin() - { - // plugin deactivate popup - // if ( ! $this->is_local_server() ) { - // add_filter( 'plugin_action_links_' . $this->client->basename, [ $this, 'plugin_action_links' ] ); - // add_action( 'admin_footer', [ $this, 'deactivate_scripts' ] ); - // } - - add_filter('plugin_action_links_' . $this->client->basename, [$this, 'plugin_action_links']); - add_action('admin_footer', [$this, 'deactivate_scripts']); + public function init_plugin() { + add_filter( 'plugin_action_links_' . $this->client->basename, array( $this, 'plugin_action_links' ) ); + add_action( 'admin_footer', array( $this, 'deactivate_scripts' ) ); $this->init_common(); - register_activation_hook($this->client->file, [$this, 'activate_plugin']); - register_deactivation_hook($this->client->file, [$this, 'deactivation_cleanup']); + register_activation_hook( $this->client->file, array( $this, 'activate_plugin' ) ); + register_deactivation_hook( $this->client->file, array( $this, 'deactivation_cleanup' ) ); } /** @@ -168,49 +156,43 @@ public function init_plugin() * * @return void */ - protected function init_common() - { - if ($this->show_notice) { - // tracking notice - add_action('admin_notices', [$this, 'admin_notice']); + protected function init_common() { + if ( $this->show_notice ) { + add_action( 'admin_notices', array( $this, 'admin_notice' ) ); } - add_action('admin_init', [$this, 'handle_optin_optout']); + add_action( 'admin_init', array( $this, 'handle_optin_optout' ) ); - // uninstall reason - add_action('wp_ajax_' . $this->client->slug . '_submit-uninstall-reason', [$this, 'uninstall_reason_submission']); + add_action( 'wp_ajax_' . $this->client->slug . '_submit-uninstall-reason', array( $this, 'uninstall_reason_submission' ) ); - // cron events - add_filter('cron_schedules', [$this, 'add_weekly_schedule']); - add_action($this->client->slug . '_tracker_send_event', [$this, 'send_tracking_data']); - // add_action( 'admin_init', array( $this, 'send_tracking_data' ) ); // test + add_filter( 'cron_schedules', array( $this, 'add_weekly_schedule' ) ); + add_action( $this->client->slug . '_tracker_send_event', array( $this, 'send_tracking_data' ) ); } /** * Send tracking data to AppSero server * - * @param bool $override + * @param bool $override Whether to override the tracking allowed check. * * @return void */ - public function send_tracking_data($override = false) - { - if (!$this->tracking_allowed() && !$override) { + public function send_tracking_data( $override = false ) { + if ( ! $this->tracking_allowed() && ! $override ) { return; } - // Send a maximum of once per week + // Send a maximum of once per week. $last_send = $this->get_last_send(); - if ($last_send && $last_send > strtotime('-1 week')) { + if ( $last_send && $last_send > strtotime( '-1 week' ) ) { return; } $tracking_data = $this->get_tracking_data(); - $response = $this->client->send_request($tracking_data, 'track'); + $response = $this->client->send_request( $tracking_data, 'track' ); - update_option($this->client->slug . '_tracking_last_send', time()); + update_option( $this->client->slug . '_tracking_last_send', time() ); } /** @@ -218,88 +200,87 @@ public function send_tracking_data($override = false) * * @return array */ - protected function get_tracking_data() - { + protected function get_tracking_data() { $all_plugins = $this->get_all_plugins(); $users = get_users( - [ + array( 'role' => 'administrator', 'orderby' => 'ID', 'order' => 'ASC', 'number' => 1, 'paged' => 1, - ] + ) ); - $admin_user = (is_array($users) && !empty($users)) ? $users[0] : false; + $admin_user = ( is_array( $users ) && ! empty( $users ) ) ? $users[0] : false; $first_name = ''; $last_name = ''; - if ($admin_user) { + if ( $admin_user ) { $first_name = $admin_user->first_name ? $admin_user->first_name : $admin_user->display_name; $last_name = $admin_user->last_name; } - $data = [ - 'url' => esc_url(home_url()), + $data = array( + 'url' => esc_url( home_url() ), 'site' => $this->get_site_name(), - 'admin_email' => get_option('admin_email'), + 'admin_email' => get_option( 'admin_email' ), 'first_name' => $first_name, 'last_name' => $last_name, 'hash' => $this->client->hash, 'server' => $this->get_server_info(), 'wp' => $this->get_wp_info(), 'users' => $this->get_user_counts(), - 'active_plugins' => count($all_plugins['active_plugins']), - 'inactive_plugins' => count($all_plugins['inactive_plugins']), + 'active_plugins' => count( $all_plugins['active_plugins'] ), + 'inactive_plugins' => count( $all_plugins['inactive_plugins'] ), 'ip_address' => $this->get_user_ip_address(), 'project_version' => $this->client->project_version, 'tracking_skipped' => false, 'is_local' => $this->is_local_server(), - ]; + ); - // Add Plugins - if ($this->plugin_data) { - $plugins_data = []; + // Add Plugins. + if ( $this->plugin_data ) { + $plugins_data = array(); - foreach ($all_plugins['active_plugins'] as $slug => $plugin) { - $slug = strstr($slug, '/', true); + foreach ( $all_plugins['active_plugins'] as $slug => $plugin ) { + $slug = strstr( $slug, '/', true ); - if (!$slug) { + if ( ! $slug ) { continue; } - $plugins_data[$slug] = [ - 'name' => isset($plugin['name']) ? $plugin['name'] : '', - 'version' => isset($plugin['version']) ? $plugin['version'] : '', - ]; + $plugins_data[ $slug ] = array( + 'name' => isset( $plugin['name'] ) ? $plugin['name'] : '', + 'version' => isset( $plugin['version'] ) ? $plugin['version'] : '', + ); } - if (array_key_exists($this->client->slug, $plugins_data)) { - unset($plugins_data[$this->client->slug]); + if ( array_key_exists( $this->client->slug, $plugins_data ) ) { + unset( $plugins_data[ $this->client->slug ] ); } $data['plugins'] = $plugins_data; } - // Add Metadata + // Add Metadata. $extra = $this->get_extra_data(); - if ($extra) { + if ( $extra ) { $data['extra'] = $extra; } - // Check this has previously skipped tracking - $skipped = get_option($this->client->slug . '_tracking_skipped'); + // Check if tracking was previously skipped. + $skipped = get_option( $this->client->slug . '_tracking_skipped' ); - if ($skipped === 'yes') { - delete_option($this->client->slug . '_tracking_skipped'); + if ( 'yes' === $skipped ) { + delete_option( $this->client->slug . '_tracking_skipped' ); $data['tracking_skipped'] = true; } - return apply_filters($this->client->slug . '_tracker_data', $data); + return apply_filters( $this->client->slug . '_tracker_data', $data ); } /** @@ -307,17 +288,16 @@ protected function get_tracking_data() * * @return mixed */ - protected function get_extra_data() - { - if (is_callable($this->extra_data)) { - return call_user_func($this->extra_data); + protected function get_extra_data() { + if ( is_callable( $this->extra_data ) ) { + return call_user_func( $this->extra_data ); } - if (is_array($this->extra_data)) { + if ( is_array( $this->extra_data ) ) { return $this->extra_data; } - return []; + return array(); } /** @@ -325,19 +305,18 @@ protected function get_extra_data() * * @return array */ - protected function data_we_collect() - { - $data = [ + protected function data_we_collect() { + $data = array( 'Server environment details (php, mysql, server, WordPress versions)', 'Number of users in your site', 'Site language', 'Number of active and inactive plugins', 'Site name and URL', 'Your name and email address', - ]; + ); - if ($this->plugin_data) { - array_splice($data, 4, 0, ["active plugins' name"]); + if ( $this->plugin_data ) { + array_splice( $data, 4, 0, array( "active plugins' name" ) ); } return $data; @@ -348,11 +327,10 @@ protected function data_we_collect() * * @return bool */ - public function tracking_allowed() - { - $allow_tracking = get_option($this->client->slug . '_allow_tracking', 'no'); + public function tracking_allowed() { + $allow_tracking = get_option( $this->client->slug . '_allow_tracking', 'no' ); - return $allow_tracking === 'yes'; + return 'yes' === $allow_tracking; } /** @@ -360,9 +338,8 @@ public function tracking_allowed() * * @return false|string */ - private function get_last_send() - { - return get_option($this->client->slug . '_tracking_last_send', false); + private function get_last_send() { + return get_option( $this->client->slug . '_tracking_last_send', false ); } /** @@ -370,11 +347,10 @@ private function get_last_send() * * @return bool */ - public function notice_dismissed() - { - $hide_notice = get_option($this->client->slug . '_tracking_notice', null); + public function notice_dismissed() { + $hide_notice = get_option( $this->client->slug . '_tracking_notice', null ); - if ('hide' === $hide_notice) { + if ( 'hide' === $hide_notice ) { return true; } @@ -386,21 +362,20 @@ public function notice_dismissed() * * @return bool */ - private function is_local_server() - { - $host = isset($_SERVER['HTTP_HOST']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_HOST'])) : 'localhost'; - $ip = isset($_SERVER['SERVER_ADDR']) ? sanitize_text_field(wp_unslash($_SERVER['SERVER_ADDR'])) : '127.0.0.1'; - $is_local = false; + private function is_local_server() { + $host = isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : 'localhost'; + $ip = isset( $_SERVER['SERVER_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) ) : '127.0.0.1'; + $is_local = false; if ( - in_array($ip, ['127.0.0.1', '::1'], true) - || !strpos($host, '.') - || in_array(strrchr($host, '.'), ['.test', '.testing', '.local', '.localhost', '.localdomain'], true) + in_array( $ip, array( '127.0.0.1', '::1' ), true ) || + ! strpos( $host, '.' ) || + in_array( strrchr( $host, '.' ), array( '.test', '.testing', '.local', '.localhost', '.localdomain' ), true ) ) { $is_local = true; } - return apply_filters('appsero_is_local', $is_local); + return apply_filters( 'appsero_is_local', $is_local ); } /** @@ -408,12 +383,11 @@ private function is_local_server() * * @return void */ - private function schedule_event() - { - $hook_name = wp_unslash($this->client->slug . '_tracker_send_event'); + private function schedule_event() { + $hook_name = wp_unslash( $this->client->slug . '_tracker_send_event' ); - if (!wp_next_scheduled($hook_name)) { - wp_schedule_event(time(), 'weekly', $hook_name); + if ( ! wp_next_scheduled( $hook_name ) ) { + wp_schedule_event( time(), 'weekly', $hook_name ); } } @@ -422,9 +396,8 @@ private function schedule_event() * * @return void */ - private function clear_schedule_event() - { - wp_clear_scheduled_hook($this->client->slug . '_tracker_send_event'); + private function clear_schedule_event() { + wp_clear_scheduled_hook( $this->client->slug . '_tracker_send_event' ); } /** @@ -432,53 +405,49 @@ private function clear_schedule_event() * * @return void */ - public function admin_notice() - { - if ($this->notice_dismissed()) { + public function admin_notice() { + if ( $this->notice_dismissed() ) { return; } - if ($this->tracking_allowed()) { + if ( $this->tracking_allowed() ) { return; } - if (!current_user_can('manage_options')) { + if ( ! current_user_can( 'manage_options' ) ) { return; } - // don't show tracking if a local server - // if ( $this->is_local_server() ) { - // return; - // } + $optin_url = wp_nonce_url( add_query_arg( $this->client->slug . '_tracker_optin', 'true' ), '_wpnonce' ); + $optout_url = wp_nonce_url( add_query_arg( $this->client->slug . '_tracker_optout', 'true' ), '_wpnonce' ); - $optin_url = wp_nonce_url(add_query_arg($this->client->slug . '_tracker_optin', 'true'), '_wpnonce'); - $optout_url = wp_nonce_url(add_query_arg($this->client->slug . '_tracker_optout', 'true'), '_wpnonce'); - - if (empty($this->notice)) { - $notice = sprintf($this->client->__trans('Want to help make %1$s even more awesome? Allow %1$s to collect diagnostic data and usage information.'), $this->client->name); + if ( empty( $this->notice ) ) { + $notice = sprintf( + $this->client->__trans( 'Want to help make %1$s even more awesome? Allow %1$s to collect diagnostic data and usage information.' ), + $this->client->name + ); } else { $notice = $this->notice; } $policy_url = 'https://appsero.com/privacy-policy/'; - $notice .= ' (' . $this->client->__trans('what we collect') . ')'; - $notice .= '
'; echo ''; - echo $notice; + echo wp_kses_post( $notice ); echo '
'; - echo ' ' . $this->client->__trans('Allow') . ''; - echo ' ' . $this->client->__trans('No thanks') . ''; + echo ' ' . esc_html( $this->client->__trans( 'Allow' ) ) . ''; + echo ' ' . esc_html( $this->client->__trans( 'No thanks' ) ) . ''; echo '