Skip to content

Commit

Permalink
Adding checks back for AJAX functions which can be submitted sans AJA…
Browse files Browse the repository at this point in the history
…X, cont'd. Fixes #394
  • Loading branch information
JustinSainton committed May 6, 2013
1 parent 242685b commit 8087d74
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions wpsc-includes/ajax.functions.php
Expand Up @@ -106,21 +106,27 @@ function wpsc_add_to_cart() {
}
}

$json_response = array( 'cart_messages' => $cart_messages, 'product_id' => $product_id );
$output = _wpsc_ajax_get_cart( false, $cart_messages );
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
$json_response = array( 'cart_messages' => $cart_messages, 'product_id' => $product_id );
$output = _wpsc_ajax_get_cart( false, $cart_messages );

$json_response = $json_response + $output;
$json_response = $json_response + $output;

if ( is_numeric( $product_id ) && 1 == get_option( 'fancy_notifications' ) )
$json_response['fancy_notification'] = str_replace( array( "\n", "\r" ), array( '\n', '\r' ), fancy_notification_content( $cart_messages ) );
if ( is_numeric( $product_id ) && 1 == get_option( 'fancy_notifications' ) )
$json_response['fancy_notification'] = str_replace( array( "\n", "\r" ), array( '\n', '\r' ), fancy_notification_content( $cart_messages ) );

if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
die( json_encode( $json_response ) );
}
}

add_action( 'wp_ajax_add_to_cart' , 'wpsc_add_to_cart' );
add_action( 'wp_ajax_nopriv_add_to_cart', 'wpsc_add_to_cart' );

// execute on POST and GET
if ( isset( $_REQUEST['wpsc_ajax_action'] ) && 'add_to_cart' == $_REQUEST['wpsc_ajax_action'] ) {
add_action( 'init', 'wpsc_add_to_cart' );
}

function wpsc_get_cart() {
_wpsc_ajax_get_cart();
}
Expand Down Expand Up @@ -313,6 +319,7 @@ function wpsc_update_product_rating() {
add_action( 'init', 'wpsc_update_product_rating' );
}


/**
* update_shipping_price function, used through ajax and in normal page loading.
* No parameters, returns nothing
Expand Down Expand Up @@ -419,6 +426,11 @@ function wpsc_update_product_price() {
add_action( 'wp_ajax_update_product_price' , 'wpsc_update_product_price' );
add_action( 'wp_ajax_nopriv_update_product_price', 'wpsc_update_product_price' );

// execute on POST and GET
if ( isset( $_REQUEST['update_product_price'] ) && 'true' == $_REQUEST['update_product_price'] && ! empty( $_POST['product_id'] ) && is_numeric( $_POST['product_id'] ) ) {
add_action( 'init', 'wpsc_update_product_price' );
}

/**
* update location function, used through ajax and in normal page loading.
* No parameters, returns nothing
Expand Down Expand Up @@ -481,13 +493,14 @@ function wpsc_update_location() {
exit;
}

add_action( 'wp_ajax_update_location' , 'wpsc_update_location' );
add_action( 'wp_ajax_nopriv_update_location', 'wpsc_update_location' );

// execute on POST and GET
if ( isset( $_REQUEST['wpsc_ajax_actions'] ) && $_REQUEST['wpsc_ajax_actions'] == 'update_location' ) {
if ( isset( $_REQUEST['wpsc_ajax_actions'] ) && 'update_location' == $_REQUEST['wpsc_ajax_actions'] ) {
add_action( 'init', 'wpsc_update_location' );
}

add_action( 'wp_ajax_update_location' , 'wpsc_update_location' );
add_action( 'wp_ajax_nopriv_update_location', 'wpsc_update_location' );

function wpsc_cart_html_page() {
require_once(WPSC_FILE_PATH . "/wpsc-includes/shopping_cart_container.php");
Expand Down Expand Up @@ -830,6 +843,11 @@ function wpsc_change_tax() {
add_action( 'wp_ajax_change_tax' , 'wpsc_change_tax' );
add_action( 'wp_ajax_nopriv_change_tax', 'wpsc_change_tax' );

// execute on POST and GET
if ( isset( $_REQUEST['wpsc_ajax_action'] ) && 'change_tax' == $_REQUEST['wpsc_ajax_action'] ) {
add_action( 'init', 'wpsc_change_tax' );
}

function _wpsc_change_profile_country() {
global $wpdb;

Expand Down

0 comments on commit 8087d74

Please sign in to comment.