Yoast\WP\SEO\Services\Importing\Aioseo
Aioseo_Social_Images_Provider_Service::get_first_attached_image
Retrieves the url of the first attached image.
Метод класса: Aioseo_Social_Images_Provider_Service{}
Хуков нет.
Возвращает
Строку. The url of the first attached image.
Использование
$Aioseo_Social_Images_Provider_Service = new Aioseo_Social_Images_Provider_Service(); $Aioseo_Social_Images_Provider_Service->get_first_attached_image( $post_id );
- $post_id(int) (обязательный)
- The post id to extract the image from.
Код Aioseo_Social_Images_Provider_Service::get_first_attached_image() Aioseo Social Images Provider Service::get first attached image Yoast 27.4
public function get_first_attached_image( $post_id ) {
if ( \get_post_type( $post_id ) === 'attachment' ) {
return $this->image->get_attachment_image_source( $post_id, 'fullsize' );
}
$attachments = \get_children(
[
'post_parent' => $post_id,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
],
);
if ( $attachments && ! empty( $attachments ) ) {
return $this->image->get_attachment_image_source( \array_values( $attachments )[0]->ID, 'fullsize' );
}
return '';
}