[wp-trac] [WordPress Trac] #42807: Add filter to modfiy wp.api versionString
WordPress Trac
noreply at wordpress.org
Wed Dec 6 14:46:14 UTC 2017
#42807: Add filter to modfiy wp.api versionString
--------------------------+------------------------------
Reporter: mkaz | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by adamsilverstein):
@mkaz Thanks for your bug report.
I can see how a filter might be useful here to change the default for
initial load. In the meantime you should be able to overwrite this value
already, or connect the wp-api client to another root/namespace after the
initial connection.
To override the default, add this line right after you enqueue wp-api:
{{{
wp_localize_script( 'wp-api', 'wpApiSettings', array(
'root' => esc_url_raw( get_rest_url() ),
'nonce' => ( wp_installing() && !
is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ),
'versionString' => 'wp/v1/',
) );
}}}
if you look in the source code this will come after core's localization
and overwrite the values passed there.
Alternately, if the client is connecting fine at `wp/v2` and you '''want
to add an additional connection''' you can call init again:
`wp.api.init( { 'versionString': 'wp/v1/' } )` - this will connect you do
whatever versionString (or apiRoot if you provide that).
`init` returns a promise that resolves to the endpoint connection, which
will contain the models and collections from that endpoint
in addition, multiple endpoints that have been connected thru init are
stored in a collection: `wp.api.endpoints`
Does that help for your use case?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42807#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list