WP_REST_Themes_Controller::prepare_links
Prepares links for the request.
Метод класса: WP_REST_Themes_Controller{}
Хуков нет.
Возвращает
Массив. Links for the given block type.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->prepare_links( $theme );
- $theme(WP_Theme) (обязательный)
- Theme data.
Список изменений
| С версии 5.7.0 | Введена. |
Код WP_REST_Themes_Controller::prepare_links() WP REST Themes Controller::prepare links WP 7.0
protected function prepare_links( $theme ) {
$links = array(
'self' => array(
'href' => rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $theme->get_stylesheet() ) ),
),
'collection' => array(
'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
),
);
if ( $this->is_same_theme( $theme, wp_get_theme() ) ) {
// This creates a record for the active theme if not existent.
$id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id();
} else {
$user_cpt = WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles( $theme );
$id = $user_cpt['ID'] ?? null;
}
if ( $id ) {
$links['https://api.w.org/user-global-styles'] = array(
'href' => rest_url( 'wp/v2/global-styles/' . $id ),
);
}
if ( $theme->is_block_theme() && $this->is_same_theme( $theme, wp_get_theme() ) ) {
$links['https://api.w.org/export-theme'] = array(
'href' => rest_url( 'wp-block-editor/v1/export' ),
'targetHints' => array(
'allow' => current_user_can( 'export' ) ? array( 'GET' ) : array(),
),
);
}
return $links;
}