From 560d9129182799141c02a948e20a445108c741f8 Mon Sep 17 00:00:00 2001 From: Joldis Mihai Alexandru Date: Thu, 18 May 2017 22:01:57 +0300 Subject: [PATCH 1/9] Initial Credit Work --- .../gateways/paypal-digital-goods.php | 4 +- .../gateways/paypal-express-checkout.php | 138 +++++++++++++++++- .../gateways/paypal-express-checkout.php | 2 +- 3 files changed, 138 insertions(+), 6 deletions(-) diff --git a/wpsc-components/merchant-core-v3/gateways/paypal-digital-goods.php b/wpsc-components/merchant-core-v3/gateways/paypal-digital-goods.php index a0566b9331..c55064559b 100644 --- a/wpsc-components/merchant-core-v3/gateways/paypal-digital-goods.php +++ b/wpsc-components/merchant-core-v3/gateways/paypal-digital-goods.php @@ -119,10 +119,10 @@ public function add_ecs_button( $cart_table, $context ) { * * @return void */ - public function get_shortcut_url() { + public function get_shortcut_url( $callback = 'shortcut_process' ) { $location = add_query_arg( array( 'payment_gateway' => 'paypal-digital-goods', - 'payment_gateway_callback' => 'shortcut_process', + 'payment_gateway_callback' => $callback, ), home_url( 'index.php' ) ); return apply_filters( 'wpsc_paypal_digital_goods_shortcut_url', $location ); diff --git a/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php b/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php index cfc63d71d7..2a392a5f56 100644 --- a/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php +++ b/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php @@ -42,16 +42,23 @@ public function __construct( $options, $child = false ) { 'cart_border' => $this->setting->get( 'cart_border' ), 'incontext' => (bool) $this->setting->get( 'incontext', '1' ), 'shortcut' => (bool) $this->setting->get( 'shortcut' , '1' ), + 'credit' => (bool) $this->setting->get( 'credit' , '0' ), ) ); // Express Checkout Button if ( (bool) $this->setting->get( 'shortcut' ) ) { add_action( 'wpsc_cart_item_table_form_actions_left', array( $this, 'add_ecs_button' ), 2, 2 ); } + // Incontext Checkout Scripts if ( (bool) $this->setting->get( 'incontext' ) ) { add_action( 'wp_enqueue_scripts', array( $this, 'incontext_load_scripts' ) ); } + + // PayPal Credit Button + if ( (bool) $this->setting->get( 'credit' ) ) { + add_action( 'wpsc_cart_item_table_form_actions_left', array( $this, 'add_credit_button' ), 1, 2 ); + } } } @@ -89,15 +96,34 @@ public function add_ecs_button( $cart_table, $context ) { } } + /** + * Insert the Credit Shortcut Button + * + * @return void + */ + public function add_credit_button( $cart_table, $context ) { + + if ( wpsc_is_gateway_active( 'paypal-digital-goods' ) || ! wpsc_is_gateway_active( 'paypal-express-checkout' ) ) { + return; + } + + if ( _wpsc_get_current_controller_name() === 'cart' ) { + $url = $this->get_shortcut_url( 'credit_process' ); + echo '' . __( 'PayPal Credit', 'wp-e-commerce' ) . ''; + echo '' . __( '— or —', 'wp-e-commerce' ) . ''; + } + } + /** * Return the ExpressCheckout Shortcut redirection URL * + * @param string $callback * @return void */ - public function get_shortcut_url() { + public function get_shortcut_url( $callback = 'shortcut_process' ) { $location = add_query_arg( array( 'payment_gateway' => 'paypal-express-checkout', - 'payment_gateway_callback' => 'shortcut_process', + 'payment_gateway_callback' => $callback, ), home_url( 'index.php' ) ); return apply_filters( 'wpsc_paypal_express_checkout_shortcut_url', $location ); @@ -112,6 +138,7 @@ public function callback_shortcut_process() { if ( ! isset( $_GET['payment_gateway'] ) ) { return; } + $payment_gateway = $_GET['payment_gateway']; global $wpsc_cart; @@ -136,6 +163,7 @@ public function callback_shortcut_process() { $tax = 0; $tax_percentage = 0; } + $purchase_log->set( array( 'wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage, @@ -182,6 +210,87 @@ public function callback_shortcut_process() { return $sessionid; } + /** + * Credit Shortcut Callback + * + * @return int + */ + public function callback_credit_process() { + if ( ! isset( $_GET['payment_gateway'] ) ) { + return; + } + + $payment_gateway = $_GET['payment_gateway']; + + global $wpsc_cart; + // Create a new PurchaseLog Object + $purchase_log = new WPSC_Purchase_Log(); + + // Create a Sessionid + $sessionid = ( mt_rand( 100, 999 ) . time() ); + wpsc_update_customer_meta( 'checkout_session_id', $sessionid ); + $purchase_log->set( array( + 'user_ID' => get_current_user_id(), + 'date' => time(), + 'plugin_version' => WPSC_VERSION, + 'statusno' => '0', + 'sessionid' => $sessionid, + ) ); + + if ( wpsc_is_tax_included() ) { + $tax = $wpsc_cart->calculate_total_tax(); + $tax_percentage = $wpsc_cart->tax_percentage; + } else { + $tax = 0; + $tax_percentage = 0; + } + + $purchase_log->set( array( + 'wpec_taxes_total' => $tax, + 'wpec_taxes_rate' => $tax_percentage, + ) ); + + // Save the purchase_log object to generate it's id + $purchase_log->save(); + $purchase_log_id = $purchase_log->get( 'id' ); + + $wpsc_cart->log_id = $purchase_log_id; + wpsc_update_customer_meta( 'current_purchase_log_id', $purchase_log_id ); + + $purchase_log->set( array( + 'gateway' => $payment_gateway, + 'base_shipping' => $wpsc_cart->calculate_base_shipping(), + 'totalprice' => $wpsc_cart->calculate_total_price(), + ) ); + + $purchase_log->save(); + + $wpsc_cart->empty_db( $purchase_log_id ); + $wpsc_cart->save_to_db( $purchase_log_id ); + $wpsc_cart->submit_stock_claims( $purchase_log_id ); + + // Save an empty Form + $form = WPSC_Checkout_Form::get(); + $fields = $form->get_fields(); + WPSC_Checkout_Form_Data::save_form( $purchase_log, $fields ); + + // Return Customer to Review Order Page if there is Shipping + add_filter( 'wpsc_paypal_express_checkout_transact_url', array( &$this, 'review_order_url' ) ); + add_filter( 'wpsc_paypal_express_checkout_return_url', array( &$this, 'review_order_callback' ) ); + + // Set a Temporary Option for EC Shortcut + wpsc_update_customer_meta( 'esc-' . $sessionid, true ); + + // Apply Checkout Actions + do_action( 'wpsc_submit_checkout', array( + 'purchase_log_id' => $purchase_log_id, + 'our_user_id' => get_current_user_id(), + ) ); + do_action( 'wpsc_submit_checkout_gateway', $payment_gateway, $purchase_log ); + + return $sessionid; + } + /** * Return Customer to Review Order Page if there are Shipping Costs. * @@ -884,7 +993,21 @@ public function setup_form() { - + + + +

+ + + + + + + +     + + + is_currency_supported() ) : ?> @@ -997,6 +1120,7 @@ protected function convert( $amt ) { * @since 3.9.0 */ public function process() { + $total = $this->convert( $this->purchase_log->get( 'totalprice' ) ); $options = array( 'return_url' => $this->get_return_url(), @@ -1012,6 +1136,14 @@ public function process() { $options['notify_url'] = $this->get_notify_url(); } + // Check if its a Credit transaction and pass required params. + if ( isset( $_GET['payment_gateway_callback'] ) && $_GET['payment_gateway_callback'] == 'credit_process' ) { + $options += array( + 'solution_type' => 'SOLE', + 'user_funding_source' => 'Finance', + ); + } + // SetExpressCheckout $response = $this->gateway->setup_purchase( $options ); diff --git a/wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-express-checkout.php b/wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-express-checkout.php index 04db3fc646..b7275cbccc 100644 --- a/wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-express-checkout.php +++ b/wpsc-components/merchant-core-v3/gateways/php-merchant/gateways/paypal-express-checkout.php @@ -193,6 +193,7 @@ protected function build_checkout_request( $action, $options = array() ) { 'MSGSUBID' => 'message_id', 'INVOICEID' => 'invoice', 'NOTE' => 'note', + 'USERSELECTEDFUNDINGSOURCE' => 'user_funding_source', ) ); // Cart Customization Fields @@ -243,7 +244,6 @@ public function setup_purchase( $options = array(), $action = 'Sale' ) { $this->options = array_merge( $this->options, $options ); $this->requires( array( 'amount', 'return_url', 'cancel_url' ) ); $request = $this->build_checkout_request( $action, $options ); - $response_str = $this->commit( 'SetExpressCheckout', $request ); return new PHP_Merchant_Paypal_Express_Checkout_Response( $response_str ); } From 5f62be9d86f9401a1b99e0f84b28b4a9c6065d22 Mon Sep 17 00:00:00 2001 From: Joldis Mihai Alexandru Date: Thu, 18 May 2017 22:20:06 +0300 Subject: [PATCH 2/9] Disable Credit by default --- .../merchant-core-v3/gateways/paypal-express-checkout.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php b/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php index 2a392a5f56..cbfad38acd 100644 --- a/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php +++ b/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php @@ -1004,8 +1004,8 @@ public function setup_form() { -     - +     + From 54e2b644424e308ea653b824f9a76f482fc6ec1a Mon Sep 17 00:00:00 2001 From: Joldis Mihai Alexandru Date: Thu, 18 May 2017 22:21:09 +0300 Subject: [PATCH 3/9] Set default credit to 1 --- .../merchant-core-v3/gateways/paypal-express-checkout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php b/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php index cbfad38acd..94193a358b 100644 --- a/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php +++ b/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php @@ -42,7 +42,7 @@ public function __construct( $options, $child = false ) { 'cart_border' => $this->setting->get( 'cart_border' ), 'incontext' => (bool) $this->setting->get( 'incontext', '1' ), 'shortcut' => (bool) $this->setting->get( 'shortcut' , '1' ), - 'credit' => (bool) $this->setting->get( 'credit' , '0' ), + 'credit' => (bool) $this->setting->get( 'credit' , '1' ), ) ); // Express Checkout Button From 581d2efbdef07153d5bb80e71b931c6b1b97a2fa Mon Sep 17 00:00:00 2001 From: Justin Sainton Date: Wed, 24 May 2017 17:34:08 -0700 Subject: [PATCH 4/9] Version bump --- package.json | 2 +- readme.md | 2 +- readme.txt | 6 +++++- wp-shopping-cart.php | 2 +- wpsc-core/wpsc-constants.php | 4 ++-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 0328b176b7..7fe20b5d30 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wp-e-commerce", - "version": "3.12.0", + "version": "3.12.1", "private": true, "devDependencies": { "grunt": "^0.4.5", diff --git a/readme.md b/readme.md index 93f5c192c0..08cffc85f6 100644 --- a/readme.md +++ b/readme.md @@ -17,7 +17,7 @@ If you're looking for general user support, please submit your support request o Development status ------------------------- -* The latest stable version is [3.12.0](http://wordpress.org/extend/plugins/wp-e-commerce). +* The latest stable version is [3.12.1](http://wordpress.org/extend/plugins/wp-e-commerce). * Active development version: 4.0-dev (branch [master](https://github.com/wp-e-commerce/WP-e-Commerce)) * [Roadmap for 4.0](https://github.com/wp-e-commerce/wp-e-commerce/wiki/Roadmap) * [4.0 tickets](https://github.com/wp-e-commerce/WP-e-Commerce/milestones/4.0) diff --git a/readme.txt b/readme.txt index a86672a8ca..004f5e4113 100755 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://wpecommerce.org Tags: e-commerce, digital downloads, wp-e-commerce, shop, cart, paypal, authorize, stock control, ecommerce, shipping, tax Requires at least: 4.5 Tested up to: 4.7.2 -Stable tag: 3.12.0 +Stable tag: 3.12.1 WP eCommerce is a free, powerful plugin that empowers you to sell anything online, quickly and easily. @@ -36,6 +36,10 @@ After upgrading from earlier versions look for link "Update Store". This will up == Changelog == += 3.12.1 [2017-2-17] = + +* New: Addition of PayPal Credit to PayPal Express Checkout. + = 3.12.0 [2017-2-17] = * Fix: When updating a pending order, ensure that the order object's total price is updated as well. diff --git a/wp-shopping-cart.php b/wp-shopping-cart.php index cc8d4b417d..7d849afa2d 100644 --- a/wp-shopping-cart.php +++ b/wp-shopping-cart.php @@ -3,7 +3,7 @@ * Plugin Name: WP eCommerce * Plugin URI: http://wpecommerce.org/ * Description: A plugin that provides a WordPress Shopping Cart. See also: WPeCommerce.org | Support Forum | Documentation - * Version: 3.12.0 + * Version: 3.12.1 * Author: WP eCommerce * Author URI: http://wpecommerce.org/ * Text Domain: wp-e-commerce diff --git a/wpsc-core/wpsc-constants.php b/wpsc-core/wpsc-constants.php index 4cb8502161..6980ea5022 100644 --- a/wpsc-core/wpsc-constants.php +++ b/wpsc-core/wpsc-constants.php @@ -55,7 +55,7 @@ function wpsc_core_constants() { // Define Plugin version if ( ! defined( 'WPSC_VERSION' ) ) { - define( 'WPSC_VERSION' , '3.12.0' ); + define( 'WPSC_VERSION' , '3.12.1' ); } if ( ! defined( 'WPSC_MINOR_VERSION' ) ) { @@ -63,7 +63,7 @@ function wpsc_core_constants() { } if ( ! defined( 'WPSC_PRESENTABLE_VERSION' ) ) { - define( 'WPSC_PRESENTABLE_VERSION', '3.12.0' ); + define( 'WPSC_PRESENTABLE_VERSION', '3.12.1' ); } // Define a salt to use when we hash, WPSC_SALT may be defined for us in our config file, so check first From 48ed2ea406f6690830810da0ba644f3812f8d03f Mon Sep 17 00:00:00 2001 From: Drew Jaynes Date: Wed, 24 May 2017 19:51:33 -0600 Subject: [PATCH 5/9] Wrap calls to wpsc functions inside a 'shutdown' callback to avoid a fatal triggered during wp-cli activation. (#2316) --- wpsc-core/wpsc-functions.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/wpsc-core/wpsc-functions.php b/wpsc-core/wpsc-functions.php index 243a876c4e..553dd2efa2 100644 --- a/wpsc-core/wpsc-functions.php +++ b/wpsc-core/wpsc-functions.php @@ -644,12 +644,14 @@ function wpsc_serialize_shopping_cart() { $wpsc_cart->errors = array(); } - // need to prevent set_cookie from being called at this stage in case the user just logged out - // because by now, some output must have been printed out - $customer_id = wpsc_get_current_customer_id(); + if ( function_exists( 'wpsc_get_current_customer_id' ) ) { + // Need to prevent set_cookie from being called at this stage in case the user + // just logged out because by now, some output must have been printed out. + $customer_id = wpsc_get_current_customer_id(); - if ( $customer_id ) { - wpsc_update_customer_cart( $wpsc_cart, $customer_id ); + if ( $customer_id ) { + wpsc_update_customer_cart( $wpsc_cart, $customer_id ); + } } return true; From f35169792326b9568d3db5aa42bfb9726f1ef9f9 Mon Sep 17 00:00:00 2001 From: Justin Sainton Date: Wed, 24 May 2017 18:53:58 -0700 Subject: [PATCH 6/9] Update changelog --- readme.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.txt b/readme.txt index 004f5e4113..bf2d9375ca 100755 --- a/readme.txt +++ b/readme.txt @@ -39,6 +39,7 @@ After upgrading from earlier versions look for link "Update Store". This will up = 3.12.1 [2017-2-17] = * New: Addition of PayPal Credit to PayPal Express Checkout. +* Fix: Ensure WPEC works via WP-CLI. = 3.12.0 [2017-2-17] = From 9d3dec5639fd58debefb9a96b141ab4e063da943 Mon Sep 17 00:00:00 2001 From: Joldis Mihai Alexandru Date: Thu, 25 May 2017 22:38:47 +0300 Subject: [PATCH 7/9] Enable PayPal credid on tev1 too (#2317) --- .../gateways/paypal-express-checkout.php | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php b/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php index 94193a358b..5281c9f575 100644 --- a/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php +++ b/wpsc-components/merchant-core-v3/gateways/paypal-express-checkout.php @@ -54,14 +54,24 @@ public function __construct( $options, $child = false ) { if ( (bool) $this->setting->get( 'incontext' ) ) { add_action( 'wp_enqueue_scripts', array( $this, 'incontext_load_scripts' ) ); } - + // PayPal Credit Button if ( (bool) $this->setting->get( 'credit' ) ) { + add_action( 'wpsc_gateway_v2_inside_gateway_label', array( $this, 'add_credit_button_tev1' ) ); add_action( 'wpsc_cart_item_table_form_actions_left', array( $this, 'add_credit_button' ), 1, 2 ); } + } } + public function add_credit_button_tev1( $gateway ) { + if ( 'paypal-express-checkout' !== $gateway ) { return; } + + $url = $this->get_shortcut_url( 'credit_process' ); + echo '' . __( '— or —', 'wp-e-commerce' ) . ''; + echo '' . __( 'PayPal Credit', 'wp-e-commerce' ) . ''; + } + public function incontext_load_scripts() { $is_cart = wpsc_is_theme_engine( '1.0' ) ? wpsc_is_checkout() : ( wpsc_is_checkout() || wpsc_is_cart() ); @@ -113,7 +123,7 @@ public function add_credit_button( $cart_table, $context ) { echo '' . __( '— or —', 'wp-e-commerce' ) . ''; } } - + /** * Return the ExpressCheckout Shortcut redirection URL * @@ -237,7 +247,7 @@ public function callback_credit_process() { 'sessionid' => $sessionid, ) ); - if ( wpsc_is_tax_included() ) { + if ( wpsc_tax_isincluded() ) { $tax = $wpsc_cart->calculate_total_tax(); $tax_percentage = $wpsc_cart->tax_percentage; } else { @@ -272,7 +282,8 @@ public function callback_credit_process() { // Save an empty Form $form = WPSC_Checkout_Form::get(); $fields = $form->get_fields(); - WPSC_Checkout_Form_Data::save_form( $purchase_log, $fields ); + + WPSC_Checkout_Form_Data::save_form( $purchase_log, $fields, array(), false ); // Return Customer to Review Order Page if there is Shipping add_filter( 'wpsc_paypal_express_checkout_transact_url', array( &$this, 'review_order_url' ) ); @@ -526,7 +537,7 @@ public function pull_paypal_details() { } // Save details to the Forms Table - WPSC_Checkout_Form_Data::save_form( $this->purchase_log, $fields ); + WPSC_Checkout_Form_Data::save_form( $this->purchase_log, $fields, array(), false ); } /** @@ -1004,8 +1015,8 @@ public function setup_form() { -     - +     + From dd6af196809f0aee4a697c7012982c78e2130046 Mon Sep 17 00:00:00 2001 From: Justin Sainton Date: Thu, 25 May 2017 12:42:42 -0700 Subject: [PATCH 8/9] Version bump --- package.json | 2 +- readme.md | 2 +- readme.txt | 8 ++++++-- wp-shopping-cart.php | 2 +- wpsc-core/wpsc-constants.php | 4 ++-- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 7fe20b5d30..6e9b80158c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wp-e-commerce", - "version": "3.12.1", + "version": "3.12.2", "private": true, "devDependencies": { "grunt": "^0.4.5", diff --git a/readme.md b/readme.md index 08cffc85f6..95dcb35e1e 100644 --- a/readme.md +++ b/readme.md @@ -17,7 +17,7 @@ If you're looking for general user support, please submit your support request o Development status ------------------------- -* The latest stable version is [3.12.1](http://wordpress.org/extend/plugins/wp-e-commerce). +* The latest stable version is [3.12.2](http://wordpress.org/extend/plugins/wp-e-commerce). * Active development version: 4.0-dev (branch [master](https://github.com/wp-e-commerce/WP-e-Commerce)) * [Roadmap for 4.0](https://github.com/wp-e-commerce/wp-e-commerce/wiki/Roadmap) * [4.0 tickets](https://github.com/wp-e-commerce/WP-e-Commerce/milestones/4.0) diff --git a/readme.txt b/readme.txt index bf2d9375ca..4f51a6b8d5 100755 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://wpecommerce.org Tags: e-commerce, digital downloads, wp-e-commerce, shop, cart, paypal, authorize, stock control, ecommerce, shipping, tax Requires at least: 4.5 Tested up to: 4.7.2 -Stable tag: 3.12.1 +Stable tag: 3.12.2 WP eCommerce is a free, powerful plugin that empowers you to sell anything online, quickly and easily. @@ -36,7 +36,11 @@ After upgrading from earlier versions look for link "Update Store". This will up == Changelog == -= 3.12.1 [2017-2-17] = += 3.12.2 [2017-3-25] = + +* Enhancement: Default PayPal Credit to On, and ensure it is functional for our 1.0 theme engine. + += 3.12.1 [2017-3-24] = * New: Addition of PayPal Credit to PayPal Express Checkout. * Fix: Ensure WPEC works via WP-CLI. diff --git a/wp-shopping-cart.php b/wp-shopping-cart.php index 7d849afa2d..ab762df540 100644 --- a/wp-shopping-cart.php +++ b/wp-shopping-cart.php @@ -3,7 +3,7 @@ * Plugin Name: WP eCommerce * Plugin URI: http://wpecommerce.org/ * Description: A plugin that provides a WordPress Shopping Cart. See also: WPeCommerce.org | Support Forum | Documentation - * Version: 3.12.1 + * Version: 3.12.2 * Author: WP eCommerce * Author URI: http://wpecommerce.org/ * Text Domain: wp-e-commerce diff --git a/wpsc-core/wpsc-constants.php b/wpsc-core/wpsc-constants.php index 6980ea5022..9e96283319 100644 --- a/wpsc-core/wpsc-constants.php +++ b/wpsc-core/wpsc-constants.php @@ -55,7 +55,7 @@ function wpsc_core_constants() { // Define Plugin version if ( ! defined( 'WPSC_VERSION' ) ) { - define( 'WPSC_VERSION' , '3.12.1' ); + define( 'WPSC_VERSION' , '3.12.2' ); } if ( ! defined( 'WPSC_MINOR_VERSION' ) ) { @@ -63,7 +63,7 @@ function wpsc_core_constants() { } if ( ! defined( 'WPSC_PRESENTABLE_VERSION' ) ) { - define( 'WPSC_PRESENTABLE_VERSION', '3.12.1' ); + define( 'WPSC_PRESENTABLE_VERSION', '3.12.2' ); } // Define a salt to use when we hash, WPSC_SALT may be defined for us in our config file, so check first From dec7b2af797d201e65751770d5274b6ba5e0f109 Mon Sep 17 00:00:00 2001 From: Ben Huson Date: Thu, 27 Jul 2017 20:40:59 +0100 Subject: [PATCH 9/9] Only do Fancy Notifications if option is enabled. --- .../fancy-notifications.php | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/wpsc-components/fancy-notifications/fancy-notifications.php b/wpsc-components/fancy-notifications/fancy-notifications.php index b59d0462b3..7618ca46d0 100644 --- a/wpsc-components/fancy-notifications/fancy-notifications.php +++ b/wpsc-components/fancy-notifications/fancy-notifications.php @@ -4,11 +4,7 @@ * WP eCommerce Fancy Notifications */ -add_action( 'wp_enqueue_scripts', array( 'WPSC_Fancy_Notifications', 'enqueue_styles' ) ); -add_action( 'wp_enqueue_scripts', array( 'WPSC_Fancy_Notifications', 'enqueue_scripts' ) ); -add_action( 'wpsc_add_to_cart_button_form_begin', array( 'WPSC_Fancy_Notifications', 'add_fancy_notifications' ) ); -add_action( 'wpsc_theme_footer', array( 'WPSC_Fancy_Notifications', 'fancy_notifications' ) ); -add_filter( 'wpsc_add_to_cart_json_response', array( 'WPSC_Fancy_Notifications', 'wpsc_add_to_cart_json_response' ) ); +add_action( 'plugins_loaded', array( 'WPSC_Fancy_Notifications', 'setup_hooks' ) ); /** * WP eCommerce Fancy Notifications Class @@ -17,6 +13,23 @@ */ class WPSC_Fancy_Notifications { + /** + * Setup Hooks + */ + public static function setup_hooks() { + + if ( self::is_active() ) { + + add_action( 'wp_enqueue_scripts', array( get_class(), 'enqueue_styles' ) ); + add_action( 'wp_enqueue_scripts', array( get_class(), 'enqueue_scripts' ) ); + add_action( 'wpsc_add_to_cart_button_form_begin', array( get_class(), 'add_fancy_notifications' ) ); + add_action( 'wpsc_theme_footer', array( get_class(), 'fancy_notifications' ) ); + add_filter( 'wpsc_add_to_cart_json_response', array( get_class(), 'wpsc_add_to_cart_json_response' ) ); + + } + + } + /** * Fancy Notifications * @@ -128,6 +141,17 @@ public static function enqueue_scripts() { } + /** + * Is Active? + * + * @return boolean + */ + public static function is_active() { + + return get_option( 'fancy_notifications' ) == 1; + + } + /** * Plugin URL *