diff --git a/.eslintrc.json b/.eslintrc.json index 58bbb406e..85f09bd41 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -24,5 +24,5 @@ "Block": "readonly" }, "extends": ["plugin:@wordpress/eslint-plugin/recommended"], - "ignorePatterns": ["*.json"] + "ignorePatterns": ["*.json", "webpack.config.js"] } diff --git a/assets/img/block-icon.svg b/assets/img/block-icon.svg index e74bacb9d..01da9f386 100644 --- a/assets/img/block-icon.svg +++ b/assets/img/block-icon.svg @@ -1,3 +1,3 @@ - + diff --git a/includes/Classifai/Features/AudioTranscriptsGeneration.php b/includes/Classifai/Features/AudioTranscriptsGeneration.php index 13a4b6d54..bc9c4ba99 100644 --- a/includes/Classifai/Features/AudioTranscriptsGeneration.php +++ b/includes/Classifai/Features/AudioTranscriptsGeneration.php @@ -140,10 +140,10 @@ public function rest_endpoint_callback( WP_REST_Request $request ) { */ public function enqueue_admin_assets() { wp_enqueue_script( - 'classifai-media-script', - CLASSIFAI_PLUGIN_URL . 'dist/media.js', - array_merge( get_asset_info( 'media', 'dependencies' ), array( 'jquery', 'media-editor', 'lodash' ) ), - get_asset_info( 'media', 'version' ), + 'classifai-plugin-media-processing-js', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-media-processing.js', + array_merge( get_asset_info( 'classifai-plugin-media-processing', 'dependencies' ), array( 'jquery', 'media-editor', 'lodash' ) ), + get_asset_info( 'classifai-plugin-media-processing', 'version' ), true ); } diff --git a/includes/Classifai/Features/Classification.php b/includes/Classifai/Features/Classification.php index f3b8427d7..72ad266b2 100644 --- a/includes/Classifai/Features/Classification.php +++ b/includes/Classifai/Features/Classification.php @@ -303,18 +303,18 @@ public function rest_after_insert( \WP_Post $post ) { */ public function enqueue_admin_assets() { wp_enqueue_script( - 'classifai-language-processing-script', - CLASSIFAI_PLUGIN_URL . 'dist/language-processing.js', - get_asset_info( 'language-processing', 'dependencies' ), - get_asset_info( 'language-processing', 'version' ), + 'classifai-plugin-classification-previewer-js', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-classification-previewer.js', + get_asset_info( 'classifai-plugin-classification-previewer', 'dependencies' ), + get_asset_info( 'classifai-plugin-classification-previewer', 'version' ), true ); wp_enqueue_style( - 'classifai-language-processing-style', - CLASSIFAI_PLUGIN_URL . 'dist/language-processing.css', + 'classifai-plugin-classification-previewer-css', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-classification-previewer.css', array(), - get_asset_info( 'language-processing', 'version' ), + get_asset_info( 'classifai-plugin-classification-previewer', 'version' ), 'all' ); } @@ -326,10 +326,10 @@ public function enqueue_editor_assets() { global $post; wp_enqueue_script( - 'classifai-editor', - CLASSIFAI_PLUGIN_URL . 'dist/editor.js', - get_asset_info( 'editor', 'dependencies' ), - get_asset_info( 'editor', 'version' ), + 'classifai-plugin-classification-ibm-watson-js', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-classification-ibm-watson.js', + get_asset_info( 'classifai-plugin-classification-ibm-watson', 'dependencies' ), + get_asset_info( 'classifai-plugin-classification-ibm-watson', 'version' ), true ); @@ -338,15 +338,15 @@ public function enqueue_editor_assets() { } wp_enqueue_script( - 'classifai-gutenberg-plugin', - CLASSIFAI_PLUGIN_URL . 'dist/gutenberg-plugin.js', - array_merge( get_asset_info( 'gutenberg-plugin', 'dependencies' ), array( 'lodash' ) ), - get_asset_info( 'gutenberg-plugin', 'version' ), + 'classifai-plugin-classification-js', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-classification.js', + array_merge( get_asset_info( 'classifai-plugin-classification', 'dependencies' ), array( 'lodash' ), array( Feature::PLUGIN_AREA_SCRIPT ) ), + get_asset_info( 'classifai-plugin-classification', 'version' ), true ); wp_add_inline_script( - 'classifai-gutenberg-plugin', + 'classifai-plugin-classification-js', sprintf( 'var classifaiPostData = %s;', wp_json_encode( diff --git a/includes/Classifai/Features/ContentResizing.php b/includes/Classifai/Features/ContentResizing.php index 34836ade0..431005e89 100644 --- a/includes/Classifai/Features/ContentResizing.php +++ b/includes/Classifai/Features/ContentResizing.php @@ -85,7 +85,6 @@ static function () { */ public function feature_setup() { add_action( 'enqueue_block_assets', [ $this, 'enqueue_editor_assets' ] ); - add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] ); } /** @@ -189,39 +188,22 @@ public function enqueue_editor_assets() { } wp_enqueue_script( - 'classifai-content-resizing-plugin-js', - CLASSIFAI_PLUGIN_URL . 'dist/content-resizing-plugin.js', - get_asset_info( 'content-resizing-plugin', 'dependencies' ), - get_asset_info( 'content-resizing-plugin', 'version' ), + 'classifai-plugin-content-resizing-js', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-content-resizing.js', + get_asset_info( 'classifai-plugin-content-resizing', 'dependencies' ), + get_asset_info( 'classifai-plugin-content-resizing', 'version' ), true ); wp_enqueue_style( - 'classifai-content-resizing-plugin-css', - CLASSIFAI_PLUGIN_URL . 'dist/content-resizing-plugin.css', + 'classifai-plugin-content-resizing-css', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-content-resizing.css', [], - get_asset_info( 'content-resizing-plugin', 'version' ), + get_asset_info( 'classifai-plugin-content-resizing', 'version' ), 'all' ); } - /** - * Enqueue the admin scripts. - * - * @param string $hook_suffix The current admin page. - */ - public function enqueue_admin_assets( string $hook_suffix ) { - // Load asset in new post and edit post screens. - if ( 'post.php' === $hook_suffix || 'post-new.php' === $hook_suffix ) { - wp_enqueue_style( - 'classifai-language-processing-style', - CLASSIFAI_PLUGIN_URL . 'dist/language-processing.css', - [], - get_asset_info( 'language-processing', 'version' ), - ); - } - } - /** * Get the description for the enable field. * diff --git a/includes/Classifai/Features/ExcerptGeneration.php b/includes/Classifai/Features/ExcerptGeneration.php index 431ec22cb..7ab110922 100644 --- a/includes/Classifai/Features/ExcerptGeneration.php +++ b/includes/Classifai/Features/ExcerptGeneration.php @@ -198,10 +198,10 @@ public function enqueue_editor_assets() { // This script removes the core excerpt panel and replaces it with our own. wp_enqueue_script( - 'classifai-post-excerpt', - CLASSIFAI_PLUGIN_URL . 'dist/post-excerpt.js', - array_merge( get_asset_info( 'post-excerpt', 'dependencies' ), [ 'lodash' ] ), - get_asset_info( 'post-excerpt', 'version' ), + 'classifai-plugin-excerpt-generation-js', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-excerpt-generation.js', + array_merge( get_asset_info( 'classifai-plugin-excerpt-generation', 'dependencies' ), [ 'lodash' ] ), + get_asset_info( 'classifai-plugin-excerpt-generation', 'version' ), true ); } @@ -220,23 +220,23 @@ public function enqueue_admin_assets( string $hook_suffix ) { if ( $screen && ! $screen->is_block_editor() ) { if ( post_type_supports( $screen->post_type, 'excerpt' ) ) { wp_enqueue_style( - 'classifai-generate-title-classic-css', - CLASSIFAI_PLUGIN_URL . 'dist/generate-title-classic.css', + 'classifai-plugin-classic-excerpt-generation-css', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-classic-excerpt-generation.css', [], - get_asset_info( 'generate-title-classic', 'version' ), + get_asset_info( 'classifai-plugin-classic-excerpt-generation', 'version' ), 'all' ); wp_enqueue_script( - 'classifai-generate-excerpt-classic-js', - CLASSIFAI_PLUGIN_URL . 'dist/generate-excerpt-classic.js', - array_merge( get_asset_info( 'generate-excerpt-classic', 'dependencies' ), array( 'wp-api' ) ), - get_asset_info( 'generate-excerpt-classic', 'version' ), + 'classifai-plugin-classic-excerpt-generation-js', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-classic-excerpt-generation.js', + array_merge( get_asset_info( 'classifai-plugin-classic-excerpt-generation', 'dependencies' ), array( 'wp-api' ) ), + get_asset_info( 'classifai-plugin-classic-excerpt-generation', 'version' ), true ); wp_add_inline_script( - 'classifai-generate-excerpt-classic-js', + 'classifai-plugin-classic-excerpt-generation-js', sprintf( 'var classifaiGenerateExcerpt = %s;', wp_json_encode( @@ -251,13 +251,6 @@ public function enqueue_admin_assets( string $hook_suffix ) { ); } } - - wp_enqueue_style( - 'classifai-language-processing-style', - CLASSIFAI_PLUGIN_URL . 'dist/language-processing.css', - [], - get_asset_info( 'language-processing', 'version' ), - ); } } diff --git a/includes/Classifai/Features/Feature.php b/includes/Classifai/Features/Feature.php index cd1e6a636..f4e468035 100644 --- a/includes/Classifai/Features/Feature.php +++ b/includes/Classifai/Features/Feature.php @@ -5,6 +5,7 @@ use WP_REST_Request; use WP_Error; use function Classifai\find_provider_class; +use function Classifai\get_asset_info; abstract class Feature { /** @@ -16,6 +17,16 @@ abstract class Feature { */ const ID = ''; + /** + * Plugin area script handle. + * + * Every feature that injects content into the plugin area + * should add this script as a dependency. + * + * @var string + */ + const PLUGIN_AREA_SCRIPT = 'classifai-plugin-fill-js'; + /** * Feature label. * @@ -53,6 +64,7 @@ public function setup() { add_action( 'admin_init', [ $this, 'setup_roles' ] ); add_action( 'admin_init', [ $this, 'register_setting' ] ); add_action( 'admin_init', [ $this, 'setup_fields_sections' ] ); + add_action( 'admin_enqueue_scripts', [ $this, 'register_plugin_area_script' ] ); if ( $this->is_feature_enabled() ) { $this->feature_setup(); @@ -114,6 +126,19 @@ public function get_label(): string { ); } + /** + * Registers the plugin area script. + */ + public function register_plugin_area_script() { + wp_register_script( + self::PLUGIN_AREA_SCRIPT, + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-fill.js', + get_asset_info( 'classifai-plugin-fill', 'dependencies' ), + get_asset_info( 'classifai-plugin-fill', 'version' ), + true + ); + } + /** * Set up the fields for each section. * diff --git a/includes/Classifai/Features/ImageGeneration.php b/includes/Classifai/Features/ImageGeneration.php index 56df86aef..0db56fe52 100644 --- a/includes/Classifai/Features/ImageGeneration.php +++ b/includes/Classifai/Features/ImageGeneration.php @@ -186,34 +186,26 @@ public function enqueue_admin_scripts( string $hook_suffix = '' ) { wp_enqueue_media(); wp_enqueue_style( - 'classifai-image-processing-style', - CLASSIFAI_PLUGIN_URL . 'dist/media-modal.css', + 'classifai-plugin-image-generation-media-modal-css', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-image-generation-media-modal.css', [], - get_asset_info( 'media-modal', 'version' ), + get_asset_info( 'classifai-plugin-image-generation-media-modal', 'version' ), 'all' ); wp_enqueue_script( - 'classifai-generate-images', - CLASSIFAI_PLUGIN_URL . 'dist/media-modal.js', - array_merge( get_asset_info( 'media-modal', 'dependencies' ), array( 'jquery', 'wp-api' ) ), - get_asset_info( 'media-modal', 'version' ), + 'classifai-plugin-image-generation-media-modal-js', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-image-generation-media-modal.js', + array_merge( get_asset_info( 'classifai-plugin-image-generation-media-modal', 'dependencies' ), array( 'jquery', 'wp-api' ) ), + get_asset_info( 'classifai-plugin-image-generation-media-modal', 'version' ), true ); wp_enqueue_script( - 'classifai-inserter-media-category', - CLASSIFAI_PLUGIN_URL . 'dist/inserter-media-category.js', - get_asset_info( 'inserter-media-category', 'dependencies' ), - get_asset_info( 'inserter-media-category', 'version' ), - true - ); - - wp_enqueue_script( - 'classifai-extend-image-blocks', - CLASSIFAI_PLUGIN_URL . 'dist/extend-image-blocks.js', - get_asset_info( 'extend-image-blocks', 'dependencies' ), - get_asset_info( 'extend-image-blocks', 'version' ), + 'classifai-plugin-inserter-media-category-js', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-inserter-media-category.js', + get_asset_info( 'classifai-plugin-inserter-media-category', 'dependencies' ), + get_asset_info( 'classifai-plugin-inserter-media-category', 'version' ), true ); @@ -237,7 +229,7 @@ public function enqueue_admin_scripts( string $hook_suffix = '' ) { ); wp_localize_script( - 'classifai-generate-images', + 'classifai-plugin-image-generation-media-modal-js', 'classifaiDalleData', [ 'endpoint' => 'classifai/v1/generate-image', @@ -253,15 +245,15 @@ public function enqueue_admin_scripts( string $hook_suffix = '' ) { if ( 'classifai-generate-image' === $action ) { wp_enqueue_script( - 'classifai-generate-images-media-upload', - CLASSIFAI_PLUGIN_URL . 'dist/generate-image-media-upload.js', - array_merge( get_asset_info( 'generate-image-media-upload', 'dependencies' ), array( 'jquery' ) ), - get_asset_info( 'classifai-generate-images-media-upload', 'version' ), + 'classifai-plugin-image-generation-generate-image-media-upload-js', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-image-generation-generate-image-media-upload.js', + array_merge( get_asset_info( 'classifai-plugin-image-generation-generate-image-media-upload', 'dependencies' ), array( 'jquery' ) ), + get_asset_info( 'classifai-plugin-image-generation-generate-image-media-upload', 'version' ), true ); wp_localize_script( - 'classifai-generate-images-media-upload', + 'classifai-plugin-image-generation-generate-image-media-upload-js', 'classifaiGenerateImages', [ 'upload_url' => esc_url( admin_url( 'upload.php' ) ), diff --git a/includes/Classifai/Features/ImageTextExtraction.php b/includes/Classifai/Features/ImageTextExtraction.php index 7e0a40673..c896b7379 100644 --- a/includes/Classifai/Features/ImageTextExtraction.php +++ b/includes/Classifai/Features/ImageTextExtraction.php @@ -216,10 +216,10 @@ public function add_ocr_data_to_api_response() { */ public function enqueue_editor_assets() { wp_enqueue_script( - 'editor-ocr', - CLASSIFAI_PLUGIN_URL . 'dist/editor-ocr.js', - array_merge( get_asset_info( 'editor-ocr', 'dependencies' ), array( 'lodash' ) ), - get_asset_info( 'editor-ocr', 'version' ), + 'classifai-plugin-editor-ocr-js', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-editor-ocr.js', + array_merge( get_asset_info( 'classifai-plugin-editor-ocr', 'dependencies' ), array( 'lodash' ) ), + get_asset_info( 'classifai-plugin-editor-ocr', 'version' ), true ); } diff --git a/includes/Classifai/Features/TextToSpeech.php b/includes/Classifai/Features/TextToSpeech.php index 9ac3250a1..1f177fe0a 100644 --- a/includes/Classifai/Features/TextToSpeech.php +++ b/includes/Classifai/Features/TextToSpeech.php @@ -118,20 +118,15 @@ public function enqueue_editor_assets() { } wp_enqueue_script( - 'classifai-gutenberg-plugin', - CLASSIFAI_PLUGIN_URL . 'dist/gutenberg-plugin.js', - array_merge( get_asset_info( 'gutenberg-plugin', 'dependencies' ), array( 'lodash' ) ), - get_asset_info( 'gutenberg-plugin', 'version' ), - true - ); - - wp_add_inline_script( - 'classifai-gutenberg-plugin', - sprintf( - 'var classifaiTTSEnabled = %d;', - true + 'classifai-plugin-text-to-speech', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-text-to-speech.js', + array_merge( + get_asset_info( 'classifai-plugin-text-to-speech', 'dependencies' ), + array( 'lodash' ), + array( Feature::PLUGIN_AREA_SCRIPT ) ), - 'before' + get_asset_info( 'classifai-plugin-text-to-speech', 'version' ), + true ); } @@ -662,18 +657,18 @@ public function render_post_audio_controls( string $content ): string { } wp_enqueue_script( - 'classifai-post-audio-player-js', - CLASSIFAI_PLUGIN_URL . 'dist/post-audio-controls.js', - get_asset_info( 'post-audio-controls', 'dependencies' ), - get_asset_info( 'post-audio-controls', 'version' ), + 'classifai-plugin-text-to-speech-frontend-js', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-text-to-speech-frontend.js', + get_asset_info( 'classifai-plugin-text-to-speech-frontend', 'dependencies' ), + get_asset_info( 'classifai-plugin-text-to-speech-frontend', 'version' ), true ); wp_enqueue_style( - 'classifai-post-audio-player-css', - CLASSIFAI_PLUGIN_URL . 'dist/post-audio-controls.css', + 'classifai-plugin-text-to-speech-frontend-css', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-text-to-speech-frontend.css', array( 'dashicons' ), - get_asset_info( 'post-audio-controls', 'version' ), + get_asset_info( 'classifai-plugin-text-to-speech-frontend', 'version' ), 'all' ); diff --git a/includes/Classifai/Features/TitleGeneration.php b/includes/Classifai/Features/TitleGeneration.php index be6646471..a86d74388 100644 --- a/includes/Classifai/Features/TitleGeneration.php +++ b/includes/Classifai/Features/TitleGeneration.php @@ -200,15 +200,15 @@ public function enqueue_editor_assets() { } wp_enqueue_script( - 'classifai-post-status-info', - CLASSIFAI_PLUGIN_URL . 'dist/post-status-info.js', - get_asset_info( 'post-status-info', 'dependencies' ), - get_asset_info( 'post-status-info', 'version' ), + 'classifai-plugin-title-generation-js', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-title-generation.js', + get_asset_info( 'classifai-plugin-title-generation', 'dependencies' ), + get_asset_info( 'classifai-plugin-title-generation', 'version' ), true ); wp_add_inline_script( - 'classifai-post-status-info', + 'classifai-plugin-title-generation-js', sprintf( 'var classifaiChatGPTData = %s;', wp_json_encode( $this->get_localised_vars() ) @@ -231,23 +231,23 @@ public function enqueue_admin_assets( string $hook_suffix ) { if ( $screen && ! $screen->is_block_editor() ) { if ( post_type_supports( $screen->post_type, 'title' ) ) { wp_enqueue_style( - 'classifai-generate-title-classic-css', - CLASSIFAI_PLUGIN_URL . 'dist/generate-title-classic.css', + 'classifai-plugin-classic-title-generation-css', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-classic-title-generation.css', [], - get_asset_info( 'generate-title-classic', 'version' ), + get_asset_info( 'classifai-plugin-classic-title-generation', 'version' ), 'all' ); wp_enqueue_script( - 'classifai-generate-title-classic-js', - CLASSIFAI_PLUGIN_URL . 'dist/generate-title-classic.js', - array_merge( get_asset_info( 'generate-title-classic', 'dependencies' ), array( 'wp-api' ) ), + 'classifai-plugin-classic-title-generation-js', + CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-classic-title-generation.js', + array_merge( get_asset_info( 'classifai-plugin-classic-title-generation', 'dependencies' ), array( 'wp-api' ) ), get_asset_info( 'generate-title-classic', 'version' ), true ); wp_add_inline_script( - 'classifai-generate-title-classic-js', + 'classifai-plugin-classic-title-generation-js', sprintf( 'var classifaiChatGPTData = %s;', wp_json_encode( $this->get_localised_vars() ) @@ -256,13 +256,6 @@ public function enqueue_admin_assets( string $hook_suffix ) { ); } } - - wp_enqueue_style( - 'classifai-language-processing-style', - CLASSIFAI_PLUGIN_URL . 'dist/language-processing.css', - [], - get_asset_info( 'language-processing', 'version' ), - ); } } @@ -271,12 +264,12 @@ public function enqueue_admin_assets( string $hook_suffix ) { */ public function register_generated_titles_template() { ?> -