dmchale / disable-json-api

Public repo for the "Disable REST API" WordPress plugin, currently with 90,000+ active installs in the wordpress.org repository
10 stars 9 forks source link

If pretty permalinks is enabled and wp-admin lives in a directory, settings page can't get endpoints #2

Closed tangrufus closed 7 years ago

tangrufus commented 7 years ago

Example:

disable_rest_api_settings_ _wordpress_site_ _wordpress

When pretty permalinks is disabled, it works.

dmchale commented 7 years ago

All set! https://github.com/dmchale/disable-json-api/commit/f907172e83021f622b3007ef363bc5fa6c610cdc

This does open my eyes to the fact that I have additional testing to do for multisite, too. These functions won't work properly on multisite installs but I thought I'd patch this for now and circle back to those.

tangrufus commented 7 years ago

Try:

var restPath = '<?php echo rest_url(); ?>';

See:

tangrufus commented 7 years ago

Going further:

  1. Get routes by PHP:
    $wp_rest_server = rest_get_server();
    $routes = $wp_rest_server->get_routes();
  2. Pass routes to JS via wp_localize_script

This can save some jQuery ajax code.

Or, we don't need the JS part at all

dmchale commented 7 years ago

Converted admin page to php-based rather than JS-based: https://github.com/dmchale/disable-json-api/commit/6af19e4377efdc639ad53ee08dbdc3df15753f95