WordPress.org

Make WordPress Core

Opened 5 months ago

Closed 5 months ago

#50241 closed defect (bug) (wontfix)

Cannot publish the post using Gutenberg after changing REST URL prefix

Reported by: ibachal Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.5
Component: REST API Keywords: has-screenshots reporter-feedback close
Focuses: administration, rest-api Cc:

Description

When I change REST URL prefix to something different "my-api" for example, using "rest_url_prefix" filter hook then it breaks the Gutenberg post save functionality because Gutenberg uses default "wp-json" REST URL prefix for API interactions.

Possible solution: Use "rest_get_url_prefix()" function to get URL prefix instead of "wp-json".

Attachments (2)

Screenshot 2020-05-25 at 12.43.45 PM.png (362.9 KB) - added by ibachal 5 months ago.
Screen Shot 2020-05-25 at 1.11.17 PM.png (171.2 KB) - added by TimothyBlynJacobs 5 months ago.

Download all attachments as: .zip

Change History (7)

#1 @TimothyBlynJacobs
5 months ago

  • Keywords reporter-feedback added

Hi @ibachal,

Could you share the code you are using to change the REST URL prefix? Gutenberg uses the createRootURLMiddleware to set the base URL of the REST API. The only hardcoded usages of wp-json I see in the repo are docs or test code.

#2 @ibachal
5 months ago

Hi @TimothyBlynJacobs

Thank you for looking into this. I am using the following code to change the REST URL prefix:

add_filter( 'rest_url_prefix', 'custom_rest_url_prefix' );
function custom_rest_url_prefix( $prefix ) {
 return 'api';
}

It changes default "wp-json" prefix to "api"

#3 @TimothyBlynJacobs
5 months ago

  • Keywords close added

Where are you putting that code? Is it in any kind of conditional somewhere? I'm unable to replicate using that code.

#4 @ibachal
5 months ago

I am using this code in theme's functions.php file. I just retested and getting the same error.

#5 @TimothyBlynJacobs
5 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

I am using this code in theme's functions.php file.

Ah, I think that would be the issue, that is too late in the setup process. Try creating a site specific plugin or using the Snippets plugin and including your same code there.

Note: See TracTickets for help on using tickets.