Skip to content

Commit

Permalink
Release: (0f6b46e) Merge branch 'develop' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
dkotter committed Jan 11, 2024
1 parent 97ec178 commit dc720e3
Show file tree
Hide file tree
Showing 51 changed files with 293 additions and 300 deletions.
12 changes: 6 additions & 6 deletions autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ public function add_namespace( $prefix, $base_dir, $prepend = false ) {
/**
* Loads the class file for a given class name.
*
* @param string $class The fully-qualified class name.
* @param string $classname The fully-qualified class name.
* @return mixed The mapped file name on success, or boolean false on
* failure.
*/
public function load_class( $class ) {
public function load_class( $classname ) {
// the current namespace prefix
$prefix = $class;
$prefix = $classname;

// work backwards through the namespace names of the fully-qualified
// class name to find a mapped file name
while ( false !== $pos = strrpos( $prefix, '\\' ) ) { // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
while ( false !== $pos = strrpos( $prefix, '\\' ) ) { // phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition, WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition

// retain the trailing namespace separator in the prefix
$prefix = substr( $class, 0, $pos + 1 );
$prefix = substr( $classname, 0, $pos + 1 );

// the rest is the relative class name
$relative_class = substr( $class, $pos + 1 );
$relative_class = substr( $classname, $pos + 1 );

// try to load a mapped file for the prefix and relative class
$mapped_file = $this->load_mapped_file( $prefix, $relative_class );
Expand Down
4 changes: 2 additions & 2 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.5.0
* Version: 2.5.1
* Requires at least: 6.1
* Requires PHP: 7.4
* Author: 10up
Expand Down Expand Up @@ -37,7 +37,7 @@ function classifai_site_meets_php_requirements() {
if ( ! classifai_site_meets_php_requirements() ) {
add_action(
'admin_notices',
function() {
function () {
?>
<div class="notice notice-error">
<p>
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.5.0';
$plugin_version = '2.5.1';

if ( file_exists( __DIR__ . '/.commit' ) ) {
$plugin_version .= '-' . file_get_contents( __DIR__ . '/.commit' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
Expand Down
58 changes: 46 additions & 12 deletions includes/Classifai/Admin/BulkActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Classifai\Providers\OpenAI\Embeddings;
use Classifai\Providers\OpenAI\Whisper;
use Classifai\Providers\OpenAI\Whisper\Transcribe;
use Classifai\Providers\Watson\NLU;

use function Classifai\get_post_types_for_language_settings;
use function Classifai\get_supported_post_types;
use function Classifai\get_tts_supported_post_types;
Expand Down Expand Up @@ -55,6 +57,11 @@ public function can_register() {
*/
private $text_to_speech;

/**
* @var \Classifai\Providers\Watson\NLU
*/
private $ibm_watson_nlu;

/**
* Register the actions needed.
*/
Expand All @@ -72,12 +79,33 @@ public function register_language_processing_hooks() {
$this->chat_gpt = new ChatGPT( false );
$this->embeddings = new Embeddings( false );
$this->text_to_speech = new TextToSpeech( false );
$this->ibm_watson_nlu = new NLU( false );

$embeddings_post_types = [];
$nlu_post_types = get_supported_post_types();
$text_to_speech_post_types = get_tts_supported_post_types();
$nlu_post_types = [];
$text_to_speech_post_types = [];
$chat_gpt_post_types = [];

// Set up the NLU post types if the feature is enabled. Otherwise clear.
if (
$this->ibm_watson_nlu &&
$this->ibm_watson_nlu->is_feature_enabled( 'content_classification' )
) {
$nlu_post_types = get_supported_post_types();
} else {
$this->ibm_watson_nlu = null;
}

// Set up the NLU post types if the feature is enabled. Otherwise clear.
if (
$this->text_to_speech &&
$this->text_to_speech->is_feature_enabled( 'content_classification' )
) {
$text_to_speech_post_types = get_tts_supported_post_types();
} else {
$this->text_to_speech = null;
}

// Set up the save post handler if we have any post types.
if ( ! empty( $nlu_post_types ) || ! empty( $text_to_speech_post_types ) ) {
$this->save_post_handler = new SavePostHandler();
Expand All @@ -100,11 +128,6 @@ public function register_language_processing_hooks() {
$this->embeddings = 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( $chat_gpt_post_types, $embeddings_post_types, $nlu_post_types, $text_to_speech_post_types ) );

Expand Down Expand Up @@ -147,15 +170,24 @@ public function register_bulk_actions( $bulk_actions ) {
$nlu_post_types = get_supported_post_types();

if (
! empty( $nlu_post_types ) ||
( is_a( $this->embeddings, '\Classifai\Providers\OpenAI\Embeddings' ) && ! empty( $this->embeddings->supported_post_types() ) )
(
is_a( $this->ibm_watson_nlu, '\Classifai\Providers\Watson\NLU' ) &&
$this->ibm_watson_nlu->is_feature_enabled( 'content_classification' ) &&
! empty( $nlu_post_types )
) ||
(
is_a( $this->embeddings, '\Classifai\Providers\OpenAI\Embeddings' ) &&
$this->embeddings->is_feature_enabled( 'classification' ) &&
! empty( $this->embeddings->supported_post_types() )
)
) {
$bulk_actions['classify'] = __( 'Classify', 'classifai' );
}

if (
is_a( $this->chat_gpt, '\Classifai\Providers\OpenAI\ChatGPT' ) &&
in_array( get_current_screen()->post_type, array_keys( get_post_types_for_language_settings() ), true )
in_array( get_current_screen()->post_type, array_keys( get_post_types_for_language_settings() ), true ) &&
$this->chat_gpt->is_feature_enabled( 'excerpt_generation' )
) {
$bulk_actions['generate_excerpt'] = __( 'Generate excerpt', 'classifai' );
}
Expand Down Expand Up @@ -221,7 +253,10 @@ public function bulk_action_handler( $redirect_to, $doaction, $post_ids ) {
foreach ( $post_ids as $post_id ) {
if ( 'classify' === $doaction ) {
// Handle NLU classification.
if ( is_a( $this->save_post_handler, '\Classifai\Admin\SavePostHandler' ) ) {
if (
is_a( $this->ibm_watson_nlu, '\Classifai\Providers\Watson\NLU' ) &&
is_a( $this->save_post_handler, '\Classifai\Admin\SavePostHandler' )
) {
$action = 'classified';
$this->save_post_handler->classify( $post_id );
}
Expand Down Expand Up @@ -454,5 +489,4 @@ public function register_media_row_action( $actions, $post ) {

return $actions;
}

}
2 changes: 1 addition & 1 deletion includes/Classifai/Admin/DebugInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function add_classifai_debug_information( $information ) {
$fields = [];
}

$validate_field = function( $field ) {
$validate_field = function ( $field ) {
if ( ! is_array( $field ) ) {
return false;
}
Expand Down
11 changes: 5 additions & 6 deletions includes/Classifai/Admin/Onboarding.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,14 @@ public function handle_step_submission() {
* Sanitize variables using sanitize_text_field and wp_unslash. Arrays are cleaned recursively.
* Non-scalar values are ignored.
*
* @param string|array $var Data to sanitize.
* @param string|array $data Data to sanitize.
* @return string|array
*/
public function classifai_sanitize( $var ) {
if ( is_array( $var ) ) {
return array_map( array( $this, 'classifai_sanitize' ), $var );
public function classifai_sanitize( $data ) {
if ( is_array( $data ) ) {
return array_map( array( $this, 'classifai_sanitize' ), $data );
} else {
return is_scalar( $var ) ? sanitize_text_field( wp_unslash( $var ) ) : $var;
return is_scalar( $data ) ? sanitize_text_field( wp_unslash( $data ) ) : $data;
}
}

Expand Down Expand Up @@ -663,5 +663,4 @@ public function get_configured_features() {

return $configured_features;
}

}
5 changes: 2 additions & 3 deletions includes/Classifai/Admin/PreviewClassifierData.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function filter_classify_preview_data( $classified_data ) {
if ( 'categories' === $feature ) {
$classified_data[ $feature ] = array_filter(
$classified_data[ $feature ],
function( $item ) use ( $taxonomy ) {
function ( $item ) use ( $taxonomy ) {
$keep = false;
$parts = explode( '/', $item['label'] );
$parts = array_filter( $parts );
Expand All @@ -128,7 +128,7 @@ function( $item ) use ( $taxonomy ) {

$classified_data[ $feature ] = array_filter(
$classified_data[ $feature ],
function( $item ) use ( $taxonomy, $key ) {
function ( $item ) use ( $taxonomy, $key ) {
$name = $item['text'];
if ( 'keyword' === $key ) {
$name = preg_replace( '#^[a-z]+ ([A-Z].*)$#', '$1', $name );
Expand All @@ -148,4 +148,3 @@ function( $item ) use ( $taxonomy, $key ) {
return $classified_data;
}
}

4 changes: 2 additions & 2 deletions includes/Classifai/Admin/SavePostHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Classifai\Admin;

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

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/Classifai/Admin/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function init() {
);

$this->updater->addResultFilter(
function( $plugin_info, $http_response = null ) {
function ( $plugin_info ) {
$plugin_info->icons = array(
'svg' => CLASSIFAI_PLUGIN_URL . 'assets/img/icon.svg',
);
Expand Down
5 changes: 5 additions & 0 deletions includes/Classifai/Admin/UserProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ public function get_allowed_features( $user_id ) {
continue;
}
foreach ( $provider_features as $feature => $feature_name ) {
// Check if feature is enabled.
if ( ! $provider_class->is_enabled( $feature ) ) {
continue;
}

$access_control = new AccessControl( $provider_class, $feature );

// Check if feature has user based opt-out enabled.
Expand Down
4 changes: 2 additions & 2 deletions includes/Classifai/Blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* @return void
*/
function setup() {
$n = function( $function ) {
return __NAMESPACE__ . "\\$function";
$n = function ( $function_name ) {
return __NAMESPACE__ . "\\$function_name";
};

add_action( 'enqueue_block_assets', $n( 'blocks_styles' ) );
Expand Down
12 changes: 5 additions & 7 deletions includes/Classifai/Blocks/recommended-content-block/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

namespace Classifai\Blocks\RecommendedContentBlock;

use function Classifai\get_asset_info;
use Classifai\Providers\Azure\Personalizer;
use function Classifai\get_asset_info;

/**
* Register the block
*/
function register() {
$n = function( $function ) {
return __NAMESPACE__ . "\\$function";
$n = function ( $function_name ) {
return __NAMESPACE__ . "\\$function_name";
};

$personalizer = new Personalizer( false );
Expand Down Expand Up @@ -48,13 +48,11 @@ function register() {
/**
* Render callback method for the block
*
* @param array $attributes The blocks attributes.
* @param string $content Data returned from InnerBlocks.Content.
* @param array $block Block information such as context.
* @param array $attributes The blocks attributes.
*
* @return string The rendered block markup.
*/
function render_block_callback( $attributes, $content, $block ) {
function render_block_callback( $attributes ) {
// Render block in Gutenberg Editor.
if ( defined( 'REST_REQUEST' ) && \REST_REQUEST ) {
$personalizer = new Personalizer( false );
Expand Down
Loading

0 comments on commit dc720e3

Please sign in to comment.