WP_REST_Server::add_active_theme_link_to_index
Adds a link to the active theme for users who have proper permissions.
Метод класса: WP_REST_Server{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->add_active_theme_link_to_index( $response );
- $response(WP_REST_Response) (обязательный)
- REST API response.
Список изменений
| С версии 5.7.0 | Введена. |
Код WP_REST_Server::add_active_theme_link_to_index() WP REST Server::add active theme link to index WP 6.9.1
protected function add_active_theme_link_to_index( WP_REST_Response $response ) {
$should_add = current_user_can( 'switch_themes' ) || current_user_can( 'manage_network_themes' );
if ( ! $should_add && current_user_can( 'edit_posts' ) ) {
$should_add = true;
}
if ( ! $should_add ) {
foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) {
if ( current_user_can( $post_type->cap->edit_posts ) ) {
$should_add = true;
break;
}
}
}
if ( $should_add ) {
$theme = wp_get_theme();
$response->add_link( 'https://api.w.org/active-theme', rest_url( 'wp/v2/themes/' . $theme->get_stylesheet() ) );
}
}