Skip to content

Commit

Permalink
Merge pull request #470 from 10up/fix/hooks
Browse files Browse the repository at this point in the history
Ensure all custom hooks have proper docblocks
  • Loading branch information
dkotter committed May 26, 2023
2 parents ec9e7e1 + 63b6918 commit c5411af
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 69 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

[![E2E Testing](https://github.com/10up/classifai/actions/workflows/cypress.yml/badge.svg)](https://github.com/10up/classifai/actions/workflows/cypress.yml) [![PHPUnit Testing](https://github.com/10up/classifai/actions/workflows/test.yml/badge.svg)](https://github.com/10up/classifai/actions/workflows/test.yml) [![Linting](https://github.com/10up/classifai/actions/workflows/lint.yml/badge.svg)](https://github.com/10up/classifai/actions/workflows/lint.yml) [![CodeQL](https://github.com/10up/classifai/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/10up/classifai/actions/workflows/codeql-analysis.yml) [![Dependency Review](https://github.com/10up/classifai/actions/workflows/dependency-review.yml/badge.svg)](https://github.com/10up/classifai/actions/workflows/dependency-review.yml)

*You can learn more about ClassifAI's features at [ClassifAIPlugin.com](https://classifaiplugin.com/) and documentation at the [ClassifAI documentation site](https://10up.github.io/classifai/).*

## Table of Contents
* [Overview](#overview)
* [Features](#features)
Expand Down
16 changes: 8 additions & 8 deletions includes/Classifai/Providers/Azure/ComputerVision.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,11 @@ public function ocr_processing( array $metadata = [], int $attachment_id = 0, bo
* @since 1.6.0
* @hook classifai_should_ocr_scan_image
*
* @param bool $should_ocr_scan Whether to run OCR scanning. The default value is set in ComputerVision settings.
* @param array $metadata Image metadata.
* @param int $attachment_id The attachment ID.
* @param {bool} $should_ocr_scan Whether to run OCR scanning. The default value is set in ComputerVision settings.
* @param {array} $metadata Image metadata.
* @param {int} $attachment_id The attachment ID.
*
* @return bool Whether to run OCR scanning.
* @return {bool} Whether to run OCR scanning.
*/
if ( ! $force && ! apply_filters( 'classifai_should_ocr_scan_image', $should_ocr_scan, $metadata, $attachment_id ) ) {
return $metadata;
Expand Down Expand Up @@ -815,8 +815,8 @@ protected function generate_alt_tags( $captions, $attachment_id ) {
* @since 1.5.0
* @hook classifai_computer_vision_caption_failed
*
* @param array $tags The caption data.
* @param int $threshold The caption_threshold setting.
* @param {array} $tags The caption data.
* @param {int} $threshold The caption_threshold setting.
*/
do_action( 'classifai_computer_vision_caption_failed', $captions, $threshold );
}
Expand Down Expand Up @@ -928,8 +928,8 @@ protected function generate_image_tags( $tags, $attachment_id ) {
* @since 1.5.0
* @hook classifai_computer_vision_image_tag_failed
*
* @param array $tags The image tag data.
* @param int $threshold The tag_threshold setting.
* @param {array} $tags The image tag data.
* @param {int} $threshold The tag_threshold setting.
*/
do_action( 'classifai_computer_vision_image_tag_failed', $tags, $threshold );
}
Expand Down
56 changes: 28 additions & 28 deletions includes/Classifai/Providers/Azure/OCR.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ public function should_process( int $attachment_id ) {
* @since 1.6.0
* @hook classifai_ocr_approved_media_types
*
* @param array $media_types The media types to process.
* @param int $attachment_id The attachment ID.
* @param {array} $media_types The media types to process.
* @param {int} $attachment_id The attachment ID.
*
* @return array Filtered media types.
* @return {array} Filtered media types.
*/
$approved_media_types = apply_filters( 'classifai_ocr_approved_media_types', $this->media_to_process, $attachment_id );

Expand All @@ -145,11 +145,11 @@ public function should_process( int $attachment_id ) {
* @since 1.6.0
* @hook classifai_ocr_tags
*
* @param array $tags Tags to look for. Default handwriting and text.
* @param int $attachment_id The attachment ID.
* @param bool|object $scan Previosly run scan.
* @param {array} $tags Tags to look for. Default handwriting and text.
* @param {int} $attachment_id The attachment ID.
* @param {bool|object} $scan Previously run scan.
*
* @return array Filtered tags.
* @return {array} Filtered tags.
*/
$tags = apply_filters( 'classifai_ocr_tags', [ 'handwriting', 'text' ], $attachment_id, $this->scan );

Expand All @@ -159,11 +159,11 @@ public function should_process( int $attachment_id ) {
* @since 1.6.0
* @hook classifai_ocr_tag_confidence
*
* @param int $confidence The mininum confidence level. Default 90.
* @param int $attachment_id The attachment ID.
* @param bool|object $scan Previosly run scan.
* @param {int} $confidence The minimum confidence level. Default 90.
* @param {int} $attachment_id The attachment ID.
* @param {bool|object} $scan Previously run scan.
*
* @return int Confidence level.
* @return {int} Confidence level.
*/
$tag_confidence = apply_filters( 'classifai_ocr_tag_confidence', 90, $attachment_id, $this->scan );

Expand All @@ -181,11 +181,11 @@ public function should_process( int $attachment_id ) {
* @since 1.6.0
* @hook classifai_ocr_should_process
*
* @param bool $process Whether to run OCR processing or not.
* @param int $attachment_id The attachment ID.
* @param bool|object $scan Previosly run scan.
* @param {bool} $process Whether to run OCR processing or not.
* @param {int} $attachment_id The attachment ID.
* @param {bool|object} $scan Previously run scan.
*
* @return bool Whether this attachment should have OCR processing.
* @return {bool} Whether this attachment should have OCR processing.
*/
return apply_filters( 'classifai_ocr_should_process', $process, $attachment_id, $this->scan );
}
Expand Down Expand Up @@ -246,10 +246,10 @@ public function generate_ocr_data( array $metadata, int $attachment_id ) {
* @since 1.6.0
* @hook classifai_ocr_text
*
* @param string $text The returned text data.
* @param object $scan The full scan results from the API.
* @param {string} $text The returned text data.
* @param {object} $scan The full scan results from the API.
*
* @return string The filtered text data.
* @return {string} The filtered text data.
*/
$text = apply_filters( 'classifai_ocr_text', implode( ' ', $text ), $scan );

Expand All @@ -267,13 +267,13 @@ public function generate_ocr_data( array $metadata, int $attachment_id ) {
* @since 1.6.0
* @hook classifai_ocr_text_post_args
*
* @param string $post_args Array of post data for the attachment post update. Defaults to `ID` and `post_content`.
* @param int $attachment_id ID of the attachment post.
* @param object $scan The full scan results from the API.
* @param string $text The text data to be saved.
* @param object $scan The full scan results from the API.
* @param {string} $post_args Array of post data for the attachment post update. Defaults to `ID` and `post_content`.
* @param {int} $attachment_id ID of the attachment post.
* @param {object} $scan The full scan results from the API.
* @param {string} $text The text data to be saved.
* @param {object} $scan The full scan results from the API.
*
* @return string The filtered text data.
* @return {string} The filtered text data.
*/
$post_args = apply_filters( 'classifai_ocr_text_post_args', $post_args, $attachment_id, $text, $scan );

Expand Down Expand Up @@ -326,8 +326,8 @@ public function process( string $url ) {
* @since 1.6.0
* @hook classifai_ocr_after_request
*
* @param array|WP_Error Response data or a WP_Error if the request failed.
* @param string The attachment URL.
* @param {array|WP_Error} Response data or a WP_Error if the request failed.
* @param {string} The attachment URL.
*/
do_action( 'classifai_ocr_after_request', $response, $url );

Expand All @@ -349,8 +349,8 @@ public function process( string $url ) {
* @since 1.6.0
* @hook classifai_ocr_unsuccessful_response
*
* @param array|WP_Error Response data or a WP_Error if the request failed.
* @param string The attachment URL.
* @param {array|WP_Error} Response data or a WP_Error if the request failed.
* @param {string} The attachment URL.
*/
do_action( 'classifai_ocr_unsuccessful_response', $response, $url );

Expand Down
48 changes: 31 additions & 17 deletions includes/Classifai/Providers/Azure/Read.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ public function should_process() {
/**
* Filters whether to run Read processing on this attachment item
*
* @since 1.7.0
* @hook classifai_azure_read_should_process
*
* @param bool $process Whether to run OCR processing or not.
* @param int $attachment_id The attachment ID.
* @param {bool} $process Whether to run OCR processing or not.
* @param {int} $attachment_id The attachment ID.
*
* @return bool Whether this attachment should have OCR processing.
* @return {bool} Whether this attachment should have OCR processing.
*/
return apply_filters( 'classifai_azure_read_should_process', $process, $this->attachment_id );
}
Expand Down Expand Up @@ -145,12 +146,13 @@ public function read_document() {
/**
* Filters the request arguments sent to Read endpoint.
*
* @since 1.7.0
* @hook classifai_azure_read_should_process
*
* @param array $args Whether to run OCR processing or not.
* @param int $attachment_id The attachment ID.
* @param {array} $args Whether to run OCR processing or not.
* @param {int} $attachment_id The attachment ID.
*
* @return array Filtered request arguments.
* @return {array} Filtered request arguments.
*/
$request_args = apply_filters( 'classifai_azure_read_request_args', [], $this->attachment_id );

Expand Down Expand Up @@ -186,10 +188,10 @@ public function read_document() {
* @since 1.5.0
* @hook classifai_azure_read_after_request
*
* @param array|WP_Error Response data or a WP_Error if the request failed.
* @param string The request URL with query args added.
* @param int The document ID.
* @param string The document URL.
* @param {array|WP_Error} Response data or a WP_Error if the request failed.
* @param {string} The request URL with query args added.
* @param {int} The document ID.
* @param {string} The document URL.
*/
do_action( 'classifai_azure_read_after_request', $response, $url, $this->attachment_id, $document_url );

Expand Down Expand Up @@ -251,6 +253,16 @@ public function check_read_result( $operation_url ) {
case 'notStarted':
case 'running':
$this->update_status( $body );
/**
* Filters the Read retry interval.
*
* @since 1.7.0
* @hook classifai_azure_read_retry_interval
*
* @param {int} $seconds How many seconds should the interval be? Default 60.
*
* @return {int} Filtered interval.
*/
$retry_interval = apply_filters( 'classifai_azure_read_retry_interval', MINUTE_IN_SECONDS );
wp_schedule_single_event( time() + $retry_interval, 'classifai_retry_get_read_result', [ $operation_url, $this->attachment_id ] );
break;
Expand Down Expand Up @@ -280,13 +292,14 @@ public function update_document_description( $data ) {
}

/**
* Filter the text max pages can be processed.
* Filter the max pages that can be processed.
*
* @since 1.7.0
* @hook classifai_azure_read_result_max_page
*
* @param int $max_page The attachment ID.
* @param {int} $max_page The maximum pages that are read.
*
* @return int
* @return {int} Filtered max pages.
*/
$max_page = min( apply_filters( 'classifai_azure_read_result_max_page', 2 ), count( $data['analyzeResult']['readResults'] ) );

Expand All @@ -301,13 +314,14 @@ public function update_document_description( $data ) {
/**
* Filter the text result returned from Read API.
*
* @since 1.7.0
* @hook classifai_azure_read_text_result
*
* @param array $lines_of_text Array of text extracted from the response.
* @param int $attachment_id The attachment ID.
* @param array $data Read result.
* @param {array} $lines_of_text Array of text extracted from the response.
* @param {int} $attachment_id The attachment ID.
* @param {array} $data Read result.
*
* @return array
* @return {array} Filtered array of text.
*/
$lines_of_text = apply_filters( 'classifai_azure_read_text_result', $lines_of_text, $this->attachment_id, $data );

Expand Down
23 changes: 13 additions & 10 deletions includes/Classifai/Providers/Azure/SmartCropping.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function get_max_pixel_dimension() {
* @since 1.5.0
* @hook classifai_smart_crop_max_pixel_dimension
*
* @param {int} max The max width/height in pixels.
* @param {int} $max The max width/height in pixels. Default 1024.
*
* @return {int} Filtered max dimension in pixels.
*/
Expand Down Expand Up @@ -264,10 +264,13 @@ public function get_cropped_thumbnail( $attachment_id, $size_data ) {
* the original file in the file system.
*
* @since 1.5.0
* @hook classifai_smart_cropping_thumb_file_name
*
* @param string Default file name.
* @param int The ID of the attachment being processed.
* @param array Width and height data for the image.
* @param {string} Default file name.
* @param {int} The ID of the attachment being processed.
* @param {array} Width and height data for the image.
*
* @return {string} Filtered file name.
*/
$new_thumb_file_name = apply_filters(
'classifai_smart_cropping_thumb_file_name',
Expand Down Expand Up @@ -334,9 +337,9 @@ public function request_cropped_thumbnail( $data ) {
* @since 1.5.0
* @hook classifai_smart_cropping_after_request
*
* @param array|WP_Error Response data or a WP_Error if the request failed.
* @param string The request URL with query args added.
* @param array Array containing the image height and width.
* @param {array|WP_Error} Response data or a WP_Error if the request failed.
* @param {string} The request URL with query args added.
* @param {array} Array containing the image height and width.
*/
do_action( 'classifai_smart_cropping_after_request', $response, $url, $data );

Expand All @@ -358,9 +361,9 @@ public function request_cropped_thumbnail( $data ) {
* @since 1.5.0
* @hook classifai_smart_cropping_unsuccessful_response
*
* @param array|WP_Error Response data or a WP_Error if the request failed.
* @param string The request URL with query args added.
* @param array Array containing the image height and width.
* @param {array|WP_Error} Response data or a WP_Error if the request failed.
* @param {string} The request URL with query args added.
* @param {array} Array containing the image height and width.
*/
do_action( 'classifai_smart_cropping_unsuccessful_response', $response, $url, $data );

Expand Down
20 changes: 14 additions & 6 deletions includes/Classifai/Providers/Azure/TextToSpeech.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,15 @@ public function render_post_audio_controls( $content ) {
}

/**
* Filter to disable Text to Speech synthesis for a post by post ID.
* Filter to disable the rendering of the Text to Speech block.
*
* @param boolean 'is_disabled' Boolean to toggle the service. By default - false.
* @param boolean 'post_id' Post ID.
* @since 2.2.0
* @hook classifai_disable_post_to_audio_block
*
* @param {bool} $is_disabled Whether to disable the display or not. By default - false.
* @param {bool} $post_id Post ID.
*
* @return {bool} Whether the audio block should be shown.
*/
if ( apply_filters( 'classifai_disable_post_to_audio_block', false, $post->ID ) ) {
return $content;
Expand Down Expand Up @@ -555,10 +560,13 @@ public function render_post_audio_controls( $content ) {
/**
* Hook to filter the text next to the audio controls on the frontend.
*
* @param string The text to filter.
* @param integer The Post ID.
* @since 2.2.0
* @hook classifai_listen_to_this_post_text
*
* @param {string} The text to filter.
* @param {int} Post ID.
*
* @return string
* @return {string} Filtered text.
*/
apply_filters( 'classifai_listen_to_this_post_text', '%s %s', $post->ID ),
esc_html__( 'Listen to this', 'classifai' ),
Expand Down
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Supercharge WordPress Content Workflows and Engagement with Artificial Intellige

Tap into leading cloud-based services like [OpenAI](https://openai.com/), [Microsoft Azure AI](https://azure.microsoft.com/en-us/overview/ai-platform/), and [IBM Watson](https://www.ibm.com/watson) to augment your WordPress-powered websites. Publish content faster while improving SEO performance and increasing audience engagement. ClassifAI integrates Artificial Intelligence and Machine Learning technologies to lighten your workload and eliminate tedious tasks, giving you more time to create original content that matters.

*You can learn more about ClassifAI's features at [ClassifAIPlugin.com](https://classifaiplugin.com/) and documentation at the [ClassifAI documentation site](https://10up.github.io/classifai/).*

**Features**

* Generate a summary of post content and store it as an excerpt using [OpenAI's ChatGPT API](https://platform.openai.com/docs/guides/chat)
Expand Down

0 comments on commit c5411af

Please sign in to comment.