parent_id = add_submenu_page( 'tptn_dashboard', esc_html__( 'Top 10 Tools', 'top-10' ), esc_html__( 'Tools', 'top-10' ), 'manage_options', 'tptn_tools_page', array( $this, 'render_page' ) ); add_action( 'load-' . $this->parent_id, array( $this, 'help_tabs' ) ); } /** * Admin Menu. * * @since 3.3.0 */ public function network_admin_menu() { $this->parent_id = add_submenu_page( 'tptn_dashboard', esc_html__( 'Top 10 Tools', 'top-10' ), esc_html__( 'Tools', 'top-10' ), 'manage_network_options', 'tptn_network_tools_page', array( $this, 'render_page' ) ); add_action( 'load-' . $this->parent_id, array( $this, 'help_tabs' ) ); } /** * Enqueue scripts in admin area. * * @since 3.3.0 * * @param string $hook The current admin page. */ public function admin_enqueue_scripts( $hook ) { if ( $hook === $this->parent_id ) { wp_enqueue_script( 'top-ten-admin-js' ); wp_enqueue_style( 'top-ten-admin-css' ); wp_enqueue_style( 'wp-spinner' ); wp_localize_script( 'top-ten-admin-js', 'top_ten_admin_data', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'security' => wp_create_nonce( 'tptn-admin' ), 'strings' => array( 'confirm_message' => esc_html__( 'Are you sure you want to clear the cache?', 'top-10' ), 'clearing_text' => esc_html__( 'Clearing...', 'top-10' ), 'fail_message' => esc_html__( 'Failed to clear cache. Please try again.', 'top-10' ), 'request_fail_message' => esc_html__( 'Request failed: ', 'top-10' ), ), ) ); } } /** * Render the tools settings page. * * @since 2.5.0 * * @return void */ public function render_page() { $screen = get_current_screen(); $network_wide = false; if ( $screen->id === $this->parent_id . '-network' ) { $network_wide = true; } /* Truncate overall posts table */ if ( isset( $_POST['tptn_recreate_primary_key'] ) && check_admin_referer( 'tptn-tools-settings' ) ) { self::recreate_primary_key(); add_settings_error( 'tptn-notices', '', esc_html__( 'Primary Key has been recreated', 'top-10' ), 'updated' ); } /* Truncate overall posts table */ if ( isset( $_POST['tptn_reset_overall'] ) && check_admin_referer( 'tptn-tools-settings' ) ) { if ( ! is_multisite() || $network_wide ) { Database::truncate_table( Database::get_table( false ) ); } else { Counter::delete_counts( array( 'daily' => false ) ); } add_settings_error( 'tptn-notices', '', esc_html__( 'Top 10 popular posts reset', 'top-10' ), 'updated' ); } /* Truncate daily posts table */ if ( isset( $_POST['tptn_reset_daily'] ) && check_admin_referer( 'tptn-tools-settings' ) ) { if ( ! is_multisite() || $network_wide ) { Database::truncate_table( Database::get_table( true ) ); } else { Counter::delete_counts( array( 'daily' => true ) ); } add_settings_error( 'tptn-notices', '', esc_html__( 'Top 10 daily popular posts reset', 'top-10' ), 'updated' ); } /* Recreate tables */ if ( isset( $_POST['tptn_recreate_tables'] ) && check_admin_referer( 'tptn-tools-settings' ) ) { $result = self::recreate_tables(); if ( is_wp_error( $result ) ) { add_settings_error( 'tptn-notices', '', $result->get_error_message(), 'error' ); } else { add_settings_error( 'tptn-notices', '', esc_html__( 'Top 10 tables have been recreated', 'top-10' ), 'updated' ); } } /* Sync funnel (run aggregation now) */ if ( isset( $_POST['tptn_sync_funnel'] ) && check_admin_referer( 'tptn-tools-settings' ) ) { $result = Database::aggregate_visit_log(); if ( true === $result ) { add_settings_error( 'tptn-notices', '', esc_html__( 'Funnel has been synced. Buffered visits have been aggregated.', 'top-10' ), 'updated' ); } elseif ( 0 === $result ) { add_settings_error( 'tptn-notices', '', esc_html__( 'Nothing to sync. The funnel is empty.', 'top-10' ), 'updated' ); } elseif ( false === $result ) { add_settings_error( 'tptn-notices', '', esc_html__( 'Sync skipped: another aggregation is already in progress. Please try again in a moment.', 'top-10' ), 'updated' ); } elseif ( is_wp_error( $result ) ) { add_settings_error( 'tptn-notices', '', sprintf( /* translators: %s: error message from the database */ esc_html__( 'Sync failed: %s', 'top-10' ), esc_html( $result->get_error_message() ) ), 'error' ); } } ob_start(); ?>
' . sprintf( __( 'For more information or how to get support visit the WebberZone support site.', 'top-10' ), esc_url( 'https://webberzone.com/support/' ) ) . '
' . /* translators: 1: Forum link. */ '' . sprintf( __( 'Support queries should be posted in the WordPress.org support forums.', 'top-10' ), esc_url( 'https://wordpress.org/support/plugin/top-10' ) ) . '
' . '' . sprintf( /* translators: 1: Github Issues link, 2: Github page. */ __( 'Post an issue on GitHub (bug reports only).', 'top-10' ), esc_url( 'https://github.com/WebberZone/top-10/issues' ), esc_url( 'https://github.com/WebberZone/top-10' ) ) . '
' ); $screen->add_help_tab( array( 'id' => 'tptn-settings-general', 'title' => __( 'General', 'top-10' ), 'content' => '' . __( 'This screen provides some tools that help maintain certain features of Top 10.', 'top-10' ) . '
' . '' . __( 'Clear the cache, reset the popular posts tables plus some miscellaneous fixes for older versions of Top 10.', 'top-10' ) . '
', ) ); do_action( 'tptn_settings_tools_help', $screen ); } /** * Check if tables exist and create them if they don't. * * @since 4.2.0 * * @return array Array of table statuses indicating whether they are installed. */ public static function check_table_status() { $tables = array( 'top_ten' => Database::get_table( false ), 'top_ten_daily' => Database::get_table( true ), 'top_ten_visits_funnel' => Database::get_funnel_table(), 'top_ten_visits_log' => Database::get_log_table(), ); $statuses = array(); $installed_label = '' . __( 'Installed', 'top-10' ) . ''; $not_installed_label = '' . __( 'Not Installed', 'top-10' ) . ''; foreach ( $tables as $key => $table_name ) { $statuses[ $key ] = Database::is_table_installed( $table_name ) ? $installed_label : $not_installed_label; } // Create tables if they don't exist. if ( ! Database::are_tables_installed() ) { // Use Activator to create tables. Activator::create_tables(); Database::clear_table_statistics_cache(); // Refresh statuses after creating tables. foreach ( $tables as $key => $table_name ) { $statuses[ $key ] = Database::is_table_installed( $table_name ) ? $installed_label : $not_installed_label; } } /** * Filter the table statuses report. * * @since 4.1.0 * * @param array $statuses Array of table statuses. */ return apply_filters( 'tptn_table_statuses', $statuses ); } /** * Get database status report. * * @since 4.2.0 * * @return string HTML output for the database status report. */ public static function get_db_status_report() { global $tptn_db_version; // Get table statuses. $statuses = self::check_table_status(); // Get table statistics from Database class. $table_stats = Database::get_table_statistics(); ob_start(); ?>