init_hooks(); } /** * Hook into actions and filters. */ private function init_hooks() { add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 ); } /** * Enqueue admin scripts and styles. * * @param string $hook Current admin page hook. */ public function enqueue_scripts( $hook ) { $screen = get_current_screen(); if ( ! $screen || strpos( $screen->id, 'ai-answer-toolkit' ) === false ) { return; } // Enqueue admin CSS wp_enqueue_style( 'ai-answer-toolkit-admin', AI_ANSWER_TOOLKIT_PLUGIN_URL . 'assets/css/admin.css', array(), AI_ANSWER_TOOLKIT_VERSION ); // Enqueue dashboard CSS on main dashboard page wp_enqueue_style( 'ai-answer-toolkit-dashboard', AI_ANSWER_TOOLKIT_PLUGIN_URL . 'assets/css/dashboard.css', array(), AI_ANSWER_TOOLKIT_VERSION ); // Enqueue admin JS wp_enqueue_script( 'ai-answer-toolkit-admin', AI_ANSWER_TOOLKIT_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery' ), AI_ANSWER_TOOLKIT_VERSION, true ); wp_localize_script( 'ai-answer-toolkit-admin', 'aitkAdmin', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'ai_answer_toolkit_admin' ), ) ); } /** * Add admin menu items. */ public function admin_menu() { // Add main menu page add_menu_page( __( 'AI Answer Toolkit', 'ai-answer-toolkit' ), __( 'AI Answer Toolkit', 'ai-answer-toolkit' ), 'manage_options', 'ai-answer-toolkit', array( $this, 'settings_page' ), 'dashicons-search', 58 ); // Add Dashboard submenu (points to same page as main menu) add_submenu_page( 'ai-answer-toolkit', __( 'Dashboard', 'ai-answer-toolkit' ), __( 'Dashboard', 'ai-answer-toolkit' ), 'manage_options', 'ai-answer-toolkit', array( $this, 'settings_page' ) ); } /** * Render settings page. */ public function settings_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } // Get dashboard data $data = $this->get_dashboard_data(); ?>

/100

$stats ) : ?>

/
%
0, 'overall_color' => 'poor', 'overall_label' => __( 'Poor', 'ai-answer-toolkit' ), 'good_count' => 0, 'ok_count' => 0, 'poor_count' => 0, 'not_analyzed_count' => 0, 'post_types' => array(), ); // Get all public post types $post_types = get_post_types( array( 'public' => true, ), 'objects' ); $total_score = 0; $total_posts = 0; foreach ( $post_types as $post_type ) { if ( in_array( $post_type->name, array( 'attachment' ), true ) ) { continue; } // Get all posts of this type $posts = get_posts( array( 'post_type' => $post_type->name, 'posts_per_page' => -1, 'post_status' => 'publish', ) ); $type_total = count( $posts ); $type_analyzed = 0; $type_with_summary = 0; foreach ( $posts as $post ) { // Use Ultimate Score if available, fallback to legacy Score $score = 0; if ( class_exists( 'AI_Answer_Toolkit_Ultimate_Score' ) ) { $ultimate_score = AI_Answer_Toolkit_Ultimate_Score::calculate_ultimate_score( $post->ID ); $score = $ultimate_score['score']; } else { $score_data = AI_Answer_Toolkit_Score::calculate_score( $post->ID ); $score = $score_data['score']; } if ( $score > 0 ) { $type_analyzed++; $total_score += $score; $total_posts++; // Categorize by score if ( $score >= 80 ) { $data['good_count']++; } elseif ( $score >= 50 ) { $data['ok_count']++; } else { $data['poor_count']++; } } else { $data['not_analyzed_count']++; } // Check for summary $summary = get_post_meta( $post->ID, '_aitk_summary', true ); if ( ! empty( $summary ) ) { $type_with_summary++; } } $percentage = $type_total > 0 ? round( ( $type_analyzed / $type_total ) * 100 ) : 0; $data['post_types'][ $post_type->name ] = array( 'label' => $post_type->labels->name, 'total' => $type_total, 'analyzed' => $type_analyzed, 'with_summary' => $type_with_summary, 'percentage' => $percentage, ); } // Calculate average score if ( $total_posts > 0 ) { $data['average_score'] = round( $total_score / $total_posts ); } // Determine overall color and label if ( $data['average_score'] >= 80 ) { $data['overall_color'] = 'good'; $data['overall_label'] = __( 'Good', 'ai-answer-toolkit' ); } elseif ( $data['average_score'] >= 50 ) { $data['overall_color'] = 'ok'; $data['overall_label'] = __( 'Needs Improvement', 'ai-answer-toolkit' ); } else { $data['overall_color'] = 'poor'; $data['overall_label'] = __( 'Poor', 'ai-answer-toolkit' ); } return apply_filters( 'ai_answer_toolkit_dashboard_data', $data ); } }