@E~U  _ E~U E~UP p`E~U G E~U HpE~U =pE~U`p =pE~U`` =' E~U`PuE~U E~UPuE~U E~UPuE~U < E~U  HpE~U =hE~Up PAhE~U` `AE~U0< E~U00 @G@ E~U@ H7 E~UPt E~U<u E~U``Mp E~U`p`N _ E~UpO E~UE~UP b a E~UE~U b a E~UpE~UF E~UP p`E~U G E~U H E~U HpE~U =' E~UPuE~U< E~U` H7 E~UPt E~U<0E~U*PE~U`pE~U(=E~U< E~U .pE~U0=hE~UpPAE~U0<E~U0 4pE~U + E~UP8p`E~U@G^E~U@HpE~UH=hE~UPAhE~U`AE~UP< E~UP@HpE~U P=hE~UPAE~U`< E~U``@H7 E~U@Pt E~U<(E~U> 3E~UhA\Y hANcApgANcAJjAnA4wANcAlAxnA8wAhApgA؝nA8wAhAlAxnA8wApgA0BjA9wAhbAPoA@nA@9wAhApgAhAJjAnAh9wAhAlAxnA9wANcAhAhApgAJjAnAXYA9wAlAxnAXYA:wA(:wA(:wAh:wApgABjAaApgA TjA:wAhbAhimA@nA:wAV hbA:wA;wAH;wAhmA`#wA`#wA;wA[AcA_bAYAYAH7cAhbA:wA;wA#wAH#cA`#wA`#wA;wAaA[AcA_bAH7cAaApgAPDjA`#wA`#wA;wAaA;wA[AhbA $maximum ) ) { return false; } } return true; } /** * Gets the post's first usable content image. Null if none is available. * * @param int|null $post_id The post id. * * @return string|null The image URL. */ public static function get_first_usable_content_image_for_post( $post_id = null ) { $post = get_post( $post_id ); // We know get_post() returns the post or null. if ( ! $post ) { return null; } $image_finder = new WPSEO_Content_Images(); $images = $image_finder->get_images( $post->ID, $post ); return self::get_first_image( $images ); } /** * Gets the term's first usable content image. Null if none is available. * * @param int $term_id The term id. * * @return string|null The image URL. */ public static function get_first_content_image_for_term( $term_id ) { $term_description = term_description( $term_id ); // We know term_description() returns a string which may be empty. if ( $term_description === '' ) { return null; } $image_finder = new WPSEO_Content_Images(); $images = $image_finder->get_images_from_content( $term_description ); return self::get_first_image( $images ); } /** * Retrieves an attachment ID for an image uploaded in the settings. * * Due to self::get_attachment_by_url returning 0 instead of false. * 0 is also a possibility when no ID is available. * * @param string $setting The setting the image is stored in. * * @return int|bool The attachment id, or false or 0 if no ID is available. */ public static function get_attachment_id_from_settings( $setting ) { $image_id = WPSEO_Options::get( $setting . '_id', false ); if ( ! $image_id ) { $image = WPSEO_Options::get( $setting, false ); if ( $image ) { // There is not an option to put a URL in an image field in the settings anymore, only to upload it through the media manager. // This means an attachment always exists, so doing this is only needed once. $image_id = self::get_attachment_by_url( $image ); WPSEO_Options::set( $setting . '_id', $image_id ); } } return $image_id; } /** * Retrieves the first possible image url from an array of images. * * @param array $images The array to extract image url from. * * @return string|null The extracted image url when found, null when not found. */ protected static function get_first_image( $images ) { if ( ! is_array( $images ) ) { return null; } $images = array_filter( $images ); if ( empty( $images ) ) { return null; } return reset( $images ); } }