get_var( "SELECT COUNT(*) FROM {$wpdb->comments} WHERE comment_approved = 'spam'" ); // Count trashed comments. $trash_comments = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->comments} WHERE comment_approved = 'trash'" ); // Count trashed posts. $trash_posts = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_status = 'trash'" ); // Count revisions. $revisions = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = 'revision'" ); // Count auto-drafts. $auto_drafts = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_status = 'auto-draft'" ); // Count expired transients. $expired_transients = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->options} WHERE option_name LIKE %s AND option_value < UNIX_TIMESTAMP()", $wpdb->esc_like( '_transient_timeout_' ) . '%' ) ); $total_junk = $spam_count + $trash_comments + $trash_posts + $auto_drafts + $expired_transients; $details = array( 'spam_comments' => $spam_count, 'trash_comments' => $trash_comments, 'trash_posts' => $trash_posts, 'revisions' => $revisions, 'auto_drafts' => $auto_drafts, 'expired_transients' => $expired_transients, 'total_junk' => $total_junk, ); // Build issues list. $issues = array(); if ( $spam_count > 100 ) { $issues[] = sprintf( /* translators: %s: number */ \__( '%s spam comments', '0-day-analytics' ), static::format_number( $spam_count ) ); } if ( $trash_posts > 50 ) { $issues[] = sprintf( /* translators: %s: number */ \__( '%s trashed posts', '0-day-analytics' ), static::format_number( $trash_posts ) ); } if ( $expired_transients > 100 ) { $issues[] = sprintf( /* translators: %s: number */ \__( '%s expired temporary data entries', '0-day-analytics' ), static::format_number( $expired_transients ) ); } if ( $revisions > 1000 ) { $issues[] = sprintf( /* translators: %s: number */ \__( '%s post revisions', '0-day-analytics' ), static::format_number( $revisions ) ); } if ( count( $issues ) >= 2 || $total_junk > 1000 ) { return static::fail( 'medium', sprintf( /* translators: %s: list of issues */ \__( 'Your database has accumulated unnecessary data: %s. This bloat slows down database queries and backups.', '0-day-analytics' ), implode( ', ', $issues ) ), \__( 'Use a database cleanup plugin like WP-Optimize or Advanced Database Cleaner to safely remove this data. Many caching plugins also include database optimization tools.', '0-day-analytics' ), $details ); } if ( ! empty( $issues ) ) { return static::warning( sprintf( /* translators: %s: list of issues */ \__( 'Your database has some accumulated overhead: %s. While not critical, periodic cleanup helps keep your site fast.', '0-day-analytics' ), implode( ', ', $issues ) ), \__( 'Consider using a database cleanup plugin or your hosting control panel to clean up old data periodically.', '0-day-analytics' ), $details ); } return static::pass( \__( 'Your database is clean with minimal overhead. Spam, trash, and temporary data are at acceptable levels.', '0-day-analytics' ), $details ); } } }