Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to WPCS v3 #184

Merged
merged 3 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"require-dev": {
"wp-cli/entity-command": "^1.3 || ^2",
"wp-cli/extension-command": "^2.0",
"wp-cli/wp-cli-tests": "^3.1"
"wp-cli/wp-cli-tests": "^4"
},
"config": {
"process-timeout": 7200,
Expand Down
2 changes: 1 addition & 1 deletion media-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
return;
}

$wpcli_media_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php';
$wpcli_media_autoloader = __DIR__ . '/vendor/autoload.php';
if ( file_exists( $wpcli_media_autoloader ) ) {
require_once $wpcli_media_autoloader;
}
Expand Down
50 changes: 24 additions & 26 deletions src/Media_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function regenerate( $args, $assoc_args = array() ) {
$errors = 0;
$skips = 0;
foreach ( $images->posts as $post ) {
$number++;
++$number;
if ( 0 === $number % self::WP_CLEAR_OBJECT_CACHE_INTERVAL ) {
Utils\wp_clear_object_cache();
}
Expand Down Expand Up @@ -286,7 +286,7 @@ public function import( $args, $assoc_args = array() ) {
$successes = 0;
$errors = 0;
foreach ( $args as $file ) {
$number++;
++$number;
if ( 0 === $number % self::WP_CLEAR_OBJECT_CACHE_INTERVAL ) {
Utils\wp_clear_object_cache();
}
Expand All @@ -299,7 +299,7 @@ public function import( $args, $assoc_args = array() ) {
if ( empty( $is_file_remote ) ) {
if ( ! file_exists( $file ) ) {
WP_CLI::warning( "Unable to import file '$file'. Reason: File doesn't exist." );
$errors++;
++$errors;
continue;
}
if ( Utils\get_flag_value( $assoc_args, 'skip-copy' ) ) {
Expand All @@ -322,7 +322,7 @@ public function import( $args, $assoc_args = array() ) {
implode( ', ', $tempfile->get_error_messages() )
)
);
$errors++;
++$errors;
continue;
}
$name = strtok( Utils\basename( $file ), '?' );
Expand Down Expand Up @@ -383,7 +383,7 @@ public function import( $args, $assoc_args = array() ) {
implode( ', ', $success->get_error_messages() )
)
);
$errors++;
++$errors;
continue;
}
wp_update_attachment_metadata( $success, wp_generate_attachment_metadata( $success, $file ) );
Expand All @@ -398,7 +398,7 @@ public function import( $args, $assoc_args = array() ) {
implode( ', ', $success->get_error_messages() )
)
);
$errors++;
++$errors;
continue;
}
}
Expand Down Expand Up @@ -438,7 +438,7 @@ public function import( $args, $assoc_args = array() ) {
)
);
}
$successes++;
++$successes;
}

// Report the result of the operation
Expand Down Expand Up @@ -507,7 +507,7 @@ public function image_size( $args, $assoc_args ) {

usort(
$sizes,
function( $a, $b ) {
function ( $a, $b ) {
if ( $a['width'] === $b['width'] ) {
return 0;
}
Expand Down Expand Up @@ -588,7 +588,7 @@ private function process_regeneration( $id, $skip_delete, $only_missing, $image_

if ( false === $fullsizepath || ! file_exists( $fullsizepath ) ) {
WP_CLI::warning( "Can't find $att_desc." );
$errors++;
++$errors;
return;
}

Expand All @@ -600,37 +600,37 @@ private function process_regeneration( $id, $skip_delete, $only_missing, $image_

if ( $skip_it ) {
WP_CLI::log( "$progress Skipped $thumbnail_desc regeneration for $att_desc." );
$skips++;
++$skips;
return;
}

if ( $only_missing && ! $needs_regeneration ) {
WP_CLI::log( "$progress No $thumbnail_desc regeneration needed for $att_desc." );
$successes++;
++$successes;
return;
}

$metadata = wp_generate_attachment_metadata( $id, $fullsizepath );
if ( is_wp_error( $metadata ) ) {
WP_CLI::warning( sprintf( '%s (ID %d)', $metadata->get_error_message(), $id ) );
WP_CLI::log( "$progress Couldn't regenerate thumbnails for $att_desc." );
$errors++;
++$errors;
return;
}

// Note it's possible for no metadata to be generated for PDFs if restricted to a specific image size.
if ( empty( $metadata ) && ! ( $is_pdf && $image_size ) ) {
WP_CLI::warning( sprintf( 'No metadata. (ID %d)', $id ) );
WP_CLI::log( "$progress Couldn't regenerate thumbnails for $att_desc." );
$errors++;
++$errors;
return;
}

// On read error, we might only get the filesize returned and nothing else.
if ( 1 === count( $metadata ) && array_key_exists( 'filesize', $metadata ) && ! ( $is_pdf && $image_size ) ) {
WP_CLI::warning( sprintf( 'Read error while retrieving metadata. (ID %d)', $id ) );
WP_CLI::log( "$progress Couldn't regenerate thumbnails for $att_desc." );
$errors++;
++$errors;
return;
}

Expand All @@ -645,7 +645,7 @@ private function process_regeneration( $id, $skip_delete, $only_missing, $image_

WP_CLI::log( "$progress Regenerated thumbnails for $att_desc." );
}
$successes++;
++$successes;
}

private function remove_old_images( $metadata, $fullsizepath, $image_size ) {
Expand Down Expand Up @@ -841,13 +841,11 @@ private function get_intermediate_sizes( $is_pdf, $metadata, $att_id ) {

if ( isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ) {
$sizes[ $s ]['crop'] = (bool) $_wp_additional_image_sizes[ $s ]['crop'];
} else {
// Force PDF thumbnails to be soft crops.
if ( $is_pdf && 'thumbnail' === $s ) {
$sizes[ $s ]['crop'] = false;
} else {
$sizes[ $s ]['crop'] = (bool) get_option( "{$s}_crop" );
}
} elseif ( $is_pdf && 'thumbnail' === $s ) {
$sizes[ $s ]['crop'] = false;
} else {
$sizes[ $s ]['crop'] = (bool) get_option( "{$s}_crop" );
}
}

Expand Down Expand Up @@ -1055,7 +1053,7 @@ public function fix_orientation( $args, $assoc_args ) {
$successes = 0;
$errors = 0;
foreach ( $images->posts as $post ) {
$number++;
++$number;
if ( 0 === $number % self::WP_CLEAR_OBJECT_CACHE_INTERVAL ) {
Utils\wp_clear_object_cache();
}
Expand Down Expand Up @@ -1096,7 +1094,7 @@ private function process_orientation_fix( $id, $progress, &$successes, &$errors,

if ( false === $full_size_path || ! file_exists( $full_size_path ) ) {
WP_CLI::warning( "Can't find {$att_desc}." );
$errors++;
++$errors;
return;
}

Expand All @@ -1108,14 +1106,14 @@ private function process_orientation_fix( $id, $progress, &$successes, &$errors,
if ( ! $dry_run ) {
WP_CLI::log( "{$progress} Fixing orientation for {$att_desc}." );
if ( false !== $this->flip_rotate_image( $id, $metadata, $image_meta, $full_size_path ) ) {
$successes++;
++$successes;
} else {
$errors++;
++$errors;
WP_CLI::log( "Couldn't fix orientation for {$att_desc}." );
}
} else {
WP_CLI::log( "{$progress} {$att_desc} will be affected." );
$successes++;
++$successes;
}
} else {
WP_CLI::log( "{$progress} No orientation fix required for {$att_desc}." );
Expand Down