base ) { return false; } // Block-editor screens are handled by Admin\BlockEditor. return ! ( method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() ); } /** * Enqueue the classic editor assets. * * @since 2.3.0 * @return void */ public function enqueue_assets() { if ( ! $this->is_classic_editor_screen() ) { return; } $this->enqueue(); } /** * Enqueue the classic editor assets inside the Elementor editor. * * @since 2.4.2 * @return void */ public function enqueue_for_elementor() { $this->enqueue(); wp_enqueue_style( 'aicw-elementor-editor', AICW_ASSETS_URL . 'css/aicw-elementor-editor.css', array( 'aicw-classic-editor' ), AICW_VERSION ); } /** * Register, localize and enqueue the classic editor assets. * * @since 2.4.2 * @return void */ protected function enqueue() { wp_enqueue_style( 'aicw-classic-editor', AICW_ASSETS_URL . 'css/aicw-classic-editor.css', array(), AICW_VERSION ); wp_enqueue_script( 'aicw-classic-editor', AICW_ASSETS_URL . 'js/aicw-classic-editor.js', array( 'jquery' ), AICW_VERSION, true ); $provider = aicw_get_ai_provider( get_option( 'aicw_api_model' ) ); $tones = array(); foreach ( aicw_get_content_tones() as $tone_value => $tone_label ) { $tones[] = array( 'value' => $tone_value, 'label' => $tone_label, ); } $languages = array(); foreach ( aicw_get_languages() as $language_value => $language_label ) { $languages[] = array( 'value' => $language_value, 'label' => $language_label, ); } wp_localize_script( 'aicw-classic-editor', 'aicwClassicData', array( 'endpoint' => rest_url( 'aicw/v1/generateContent' ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'hasApiKey' => $provider && $provider->is_configured(), 'settingsUrl' => admin_url( 'admin.php?page=aicw-settings' ), 'tones' => $tones, 'languages' => $languages, 'i18n' => array( 'title' => __( 'AI Content Writer', 'ai-content-writer' ), 'modeGenerate' => __( 'Write new content', 'ai-content-writer' ), 'modeModify' => __( 'Rewrite selected text', 'ai-content-writer' ), 'typeParagraph' => __( 'Paragraph', 'ai-content-writer' ), 'typeArticle' => __( 'Full article', 'ai-content-writer' ), 'topicLabel' => __( 'Topic / keywords', 'ai-content-writer' ), 'instructions' => __( 'Additional instructions (optional)', 'ai-content-writer' ), 'tone' => __( 'Tone', 'ai-content-writer' ), 'length' => __( 'Length', 'ai-content-writer' ), 'language' => __( 'Language', 'ai-content-writer' ), 'lengthDefault' => __( 'Default', 'ai-content-writer' ), 'lengthShort' => __( 'Short', 'ai-content-writer' ), 'lengthMedium' => __( 'Medium', 'ai-content-writer' ), 'lengthLong' => __( 'Long', 'ai-content-writer' ), 'generate' => __( 'Generate', 'ai-content-writer' ), 'generating' => __( 'Generating…', 'ai-content-writer' ), 'insert' => __( 'Insert', 'ai-content-writer' ), 'cancel' => __( 'Cancel', 'ai-content-writer' ), 'topicRequired' => __( 'Please enter a topic or keywords.', 'ai-content-writer' ), 'genericError' => __( 'Something went wrong. Please try again.', 'ai-content-writer' ), 'noApiKey' => __( 'No AI provider is configured yet. Add your API key on the settings page.', 'ai-content-writer' ), 'openSettings' => __( 'Open Settings', 'ai-content-writer' ), 'noSelection' => __( 'Select some text in the editor first to rewrite it.', 'ai-content-writer' ), ), ) ); } /** * Render the "AI Writer" media button above classic editors. * * @param string $editor_id The editor instance ID. * * @since 2.3.0 * @return void */ public function render_button( $editor_id ) { if ( ! $this->is_classic_editor_screen() ) { return; } printf( '', esc_attr( $editor_id ), esc_html__( 'AI Writer', 'ai-content-writer' ) ); } }