id || $dashboard_screen_id . '-network' === $current_screen->id ) ) { \wp_enqueue_style( 'advan-dashboard-style', \ADVAN_PLUGIN_ROOT_URL . 'css/admin/dashboard.css', array( 'advan-admin-style' ), \ADVAN_VERSION, 'all' ); \wp_enqueue_script( 'advan-dashboard-js', \ADVAN_PLUGIN_ROOT_URL . 'js/admin/dashboard.js', array(), \ADVAN_VERSION, true ); \wp_localize_script( 'advan-dashboard-js', 'advanDashboard', array( 'ajaxUrl' => \admin_url( 'admin-ajax.php' ), 'ajaxAction' => ADVAN_PREFIX . 'toggle_module', ) ); } \wp_enqueue_script( 'wp-api-fetch' ); // Exporting CSV start. \wp_enqueue_style( 'oda-admin-export-style', ADVAN_PLUGIN_ROOT_URL . 'css/admin-export-csv.css', array(), '1.1' ); \wp_enqueue_script( 'aadvana-admin-export-js', ADVAN_PLUGIN_ROOT_URL . 'js/admin-export-csv.js', array(), '1.1', true ); \wp_localize_script( 'aadvana-admin-export-js', 'aadvanaExport', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'export_large_csv_nonce' ), 'i18n' => array( 'starting' => __( 'Starting export...', '0-day-analytics' ), 'exporting' => __( 'Exporting...', '0-day-analytics' ), 'completed' => __( '✅ Export complete! Downloading...', '0-day-analytics' ), 'cancelled' => __( '❌ Export cancelled.', '0-day-analytics' ), 'networkError' => __( 'Network error', '0-day-analytics' ), 'error' => __( 'Error during export:', '0-day-analytics' ), 'unauthorized' => __( 'Unauthorized', '0-day-analytics' ), 'csvExportBtnTitle' => __( 'CSV Export', '0-day-analytics' ), ), ) ); // Exporting CSV end. ?> 'text/plain', 'codemirror' => array( 'indentUnit' => 4, 'tabSize' => 4, 'theme' => 'cobalt', ), ) ); // Bail if user disabled CodeMirror. if ( false === $settings ) { return; } // Target the textarea. \wp_add_inline_script( 'code-editor', sprintf( 'jQuery( function() { wp.codeEditor.initialize( "transient-editor", %s ); } );', \wp_json_encode( $settings ) ) ); // Custom styling. \wp_add_inline_style( 'code-editor', '.CodeMirror-wrap { width: 99%; border: 1px solid #8c8f94; border-radius: 3px; overflow: hidden; } .CodeMirror-gutters { background: transparent; }' ); } } /** * Returns the current options. * Fills the current options array with values if empty. * * @return array * * @since 1.1.0 */ public static function get_current_options(): array { if ( empty( self::$current_options ) ) { // Get the current settings or setup some defaults if needed. self::$current_options = \get_option( ADVAN_SETTINGS_NAME ); if ( ! self::$current_options ) { self::$current_options = self::get_default_options(); // Ensure sensitive fields are stored encrypted at rest. $to_store = self::$current_options; Secure_Store::encrypt_sensitive_fields( $to_store ); self::store_options( $to_store ); } // Ensure any missing default options are set. Persist only when we added keys. $defaults = self::get_default_options(); $added = false; foreach ( $defaults as $key => $value ) { if ( ! isset( self::$current_options[ $key ] ) ) { self::$current_options[ $key ] = $value; $added = true; } } if ( $added ) { $to_store = self::$current_options; Secure_Store::encrypt_sensitive_fields( $to_store ); self::store_options( $to_store ); } // Decrypt sensitive fields for runtime and migrate legacy plaintext on the fly. if ( is_array( self::$current_options ) ) { $migrated = Secure_Store::decrypt_sensitive_fields( self::$current_options ); if ( $migrated ) { $to_store = self::$current_options; Secure_Store::encrypt_sensitive_fields( $to_store ); self::store_options( $to_store ); } } } return self::$current_options; } /** * Returns current option or one stored in the defaults if not present in the current options. * * @param string $option - The name of the option to return value for. * * @return mixed * * @since 2.8.0 */ public static function get_option( string $option ) { $current = self::get_current_options(); if ( ! isset( $current[ $option ] ) ) { $current = self::get_default_options(); if ( ! isset( $current[ $option ] ) ) { return null; } } return $current[ $option ]; } /** * Stores the options in the database * * @param array $options - The array with the options to store. * * @return void * * @since 1.1.0 */ public static function store_options( array $options ): void { global $wpdb; // Ensure option exists with autoload = no (prevents loading secrets on every request). if ( false === \get_option( ADVAN_SETTINGS_NAME, false ) ) { \add_option( ADVAN_SETTINGS_NAME, $options, '', 'no' ); return; } \update_option( ADVAN_SETTINGS_NAME, $options ); // Force autoload = no for existing installs. $wpdb->update( $wpdb->options, array( 'autoload' => 'no' ), array( 'option_name' => ADVAN_SETTINGS_NAME ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery } /** * Returns the default plugin options * * @return array * * @since 1.1.0 */ public static function get_default_options(): array { if ( empty( self::$default_options ) ) { // Define default options. self::$default_options = array( 'live_notifications_admin_bar' => true, 'environment_type_admin_bar' => true, 'protected_config_source' => true, 'keep_reading_error_log' => false, 'plugin_debug_enable' => false, 'plugin_exception_handler_disable' => false, 'advana_requests_enable' => true, 'advana_http_requests_disable' => false, 'advana_rest_requests_disable' => false, 'no_rest_api_monitor' => false, 'no_wp_die_monitor' => false, 'advana_server_info_admin_bar_refresh_interval' => 10, 'keep_error_log_records_truncate' => 10, 'plugin_version_switch_count' => 3, 'cron_module_enabled' => true, 'performance_module_enabled' => true, 'pagespeed_api_key' => '', 'urls_module_enabled' => true, 'advana_urls_enable' => true, 'file_editor_module_enabled' => false, 'show_active_plugins_first' => true, 'requests_module_enabled' => true, 'fatals_module_enabled' => true, 'wp_mail_module_enabled' => true, 'transients_module_enabled' => true, 'tables_module_enabled' => true, 'snippets_module_enabled' => true, 'snippets_temp_storage' => 'uploads', 'hooks_capture_module_enabled' => true, 'advana_hooks_capture_clear' => 'weekly', 'rest_api_module_enabled' => true, 'wp_panel_module_enabled' => true, 'server_info_module_enabled' => true, 'traffic_analytics_module_enabled' => true, 'traffic_tracking_method' => 'server', 'traffic_exclude_admins' => true, 'traffic_retention_days' => 365, 'login_auditor_module_enabled' => true, 'advana_login_auditor_enable' => true, 'login_audit_retention_days' => 90, 'security_module_enabled' => true, 'advana_security_rate_limit_enable' => true, 'advana_security_priv_guard_enable' => true, 'advana_security_incident_detect_enable' => true, 'advana_security_block_user_enum' => true, 'advana_security_auto_lockdown' => true, 'advana_security_email_alerts' => true, 'security_trust_proxy_headers' => false, 'security_rate_limit_per_minute' => 1200, 'security_burst_limit' => 15, 'security_login_rate_limit' => 5, 'security_block_duration' => 300, 'security_event_retention_days' => 90, 'security_ddos_ip_threshold' => 50, 'security_ddos_window_minutes' => 5, 'security_brute_force_threshold' => 20, 'security_brute_force_window_minutes' => 10, 'security_escalation_threshold' => 3, 'security_escalation_window_minutes' => 30, 'security_lockdown_duration_minutes' => 30, 'advana_server_info_mem_enable' => true, 'advana_server_info_hdd_enable' => true, 'advana_server_info_cpu_enable' => true, 'advana_rest_requests_clear' => 'weekly', 'advana_urls_clear' => 'weekly', 'advana_mail_logging_clear' => 'weekly', 'advana_error_log_clear' => '-1', 'browser_notifications_seconds' => 10, 'browser_notifications_not_send' => false, 'from_email' => '', 'from_email_name' => '', 'smtp_host' => '', 'smtp_port' => '', 'smtp_username' => '', 'smtp_password' => '', 'encryption_type' => 'none', 'bypass_ssl_verification' => false, 'slack_notifications' => array( 'all' => array( 'channel' => '', 'auth_token' => '', ), ), 'telegram_notifications' => array( 'all' => array( 'channel' => '', 'auth_token' => '', ), ), 'severities' => array( 'deprecated' => array( 'name' => __( 'Deprecated', '0-day-analytics' ), 'color' => '#c4b576', 'display' => true, ), 'error' => array( 'name' => __( 'Error', '0-day-analytics' ), 'color' => '#ffb3b3', 'display' => true, ), 'success' => array( 'name' => __( 'Success', '0-day-analytics' ), 'color' => '#00ff00', 'display' => true, ), 'info' => array( 'name' => __( 'Info', '0-day-analytics' ), 'color' => '#aeaeec', 'display' => true, ), 'notice' => array( 'name' => __( 'Notice', '0-day-analytics' ), 'color' => '#feeb8e', 'display' => true, ), 'warning' => array( 'name' => __( 'Warning', '0-day-analytics' ), 'color' => '#ffff00', 'display' => true, ), 'fatal' => array( 'name' => __( 'Fatal', '0-day-analytics' ), 'color' => '#f09595', 'display' => true, ), 'parse' => array( 'name' => __( 'Parse', '0-day-analytics' ), 'color' => '#e3bb8d', 'display' => true, ), 'user' => array( 'name' => __( 'User', '0-day-analytics' ), 'color' => '#85b395', 'display' => true, ), 'not set' => array( 'name' => __( 'Not Set', '0-day-analytics' ), 'color' => '#7a6f72', 'display' => true, ), 'request' => array( 'name' => __( 'Request', '0-day-analytics' ), 'color' => '#759b71', 'display' => true, ), 'rest_no_route' => array( 'name' => __( 'Rest No Route', '0-day-analytics' ), 'color' => '#759b71', 'display' => true, ), 'rest_forbidden' => array( 'name' => __( 'Rest Forbidden', '0-day-analytics' ), 'color' => '#759b71', 'display' => true, ), ), ); } return self::$default_options; } /** * Returns the stored main menu hook * * @return string * * @since 1.1.0 */ public static function get_main_menu_page_hook() { return self::$hook; } /** * Add to Admin * * Add the options page to the admin menu * * @since 1.1.0 */ public static function add_options_page() { if ( ! \current_user_can( 'manage_options' ) ) { return; } else { $base = 'base'; $base .= '64_en'; $base .= 'code'; $icon = ''; if ( \file_exists( \ADVAN_PLUGIN_ROOT . 'assets/icon.svg' ) ) { $icon = 'data:image/svg+xml;base64,' . $base( file_get_contents( \ADVAN_PLUGIN_ROOT . 'assets/icon.svg' ) ); } self::$hook = \add_menu_page( ADVAN_INNER_NAME, ADVAN_INNER_NAME . self::get_updates_count_html(), 'manage_options', Logs_List::MENU_SLUG, array( Dashboard_View::class, 'render' ), $icon, 3 ); \register_setting( \ADVAN_SETTINGS_NAME, \ADVAN_SETTINGS_NAME, array( self::class, 'collect_and_sanitize_options', ) ); \add_submenu_page( Logs_List::MENU_SLUG, ADVAN_INNER_NAME, \esc_html__( 'Dashboard', '0-day-analytics' ), 'manage_options', Logs_List::MENU_SLUG, array( Dashboard_View::class, 'render' ), 0 ); $error_log_hook = \add_submenu_page( Logs_List::MENU_SLUG, ADVAN_INNER_NAME, \esc_html__( 'Error Log viewer', '0-day-analytics' ), 'manage_options', 'advan_error_log', array( Logs_List_View::class, 'render' ), 1 ); \add_filter( 'manage_' . $error_log_hook . '_columns', array( Logs_List::class, 'manage_columns' ) ); Logs_List::add_screen_options( $error_log_hook ); if ( self::get_option( 'server_info_module_enabled' ) ) { \add_submenu_page( Logs_List::MENU_SLUG, __( 'Server Info', '0-day-analytics' ), __( 'Server Info', '0-day-analytics' ), 'manage_options', 'advan_system_analytics', array( System_Analytics::class, 'render_admin_page' ), 3 ); } /* WP Panel start */ if ( self::get_option( 'wp_panel_module_enabled' ) ) { WP_Panel::menu_add(); } /* WP Panel end */ /* Fatals start */ if ( self::get_option( 'fatals_module_enabled' ) ) { Fatals_List::menu_add(); } /* Fatals end */ /* Crons start */ if ( self::get_option( 'cron_module_enabled' ) ) { Crons_List::menu_add(); } /* Crons end */ /* Performance start */ if ( self::get_option( 'performance_module_enabled' ) ) { Performance_View::menu_add(); } /* Performance end */ /* Transients */ if ( self::get_option( 'transients_module_enabled' ) ) { Transients_List::menu_add(); } /* Transients end */ /* WP Mail start */ if ( self::get_option( 'wp_mail_module_enabled' ) ) { WP_Mail_List::menu_add(); } /* WP Mail end */ /* Snippets start */ if ( self::get_option( 'snippets_module_enabled' ) ) { Snippets_List::menu_add(); } /* Snippets end */ /* Table */ if ( self::get_option( 'tables_module_enabled' ) ) { Table_List::menu_add(); } /* Table end */ /* REST API start */ if ( self::get_option( 'rest_api_module_enabled' ) ) { Rest_Api_List::menu_add(); } /* REST API end */ /* Hooks Capture start */ if ( self::get_option( 'hooks_capture_module_enabled' ) ) { \ADVAN\Lists\Hooks_Capture_List::menu_add(); \ADVAN\Lists\Hooks_Management_List::menu_add(); } /* Hooks Capture end */ /* Requests start */ if ( self::get_option( 'requests_module_enabled' ) ) { Requests_List::menu_add(); } /* Requests end */ /* File Editor start */ if ( self::get_option( 'file_editor_module_enabled' ) ) { File_Editor::menu_add(); } /* File Editor end */ /* Traffic Analytics start */ if ( self::get_option( 'traffic_analytics_module_enabled' ) ) { Traffic_Analytics_View::menu_add(); } /* Traffic Analytics end */ /* Security start */ if ( self::get_option( 'security_module_enabled' ) ) { Security_List::menu_add(); } /* Security end */ /* Login Audit start */ if ( self::get_option( 'login_auditor_module_enabled' ) ) { Login_Audit_List::menu_add(); } /* Login Audit end */ if ( ! is_a( WP_Helper::check_debug_status(), '\WP_Error' ) && ! is_a( WP_Helper::check_debug_log_status(), '\WP_Error' ) && self::get_option( 'live_notifications_admin_bar' ) ) { \add_action( 'admin_bar_menu', array( __CLASS__, 'live_notifications' ), 1000, 1 ); \add_action( 'admin_enqueue_scripts', function() { \wp_enqueue_script( self::LIVE_NOTIF_JS_MODULE, \ADVAN_PLUGIN_ROOT_URL . 'js/admin/endpoints.js', array( 'wp-api-fetch', 'wp-dom-ready', 'wp-i18n' ), \ADVAN_VERSION, array( 'in_footer' => true ) ); } ); } \add_action( 'admin_footer', array( __CLASS__, 'show_error_count' ), \PHP_INT_MAX ); \add_action( 'load-' . $error_log_hook, array( __CLASS__, 'aadvana_common_help' ) ); $settings_hook = \add_submenu_page( Logs_List::MENU_SLUG, \esc_html__( 'Settings', '0-day-analytics' ), \esc_html__( 'Settings', '0-day-analytics' ), 'manage_options', // No capability requirement. self::SETTINGS_MENU_SLUG, array( __CLASS__, 'aadvana_show_options' ), 301 ); \add_action( 'load-' . $settings_hook, array( __CLASS__, 'aadvana_settings_help' ) ); if ( ! self::is_plugin_settings_page() ) { return; } Settings_Export_Import::process_requests(); } } /** * Return the updates count markup. * * @return string Updates count markup, empty string if no updates available. * * @since 1.1.0 */ public static function get_updates_count_html(): string { $count_html = sprintf( ' ', '' // \number_format_i18n( $count ) ); return $count_html; } /** * Add Options Help * * Add help tab to options screen * * @since 1.1.0 */ public static function aadvana_common_help() { $screen = WP_Helper::get_wp_screen(); $suffix = ''; if ( WP_Helper::is_multisite() ) { $suffix = '-network'; } if ( Logs_List::PAGE_SLUG . $suffix === $screen->base || Logs_List::PAGE_SLUG === $screen->base ) { $screen->add_help_tab( array( 'id' => 'advanced-analytics-help-tab', 'title' => __( 'Help', '0-day-analytics' ), 'content' => self::add_help_content_error_log(), ) ); } if ( Transients_List::PAGE_SLUG . $suffix === $screen->base || Transients_List::PAGE_SLUG === $screen->base ) { $screen->add_help_tab( array( 'id' => 'advanced-analytics-help-tab', 'title' => __( 'Help', '0-day-analytics' ), 'content' => Transients_View::add_help_content_transients(), ) ); } if ( Crons_List::PAGE_SLUG . $suffix === $screen->base || Crons_List::PAGE_SLUG === $screen->base ) { $screen->add_help_tab( array( 'id' => 'advanced-analytics-help-tab', 'title' => __( 'Help', '0-day-analytics' ), 'content' => Crons_View::add_help_content_crons(), ) ); } if ( Table_List::PAGE_SLUG . $suffix === $screen->base || Table_List::PAGE_SLUG === $screen->base ) { $screen->add_help_tab( array( 'id' => 'advanced-analytics-help-tab', 'title' => __( 'Table Info', '0-day-analytics' ), 'content' => Table_View::add_config_content_table(), ) ); $screen->add_help_tab( array( 'id' => 'advanced-analytics-info-tab', 'title' => __( 'Help', '0-day-analytics' ), 'content' => Table_View::add_help_content_table(), ) ); } if ( Requests_List::PAGE_SLUG . $suffix === $screen->base || Requests_List::PAGE_SLUG === $screen->base ) { $screen->add_help_tab( array( 'id' => 'advanced-analytics-help-tab', 'title' => __( 'Requests Table Info', '0-day-analytics' ), 'content' => Requests_View::add_config_content_table(), ) ); $screen->add_help_tab( array( 'id' => 'advanced-analytics-info-tab', 'title' => __( 'Help', '0-day-analytics' ), 'content' => Requests_View::add_help_content_table(), ) ); } if ( WP_Mail_List::PAGE_SLUG . $suffix === $screen->base || WP_Mail_List::PAGE_SLUG === $screen->base ) { $screen->add_help_tab( array( 'id' => 'advanced-analytics-help-tab', 'title' => __( 'WP Mail Log Table Info', '0-day-analytics' ), 'content' => WP_Mail_View::add_config_content_table(), ) ); $screen->add_help_tab( array( 'id' => 'advanced-analytics-info-tab', 'title' => __( 'Help', '0-day-analytics' ), 'content' => WP_Mail_View::add_help_content_table(), ) ); } if ( Fatals_List::PAGE_SLUG . $suffix === $screen->base || Fatals_List::PAGE_SLUG === $screen->base ) { $screen->add_help_tab( array( 'id' => 'advanced-analytics-help-tab', 'title' => __( 'WP Mail Log Table Info', '0-day-analytics' ), 'content' => Fatals_View::add_config_content_table(), ) ); $screen->add_help_tab( array( 'id' => 'advanced-analytics-info-tab', 'title' => __( 'Help', '0-day-analytics' ), 'content' => Fatals_View::add_help_content_table(), ) ); } $screen->set_help_sidebar( self::add_sidebar_content() ); } /** * Add Options Help * * Add help tab to options screen * * @since 1.1.0 */ public static function aadvana_settings_help() { $add_style = ' '; $screen = WP_Helper::get_wp_screen(); $screen->add_help_tab( array( 'id' => 'advanced-analytics-help-tab', 'title' => __( 'Help', '0-day-analytics' ), 'content' => $add_style . self::add_help_content(), ) ); $screen->set_help_sidebar( self::add_sidebar_content() ); } /** * Options Help * * Return help text for options screen * * @return string Help Text * * @since 1.9.8.1 */ public static function add_help_content_error_log() { $help_text = '
' . __( 'This screen allows you to see last occurred records (last are first), check their sources, see the code responsible / involved in given error.', '0-day-analytics' ) . '
'; $help_text .= '' . __( 'You can specify how many errors to be shown (up to 100), which columns to see or filter error by severity.', '0-day-analytics' ) . '
'; $help_text .= '' . __( 'You can truncate error log (clear it) or truncate it but leave last records (from settings you can specify how many records you want to be kept).', '0-day-analytics' ) . '
'; $help_text .= '' . __( 'Right under the list, there is a console-like window where you can see the raw error list, everything you select there (with mouse) is automatically copied in you clipboard, so you can use it in chat channel or share it easily.', '0-day-analytics' ) . '
'; $help_text .= '' . __( 'You can see the size of your log file and download it if you need to.', '0-day-analytics' ) . '
'; return $help_text; } /** * Options Help * * Return help text for options screen * * @return string Help Text * * @since 1.1.0 */ public static function add_help_content() { $help_text = '' . __( 'This screen allows you to specify the options for the 0 Day Analytics plugin.', '0-day-analytics' ) . '
'; $help_text .= '' . __( 'Here adjust the plugin to your specific needs.', '0-day-analytics' ) . '
'; $help_text .= '' . __( 'Remember to click the Save Changes button when on settings page for new settings to take effect.', '0-day-analytics' ) . '
'; return $help_text; } /** * Options Help Sidebar * * Add a links sidebar to the options help * * @return string Help Text * * @since 1.1.0 */ public static function add_sidebar_content() { $help_text = '' . __( 'For more information:', '0-day-analytics' ) . '
'; $help_text .= '' . __( 'Instructions', '0-day-analytics' ) . '
'; $help_text .= '' . __( 'Support Forum', '0-day-analytics' ) . '
'; return $help_text; } /** * Shows the save button in the settings * * @return void * * @since 1.1.0 */ public static function save_button() { Settings_Page_Renderer::save_button(); } /** * The Settings Panel UI * * @return void * * @since 1.1.0 */ public static function aadvana_show_options() { Settings_Page_Renderer::render(); } /** * The settings panel option tabs. * * @return array * * @since 1.1.0 */ public static function build_options_tabs(): array { return Settings_Page_Renderer::build_options_tabs(); } /** * Creates an option and draws it * * @param array $value - The array with option data. * * @return void * * @since 1.1.0 */ public static function build_option( array $value ) { $data = null; if ( empty( $value['id'] ) ) { $value['id'] = ' '; } if ( isset( self::get_current_options()[ $value['id'] ] ) ) { $data = self::get_current_options()[ $value['id'] ]; } Settings_Builder::create( $value, \ADVAN_SETTINGS_NAME . '[' . $value['id'] . ']', $data ); } /** * Setter method for the current options * * @param array $options - Array with the options to store. * * @return array * * @since 1.1.0 */ public static function set_current_options( array $options ) { return self::$current_options = $options; // phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found } /** * Checks if current page is plugin settings page * * @return boolean * * @since 1.1.0 */ public static function is_plugin_settings_page() { $current_page = ! empty( $_REQUEST['page'] ) ? \sanitize_text_field( \wp_unslash( $_REQUEST['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended return Logs_List::MENU_SLUG === $current_page || 'advan_error_log' === $current_page || self::OPTIONS_PAGE_SLUG === $current_page || Crons_List::CRON_MENU_SLUG === $current_page || Transients_List::TRANSIENTS_MENU_SLUG === $current_page || Table_List::TABLE_MENU_SLUG === $current_page || self::SETTINGS_MENU_SLUG === $current_page || Requests_List::REQUESTS_MENU_SLUG === $current_page || WP_Mail_List::WP_MAIL_MENU_SLUG === $current_page || Fatals_List::FATALS_MENU_SLUG === $current_page || System_Analytics::SYS_MENU_SLUG === $current_page || File_Editor::FILE_EDITOR_MENU_SLUG === $current_page || Snippets_List::MENU_SLUG === $current_page || Hooks_Management_List::MENU_SLUG === $current_page || Hooks_Capture_List::MENU_SLUG === $current_page || Performance_View::MENU_SLUG === $current_page || Rest_Api_List::MENU_SLUG === $current_page || WP_Panel::MENU_SLUG === $current_page || Traffic_Analytics_View::MENU_SLUG === $current_page || Security_View::MENU_SLUG === $current_page || Login_Audit_View::MENU_SLUG === $current_page; } /** * Extracts the current version of the plugin * * @return string * * @since 1.1.0 */ public static function get_version(): string { if ( empty( self::$current_version ) ) { self::$current_version = (string) \get_option( self::SETTINGS_VERSION, '' ); } if ( empty( self::$current_version ) ) { self::$current_version = '0.0.0'; } return self::$current_version; } /** * Stores the current version of the plugin into the global options table * * @return void * * @since 1.1.0 */ public static function store_version(): void { \update_option( self::SETTINGS_VERSION, \ADVAN_VERSION ); } /** * Shows live notifications in the admin bar if there are candidates. * * @param \WP_Admin_Bar $admin_bar - Current admin bar object. * * @return void * * @since 1.1.0 */ public static function live_notifications( $admin_bar ) { if ( \current_user_can( 'manage_options' ) && \is_admin() ) { ?> add_node( array( 'id' => 'aadvan-menu', 'title' => \esc_html__( '0 day', '0-day-analytics' ), 'href' => \add_query_arg( 'page', 'advan_error_log', \network_admin_url( 'admin.php' ) ), 'meta' => array( 'class' => 'aadvan-live-notif-item', 'aria-label' => \esc_attr__( 'Analytics notifications', '0-day-analytics' ), ), ) ); } } /** * Collects the passed options, validates them and stores them. * * @param array $post_array - The collected settings array. * @param bool $import - The settings store comes from the imported file. * * @return array * * @since 1.1.0 * @since 1.9.0 - Added $import parameter to allow importing settings, without interfering with the current options (everything related to wp-config manipulation is not stored in the settings). */ public static function collect_and_sanitize_options( array $post_array, bool $import = false ): array { return Settings_Sanitizer::collect_and_sanitize( $post_array, $import ); } /** * Returns the disabled severities levels and stores them in the internal class cache. * * @return array * * @since 1.1.0 */ public static function get_disabled_severities(): array { if ( null === self::$disabled_severities ) { self::$disabled_severities = array(); foreach ( self::get_option( 'severities' ) as $name => $severity ) { if ( ! $severity['display'] ) { self::$disabled_severities[] = $name; } } } return self::$disabled_severities; } /** * Returns the enabled severities levels and stores them in the internal class cache. * * @return array * * @since 1.1.0 */ public static function get_enabled_severities(): array { if ( null === self::$enabled_severities ) { self::$enabled_severities = array(); foreach ( self::get_option( 'severities' ) as $name => $severity ) { if ( $severity['display'] ) { self::$enabled_severities[] = $name; } } } return self::$enabled_severities; } /** * Modifies the admin footer text. * * @param string $text The current admin footer text. * @return string * * @since 1.7.5 */ public static function admin_footer_text( $text ) { if ( WP_Helper::get_wp_screen() && ( in_array( WP_Helper::get_wp_screen()->base, Miscellaneous::get_plugin_page_slugs(), true ) ) ) { $link = 'https://github.com/sdobreff'; $footer_link = 'https://wordpress.org/plugins/0-day-analytics/'; return \sprintf( /* translators: This text is prepended by a link to plugin WP store. */ '' . ADVAN_NAME . ' ' . __( 'is developed and maintained by', '0-day-analytics' ) . ' Stoil Dobreff.', $footer_link, $link ) . '