WPSEO_Import_AIOSEO_V4::get_unique_custom_fields_or_taxonomies
Filters out all unique custom fields/taxonomies/etc. used in an AiOSEO replace var.
Метод класса: WPSEO_Import_AIOSEO_V4{}
Хуков нет.
Возвращает
Строку[]. An array of all the unique custom fields/taxonomies/etc. used in the replace vars. E.g. xyz in the above example.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_unique_custom_fields_or_taxonomies( $meta_values, $aioseo_prefix );
- $meta_values(string[]) (обязательный)
- An array of all the meta values that contain one or more AIOSEO custom field replace vars (in the form
#custom_field-xyz). - $aioseo_prefix(строка) (обязательный)
- The AiOSEO prefix to use (e.g.
custom-fieldfor custom fields ortax_namefor custom taxonomies).
Код WPSEO_Import_AIOSEO_V4::get_unique_custom_fields_or_taxonomies() WPSEO Import AIOSEO V4::get unique custom fields or taxonomies Yoast 26.9
protected function get_unique_custom_fields_or_taxonomies( $meta_values, $aioseo_prefix ) {
$unique_custom_fields_or_taxonomies = [];
foreach ( $meta_values as $meta_value ) {
// Find all custom field replace vars, store them in `$matches`.
preg_match_all(
"/#$aioseo_prefix-([\w-]+)/",
$meta_value,
$matches
);
/*
* `$matches[1]` contain the captured matches of the
* first capturing group (the `([\w-]+)` in the regex above).
*/
$custom_fields_or_taxonomies = $matches[1];
foreach ( $custom_fields_or_taxonomies as $custom_field_or_taxonomy ) {
$unique_custom_fields_or_taxonomies[ trim( $custom_field_or_taxonomy ) ] = 1;
}
}
return array_keys( $unique_custom_fields_or_taxonomies );
}