Skip to content

Commit c897b7a

Browse files
author
Marco Pereirinha
committed
Merge branch 'develop' into uat
2 parents 626e396 + 31bf160 commit c897b7a

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

php/class-media.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -356,22 +356,16 @@ public function maybe_file_exist_in_url( $url ) {
356356
if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) {
357357
return false;
358358
}
359-
// phpcs:disable WordPress.WP.AlternativeFunctions
360-
$ch = curl_init( $url );
361-
curl_setopt( $ch, CURLOPT_NOBODY, true );
362-
curl_exec( $ch );
363-
$code = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
364-
365-
if ( 200 === $code ) {
366-
$status = true;
367-
} else {
368-
$status = false;
359+
360+
$head = wp_safe_remote_head( $url );
361+
362+
if ( is_wp_error( $head ) ) {
363+
return false;
369364
}
370365

371-
curl_close( $ch );
372-
// phpcs:enable
366+
$code = wp_remote_retrieve_response_code( $head );
373367

374-
return $status;
368+
return 200 === $code;
375369
}
376370

377371
/**

php/relate/class-relationship.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,17 @@ public function flush_cache() {
160160
* @param array $post_ids The post ids.
161161
*/
162162
public static function preload( $post_ids ) {
163+
// Check if the post_ids are objects.
164+
$maybe_ids = array_column( $post_ids, 'ID' );
165+
if ( ! empty( $maybe_ids ) ) {
166+
// If so, make sure to just use the IDs.
167+
$post_ids = $maybe_ids;
168+
}
163169
global $wpdb;
164170
$table_name = Utils::get_relationship_table();
165171
// Do the public_ids.
166172
$list = implode( ', ', array_fill( 0, count( $post_ids ), '%d' ) );
167-
$where = "post_id IN( {$list} )";
173+
$where = "post_id IN ( {$list} )";
168174

169175
$sql = $wpdb->prepare( "SELECT * FROM {$table_name} WHERE {$where}", $post_ids ); // phpcs:ignore WordPress.DB
170176
$posts = $wpdb->get_results( $sql, ARRAY_A ); // phpcs:ignore WordPress.DB

php/sync/class-sync-queue.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,18 +394,18 @@ public function get_total_synced_media() {
394394
$return = array(
395395
// Original sizes.
396396
'original_size' => $total_local_size,
397-
'original_size_percent' => '100%', // The original will always be 100%, as it's the comparison to optimized.
397+
'original_size_percent' => 0 !== $total_assets ? '100%' : '0%', // The original will always be 100%, as it's the comparison to optimized.
398398
'original_size_hr' => size_format( $total_local_size ),
399399

400400
// Optimized size. We use the `original_size` to determine the percentage between for the progress bar.
401401
'optimized_size' => $total_remote_size,
402-
'optimized_size_percent' => round( abs( $total_remote_size ) / abs( $total_local_size ) * 100 ) . '%', // This is the percentage difference.
403-
'optimized_diff_percent' => round( ( $total_local_size - $total_remote_size ) / $total_local_size * 100 ) . '%', // We use this for the "Size saved.." status text.
402+
'optimized_size_percent' => $total_local_size > 0 ? round( abs( $total_remote_size ) / abs( $total_local_size ) * 100 ) . '%' : '0%', // This is the percentage difference.
403+
'optimized_diff_percent' => $total_local_size > 0 ? round( ( $total_local_size - $total_remote_size ) / $total_local_size * 100 ) . '%' : '0%', // We use this for the "Size saved.." status text.
404404
'optimized_size_hr' => size_format( $total_remote_size ), // This is the formatted byte size.
405405

406406
// Optimized is the % optimized vs unoptimized.
407-
'optimized_percent' => round( $total_optimized / $total_assets, 4 ),
408-
'optimized_percent_hr' => round( $total_optimized / $total_assets * 100, 1 ) . '%',
407+
'optimized_percent' => $total_assets > 0 ? round( $total_optimized / $total_assets, 4 ) : 0,
408+
'optimized_percent_hr' => $total_assets > 0 ? round( $total_optimized / $total_assets * 100, 1 ) . '%' : '0%',
409409
'optimized_info' => __( 'Optimized assets', 'cloudinary' ),
410410

411411
// Error size: No mockups on what to display here.

0 commit comments

Comments
 (0)