Skip to content

Commit 31bf160

Browse files
authored
Merge pull request #998 from cloudinary/fix/file-exist-check
Fix/file exist check
2 parents 11b26aa + e8a392e commit 31bf160

2 files changed

Lines changed: 14 additions & 14 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

0 commit comments

Comments
 (0)