diff --git a/php/class-media.php b/php/class-media.php index 940cc0602..c23990305 100644 --- a/php/class-media.php +++ b/php/class-media.php @@ -356,22 +356,16 @@ public function maybe_file_exist_in_url( $url ) { if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) { return false; } - // phpcs:disable WordPress.WP.AlternativeFunctions - $ch = curl_init( $url ); - curl_setopt( $ch, CURLOPT_NOBODY, true ); - curl_exec( $ch ); - $code = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); - - if ( 200 === $code ) { - $status = true; - } else { - $status = false; + + $head = wp_safe_remote_head( $url ); + + if ( is_wp_error( $head ) ) { + return false; } - curl_close( $ch ); - // phpcs:enable + $code = wp_remote_retrieve_response_code( $head ); - return $status; + return 200 === $code; } /** diff --git a/php/relate/class-relationship.php b/php/relate/class-relationship.php index 458ba9fd2..8ae352110 100644 --- a/php/relate/class-relationship.php +++ b/php/relate/class-relationship.php @@ -160,11 +160,17 @@ public function flush_cache() { * @param array $post_ids The post ids. */ public static function preload( $post_ids ) { + // Check if the post_ids are objects. + $maybe_ids = array_column( $post_ids, 'ID' ); + if ( ! empty( $maybe_ids ) ) { + // If so, make sure to just use the IDs. + $post_ids = $maybe_ids; + } global $wpdb; $table_name = Utils::get_relationship_table(); // Do the public_ids. $list = implode( ', ', array_fill( 0, count( $post_ids ), '%d' ) ); - $where = "post_id IN( {$list} )"; + $where = "post_id IN ( {$list} )"; $sql = $wpdb->prepare( "SELECT * FROM {$table_name} WHERE {$where}", $post_ids ); // phpcs:ignore WordPress.DB $posts = $wpdb->get_results( $sql, ARRAY_A ); // phpcs:ignore WordPress.DB