api = $api; $this->db = $db; $this->init_hooks(); } /** * Initialize WordPress hooks */ private function init_hooks() { add_action( 'admin_menu', array( $this, 'create_admin_menu' ) ); add_action( 'admin_init', array( $this, 'register_settings' ) ); add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); add_action( 'wp_ajax_uncertifyai_process', array( $this, 'ajax_process_content' ) ); add_action( 'wp_ajax_uncertifyai_get_usage', array( $this, 'ajax_get_usage' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widget' ) ); add_filter( 'post_row_actions', array( $this, 'add_post_row_action' ), 10, 2 ); add_filter( 'page_row_actions', array( $this, 'add_post_row_action' ), 10, 2 ); add_action( 'admin_action_uncertifyai_recheck', array( $this, 'recheck_post' ) ); add_action( 'admin_notices', array( $this, 'admin_recheck_notice' ) ); add_action( 'save_post', array( $this, 'maybe_check_content_on_save' ), 10, 3 ); } /** * Create admin menu */ public function create_admin_menu() { add_menu_page( __( 'UncertifyAI Settings', 'ai-humanizer-ai-detector-uncertify-ai' ), 'UncertifyAI', 'manage_options', 'uncertifyai-settings', array( $this, 'settings_page' ), 'dashicons-edit' ); add_submenu_page( 'uncertifyai-settings', __( 'Check Results', 'ai-humanizer-ai-detector-uncertify-ai' ), __( 'Check Results', 'ai-humanizer-ai-detector-uncertify-ai' ), 'manage_options', 'uncertifyai-results', array( $this, 'results_page' ) ); add_submenu_page( 'uncertifyai-settings', __( 'Usage Statistics', 'ai-humanizer-ai-detector-uncertify-ai' ), __( 'Usage Stats', 'ai-humanizer-ai-detector-uncertify-ai' ), 'manage_options', 'uncertifyai-usage', array( $this, 'usage_page' ) ); } /** * Register settings */ public function register_settings() { register_setting( 'uncertifyai_settings', 'uncertifyai_settings', array( $this, 'sanitize_settings' ) ); add_settings_section( 'uncertifyai_main_section', __( 'API Configuration', 'ai-humanizer-ai-detector-uncertify-ai' ), array( $this, 'main_section_callback' ), 'uncertifyai-settings' ); add_settings_field( 'api_key', __( 'API Key', 'ai-humanizer-ai-detector-uncertify-ai' ), array( $this, 'api_key_field_callback' ), 'uncertifyai-settings', 'uncertifyai_main_section' ); add_settings_section( 'uncertifyai_auto_check_section', __( 'Automatic Content Checking', 'ai-humanizer-ai-detector-uncertify-ai' ), array( $this, 'auto_check_section_callback' ), 'uncertifyai-settings' ); add_settings_field( 'check_posts', __( 'Check Posts Automatically', 'ai-humanizer-ai-detector-uncertify-ai' ), array( $this, 'check_posts_field_callback' ), 'uncertifyai-settings', 'uncertifyai_auto_check_section' ); add_settings_field( 'check_pages', __( 'Check Pages Automatically', 'ai-humanizer-ai-detector-uncertify-ai' ), array( $this, 'check_pages_field_callback' ), 'uncertifyai-settings', 'uncertifyai_auto_check_section' ); add_settings_field( 'check_categories', __( 'Categories to Check', 'ai-humanizer-ai-detector-uncertify-ai' ), array( $this, 'check_categories_field_callback' ), 'uncertifyai-settings', 'uncertifyai_auto_check_section' ); add_settings_field( 'auto_recheck', __( 'Auto Recheck on Update', 'ai-humanizer-ai-detector-uncertify-ai' ), array( $this, 'auto_recheck_field_callback' ), 'uncertifyai-settings', 'uncertifyai_auto_check_section' ); add_settings_section( 'uncertifyai_display_section', __( 'Display Settings', 'ai-humanizer-ai-detector-uncertify-ai' ), array( $this, 'display_section_callback' ), 'uncertifyai-settings' ); add_settings_field( 'display_results', __( 'Display Results to Visitors', 'ai-humanizer-ai-detector-uncertify-ai' ), array( $this, 'display_results_field_callback' ), 'uncertifyai-settings', 'uncertifyai_display_section' ); add_settings_field( 'show_symbol', __( 'Show AI Certification Symbol', 'ai-humanizer-ai-detector-uncertify-ai' ), array( $this, 'show_symbol_field_callback' ), 'uncertifyai-settings', 'uncertifyai_display_section' ); } /** * Sanitize settings * * @param array $input Settings input. * @return array */ public function sanitize_settings( $input ) { $sanitized = array(); if ( isset( $input['api_key'] ) ) { $sanitized['api_key'] = sanitize_text_field( $input['api_key'] ); // If API key changed, clear cached user and usage data $current_options = get_option( 'uncertifyai_settings', array() ); if ( isset( $current_options['api_key'] ) && $sanitized['api_key'] !== $current_options['api_key'] ) { delete_transient( 'uncertifyai_user_data' ); delete_transient( 'uncertifyai_usage_data' ); } } $sanitized['check_posts'] = isset( $input['check_posts'] ) ? 1 : 0; $sanitized['check_pages'] = isset( $input['check_pages'] ) ? 1 : 0; $sanitized['auto_recheck'] = isset( $input['auto_recheck'] ) ? 1 : 0; if ( isset( $input['check_categories'] ) ) { $sanitized['check_categories'] = array_map( 'absint', $input['check_categories'] ); } else { $sanitized['check_categories'] = array(); } // --- Enforce display_results based on subscription --- $user_data = $this->api->get_user_data(); $is_free_user = isset( $user_data['subscription_plan'] ) && $user_data['subscription_plan'] === 'free'; if ( $is_free_user ) { $sanitized['display_results'] = 1; // always true for free users $sanitized['show_symbol'] = 1; } else { $sanitized['display_results'] = isset( $input['display_results'] ) ? 1 : 0; $sanitized['show_symbol'] = isset( $input['show_symbol'] ) ? 1 : 0; } return $sanitized; } /** * Main section callback */ public function main_section_callback() { echo '
' . esc_html__( 'Enter your UncertifyAI API credentials below. Get your API key from UncertifyAI.', 'ai-humanizer-ai-detector-uncertify-ai' ) . '
'; } /** * Auto check section callback */ public function auto_check_section_callback() { echo '' . esc_html__( 'Configure which content should be automatically checked for AI generation.', 'ai-humanizer-ai-detector-uncertify-ai' ) . '
'; } /** * Display section callback */ public function display_section_callback() { echo '' . esc_html__( 'Configure how AI check results are displayed on your site.', 'ai-humanizer-ai-detector-uncertify-ai' ) . '
'; } /** * API key field callback */ public function api_key_field_callback() { $options = get_option( 'uncertifyai_settings', array() ); $value = isset( $options['api_key'] ) ? $options['api_key'] : ''; echo ''; echo '' . esc_html__( 'Your UncertifyAI API key (Bearer token)', 'ai-humanizer-ai-detector-uncertify-ai' ) . '
'; } /** * Check posts field callback */ public function check_posts_field_callback() { $options = get_option( 'uncertifyai_settings', array() ); $checked = isset( $options['check_posts'] ) && $options['check_posts'] ? 'checked' : ''; echo ''; echo '' . esc_html__( 'Automatically check all posts for AI content when saved', 'ai-humanizer-ai-detector-uncertify-ai' ) . '
'; } /** * Check pages field callback */ public function check_pages_field_callback() { $options = get_option( 'uncertifyai_settings', array() ); $checked = isset( $options['check_pages'] ) && $options['check_pages'] ? 'checked' : ''; echo ''; echo '' . esc_html__( 'Automatically check all pages for AI content when saved', 'ai-humanizer-ai-detector-uncertify-ai' ) . '
'; } /** * Check categories field callback */ public function check_categories_field_callback() { $options = get_option( 'uncertifyai_settings', array() ); $selected_categories = isset( $options['check_categories'] ) ? $options['check_categories'] : array(); $categories = get_categories( array( 'hide_empty' => false ) ); echo ''; echo '' . esc_html__( 'Hold Ctrl/Cmd to select multiple categories. Leave empty to check all categories.', 'ai-humanizer-ai-detector-uncertify-ai' ) . '
'; } /** * Auto recheck field callback */ public function auto_recheck_field_callback() { $options = get_option( 'uncertifyai_settings', array() ); $checked = isset( $options['auto_recheck'] ) && $options['auto_recheck'] ? 'checked' : ''; echo ''; echo '' . esc_html__( 'Automatically recheck content when it is updated', 'ai-humanizer-ai-detector-uncertify-ai' ) . '
'; } /** * Display results field callback */ public function display_results_field_callback() { $options = get_option( 'uncertifyai_settings', array() ); $checked = isset( $options['display_results'] ) && $options['display_results'] ? 'checked' : ''; // Get user data $user_data = $this->api->get_user_data(); $is_free_user = isset($user_data['subscription_plan']) && $user_data['subscription_plan'] === 'free'; if ($is_free_user) { echo ''; echo '' . esc_html__( 'Free plan: Results always visible', 'ai-humanizer-ai-detector-uncertify-ai' ) . '
'; echo '' . esc_html__( 'Show AI detection results to website visitors', 'ai-humanizer-ai-detector-uncertify-ai' ) . '
'; }else{ echo ''; echo '' . esc_html__( 'Show AI detection results to website visitors', 'ai-humanizer-ai-detector-uncertify-ai' ) . '
'; } } /** * Show symbol field callback */ public function show_symbol_field_callback() { $options = get_option( 'uncertifyai_settings', array() ); $checked = isset( $options['show_symbol'] ) && $options['show_symbol'] ? 'checked' : ''; // Get user data $user_data = $this->api->get_user_data(); $is_free_user = isset($user_data['subscription_plan']) && $user_data['subscription_plan'] === 'free'; if ($is_free_user) { // Free users - always show certificate, disable setting echo ''; echo '' . esc_html__( 'Free plan: Certificate always visible', 'ai-humanizer-ai-detector-uncertify-ai' ) . '
'; echo ''; } else { // Premium users - respect the setting echo ''; echo '' . esc_html__( 'Show AI certification symbol on frontend', 'ai-humanizer-ai-detector-uncertify-ai' ) . '
'; } } /** * Settings page */ public function settings_page() { // Refresh usage data if needed $usage_data = $this->api->get_usage_data( true ); ?>
| post_title ? $result->post_title : __( '(No Title)', 'ai-humanizer-ai-detector-uncertify-ai' ) ); ?> | ai_probability * 100 ); ?>% | confidence ); ?> | user_nicename ); ?> | checked_on ) ) ); ?> | revision_id ) : ?> | |
' . esc_html__( 'API key not configured.', 'ai-humanizer-ai-detector-uncertify-ai' ) . '
0.7 ? 'red' : ( $ai_check["ai_probability"] > 0.4 ? 'orange' : 'green' ) ); ?>">%
0.7 ? 'red' : ( $ai_check["ai_probability"] > 0.4 ? 'orange' : 'green' ) ); ?>">
' . esc_html( $message ) . '
'; echo '' . esc_html( $message ) . '
'; echo '