diff --git a/Gruntfile.js b/Gruntfile.js index dc802beae..2e4bcacff 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -170,7 +170,19 @@ module.exports = function( grunt ) { } ] } + }, + + copy: { + main: { + options: { + mode: true + }, + src: [ + '!phpinsights.php', + ], + dest: 'header-footer-elementor/' } + }, } ); diff --git a/admin/bsf-analytics/class-bsf-analytics-loader.php b/admin/bsf-analytics/class-bsf-analytics-loader.php index de513b792..3d08ea48d 100644 --- a/admin/bsf-analytics/class-bsf-analytics-loader.php +++ b/admin/bsf-analytics/class-bsf-analytics-loader.php @@ -8,21 +8,20 @@ */ if ( ! defined( 'ABSPATH' ) ) { - exit(); + exit; } /** * Class BSF_Analytics_Loader. */ class BSF_Analytics_Loader { - /** * Analytics Entities. * * @access private * @var array Entities array. */ - private $entities = array(); + private $entities = []; /** * Analytics Version. @@ -48,33 +47,33 @@ class BSF_Analytics_Loader { */ private static $instance = null; + /** + * Constructor + */ + public function __construct() { + add_action( 'init', [ $this, 'load_analytics' ] ); + } + /** * Get instace of class. * * @return object */ public static function get_instance() { - if ( null === self::$instance ) { + if ( self::$instance === null ) { self::$instance = new self(); } return self::$instance; } - /** - * Constructor - */ - public function __construct() { - add_action( 'init', array( $this, 'load_analytics' ) ); - } - /** * Set entity for analytics. * * @param string $data Entity attributes data. * @return void */ - public function set_entity( $data ) { + public function set_entity( $data ): void { array_push( $this->entities, $data ); } @@ -83,8 +82,8 @@ public function set_entity( $data ) { * * @return void */ - public function load_analytics() { - $unique_entities = array(); + public function load_analytics(): void { + $unique_entities = []; if ( ! empty( $this->entities ) ) { foreach ( $this->entities as $entity ) { diff --git a/admin/bsf-analytics/class-bsf-analytics-stats.php b/admin/bsf-analytics/class-bsf-analytics-stats.php index 4d2b7bed3..12591b2fa 100644 --- a/admin/bsf-analytics/class-bsf-analytics-stats.php +++ b/admin/bsf-analytics/class-bsf-analytics-stats.php @@ -14,7 +14,6 @@ * BSF analytics stat class. */ class BSF_Analytics_Stats { - /** * Active plugins. * @@ -40,7 +39,7 @@ class BSF_Analytics_Stats { * @since 1.0.0 */ public static function instance() { - if ( null === self::$instance ) { + if ( self::$instance === null ) { self::$instance = new self(); } @@ -57,6 +56,24 @@ public function get_stats() { return apply_filters( 'bsf_core_stats', $this->get_default_stats() ); } + /** + * Format plugin data. + * + * @param string $plugin plugin. + * @return array formatted plugin data. + * @since 1.0.0 + */ + public function format_plugin( $plugin ) { + return [ + 'name' => html_entity_decode( $plugin['Name'], ENT_COMPAT, 'UTF-8' ), + 'url' => $plugin['PluginURI'], + 'version' => $plugin['Version'], + 'slug' => $plugin['TextDomain'], + 'author_name' => html_entity_decode( wp_strip_all_tags( $plugin['Author'] ), ENT_COMPAT, 'UTF-8' ), + 'author_url' => $plugin['AuthorURI'], + ]; + } + /** * Retrieve stats for site. * @@ -64,7 +81,7 @@ public function get_stats() { * @since 1.0.0 */ private function get_default_stats() { - return array( + return [ 'graupi_version' => defined( 'BSF_UPDATER_VERSION' ) ? BSF_UPDATER_VERSION : false, 'domain_name' => get_site_url(), 'php_os' => PHP_OS, @@ -99,7 +116,7 @@ private function get_default_stats() { 'active_theme' => get_template(), 'active_stylesheet' => get_stylesheet(), - ); + ]; } /** @@ -148,30 +165,12 @@ private function get_active_plugins() { $plugins = wp_get_active_and_valid_plugins(); $plugins = array_map( 'get_plugin_data', $plugins ); - $this->plugins = array_map( array( $this, 'format_plugin' ), $plugins ); + $this->plugins = array_map( [ $this, 'format_plugin' ], $plugins ); } return $this->plugins; } - /** - * Format plugin data. - * - * @param string $plugin plugin. - * @return array formatted plugin data. - * @since 1.0.0 - */ - public function format_plugin( $plugin ) { - return array( - 'name' => html_entity_decode( $plugin['Name'], ENT_COMPAT, 'UTF-8' ), - 'url' => $plugin['PluginURI'], - 'version' => $plugin['Version'], - 'slug' => $plugin['TextDomain'], - 'author_name' => html_entity_decode( wp_strip_all_tags( $plugin['Author'] ), ENT_COMPAT, 'UTF-8' ), - 'author_url' => $plugin['AuthorURI'], - ); - } - /** * Curl SSL version. * @@ -179,12 +178,12 @@ public function format_plugin( $plugin ) { * @since 1.0.0 */ private function get_curl_ssl_version() { - $curl = array(); + $curl = []; if ( function_exists( 'curl_version' ) ) { $curl = curl_version(); // phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_version } - return isset( $curl['ssl_version'] ) ? $curl['ssl_version'] : false; + return $curl['ssl_version'] ?? false; } /** @@ -198,7 +197,7 @@ private function get_curl_version() { $curl = curl_version(); // phpcs:ignore WordPress.WP.AlternativeFunctions.curl_curl_version } - return isset( $curl['version'] ) ? $curl['version'] : false; + return $curl['version'] ?? false; } /** @@ -244,13 +243,11 @@ function wp_timezone_string() { $offset = (float) get_option( 'gmt_offset' ); $hours = (int) $offset; - $minutes = ( $offset - $hours ); + $minutes = $offset - $hours; - $sign = ( $offset < 0 ) ? '-' : '+'; + $sign = $offset < 0 ? '-' : '+'; $abs_hour = abs( $hours ); $abs_mins = abs( $minutes * 60 ); - $tz_offset = sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins ); - - return $tz_offset; + return sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins ); } } diff --git a/admin/bsf-analytics/class-bsf-analytics.php b/admin/bsf-analytics/class-bsf-analytics.php index ebf78b1ad..a3c97d835 100644 --- a/admin/bsf-analytics/class-bsf-analytics.php +++ b/admin/bsf-analytics/class-bsf-analytics.php @@ -17,20 +17,18 @@ * BSF analytics */ class BSF_Analytics { - /** * Member Variable * - * @var array Entities data. + * @var string Usage tracking document URL */ - private $entities; - + public $usage_doc_link = 'https://store.brainstormforce.com/usage-tracking/?utm_source=wp_dashboard&utm_medium=general_settings&utm_campaign=usage_tracking'; /** * Member Variable * - * @var string Usage tracking document URL + * @var array Entities data. */ - public $usage_doc_link = 'https://store.brainstormforce.com/usage-tracking/?utm_source=wp_dashboard&utm_medium=general_settings&utm_campaign=usage_tracking'; + private $entities; /** * Setup actions, load files. @@ -53,13 +51,13 @@ public function __construct( $args, $analytics_path, $analytics_version ) { define( 'BSF_ANALYTICS_VERSION', $analytics_version ); define( 'BSF_ANALYTICS_URI', $this->get_analytics_url( $analytics_path ) ); - add_action( 'admin_init', array( $this, 'handle_optin_optout' ) ); - add_action( 'admin_notices', array( $this, 'option_notice' ) ); - add_action( 'init', array( $this, 'maybe_track_analytics' ), 99 ); + add_action( 'admin_init', [ $this, 'handle_optin_optout' ] ); + add_action( 'admin_notices', [ $this, 'option_notice' ] ); + add_action( 'init', [ $this, 'maybe_track_analytics' ], 99 ); $this->set_actions(); - add_action( 'admin_init', array( $this, 'register_usage_tracking_setting' ) ); + add_action( 'admin_init', [ $this, 'register_usage_tracking_setting' ] ); $this->includes(); } @@ -70,12 +68,12 @@ public function __construct( $args, $analytics_path, $analytics_version ) { * @since 1.0.4 * @return void */ - public function set_actions() { + public function set_actions(): void { foreach ( $this->entities as $key => $data ) { - add_action( 'astra_notice_before_markup_' . $key . '-optin-notice', array( $this, 'enqueue_assets' ) ); - add_action( 'update_option_' . $key . '_analytics_optin', array( $this, 'update_analytics_option_callback' ), 10, 3 ); - add_action( 'add_option_' . $key . '_analytics_optin', array( $this, 'add_analytics_option_callback' ), 10, 2 ); + add_action( 'astra_notice_before_markup_' . $key . '-optin-notice', [ $this, 'enqueue_assets' ] ); + add_action( 'update_option_' . $key . '_analytics_optin', [ $this, 'update_analytics_option_callback' ], 10, 3 ); + add_action( 'add_option_' . $key . '_analytics_optin', [ $this, 'add_analytics_option_callback' ], 10, 2 ); } } @@ -95,32 +93,22 @@ public function get_analytics_url( $analytics_path ) { return str_replace( $content_dir_path, content_url(), $analytics_path ); } - /** - * Get API URL for sending analytics. - * - * @return string API URL. - * @since 1.0.0 - */ - private function get_api_url() { - return defined( 'BSF_API_URL' ) ? BSF_API_URL : 'https://support.brainstormforce.com/'; - } - /** * Enqueue Scripts. * * @since 1.0.0 * @return void */ - public function enqueue_assets() { + public function enqueue_assets(): void { /** * Load unminified if SCRIPT_DEBUG is true. * * Directory and Extensions. */ - $dir_name = ( SCRIPT_DEBUG ) ? 'unminified' : 'minified'; - $file_rtl = ( is_rtl() ) ? '-rtl' : ''; - $css_ext = ( SCRIPT_DEBUG ) ? '.css' : '.min.css'; + $dir_name = SCRIPT_DEBUG ? 'unminified' : 'minified'; + $file_rtl = is_rtl() ? '-rtl' : ''; + $css_ext = SCRIPT_DEBUG ? '.css' : '.min.css'; $css_uri = BSF_ANALYTICS_URI . '/assets/css/' . $dir_name . '/style' . $file_rtl . $css_ext; @@ -133,14 +121,14 @@ public function enqueue_assets() { * @since 1.0.0 * @return void */ - public function send() { + public function send(): void { wp_remote_post( $this->get_api_url() . 'wp-json/bsf-core/v1/analytics/', - array( + [ 'body' => BSF_Analytics_Stats::instance()->get_stats(), 'timeout' => 5, 'blocking' => false, - ) + ] ); } @@ -174,12 +162,12 @@ public function is_tracking_enabled() { */ public function is_white_label_enabled( $source ) { - $options = apply_filters( $source . '_white_label_options', array() ); + $options = apply_filters( $source . '_white_label_options', [] ); $is_enabled = false; if ( is_array( $options ) ) { foreach ( $options as $option ) { - if ( true === $option ) { + if ( $option === true ) { $is_enabled = true; break; } @@ -195,7 +183,7 @@ public function is_white_label_enabled( $source ) { * @since 1.0.0 * @return void */ - public function option_notice() { + public function option_notice(): void { if ( ! current_user_can( 'manage_options' ) ) { return; @@ -203,11 +191,11 @@ public function option_notice() { foreach ( $this->entities as $key => $data ) { - $time_to_display = isset( $data['time_to_display'] ) ? $data['time_to_display'] : '+24 hours'; - $usage_doc_link = isset( $data['usage_doc_link'] ) ? $data['usage_doc_link'] : $this->usage_doc_link; + $time_to_display = $data['time_to_display'] ?? '+24 hours'; + $usage_doc_link = $data['usage_doc_link'] ?? $this->usage_doc_link; // Don't display the notice if tracking is disabled or White Label is enabled for any of our plugins. - if ( false !== get_site_option( $key . '_analytics_optin', false ) || $this->is_white_label_enabled( $key ) ) { + if ( get_site_option( $key . '_analytics_optin', false ) !== false || $this->is_white_label_enabled( $key ) ) { continue; } @@ -226,7 +214,7 @@ public function option_notice() { $language_dir = is_rtl() ? 'rtl' : 'ltr'; Astra_Notices::add_notice( - array( + [ 'id' => $key . '-optin-notice', 'type' => '', 'message' => sprintf( @@ -246,19 +234,19 @@ public function option_notice() { /* translators: %s usage doc link */ sprintf( $notice_string . '%4s', esc_html( $data['product_name'] ), $language_dir, esc_url( $usage_doc_link ), __( ' Know More.', 'header-footer-elementor' ) ), add_query_arg( - array( + [ $key . '_analytics_optin' => 'yes', $key . '_analytics_nonce' => wp_create_nonce( $key . '_analytics_optin' ), 'bsf_analytics_source' => $key, - ) + ] ), __( 'Yes! Allow it', 'header-footer-elementor' ), add_query_arg( - array( + [ $key . '_analytics_optin' => 'no', $key . '_analytics_nonce' => wp_create_nonce( $key . '_analytics_optin' ), 'bsf_analytics_source' => $key, - ) + ] ), MONTH_IN_SECONDS, __( 'No Thanks', 'header-footer-elementor' ) @@ -267,7 +255,7 @@ public function option_notice() { 'repeat-notice-after' => false, 'priority' => 18, 'display-with-other-notices' => true, - ) + ] ); } } @@ -278,7 +266,7 @@ public function option_notice() { * @since 1.0.0 * @return void */ - public function handle_optin_optout() { + public function handle_optin_optout(): void { if ( ! current_user_can( 'manage_options' ) ) { return; @@ -296,62 +284,30 @@ public function handle_optin_optout() { $optin_status = isset( $_GET[ $source . '_analytics_optin' ] ) ? sanitize_text_field( wp_unslash( $_GET[ $source . '_analytics_optin' ] ) ) : ''; - if ( 'yes' === $optin_status ) { + if ( $optin_status === 'yes' ) { $this->optin( $source ); - } elseif ( 'no' === $optin_status ) { + } elseif ( $optin_status === 'no' ) { $this->optout( $source ); } wp_safe_redirect( remove_query_arg( - array( + [ $source . '_analytics_optin', $source . '_analytics_nonce', 'bsf_analytics_source', - ) + ] ) ); } - /** - * Opt in to usage tracking. - * - * @param string $source source of analytics. - * @since 1.0.0 - * @return void - */ - private function optin( $source ) { - update_site_option( $source . '_analytics_optin', 'yes' ); - } - - /** - * Opt out to usage tracking. - * - * @param string $source source of analytics. - * @since 1.0.0 - * @return void - */ - private function optout( $source ) { - update_site_option( $source . '_analytics_optin', 'no' ); - } - - /** - * Load analytics stat class. - * - * @since 1.0.0 - * @return void - */ - private function includes() { - require_once __DIR__ . '/class-bsf-analytics-stats.php'; - } - /** * Register usage tracking option in General settings page. * * @since 1.0.0 * @return void */ - public function register_usage_tracking_setting() { + public function register_usage_tracking_setting(): void { foreach ( $this->entities as $key => $data ) { @@ -359,29 +315,29 @@ public function register_usage_tracking_setting() { return; } - $usage_doc_link = isset( $data['usage_doc_link'] ) ? $data['usage_doc_link'] : $this->usage_doc_link; - $author = isset( $data['author'] ) ? $data['author'] : 'Brainstorm Force'; + $usage_doc_link = $data['usage_doc_link'] ?? $this->usage_doc_link; + $author = $data['author'] ?? 'Brainstorm Force'; register_setting( 'general', // Options group. $key . '_analytics_optin', // Option name/database. - array( 'sanitize_callback' => array( $this, 'sanitize_option' ) ) // sanitize callback function. + [ 'sanitize_callback' => [ $this, 'sanitize_option' ] ] // sanitize callback function. ); add_settings_field( $key . '-analytics-optin', // Field ID. __( 'Usage Tracking', 'header-footer-elementor' ), // Field title. - array( $this, 'render_settings_field_html' ), // Field callback function. + [ $this, 'render_settings_field_html' ], // Field callback function. 'general', 'default', // Settings page slug. - array( + [ 'type' => 'checkbox', 'title' => $author, 'name' => $key . '_analytics_optin', 'label_for' => $key . '-analytics-optin', 'id' => $key . '-analytics-optin', 'usage_doc_link' => $usage_doc_link, - ) + ] ); } } @@ -395,7 +351,7 @@ public function register_usage_tracking_setting() { */ public function sanitize_option( $input ) { - if ( ! $input || 'no' === $input ) { + if ( ! $input || $input === 'no' ) { return 'no'; } @@ -409,7 +365,7 @@ public function sanitize_option( $input ) { * @since 1.0.0 * @return void */ - public function render_settings_field_html( $args ) { + public function render_settings_field_html( $args ): void { ?>