Skip to content

Commit

Permalink
Merge pull request #634 from 10up/enhancement/566-2
Browse files Browse the repository at this point in the history
Enhancement/566-2 Fix the Classification Popup after refactoring
  • Loading branch information
Sidsector9 committed Dec 21, 2023
2 parents 2967390 + b4df0d9 commit fb6c7b7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
43 changes: 40 additions & 3 deletions includes/Classifai/Providers/Watson/NLU.php
Original file line number Diff line number Diff line change
Expand Up @@ -951,14 +951,51 @@ public function generate_post_tags( WP_REST_Request $request ) {
return new WP_Error( 'post_id_required', esc_html__( 'Post ID is required to classify post.', 'classifai' ) );
}

$result = $this->rest_endpoint_callback(
$post_id,
'classify'
);

return rest_ensure_response(
$this->rest_endpoint_callback(
$post_id,
'classify'
array(
'terms' => $result,
'feature_taxonomies' => $this->get_all_feature_taxonomies(),
)
);
}

/**
* Get all feature taxonomies.
*
* @since 2.5.0
*
* @return array|WP_Error
*/
public function get_all_feature_taxonomies() {
// Get all feature taxonomies.
$feature_taxonomies = [];
foreach ( [ 'category', 'keyword', 'concept', 'entity' ] as $feature ) {
if ( \Classifai\get_feature_enabled( $feature ) ) {
$taxonomy = \Classifai\get_feature_taxonomy( $feature );
$permission = check_term_permissions( $taxonomy );

if ( is_wp_error( $permission ) ) {
return $permission;
}

if ( 'post_tag' === $taxonomy ) {
$taxonomy = 'tags';
}
if ( 'category' === $taxonomy ) {
$taxonomy = 'categories';
}
$feature_taxonomies[] = $taxonomy;
}
}

return $feature_taxonomies;
}

/**
* Common entry point for all REST endpoints for this provider.
* This is called by the Service.
Expand Down
2 changes: 2 additions & 0 deletions src/js/gutenberg-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ const ClassifAIGenerateTagsButton = () => {
setFeatureTaxonomies( resp.feature_taxonomies );
}

let termsReady = false;

Check failure on line 98 in src/js/gutenberg-plugin.js

View workflow job for this annotation

GitHub Actions / eslint

'termsReady' is never reassigned. Use 'const' instead
resp.terms = resp.terms?.data?.terms;
const taxonomies = resp.terms;
const taxTerms = {};
const taxTermsExisting = {};
Expand Down

0 comments on commit fb6c7b7

Please sign in to comment.