Skip to content

Commit 7e4b4b4

Browse files
committed
fix WP_CLI Commands
1 parent 8f0655e commit 7e4b4b4

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

includes/Classifai/Command/ClassifaiCommand.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Classifai\Features\AudioTranscriptsGeneration;
66
use Classifai\Features\Classification;
7+
use Classifai\Features\DescriptiveTextGenerator;
78
use Classifai\Features\ExcerptGeneration;
89
use Classifai\Features\ImageCropping;
910
use Classifai\Features\TextToSpeech;
@@ -788,8 +789,7 @@ public function image( $args = [], $opts = [] ) {
788789
$attachment_ids = $this->get_attachment_to_classify( $opts );
789790
}
790791

791-
$total = count( $attachment_ids );
792-
$classifier = new ComputerVision( false );
792+
$total = count( $attachment_ids );
793793

794794
if ( empty( $total ) ) {
795795
return \WP_CLI::log( 'No images to classify.' );
@@ -812,8 +812,13 @@ public function image( $args = [], $opts = [] ) {
812812

813813
$current_meta = wp_get_attachment_metadata( $attachment_id );
814814
\WP_CLI::line( 'Processing ' . $attachment_id );
815-
$classifier->generate_image_alt_tags( $current_meta, $attachment_id );
816-
$classifier->smart_crop_image( $current_meta, $attachment_id );
815+
$feature = new DescriptiveTextGenerator();
816+
$result = $feature->run( $attachment_id, 'descriptive_text' );
817+
$feature->save( $result, $attachment_id );
818+
819+
$feature = new ImageCropping();
820+
$result = $feature->run( $attachment_id, 'crop' );
821+
$feature->save( $result, $attachment_id );
817822
}
818823

819824
$progress_bar->finish();

includes/Classifai/Features/Feature.php

+4
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,10 @@ public function has_access(): bool {
956956
$access = ( ! in_array( static::ID, $opted_out_features, true ) );
957957
}
958958

959+
if ( defined( 'WP_CLI' ) && WP_CLI ) {
960+
$access = true;
961+
}
962+
959963
/**
960964
* Filter to override user access to a ClassifAI feature.
961965
*

includes/Classifai/Providers/OpenAI/Whisper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function rest_endpoint_callback( $post_id = 0, string $route_to_call = ''
187187
* @return WP_Error|bool
188188
*/
189189
public function transcribe_audio( int $attachment_id = 0, array $args = [] ) {
190-
if ( $attachment_id && ! current_user_can( 'edit_post', $attachment_id ) ) {
190+
if ( $attachment_id && ! current_user_can( 'edit_post', $attachment_id ) && ( ! defined( 'WP_CLI' ) || ! WP_CLI ) ) {
191191
return new \WP_Error( 'no_permission', esc_html__( 'User does not have permission to edit this attachment.', 'classifai' ) );
192192
}
193193

0 commit comments

Comments
 (0)