From 3b5272e72e6d222560fde6be37bfbc8516f2161a Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Fri, 3 Feb 2012 16:17:35 +0000 Subject: [PATCH] Improved template loader --- classes/class-wc-checkout.php | 4 +- classes/class-wc-email.php | 47 ++++--- readme.txt | 1 + shortcodes/shortcode-checkout.php | 2 +- shortcodes/shortcode-my_account.php | 14 +- shortcodes/shortcode-order_tracking.php | 6 +- shortcodes/shortcode-pay.php | 4 +- shortcodes/shortcode-thankyou.php | 4 +- templates/checkout/form-billing.php | 14 +- templates/checkout/form-pay.php | 2 +- templates/checkout/form-shipping.php | 18 +-- templates/checkout/thankyou.php | 2 +- templates/emails/admin-new-order.php | 4 +- templates/emails/customer-completed-order.php | 4 +- templates/emails/customer-invoice.php | 4 +- templates/emails/customer-new-account.php | 4 +- templates/emails/customer-note.php | 4 +- .../emails/customer-processing-order.php | 4 +- templates/emails/email-header.php | 1 - templates/loop-product-cats.php | 9 +- templates/myaccount/form-edit-address.php | 2 +- templates/myaccount/my-account.php | 2 +- templates/order/order-details.php | 2 +- templates/order/tracking.php | 2 +- templates/shop/breadcrumb.php | 2 +- templates/shop/form-login.php | 2 +- templates/shop/sidebar.php | 10 +- .../single-product/add-to-cart/quantity.php | 2 - .../single-product/add-to-cart/variable.php | 2 +- templates/single-product/related.php | 15 ++- templates/single-product/review.php | 2 +- woocommerce-core-functions.php | 20 +-- woocommerce-template.php | 127 +++++++++--------- 33 files changed, 173 insertions(+), 169 deletions(-) diff --git a/classes/class-wc-checkout.php b/classes/class-wc-checkout.php index 69860bc2a27..88441c95b05 100644 --- a/classes/class-wc-checkout.php +++ b/classes/class-wc-checkout.php @@ -62,12 +62,12 @@ class WC_Checkout { /** Output the billing information form */ function checkout_form_billing() { - include( woocommerce_locate_template( 'checkout/form-billing.php' ) ); + woocommerce_get_template( 'checkout/form-billing.php', array( 'checkout' => $this ) ); } /** Output the shipping information form */ function checkout_form_shipping() { - include( woocommerce_locate_template( 'checkout/form-shipping.php' ) ); + woocommerce_get_template( 'checkout/form-shipping.php', array( 'checkout' => $this ) ); } /** diff --git a/classes/class-wc-email.php b/classes/class-wc-email.php index 3b686afe048..5b0f35e730f 100644 --- a/classes/class-wc-email.php +++ b/classes/class-wc-email.php @@ -66,12 +66,12 @@ class WC_Email { return 'text/html'; } - function email_header() { - woocommerce_get_template('emails/email-header.php', false); + function email_header( $email_heading ) { + woocommerce_get_template('emails/email-header.php', array( 'email_heading' => $email_heading )); } function email_footer() { - woocommerce_get_template('emails/email-footer.php', false); + woocommerce_get_template('emails/email-footer.php'); } /** @@ -81,7 +81,7 @@ class WC_Email { // Buffer ob_start(); - do_action('woocommerce_email_header'); + do_action('woocommerce_email_header', $email_heading); echo wpautop(wptexturize( $message )); @@ -114,7 +114,6 @@ class WC_Email { * New order **/ function new_order( $order_id ) { - global $order, $email_heading; $order = new WC_Order( $order_id ); @@ -128,7 +127,10 @@ class WC_Email { ob_start(); // Get mail template - woocommerce_get_template('emails/admin-new-order.php', false); + woocommerce_get_template('emails/admin-new-order.php', array( + 'order' => $order, + 'email_heading' => $email_heading + )); // Get contents $message = ob_get_clean(); @@ -141,7 +143,6 @@ class WC_Email { * Processing Order **/ function customer_processing_order( $order_id ) { - global $order, $email_heading; $order = new WC_Order( $order_id ); @@ -155,7 +156,10 @@ class WC_Email { ob_start(); // Get mail template - woocommerce_get_template('emails/customer-processing-order.php', false); + woocommerce_get_template('emails/customer-processing-order.php', array( + 'order' => $order, + 'email_heading' => $email_heading + )); // Get contents $message = ob_get_clean(); @@ -171,7 +175,6 @@ class WC_Email { * Completed Order **/ function customer_completed_order( $order_id ) { - global $order, $email_heading; $order = new WC_Order( $order_id ); @@ -193,7 +196,10 @@ class WC_Email { ob_start(); // Get mail template - woocommerce_get_template('emails/customer-completed-order.php', false); + woocommerce_get_template('emails/customer-completed-order.php', array( + 'order' => $order, + 'email_heading' => $email_heading + )); // Get contents $message = ob_get_clean(); @@ -209,7 +215,6 @@ class WC_Email { * Pay for order - invoice **/ function customer_invoice( $pay_for_order ) { - global $order, $email_heading; $order = $pay_for_order; @@ -223,7 +228,10 @@ class WC_Email { ob_start(); // Get mail template - woocommerce_get_template('emails/customer-invoice.php', false); + woocommerce_get_template('emails/customer-invoice.php', array( + 'order' => $order, + 'email_heading' => $email_heading + )); // Get contents $message = ob_get_clean(); @@ -239,7 +247,6 @@ class WC_Email { * Customer notes **/ function customer_note( $args ) { - global $order, $email_heading, $customer_note; $defaults = array( 'order_id' => '', @@ -264,7 +271,11 @@ class WC_Email { ob_start(); // Get mail template - woocommerce_get_template('emails/customer-note.php', false); + woocommerce_get_template('emails/customer-note.php', array( + 'order' => $order, + 'email_heading' => $email_heading, + 'customer_note' => $customer_note + )); // Get contents $message = ob_get_clean(); @@ -362,7 +373,6 @@ class WC_Email { * Customer new account welcome email **/ function customer_new_account( $user_id, $plaintext_pass ) { - global $user_login, $user_pass, $blogname; if (!$user_id || !$plaintext_pass) return; @@ -381,7 +391,12 @@ class WC_Email { ob_start(); // Get mail template - woocommerce_get_template('emails/customer-new-account.php', false); + woocommerce_get_template('emails/customer-new-account.php', array( + 'user_login' => $user_login, + 'user_pass' => $user_pass, + 'blogname' => $blogname, + 'email_heading' => $email_heading + )); // Get contents $message = ob_get_clean(); diff --git a/readme.txt b/readme.txt index 3bd728a9573..2597340fb00 100644 --- a/readme.txt +++ b/readme.txt @@ -84,6 +84,7 @@ Yes you can! Join in on our GitHub repository :) https://github.com/woothemes/wo = 1.4.2 = * Uninstall fix +* Improved template loader - passes args instead of using globals = 1.4.1 - 01/02/2012 = * Depreciated tax class fix diff --git a/shortcodes/shortcode-checkout.php b/shortcodes/shortcode-checkout.php index 48430b6b579..aea21e0634d 100644 --- a/shortcodes/shortcode-checkout.php +++ b/shortcodes/shortcode-checkout.php @@ -25,5 +25,5 @@ function woocommerce_checkout( $atts ) { if ( $woocommerce->error_count()==0 && $non_js_checkout) $woocommerce->add_message( __('The order totals have been updated. Please confirm your order by pressing the Place Order button at the bottom of the page.', 'woocommerce') ); - woocommerce_get_template('checkout/form-checkout.php', false); + woocommerce_get_template('checkout/form-checkout.php'); } \ No newline at end of file diff --git a/shortcodes/shortcode-my_account.php b/shortcodes/shortcode-my_account.php index 26179f945e4..16348c1bc2b 100644 --- a/shortcodes/shortcode-my_account.php +++ b/shortcodes/shortcode-my_account.php @@ -36,7 +36,7 @@ function get_woocommerce_view_order() { * @since 1.4 */ function woocommerce_my_account( $atts ) { - global $woocommerce, $current_user, $recent_orders; + global $woocommerce, $current_user; if ( ! is_user_logged_in() ) : @@ -52,7 +52,10 @@ function woocommerce_my_account( $atts ) { get_currentuserinfo(); - woocommerce_get_template( 'myaccount/my-account.php' ); + woocommerce_get_template( 'myaccount/my-account.php', array( + 'current_user' => $current_user, + 'recent_orders' => $recent_orders + ) ); endif; @@ -70,7 +73,7 @@ function woocommerce_my_account( $atts ) { * @since 1.4 */ function woocommerce_edit_address() { - global $woocommerce, $load_address, $address; + global $woocommerce; if ( ! is_user_logged_in() ) return; @@ -78,7 +81,10 @@ function woocommerce_edit_address() { $address = $woocommerce->countries->get_address_fields( get_user_meta( get_current_user_id(), $load_address . '_country', true ), $load_address . '_' ); - woocommerce_get_template( 'myaccount/form-edit-address.php' ); + woocommerce_get_template( 'myaccount/form-edit-address.php', array( + 'load_address' => $load_address, + 'address' => $address + ) ); } /** diff --git a/shortcodes/shortcode-order_tracking.php b/shortcodes/shortcode-order_tracking.php index 67c1da2d18b..f51380ac11b 100644 --- a/shortcodes/shortcode-order_tracking.php +++ b/shortcodes/shortcode-order_tracking.php @@ -14,7 +14,7 @@ function get_woocommerce_order_tracking($atts) { } function woocommerce_order_tracking( $atts ) { - global $woocommerce, $order; + global $woocommerce; extract(shortcode_atts(array( ), $atts)); @@ -34,7 +34,9 @@ function woocommerce_order_tracking( $atts ) { if ($order->billing_email == $order_email) : - woocommerce_get_template( 'order/tracking.php' ); + woocommerce_get_template( 'order/tracking.php', array( + 'order' => $order + ) ); return; diff --git a/shortcodes/shortcode-pay.php b/shortcodes/shortcode-pay.php index b359d6b5929..27e2da3344d 100644 --- a/shortcodes/shortcode-pay.php +++ b/shortcodes/shortcode-pay.php @@ -18,7 +18,7 @@ function get_woocommerce_pay( $atts ) { * Outputs the pay page - payment gateways can hook in here to show payment forms etc **/ function woocommerce_pay() { - global $woocommerce, $order; + global $woocommerce; if ( isset($_GET['pay_for_order']) && isset($_GET['order']) && isset($_GET['order_id']) ) : @@ -35,7 +35,7 @@ function woocommerce_pay() { if ($order->billing_postcode) $woocommerce->customer->set_postcode( $order->billing_postcode ); // Show form - woocommerce_get_template('checkout/form-pay.php'); + woocommerce_get_template('checkout/form-pay.php', array('order' => $order)); elseif (!in_array($order->status, array('pending', 'failed'))) : diff --git a/shortcodes/shortcode-thankyou.php b/shortcodes/shortcode-thankyou.php index 301526400df..7848e7c857e 100644 --- a/shortcodes/shortcode-thankyou.php +++ b/shortcodes/shortcode-thankyou.php @@ -18,7 +18,7 @@ function get_woocommerce_thankyou( $atts ) { * Outputs the order received page **/ function woocommerce_thankyou( $atts ) { - global $woocommerce, $order; + global $woocommerce; $order = false; @@ -36,5 +36,5 @@ function woocommerce_thankyou( $atts ) { endif; endif; - woocommerce_get_template( 'checkout/thankyou.php' ); + woocommerce_get_template( 'checkout/thankyou.php', array( 'order' => $order ) ); } \ No newline at end of file diff --git a/templates/checkout/form-billing.php b/templates/checkout/form-billing.php index 2b95df65dbe..257d71a5f20 100644 --- a/templates/checkout/form-billing.php +++ b/templates/checkout/form-billing.php @@ -15,22 +15,22 @@ global $woocommerce; - + -checkout_fields['billing'] as $key => $field) : ?> +checkout_fields['billing'] as $key => $field) : ?> - get_value( $key ) ); ?> + get_value( $key ) ); ?> - +

- get_value('createaccount'), true) ?> type="checkbox" name="createaccount" value="1" /> + get_value('createaccount'), true) ?> type="checkbox" name="createaccount" value="1" />

@@ -39,9 +39,9 @@ global $woocommerce;

- checkout_fields['account'] as $key => $field) : ?> + checkout_fields['account'] as $key => $field) : ?> - get_value( $key ) ); ?> + get_value( $key ) ); ?> diff --git a/templates/checkout/form-pay.php b/templates/checkout/form-pay.php index f83bb5fad61..068d89ec406 100755 --- a/templates/checkout/form-pay.php +++ b/templates/checkout/form-pay.php @@ -2,7 +2,7 @@ /** * Pay for order form */ -global $order, $woocommerce; +global $woocommerce; ?>
diff --git a/templates/checkout/form-shipping.php b/templates/checkout/form-shipping.php index eb736541fb0..06f157821c2 100644 --- a/templates/checkout/form-shipping.php +++ b/templates/checkout/form-shipping.php @@ -15,7 +15,7 @@ global $woocommerce; else : - $shiptobilling = $this->get_value('shiptobilling'); + $shiptobilling = $checkout->get_value('shiptobilling'); endif; ?> @@ -28,21 +28,21 @@ global $woocommerce;
- + - checkout_fields['shipping'] as $key => $field) : ?> + checkout_fields['shipping'] as $key => $field) : ?> - get_value( $key ) ); ?> + get_value( $key ) ); ?> - +
- + @@ -52,12 +52,12 @@ global $woocommerce; - checkout_fields['order'] as $key => $field) : ?> + checkout_fields['order'] as $key => $field) : ?> - get_value( $key ) ); ?> + get_value( $key ) ); ?> - \ No newline at end of file + \ No newline at end of file diff --git a/templates/checkout/thankyou.php b/templates/checkout/thankyou.php index fa0dc32fd8c..4694e05e527 100644 --- a/templates/checkout/thankyou.php +++ b/templates/checkout/thankyou.php @@ -3,7 +3,7 @@ * Thankyou Page */ -global $woocommerce, $order; +global $woocommerce; ?> diff --git a/templates/emails/admin-new-order.php b/templates/emails/admin-new-order.php index c8254119ca6..e9dd7440029 100644 --- a/templates/emails/admin-new-order.php +++ b/templates/emails/admin-new-order.php @@ -1,8 +1,6 @@ - - - +

billing_first_name . ' ' . $order->billing_last_name . __(". Their order is as follows:", 'woocommerce'); ?>

diff --git a/templates/emails/customer-completed-order.php b/templates/emails/customer-completed-order.php index a661865fabe..e47fec9c097 100644 --- a/templates/emails/customer-completed-order.php +++ b/templates/emails/customer-completed-order.php @@ -1,8 +1,6 @@ - - - +

diff --git a/templates/emails/customer-invoice.php b/templates/emails/customer-invoice.php index c46a1437803..469c2913c5a 100644 --- a/templates/emails/customer-invoice.php +++ b/templates/emails/customer-invoice.php @@ -1,8 +1,6 @@ - - - + status=='pending') : ?> diff --git a/templates/emails/customer-new-account.php b/templates/emails/customer-new-account.php index e74268b15ee..532476c2ff5 100644 --- a/templates/emails/customer-new-account.php +++ b/templates/emails/customer-new-account.php @@ -1,8 +1,6 @@ - - - +

diff --git a/templates/emails/customer-note.php b/templates/emails/customer-note.php index b88287e18af..9b3b2854474 100644 --- a/templates/emails/customer-note.php +++ b/templates/emails/customer-note.php @@ -1,8 +1,6 @@ - - - +

diff --git a/templates/emails/customer-processing-order.php b/templates/emails/customer-processing-order.php index 5e9defaf00e..1413a23473a 100644 --- a/templates/emails/customer-processing-order.php +++ b/templates/emails/customer-processing-order.php @@ -1,8 +1,6 @@ - - - +

diff --git a/templates/emails/email-header.php b/templates/emails/email-header.php index a7027a7f23a..4638db6325d 100644 --- a/templates/emails/email-header.php +++ b/templates/emails/email-header.php @@ -165,7 +165,6 @@

diff --git a/templates/loop-product-cats.php b/templates/loop-product-cats.php index b66375dfebe..552b3327fcc 100644 --- a/templates/loop-product-cats.php +++ b/templates/loop-product-cats.php @@ -1,4 +1,10 @@ - +
  • diff --git a/templates/myaccount/form-edit-address.php b/templates/myaccount/form-edit-address.php index 8734b7c5871..91edced6a7a 100644 --- a/templates/myaccount/form-edit-address.php +++ b/templates/myaccount/form-edit-address.php @@ -3,7 +3,7 @@ * Edit Address Form */ -global $woocommerce, $load_address, $address; +global $woocommerce; ?> show_messages(); ?> diff --git a/templates/myaccount/my-account.php b/templates/myaccount/my-account.php index ec5fc059997..9928cde2b95 100644 --- a/templates/myaccount/my-account.php +++ b/templates/myaccount/my-account.php @@ -3,7 +3,7 @@ * My Account */ -global $woocommerce, $current_user, $recent_orders; +global $woocommerce; ?> show_messages(); ?> diff --git a/templates/order/order-details.php b/templates/order/order-details.php index f9e15e02184..ebf3860a493 100644 --- a/templates/order/order-details.php +++ b/templates/order/order-details.php @@ -3,7 +3,7 @@ * Order Details */ -global $woocommerce, $order_id; +global $woocommerce; $order = new WC_Order( $order_id ); ?> diff --git a/templates/order/tracking.php b/templates/order/tracking.php index fb3db4f33ff..7a3eaa78746 100644 --- a/templates/order/tracking.php +++ b/templates/order/tracking.php @@ -3,7 +3,7 @@ * Order Tracking */ -global $woocommerce, $order; +global $woocommerce; ?> diff --git a/templates/shop/sidebar.php b/templates/shop/sidebar.php index aaff5085db6..7204768c0db 100644 --- a/templates/shop/sidebar.php +++ b/templates/shop/sidebar.php @@ -1,9 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/templates/single-product/add-to-cart/quantity.php b/templates/single-product/add-to-cart/quantity.php index b3da99ba528..9b0d15e6fa9 100644 --- a/templates/single-product/add-to-cart/quantity.php +++ b/templates/single-product/add-to-cart/quantity.php @@ -2,7 +2,5 @@ /** * Single Product Quantity Inputs */ - -global $input_name, $input_value, $max_value; ?>
    \ No newline at end of file diff --git a/templates/single-product/add-to-cart/variable.php b/templates/single-product/add-to-cart/variable.php index 0d76b7a5d0e..a8e699b686b 100644 --- a/templates/single-product/add-to-cart/variable.php +++ b/templates/single-product/add-to-cart/variable.php @@ -3,7 +3,7 @@ * Variable Product Add to Cart */ -global $woocommerce, $product, $available_variations, $attributes, $selected_attributes; +global $woocommerce, $product; ?>