Skip to content

Commit

Permalink
Merge pull request #3822 from impress-org/issue/3819
Browse files Browse the repository at this point in the history
fix: give session cookie prefix #3819
  • Loading branch information
ravinderk committed Nov 2, 2018
2 parents 7836ac3 + 934fcc1 commit 53c3554
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions assets/src/js/frontend/give-ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jQuery( document ).ready( function( $ ) {
// Reset nonce only if form exists.
if( Give.form.fn.isFormExist() ) {
// Reset nonce if session start. It will prevent nonce failed issue for cached pages.
const resetNonce = '1' === Give.fn.__getCookie( 'wp_give_session_reset_nonce_' + Give.fn.getGlobalVar('cookie_hash') ) && '1' !== Give.fn.getGlobalVar('delete_session_nonce_cookie');
const resetNonce = '1' === Give.fn.__getCookie( Give.fn.getGlobalVar( 'session_nonce_cookie_name' ) ) && '1' !== Give.fn.getGlobalVar( 'delete_session_nonce_cookie' );

//Hide loading elements
$( '.give-loading-text' ).hide();
Expand Down Expand Up @@ -275,10 +275,10 @@ jQuery( document ).ready( function( $ ) {
},
payment_key = Give.fn.getParameterByName('payment_key');

const cookie_name = 'wp_give_session_reset_nonce_' + Give.fn.getGlobalVar('cookie_hash');
const cookie_name = Give.fn.getGlobalVar( 'session_nonce_cookie_name' );

// Set cookie.
data[cookie_name] = Give.fn.__getCookie( 'wp_give_session_' + Give.fn.getGlobalVar('cookie_hash') );
data[cookie_name] = Give.fn.__getCookie( Give.fn.getGlobalVar( 'session_cookie_name' ) );

// Set payment key.
if( null !== payment_key ) {
Expand Down
4 changes: 3 additions & 1 deletion includes/class-give-scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ public function public_localize_scripts() {
'number_decimals' => give_get_price_decimals(),
) ),
'cookie_hash' => COOKIEHASH,
'delete_session_nonce_cookie' => absint( Give()->session->is_delete_nonce_cookie() )
'session_nonce_cookie_name' => Give()->session->get_cookie_name( 'nonce' ),
'session_cookie_name' => Give()->session->get_cookie_name( 'session' ),
'delete_session_nonce_cookie' => absint( Give()->session->is_delete_nonce_cookie() ),
) );

wp_localize_script( 'give', 'give_global_vars', $localize_give_vars );
Expand Down
16 changes: 8 additions & 8 deletions includes/class-give-session.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private function __handle_ajax_cookie(){
$cookie = false;

// @see https://github.com/WordImpress/Give/issues/3705
if(
if (
empty( $cookie_value )
&& wp_doing_ajax()
&& isset( $_GET['action'] )
Expand Down Expand Up @@ -290,7 +290,7 @@ public function has_session() {
* @since 2.2.0
* @access private
*
* @return string Cookie name.
* @return void
*/
private function set_cookie_name() {
/**
Expand All @@ -303,14 +303,14 @@ private function set_cookie_name() {
*/
$this->cookie_name = apply_filters(
'give_session_cookie',
'wp_give_session_' . COOKIEHASH, // Cookie name.
'wp-give_session_' . COOKIEHASH, // Cookie name.
'session' // Cookie type.
);

$this->nonce_cookie_name = apply_filters(
'give_session_cookie',
'wp_give_session_reset_nonce_' . COOKIEHASH, // Cookie name.
'nonce' // Cookie type
'wp-give_session_reset_nonce_' . COOKIEHASH, // Cookie name.
'nonce' // Cookie type.
);
}

Expand All @@ -322,8 +322,8 @@ private function set_cookie_name() {
* @since 1.0
* @access public
*
* @param string $key Session key.
* @param mixed $default default value.
* @param string $key Session key.
* @param mixed $default default value.
*
* @return string|array Session variable.
*/
Expand Down Expand Up @@ -575,7 +575,7 @@ public function __cleanup_sessions() { // @codingStandardsIgnoreLine
* @return string Session ID.
*/
public function get_id() {
return $this->get_cookie_name('session');
return $this->get_cookie_name( 'session' );
}

/**
Expand Down

0 comments on commit 53c3554

Please sign in to comment.