Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#34707 closed enhancement (wontfix)

Separate out the namespace from the path in rest_url

Reported by: rmccue's profile rmccue Owned by: wonderboymusic's profile wonderboymusic
Milestone: Priority: normal
Severity: normal Version:
Component: REST API Keywords: dev-feedback
Focuses: Cc:

Description

From API#1504, discussed briefly in #34302; PR on https://github.com/WP-API/api-core/pull/4.

Everywhere else we deal with URLs, we specify namespace and route separately, except when generating URLs.

This changes to no longer match the format of get_home_url/get_site_url/get_admin_url (blog ID, path, scheme), however there are already a few that don't follow this format:

  • get_dashboard_url (user, path, scheme)
  • get_edit_profile_url (user, scheme)
  • get_site_icon_url (size, URL, blog).

This also breaks compatibility with existing versions of the API.

If we want to pull the trigger, we need to do it now.

Change History (7)

#1 @rmccue
10 years ago

  • Keywords dev-feedback added
  • Type changed from defect (bug) to enhancement

@danielbachhuber @rachelbaker @joehoyle I'm not sure I want to change this and break BC so late; what if we accept both a string (of namespace/route) and and array of namespace, route? Taking a string lets us keep BC and is relatively concise, array-form means you don't have to build it yourself. Win-win?

#2 @danielbachhuber
10 years ago

Aside from consistency, are there any pragmatic advantages to separating the namespace and path in get_rest_url()? I can't think of any.

Everywhere else we deal with URLs, we specify namespace and route separately, except when generating URLs.

I think this is fine. Elsewhere, specifying the namespace and route separately has a pragmatic application. Given get_rest_url() is largely just a wrapper for home_url(), I don't see the inconsistency as an issue needing to be fixed.

#3 @rachelbaker
10 years ago

@rmccue @danielbachhuber I believe the overall issue here is the confusion developers experience with the inconsistencies between register_rest_route() and get_rest_url().

I am too close to the code to understand if accepting an array and a string would reduce any confusion. I am okay with wontfixing this because of the BC breakage and unclear path forward.

#4 @rmccue
10 years ago

The main use case I can think of is in controllers, you may have the namespace and route separate already, so to generate URLs, you'd need to build the string yourself. I don't think that's a huge issue.

If we did allow an array, we'd have something like...

register_rest_route( $this->namespace, $this->route, array( /* ... */ ) );

// Current style
$url = get_rest_url( $this->namespace . '/' . $this->route );

// New style
$url = get_rest_url( array( $this->namespace, $this->route ) );

@wonderboymusic I think it was you that originally suggested splitting the args here. Was there a particular reason for that?

#5 @rachelbaker
10 years ago

@rmccue Here are @wonderboymusic's comments that sparked this fire: https://wordpress.slack.com/archives/core-restapi/p1439328572003434

#6 @danielbachhuber
10 years ago

  • Milestone changed from Awaiting Review to 4.4
  • Owner set to wonderboymusic
  • Status changed from new to assigned

Final determination to @wonderboymusic

#7 @wonderboymusic
10 years ago

  • Milestone 4.4 deleted
  • Resolution set to wontfix
  • Status changed from assigned to closed

I no longer have the passion for this change

Note: See TracTickets for help on using tickets.