Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new @wordpress/api-request package #7018

Merged
merged 9 commits into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
'jest/globals': true,
},
globals: {
wpApiSchema: true,
wpApiSettings: true,
},
plugins: [
'jest',
Expand Down
4 changes: 2 additions & 2 deletions components/code-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function loadScript() {
}

const script = document.createElement( 'script' );
script.src = `${ wpApiSchema.url }/wp-admin/load-scripts.php?load=${ handles.join( ',' ) }`;
script.src = `${ wpApiSettings.schema.url }/wp-admin/load-scripts.php?load=${ handles.join( ',' ) }`;
script.onload = resolve;
script.onerror = reject;

Expand All @@ -35,7 +35,7 @@ function loadStyle() {

const style = document.createElement( 'link' );
style.rel = 'stylesheet';
style.href = `${ wpApiSchema.url }/wp-admin/load-styles.php?load=${ handles.join( ',' ) }`;
style.href = `${ wpApiSettings.schema.url }/wp-admin/load-styles.php?load=${ handles.join( ',' ) }`;
style.onload = resolve;
style.onerror = reject;

Expand Down
2 changes: 1 addition & 1 deletion editor/components/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class EditorProvider extends Component {
[
APIProvider,
{
schema: wpApiSchema,
...wpApiSettings,
...pick( wp.api, [
'postTypeRestBaseMapping',
'taxonomyRestBaseMapping',
Expand Down
7 changes: 6 additions & 1 deletion lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -789,12 +789,17 @@ function gutenberg_extend_wp_api_backbone_client() {
};
JS;
wp_add_inline_script( 'wp-api', $script );
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/v2/',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever use it? I think it might be useful, but I don't see any code occurrence inside Gutenberg.

Copy link
Contributor Author

@youknowriad youknowriad Jun 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This global is the reason the tests were failing, I just left it as is, it's being used by Core's wp-api

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey 👍

) );

// Localize the wp-api settings and schema.
$schema_response = rest_do_request( new WP_REST_Request( 'GET', '/' ) );
if ( ! $schema_response->is_error() ) {
wp_add_inline_script( 'wp-api', sprintf(
'wpApiSchema = %s;',
'wpApiSettings.cacheSchema = true; wpApiSettings.schema = %s;',
wp_json_encode( $schema_response->get_data() )
), 'before' );
}
Expand Down