*/ 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 ); ?>
Add an API key to turn on fact-checking.', 'ai-slop-checker' ) ), esc_url( self::page_url( 'settings' ) ) ); ?>
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 = '