The rest_add_application_passwords_to_index() WordPress PHP function adds Application Passwords info to the REST API index.
Usage
rest_add_application_passwords_to_index( $response );
Parameters
$response
(WP_REST_Response) – The index response object.
More information
See WordPress Developer Resources: rest_add_application_passwords_to_index
Examples
Add Application Passwords info to REST API index
This example shows how to use the rest_add_application_passwords_to_index() function to add Application Passwords info to the REST API index.
// Add a filter to modify the REST API index add_filter( 'rest_index', 'add_application_passwords_info_to_index' ); function add_application_passwords_info_to_index( $response ) { // Use rest_add_application_passwords_to_index() to add the info return rest_add_application_passwords_to_index( $response ); }
Remove Application Passwords info from REST API index
This example shows how to use the remove_filter() function to remove the Application Passwords info from the REST API index.
// Remove the filter that adds Application Passwords info to the index remove_filter( 'rest_index', 'rest_add_application_passwords_to_index' );
Check if Application Passwords info is added to REST API index
This example shows how to use the has_filter() function to check if the Application Passwords info is added to the REST API index.
// Check if the filter is applied if ( has_filter( 'rest_index', 'rest_add_application_passwords_to_index' ) ) { echo 'Application Passwords info is added to the REST API index.'; } else { echo 'Application Passwords info is NOT added to the REST API index.'; }
Customize Application Passwords info in REST API index
This example shows how to use the apply_filters() function to customize the Application Passwords info added to the REST API index.
add_filter( 'rest_index', 'customize_application_passwords_info_in_index', 10, 1 ); function customize_application_passwords_info_in_index( $response ) { // Customize the info $app_passwords_info = apply_filters( 'app_passwords_info', array( 'enabled' => true, 'custom_info' => 'My Custom Info', ) ); // Add the customized info to the index $response->data['app_passwords'] = $app_passwords_info; return $response; }
Retrieve Application Passwords info from REST API index
This example shows how to use the rest_do_request() function to retrieve the Application Passwords info from the REST API index.
// Create a new REST request $request = new WP_REST_Request( 'GET', '/' ); // Execute the request $response = rest_do_request( $request ); // Get the Application Passwords info $app_passwords_info = $response->get_data()['app_passwords']; // Display the info echo 'Application Passwords info: ' . print_r( $app_passwords_info, true );