| @@ -12,10 +12,10 @@ | ||
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Retrieves images from the post content. |
| 15 | 15 | * |
| 16 | - * @param int $post_id The post ID. | |
| 17 | - * @param \WP_Post|null $post The post object. | |
| 16 | + * @param int $post_id The post ID. | |
| 17 | + * @param WP_Post|null $post The post object. | |
| 18 | 18 | * |
| 19 | 19 | * @return array An array of images found in this post. |
| 20 | 20 | */ |
| 21 | 21 | public function get_images( $post_id, $post = null ) { |
| @@ -34,13 +34,13 @@ | ||
| 34 | 34 | return []; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | $content_images = $this->get_img_tags_from_content( $content ); |
| 38 | - $images = array_map( [ $this, 'get_img_tag_source' ], $content_images ); | |
| 39 | - $images = array_filter( $images ); | |
| 40 | - $images = array_unique( $images ); | |
| 41 | - $images = array_values( $images ); // Reset the array keys. | |
| 42 | 38 | |
| 39 | + $images = array_map( [ $this, 'get_img_tag_source' ], $content_images ); | |
| 40 | + $images = array_filter( $images ); | |
| 41 | + $images = array_unique( $images ); | |
| 42 | + $images = array_values( $images ); // Reset the array keys. | |
| 43 | 43 | return $images; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
| @@ -71,9 +71,9 @@ | ||
| 71 | 71 | * @return string|bool The image URL on success, false on failure. |
| 72 | 72 | */ |
| 73 | 73 | private function get_img_tag_source( $image ) { |
| 74 | 74 | preg_match( '`src=(["\'])(.*?)\1`', $image, $matches ); |
| 75 | - if ( isset( $matches[2] ) ) { | |
| 75 | + if ( isset( $matches[2] ) && filter_var( $matches[2], FILTER_VALIDATE_URL ) ) { | |
| 76 | 76 | return $matches[2]; |
| 77 | 77 | } |
| 78 | 78 | return false; |
| 79 | 79 | } |
| @@ -86,11 +86,9 @@ | ||
| 86 | 86 | * |
| 87 | 87 | * @return string The content of the supplied post. |
| 88 | 88 | */ |
| 89 | 89 | private function get_post_content( $post_id, $post ) { |
| 90 | - if ( $post === null ) { | |
| 91 | - $post = get_post( $post_id ); | |
| 92 | - } | |
| 90 | + $post ??= get_post( $post_id ); | |
| 93 | 91 | |
| 94 | 92 | if ( $post === null ) { |
| 95 | 93 | return ''; |
| 96 | 94 | } |
| @@ -97,9 +95,10 @@ | ||
| 97 | 95 | |
| 98 | 96 | /** |
| 99 | 97 | * Filter: 'wpseo_pre_analysis_post_content' - Allow filtering the content before analysis. |
| 100 | 98 | * |
| 101 | - * @api string $post_content The Post content string. | |
| 99 | + * @param string $post_content The Post content string. | |
| 100 | + * @param WP_Post $post The current post. | |
| 102 | 101 | */ |
| 103 | 102 | $content = apply_filters( 'wpseo_pre_analysis_post_content', $post->post_content, $post ); |
| 104 | 103 | |
| 105 | 104 | if ( ! is_string( $content ) ) { |