From a8ec8136f07e198434cd96c3d80a68296f6ee609 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Thu, 7 Dec 2023 22:01:52 +0530 Subject: [PATCH 1/2] add missing function --- includes/Classifai/Providers/Watson/NLU.php | 43 +++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/includes/Classifai/Providers/Watson/NLU.php b/includes/Classifai/Providers/Watson/NLU.php index 6cef7a075..fd8d86e3b 100644 --- a/includes/Classifai/Providers/Watson/NLU.php +++ b/includes/Classifai/Providers/Watson/NLU.php @@ -946,14 +946,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. From 0d7c21f1bd1ea6b97a537d9fb680ca1752f76ec7 Mon Sep 17 00:00:00 2001 From: faisal-alvi Date: Thu, 7 Dec 2023 22:02:06 +0530 Subject: [PATCH 2/2] fix the terms data object --- src/js/gutenberg-plugin.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/js/gutenberg-plugin.js b/src/js/gutenberg-plugin.js index f5287a328..1f0a23ab2 100644 --- a/src/js/gutenberg-plugin.js +++ b/src/js/gutenberg-plugin.js @@ -96,6 +96,7 @@ const ClassifAIGenerateTagsButton = () => { } let termsReady = false; + resp.terms = resp.terms?.data?.terms; const taxonomies = resp.terms; const taxTerms = {}; const taxTermsExisting = {};