RESTful Localized Scripts
WP REST API enhancement to return JSON arrays containing localized strings registered with WordPress' wp_localize_script() function
Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/shawnhooper/restful-localized-scripts/archive/refs/heads/master.zipWP REST API enhancement to return JSON arrays containing localized strings registered with WordPress' wp_localize_script() function
Description
WP REST API enhancement to return JSON arrays containing localized strings registered with WordPress' wp_localize_script() function
Usage
- Install & Activate Plugin
- Specify which localized scripts are allowed to be returned via the API using the allowed_restful_localized_scripts filter
- Go to endpoint
/wp-json/shawnhooper/v1/localized/to see all scripts - Go to endpoint
/wp-json/shawnhooper/v1/localized/<script_handle>to see a specific script.
Specifying Which Scripts Are Allowed
By default, no scripts are allowed to be returned by the API.
To specify specific scripts that are allowed to be returned via the API:
add_filter('allowed_restful_localized_scripts', function($allowed) {
array_push($allowed, 'my_script_name');
array_push($allowed, 'my_second_script_name');
return $allowed;
});
To allow all scripts to be returned via the API:
add_filter('allowed_restful_localized_scripts', '__return_true');
Changelog
1.0.1 (2022-05-31)
- Update build tool dependencies to fix CVE-2022-1537, CVE-2022-0436 and CVE-2020-7729
1.0
- First release.