classifai icon indicating copy to clipboard operation
classifai copied to clipboard

Add option to do language processing for existing content in Classic Editor

Open thrijith opened this issue 4 years ago • 8 comments

https://github.com/10up/classifai/issues/202

Description of the Change

Allows generating tags for published post content without having to save the post to do so.

Benefits

  • Tag generation can be done on existing post without having to Update the post, doesn't trigger normal post save actions.

Possible Drawbacks

  • Block editor requires a refresh once tags are generated, don't see an option that updates the metabox value programmatically.
  • Trying to update records based on generated terms, breaks the editor using following snippet.
wp.data.dispatch( 'core' ).editEntityRecord(
            'postType',
            currentPost.type,
            currentPost.id,
            { [e]: response[e] } // [e] is taxonomy name, response[e] are ids of the new terms
        );

Verification Process

  • Tested language processing in Classic Editor and Block Editor

Checklist:

  • [x] I have read the CONTRIBUTING document.
  • [x] My code follows the code style of this project.
  • [x] My change requires a change to the documentation.
  • [x] I have updated the documentation accordingly.
  • [ ] I have added tests to cover my change.
  • [ ] All new and existing tests passed.

Applicable Issues

Fixes https://github.com/10up/classifai/issues/202

Changelog Entry

  • Add support to process language for existing content

thrijith avatar Feb 26 '21 21:02 thrijith

@thrijith mind helping resolve the merge conflicts here?

@dkotter @dinhtungdu either of you able to help review here?

jeffpaul avatar Jan 17 '22 22:01 jeffpaul

@thrijith Tested this PR against WordPress 5.9 beta, I got this fatal error when I tried to edit a post:

Fatal error: Uncaught TypeError: array_intersect_key(): Argument #1 ($array) must be of type array, string given in /Users/tenup/Sites/oss/app/public/wp-includes/rest-api/class-wp-rest-server.php on line 1482

My Site Health Info
### wp-core ###

version: 5.9-RC2-52594
site_language: en_US
user_language: en_US
timezone: +00:00
permalink: undefined
https_status: true
multisite: false
user_registration: 0
blog_public: 1
default_comment_status: open
environment_type: local
user_count: 2
dotorg_communication: true

### wp-paths-sizes ###

wordpress_path: /Users/tenup/Sites/oss/app/public
wordpress_size: 49.90 MB (52325190 bytes)
uploads_path: /Users/tenup/Sites/oss/app/public/wp-content/uploads
uploads_size: 122.22 MB (128152057 bytes)
themes_path: /Users/tenup/Sites/oss/app/public/wp-content/themes
themes_size: 24.50 MB (25688534 bytes)
plugins_path: /Users/tenup/Sites/oss/app/public/wp-content/plugins
plugins_size: 2.57 GB (2761524561 bytes)
database_size: 3.00 MB (3145728 bytes)
total_size: 2.77 GB (2970836070 bytes)

### wp-active-theme ###

name: Twenty Twenty-Two (twentytwentytwo)
version: 1.0
author: the WordPress team
author_website: https://wordpress.org/
parent_theme: none
theme_features: core-block-patterns, post-thumbnails, responsive-embeds, editor-styles, html5, automatic-feed-links, block-templates, widgets-block-editor, wp-block-styles, editor-style
theme_path: /Users/tenup/Sites/oss/app/public/wp-content/themes/twentytwentytwo
auto_update: Disabled

### wp-themes-inactive (13) ###

Emptytheme: version: 1.0, author: the WordPress team, Auto-updates disabled
TT1 Blocks: version: 0.4.8, author: the WordPress team, Auto-updates disabled
Twenty Eleven: version: 3.9, author: the WordPress team, Auto-updates disabled
Twenty Fifteen: version: 3.0, author: the WordPress team, Auto-updates disabled
Twenty Fourteen: version: 3.2, author: the WordPress team, Auto-updates disabled
Twenty Nineteen: version: 2.1, author: the WordPress team, Auto-updates disabled
Twenty Seventeen: version: 2.8, author: the WordPress team, Auto-updates disabled
Twenty Sixteen: version: 2.5, author: the WordPress team, Auto-updates disabled
Twenty Ten: version: 3.5, author: the WordPress team, Auto-updates disabled
Twenty Thirteen: version: 3.4, author: the WordPress team, Auto-updates disabled
Twenty Twelve: version: 3.5, author: the WordPress team, Auto-updates disabled
Twenty Twenty: version: 1.8, author: the WordPress team, Auto-updates disabled
Twenty Twenty-One: version: 1.4, author: the WordPress team, Auto-updates disabled

### wp-plugins-active (2) ###

ClassifAI: version: 1.6.0, author: 10up, Auto-updates disabled
User Switching: version: 1.5.8, author: John Blackbourn & contributors, Auto-updates disabled

### wp-plugins-inactive (17) ###

Accessibility CheckUp: version: 1.1.9, author: 10up, Auto-updates disabled
Akismet Anti-Spam: version: 4.2.1, author: Automattic, Auto-updates disabled
Autoshare for Twitter: version: 1.0.5, author: 10up (latest version: 1.0.6), Auto-updates disabled
Block for Apple Maps: version: 1.0.1, author: 10up, Auto-updates disabled
Classic Editor: version: 1.6.2, author: WordPress Contributors, Auto-updates disabled
Distributor: version: 1.6.6-dev, author: 10up Inc., Auto-updates disabled
ElasticPress: version: 3.6.2, author: 10up (latest version: 3.6.6), Auto-updates disabled
Fox Admin Step Up MFA: version: 1.0.0-dev, author: 10up, Auto-updates disabled
Gutenberg: version: 11.7.1, author: Gutenberg Team (latest version: 12.3.2), Auto-updates disabled
miniOrange 2 Factor Authentication: version: 5.4.44, author: miniOrange (latest version: 5.4.50), Auto-updates disabled
Publisher Media Kit: version: 0.9.0, author: 10up (latest version: 1.0.0), Auto-updates disabled
Restricted Site Access: version: 7.2.0, author: Jake Goldman, 10up, Oomph, Auto-updates disabled
Retro Winamp Block: version: 0.1.0, author: 10up (latest version: 1.0.1), Auto-updates disabled
Simple Local Avatars: version: 2.2.0, author: Jake Goldman, 10up, Auto-updates disabled
Simple Podcasting: version: 1.2.0, author: 10up (latest version: 1.2.1), Auto-updates disabled
Sophi: version: 1.0.8-dev, author: 10up (latest version: 1.0.8), Auto-updates disabled
WP 2FA - Two-factor authentication for WordPress: version: 1.7.1, author: WP White Security (latest version: 2.1.0), Auto-updates disabled

### wp-media ###

image_editor: WP_Image_Editor_GD
imagick_module_version: Not available
imagemagick_version: Not available
imagick_version: Not available
file_uploads: File uploads is turned off
post_max_size: 1000M
upload_max_filesize: 300M
max_effective_size: 300 MB
max_file_uploads: 20
gd_version: bundled (2.1.0 compatible)
gd_formats: GIF, JPEG, PNG, BMP
ghostscript_version: not available

### wp-server ###

server_architecture: Darwin 21.1.0 x86_64
httpd_software: nginx/1.16.0
php_version: 8.0.0 64bit
php_sapi: fpm-fcgi
max_input_variables: 4000
time_limit: 1200
memory_limit: 256M
max_input_time: 600
upload_max_filesize: 300M
php_post_max_size: 1000M
curl_version: 7.77.0 (SecureTransport) LibreSSL/2.8.3
suhosin: false
imagick_availability: false
pretty_permalinks: true
htaccess_extra_rules: false

### wp-database ###

extension: mysqli
server_version: 8.0.16
client_version: mysqlnd 8.0.0
max_allowed_packet: 16777216
max_connections: 151

### wp-constants ###

WP_HOME: undefined
WP_SITEURL: undefined
WP_CONTENT_DIR: /Users/tenup/Sites/oss/app/public/wp-content
WP_PLUGIN_DIR: /Users/tenup/Sites/oss/app/public/wp-content/plugins
WP_MEMORY_LIMIT: 40M
WP_MAX_MEMORY_LIMIT: 256M
WP_DEBUG: true
WP_DEBUG_DISPLAY: true
WP_DEBUG_LOG: true
SCRIPT_DEBUG: false
WP_CACHE: false
CONCATENATE_SCRIPTS: undefined
COMPRESS_SCRIPTS: undefined
COMPRESS_CSS: undefined
WP_ENVIRONMENT_TYPE: local
DB_CHARSET: utf8
DB_COLLATE: undefined

### wp-filesystem ###

wordpress: writable
wp-content: writable
uploads: writable
plugins: writable
themes: writable
mu-plugins: writable

### classifai ###

0: 1.6.0
1: no
2: undefined
3: 
	Configured: yes
	API URL: https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/instances/cbba6427-bd82-41af-989b-3c862fd23849
	API username: apikey
	Post types: post
	Features: {"category":1, "category_threshold":70, "category_taxonomy":"watson-category", "keyword":1, "keyword_threshold":70, "keyword_taxonomy":"watson-keyword", "entity":1, "entity_threshold":70, "entity_taxonomy":"watson-entity", "concept":1, "concept_threshold":70, "concept_taxonomy":"watson-concept"}
	Latest response: N/A
4: 
	Authenticated: no
	API URL: 
	Caption threshold: 75
	Latest response - Image Scan: N/A
	Latest response - Smart Cropping: N/A
	Latest response - OCR: N/A

dinhtungdu avatar Jan 18 '22 09:01 dinhtungdu

@dinhtungdu I've updated the MR to fix conflicts, but I am still not able to get this working in block editor, the tags get added to the post, which I can see in db but it doesn't show up in editor, here is the code for adding the tags, please note doing this process in browser console works, adds the tags and shows the tags

8744e96 (#268)

Also when the page is reloaded it results in an error, please note that the error occurs when saving post with normal update and is happening in on develop branch as well.

CleanShot 2022-02-04 at 02 15 34@2x

thrijith avatar Feb 03 '22 21:02 thrijith

Also when the page is reloaded it results in an error, please note that the error occurs when saving post with normal update and is happening in on develop branch as well.

Can you share with us the reproduce steps? I don't see the error you mentioned.

dinhtungdu avatar Feb 11 '22 06:02 dinhtungdu

Can you share with us the reproduce steps? I don't see the error you mentioned.

Sorry for the delay @dinhtungdu, here are the steps

  • Checkout todevelop pull and build
  • Create new post in block editor with sample content and make sure the tags and categories are created and filled up in Watson Categories, Watson Keywords etc
  • Publish the post and reload, here is a video of the same https://cln.sh/m2lao9

thrijith avatar Mar 09 '22 13:03 thrijith

@dinhtungdu are you able to replicate based on the steps from @thrijith above?

jeffpaul avatar Jun 13 '22 21:06 jeffpaul

@dinhtungdu are you able to replicate based on the steps from @thrijith above?

I can't. Tested again with the latest develop and WP 6.0, and I didn't see any error after reloading the page.

dinhtungdu avatar Jun 14 '22 10:06 dinhtungdu

@thrijith do you want to resolve the merge conflicts and re-assess what might still be needed here to bring this out of draft and ready for more formal review?

jeffpaul avatar Jun 14 '22 15:06 jeffpaul

Closing in favor of https://github.com/10up/classifai/pull/366

iamdharmesh avatar Sep 26 '22 06:09 iamdharmesh