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

json_register_scripts - wpApiOptions.nonce is now WP_API_Settings.nonce #321

Merged
merged 1 commit into from Jun 30, 2014

Conversation

Projects
None yet
4 participants
@rachelbaker
Member

rachelbaker commented Jun 24, 2014

json_register_scripts used wp_localize_script to output the nonce.
The original name was wpApiOptions now it is WP_API_Settings.

--old--
wp_localize_script( 'wp-api', 'wpApiOptions', array( 'base' => json_url(), 'nonce' => wp_create_nonce( 'wp_json' ) ) );

--new--
$settings = array( 'root' => esc_url_raw( get_json_url() ), 'nonce' => wp_create_nonce( 'wp_json' ) );
wp_localize_script( 'wp-api', 'WP_API_Settings', $settings );

@rmccue

This comment has been minimized.

Show comment
Hide comment
@rmccue

rmccue Jun 19, 2014

Member

@tlovett1 Can we check both in the JS, and use the old name?

Member

rmccue commented Jun 19, 2014

@tlovett1 Can we check both in the JS, and use the old name?

@tlovett1

This comment has been minimized.

Show comment
Hide comment
@tlovett1

tlovett1 Jun 20, 2014

Member

So check if either variable exist and use wpApiOptions? Why not just use WP_API_Settings?

Member

tlovett1 commented Jun 20, 2014

So check if either variable exist and use wpApiOptions? Why not just use WP_API_Settings?

@rmccue

This comment has been minimized.

Show comment
Hide comment
@rmccue

rmccue Jun 20, 2014

Member

So check if either variable exist and use wpApiOptions? Why not just use WP_API_Settings?

Use whichever is set in JS, but wpApiOptions in wp_localize_script. We need to switch this back for backwards compatibility with existing scripts, but given that we've now released new code based on this, we may need to add both. :/

Member

rmccue commented Jun 20, 2014

So check if either variable exist and use wpApiOptions? Why not just use WP_API_Settings?

Use whichever is set in JS, but wpApiOptions in wp_localize_script. We need to switch this back for backwards compatibility with existing scripts, but given that we've now released new code based on this, we may need to add both. :/

@tlovett1

This comment has been minimized.

Show comment
Hide comment
@tlovett1

tlovett1 Jun 20, 2014

Member

wpApiOptions was changed to WP_API_Settings when we created the client-js repo. All versions that use wpApiOptions should be old enough that they have their own JS file and do not reference the Github Pages JS. Am I missing something?

Member

tlovett1 commented Jun 20, 2014

wpApiOptions was changed to WP_API_Settings when we created the client-js repo. All versions that use wpApiOptions should be old enough that they have their own JS file and do not reference the Github Pages JS. Am I missing something?

@NowellVanHoesen

This comment has been minimized.

Show comment
Hide comment
@NowellVanHoesen

NowellVanHoesen Jun 20, 2014

Thanks for this plugin and your time building and supporting its users.

I am using this plugin to add backbone driven pages that manipulate an external database.

When the nonce became required I found a way to add X_WP_NONCE to the request headers for cookie auth. After the last update I would get empty results and the error - Uncaught ReferenceError: wpApiOptions is not defined.

I didn't find anything here or in the change log about the change so I posted here.

NowellVanHoesen commented Jun 20, 2014

Thanks for this plugin and your time building and supporting its users.

I am using this plugin to add backbone driven pages that manipulate an external database.

When the nonce became required I found a way to add X_WP_NONCE to the request headers for cookie auth. After the last update I would get empty results and the error - Uncaught ReferenceError: wpApiOptions is not defined.

I didn't find anything here or in the change log about the change so I posted here.

@tlovett1

This comment has been minimized.

Show comment
Hide comment
@tlovett1

tlovett1 Jun 20, 2014

Member

I see. We have our own Backbone driven implementation that interacts with the API that sets the X-WP-NONCE on every request. @rmccue we can support the old variable for back compat, or @NowellVanHoesen can just start using the new localized variable.

Member

tlovett1 commented Jun 20, 2014

I see. We have our own Backbone driven implementation that interacts with the API that sets the X-WP-NONCE on every request. @rmccue we can support the old variable for back compat, or @NowellVanHoesen can just start using the new localized variable.

@NowellVanHoesen

This comment has been minimized.

Show comment
Hide comment
@NowellVanHoesen

NowellVanHoesen Jun 20, 2014

I have already changed my code to use WP_API_Settings.

$(document).ajaxSend( function ( event, XMLHttpRequest, ajaxOptions ) {
XMLHttpRequest.setRequestHeader( 'X_WP_NONCE', WP_API_Settings.nonce );
});

The docs for Cookie based auth could use updating though: https://github.com/WP-API/WP-API/blob/master/docs/authentication.md#cookie-authentication

NowellVanHoesen commented Jun 20, 2014

I have already changed my code to use WP_API_Settings.

$(document).ajaxSend( function ( event, XMLHttpRequest, ajaxOptions ) {
XMLHttpRequest.setRequestHeader( 'X_WP_NONCE', WP_API_Settings.nonce );
});

The docs for Cookie based auth could use updating though: https://github.com/WP-API/WP-API/blob/master/docs/authentication.md#cookie-authentication

@rmccue

This comment has been minimized.

Show comment
Hide comment
@rmccue

rmccue Jun 23, 2014

Member

Cool, let's just update the docs then.

Member

rmccue commented Jun 23, 2014

Cool, let's just update the docs then.

@rachelbaker

This comment has been minimized.

Show comment
Hide comment
@rachelbaker

rachelbaker Jun 24, 2014

Member

@rmccue #reviewmerge

Member

rachelbaker commented Jun 24, 2014

@rmccue #reviewmerge

@rachelbaker rachelbaker added Review and removed Bug labels Jun 24, 2014

@rmccue rmccue added this to the 1.2 milestone Jun 30, 2014

@rmccue rmccue self-assigned this Jun 30, 2014

rmccue added a commit that referenced this pull request Jun 30, 2014

Merge pull request #321 from WP-API/cookie-docs-fix
json_register_scripts - wpApiOptions.nonce is now WP_API_Settings.nonce

@rmccue rmccue merged commit 1598c86 into master Jun 30, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details

@rmccue rmccue deleted the cookie-docs-fix branch Jun 30, 2014

@rmccue

This comment has been minimized.

Show comment
Hide comment
@rmccue

rmccue Jun 30, 2014

Member

Sorry for missing this one earlier!

Member

rmccue commented Jun 30, 2014

Sorry for missing this one earlier!

kellbot pushed a commit to kellbot/WP-API that referenced this pull request Aug 1, 2014

Merge pull request #321 from WP-API/cookie-docs-fix
json_register_scripts - wpApiOptions.nonce is now WP_API_Settings.nonce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment