Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion includes/Classifai/Admin/SimilarTermsListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ public function generate_term_html( $term, $similar_term, $score = null ) {
's' => isset( $_REQUEST['s'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) : false, // phpcs:ignore WordPress.Security.NonceVerification.Recommended
);
$merge_url = add_query_arg( $args, wp_nonce_url( admin_url( 'admin-post.php' ), 'classifai_merge_term' ) );
$score = $score ? ( $score > 1 ? $score - 1 : $score ) : '';

if ( ! $score ) {
$score = '';
} else {
$score = $score > 1 ? $score - 1 : $score;
}

return sprintf(
// translators: %s: Term name, %d: Term ID.
Expand Down
4 changes: 2 additions & 2 deletions includes/Classifai/Admin/UserProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function user_settings( \WP_User $user ) {
}
?>
<div id="classifai-profile-features-section">
<h3><?php esc_html_e( 'ClassifAI features', 'classifai' ); ?></h3>
<h3><?php esc_html_e( 'ClassifAI Features', 'classifai' ); ?></h3>

<table class="form-table" role="presentation">
<?php
Expand All @@ -61,7 +61,7 @@ public function user_settings( \WP_User $user ) {
?>
<tr class="classifai-features-row">
<th scope="row"><?php echo esc_html( $feature_name ); ?></th>
<td >
<td>
<label for="<?php echo esc_attr( $this->opt_out_key . '_' . $feature ); ?>">
<input
name="<?php echo esc_attr( $this->opt_out_key . '[]' ); ?>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ import save from './save';
import block from './block.json';
import { ReactComponent as icon } from '../../../../assets/img/block-icon.svg';

/* Uncomment for CSS overrides in the admin */
// import './index.css';

/**
* Register block
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ function render_block_callback( array $attributes ): string {

// Render block in Front-end.
ob_start();
include __DIR__ . '/markup.php';
include_once __DIR__ . '/markup.php';
return ob_get_clean();
}
1 change: 0 additions & 1 deletion includes/Classifai/Command/ClassifaiCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,6 @@ public function crop( $args = [], $opts = [] ) {
$image_cropping = new ImageCropping();
$provider = $image_cropping->get_feature_provider_instance();
$provider_class = get_class( $provider );
$settings = $image_cropping->get_settings( $provider_class::ID );
$default_opts = [
'limit' => false,
];
Expand Down
3 changes: 1 addition & 2 deletions includes/Classifai/Command/RSSImporterCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ public function get_rss_item_info( $item ) {
* @param string $feed_url The feed URL.
*/
public function get_rss_feed( $feed_url ) {
$rss = simplexml_load_file( $feed_url );
return $rss;
return simplexml_load_file( $feed_url );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use function Classifai\get_asset_info;
use function Classifai\clean_input;
use function Classifai\get_resource_type;

/**
* Class AudioTranscriptsGeneration
Expand Down
23 changes: 12 additions & 11 deletions includes/Classifai/Features/Classification.php
Original file line number Diff line number Diff line change
Expand Up @@ -1058,18 +1058,19 @@ public function migrate_settings() {
}

// Post statuses
if ( isset( $old_settings['post_statuses'] ) ) {
if ( is_array( $old_settings['post_statuses'] ) ) {
foreach ( $old_settings['post_statuses'] as $post_status => $value ) {
if ( 1 === $value ) {
$new_settings['post_statuses'][ $post_status ] = $post_status;
continue;
} elseif ( is_null( $value ) ) {
$new_settings['post_statuses'][ $post_status ] = '0';
continue;
}
$new_settings['post_statuses'][ $post_status ] = $value;
if (
isset( $old_settings['post_statuses'] ) &&
is_array( $old_settings['post_statuses'] )
) {
foreach ( $old_settings['post_statuses'] as $post_status => $value ) {
if ( 1 === $value ) {
$new_settings['post_statuses'][ $post_status ] = $post_status;
continue;
} elseif ( is_null( $value ) ) {
$new_settings['post_statuses'][ $post_status ] = '0';
continue;
}
$new_settings['post_statuses'][ $post_status ] = $value;
}
}

Expand Down
2 changes: 0 additions & 2 deletions includes/Classifai/Features/ContentResizing.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,6 @@ public function get_settings( $index = false ) {
* @return array
*/
public function sanitize_default_feature_settings( array $new_settings ): array {
$settings = $this->get_settings();

$new_settings['condense_text_prompt'] = sanitize_prompts( 'condense_text_prompt', $new_settings );
$new_settings['expand_text_prompt'] = sanitize_prompts( 'expand_text_prompt', $new_settings );

Expand Down
5 changes: 2 additions & 3 deletions includes/Classifai/Features/DescriptiveTextGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,8 @@ public function get_alt_text_settings(): array {
*/
public function get_processing_mode(): string {
$settings = $this->get_settings();
$value = $settings['processing_mode'] ?? 'automatic';

return $value;
return $settings['processing_mode'] ?? 'automatic';
}

/**
Expand Down Expand Up @@ -498,7 +497,7 @@ public function migrate_settings() {
if ( isset( $old_settings['enable_image_captions'] ) ) {
$new_settings['descriptive_text_fields'] = $old_settings['enable_image_captions'];

foreach ( $new_settings['descriptive_text_fields'] as $key => $value ) {
foreach ( $new_settings['descriptive_text_fields'] as $value ) {
if ( '0' !== $value ) {
$new_settings['status'] = '1';
break;
Expand Down
68 changes: 35 additions & 33 deletions includes/Classifai/Features/ExcerptGeneration.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,39 +262,41 @@ public function enqueue_admin_assets( string $hook_suffix ) {
$screen = get_current_screen();

// Load the assets for the classic editor.
if ( $screen && ! $screen->is_block_editor() ) {
if ( post_type_supports( $screen->post_type, 'excerpt' ) ) {
wp_enqueue_style(
'classifai-plugin-classic-excerpt-generation-css',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-classic-excerpt-generation.css',
[],
get_asset_info( 'classifai-plugin-classic-excerpt-generation', 'version' ),
'all'
);

wp_enqueue_script(
'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-plugin-classic-excerpt-generation-js',
sprintf(
'var classifaiGenerateExcerpt = %s;',
wp_json_encode(
[
'path' => '/classifai/v1/generate-excerpt/',
'buttonText' => __( 'Generate excerpt', 'classifai' ),
'regenerateText' => __( 'Re-generate excerpt', 'classifai' ),
]
)
),
'before'
);
}
if (
$screen &&
! $screen->is_block_editor() &&
post_type_supports( $screen->post_type, 'excerpt' )
) {
wp_enqueue_style(
'classifai-plugin-classic-excerpt-generation-css',
CLASSIFAI_PLUGIN_URL . 'dist/classifai-plugin-classic-excerpt-generation.css',
[],
get_asset_info( 'classifai-plugin-classic-excerpt-generation', 'version' ),
'all'
);

wp_enqueue_script(
'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-plugin-classic-excerpt-generation-js',
sprintf(
'var classifaiGenerateExcerpt = %s;',
wp_json_encode(
[
'path' => '/classifai/v1/generate-excerpt/',
'buttonText' => __( 'Generate excerpt', 'classifai' ),
'regenerateText' => __( 'Re-generate excerpt', 'classifai' ),
]
)
),
'before'
);
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions includes/Classifai/Features/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,13 +817,14 @@ public function render_auto_caption_fields( array $args ) {
$setting_index = $this->get_settings();
$default_value = '';

if ( isset( $setting_index['enable_image_captions'] ) ) {
if ( ! is_array( $setting_index['enable_image_captions'] ) ) {
if ( '1' === $setting_index['enable_image_captions'] ) {
$default_value = 'alt';
} elseif ( 'no' === $setting_index['enable_image_captions'] ) {
$default_value = '';
}
if (
isset( $setting_index['enable_image_captions'] ) &&
! is_array( $setting_index['enable_image_captions'] )
) {
if ( '1' === $setting_index['enable_image_captions'] ) {
$default_value = 'alt';
} elseif ( 'no' === $setting_index['enable_image_captions'] ) {
$default_value = '';
}
}

Expand Down Expand Up @@ -1202,10 +1203,9 @@ public function get_feature_provider_instance( string $provider_id = '' ) {
return null;
}

$provider_class = get_class( $provider_instance );
$provider_instance = new $provider_class( $this );
$provider_class = get_class( $provider_instance );

return $provider_instance;
return new $provider_class( $this );
}

/**
Expand Down
3 changes: 1 addition & 2 deletions includes/Classifai/Features/ImageCropping.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,8 @@ public function get_wp_filesystem() {
*/
public function get_processing_mode(): string {
$settings = $this->get_settings();
$value = $settings['processing_mode'] ?? 'automatic';

return $value;
return $settings['processing_mode'] ?? 'automatic';
}

/**
Expand Down
3 changes: 1 addition & 2 deletions includes/Classifai/Features/ImageTagsGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,8 @@ public function get_taxonomies( array $object_types = [] ): array {
*/
public function get_processing_mode(): string {
$settings = $this->get_settings();
$value = $settings['processing_mode'] ?? 'automatic';

return $value;
return $settings['processing_mode'] ?? 'automatic';
}

/**
Expand Down
3 changes: 1 addition & 2 deletions includes/Classifai/Features/ImageTextExtraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,8 @@ public function sanitize_default_feature_settings( array $new_settings ): array
*/
public function get_processing_mode(): string {
$settings = $this->get_settings();
$value = $settings['processing_mode'] ?? 'automatic';

return $value;
return $settings['processing_mode'] ?? 'automatic';
}

/**
Expand Down
9 changes: 5 additions & 4 deletions includes/Classifai/Features/Moderation.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,11 @@ public function comment_moderation_permissions_check( WP_REST_Request $request )
}

// Handle checks for the comment item_type.
if ( 'comment' === $item_type ) {
if ( ! in_array( 'comments', $this->get_moderation_content_settings(), true ) ) {
return new WP_Error( 'not_enabled', esc_html__( 'Comment moderation not currently enabled.', 'classifai' ) );
}
if (
'comment' === $item_type &&
! in_array( 'comments', $this->get_moderation_content_settings(), true )
) {
return new WP_Error( 'not_enabled', esc_html__( 'Comment moderation not currently enabled.', 'classifai' ) );
}

// Ensure the feature is enabled. Also runs a user check.
Expand Down
3 changes: 1 addition & 2 deletions includes/Classifai/Features/PDFTextExtraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,8 @@ public function sanitize_default_feature_settings( array $new_settings ): array
*/
public function get_processing_mode(): string {
$settings = $this->get_settings();
$value = $settings['processing_mode'] ?? 'automatic';

return $value;
return $settings['processing_mode'] ?? 'automatic';
}

/**
Expand Down
28 changes: 11 additions & 17 deletions includes/Classifai/Features/Smart404EPIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,15 @@ public function add_vector_field_to_post_sync( array $args, int $post_id ): arra
}

// Show an error message if something went wrong.
if ( is_wp_error( $embedding ) ) {
if ( is_indexing_wpcli() ) {
WP_CLI::warning(
sprintf(
/* translators: %d is the post ID; %s is the error message */
esc_html__( 'Error generating embedding for ID #%1$d: %2$s', 'classifai' ),
$post_id,
$embedding->get_error_message()
)
);
}
if ( is_wp_error( $embedding ) && ! is_indexing_wpcli() ) {
WP_CLI::warning(
sprintf(
/* translators: %d is the post ID; %s is the error message */
esc_html__( 'Error generating embedding for ID #%1$d: %2$s', 'classifai' ),
$post_id,
$embedding->get_error_message()
)
);
}
}
} else {
Expand Down Expand Up @@ -331,9 +329,7 @@ public function get_embedding( string $text, bool $cache = false ) {
*/
public function get_embeddings( array $strings ) {
// Generate the embeddings.
$embeddings = $this->embeddings_handler->generate_embeddings( $strings, new Smart404() );

return $embeddings;
return $this->embeddings_handler->generate_embeddings( $strings, new Smart404() );
}

/**
Expand Down Expand Up @@ -582,9 +578,7 @@ private function default_search_post_query( string $query, array $post_type, int
$search_query->query = wp_parse_args( $search_args );
$search_query->query_vars = $search_query->query;

$default_query = $indexable->format_args( $search_query->query_vars, $search_query );

return $default_query;
return $indexable->format_args( $search_query->query_vars, $search_query );
}

/**
Expand Down
Loading