Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/moderation
Browse files Browse the repository at this point in the history
  • Loading branch information
kirtangajjar committed Aug 8, 2023
2 parents 12e5dd3 + 61e98ad commit d09406a
Show file tree
Hide file tree
Showing 31 changed files with 972 additions and 479 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.nvmrc export-ignore
.wordpress-version-checker.json export-ignore
.wp-env.json export-ignore
CHANGELOG.md export-ignore
classifai.zip export-ignore
Expand Down
27 changes: 4 additions & 23 deletions .github/workflows/build-release-zip.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Build release zip

on:
workflow_dispatch:
release:
types: [published]

Expand All @@ -14,34 +13,16 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: Set Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x

- name: npm install and build
- name: Create ZIP
run: |
npm install
npm run build
npm run makepot
composer install --no-dev
npm run archive
- name: Upload the ZIP file as an artifact
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.repository.name }}
path: release
retention-days: 5
git archive --prefix=classifai/ HEAD -o classifai.zip
- name: Upload release asset
if: ${{ github.event_name == 'release' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{github.workspace}}/${{ github.event.repository.name }}.zip
asset_name: ${{ github.event.repository.name }}.zip
asset_path: ${{github.workspace}}/classifai.zip
asset_name: classifai.zip
asset_content_type: application/zip
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ on:
schedule:
- cron: '0 0 * * 1'

permissions:
issues: write

jobs:
wordpress-version-checker:
runs-on: ubuntu-latest
steps:
- name: WordPress version checker
uses: skaut/wordpress-version-checker@v1.2.0
uses: skaut/wordpress-version-checker@master
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .wordpress-version-checker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"readme": "readme.txt",
"channel": "rc"
}
59 changes: 38 additions & 21 deletions 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.3
* Version: 2.3.0-dev
* Requires at least: 5.7
* Requires PHP: 7.4
* Author: 10up
Expand All @@ -16,30 +16,47 @@
*/

/**
* Require PHP version 7.4+ - throw an error if the plugin is activated on an older version.
* Get the minimum version of PHP required by this plugin.
*
* Note that this itself is only PHP5.3+ compatible because of the anonymous callback.
* @return string Minimum version required.
*/
register_activation_hook(
__FILE__,
function() {
if ( version_compare( PHP_VERSION, '7.4.0', '<' ) ) {
wp_die(
sprintf(
wp_kses(
/* translators: PHP Update guide URL */
__( 'ClassifAI requires PHP version 7.4. <a href="%s">Click here</a> to learn how to update your PHP version.', 'classifai' ),
array(
'a' => array( 'href' => array() ),
function classifai_minimum_php_requirement() {
return '7.4';
}

/**
* Whether PHP installation meets the minimum requirements
*
* @return bool True if meets minimum requirements, false otherwise.
*/
function classifai_site_meets_php_requirements() {
return version_compare( phpversion(), classifai_minimum_php_requirement(), '>=' );
}

// Ensuring our PHP version requirement is met first before loading plugin.
if ( ! classifai_site_meets_php_requirements() ) {
add_action(
'admin_notices',
function() {
?>
<div class="notice notice-error">
<p>
<?php
echo wp_kses_post(
sprintf(
/* translators: %s: Minimum required PHP version */
__( 'ClassifAI requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'classifai' ),
esc_html( classifai_minimum_php_requirement() )
)
),
esc_url( 'https://wordpress.org/support/update-php/' )
),
esc_html__( 'Error Activating', 'classifai' )
);
);
?>
</p>
</div>
<?php
}
}
);
);
return;
}

/**
* Small wrapper around PHP's define function. The defined constant is
Expand Down
5 changes: 3 additions & 2 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ classifai_define( 'CLASSIFAI_PLUGIN_VERSION', $plugin_version );
classifai_define( 'CLASSIFAI_PLUGIN_DIR', __DIR__ );
classifai_define( 'CLASSIFAI_PLUGIN_URL', plugin_dir_url( __FILE__ ) );

// API
classifai_define( 'WATSON_NLU_VERSION', '2018-03-19' );
// API - https://cloud.ibm.com/docs/natural-language-understanding?topic=natural-language-understanding-release-notes#active-version-dates
classifai_define( 'WATSON_NLU_VERSION', '2022-08-10' );

// Taxonomies
classifai_define( 'WATSON_CATEGORY_TAXONOMY', 'watson-category' );
classifai_define( 'WATSON_KEYWORD_TAXONOMY', 'watson-keyword' );
Expand Down
9 changes: 2 additions & 7 deletions includes/Classifai/Admin/BulkActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Classifai\Providers\OpenAI\Whisper\Transcribe;
use function Classifai\get_post_types_for_language_settings;
use function Classifai\get_supported_post_types;
use function Classifai\get_tts_supported_post_types;

/**
* Handle bulk actions.
Expand Down Expand Up @@ -77,13 +78,12 @@ public function register_language_processing_hooks() {
$this->chat_gpt = new ChatGPT( false );
$this->moderation = new Moderation( false );
$this->embeddings = new Embeddings( false );
$this->text_to_speech = new TextToSpeech( false );

$user_roles = wp_get_current_user()->roles ?? [];
$embedding_settings = $this->embeddings->get_settings();
$embeddings_post_types = [];
$nlu_post_types = get_supported_post_types();
$text_to_speech_post_types = $this->text_to_speech->get_supported_post_types();
$text_to_speech_post_types = get_tts_supported_post_types();
$chat_gpt_post_types = [];
$chat_gpt_settings = $this->chat_gpt->get_settings();
$moderation_post_types = [];
Expand Down Expand Up @@ -120,11 +120,6 @@ public function register_language_processing_hooks() {
$this->moderation = null;
}

// Clear our TextToSpeech handler if no post types are set up.
if ( empty( $text_to_speech_post_types ) ) {
$this->text_to_speech = null;
}

// Merge our post types together and make them unique.
$post_types = array_unique(
array_merge(
Expand Down
23 changes: 23 additions & 0 deletions includes/Classifai/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Classifai;

use Classifai\Providers\Provider;
use Classifai\Providers\Azure;
use Classifai\Services\Service;
use Classifai\Services\ServicesManager;
use WP_Error;
Expand Down Expand Up @@ -275,6 +276,28 @@ function get_supported_post_types() {
return $post_types;
}

/**
* The list of post types that TTS supports.
*
* @return array Supported Post Types.
*/
function get_tts_supported_post_types() {
$classifai_settings = get_plugin_settings( 'language_processing', Azure\TextToSpeech::FEATURE_NAME );

if ( empty( $classifai_settings ) ) {
$post_types = [];
} else {
$post_types = [];
foreach ( $classifai_settings['post_types'] as $post_type => $enabled ) {
if ( ! empty( $enabled ) ) {
$post_types[] = $post_type;
}
}
}

return $post_types;
}

/**
* The list of post statuses that get the ClassifAI taxonomies. Defaults
* to 'publish'.
Expand Down
10 changes: 10 additions & 0 deletions includes/Classifai/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ public function enqueue_admin_assets() {
'ajax_nonce' => wp_create_nonce( 'classifai' ),
]
);

if ( wp_script_is( 'wp-commands', 'registered' ) ) {
wp_enqueue_script(
'classifai-commands',
CLASSIFAI_PLUGIN_URL . 'dist/commands.js',
get_asset_info( 'commands', 'dependencies' ),
get_asset_info( 'commands', 'version' ),
true
);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/Classifai/Providers/Azure/ComputerVision.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function reset_settings() {
*
* @return array
*/
private function get_default_settings() {
public function get_default_settings() {
return [
'valid' => false,
'url' => '',
Expand Down
2 changes: 1 addition & 1 deletion includes/Classifai/Providers/Azure/Personalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function reset_settings() {
*
* @return array
*/
private function get_default_settings() {
public function get_default_settings() {
return [
'authenticated' => false,
'url' => '',
Expand Down
Loading

0 comments on commit d09406a

Please sign in to comment.