Skip to content

Commit

Permalink
Release: (bfb3822) Merge branch 'develop' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
dkotter committed Nov 9, 2023
1 parent cd59199 commit 2a0d9d7
Show file tree
Hide file tree
Showing 30 changed files with 933 additions and 329 deletions.
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.3.0
* Version: 2.4.0
* Requires at least: 5.8
* Requires PHP: 7.4
* Author: 10up
Expand Down Expand Up @@ -87,7 +87,7 @@ classifai_define( 'CLASSIFAI_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
/**
* Loads the CLASSIFAI PHP autoloader if possible.
*
* @return bool True or false if autoloading was successfull.
* @return bool True or false if autoloading was successful.
*/
function classifai_autoload() {
if ( classifai_can_autoload() ) {
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.3.0';
$plugin_version = '2.4.0';

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
2 changes: 1 addition & 1 deletion dist/admin.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => 'b88da674f852dcc57e0e');
<?php return array('dependencies' => array('wp-i18n'), 'version' => 'c640880b75ab1a186669');
2 changes: 1 addition & 1 deletion dist/admin.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion includes/Classifai/Admin/SavePostHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function is_configured() {
*
* Skips classification if running under the Gutenberg Metabox
* compatibility request. The classification is performed during the REST
* lifecyle when using Gutenberg.
* lifecycle when using Gutenberg.
*
* @param int $post_id The post that was saved
*/
Expand Down
2 changes: 1 addition & 1 deletion includes/Classifai/Blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function blocks_styles() {
'recommended-content-block-style',
CLASSIFAI_PLUGIN_URL . 'dist/recommended-content-block-frontend.css',
[],
CLASSIFAI_PLUGIN_VERSION
get_asset_info( 'recommended-content-block-frontend', 'version' )
);

wp_enqueue_script(
Expand Down
4 changes: 2 additions & 2 deletions includes/Classifai/Command/ClassifaiCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ private function should_transcribe_attachment( $attachment, int $attachment_id,
* ## Options
*
* [<attachment_ids>]
* : Comma delimeted Attachment IDs to classify
* : Comma delimited Attachment IDs to classify
*
* [--limit=<limit>]
* : Limit classification to N attachments. Default 100.
Expand Down Expand Up @@ -1219,7 +1219,7 @@ private function get_attachment_to_classify( $opts = [] ) {
/**
* Prints the output from the NLU API.
*
* @param mixed $output The variable to oputput.
* @param mixed $output The variable to output.
* @param int $post_id The post id.
*/
private function print( $output, $post_id ) {
Expand Down
8 changes: 5 additions & 3 deletions includes/Classifai/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,24 @@ public function add_privacy_policy_content() {

/**
* Enqueue the admin scripts.
*
* @since 2.4.0 Use get_asset_info to get the asset version and dependencies.
*/
public function enqueue_admin_assets() {

wp_enqueue_style(
'classifai-admin-style',
CLASSIFAI_PLUGIN_URL . 'dist/admin.css',
array(),
CLASSIFAI_PLUGIN_VERSION,
get_asset_info( 'admin', 'version' ),
'all'
);

wp_enqueue_script(
'classifai-admin-script',
CLASSIFAI_PLUGIN_URL . 'dist/admin.js',
[],
CLASSIFAI_PLUGIN_VERSION,
get_asset_info( 'admin', 'dependencies' ),
get_asset_info( 'admin', '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 @@ -1193,7 +1193,7 @@ public function sanitize_settings( $settings ) {
}

/**
* Authenitcates our credentials.
* Authenticates our credentials.
*
* @param string $url Endpoint URL.
* @param string $api_key Api Key.
Expand Down
4 changes: 2 additions & 2 deletions includes/Classifai/Providers/Azure/Read.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function read_document() {
* Filters the request arguments sent to Read endpoint.
*
* @since 1.7.0
* @hook classifai_azure_read_should_process
* @hook classifai_azure_read_request_args
*
* @param {array} $args Whether to run OCR processing or not.
* @param {int} $attachment_id The attachment ID.
Expand Down Expand Up @@ -277,7 +277,7 @@ public function check_read_result( $operation_url ) {
}

/**
* Update document desctiption using text received from Read API.
* Update document description using text received from Read API.
*
* @param array $data Read result.
*
Expand Down
8 changes: 5 additions & 3 deletions includes/Classifai/Providers/Azure/TextToSpeech.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public function __construct( $service ) {

/**
* Enqueue the editor scripts.
*
* @since 2.4.0 Use get_asset_info to get the asset version and dependencies.
*/
public function enqueue_editor_assets() {
$post = get_post();
Expand All @@ -102,8 +104,8 @@ public function enqueue_editor_assets() {
wp_enqueue_script(
'classifai-gutenberg-plugin',
CLASSIFAI_PLUGIN_URL . 'dist/gutenberg-plugin.js',
array( 'lodash', 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor', 'wp-edit-post', 'wp-components', 'wp-data', 'wp-plugins' ),
CLASSIFAI_PLUGIN_VERSION,
array_merge( get_asset_info( 'gutenberg-plugin', 'dependencies' ), array( 'lodash' ) ),
get_asset_info( 'gutenberg-plugin', 'version' ),
true
);

Expand Down Expand Up @@ -719,7 +721,7 @@ public function save_post_metadata( $post_id ) {
}

/**
* Adds audio controls to the post that has speech sythesis enabled.
* Adds audio controls to the post that has speech synthesis enabled.
*
* @param string $content Post content.
* @return string
Expand Down
174 changes: 164 additions & 10 deletions includes/Classifai/Providers/OpenAI/APIRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,22 @@ class APIRequest {
*/
public $api_key;

/**
* The feature name.
*
* @var string
*/
public $feature;

/**
* OpenAI APIRequest constructor.
*
* @param string $api_key OpenAI API key.
* @param string $feature Feature name.
*/
public function __construct( string $api_key = '' ) {
public function __construct( string $api_key = '', string $feature = '' ) {
$this->api_key = $api_key;
$this->feature = $feature;
}

/**
Expand All @@ -42,8 +51,55 @@ public function __construct( string $api_key = '' ) {
* @return array|WP_Error
*/
public function get( string $url, array $options = [] ) {
/**
* Filter the URL for the get request.
*
* @since 2.4.0
* @hook classifai_openai_api_request_get_url
*
* @param {string} $url The URL for the request.
* @param {array} $options The options for the request.
* @param {string} $this->feature The feature name.
*
* @return {string} The URL for the request.
*/
$url = apply_filters( 'classifai_openai_api_request_get_url', $url, $options, $this->feature );

/**
* Filter the options for the get request.
*
* @since 2.4.0
* @hook classifai_openai_api_request_get_options
*
* @param {array} $options The options for the request.
* @param {string} $url The URL for the request.
* @param {string} $this->feature The feature name.
*
* @return {array} The options for the request.
*/
$options = apply_filters( 'classifai_openai_api_request_get_options', $options, $url, $this->feature );

$this->add_headers( $options );
return $this->get_result( wp_remote_get( $url, $options ) ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get

/**
* Filter the response from OpenAI for a get request.
*
* @since 2.4.0
* @hook classifai_openai_api_response_get
*
* @param {string} $url Request URL.
* @param {array} $options Request body options.
* @param {string} $this->feature Feature name.
*
* @return {array} API response.
*/
return apply_filters(
'classifai_openai_api_response_get',
$this->get_result( wp_remote_get( $url, $options ) ), // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get
$url,
$options,
$this->feature
);
}

/**
Expand All @@ -60,8 +116,56 @@ public function post( string $url = '', array $options = [] ) {
'timeout' => 60, // phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout
]
);

/**
* Filter the URL for the post request.
*
* @since 2.4.0
* @hook classifai_openai_api_request_post_url
*
* @param {string} $url The URL for the request.
* @param {array} $options The options for the request.
* @param {string} $this->feature The feature name.
*
* @return {string} The URL for the request.
*/
$url = apply_filters( 'classifai_openai_api_request_post_url', $url, $options, $this->feature );

/**
* Filter the options for the post request.
*
* @since 2.4.0
* @hook classifai_openai_api_request_post_options
*
* @param {array} $options The options for the request.
* @param {string} $url The URL for the request.
* @param {string} $this->feature The feature name.
*
* @return {array} The options for the request.
*/
$options = apply_filters( 'classifai_openai_api_request_post_options', $options, $url, $this->feature );

$this->add_headers( $options );
return $this->get_result( wp_remote_post( $url, $options ) ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get

/**
* Filter the response from OpenAI for a post request.
*
* @since 2.4.0
* @hook classifai_openai_api_response_post
*
* @param {string} $url Request URL.
* @param {array} $options Request body options.
* @param {string} $this->feature Feature name.
*
* @return {array} API response.
*/
return apply_filters(
'classifai_openai_api_response_post',
$this->get_result( wp_remote_post( $url, $options ) ), // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get
$url,
$options,
$this->feature
);
}

/**
Expand All @@ -72,6 +176,19 @@ public function post( string $url = '', array $options = [] ) {
* @return array|WP_Error
*/
public function post_form( string $url = '', array $body = [] ) {
/**
* Filter the URL for the post form request.
*
* @since 2.4.0
* @hook classifai_openai_api_request_post_form_url
*
* @param {string} $url The URL for the request.
* @param {string} $this->feature The feature name.
*
* @return {string} The URL for the request.
*/
$url = apply_filters( 'classifai_openai_api_request_post_form_url', $url, $this->feature );

$boundary = wp_generate_password( 24, false );
$payload = '';

Expand All @@ -95,17 +212,54 @@ public function post_form( string $url = '', array $body = [] ) {

$payload .= '--' . $boundary . '--';

$options = [
'body' => $payload,
'headers' => [
'Content-Type' => 'multipart/form-data; boundary=' . $boundary,
/**
* Filter the options for the post form request.
*
* @since 2.4.0
* @hook classifai_openai_api_request_post_form_options
*
* @param {array} $options The options for the request.
* @param {string} $url The URL for the request.
* @param {array} $body The body of the request.
* @param {string} $this->feature The feature name.
*
* @return {array} The options for the request.
*/
$options = apply_filters(
'classifai_openai_api_request_post_form_options',
[
'body' => $payload,
'headers' => [
'Content-Type' => 'multipart/form-data; boundary=' . $boundary,
],
'timeout' => 60, // phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout
],
'timeout' => 60, // phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout
];
$url,
$body,
$this->feature
);

$this->add_headers( $options );

return $this->get_result( wp_remote_post( $url, $options ) );
/**
* Filter the response from OpenAI for a post form request.
*
* @since 2.4.0
* @hook classifai_openai_api_response_post_form
*
* @param {string} $url Request URL.
* @param {array} $options Request body options.
* @param {string} $this->feature Feature name.
*
* @return {array} API response.
*/
return apply_filters(
'classifai_openai_api_response_post_form',
$this->get_result( wp_remote_post( $url, $options ) ), // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get
$url,
$options,
$this->feature
);
}

/**
Expand Down
Loading

0 comments on commit 2a0d9d7

Please sign in to comment.