[wp-trac] [WordPress Trac] #42807: Add filter to modfiy wp.api versionString
WordPress Trac
noreply at wordpress.org
Fri Dec 8 15:22:18 UTC 2017
#42807: Add filter to modfiy wp.api versionString
--------------------------+------------------------------
Reporter: mkaz | Owner: adamsilverstein
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version:
Severity: normal | Resolution:
Keywords: | Focuses: javascript
--------------------------+------------------------------
Comment (by adamsilverstein):
Replying to [comment:6 mkaz]:
> Thanks @adamsilverstein for the suggestions - I've tried modifying the
versionString in numerous other spots and it only seems to work within
Gutenberg when modified at the source so it is picked up on initial load.
>
@mkaz
Ah, didn’t catch you were trying this for Gutenberg. Starting to see how
this filter could be really useful, as long as we can ensure all uses of
the namespace in core get filtered.
Did you try calling the init with your namespace on the api before
gutenberg loads? this should add you data types to the wp.api
models/collections and maybe let them work in Gutemberg?
One other idea if that doesn't work and you *really* need to replace the
namespace used by Gutenberg:
If you can load after wp-api and before Gutenberg, you should be able to
overwrite the wp.api.init method with your own implementation that calls
the default implementation but sets the namespace to your own.
{{{
var originalInit = wp.api.init;
wp.api.init = function() { originalInit( { 'versionString': 'wp/v1/' } )
};
}}}
However looking at how Gutenberg is enqueueing wp-api, none of these
changes are possible - the namespace is hardcoded in a server side schema
call:
https://github.com/WordPress/gutenberg/blob/master/lib/client-
assets.php#L489-L499
the schema is then localized and passed to the client. You will need to
change this behavior to alter the namespace.
Maybe a good start would be a pull request for Gutenberg to add a filter
there?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42807#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list