plugin_name = $plugin_name; $this->version = $version; $this->core = $core; } public function render_tab() { global $wpdb; // Collect Real Data // Total Posts $total_posts = wp_count_posts('post'); $count_posts = isset($total_posts->publish) ? $total_posts->publish : 0; // Total Pages $total_pages = wp_count_posts('page'); $count_pages = isset($total_pages->publish) ? $total_pages->publish : 0; // Total internal links and orphans via Repository. $total_internal_links = AILM_Link_Repository::count_all('internal'); $orphan_ids = AILM_Link_Repository::get_orphan_ids(); $orphan_count = count($orphan_ids); // Clicks $total_all_clicks = 0; $total_internal_clicks = 0; $total_external_clicks = 0; $total_sponsored_clicks = 0; if (class_exists('AILM_Clicks_DB')) { $table_name = esc_sql(AILM_Clicks_DB::get_table_name()); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching if ($wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table_name)) === $table_name) { // Request // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter $clicks_data = $wpdb->get_results("SELECT link_type, SUM(click_count) as total FROM {$table_name} GROUP BY link_type"); if ($clicks_data) { foreach ($clicks_data as $row) { if ($row->link_type === 'internal') { $total_internal_clicks = (int) $row->total; } elseif ($row->link_type === 'external') { $total_external_clicks = (int) $row->total; } elseif ($row->link_type === 'sponsored') { $total_sponsored_clicks = (int) $row->total; } } } // Total $total_all_clicks = $total_internal_clicks + $total_external_clicks + $total_sponsored_clicks; } } // Broken Links & Outbound (404 Scout) $broken_links = 0; $total_outbound_links = 0; if (class_exists('AILM_Scout_DB')) { $table_name = AILM_Scout_DB::get_table_name(); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching if ($wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table_name)) === $table_name) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $broken_links = (int) $wpdb->get_var("SELECT COUNT(id) FROM {$table_name} WHERE status_code >= 400"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $total_outbound_links = (int) $wpdb->get_var("SELECT COUNT(id) FROM {$table_name} WHERE link_type = 'external'"); } } // Sponsored Links $total_sponsored_links = 0; if (class_exists('AILM_Scout_DB')) { $table_name = AILM_Scout_DB::get_table_name(); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching if ($wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table_name)) === $table_name) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $total_sponsored_links = (int) $wpdb->get_var("SELECT COUNT(id) FROM {$table_name} WHERE link_type = 'sponsored'"); } } ?>