Yoast\WP\SEO\Images\Application
Image_Content_Extractor::extract_id_of_classes()
Extracts image ID out of the image's classes.
Метод класса: Image_Content_Extractor{}
Хуки из метода
Возвращает
int
. The ID that's extracted from the classes.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->extract_id_of_classes( $classes );
- $classes(строка) (обязательный)
- The classes assigned to the image.
Код Image_Content_Extractor::extract_id_of_classes() Image Content Extractor::extract id of classes Yoast 24.0
protected function extract_id_of_classes( $classes ) { if ( ! $classes ) { return 0; } /** * Filter 'wpseo_extract_id_pattern' - Allows filtering the regex patern to be used to extract image IDs from class/attribute names. * * Defaults to the pattern that extracts image IDs from core's `wp-image-<ID>` native format in image classes. * * @api string The regex pattern to be used to extract image IDs from class names. Empty string if the whole class/attribute should be returned. */ $pattern = \apply_filters( 'wpseo_extract_id_pattern', '/(?<!\S)wp-image-(\d+)(?!\S)/i' ); if ( $pattern === '' ) { return (int) $classes; } $matches = []; if ( \preg_match( $pattern, $classes, $matches ) ) { return (int) $matches[1]; } return 0; }