WP_REST_Template_Revisions_Controller::get_parent
Gets the parent post, if the template ID is valid.
Метод класса: WP_REST_Template_Revisions_Controller{}
Хуков нет.
Возвращает
WP_Post|WP_Error. Post object if ID is valid, WP_Error otherwise.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_parent( $parent_template_id );
- $parent_template_id(строка) (обязательный)
- Supplied ID.
Список изменений
| С версии 6.4.0 | Введена. |
Код WP_REST_Template_Revisions_Controller::get_parent() WP REST Template Revisions Controller::get parent WP 7.1.4
protected function get_parent( $parent_template_id ) {
$template = get_block_template( $parent_template_id, $this->parent_post_type );
if ( ! $template ) {
return new WP_Error(
'rest_post_invalid_parent',
__( 'Invalid template parent ID.' ),
array( 'status' => WP_Http::NOT_FOUND )
);
}
$parent_post_id = isset( $template->wp_id ) ? (int) $template->wp_id : 0;
if ( $parent_post_id <= 0 ) {
return new WP_Error(
'rest_invalid_template',
__( 'Templates based on theme files can\'t have revisions.' ),
array( 'status' => WP_Http::BAD_REQUEST )
);
}
return get_post( $template->wp_id );
}