WP_REST_Templates_Controller::_sanitize_template_id()
Requesting this endpoint for a template like 'twentytwentytwo//home' requires using a path like /wp/v2/templates/twentytwentytwo//home. There are special cases when WordPress routing corrects the name to contain only a single slash like 'twentytwentytwo/home'.
This method doubles the last slash if it's not already doubled. It relies on the template ID format {theme_name}//{template_slug} and the fact that slugs cannot contain slashes.
Метод класса: WP_REST_Templates_Controller{}
Хуков нет.
Возвращает
Строку
. Sanitized template ID.
Использование
$WP_REST_Templates_Controller = new WP_REST_Templates_Controller(); $WP_REST_Templates_Controller->_sanitize_template_id( $id );
- $id(строка) (обязательный)
- Template ID.
Заметки
Список изменений
С версии 5.9.0 | Введена. |
Код WP_REST_Templates_Controller::_sanitize_template_id() WP REST Templates Controller:: sanitize template id WP 6.2.2
public function _sanitize_template_id( $id ) { $id = urldecode( $id ); $last_slash_pos = strrpos( $id, '/' ); if ( false === $last_slash_pos ) { return $id; } $is_double_slashed = substr( $id, $last_slash_pos - 1, 1 ) === '/'; if ( $is_double_slashed ) { return $id; } return ( substr( $id, 0, $last_slash_pos ) . '/' . substr( $id, $last_slash_pos ) ); }