Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:10up/classifai into enhancement/…
Browse files Browse the repository at this point in the history
…react-settings
  • Loading branch information
iamdharmesh committed Sep 27, 2024
2 parents f73d7c4 + c1da04f commit eaa07bf
Show file tree
Hide file tree
Showing 60 changed files with 1,088 additions and 1,029 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
"react/jsx-no-undef": "off"
},
"extends": ["plugin:@wordpress/eslint-plugin/recommended"],
"ignorePatterns": ["*.json"]
"ignorePatterns": ["*.json", "webpack.config.js"]
}
2 changes: 1 addition & 1 deletion assets/img/block-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions includes/Classifai/Features/AudioTranscriptsGeneration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
34 changes: 17 additions & 17 deletions includes/Classifai/Features/Classification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
}
Expand 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
);

Expand All @@ -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(
Expand Down Expand Up @@ -738,7 +738,7 @@ public function render_previewer( string $active_feature ) {
* @return string
*/
public function get_enable_description(): string {
return esc_html__( 'Enables automatic content classification.', 'classifai' );
return esc_html__( 'Enables content classification.', 'classifai' );
}

/**
Expand Down
32 changes: 7 additions & 25 deletions includes/Classifai/Features/ContentResizing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ] );
}

/**
Expand Down Expand Up @@ -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.
*
Expand Down
31 changes: 12 additions & 19 deletions includes/Classifai/Features/ExcerptGeneration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand All @@ -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(
Expand All @@ -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' ),
);
}
}

Expand Down
26 changes: 26 additions & 0 deletions includes/Classifai/Features/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use WP_Error;
use function Classifai\find_provider_class;
use function Classifai\should_use_legacy_settings_panel;
use function Classifai\get_asset_info;

abstract class Feature {
/**
Expand All @@ -17,6 +18,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.
*
Expand Down Expand Up @@ -58,6 +69,8 @@ public function setup() {
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();
}
Expand Down Expand Up @@ -131,6 +144,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.
*
Expand Down
42 changes: 17 additions & 25 deletions includes/Classifai/Features/ImageGeneration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand All @@ -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',
Expand All @@ -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' ) ),
Expand Down
8 changes: 4 additions & 4 deletions includes/Classifai/Features/ImageTextExtraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
Loading

0 comments on commit eaa07bf

Please sign in to comment.