From 88a7f0f72097dff1c902a3a96748d95fb0698815 Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Wed, 5 Jun 2013 15:43:24 +0200 Subject: [PATCH] Abstracted nonce helper to class #3282 --- classes/class-wc-cart.php | 2 +- classes/class-wc-order.php | 2 +- classes/helpers/class-wc-nonce-helper.php | 31 ++++++++++ templates/cart/cart.php | 2 +- templates/cart/shipping-calculator.php | 2 +- templates/checkout/form-pay.php | 2 +- templates/checkout/review-order.php | 2 +- templates/myaccount/form-change-password.php | 2 +- templates/myaccount/form-edit-address.php | 2 +- templates/myaccount/form-login.php | 4 +- templates/myaccount/form-lost-password.php | 2 +- templates/order/form-tracking.php | 2 +- templates/order/order-details.php | 2 +- templates/shop/form-login.php | 2 +- templates/single-product-reviews.php | 2 +- woocommerce.php | 60 ++++++++++---------- 16 files changed, 77 insertions(+), 44 deletions(-) create mode 100644 classes/helpers/class-wc-nonce-helper.php diff --git a/classes/class-wc-cart.php b/classes/class-wc-cart.php index de3857a254e..a581113edad 100644 --- a/classes/class-wc-cart.php +++ b/classes/class-wc-cart.php @@ -682,7 +682,7 @@ class WC_Cart { global $woocommerce; $cart_page_id = woocommerce_get_page_id('cart'); if ($cart_page_id) - return apply_filters( 'woocommerce_get_remove_url', $woocommerce->nonce_url( 'cart', add_query_arg( 'remove_item', $cart_item_key, get_permalink($cart_page_id) ) ) ); + return apply_filters( 'woocommerce_get_remove_url', $woocommerce->get_helper( 'nonce' )->nonce_url( 'cart', add_query_arg( 'remove_item', $cart_item_key, get_permalink($cart_page_id) ) ) ); } /** diff --git a/classes/class-wc-order.php b/classes/class-wc-order.php index 6c0fca74212..23e04ad7654 100644 --- a/classes/class-wc-order.php +++ b/classes/class-wc-order.php @@ -1147,7 +1147,7 @@ class WC_Order { */ public function get_cancel_order_url() { global $woocommerce; - return apply_filters('woocommerce_get_cancel_order_url', $woocommerce->nonce_url( 'cancel_order', add_query_arg('cancel_order', 'true', add_query_arg('order', $this->order_key, add_query_arg('order_id', $this->id, trailingslashit( home_url() )))))); + return apply_filters('woocommerce_get_cancel_order_url', $woocommerce->get_helper( 'nonce' )->nonce_url( 'cancel_order', add_query_arg('cancel_order', 'true', add_query_arg('order', $this->order_key, add_query_arg('order_id', $this->id, trailingslashit( home_url() )))))); } diff --git a/classes/helpers/class-wc-nonce-helper.php b/classes/helpers/class-wc-nonce-helper.php new file mode 100644 index 00000000000..6ee2a0ccc72 --- /dev/null +++ b/classes/helpers/class-wc-nonce-helper.php @@ -0,0 +1,31 @@ +show_messages(); - nonce_field('cart') ?> + get_helper( 'nonce' )->nonce_field('cart') ?> diff --git a/templates/cart/shipping-calculator.php b/templates/cart/shipping-calculator.php index 759e7b55d62..4421a3977f8 100644 --- a/templates/cart/shipping-calculator.php +++ b/templates/cart/shipping-calculator.php @@ -84,7 +84,7 @@ if ( get_option('woocommerce_enable_shipping_calc')=='no' || ! $woocommerce->car

- nonce_field('cart') ?> + get_helper( 'nonce' )->nonce_field('cart') ?> diff --git a/templates/checkout/form-pay.php b/templates/checkout/form-pay.php index ebe8762ef26..ca97c65383e 100644 --- a/templates/checkout/form-pay.php +++ b/templates/checkout/form-pay.php @@ -83,7 +83,7 @@ global $woocommerce;
- nonce_field('pay')?> + get_helper( 'nonce' )->nonce_field('pay')?>
diff --git a/templates/checkout/review-order.php b/templates/checkout/review-order.php index b36a6281a40..d57f54ad473 100644 --- a/templates/checkout/review-order.php +++ b/templates/checkout/review-order.php @@ -184,7 +184,7 @@ $available_methods = $woocommerce->shipping->get_available_shipping_methods(); - nonce_field('process_checkout')?> + get_helper( 'nonce' )->nonce_field('process_checkout')?> diff --git a/templates/myaccount/form-change-password.php b/templates/myaccount/form-change-password.php index 0d775930322..9869be9d412 100644 --- a/templates/myaccount/form-change-password.php +++ b/templates/myaccount/form-change-password.php @@ -28,7 +28,7 @@ global $woocommerce;

- nonce_field('change_password')?> + get_helper( 'nonce' )->nonce_field('change_password')?> \ No newline at end of file diff --git a/templates/myaccount/form-edit-address.php b/templates/myaccount/form-edit-address.php index bfc438cd1e7..43b50d6cce7 100644 --- a/templates/myaccount/form-edit-address.php +++ b/templates/myaccount/form-edit-address.php @@ -41,7 +41,7 @@ get_currentuserinfo();

- nonce_field('edit_address') ?> + get_helper( 'nonce' )->nonce_field('edit_address') ?>

diff --git a/templates/myaccount/form-login.php b/templates/myaccount/form-login.php index 838dffd5606..6b5b67b06ea 100644 --- a/templates/myaccount/form-login.php +++ b/templates/myaccount/form-login.php @@ -36,7 +36,7 @@ global $woocommerce; ?>

- nonce_field('login', 'login') ?> + get_helper( 'nonce' )->nonce_field('login', 'login') ?> - nonce_field('register', 'register') ?> + get_helper( 'nonce' )->nonce_field('register', 'register') ?>

diff --git a/templates/myaccount/form-lost-password.php b/templates/myaccount/form-lost-password.php index 567784502d0..39f769e741f 100644 --- a/templates/myaccount/form-lost-password.php +++ b/templates/myaccount/form-lost-password.php @@ -43,6 +43,6 @@ global $woocommerce, $post;

- nonce_field( $args['form'] ); ?> + get_helper( 'nonce' )->nonce_field( $args['form'] ); ?> \ No newline at end of file diff --git a/templates/order/form-tracking.php b/templates/order/form-tracking.php index 39a884fbe0b..19cd7e493c6 100644 --- a/templates/order/form-tracking.php +++ b/templates/order/form-tracking.php @@ -21,6 +21,6 @@ global $woocommerce, $post;

- nonce_field('order_tracking') ?> + get_helper( 'nonce' )->nonce_field('order_tracking') ?> \ No newline at end of file diff --git a/templates/order/order-details.php b/templates/order/order-details.php index 7c64a70d43c..199e354b69b 100755 --- a/templates/order/order-details.php +++ b/templates/order/order-details.php @@ -87,7 +87,7 @@ $order = new WC_Order( $order_id ); status=='completed' ) : ?>

- +

diff --git a/templates/shop/form-login.php b/templates/shop/form-login.php index 1d377331978..064238ade1f 100644 --- a/templates/shop/form-login.php +++ b/templates/shop/form-login.php @@ -27,7 +27,7 @@ if (is_user_logged_in()) return;

- nonce_field('login', 'login') ?> + get_helper( 'nonce' )->nonce_field('login', 'login') ?> diff --git a/templates/single-product-reviews.php b/templates/single-product-reviews.php index 36c103e1e00..f0711bee253 100644 --- a/templates/single-product-reviews.php +++ b/templates/single-product-reviews.php @@ -104,7 +104,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly } - $comment_form['comment_field'] .= '

' . $woocommerce->nonce_field('comment_rating', true, false); + $comment_form['comment_field'] .= '

' . $woocommerce->get_helper( 'nonce' )->nonce_field('comment_rating', true, false); comment_form( apply_filters( 'woocommerce_product_review_comment_form_args', $comment_form ) ); diff --git a/woocommerce.php b/woocommerce.php index 31a5d7a6a3c..47fd3f63e40 100644 --- a/woocommerce.php +++ b/woocommerce.php @@ -1342,35 +1342,6 @@ class Woocommerce { if ( isset( $types[$type] ) ) return $types[$type]; } - /** Nonces ****************************************************************/ - - /** - * Return a nonce field. - * - * @access public - * @param mixed $action - * @param bool $referer (default: true) - * @param bool $echo (default: true) - * @return void - */ - public function nonce_field( $action, $referer = true , $echo = true ) { - return wp_nonce_field('woocommerce-' . $action, '_n', $referer, $echo ); - } - - - /** - * Return a url with a nonce appended. - * - * @access public - * @param mixed $action - * @param string $url (default: '') - * @return string - */ - public function nonce_url( $action, $url = '' ) { - return add_query_arg( '_n', wp_create_nonce( 'woocommerce-' . $action ), $url ); - } - - /** * Check a nonce and sets woocommerce error in case it is invalid. * @@ -1568,6 +1539,37 @@ class Woocommerce { $helper = $this->get_helper( 'inline-javascript' ); $helper->output_inline_js(); } + + /** + * Return a nonce field. + * + * @deprecated 2.1.0 Access via the helpers + * @access public + * @param mixed $action + * @param bool $referer (default: true) + * @param bool $echo (default: true) + * @return void + */ + public function nonce_field( $action, $referer = true , $echo = true ) { + _deprecated_function( 'Woocommerce->nonce_field', '2.1', 'WC_Nonce_Helper->nonce_field' ); + $helper = $this->get_helper( 'nonce' ); + return $helper->nonce_field( $action, $referer = true , $echo = true ); + } + + /** + * Return a url with a nonce appended. + * + * @deprecated 2.1.0 Access via the helpers + * @access public + * @param mixed $action + * @param string $url (default: '') + * @return string + */ + public function nonce_url( $action, $url = '' ) { + _deprecated_function( 'Woocommerce->nonce_url', '2.1', 'WC_Nonce_Helper->nonce_url' ); + $helper = $this->get_helper( 'nonce' ); + return $helper->nonce_url( $action, $url = '' ); + } } /**