Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/566 Confirm Classification before Save #609

Merged
merged 79 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
4395373
add a new modal
faisal-alvi Oct 30, 2023
d669b57
show terms in the modal
faisal-alvi Oct 30, 2023
25bc752
update existing logic
faisal-alvi Oct 30, 2023
5e83c74
add a new attr: linkTerms
faisal-alvi Oct 30, 2023
7e59182
handle new term in the request
faisal-alvi Oct 30, 2023
97adee0
avoid term deletion
faisal-alvi Oct 30, 2023
7d8d918
create terms but skip linking
faisal-alvi Oct 30, 2023
c5c08a2
return new set of terms when linking disabled
faisal-alvi Oct 30, 2023
d250dd9
supply the Object values; dont pass term name to avoid error
faisal-alvi Oct 31, 2023
85b1f9d
tweak: design and logic change; TaxonomyControls
faisal-alvi Oct 31, 2023
0b71c25
tweak: add new term logic added
faisal-alvi Nov 1, 2023
3854e5d
tweak: append "[AI]" prefix
faisal-alvi Nov 1, 2023
4c13225
appendAIPrefix
faisal-alvi Nov 2, 2023
e01cffb
also show existing terms along with AI terms
faisal-alvi Nov 2, 2023
3c4ba25
pre publish post panel added
faisal-alvi Nov 2, 2023
cfc7369
handle pre publish post request
faisal-alvi Nov 2, 2023
5cd1e38
return the update terms
faisal-alvi Nov 2, 2023
48cf62e
if popup opened; don't display in pre-pub-panel
faisal-alvi Nov 2, 2023
2820079
add notes at the bottom
faisal-alvi Nov 2, 2023
cd66fd5
retun null if popupOpened
faisal-alvi Nov 2, 2023
9022fce
pass link terms parameter
faisal-alvi Nov 2, 2023
748e3e3
the design fixes
faisal-alvi Nov 2, 2023
e6da0b3
handle the updated response when terms not linked
faisal-alvi Nov 2, 2023
b1474a5
eslint: fixes for taxo control file
faisal-alvi Nov 3, 2023
222d307
eslint: fixes for gutenberg plugin file
faisal-alvi Nov 3, 2023
efb3e17
eslint: fixes for helper file
faisal-alvi Nov 3, 2023
bf915af
eslint: a few more fixes
faisal-alvi Nov 3, 2023
51542d3
show note when no unique terms returned
faisal-alvi Nov 3, 2023
396a353
add hr to each taxo
faisal-alvi Nov 3, 2023
f54372e
callback args added to open popup after response received
faisal-alvi Nov 3, 2023
51d0635
eslint: single quote issue fixed
faisal-alvi Nov 3, 2023
e235fd2
eslint: few more minor fixes
faisal-alvi Nov 3, 2023
9579f49
eslint: jdoc fixes
faisal-alvi Nov 3, 2023
4125f3a
display dropdowns even when no unique returns
faisal-alvi Nov 6, 2023
bd8a2dc
display message above the field
faisal-alvi Nov 6, 2023
5449def
a few changes + return null on non-watson taxonomy
faisal-alvi Nov 6, 2023
074e6ca
fix width to avoid button ttoo close to text
faisal-alvi Nov 6, 2023
4539795
stop auto classify on pre publish panel
faisal-alvi Nov 6, 2023
ec50547
delete the taxonom file
faisal-alvi Nov 6, 2023
c39ddc6
move to the new location
faisal-alvi Nov 6, 2023
73d2b70
update imports as per new location
faisal-alvi Nov 6, 2023
61d2814
eslint: minor fixes
faisal-alvi Nov 6, 2023
79206d1
eslint: already declared fixes
faisal-alvi Nov 6, 2023
d76a4b4
eslint: fix already declared select
faisal-alvi Nov 6, 2023
57a1409
adding a global setting for mode
faisal-alvi Nov 7, 2023
bf85790
detect existing vs new users and serve default value accordingly.
faisal-alvi Nov 8, 2023
376c675
toggle as per the global settings
faisal-alvi Nov 8, 2023
f7bcdb9
use isset before proceed
faisal-alvi Nov 8, 2023
7976f29
update the test
faisal-alvi Nov 8, 2023
356c17d
remove unnecssary comment
faisal-alvi Nov 8, 2023
626419a
fix cypress test failure
faisal-alvi Nov 8, 2023
9ceb17b
Merge branch 'develop' into enhancement/566
dkotter Nov 9, 2023
7d3c78c
fix php warning issue
faisal-alvi Nov 13, 2023
c58259c
fix first time setting not saving issue
faisal-alvi Nov 13, 2023
734e38b
Decode HTML entities
faisal-alvi Nov 13, 2023
1c88558
error message tweaks
faisal-alvi Nov 13, 2023
ad66a0c
add e2e tests
faisal-alvi Nov 14, 2023
55d72ae
eslint fixes
faisal-alvi Nov 14, 2023
92afec6
fix test fail issue
faisal-alvi Nov 14, 2023
f444386
test fail fix: open panel before check
faisal-alvi Nov 14, 2023
d0b4637
use util functions
faisal-alvi Nov 14, 2023
edf0bd8
cypress fix for WP 5.8 (min)
faisal-alvi Nov 14, 2023
5104e13
bum min wp 6.1
faisal-alvi Nov 14, 2023
9b511fe
set 6.1 wp min in workflow
faisal-alvi Nov 14, 2023
6d0a752
combine the tests in the relative file
faisal-alvi Nov 15, 2023
fd3dc6e
few more fixes for test failures
faisal-alvi Nov 15, 2023
1e68825
test for NewTestTerm updated
faisal-alvi Nov 15, 2023
1cab03a
min wp required bump to 6.1
faisal-alvi Nov 15, 2023
91c88d6
function to get_all_feature_taxonomies
faisal-alvi Nov 17, 2023
109cac6
pass feature taxonomies for filter
faisal-alvi Nov 17, 2023
3b79afe
show only the feature taxonomy set in settings
faisal-alvi Nov 17, 2023
627832a
fix eslint error
faisal-alvi Nov 17, 2023
07f4dcb
Update labeling
dkotter Nov 20, 2023
bd61fb6
Update since version
dkotter Nov 20, 2023
e44e864
Add an older version of mochawesome-json-to-md as the latest version …
dkotter Nov 20, 2023
9f9fa57
Merge branch 'develop' into enhancement/566
dkotter Nov 21, 2023
a1d8a26
Add disable link to our modal
dkotter Nov 21, 2023
3dac84e
Ensure we actually run our tests
dkotter Nov 21, 2023
fa8b86e
Fix tests
dkotter Nov 21, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
matrix:
core:
- {name: 'WP latest', version: 'latest'}
- {name: 'WP minimum', version: 'WordPress/WordPress#5.8'}
- {name: 'WP minimum', version: 'WordPress/WordPress#6.1'}
- {name: 'WP trunk', version: 'WordPress/WordPress#master'}
steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{

Check warning on line 1 in .wp-env.json

View workflow job for this annotation

GitHub Actions / eslint

File ignored by default.
"core": "WordPress/WordPress#6.1",
"plugins": [".", "./tests/test-plugin", "https://downloads.wordpress.org/plugin/classic-editor.zip"],
"env": {
"tests": {
Expand Down
2 changes: 1 addition & 1 deletion classifai.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Update URI: https://classifaiplugin.com
* Description: Enhance your WordPress content with Artificial Intelligence and Machine Learning services.
* Version: 2.5.0-dev
* Requires at least: 5.8
* Requires at least: 6.1
* Requires PHP: 7.4
* Author: 10up
* Author URI: https://10up.com
Expand Down
55 changes: 41 additions & 14 deletions includes/Classifai/Admin/SavePostHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use \Classifai\Providers\Azure\TextToSpeech;
use \Classifai\Watson\Normalizer;
use function Classifai\get_classification_mode;

/**
* Classifies Posts based on the current ClassifAI configuration.
Expand All @@ -20,6 +21,7 @@ class SavePostHandler {
*/
public function register() {
add_filter( 'removable_query_args', [ $this, 'classifai_removable_query_args' ] );
add_filter( 'default_post_metadata', [ $this, 'default_post_metadata' ], 10, 3 );
add_action( 'save_post', [ $this, 'did_save_post' ] );
add_action( 'admin_notices', [ $this, 'show_error_if' ] );
add_action( 'admin_post_classifai_classify_post', array( $this, 'classifai_classify_post' ) );
Expand Down Expand Up @@ -58,6 +60,28 @@ public function is_configured() {
return ! empty( get_option( 'classifai_configured' ) ) && ! empty( get_option( 'classifai_watson_nlu' )['credentials']['watson_url'] );
}

/**
* Sets the default value for the _classifai_process_content meta key.
*
* @param mixed $value The value get_metadata() should return - a single metadata value,
* or an array of values.
* @param int $object_id Object ID.
* @param string $meta_key Meta key.
*
* @return mixed
*/
public function default_post_metadata( $value, $object_id, $meta_key ) {
if ( '_classifai_process_content' === $meta_key ) {
if ( 'automatic_classification' === get_classification_mode() ) {
return 'yes';
} else {
return 'no';
}
}

return $value;
}

/**
* If current post type support is enabled in ClassifAI settings, it
* is tagged using the IBM Watson classification result.
Expand Down Expand Up @@ -107,11 +131,12 @@ public function did_save_post( $post_id ) {
* Classifies the post specified with the PostClassifier object.
* Existing terms relationships are removed before classification.
*
* @param int $post_id the post to classify & link
* @param int $post_id the post to classify & link.
* @param bool $link_terms Whether to link the terms to the post.
*
* @return array
*/
public function classify( $post_id ) {
public function classify( $post_id, $link_terms = true ) {
/**
* Filter whether ClassifAI should classify a post.
*
Expand All @@ -133,23 +158,25 @@ public function classify( $post_id ) {

$classifier = $this->get_classifier();

if ( \Classifai\get_feature_enabled( 'category' ) ) {
wp_delete_object_term_relationships( $post_id, \Classifai\get_feature_taxonomy( 'category' ) );
}
if ( $link_terms ) {
if ( \Classifai\get_feature_enabled( 'category' ) ) {
wp_delete_object_term_relationships( $post_id, \Classifai\get_feature_taxonomy( 'category' ) );
}

if ( \Classifai\get_feature_enabled( 'keyword' ) ) {
wp_delete_object_term_relationships( $post_id, \Classifai\get_feature_taxonomy( 'keyword' ) );
}
if ( \Classifai\get_feature_enabled( 'keyword' ) ) {
wp_delete_object_term_relationships( $post_id, \Classifai\get_feature_taxonomy( 'keyword' ) );
}

if ( \Classifai\get_feature_enabled( 'concept' ) ) {
wp_delete_object_term_relationships( $post_id, \Classifai\get_feature_taxonomy( 'concept' ) );
}
if ( \Classifai\get_feature_enabled( 'concept' ) ) {
wp_delete_object_term_relationships( $post_id, \Classifai\get_feature_taxonomy( 'concept' ) );
}

if ( \Classifai\get_feature_enabled( 'entity' ) ) {
wp_delete_object_term_relationships( $post_id, \Classifai\get_feature_taxonomy( 'entity' ) );
if ( \Classifai\get_feature_enabled( 'entity' ) ) {
wp_delete_object_term_relationships( $post_id, \Classifai\get_feature_taxonomy( 'entity' ) );
}
}

$output = $classifier->classify_and_link( $post_id );
$output = $classifier->classify_and_link( $post_id, [], $link_terms );

if ( is_wp_error( $output ) ) {
update_post_meta(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { list, grid } from '@wordpress/icons';
import { useSelect } from '@wordpress/data';
import ServerSideRender from '@wordpress/server-side-render';
import TaxonomyControls from './inspector-controls/taxonomy-controls';
import TaxonomyControls from '../../../../src/js/taxonomy-controls';
import { usePostTypes } from './utils';

/**
Expand Down

This file was deleted.

29 changes: 28 additions & 1 deletion includes/Classifai/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Classifai\Providers\Provider;
use Classifai\Providers\Azure;
use Classifai\Providers\Watson\NLU;
use Classifai\Services\Service;
use Classifai\Services\ServicesManager;
use WP_Error;
Expand Down Expand Up @@ -126,7 +127,6 @@ function reset_plugin_settings() {
}
}


/**
* Returns the currently configured Watson API URL. Lookup order is,
*
Expand Down Expand Up @@ -170,6 +170,33 @@ function get_watson_username() {
}
}

/**
* Get Classification mode.
*
* @since 2.5.0
*
* @return string
*/
function get_classification_mode() {
$provider = new NLU( 'Natural Language Understanding' );
$settings = get_plugin_settings( 'language_processing', 'Natural Language Understanding' );
$value = isset( $settings['classification_mode'] ) ? $settings['classification_mode'] : '';

if ( $provider->is_configured() ) {
if ( empty( $value ) ) {
// existing users
// default: automatic_classification
return 'automatic_classification';
}
} else {
// new users
// default: manual_review
return 'manual_review';
}

return $value;
}

/**
* Returns the currently configured Watson username. Lookup order is,
*
Expand Down
17 changes: 12 additions & 5 deletions includes/Classifai/PostClassifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,21 @@ public function classify( $post_id, $opts = [] ) {
*
* @param int $post_id The post to classify
* @param array $opts The classification options
* @param bool $link_terms Whether to link the terms or not.
*
* @return array
*/
public function classify_and_link( $post_id, $opts = [] ) {
public function classify_and_link( $post_id, $opts = [], $link_terms = true ) {
$output = $this->classify( $post_id, $opts );

if ( is_wp_error( $output ) ) {
return $output;
} elseif ( empty( $output ) ) {
return false;
} else {
$this->link( $post_id, $output, $opts );
return $output;
$link_output = $this->link( $post_id, $output, $opts, $link_terms );

return $link_terms ? $output : $link_output;
}
}

Expand All @@ -89,10 +92,14 @@ public function classify_and_link( $post_id, $opts = [] ) {
* @param int $post_id The post id.
* @param array $output The classification results from Watson NLU.
* @param array $opts Link options.
* @param bool $link_terms Whether to link the terms or not.
*
* @return array The linked output.
*/
public function link( $post_id, $output, $opts = [] ) {
public function link( $post_id, $output, $opts = [], $link_terms = true ) {
$linker = $this->get_linker();
$linker->link( $post_id, $output, $opts );

return $linker->link( $post_id, $output, $opts, $link_terms );
}

/* helpers */
Expand Down
2 changes: 1 addition & 1 deletion includes/Classifai/Providers/OpenAI/Embeddings.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ public function render_metabox( $post ) {
<p>
<label for="classifai-process-content" class="classifai-preview-toggle">
<input type="checkbox" value="yes" name="_classifai_process_content" id="classifai-process-content" <?php echo esc_html( $checked ); ?> />
<strong><?php esc_html_e( 'Process content on update', 'classifai' ); ?></strong>
<strong><?php esc_html_e( 'Automatically tag content on update', 'classifai' ); ?></strong>
</label>
</p>
</div>
Expand Down
Loading
Loading