Title: WP_REST_Themes_Controller::prepare_links
Published: March 9, 2021
Last modified: February 24, 2026

---

# WP_REST_Themes_Controller::prepare_links( WP_Theme $theme ): array

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/prepare_links/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/prepare_links/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/prepare_links/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/prepare_links/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/prepare_links/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/prepare_links/?output_format=md#wp--skip-link--target)

Prepares links for the request.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/prepare_links/?output_format=md#parameters)󠁿

 `$theme`[WP_Theme](https://developer.wordpress.org/reference/classes/wp_theme/)
required

Theme data.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/prepare_links/?output_format=md#return)󠁿

 array Links for the given block type.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/prepare_links/?output_format=md#source)󠁿

    ```php
    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       = isset( $user_cpt['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;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php#L393)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php#L393-L427)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/prepare_links/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Theme_JSON_Resolver::get_user_global_styles_post_id()](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_user_global_styles_post_id/)`wp-includes/class-wp-theme-json-resolver.php` |

Returns the ID of the custom post type that stores user data.

  | 
| [WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles()](https://developer.wordpress.org/reference/classes/wp_theme_json_resolver/get_user_data_from_wp_global_styles/)`wp-includes/class-wp-theme-json-resolver.php` |

Returns the custom post type that contains the user’s origin config for the active theme or an empty array if none are found.

  | 
| [WP_REST_Themes_Controller::is_same_theme()](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/is_same_theme/)`wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php` |

Helper function to compare two themes.

  | 
| [rest_url()](https://developer.wordpress.org/reference/functions/rest_url/)`wp-includes/rest-api.php` |

Retrieves the URL to a REST endpoint.

  | 
| [current_user_can()](https://developer.wordpress.org/reference/functions/current_user_can/)`wp-includes/capabilities.php` |

Returns whether the current user has the specified capability.

  | 
| [wp_get_theme()](https://developer.wordpress.org/reference/functions/wp_get_theme/)`wp-includes/theme.php` |

Gets a [WP_Theme](https://developer.wordpress.org/reference/classes/wp_theme/) object for a theme.

  |

[Show 3 more](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/prepare_links/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/prepare_links/?output_format=md#)

| Used by | Description | 
| [WP_REST_Themes_Controller::prepare_item_for_response()](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/prepare_item_for_response/)`wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php` |

Prepares a single theme output for response.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/prepare_links/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.7.0](https://developer.wordpress.org/reference/since/5.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_themes_controller%2Fprepare_links%2F)
before being able to contribute a note or feedback.