Skip to content

Commit

Permalink
Merge branch 'develop' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
dkotter committed Jun 28, 2023
2 parents eb86a89 + 6d04ae1 commit 764b705
Show file tree
Hide file tree
Showing 23 changed files with 559 additions and 47 deletions.
1 change: 0 additions & 1 deletion .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
core:
- {name: 'WP latest', version: 'latest'}
- {name: 'WP minimum', version: 'WordPress/WordPress#5.7'}
- {name: 'WP trunk', version: 'WordPress/WordPress#master'}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
5 changes: 4 additions & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"plugins": [".", "./tests/test-plugin"],
"plugins": [".", "./tests/test-plugin", "https://downloads.wordpress.org/plugin/classic-editor.zip"],
"env": {
"tests": {
"mappings": {
"wp-cli.yml": "./tests/bin/wp-cli.yml"
}
}
},
"lifecycleScripts": {
"afterStart": "bash ./tests/bin/initialize.sh"
}
}
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file, per [the Ke

## [Unreleased] - TBD

## [2.2.2] - 2023-06-28
### Added
- Support for generating post titles in the Classic Editor using OpenAI's ChatGPT API (props [@Sidsector9](https://github.com/Sidsector9), [@dkotter](https://github.com/dkotter) via [#506](https://github.com/10up/classifai/pull/506)).
- New utility method to retrieve all post statuses (props [@Sidsector9](https://github.com/Sidsector9), [@dkotter](https://github.com/dkotter) via [#507](https://github.com/10up/classifai/pull/507)).

### Changed
- Optimized calls to the Microsoft Azure Text to Speech API (props [@joshuaabenazer](https://github.com/joshuaabenazer), [@ravinderk](https://github.com/ravinderk), [@dkotter](https://github.com/dkotter) via [#487](https://github.com/10up/classifai/pull/487)).
- When the Text to Speech option is toggled off, hide the Text to Speech audio button on the single post level (props [@joshuaabenazer](https://github.com/joshuaabenazer), [@ravinderk](https://github.com/ravinderk), [@dkotter](https://github.com/dkotter) via [#494](https://github.com/10up/classifai/pull/494)).

### Fixed
- Ensure any edits made to generated titles persist when that title is inserted (props [@dkotter](https://github.com/dkotter), [@Sidsector9](https://github.com/Sidsector9) via [#509](https://github.com/10up/classifai/pull/509)).
- Ensure we show all post statuses in our settings instead of just the core post ones (props [@Sidsector9](https://github.com/Sidsector9), [@dkotter](https://github.com/dkotter) via [#507](https://github.com/10up/classifai/pull/507)).

## [2.2.1] - 2023-06-08
### Added
- Ability to generate images in the Classic Editor (props [@dkotter](https://github.com/dkotter), [@ravinderk](https://github.com/ravinderk) via [#471](https://github.com/10up/classifai/pull/471)).
Expand Down Expand Up @@ -356,6 +369,7 @@ All notable changes to this project will be documented in this file, per [the Ke
- Initial closed source release

[Unreleased]: https://github.com/10up/classifai/compare/trunk...develop
[2.2.2]: https://github.com/10up/classifai/compare/2.2.1...2.2.2
[2.2.1]: https://github.com/10up/classifai/compare/2.2.0...2.2.1
[2.2.0]: https://github.com/10up/classifai/compare/2.1.0...2.2.0
[2.1.0]: https://github.com/10up/classifai/compare/2.0.0...2.1.0
Expand Down
2 changes: 1 addition & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The following individuals are responsible for curating the list of issues, respo

Thank you to all the people who have already contributed to this repository via bug reports, code, design, ideas, project management, translation, testing, etc.

[Darshan Sawardekar (@dsawardekar)](https://github.com/dsawardekar), [Ryan Welcher (@ryanwelcher)](https://github.com/ryanwelcher), [Adam Silverstein (@adamsilverstein)](https://github.com/adamsilverstein), [Jeffrey Paul (@jeffpaul)](https://github.com/jeffpaul), [Helen Hou-Sandí (@helen)](https://github.com/helen), [Christian Chung (@christianc1)](https://github.com/christianc1), [Dependabot (@dependabot)](https://github.com/dependabot), [Dillon McCallum (@McCallumDillon)](https://github.com/McCallumDillon), [Dustin Rue (@dustinrue)](https://github.com/dustinrue), [Jay Wood (@JayWood)](https://github.com/JayWood), [John Watkins (@johnwatkins0)](https://github.com/johnwatkins0), [Matthew McAchran (@mmcachran)](https://github.com/mmcachran), [Tung Du (@dinhtungdu)](https://github.com/dinhtungdu), [Darío Hereñú (@kant)](https://github.com/kant), [Aaron Jorbin (@aaronjorbin)](https://github.com/aaronjorbin), [Eduard Florea (@eflorea)](https://github.com/eflorea), [Jackie Kjome (@JackieKjome)](https://github.com/JackieKjome), [Ricky Lee Whittemore (@rickalee)](https://github.com/rickalee), [Ritesh Patel (@Ritesh-patel)](https://github.com/Ritesh-patel), [Dana Ross (@dana-ross)](https://github.com/dana-ross), [Darin Kotter (@dkotter)](https://github.com/dkotter), [Pete Nelson (@petenelson)](https://github.com/petenelson), [Connor Smyth (@ActuallyConnor)](https://github.com/ActuallyConnor), [Oscar Sanchez S. (@oscarssanchez)](https://github.com/oscarssanchez), [Shah Qureshi (@ShahAaron)](https://github.com/ShahAaron), [Barry Ceelen (@barryceelen)](https://github.com/barryceelen), [Jeffrey Carandang (@phpbits)](https://github.com/phpbits), [Thrijith Thankachan (@thrijith)](https://github.com/thrijith), [Junaid Bhura (@junaidbhura)](https://github.com/junaidbhura), [Blanca Hong [@blancahong]](https://profiles.wordpress.org/blancahong/), [Barney Jeffries (@barneyjeffries)](https://github.com/barneyjeffries), [Siddharth Thevaril (@Sidsector9)](https://github.com/Sidsector9), [@myBCN](https://github.com/myBCN), [James Morrison (@jamesmorrison)](https://github.com/jamesmorrison), [Rahul Prajapati (@rahulsprajapati)](https://github.com/rahulsprajapati), [Sérgio Santos (@s3rgiosan)](https://github.com/s3rgiosan), [Dharmesh Patel (@iamdharmesh)](https://github.com/iamdharmesh), [Delfina Hoxha](https://www.linkedin.com/in/delfina-hoxha/), [Ajay Maurya (@ajmaurya99)](https://github.com/ajmaurya99), [Faisal Alvi (@faisal-alvi)](https://github.com/faisal-alvi), [Mustafa Uysal (@mustafauysal)](https://github.com/mustafauysal), [Max Lyuchin (@cadic)](https://github.com/cadic), [Peter Wilson (@peterwilsoncc)](https://github.com/peterwilsoncc), [Quamruz Zaman (@zamanq)](https://github.com/zamanq), [Ravinder Kumar (@ravinderk)](https://github.com/ravinderk), [Joe McGill (@joemcgill)](https://github.com/joemcgill), [Tyler Bailey (@TylerB24890)](https://github.com/TylerB24890), [Viktor Szépe (@szepeviktor)](https://github.com/szepeviktor), [Ivan Ivanić (@Spoygg)](https://github.com/Spoygg), [Jayedul Kabir (@jayedul)](https://github.com/jayedul), [Garth Gutenberg (@ggutenberg)](https://github.com/ggutenberg), [Mehidi Hassan (@mehidi258)](https://github.com/mehidi258), [Julian Weiland (@derweili)](https://github.com/derweili), [Anton Vanyukov (@av3nger)](https://github.com/av3nger), [Ben Keith (@benlk)](https://github.com/benlk), [David Hechler (@pixeldevsio)](https://github.com/pixeldevsio).
[Darshan Sawardekar (@dsawardekar)](https://github.com/dsawardekar), [Ryan Welcher (@ryanwelcher)](https://github.com/ryanwelcher), [Adam Silverstein (@adamsilverstein)](https://github.com/adamsilverstein), [Jeffrey Paul (@jeffpaul)](https://github.com/jeffpaul), [Helen Hou-Sandí (@helen)](https://github.com/helen), [Christian Chung (@christianc1)](https://github.com/christianc1), [Dependabot (@dependabot)](https://github.com/dependabot), [Dillon McCallum (@McCallumDillon)](https://github.com/McCallumDillon), [Dustin Rue (@dustinrue)](https://github.com/dustinrue), [Jay Wood (@JayWood)](https://github.com/JayWood), [John Watkins (@johnwatkins0)](https://github.com/johnwatkins0), [Matthew McAchran (@mmcachran)](https://github.com/mmcachran), [Tung Du (@dinhtungdu)](https://github.com/dinhtungdu), [Darío Hereñú (@kant)](https://github.com/kant), [Aaron Jorbin (@aaronjorbin)](https://github.com/aaronjorbin), [Eduard Florea (@eflorea)](https://github.com/eflorea), [Jackie Kjome (@JackieKjome)](https://github.com/JackieKjome), [Ricky Lee Whittemore (@rickalee)](https://github.com/rickalee), [Ritesh Patel (@Ritesh-patel)](https://github.com/Ritesh-patel), [Dana Ross (@dana-ross)](https://github.com/dana-ross), [Darin Kotter (@dkotter)](https://github.com/dkotter), [Pete Nelson (@petenelson)](https://github.com/petenelson), [Connor Smyth (@ActuallyConnor)](https://github.com/ActuallyConnor), [Oscar Sanchez S. (@oscarssanchez)](https://github.com/oscarssanchez), [Shah Qureshi (@ShahAaron)](https://github.com/ShahAaron), [Barry Ceelen (@barryceelen)](https://github.com/barryceelen), [Jeffrey Carandang (@phpbits)](https://github.com/phpbits), [Thrijith Thankachan (@thrijith)](https://github.com/thrijith), [Junaid Bhura (@junaidbhura)](https://github.com/junaidbhura), [Blanca Hong [@blancahong]](https://profiles.wordpress.org/blancahong/), [Barney Jeffries (@barneyjeffries)](https://github.com/barneyjeffries), [Siddharth Thevaril (@Sidsector9)](https://github.com/Sidsector9), [@myBCN](https://github.com/myBCN), [James Morrison (@jamesmorrison)](https://github.com/jamesmorrison), [Rahul Prajapati (@rahulsprajapati)](https://github.com/rahulsprajapati), [Sérgio Santos (@s3rgiosan)](https://github.com/s3rgiosan), [Dharmesh Patel (@iamdharmesh)](https://github.com/iamdharmesh), [Delfina Hoxha](https://www.linkedin.com/in/delfina-hoxha/), [Ajay Maurya (@ajmaurya99)](https://github.com/ajmaurya99), [Faisal Alvi (@faisal-alvi)](https://github.com/faisal-alvi), [Mustafa Uysal (@mustafauysal)](https://github.com/mustafauysal), [Max Lyuchin (@cadic)](https://github.com/cadic), [Peter Wilson (@peterwilsoncc)](https://github.com/peterwilsoncc), [Quamruz Zaman (@zamanq)](https://github.com/zamanq), [Ravinder Kumar (@ravinderk)](https://github.com/ravinderk), [Joe McGill (@joemcgill)](https://github.com/joemcgill), [Tyler Bailey (@TylerB24890)](https://github.com/TylerB24890), [Viktor Szépe (@szepeviktor)](https://github.com/szepeviktor), [Ivan Ivanić (@Spoygg)](https://github.com/Spoygg), [Jayedul Kabir (@jayedul)](https://github.com/jayedul), [Garth Gutenberg (@ggutenberg)](https://github.com/ggutenberg), [Mehidi Hassan (@mehidi258)](https://github.com/mehidi258), [Julian Weiland (@derweili)](https://github.com/derweili), [Anton Vanyukov (@av3nger)](https://github.com/av3nger), [Ben Keith (@benlk)](https://github.com/benlk), [David Hechler (@pixeldevsio)](https://github.com/pixeldevsio), [Joshua Abenazer (@joshuaabenazer)](https://github.com/joshuaabenazer).

## Libraries

Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* [Set Up OpenAI ChatGPT Language Processing](#set-up-language-processing-via-openai-chatgpt)
* [Set Up OpenAI Embeddings Language Processing](#set-up-language-processing-via-openai-embeddings)
* [Set Up OpenAI Whisper Language Processing](#set-up-language-processing-via-openai-whisper)
* [Set Up Azure AI Language Processing](#set-up-language-processing-via-microsoft-azure)
* [Set Up Azure AI Computer Vision Image Processing](#set-up-image-processing-via-microsoft-azure)
* [Set Up OpenAI DALL·E Image Processing](#set-up-image-processing-via-openai)
* [Set Up Azure Personalizer Recommended Content](#set-up-recommended-content-via-microsoft-azure-personalizer)
Expand Down Expand Up @@ -226,7 +227,7 @@ IBM Watson's [Categories](https://cloud.ibm.com/docs/natural-language-understand
* To test excerpt generation, edit (or create) an item that supports excerpts. Note: only the block editor is supported.
* Ensure this item has content saved.
* Open the Excerpt panel in the sidebar and click on `Generate Excerpt`.
* To test title generation, edit (or create) an item that supports titles. Note: only the block editor is supported.
* To test title generation, edit (or create) an item that supports titles.
* Ensure this item has content saved.
* Open the Summary panel in the sidebar and click on `Generate titles`.

Expand Down Expand Up @@ -288,14 +289,14 @@ Note that [OpenAI](https://platform.openai.com/docs/guides/speech-to-text) can c
### 1. Sign up for Azure services

* [Register for a Microsoft Azure account](https://azure.microsoft.com/en-us/free/) or sign into your existing one.
* Log into your account and create a new [*Speech Service*](https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/overview) Service if you do not already have one. It may take a minute for your account to fully populate with the default resource group to use.
* Click `Keys and Endpoint` in the left hand Resource Management menu to view the `Endpoint` URL for this resource.
* Log into your account and create a new [*Speech Service*](https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/overview) if you do not already have one. It may take a minute for your account to fully populate with the default resource group to use.
* Click `Keys and Endpoint` in the left hand Resource Management menu to view the `Location/Region` for this resource.
* Click the copy icon next to `KEY 1` to copy the API Key credential for this resource.

### 2. Configure Microsoft Azure API and Key under Tools > ClassifAI > Language Processing > Microsoft Azure

* In the `Endpoint URL` field, enter your `API endpoint`.
* In the `API Key` field, enter your `KEY 1`.
* In the `Endpoint URL` field, enter the following URL, replacing `LOCATION` with the `Location/Region` you found above: `https://LOCATION.tts.speech.microsoft.com/`.
* In the `API Key` field, enter your `KEY 1` copied from above.
* Click **Save Changes** (the page will reload).
* If connected successfully, a new dropdown with the label "Voices" will be displayed.
* Select a voice as per your choice.
Expand Down
2 changes: 1 addition & 1 deletion classifai.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://github.com/10up/classifai
* Update URI: https://classifaiplugin.com
* Description: Enhance your WordPress content with Artificial Intelligence and Machine Learning services.
* Version: 2.2.1
* Version: 2.2.2
* Requires at least: 5.7
* Requires PHP: 7.4
* Author: 10up
Expand Down
2 changes: 1 addition & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* declared here instead of a Class.
*/

$plugin_version = '2.2.1';
$plugin_version = '2.2.2';

if ( file_exists( __DIR__ . '/.commit' ) ) {
$plugin_version .= '-' . file_get_contents( __DIR__ . '/.commit' );
Expand Down
28 changes: 21 additions & 7 deletions includes/Classifai/Admin/SavePostHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,24 @@ public function synthesize_speech( $post_id ) {
);
}

$normalizer = new Normalizer();
$settings = \Classifai\get_plugin_settings( 'language_processing', TextToSpeech::FEATURE_NAME );
$post = get_post( $post_id );
$post_content = $normalizer->normalize_content( $post->post_content, $post->post_title, $post_id );
$normalizer = new Normalizer();
$settings = \Classifai\get_plugin_settings( 'language_processing', TextToSpeech::FEATURE_NAME );
$post = get_post( $post_id );
$post_content = $normalizer->normalize_content( $post->post_content, $post->post_title, $post_id );
$content_hash = get_post_meta( $post_id, TextToSpeech::AUDIO_HASH_KEY, true );
$saved_attachment_id = (int) get_post_meta( $post_id, TextToSpeech::AUDIO_ID_KEY, true );

// Don't regenerate the audio file it it already exists and the content hasn't changed.
if ( $saved_attachment_id ) {

// Check if the audio file exists.
$audio_attachment_url = wp_get_attachment_url( $saved_attachment_id );

if ( $audio_attachment_url && ! empty( $content_hash ) && ( md5( $post_content ) === $content_hash ) ) {
return $saved_attachment_id;
}
}

$voice = $settings['voice'] ?? '';
$voice_data = explode( '|', $voice );
$voice_name = '';
Expand Down Expand Up @@ -255,8 +269,6 @@ public function synthesize_speech( $post_id ) {
);
}

$saved_attachment_id = (int) get_post_meta( $post_id, TextToSpeech::AUDIO_ID_KEY, true );

// If audio already exists for this post, delete it.
if ( $saved_attachment_id ) {
wp_delete_attachment( $saved_attachment_id, true );
Expand Down Expand Up @@ -291,7 +303,8 @@ public function synthesize_speech( $post_id ) {
'post_title' => $audio_file_name,
'post_mime_type' => $file_data['type'],
),
$file_data['file']
$file_data['file'],
$post_id
);

// Return error if creation of attachment fails.
Expand All @@ -304,6 +317,7 @@ public function synthesize_speech( $post_id ) {

update_post_meta( $post_id, TextToSpeech::AUDIO_ID_KEY, absint( $attachment_id ) );
update_post_meta( $post_id, TextToSpeech::AUDIO_TIMESTAMP_KEY, time() );
update_post_meta( $post_id, TextToSpeech::AUDIO_HASH_KEY, md5( $post_content ) );

return $attachment_id;
}
Expand Down
58 changes: 57 additions & 1 deletion includes/Classifai/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function get_post_types_for_language_settings() {
* @return array
*/
function get_post_statuses_for_language_settings() {
$post_statuses = get_post_statuses();
$post_statuses = get_all_post_statuses();

/**
* Filter post statuses shown in language processing settings.
Expand Down Expand Up @@ -693,3 +693,59 @@ function find_provider_class( array $provider_classes = [], string $service_name

return $provider;
}

/**
* Get core and custom post statuses.
*
* @return array
*/
function get_all_post_statuses() {
$all_statuses = wp_list_pluck(
get_post_stati(
[],
'objects'
),
'label'
);

/*
* We unset the following because we want to limit the post
* statuses to the ones returned by `get_post_statuses()` and
* any custom post statuses registered using `register_post_status()`
*/
unset(
$all_statuses['future'],
$all_statuses['trash'],
$all_statuses['auto-draft'],
$all_statuses['inherit'],
$all_statuses['request-pending'],
$all_statuses['request-confirmed'],
$all_statuses['request-failed'],
$all_statuses['request-completed']
);

/*
* There is a minor difference in the label for 'pending' status between
* `get_post_statuses()` and `get_post_stati()`.
*
* `get_post_stati()` has the label as `Pending` whereas
* `get_post_statuses()` has the label as `Pending Review`.
*
* So we normalise it here.
*/
if ( isset( $all_statuses['pending'] ) ) {
$all_statuses['pending'] = esc_html__( 'Pending Review', 'classifai' );
}

/**
* Hook to filter post statuses.
*
* @since 2.2.2
* @hook classifai_all_post_statuses
*
* @param {array} $all_statuses Array of post statuses.
*
* @return {array} Array of post statuses.
*/
return apply_filters( 'classifai_all_post_statuses', $all_statuses );
}
Loading

0 comments on commit 764b705

Please sign in to comment.