*/ public static function post_types() { /** * Filter which post types the slop checker covers. * * @param array $types Post type slugs. */ return apply_filters( 'aisc_post_types', array( 'post', 'page' ) ); } /** * Register the top-level menu. */ public static function menu() { $flagged = self::flagged_count(); $title = __( 'AI Slop', 'ai-slop-checker' ); if ( $flagged > 0 ) { $title .= sprintf( ' %d', $flagged ); } add_menu_page( __( 'AI Slop', 'ai-slop-checker' ), $title, 'manage_options', self::SLUG, array( __CLASS__, 'render_page' ), 'dashicons-warning', 76 ); } /** * Register the option. */ public static function register_settings() { register_setting( 'aisc_settings_group', AISC_OPTION, array( 'type' => 'array', 'sanitize_callback' => array( 'AISC_Settings', 'sanitize' ), 'default' => AISC_Settings::defaults(), ) ); } /** * Add the editor meta box. */ public static function meta_box() { foreach ( self::post_types() as $type ) { add_meta_box( 'aisc_box', __( 'AI Slop Checker', 'ai-slop-checker' ), array( __CLASS__, 'render_meta_box' ), $type, 'side', 'high' ); } } /** * Enqueue admin assets on the screens that need them. * * @param string $hook Current admin page hook. */ public static function assets( $hook ) { $editor = in_array( $hook, array( 'post.php', 'post-new.php' ), true ); $dashboard = false !== strpos( $hook, self::SLUG ); if ( ! $editor && ! $dashboard ) { return; } wp_enqueue_style( 'aisc-admin', AISC_URL . 'assets/admin.css', array(), AISC_VERSION ); $common = array( 'nonce' => wp_create_nonce( 'wp_rest' ), 'root' => esc_url_raw( rest_url( 'aisc/v1' ) ), 'canVerify' => AISC_Settings::can_verify(), ); if ( $editor ) { wp_enqueue_script( 'aisc-admin', AISC_URL . 'assets/admin.js', array(), AISC_VERSION, true ); wp_localize_script( 'aisc-admin', 'AISC', array_merge( $common, array( 'postId' => (int) get_the_ID(), 'settings' => esc_url_raw( self::page_url( 'settings' ) ), 'i18n' => array( 'scanning' => __( 'Scanning…', 'ai-slop-checker' ), 'checking' => __( 'Checking claims against live sources…', 'ai-slop-checker' ), 'noKey' => __( 'Add a Perplexity or Gemini API key in settings to enable fact-checking.', 'ai-slop-checker' ), 'error' => __( 'Something went wrong.', 'ai-slop-checker' ), 'noFindings' => __( 'No chat residue found in this draft.', 'ai-slop-checker' ), 'tail' => __( 'end of post', 'ai-slop-checker' ), 'claims' => __( 'claims checked', 'ai-slop-checker' ), 'problems' => __( 'need attention', 'ai-slop-checker' ), 'sources' => __( 'Sources', 'ai-slop-checker' ), 'correction' => __( 'Current fact', 'ai-slop-checker' ), 'disputed' => __( 'disputed', 'ai-slop-checker' ), 'agreed' => __( 'both agree', 'ai-slop-checker' ), 'quoted' => __( 'in a quote', 'ai-slop-checker' ), 'quotedHelp' => __( 'Inside a blockquote, so it counts for much less — quoting a chat reply is not the same as writing like one.', 'ai-slop-checker' ), 'jump' => __( 'Find in post', 'ai-slop-checker' ), 'jumpFail' => __( 'Could not locate that text — it may have been edited since the scan.', 'ai-slop-checker' ), 'dismissed' => __( 'Marked as a false positive.', 'ai-slop-checker' ), 'restored' => __( 'Restored. Re-scan to refresh the result.', 'ai-slop-checker' ), ), ) ) ); } if ( $dashboard ) { wp_enqueue_script( 'aisc-dashboard', AISC_URL . 'assets/dashboard.js', array(), AISC_VERSION, true ); wp_localize_script( 'aisc-dashboard', 'AISC_DASH', array_merge( $common, array( 'state' => AISC_Scan_Queue::state(), 'i18n' => array( 'confirmReset' => __( 'Clear all stored scan results for the whole site? This cannot be undone.', 'ai-slop-checker' ), 'error' => __( 'Something went wrong.', 'ai-slop-checker' ), 'complete' => __( 'Scan complete.', 'ai-slop-checker' ), 'ofPosts' => __( 'of', 'ai-slop-checker' ), 'flagged' => __( 'flagged', 'ai-slop-checker' ), 'skipped' => __( 'already current', 'ai-slop-checker' ), 'reload' => __( 'Reload to see the results', 'ai-slop-checker' ), 'rechecking' => __( 'Checking…', 'ai-slop-checker' ), 'recheck' => __( 'Recheck', 'ai-slop-checker' ), 'cleared' => __( 'Cleared — nothing found now', 'ai-slop-checker' ), 'stillFlagged' => __( 'Still flagged', 'ai-slop-checker' ), 'foundLabel' => __( 'Found:', 'ai-slop-checker' ), ), ) ) ); } } /** * URL for a tab on the plugin page. * * @param string $tab Tab slug. * @return string */ public static function page_url( $tab = 'dashboard' ) { return admin_url( 'admin.php?page=' . self::SLUG . '&tab=' . $tab ); } /* ------------------------------------------------------------ Meta box */ /** * Meta box markup. * * The stored verdict renders server-side so an editor opening a flagged post * sees the warning immediately, without having to click anything. * * @param WP_Post $post Current post. */ public static function render_meta_box( $post ) { $report = get_post_meta( $post->ID, AISC_META_REPORT, true ); $report = is_array( $report ) ? $report : array(); $flagged = (int) get_post_meta( $post->ID, AISC_META_FLAGGED, true ); $scanned = (int) get_post_meta( $post->ID, AISC_META_SCANNED, true ); $stale = $scanned && AISC_Post_Scan::needs_scan( $post->ID ); ?>
ID, $report ); ?>

Add an API key to turn on fact-checking.', 'ai-slop-checker' ) ), esc_url( self::page_url( 'settings' ) ) ); ?>

base ) { return; } if ( ! in_array( $screen->post_type, self::post_types(), true ) ) { return; } // The $post global is set by the time notices print, but fall back to the // query arg rather than silently skipping the warning. $post_id = (int) get_the_ID(); if ( ! $post_id && isset( $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- screen state only, nothing is changed here. $post_id = (int) $_GET['post']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- screen state only, nothing is changed here. } // That ID is user-supplied, so confirm this user may edit the post before // saying anything about what the scan found in it. if ( ! $post_id || ! current_user_can( 'edit_post', $post_id ) ) { return; } if ( ! get_post_meta( $post_id, AISC_META_FLAGGED, true ) ) { return; } $report = get_post_meta( $post_id, AISC_META_REPORT, true ); if ( ! is_array( $report ) || empty( $report['scan'] ) ) { return; } ?>

self::post_types(), 'post_status' => AISC_Scan_Queue::statuses(), 'posts_per_page' => 20, 'paged' => $paged, 'meta_key' => AISC_META_SCORE, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- indexed lookup, admin-only. 'orderby' => 'meta_value_num', 'order' => 'DESC', 'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- admin-only screen. array( 'key' => AISC_META_FLAGGED, 'value' => '1', ), ), ) ); ?>

found_posts; ?>

have_posts() ) : ?>

add_query_arg( 'paged', '%#%' ), 'format' => '', 'current' => $paged, 'total' => $query->max_num_pages, 'prev_text' => '« ' . __( 'Previous', 'ai-slop-checker' ), 'next_text' => __( 'Next', 'ai-slop-checker' ) . ' »', 'mid_size' => 3, ) ); $first = ( ( $paged - 1 ) * 20 ) + 1; $last = min( $paged * 20, (int) $query->found_posts ); $nav = ''; if ( $pagination ) { $nav = '
'; $nav .= '' . sprintf( /* translators: 1: first row number, 2: last row number, 3: total. */ esc_html__( 'Showing %1$d–%2$d of %3$d', 'ai-slop-checker' ), $first, $last, (int) $query->found_posts ) . ''; $nav .= '' . $pagination . ''; $nav .= '
'; } echo wp_kses_post( $nav ); ?> have_posts() ) : $query->the_post(); $post_id = get_the_ID(); $report = get_post_meta( $post_id, AISC_META_REPORT, true ); $report = is_array( $report ) ? $report : array(); $level = get_post_meta( $post_id, AISC_META_LEVEL, true ); $score = (int) get_post_meta( $post_id, AISC_META_SCORE, true ); $scanned = (int) get_post_meta( $post_id, AISC_META_SCANNED, true ); ?>

%s', esc_url( get_edit_post_link( $post_id ) ), esc_html__( 'See details', 'ai-slop-checker' ) ); } } ?>

  1. perplexity.ai/settings/api.', 'ai-slop-checker' ) ), 'https://www.perplexity.ai/settings/api' ); ?>

  1. aistudio.google.com/apikey and sign in with a Google account.', 'ai-slop-checker' ) ), 'https://aistudio.google.com/apikey' ); ?>

  1. Google Cloud console and select or create a project.', 'ai-slop-checker' ) ), 'https://console.cloud.google.com/projectcreate' ); ?>
  2. Fact Check Tools API. If you also want web corroboration, enable the Custom Search API as well.', 'ai-slop-checker' ) ), 'https://console.cloud.google.com/apis/library/factchecktools.googleapis.com', 'https://console.cloud.google.com/apis/library/customsearch.googleapis.com' ); ?>
  3. Credentials, choose "Create credentials → API key", and paste it below.', 'ai-slop-checker' ) ), 'https://console.cloud.google.com/apis/credentials' ); ?>

  1. programmablesearchengine.google.com.', 'ai-slop-checker' ) ), 'https://programmablesearchengine.google.com/controlpanel/create' ); ?>

self::post_types(), 'post_status' => AISC_Scan_Queue::statuses(), 'posts_per_page' => 1, 'fields' => 'ids', 'no_found_rows' => false, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, 'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- result is transient-cached below. array( 'key' => AISC_META_FLAGGED, 'value' => '1', ), ), ) ); $count = (int) $query->found_posts; set_transient( 'aisc_flagged_count', $count, 5 * MINUTE_IN_SECONDS ); return $count; } /* --------------------------------------------------------- List column */ /** * Add the slop column to post list tables. * * @param array $columns Existing columns. * @return array */ public static function column( $columns ) { $columns['aisc'] = __( 'Slop', 'ai-slop-checker' ); return $columns; } /** * Render the slop column. * * @param string $column Column key. * @param int $post_id Post ID. */ public static function column_content( $column, $post_id ) { if ( 'aisc' !== $column ) { return; } // Contributors see rows for posts they cannot edit. Show those the same // blank as an unscanned post rather than someone else's result. if ( ! current_user_can( 'edit_post', $post_id ) ) { echo '—'; return; } $scanned = (int) get_post_meta( $post_id, AISC_META_SCANNED, true ); if ( ! $scanned ) { echo '—'; return; } $level = get_post_meta( $post_id, AISC_META_LEVEL, true ); $score = (int) get_post_meta( $post_id, AISC_META_SCORE, true ); printf( '%2$s', esc_attr( $level ? $level : 'clean' ), esc_html( $score ) ); } /* ------------------------------------------------------- Auto-checking */ /** * Run the check when a post is published. * * @param string $new_status New status. * @param string $old_status Previous status. * @param WP_Post $post Post object. */ public static function on_transition( $new_status, $old_status, $post ) { if ( 'publish' !== AISC_Settings::get( 'run_on' ) ) { return; } if ( 'publish' !== $new_status || 'publish' === $old_status ) { return; } if ( ! self::should_check( $post->ID, $post ) ) { return; } self::dispatch( $post->ID ); } /** * Run the check on every save. * * @param int $post_id Post ID. * @param WP_Post $post Post object. * @param bool $update Whether this is an update. */ public static function on_save( $post_id, $post, $update ) { unset( $update ); if ( 'save' !== AISC_Settings::get( 'run_on' ) ) { return; } if ( ! self::should_check( $post_id, $post ) ) { return; } self::dispatch( $post_id ); } /** * Shared guards for the automatic hooks. * * @param int $post_id Post ID. * @param WP_Post $post Post object. * @return bool */ private static function should_check( $post_id, $post ) { if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) { return false; } if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return false; } if ( ! $post || ! in_array( $post->post_type, self::post_types(), true ) ) { return false; } if ( 'trash' === $post->post_status ) { return false; } return true; } /** * Run the pattern scan now; defer the AI pass to cron. * * Publishing must not block on a network round-trip, so the instant half * runs inline and the metered half is queued. * * @param int $post_id Post ID. */ private static function dispatch( $post_id ) { AISC_Post_Scan::run( $post_id, false ); delete_transient( 'aisc_flagged_count' ); if ( AISC_Settings::ai_enabled() ) { wp_schedule_single_event( time() + 10, 'aisc_verify_post', array( (int) $post_id ) ); spawn_cron(); } } }