page_slug, array( $this, 'render_page' ), 'dashicons-format-image', 100 ); // Переименовываем первый подпункт (WordPress создает его автоматически) add_submenu_page( $this->page_slug, __( 'Auto Featured Image', 'ai-thumbnails-maker' ), __( 'Auto Featured Image', 'ai-thumbnails-maker' ), 'manage_options', $this->page_slug, array( $this, 'render_page' ) ); } /** * Enqueue scripts * * @param string $hook Current admin page hook. */ public function enqueue_scripts( $hook ) { if ( strpos( $hook, $this->page_slug ) === false ) { return; } // Стили дашборда wp_enqueue_style( 'aitm-dashboard', AITM_PLUGIN_URL . 'assets/dist/dashboard.css', array(), AITM_VERSION ); // Скрипты дашборда (Chart.js включен в bundle) wp_enqueue_script( 'aitm-dashboard', AITM_PLUGIN_URL . 'assets/dist/dashboard.js', array( 'jquery' ), AITM_VERSION . '.' . time(), // Force cache bust true ); // Get settings $settings = get_option( 'aitm_settings', array() ); // Get saved post type from user meta $saved_post_type = get_user_meta( get_current_user_id(), 'aitm_selected_post_type', true ); // Локализация wp_localize_script( 'aitm-dashboard', 'aitmData', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'aitm_nonce' ), 'generationMethod' => $settings['generation_method'] ?? 'first_content_image', 'savedPostType' => $saved_post_type ?: 'post', 'perPage' => 10, 'strings' => array( 'generating' => __( 'Generating...', 'ai-thumbnails-maker' ), 'completed' => __( 'Generation completed!', 'ai-thumbnails-maker' ), 'generationStopped' => __( 'Generation stopped by user.', 'ai-thumbnails-maker' ), 'error' => __( 'Error occurred', 'ai-thumbnails-maker' ), 'success' => __( 'Success', 'ai-thumbnails-maker' ), 'failed' => __( 'Failed', 'ai-thumbnails-maker' ), 'withThumbnail' => __( 'With featured image', 'ai-thumbnails-maker' ), 'withoutThumbnail' => __( 'Without featured image', 'ai-thumbnails-maker' ), 'nothingToProcess' => __( 'No posts without featured images found.', 'ai-thumbnails-maker' ), 'noThumbnailsFound' => __( 'No posts with featured images found.', 'ai-thumbnails-maker' ), 'deletionComplete' => __( 'Featured images deleted successfully.', 'ai-thumbnails-maker' ), 'deletionStopped' => __( 'Deletion stopped by user.', 'ai-thumbnails-maker' ), 'deleteConfirm' => __( 'Are you sure you want to delete all featured images?', 'ai-thumbnails-maker' ), ), ) ); } /** * Render page */ public function render_page() { if ( ! current_user_can( 'manage_options' ) ) { return; } // Get settings $settings = get_option( 'aitm_settings', array() ); // Get statistics $generator = new AITM_Thumbnail_Generator( $settings ); $stats = $generator->get_statistics( 'post' ); // Get post types $post_types = get_post_types( array( 'public' => true, ), 'objects' ); // Check if overwrite is enabled $overwrite_existing = $settings['overwrite_existing'] ?? false; ?>

%

%

  • -
  • -
__( 'First Content Image', 'ai-thumbnails-maker' ), 'generate_from_title' => __( 'Generate from Title', 'ai-thumbnails-maker' ), 'search_or_generate' => __( 'Search or Generate', 'ai-thumbnails-maker' ), 'use_default_image' => __( 'Use Default Image', 'ai-thumbnails-maker' ), 'ai_generation' => __( 'AI Generation', 'ai-thumbnails-maker' ), ); $method_descriptions = array( 'first_content_image' => __( 'Uses the first image found in post content', 'ai-thumbnails-maker' ), 'generate_from_title' => __( 'Generates image from post title on colored background', 'ai-thumbnails-maker' ), 'search_or_generate' => __( 'Searches in content, generates from title if not found', 'ai-thumbnails-maker' ), 'use_default_image' => __( 'Searches in content, uses default image if not found', 'ai-thumbnails-maker' ), 'ai_generation' => __( 'Generates images using AI (ChatGPT + DALL-E)', 'ai-thumbnails-maker' ), ); $method_label = $method_labels[ $method ] ?? $method_labels['first_content_image']; $method_desc = $method_descriptions[ $method ] ?? $method_descriptions['first_content_image']; ?>

__( 'Generates images using AI (ChatGPT + DALL-E)', 'ai-thumbnails-maker' ), 'first_content_image' => __( 'Uses first image from post content', 'ai-thumbnails-maker' ), 'generate_from_title' => __( 'Generates images using AI (ChatGPT + DALL-E)', 'ai-thumbnails-maker' ), 'use_default_image' => __( 'Uses default image from settings', 'ai-thumbnails-maker' ), ); return $labels[ $type ] ?? ''; } /** * Render log entry * * @param array $entry Log entry data. */ private function render_log_entry( $entry ) { $success = $entry['success'] ?? false; $row_class = $success ? '' : 'aitm-log-table__row--error'; $post_id = $entry['post_id'] ?? 0; $type = $entry['type'] ?? ''; $method_label = $this->get_generation_method_label( $type ); ?>