WP Manifestindependent plugin directory
manifest / integrations / restful-localized-scripts

RESTful Localized Scripts

WP REST API enhancement to return JSON arrays containing localized strings registered with WordPress' wp_localize_script() function

★ 3stars

Install

Download source zip No release zip yet

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.zip
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

WP 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

  1. Install & Activate Plugin
  2. Specify which localized scripts are allowed to be returned via the API using the allowed_restful_localized_scripts filter
  3. Go to endpoint /wp-json/shawnhooper/v1/localized/ to see all scripts
  4. 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.