WPSEO_Image_Utils::get_attachment_id_from_settings
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.
Метод класса: WPSEO_Image_Utils{}
Хуков нет.
Возвращает
int|true|false. The attachment id, or false or 0 if no ID is available.
Использование
$result = WPSEO_Image_Utils::get_attachment_id_from_settings( $setting );
- $setting(строка) (обязательный)
- The setting the image is stored in.
Код WPSEO_Image_Utils::get_attachment_id_from_settings() WPSEO Image Utils::get attachment id from settings Yoast 27.6
public static function get_attachment_id_from_settings( $setting ) {
$image_id = WPSEO_Options::get( $setting . '_id', false );
if ( $image_id ) {
return $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 );
}
// Only store a new ID if it is not 0, to prevent an update loop.
if ( $image_id ) {
WPSEO_Options::set( $setting . '_id', $image_id );
}
return $image_id;
}