Title: WP_REST_Block_Directory_Controller::prepare_links
Published: August 11, 2020
Last modified: February 24, 2026

---

# WP_REST_Block_Directory_Controller::prepare_links( array $plugin ): array

## In this article

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

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

Generates a list of links to include in the response for the plugin.

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

 `$plugin`arrayrequired

The plugin data from WordPress.org.

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

 array

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

    ```php
    protected function prepare_links( $plugin ) {
    	$links = array(
    		'https://api.w.org/install-plugin' => array(
    			'href' => add_query_arg( 'slug', urlencode( $plugin['slug'] ), rest_url( 'wp/v2/plugins' ) ),
    		),
    	);

    	$plugin_file = $this->find_plugin_for_slug( $plugin['slug'] );

    	if ( $plugin_file ) {
    		$links['https://api.w.org/plugin'] = array(
    			'href'       => rest_url( 'wp/v2/plugins/' . substr( $plugin_file, 0, - 4 ) ),
    			'embeddable' => true,
    		);
    	}

    	return $links;
    }
    ```

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

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

| Uses | Description | 
| [WP_REST_Block_Directory_Controller::find_plugin_for_slug()](https://developer.wordpress.org/reference/classes/wp_rest_block_directory_controller/find_plugin_for_slug/)`wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php` |

Finds an installed plugin for the given slug.

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

Retrieves the URL to a REST endpoint.

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

Retrieves a modified URL query string.

  |

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

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

Parse block metadata for a block, and prepare it for an API response.

  |

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

| Version | Description | 
| [5.5.0](https://developer.wordpress.org/reference/since/5.5.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_block_directory_controller%2Fprepare_links%2F)
before being able to contribute a note or feedback.