Merge branch 'helpers-refactor' into core-class-refactor

Conflicts:
	classes/class-wc-shortcodes.php
	classes/shortcodes/class-wc-shortcode-change-password.php
	classes/shortcodes/class-wc-shortcode-view-order.php
	templates/myaccount/form-change-password.php
	templates/myaccount/form-login.php
	templates/order/order-details.php
	woocommerce-functions.php
This commit is contained in:
Coen Jacobs 2013-06-06 13:55:36 +02:00
commit a09ebc9cca
63 changed files with 927 additions and 491 deletions

View File

@ -759,7 +759,7 @@ function woocommerce_admin_product_quick_edit_save( $post_id, $post ) {
}
// Clear transient
$woocommerce->clear_product_transients( $post_id );
$woocommerce->get_helper( 'transient' )->clear_product_transients( $post_id );
}
add_action( 'save_post', 'woocommerce_admin_product_quick_edit_save', 10, 2 );
@ -1156,7 +1156,7 @@ function woocommerce_admin_product_bulk_edit_save( $post_id, $post ) {
do_action( 'woocommerce_product_bulk_edit_save', $product );
// Clear transient
$woocommerce->clear_product_transients( $post_id );
$woocommerce->get_helper( 'transient' )->clear_product_transients( $post_id );
}
add_action( 'save_post', 'woocommerce_admin_product_bulk_edit_save', 10, 2 );

View File

@ -85,7 +85,7 @@ function woocommerce_custom_coupon_columns( $column ) {
break;
case "type" :
echo esc_html( $woocommerce->get_coupon_discount_type( get_post_meta( $post->ID, 'discount_type', true ) ) );
echo esc_html( $woocommerce->get_helper( 'coupon' )->get_coupon_discount_type( get_post_meta( $post->ID, 'discount_type', true ) ) );
break;
case "amount" :
echo esc_html( get_post_meta( $post->ID, 'coupon_amount', true ) );
@ -148,7 +148,7 @@ function woocommerce_restrict_manage_coupons() {
<select name='coupon_type' id='dropdown_shop_coupon_type'>
<option value=""><?php _e( 'Show all types', 'woocommerce' ); ?></option>
<?php
$types = $woocommerce->get_coupon_discount_types();
$types = $woocommerce->get_helper( 'coupon' )->get_coupon_discount_types();
foreach ( $types as $name => $type ) {
echo '<option value="' . esc_attr( $name ) . '"';
@ -162,7 +162,7 @@ function woocommerce_restrict_manage_coupons() {
</select>
<?php
$woocommerce->add_inline_js( "
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js( "
jQuery('select#dropdown_shop_coupon_type, select[name=m]').css('width', '150px').chosen();
" );
}

View File

@ -310,7 +310,7 @@ function woocommerce_restrict_manage_orders() {
</select>
<?php
$woocommerce->add_inline_js( "
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js( "
jQuery('select#dropdown_shop_order_status, select[name=m]').css('width', '150px').chosen();

View File

@ -17,7 +17,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$variation_selected_value = isset( $variation_data[ 'attribute_' . sanitize_title( $attribute['name'] ) ][0] ) ? $variation_data[ 'attribute_' . sanitize_title( $attribute['name'] ) ][0] : '';
// Name will be something like attribute_pa_color
echo '<select name="attribute_' . sanitize_title( $attribute['name'] ) . '[' . $loop . ']"><option value="">' . __( 'Any', 'woocommerce' ) . ' ' . esc_html( $woocommerce->attribute_label( $attribute['name'] ) ) . '&hellip;</option>';
echo '<select name="attribute_' . sanitize_title( $attribute['name'] ) . '[' . $loop . ']"><option value="">' . __( 'Any', 'woocommerce' ) . ' ' . esc_html( $woocommerce->get_helper( 'attribute' )->attribute_label( $attribute['name'] ) ) . '&hellip;</option>';
// Get terms for attribute taxonomy or value if its a custom attribute
if ( $attribute['is_taxonomy'] ) {

View File

@ -39,7 +39,7 @@ function woocommerce_coupon_data_meta_box( $post ) {
echo '</div><div class="options_group">';
// Type
woocommerce_wp_select( array( 'id' => 'discount_type', 'label' => __( 'Discount type', 'woocommerce' ), 'options' => $woocommerce->get_coupon_discount_types() ) );
woocommerce_wp_select( array( 'id' => 'discount_type', 'label' => __( 'Discount type', 'woocommerce' ), 'options' => $woocommerce->get_helper( 'coupon' )->get_coupon_discount_types() ) );
// Amount
woocommerce_wp_text_input( array( 'id' => 'coupon_amount', 'label' => __( 'Coupon amount', 'woocommerce' ), 'placeholder' => '0.00', 'description' => __( 'Value of the coupon.', 'woocommerce' ), 'type' => 'number', 'custom_attributes' => array(

View File

@ -101,7 +101,7 @@ function woocommerce_order_data_meta_box($post) {
<?php
// Ajax Chosen Customer Selectors JS
$woocommerce->add_inline_js( "
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js( "
jQuery('select.ajax_chosen_select_customer').ajaxChosen({
method: 'GET',
url: '" . admin_url('admin-ajax.php') . "',

View File

@ -184,7 +184,7 @@ function woocommerce_order_downloads_meta_box() {
});
<?php
$javascript = ob_get_clean();
$woocommerce->add_inline_js( $javascript );
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js( $javascript );
}

View File

@ -211,7 +211,7 @@ function variable_product_type_options() {
$variation_selected_value = isset( $default_attributes[ sanitize_title( $attribute['name'] ) ] ) ? $default_attributes[ sanitize_title( $attribute['name'] ) ] : '';
// Name will be something like attribute_pa_color
echo '<select name="default_attribute_' . sanitize_title( $attribute['name'] ) . '"><option value="">' . __( 'No default', 'woocommerce' ) . ' ' . esc_html( $woocommerce->attribute_label( $attribute['name'] ) ) . '&hellip;</option>';
echo '<select name="default_attribute_' . sanitize_title( $attribute['name'] ) . '"><option value="">' . __( 'No default', 'woocommerce' ) . ' ' . esc_html( $woocommerce->get_helper( 'attribute' )->attribute_label( $attribute['name'] ) ) . '&hellip;</option>';
// Get terms for attribute taxonomy or value if its a custom attribute
if ( $attribute['is_taxonomy'] ) {
@ -616,7 +616,7 @@ function variable_product_type_options() {
});
<?php
$javascript = ob_get_clean();
$woocommerce->add_inline_js( $javascript );
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js( $javascript );
}
add_action('woocommerce_product_write_panels', 'variable_product_type_options');

View File

@ -333,7 +333,7 @@ function woocommerce_product_data_box() {
<?php
// Array of defined attribute taxonomies
$attribute_taxonomies = $woocommerce->get_attribute_taxonomies();
$attribute_taxonomies = $woocommerce->get_helper( 'attribute' )->get_attribute_taxonomies();
// Product attributes - taxonomies and custom, ordered, with visibility and variation attributes set
$attributes = maybe_unserialize( get_post_meta( $thepostid, '_product_attributes', true ) );
@ -345,7 +345,7 @@ function woocommerce_product_data_box() {
foreach ( $attribute_taxonomies as $tax ) { $i++;
// Get name of taxonomy we're now outputting (pa_xxx)
$attribute_taxonomy_name = $woocommerce->attribute_taxonomy_name( $tax->attribute_name );
$attribute_taxonomy_name = $woocommerce->get_helper( 'attribute' )->attribute_taxonomy_name( $tax->attribute_name );
// Ensure it exists
if ( ! taxonomy_exists( $attribute_taxonomy_name ) )
@ -504,7 +504,7 @@ function woocommerce_product_data_box() {
<?php
if ( $attribute_taxonomies ) {
foreach ( $attribute_taxonomies as $tax ) {
$attribute_taxonomy_name = $woocommerce->attribute_taxonomy_name( $tax->attribute_name );
$attribute_taxonomy_name = $woocommerce->get_helper( 'attribute' )->attribute_taxonomy_name( $tax->attribute_name );
$label = $tax->attribute_label ? $tax->attribute_label : $tax->attribute_name;
echo '<option value="' . esc_attr( $attribute_taxonomy_name ) . '">' . esc_html( $label ) . '</option>';
}
@ -890,7 +890,7 @@ function woocommerce_process_product_meta( $post_id, $post ) {
}
// Clear cache/transients
$woocommerce->clear_product_transients( $clear_id );
$woocommerce->get_helper( 'transient' )->clear_product_transients( $clear_id );
}
}
}
@ -1021,7 +1021,7 @@ function woocommerce_process_product_meta( $post_id, $post ) {
do_action( 'woocommerce_process_product_meta_' . $product_type, $post_id );
// Clear cache/transients
$woocommerce->clear_product_transients( $post_id );
$woocommerce->get_helper( 'transient' )->clear_product_transients( $post_id );
}
add_action('woocommerce_process_product_meta', 'woocommerce_process_product_meta', 1, 2);

View File

@ -80,7 +80,7 @@ function woocommerce_attributes() {
} elseif ( in_array( $attribute_name, $reserved_terms ) ) {
$error = sprintf( __( 'Slug “%s” is not allowed because it is a reserved term. Change it, please.', 'woocommerce' ), sanitize_title( $attribute_name ) );
} else {
$taxonomy_exists = taxonomy_exists( $woocommerce->attribute_taxonomy_name( $attribute_name ) );
$taxonomy_exists = taxonomy_exists( $woocommerce->get_helper( 'attribute' )->attribute_taxonomy_name( $attribute_name ) );
if ( 'add' === $action && $taxonomy_exists ) {
$error = sprintf( __( 'Slug “%s” is already in use. Change it, please.', 'woocommerce' ), sanitize_title( $attribute_name ) );
@ -130,7 +130,7 @@ function woocommerce_attributes() {
// Update taxonomies in the wp term taxonomy table
$wpdb->update(
$wpdb->term_taxonomy,
array( 'taxonomy' => $woocommerce->attribute_taxonomy_name( $attribute_name ) ),
array( 'taxonomy' => $woocommerce->get_helper( 'attribute' )->attribute_taxonomy_name( $attribute_name ) ),
array( 'taxonomy' => 'pa_' . $old_attribute_name )
);
@ -174,7 +174,7 @@ function woocommerce_attributes() {
if ( $attribute_name && $wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_id = $attribute_id" ) ) {
$taxonomy = $woocommerce->attribute_taxonomy_name( $attribute_name );
$taxonomy = $woocommerce->get_helper( 'attribute' )->attribute_taxonomy_name( $attribute_name );
if ( taxonomy_exists( $taxonomy ) ) {
$terms = get_terms( $taxonomy, 'orderby=name&hide_empty=0' );
@ -313,12 +313,12 @@ function woocommerce_add_attribute() {
</thead>
<tbody>
<?php
$attribute_taxonomies = $woocommerce->get_attribute_taxonomies();
$attribute_taxonomies = $woocommerce->get_helper( 'attribute' )->get_attribute_taxonomies();
if ( $attribute_taxonomies ) :
foreach ($attribute_taxonomies as $tax) :
?><tr>
<td><a href="edit-tags.php?taxonomy=<?php echo esc_html($woocommerce->attribute_taxonomy_name($tax->attribute_name)); ?>&amp;post_type=product"><?php echo esc_html( $tax->attribute_label ); ?></a>
<td><a href="edit-tags.php?taxonomy=<?php echo esc_html($woocommerce->get_helper( 'attribute' )->attribute_taxonomy_name($tax->attribute_name)); ?>&amp;post_type=product"><?php echo esc_html( $tax->attribute_label ); ?></a>
<div class="row-actions"><span class="edit"><a href="<?php echo esc_url( add_query_arg('edit', $tax->attribute_id, 'admin.php?page=woocommerce_attributes') ); ?>"><?php _e( 'Edit', 'woocommerce' ); ?></a> | </span><span class="delete"><a class="delete" href="<?php echo esc_url( wp_nonce_url( add_query_arg('delete', $tax->attribute_id, 'admin.php?page=woocommerce_attributes'), 'woocommerce-delete-attribute_' . $tax->attribute_id ) ); ?>"><?php _e( 'Delete', 'woocommerce' ); ?></a></span></div>
</td>
@ -338,9 +338,9 @@ function woocommerce_add_attribute() {
}
?></td>
<td><?php
if (taxonomy_exists($woocommerce->attribute_taxonomy_name($tax->attribute_name))) :
if (taxonomy_exists($woocommerce->get_helper( 'attribute' )->attribute_taxonomy_name($tax->attribute_name))) :
$terms_array = array();
$terms = get_terms( $woocommerce->attribute_taxonomy_name($tax->attribute_name), 'orderby=name&hide_empty=0' );
$terms = get_terms( $woocommerce->get_helper( 'attribute' )->attribute_taxonomy_name($tax->attribute_name), 'orderby=name&hide_empty=0' );
if ($terms) :
foreach ($terms as $term) :
$terms_array[] = $term->name;
@ -353,7 +353,7 @@ function woocommerce_add_attribute() {
echo '<span class="na">&ndash;</span>';
endif;
?></td>
<td><a href="edit-tags.php?taxonomy=<?php echo esc_html($woocommerce->attribute_taxonomy_name($tax->attribute_name)); ?>&amp;post_type=product" class="button alignright"><?php _e( 'Configure&nbsp;terms', 'woocommerce' ); ?></a></td>
<td><a href="edit-tags.php?taxonomy=<?php echo esc_html($woocommerce->get_helper( 'attribute' )->attribute_taxonomy_name($tax->attribute_name)); ?>&amp;post_type=product" class="button alignright"><?php _e( 'Configure&nbsp;terms', 'woocommerce' ); ?></a></td>
</tr><?php
endforeach;
else :

View File

@ -66,7 +66,7 @@ function woocommerce_dashboard_widget_right_now() {
$product_count = wp_count_posts( 'product' );
$product_cat_count = wp_count_terms( 'product_cat' );
$product_tag_count = wp_count_terms( 'product_tag' );
$product_attr_count = count( $woocommerce->get_attribute_taxonomies() );
$product_attr_count = count( $woocommerce->get_helper( 'attribute' )->get_attribute_taxonomies() );
$pending_count = get_term_by( 'slug', 'pending', 'shop_order_status' )->count;
$completed_count = get_term_by( 'slug', 'completed', 'shop_order_status' )->count;

View File

@ -105,12 +105,12 @@ function woocommerce_delete_post( $id ) {
wp_update_post( $child_post );
}
$woocommerce->clear_product_transients();
$woocommerce->get_helper( 'transient' )->clear_product_transients();
break;
case 'product_variation' :
$woocommerce->clear_product_transients();
$woocommerce->get_helper( 'transient' )->clear_product_transients();
break;
}

View File

@ -87,7 +87,7 @@ function do_install_woocommerce() {
}
// Clear transient cache
$woocommerce->clear_product_transients();
$woocommerce->get_helper( 'transient' )->clear_product_transients();
// Recompile LESS styles if they are custom
if ( get_option( 'woocommerce_frontend_css' ) == 'yes' ) {

View File

@ -134,7 +134,7 @@ if ( ! function_exists( 'woocommerce_settings' ) ) {
}
// Clear any unwanted data
$woocommerce->clear_product_transients();
$woocommerce->get_helper( 'transient' )->clear_product_transients();
delete_transient( 'woocommerce_cache_excluded_uris' );

View File

@ -578,7 +578,7 @@ function woocommerce_status_tools() {
switch ( $_GET['action'] ) {
case "clear_transients" :
$woocommerce->clear_product_transients();
$woocommerce->get_helper( 'transient' )->clear_product_transients();
echo '<div class="updated"><p>' . __( 'Product Transients Cleared', 'woocommerce' ) . '</p></div>';
break;

View File

@ -631,7 +631,7 @@ abstract class WC_Email extends WC_Settings_API {
?>
</div>
<?php
$woocommerce->add_inline_js("
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js("
jQuery('select.email_type').change(function(){
var val = jQuery( this ).val();

View File

@ -0,0 +1,4 @@
<?php
class WC_Helper {
}

View File

@ -171,7 +171,7 @@ class WC_Product {
elseif ( $this->backorders_allowed() || $this->get_total_stock() > 0 )
$this->set_stock_status( 'instock' );
$woocommerce->clear_product_transients( $this->id ); // Clear transient
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
return $this->get_stock_quantity();
}
@ -196,7 +196,7 @@ class WC_Product {
if ( ! $this->backorders_allowed() && $this->get_total_stock() <= 0 )
$this->set_stock_status( 'outofstock' );
$woocommerce->clear_product_transients( $this->id ); // Clear transient
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
return $this->get_stock_quantity();
}
@ -221,7 +221,7 @@ class WC_Product {
if ( $this->backorders_allowed() || $this->get_total_stock() > 0 )
$this->set_stock_status( 'instock' );
$woocommerce->clear_product_transients( $this->id ); // Clear transient
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
return $this->get_stock_quantity();
}

View File

@ -576,9 +576,9 @@ class WC_Cart {
}
if ( $flat )
$variation_list[] = $woocommerce->attribute_label( str_replace( 'attribute_', '', $name ) ) . ': ' . $value;
$variation_list[] = $woocommerce->get_helper( 'attribute' )->attribute_label( str_replace( 'attribute_', '', $name ) ) . ': ' . $value;
else
$variation_list[] = '<dt>' . $woocommerce->attribute_label( str_replace( 'attribute_', '', $name ) ) . ':</dt><dd>' . $value . '</dd>';
$variation_list[] = '<dt>' . $woocommerce->get_helper( 'attribute' )->attribute_label( str_replace( 'attribute_', '', $name ) ) . ':</dt><dd>' . $value . '</dd>';
}
@ -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) ) ) );
}
/**

View File

@ -340,7 +340,7 @@ class WC_Checkout {
public function process_checkout() {
global $wpdb, $woocommerce, $current_user;
$woocommerce->verify_nonce( 'process_checkout' );
$woocommerce->get_helper( 'nonce' )->verify_nonce( 'process_checkout' );
if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) )
define( 'WOOCOMMERCE_CHECKOUT', true );

View File

@ -61,9 +61,9 @@ class WC_Order_Item_Meta {
}
if ( $flat )
$meta_list[] = esc_attr( $woocommerce->attribute_label( str_replace( 'attribute_', '', $meta_key ) ) . ': ' . apply_filters( 'woocommerce_order_item_display_meta_value', $meta_value ) );
$meta_list[] = esc_attr( $woocommerce->get_helper( 'attribute' )->attribute_label( str_replace( 'attribute_', '', $meta_key ) ) . ': ' . apply_filters( 'woocommerce_order_item_display_meta_value', $meta_value ) );
else
$meta_list[] = '<dt>' . wp_kses_post( $woocommerce->attribute_label( str_replace( 'attribute_', '', $meta_key ) ) ) . ':</dt><dd>' . wp_kses_post( apply_filters( 'woocommerce_order_item_display_meta_value', $meta_value ) ) . '</dd>';
$meta_list[] = '<dt>' . wp_kses_post( $woocommerce->get_helper( 'attribute' )->attribute_label( str_replace( 'attribute_', '', $meta_key ) ) ) . ':</dt><dd>' . wp_kses_post( apply_filters( 'woocommerce_order_item_display_meta_value', $meta_value ) ) . '</dd>';
}
}

View File

@ -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() ))))));
}
/**

View File

@ -168,9 +168,9 @@ class WC_Post_types {
$wc_product_attributes = array();
if ( $attribute_taxonomies = $woocommerce->get_attribute_taxonomies() ) {
if ( $attribute_taxonomies = $woocommerce->get_helper( 'attribute' )->get_attribute_taxonomies() ) {
foreach ( $attribute_taxonomies as $tax ) {
if ( $name = $woocommerce->attribute_taxonomy_name( $tax->attribute_name ) ) {
if ( $name = $woocommerce->get_helper( 'attribute' )->attribute_taxonomy_name( $tax->attribute_name ) ) {
$label = ! empty( $tax->attribute_label ) ? $tax->attribute_label : $tax->attribute_name;

View File

@ -70,6 +70,6 @@ class WC_Product_Simple extends WC_Product {
}
}
$woocommerce->clear_product_transients( $this->id );
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id );
}
}

View File

@ -87,7 +87,7 @@ class WC_Product_Variable extends WC_Product {
elseif ( $this->backorders_allowed() || $this->get_total_stock() > 0 )
$this->set_stock_status( 'instock' );
$woocommerce->clear_product_transients( $this->id ); // Clear transient
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
return apply_filters( 'woocommerce_stock_amount', $this->stock );
}
@ -112,7 +112,7 @@ class WC_Product_Variable extends WC_Product {
if ( ! $this->backorders_allowed() && $this->get_total_stock() <= 0 )
$this->set_stock_status( 'outofstock' );
$woocommerce->clear_product_transients( $this->id ); // Clear transient
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
return apply_filters( 'woocommerce_stock_amount', $this->stock );
}
@ -138,7 +138,7 @@ class WC_Product_Variable extends WC_Product {
if ( $this->backorders_allowed() || $this->get_total_stock() > 0 )
$this->set_stock_status( 'instock' );
$woocommerce->clear_product_transients( $this->id ); // Clear transient
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
return apply_filters( 'woocommerce_stock_amount', $this->stock );
endif;
@ -507,7 +507,7 @@ class WC_Product_Variable extends WC_Product {
update_post_meta( $this->id, '_min_variation_sale_price', $this->min_variation_sale_price );
update_post_meta( $this->id, '_max_variation_sale_price', $this->max_variation_sale_price );
$woocommerce->clear_product_transients( $this->id );
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id );
}
}
}

View File

@ -297,7 +297,7 @@ class WC_Product_Variation extends WC_Product {
$this->stock = intval( $amount );
$this->total_stock = intval( $amount );
update_post_meta( $this->variation_id, '_stock', $this->stock );
$woocommerce->clear_product_transients( $this->id ); // Clear transient
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
// Check parents out of stock attribute
if ( ! $this->is_in_stock() ) {
@ -337,7 +337,7 @@ class WC_Product_Variation extends WC_Product {
$this->stock = $this->stock - $by;
$this->total_stock = $this->total_stock - $by;
update_post_meta( $this->variation_id, '_stock', $this->stock );
$woocommerce->clear_product_transients( $this->id ); // Clear transient
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
// Check parents out of stock attribute
if ( ! $this->is_in_stock() ) {
@ -375,7 +375,7 @@ class WC_Product_Variation extends WC_Product {
$this->stock = $this->stock + $by;
$this->total_stock = $this->total_stock + $by;
update_post_meta( $this->variation_id, '_stock', $this->stock );
$woocommerce->clear_product_transients( $this->id ); // Clear transient
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
// Parents out of stock attribute
if ( $this->is_in_stock() )

View File

@ -47,7 +47,7 @@ class WC_Shortcodes {
*/
public function cart( $atts ) {
global $woocommerce;
return $woocommerce->shortcode_wrapper( array( 'WC_Shortcode_Cart', 'output' ), $atts );
return $woocommerce->get_helper( 'shortcode' )->shortcode_wrapper( array( 'WC_Shortcode_Cart', 'output' ), $atts );
}
/**
@ -59,7 +59,7 @@ class WC_Shortcodes {
*/
public function checkout( $atts ) {
global $woocommerce;
return $woocommerce->shortcode_wrapper( array( 'WC_Shortcode_Checkout', 'output' ), $atts );
return $woocommerce->get_helper( 'shortcode' )->shortcode_wrapper( array( 'WC_Shortcode_Checkout', 'output' ), $atts );
}
/**
@ -71,7 +71,7 @@ class WC_Shortcodes {
*/
public function order_tracking( $atts ) {
global $woocommerce;
return $woocommerce->shortcode_wrapper( array( 'WC_Shortcode_Order_Tracking', 'output' ), $atts );
return $woocommerce->get_helper( 'shortcode' )->shortcode_wrapper( array( 'WC_Shortcode_Order_Tracking', 'output' ), $atts );
}
/**
@ -83,7 +83,7 @@ class WC_Shortcodes {
*/
public function my_account( $atts ) {
global $woocommerce;
return $woocommerce->shortcode_wrapper( array( 'WC_Shortcode_My_Account', 'output' ), $atts );
return $woocommerce->get_helper( 'shortcode' )->shortcode_wrapper( array( 'WC_Shortcode_My_Account', 'output' ), $atts );
}
/**
@ -95,7 +95,7 @@ class WC_Shortcodes {
*/
public function edit_address( $atts ) {
global $woocommerce;
return $woocommerce->shortcode_wrapper( array( 'WC_Shortcode_Edit_Address', 'output' ), $atts );
return $woocommerce->get_helper( 'shortcode' )->shortcode_wrapper( array( 'WC_Shortcode_Edit_Address', 'output' ), $atts );
}
/**
@ -107,7 +107,7 @@ class WC_Shortcodes {
*/
public function lost_password( $atts ) {
global $woocommerce;
return $woocommerce->shortcode_wrapper( array( 'WC_Shortcode_Lost_Password', 'output' ), $atts );
return $woocommerce->get_helper( 'shortcode' )->shortcode_wrapper( array( 'WC_Shortcode_Lost_Password', 'output' ), $atts );
}
/**

View File

@ -422,7 +422,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
$paypal_args_array[] = '<input type="hidden" name="'.esc_attr( $key ).'" value="'.esc_attr( $value ).'" />';
}
$woocommerce->add_inline_js( '
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js( '
$.blockUI({
message: "' . esc_js( __( 'Thank you for your order. We are now redirecting you to PayPal to make payment.', 'woocommerce' ) ) . '",
baseZ: 99999,

View File

@ -0,0 +1,96 @@
<?php
return new WC_Attribute_Helper();
class WC_Attribute_Helper extends WC_Helper {
/**
* Get attribute taxonomies.
*
* @access public
* @return object
*/
public function get_attribute_taxonomies() {
$transient_name = 'wc_attribute_taxonomies';
if ( false === ( $attribute_taxonomies = get_transient( $transient_name ) ) ) {
global $wpdb;
$attribute_taxonomies = $wpdb->get_results( "SELECT * FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies" );
set_transient( $transient_name, $attribute_taxonomies );
}
return apply_filters( 'woocommerce_attribute_taxonomies', $attribute_taxonomies );
}
/**
* Get a product attributes name.
*
* @access public
* @param mixed $name
* @return string
*/
public function attribute_taxonomy_name( $name ) {
return 'pa_' . woocommerce_sanitize_taxonomy_name( $name );
}
/**
* Get a product attributes label.
*
* @access public
* @param mixed $name
* @return string
*/
public function attribute_label( $name ) {
global $wpdb;
if ( taxonomy_is_product_attribute( $name ) ) {
$name = woocommerce_sanitize_taxonomy_name( str_replace( 'pa_', '', $name ) );
$label = $wpdb->get_var( $wpdb->prepare( "SELECT attribute_label FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name = %s;", $name ) );
if ( ! $label )
$label = ucfirst( $name );
} else {
$label = $name;
}
return apply_filters( 'woocommerce_attribute_label', $label, $name );
}
/**
* Get a product attributes orderby setting.
*
* @access public
* @param mixed $name
* @return string
*/
public function attribute_orderby( $name ) {
global $wpdb;
$name = str_replace( 'pa_', '', sanitize_title( $name ) );
$orderby = $wpdb->get_var( $wpdb->prepare( "SELECT attribute_orderby FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = %s;", $name ) );
return apply_filters( 'woocommerce_attribute_orderby', $orderby, $name );
}
/**
* Get an array of product attribute taxonomies.
*
* @access public
* @return array
*/
public function get_attribute_taxonomy_names() {
$taxonomy_names = array();
$attribute_taxonomies = $this->get_attribute_taxonomies();
if ( $attribute_taxonomies ) {
foreach ( $attribute_taxonomies as $tax ) {
$taxonomy_names[] = $this->attribute_taxonomy_name( $tax->attribute_name );
}
}
return $taxonomy_names;
}
}

View File

@ -0,0 +1,34 @@
<?php
return new WC_Body_Class_Helper();
class WC_Body_Class_Helper extends WC_Helper {
/**
* Add a class to the webpage body.
*
* @access public
* @param string $class
* @return void
*/
public function add_body_class( $class ) {
$this->_body_classes[] = sanitize_html_class( strtolower($class) );
}
/**
* Output classes on the body tag.
*
* @access public
* @param mixed $classes
* @return array
*/
public function output_body_class( $classes ) {
if ( sizeof( $this->_body_classes ) > 0 ) $classes = array_merge( $classes, $this->_body_classes );
if ( is_singular('product') ) {
$key = array_search( 'singular', $classes );
if ( $key !== false ) unset( $classes[$key] );
}
return $classes;
}
}

View File

@ -0,0 +1,34 @@
<?php
class WC_Coupon_Helper extends WC_Helper {
/**
* Get coupon types.
*
* @access public
* @return array
*/
public function get_coupon_discount_types() {
if ( ! isset( $this->coupon_discount_types ) ) {
$this->coupon_discount_types = apply_filters( 'woocommerce_coupon_discount_types', array(
'fixed_cart' => __( 'Cart Discount', 'woocommerce' ),
'percent' => __( 'Cart % Discount', 'woocommerce' ),
'fixed_product' => __( 'Product Discount', 'woocommerce' ),
'percent_product' => __( 'Product % Discount', 'woocommerce' )
) );
}
return $this->coupon_discount_types;
}
/**
* Get a coupon type's name.
*
* @access public
* @param string $type (default: '')
* @return string
*/
public function get_coupon_discount_type( $type = '' ) {
$types = (array) $this->get_coupon_discount_types();
if ( isset( $types[$type] ) ) return $types[$type];
}
}

View File

@ -0,0 +1,43 @@
<?php
return new WC_Inline_Javascript_Helper();
class WC_Inline_Javascript_Helper extends WC_Helper {
protected $_inline_js;
/**
* Add some JavaScript inline to be output in the footer.
*
* @access public
* @param string $code
* @return void
*/
public function add_inline_js( $code ) {
$this->_inline_js .= "\n" . $code . "\n";
}
/**
* Output any queued inline JS.
*
* @access public
* @return void
*/
public function output_inline_js() {
if ( $this->_inline_js ) {
echo "<!-- WooCommerce JavaScript-->\n<script type=\"text/javascript\">\njQuery(document).ready(function($) {";
// Sanitize
$this->_inline_js = wp_check_invalid_utf8( $this->_inline_js );
$this->_inline_js = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", $this->_inline_js );
$this->_inline_js = str_replace( "\r", '', $this->_inline_js );
// Output
echo $this->_inline_js;
echo "});\n</script>\n";
$this->_inline_js = '';
}
}
}

View File

@ -0,0 +1,59 @@
<?php
return new WC_Nonce_Helper();
class WC_Nonce_Helper extends WC_Helper {
/**
* 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.
*
* To fail silently, set the error_message to an empty string
*
* @access public
* @param string $name the nonce name
* @param string $action then nonce action
* @param string $method the http request method _POST, _GET or _REQUEST
* @param string $error_message custom error message, or false for default message, or an empty string to fail silently
* @return bool
*/
public function verify_nonce( $action, $method='_POST', $error_message = false ) {
$name = '_n';
$action = 'woocommerce-' . $action;
if ( $error_message === false ) $error_message = __( 'Action failed. Please refresh the page and retry.', 'woocommerce' );
if ( ! in_array( $method, array( '_GET', '_POST', '_REQUEST' ) ) ) $method = '_POST';
if ( isset($_REQUEST[$name] ) && wp_verify_nonce( $_REQUEST[$name], $action ) ) return true;
if ( $error_message ) $this->add_error( $error_message );
return false;
}
}

View File

@ -0,0 +1,31 @@
<?php
return new WC_Post_Class_Helper();
class WC_Post_Class_Helper extends WC_Helper {
/**
* Adds extra post classes for products
*
* @since 2.0
* @access public
* @param array $classes
* @param string|array $class
* @param int $post_id
* @return array
*/
public function post_class( $classes, $class, $post_id ) {
$product = get_product( $post_id );
if ( $product ) {
if ( $product->is_on_sale() ) {
$classes[] = 'sale';
}
if ( $product->is_featured() ) {
$classes[] = 'featured';
}
$classes[] = $product->stock_status;
}
return $classes;
}
}

View File

@ -0,0 +1,34 @@
<?php
return new WC_Shortcode_Helper();
class WC_Shortcode_Helper extends WC_Helper {
/**
* Shortcode Wrapper
*
* @access public
* @param mixed $function
* @param array $atts (default: array())
* @return string
*/
public function shortcode_wrapper(
$function,
$atts = array(),
$wrapper = array(
'class' => 'woocommerce',
'before' => null,
'after' => null
)
){
ob_start();
$before = empty( $wrapper['before'] ) ? '<div class="' . $wrapper['class'] . '">' : $wrapper['before'];
$after = empty( $wrapper['after'] ) ? '</div>' : $wrapper['after'];
echo $before;
call_user_func( $function, $atts );
echo $after;
return ob_get_clean();
}
}

View File

@ -0,0 +1,65 @@
<?php
return new WC_Transient_Helper();
class WC_Transient_Helper extends WC_Helper {
/**
* Clear all transients cache for product data.
*
* @access public
* @param int $post_id (default: 0)
* @return void
*/
public function clear_product_transients( $post_id = 0 ) {
global $wpdb;
$post_id = absint( $post_id );
$wpdb->show_errors();
// Clear core transients
$transients_to_clear = array(
'wc_products_onsale',
'wc_hidden_product_ids',
'wc_hidden_product_ids_search',
'wc_attribute_taxonomies',
'wc_term_counts'
);
foreach( $transients_to_clear as $transient ) {
delete_transient( $transient );
}
// Clear transients for which we don't have the name
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_uf_pid_%') OR `option_name` LIKE ('_transient_timeout_wc_uf_pid_%')" );
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_ln_count_%') OR `option_name` LIKE ('_transient_timeout_wc_ln_count_%')" );
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_ship_%') OR `option_name` LIKE ('_transient_timeout_wc_ship_%')" );
// Clear product specific transients
$post_transients_to_clear = array(
'wc_product_children_ids_',
'wc_product_total_stock_',
'wc_average_rating_',
'wc_rating_count_',
'woocommerce_product_type_', // No longer used
'wc_product_type_', // No longer used
);
if ( $post_id > 0 ) {
foreach( $post_transients_to_clear as $transient ) {
delete_transient( $transient . $post_id );
$wpdb->query( $wpdb->prepare( "DELETE FROM `$wpdb->options` WHERE `option_name` = %s OR `option_name` = %s", '_transient_' . $transient . $post_id, '_transient_timeout_' . $transient . $post_id ) );
}
clean_post_cache( $post_id );
} else {
foreach( $post_transients_to_clear as $transient ) {
$wpdb->query( $wpdb->prepare( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE %s OR `option_name` LIKE %s", '_transient_' . $transient . '%', '_transient_timeout_' . $transient . '%' ) );
}
}
}
}

View File

@ -311,7 +311,7 @@ class WC_Google_Analytics extends WC_Integration {
$parameters = apply_filters( 'woocommerce_ga_event_tracking_parameters', $parameters );
$woocommerce->add_inline_js("
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js("
$('" . $selector . "').click(function() {
" . sprintf( "_gaq.push(['_trackEvent', %s, %s, %s]);", $parameters['category'], $parameters['action'], $parameters['label'] ) . "
});

View File

@ -38,7 +38,7 @@ class WC_Shortcode_Cart {
$woocommerce->cart->remove_coupons( $_GET['remove_discounts'] );
// Update Shipping
} elseif ( ! empty( $_POST['calc_shipping'] ) && $woocommerce->verify_nonce('cart') ) {
} elseif ( ! empty( $_POST['calc_shipping'] ) && $woocommerce->get_helper( 'nonce' )->verify_nonce('cart') ) {
$validation = $woocommerce->validation();

View File

@ -0,0 +1,38 @@
<?php
/**
* Change Password Shortcode
*
* @author WooThemes
* @category Shortcodes
* @package WooCommerce/Shortcodes/Change_Password
* @version 2.0.0
*/
class WC_Shortcode_Change_Password {
/**
* Get the shortcode content.
*
* @access public
* @param array $atts
* @return string
*/
public static function get( $atts ) {
global $woocommerce;
return $woocommerce->get_helper( 'shortcode' )->shortcode_wrapper( array( __CLASS__, 'output' ), $atts );
}
/**
* Output the shortcode.
*
* @access public
* @param array $atts
* @return void
*/
public static function output( $atts ) {
global $woocommerce;
if ( ! is_user_logged_in() ) return;
woocommerce_get_template( 'myaccount/form-change-password.php' );
}
}

View File

@ -21,7 +21,7 @@ class WC_Shortcode_Checkout {
*/
public static function get( $atts ) {
global $woocommerce;
return $woocommerce->shortcode_wrapper( array( __CLASS__, 'output' ), $atts );
return $woocommerce->get_helper( 'shortcode' )->shortcode_wrapper( array( __CLASS__, 'output' ), $atts );
}
/**

View File

@ -23,7 +23,7 @@ class WC_Shortcode_Edit_Address {
*/
public static function get( $atts ) {
global $woocommerce;
return $woocommerce->shortcode_wrapper( array( __CLASS__, 'output' ), $atts );
return $woocommerce->get_helper( 'shortcode' )->shortcode_wrapper( array( __CLASS__, 'output' ), $atts );
}
/**

View File

@ -21,7 +21,7 @@ class WC_Shortcode_Lost_Password {
*/
public static function get( $atts ) {
global $woocommerce;
return $woocommerce->shortcode_wrapper( array( __CLASS__, 'output' ), $atts );
return $woocommerce->get_helper( 'shortcode' )->shortcode_wrapper( array( __CLASS__, 'output' ), $atts );
}
/**
@ -42,7 +42,7 @@ class WC_Shortcode_Lost_Password {
// process lost password form
if( isset( $_POST['user_login'] ) ) {
$woocommerce->verify_nonce( 'lost_password' );
$woocommerce->get_helper( 'nonce' )->verify_nonce( 'lost_password' );
self::retrieve_password();
}
@ -72,7 +72,7 @@ class WC_Shortcode_Lost_Password {
$args['key'] = esc_attr( $_POST['reset_key'] );
$args['login'] = esc_attr( $_POST['reset_login'] );
$woocommerce->verify_nonce( 'reset_password' );
$woocommerce->get_helper( 'nonce' )->verify_nonce( 'reset_password' );
if( empty( $_POST['password_1'] ) || empty( $_POST['password_2'] ) ) {
$woocommerce->add_error( __( 'Please enter your password.', 'woocommerce' ) );

View File

@ -20,7 +20,7 @@ class WC_Shortcode_My_Account {
*/
public static function get( $atts ) {
global $woocommerce;
return $woocommerce->shortcode_wrapper( array( __CLASS__, 'output' ), $atts );
return $woocommerce->get_helper( 'shortcode' )->shortcode_wrapper( array( __CLASS__, 'output' ), $atts );
}
/**

View File

@ -21,7 +21,7 @@ class WC_Shortcode_Order_Tracking {
*/
public static function get( $atts ) {
global $woocommerce;
return $woocommerce->shortcode_wrapper( array( __CLASS__, 'output' ), $atts );
return $woocommerce->get_helper( 'shortcode' )->shortcode_wrapper( array( __CLASS__, 'output' ), $atts );
}
/**
@ -41,7 +41,7 @@ class WC_Shortcode_Order_Tracking {
if ( ! empty( $_REQUEST['orderid'] ) ) {
$woocommerce->verify_nonce( 'order_tracking' );
$woocommerce->get_helper( 'nonce' )->verify_nonce( 'order_tracking' );
$order_id = empty( $_REQUEST['orderid'] ) ? 0 : esc_attr( $_REQUEST['orderid'] );
$order_email = empty( $_REQUEST['order_email'] ) ? '' : esc_attr( $_REQUEST['order_email']) ;

View File

@ -0,0 +1,87 @@
<?php
/**
* View_Order Shortcode
*
* @author WooThemes
* @category Shortcodes
* @package WooCommerce/Shortcodes/View_Order
* @version 2.0.0
*/
class WC_Shortcode_View_Order {
/**
* Get the shortcode content.
*
* @access public
* @param array $atts
* @return string
*/
public static function get( $atts ) {
global $woocommerce;
return $woocommerce->get_helper( 'shortcode' )->shortcode_wrapper( array( __CLASS__, 'output' ), $atts );
}
/**
* Output the shortcode.
*
* @access public
* @param array $atts
* @return void
*/
public static function output( $atts ) {
global $woocommerce;
if ( ! is_user_logged_in() ) return;
extract( shortcode_atts( array(
'order_count' => 10
), $atts ) );
$user_id = get_current_user_id();
$order_id = ( isset( $_GET['order'] ) ) ? $_GET['order'] : 0;
$order = new WC_Order( $order_id );
if ( $order_id == 0 ) {
woocommerce_get_template( 'myaccount/my-orders.php', array( 'order_count' => 'all' == $order_count ? -1 : $order_count ) );
return;
}
if ( $order->user_id != $user_id ) {
echo '<div class="woocommerce-error">' . __( 'Invalid order.', 'woocommerce' ) . ' <a href="'.get_permalink( woocommerce_get_page_id('myaccount') ).'">'. __( 'My Account &rarr;', 'woocommerce' ) .'</a>' . '</div>';
return;
}
$status = get_term_by('slug', $order->status, 'shop_order_status');
echo '<p class="order-info">'
. sprintf( __( 'Order <mark class="order-number">%s</mark> made on <mark class="order-date">%s</mark>', 'woocommerce'), $order->get_order_number(), date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ) )
. '. ' . sprintf( __( 'Order status: <mark class="order-status">%s</mark>', 'woocommerce' ), __( $status->name, 'woocommerce' ) )
. '.</p>';
$notes = $order->get_customer_order_notes();
if ($notes) :
?>
<h2><?php _e( 'Order Updates', 'woocommerce' ); ?></h2>
<ol class="commentlist notes">
<?php foreach ($notes as $note) : ?>
<li class="comment note">
<div class="comment_container">
<div class="comment-text">
<p class="meta"><?php echo date_i18n(__( 'l jS \of F Y, h:ia', 'woocommerce' ), strtotime($note->comment_date)); ?></p>
<div class="description">
<?php echo wpautop(wptexturize($note->comment_content)); ?>
</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</li>
<?php endforeach; ?>
</ol>
<?php
endif;
do_action( 'woocommerce_view_order', $order_id );
}
}

View File

@ -25,10 +25,10 @@ class WC_Widget_Layered_Nav extends WC_Widget {
$this->widget_name = __( 'WooCommerce Layered Nav', 'woocommerce' );
$attribute_array = array();
$attribute_taxonomies = $woocommerce->get_attribute_taxonomies();
$attribute_taxonomies = $woocommerce->get_helper( 'attribute' )->get_attribute_taxonomies();
if ( $attribute_taxonomies )
foreach ( $attribute_taxonomies as $tax )
if ( taxonomy_exists( $woocommerce->attribute_taxonomy_name( $tax->attribute_name ) ) )
if ( taxonomy_exists( $woocommerce->get_helper( 'attribute' )->attribute_taxonomy_name( $tax->attribute_name ) ) )
$attribute_array[ $tax->attribute_name ] = $tax->attribute_name;
$this->settings = array(
@ -86,7 +86,7 @@ class WC_Widget_Layered_Nav extends WC_Widget {
$current_tax = $_attributes_array && is_tax( $_attributes_array ) ? get_queried_object()->taxonomy : '';
$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
$taxonomy = $woocommerce->attribute_taxonomy_name($instance['attribute']);
$taxonomy = $woocommerce->get_helper( 'attribute' )->attribute_taxonomy_name($instance['attribute']);
$query_type = isset( $instance['query_type'] ) ? $instance['query_type'] : 'and';
$display_type = isset( $instance['display_type'] ) ? $instance['display_type'] : 'list';
@ -123,7 +123,7 @@ class WC_Widget_Layered_Nav extends WC_Widget {
echo '<select id="dropdown_layered_nav_' . $taxonomy_filter . '">';
echo '<option value="">' . sprintf( __( 'Any %s', 'woocommerce' ), $woocommerce->attribute_label( $taxonomy ) ) .'</option>';
echo '<option value="">' . sprintf( __( 'Any %s', 'woocommerce' ), $woocommerce->get_helper( 'attribute' )->attribute_label( $taxonomy ) ) .'</option>';
foreach ( $terms as $term ) {
@ -169,7 +169,7 @@ class WC_Widget_Layered_Nav extends WC_Widget {
echo '</select>';
$woocommerce->add_inline_js("
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js("
jQuery('#dropdown_layered_nav_$taxonomy_filter').change(function(){

View File

@ -135,7 +135,7 @@ $woocommerce->show_messages();
<?php do_action('woocommerce_proceed_to_checkout'); ?>
<?php $woocommerce->nonce_field('cart') ?>
<?php $woocommerce->get_helper( 'nonce' )->nonce_field('cart') ?>
</td>
</tr>

View File

@ -84,7 +84,7 @@ if ( get_option('woocommerce_enable_shipping_calc')=='no' || ! $woocommerce->car
<p><button type="submit" name="calc_shipping" value="1" class="button"><?php _e( 'Update Totals', 'woocommerce' ); ?></button></p>
<?php $woocommerce->nonce_field('cart') ?>
<?php $woocommerce->get_helper( 'nonce' )->nonce_field('cart') ?>
</section>
</form>

View File

@ -83,7 +83,7 @@ global $woocommerce;
<?php endif; ?>
<div class="form-row">
<?php $woocommerce->nonce_field('pay')?>
<?php $woocommerce->get_helper( 'nonce' )->nonce_field('pay')?>
<input type="submit" class="button alt" id="place_order" value="<?php _e( 'Pay for order', 'woocommerce' ); ?>" />
<input type="hidden" name="woocommerce_pay" value="1" />
</div>

View File

@ -184,7 +184,7 @@ $available_methods = $woocommerce->shipping->get_available_shipping_methods();
<noscript><?php _e( 'Since your browser does not support JavaScript, or it is disabled, please ensure you click the <em>Update Totals</em> button before placing your order. You may be charged more than the amount stated above if you fail to do so.', 'woocommerce' ); ?><br/><input type="submit" class="button alt" name="woocommerce_checkout_update_totals" value="<?php _e( 'Update totals', 'woocommerce' ); ?>" /></noscript>
<?php $woocommerce->nonce_field('process_checkout')?>
<?php $woocommerce->get_helper( 'nonce' )->nonce_field('process_checkout')?>
<?php do_action( 'woocommerce_review_order_before_submit' ); ?>

View File

@ -0,0 +1,34 @@
<?php
/**
* Change password form
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $woocommerce;
?>
<?php $woocommerce->show_messages(); ?>
<form action="<?php echo esc_url( get_permalink(woocommerce_get_page_id('change_password')) ); ?>" method="post">
<p class="form-row form-row-first">
<label for="password_1"><?php _e( 'New password', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="password" class="input-text" name="password_1" id="password_1" />
</p>
<p class="form-row form-row-last">
<label for="password_2"><?php _e( 'Re-enter new password', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="password" class="input-text" name="password_2" id="password_2" />
</p>
<div class="clear"></div>
<p><input type="submit" class="button" name="change_password" value="<?php _e( 'Save', 'woocommerce' ); ?>" /></p>
<?php $woocommerce->get_helper( 'nonce' )->nonce_field('change_password')?>
<input type="hidden" name="action" value="change_password" />
</form>

View File

@ -41,7 +41,7 @@ get_currentuserinfo();
<p>
<input type="submit" class="button" name="save_address" value="<?php _e( 'Save Address', 'woocommerce' ); ?>" />
<?php $woocommerce->nonce_field('edit_address') ?>
<?php $woocommerce->get_helper( 'nonce' )->nonce_field('edit_address') ?>
<input type="hidden" name="action" value="edit_address" />
</p>

View File

@ -36,7 +36,7 @@ global $woocommerce; ?>
</p>
<p class="form-row">
<?php $woocommerce->nonce_field('login', 'login') ?>
<?php $woocommerce->get_helper( 'nonce' )->nonce_field('login', 'login') ?>
<input type="submit" class="button" name="login" value="<?php _e( 'Login', 'woocommerce' ); ?>" /> <a class="lost_password" href="<?php
$lost_password_page_id = woocommerce_get_page_id( 'lost_password' );
@ -85,7 +85,7 @@ global $woocommerce; ?>
<?php do_action( 'register_form' ); ?>
<p class="form-row">
<?php $woocommerce->nonce_field('register', 'register') ?>
<?php $woocommerce->get_helper( 'nonce' )->nonce_field('register', 'register') ?>
<input type="submit" class="button" name="register" value="<?php _e( 'Register', 'woocommerce' ); ?>" />
</p>
</form>

View File

@ -43,6 +43,6 @@ global $woocommerce, $post;
<div class="clear"></div>
<p class="form-row"><input type="submit" class="button" name="reset" value="<?php echo 'lost_password' == $args['form'] ? __( 'Reset Password', 'woocommerce' ) : __( 'Save', 'woocommerce' ); ?>" /></p>
<?php $woocommerce->nonce_field( $args['form'] ); ?>
<?php $woocommerce->get_helper( 'nonce' )->nonce_field( $args['form'] ); ?>
</form>

View File

@ -21,6 +21,6 @@ global $woocommerce, $post;
<div class="clear"></div>
<p class="form-row"><input type="submit" class="button" name="track" value="<?php _e( 'Track', 'woocommerce' ); ?>" /></p>
<?php $woocommerce->nonce_field('order_tracking') ?>
<?php $woocommerce->get_helper( 'nonce' )->nonce_field('order_tracking') ?>
</form>

View File

@ -27,7 +27,7 @@ if (is_user_logged_in()) return;
<div class="clear"></div>
<p class="form-row">
<?php $woocommerce->nonce_field('login', 'login') ?>
<?php $woocommerce->get_helper( 'nonce' )->nonce_field('login', 'login') ?>
<input type="submit" class="button" name="login" value="<?php _e( 'Login', 'woocommerce' ); ?>" />
<input type="hidden" name="redirect" value="<?php echo esc_url( $redirect ) ?>" />
<a class="lost_password" href="<?php echo esc_url( wp_lostpassword_url( home_url() ) ); ?>"><?php _e( 'Lost Password?', 'woocommerce' ); ?></a>

View File

@ -104,7 +104,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
}
$comment_form['comment_field'] .= '<p class="comment-form-comment"><label for="comment">' . __( 'Your Review', 'woocommerce' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>' . $woocommerce->nonce_field('comment_rating', true, false);
$comment_form['comment_field'] .= '<p class="comment-form-comment"><label for="comment">' . __( 'Your Review', 'woocommerce' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>' . $woocommerce->get_helper( 'nonce' )->nonce_field('comment_rating', true, false);
comment_form( apply_filters( 'woocommerce_product_review_comment_form_args', $comment_form ) );

View File

@ -19,7 +19,7 @@ global $woocommerce, $product, $post;
<tbody>
<?php $loop = 0; foreach ( $attributes as $name => $options ) : $loop++; ?>
<tr>
<td class="label"><label for="<?php echo sanitize_title($name); ?>"><?php echo $woocommerce->attribute_label( $name ); ?></label></td>
<td class="label"><label for="<?php echo sanitize_title($name); ?>"><?php echo $woocommerce->get_helper( 'attribute' )->attribute_label( $name ); ?></label></td>
<td class="value"><select id="<?php echo esc_attr( sanitize_title($name) ); ?>" name="attribute_<?php echo sanitize_title($name); ?>">
<option value=""><?php echo __( 'Choose an option', 'woocommerce' ) ?>&hellip;</option>
<?php
@ -33,7 +33,7 @@ global $woocommerce, $product, $post;
// Get terms if this is a taxonomy - ordered
if ( taxonomy_exists( $name ) ) {
$orderby = $woocommerce->attribute_orderby( $name );
$orderby = $woocommerce->get_helper( 'attribute' )->attribute_orderby( $name );
switch ( $orderby ) {
case 'name' :

View File

@ -49,7 +49,7 @@ if ( empty( $attributes ) && ( ! $product->enable_dimensions_display() || ( ! $p
?>
<tr class="<?php if ( ( $alt = $alt * -1 ) == 1 ) echo 'alt'; ?>">
<th><?php echo $woocommerce->attribute_label( $attribute['name'] ); ?></th>
<th><?php echo $woocommerce->get_helper( 'attribute' )->attribute_label( $attribute['name'] ); ?></th>
<td><?php
if ( $attribute['is_taxonomy'] ) {

View File

@ -744,7 +744,7 @@ function woocommerce_link_all_variations() {
break;
}
$woocommerce->clear_product_transients( $post_id );
$woocommerce->get_helper( 'transient' )->clear_product_transients( $post_id );
echo $added;

View File

@ -1061,9 +1061,9 @@ function woocommerce_get_formatted_variation( $variation = '', $flat = false ) {
}
if ( $flat )
$variation_list[] = $woocommerce->attribute_label(str_replace('attribute_', '', $name)).': '.$value;
$variation_list[] = $woocommerce->get_helper( 'attribute' )->attribute_label(str_replace('attribute_', '', $name)).': '.$value;
else
$variation_list[] = '<dt>'.$woocommerce->attribute_label(str_replace('attribute_', '', $name)).':</dt><dd>'.$value.'</dd>';
$variation_list[] = '<dt>'.$woocommerce->get_helper( 'attribute' )->attribute_label(str_replace('attribute_', '', $name)).':</dt><dd>'.$value.'</dd>';
}
if ( $flat )
@ -2482,7 +2482,7 @@ function woocommerce_scheduled_sales() {
update_post_meta( $product_id, '_sale_price_dates_to', '' );
}
$woocommerce->clear_product_transients( $product_id );
$woocommerce->get_helper( 'transient' )->clear_product_transients( $product_id );
$parent = wp_get_post_parent_id( $product_id );
@ -2496,7 +2496,7 @@ function woocommerce_scheduled_sales() {
if ( $this_product->is_type( 'simple' ) )
$this_product->grouped_product_sync();
$woocommerce->clear_product_transients( $parent );
$woocommerce->get_helper( 'transient' )->clear_product_transients( $parent );
}
}
}
@ -2523,7 +2523,7 @@ function woocommerce_scheduled_sales() {
update_post_meta( $product_id, '_sale_price_dates_from', '' );
update_post_meta( $product_id, '_sale_price_dates_to', '' );
$woocommerce->clear_product_transients( $product_id );
$woocommerce->get_helper( 'transient' )->clear_product_transients( $product_id );
$parent = wp_get_post_parent_id( $product_id );
@ -2537,7 +2537,7 @@ function woocommerce_scheduled_sales() {
if ( $this_product->is_type( 'simple' ) )
$this_product->grouped_product_sync();
$woocommerce->clear_product_transients( $parent );
$woocommerce->get_helper( 'transient' )->clear_product_transients( $parent );
}
}
}

View File

@ -211,7 +211,7 @@ function woocommerce_update_cart_action() {
global $woocommerce;
// Remove from cart
if ( isset($_GET['remove_item']) && $_GET['remove_item'] && $woocommerce->verify_nonce('cart', '_GET')) {
if ( isset($_GET['remove_item']) && $_GET['remove_item'] && $woocommerce->get_helper( 'nonce' )->verify_nonce('cart', '_GET')) {
$woocommerce->cart->set_quantity( $_GET['remove_item'], 0 );
@ -222,7 +222,7 @@ function woocommerce_update_cart_action() {
exit;
// Update Cart
} elseif ( ( ! empty( $_POST['update_cart'] ) || ! empty( $_POST['proceed'] ) ) && $woocommerce->verify_nonce('cart')) {
} elseif ( ( ! empty( $_POST['update_cart'] ) || ! empty( $_POST['proceed'] ) ) && $woocommerce->get_helper( 'nonce' )->verify_nonce('cart')) {
$cart_totals = isset( $_POST['cart'] ) ? $_POST['cart'] : '';
@ -567,7 +567,7 @@ function woocommerce_checkout_action() {
function woocommerce_pay_action() {
global $woocommerce, $wp;
if ( isset( $_POST['woocommerce_pay'] ) && $woocommerce->verify_nonce( 'pay' ) ) {
if ( isset( $_POST['woocommerce_pay'] ) && $woocommerce->get_helper( 'nonce' )->verify_nonce( 'pay' ) ) {
ob_start();
@ -644,7 +644,7 @@ function woocommerce_process_login() {
if ( ! empty( $_POST['login'] ) ) {
$woocommerce->verify_nonce( 'login' );
$woocommerce->get_helper( 'nonce' )->verify_nonce( 'login' );
try {
$creds = array();
@ -711,6 +711,8 @@ function woocommerce_create_new_customer( $email, $username = '', $password = ''
if ( email_exists( $email ) )
return new WP_Error( "registration-error", __( "An account is already registered with your email address. Please login.", "woocommerce" ) );
$woocommerce->get_helper( 'nonce' )->verify_nonce( 'register' );
// Handle username creation
if ( get_option( 'woocommerce_registration_generate_username' ) == 'no' || ! empty( $username ) ) {
@ -862,7 +864,7 @@ function woocommerce_order_again() {
global $woocommerce;
// Nothing to do
if ( ! isset( $_GET['order_again'] ) || ! is_user_logged_in() || ! $woocommerce->verify_nonce( 'order_again', '_GET' ) )
if ( ! isset( $_GET['order_again'] ) || ! is_user_logged_in() || ! $woocommerce->verify_nonce( 'order_again', '_GET' ) || ! $woocommerce->get_helper( 'nonce' )->verify_nonce( 'order_again', '_GET' ) )
return;
// Clear current cart
@ -927,7 +929,7 @@ function woocommerce_cancel_order() {
$order = new WC_Order( $order_id );
if ( $order->id == $order_id && $order->order_key == $order_key && in_array( $order->status, array( 'pending', 'failed' ) ) && $woocommerce->verify_nonce( 'cancel_order', '_GET' ) ) :
if ( $order->id == $order_id && $order->order_key == $order_key && in_array( $order->status, array( 'pending', 'failed' ) ) && $woocommerce->get_helper( 'nonce' )->verify_nonce( 'cancel_order', '_GET' ) ) :
// Cancel the order + restore stock
$order->cancel_order( __('Order cancelled by customer.', 'woocommerce' ) );
@ -1301,7 +1303,7 @@ function woocommerce_check_comment_rating( $comment_data ) {
global $woocommerce;
// If posting a comment (not trackback etc) and not logged in
if ( isset( $_POST['rating'] ) && ! $woocommerce->verify_nonce('comment_rating') )
if ( isset( $_POST['rating'] ) && ! $woocommerce->get_helper( 'nonce' )->verify_nonce('comment_rating') )
wp_die( __( 'You have taken too long. Please go back and refresh the page.', 'woocommerce' ) );
elseif ( isset( $_POST['rating'] ) && empty( $_POST['rating'] ) && $comment_data['comment_type'] == '' && get_option('woocommerce_review_rating_required') == 'yes' ) {
@ -1373,12 +1375,12 @@ function woocommerce_layered_nav_init( ) {
$_chosen_attributes = $_attributes_array = array();
$attribute_taxonomies = $woocommerce->get_attribute_taxonomies();
$attribute_taxonomies = $woocommerce->get_helper( 'attribute' )->get_attribute_taxonomies();
if ( $attribute_taxonomies ) {
foreach ( $attribute_taxonomies as $tax ) {
$attribute = sanitize_title( $tax->attribute_name );
$taxonomy = $woocommerce->attribute_taxonomy_name( $attribute );
$taxonomy = $woocommerce->get_helper( 'attribute' )->attribute_taxonomy_name( $attribute );
// create an array of product attribute taxonomies
$_attributes_array[] = $taxonomy;
@ -1586,7 +1588,7 @@ function woocommerce_save_account_details() {
if ( empty( $_POST[ 'action' ] ) || ( 'save_account_details' !== $_POST[ 'action' ] ) )
return;
$woocommerce->verify_nonce( 'save_account_details' );
$woocommerce->get_helper( 'nonce' )->verify_nonce( 'save_account_details' );
$update = true;
$errors = new WP_Error();
@ -1664,7 +1666,7 @@ function woocommerce_save_address() {
if ( empty( $_POST[ 'action' ] ) || ( 'edit_address' !== $_POST[ 'action' ] ) )
return;
$woocommerce->verify_nonce( 'edit_address' );
$woocommerce->get_helper( 'nonce' )->verify_nonce( 'edit_address' );
$validation = $woocommerce->validation();

View File

@ -310,6 +310,7 @@ class Woocommerce {
include_once( 'classes/class-wc-api.php' );
// Include abstract classes
include_once( 'classes/abstracts/abstract-wc-helper.php' ); // Helper classes
include_once( 'classes/abstracts/abstract-wc-product.php' ); // Products
include_once( 'classes/abstracts/abstract-wc-settings-api.php' ); // Settings API (for gateways, shipping, and integrations)
include_once( 'classes/abstracts/abstract-wc-shipping-method.php' ); // A Shipping method
@ -328,6 +329,15 @@ class Woocommerce {
include_once( 'classes/integrations/sharedaddy/class-wc-sharedaddy.php' );
}
// Temporarily staying here until there is a better spot
// And this needs to be optimized/sanitized as well
public function get_helper( $id ) {
if ( ! isset( $this->helpers[ $id ] ) ) {
$this->helpers[ $id ] = include( 'classes/helpers/class-wc-' . $id . '-helper.php' );
}
return $this->helpers[ $id ];
}
/**
* Include required admin files.
@ -467,6 +477,9 @@ class Woocommerce {
$this->countries = new WC_Countries(); // Countries class
$this->integrations = new WC_Integrations(); // Integrations class
// Helpers blank array
$this->helpers = array();
// Classes/actions loaded for the frontend and for ajax requests
if ( ! is_admin() || defined('DOING_AJAX') ) {
@ -492,9 +505,9 @@ class Woocommerce {
add_action( 'wp_print_scripts', array( $this, 'check_jquery' ), 25 );
add_action( 'wp_head', array( $this, 'generator' ) );
add_action( 'wp_head', array( $this, 'wp_head' ) );
add_filter( 'body_class', array( $this, 'output_body_class' ) );
add_filter( 'post_class', array( $this, 'post_class' ), 20, 3 );
add_action( 'wp_footer', array( $this, 'output_inline_js' ), 25 );
add_filter( 'body_class', array( $this->get_helper( 'body-class' ), 'output_body_class' ) );
add_filter( 'post_class', array( $this->get_help( 'post-class' ), 'post_class' ), 20, 3 );
add_action( 'wp_footer', array( $this->get_helper( 'inline-javascript' ), 'output_inline_js' ), 25 );
// HTTPS urls with SSL on
$filters = array( 'post_thumbnail_html', 'widget_text', 'wp_get_attachment_url', 'wp_get_attachment_image_attributes', 'wp_get_attachment_url', 'option_stylesheet_url', 'option_template_url', 'script_loader_src', 'style_loader_src', 'template_directory_uri', 'stylesheet_directory_uri', 'site_url' );
@ -505,7 +518,7 @@ class Woocommerce {
// Actions
add_action( 'the_post', array( $this, 'setup_product_data' ) );
add_action( 'admin_footer', array( $this, 'output_inline_js' ), 25 );
add_action( 'admin_footer', array( $this->get_helper( 'inline-javascript' ), 'output_inline_js' ), 25 );
// Email Actions
$email_actions = array( 'woocommerce_low_stock', 'woocommerce_no_stock', 'woocommerce_product_on_backorder', 'woocommerce_order_status_pending_to_processing', 'woocommerce_order_status_pending_to_completed', 'woocommerce_order_status_pending_to_on-hold', 'woocommerce_order_status_failed_to_processing', 'woocommerce_order_status_failed_to_completed', 'woocommerce_order_status_completed', 'woocommerce_new_customer_note', 'woocommerce_created_customer' );
@ -722,26 +735,26 @@ class Woocommerce {
public function wp_head() {
if ( is_woocommerce() ) {
$this->add_body_class( 'woocommerce' );
$this->add_body_class( 'woocommerce-page' );
$this->get_helper( 'body-class' )->add_body_class( 'woocommerce' );
$this->get_helper( 'body-class' )->add_body_class( 'woocommerce-page' );
return;
}
if ( is_checkout() ) {
$this->add_body_class( 'woocommerce-checkout' );
$this->add_body_class( 'woocommerce-page' );
$this->get_helper( 'body-class' )->add_body_class( 'woocommerce-checkout' );
$this->get_helper( 'body-class' )->add_body_class( 'woocommerce-page' );
return;
}
if ( is_cart() ) {
$this->add_body_class( 'woocommerce-cart' );
$this->add_body_class( 'woocommerce-page' );
$this->get_helper( 'body-class' )->add_body_class( 'woocommerce-cart' );
$this->get_helper( 'body-class' )->add_body_class( 'woocommerce-page' );
return;
}
if ( is_account_page() ) {
$this->add_body_class( 'woocommerce-account' );
$this->add_body_class( 'woocommerce-page' );
$this->get_helper( 'body-class' )->add_body_class( 'woocommerce-account' );
$this->get_helper( 'body-class' )->add_body_class( 'woocommerce-page' );
return;
}
@ -1205,379 +1218,6 @@ class Woocommerce {
return apply_filters( 'woocommerce_redirect', $location );
}
/** Attribute Helpers ****************************************************************/
/**
* Get attribute taxonomies.
*
* @access public
* @return object
*/
public function get_attribute_taxonomies() {
$transient_name = 'wc_attribute_taxonomies';
if ( false === ( $attribute_taxonomies = get_transient( $transient_name ) ) ) {
global $wpdb;
$attribute_taxonomies = $wpdb->get_results( "SELECT * FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies" );
set_transient( $transient_name, $attribute_taxonomies );
}
return apply_filters( 'woocommerce_attribute_taxonomies', $attribute_taxonomies );
}
/**
* Get a product attributes name.
*
* @access public
* @param mixed $name
* @return string
*/
public function attribute_taxonomy_name( $name ) {
return 'pa_' . woocommerce_sanitize_taxonomy_name( $name );
}
/**
* Get a product attributes label.
*
* @access public
* @param mixed $name
* @return string
*/
public function attribute_label( $name ) {
global $wpdb;
if ( taxonomy_is_product_attribute( $name ) ) {
$name = woocommerce_sanitize_taxonomy_name( str_replace( 'pa_', '', $name ) );
$label = $wpdb->get_var( $wpdb->prepare( "SELECT attribute_label FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name = %s;", $name ) );
if ( ! $label )
$label = ucfirst( $name );
} else {
$label = $name;
}
return apply_filters( 'woocommerce_attribute_label', $label, $name );
}
/**
* Get a product attributes orderby setting.
*
* @access public
* @param mixed $name
* @return string
*/
public function attribute_orderby( $name ) {
global $wpdb;
$name = str_replace( 'pa_', '', sanitize_title( $name ) );
$orderby = $wpdb->get_var( $wpdb->prepare( "SELECT attribute_orderby FROM " . $wpdb->prefix . "woocommerce_attribute_taxonomies WHERE attribute_name = %s;", $name ) );
return apply_filters( 'woocommerce_attribute_orderby', $orderby, $name );
}
/**
* Get an array of product attribute taxonomies.
*
* @access public
* @return array
*/
public function get_attribute_taxonomy_names() {
$taxonomy_names = array();
$attribute_taxonomies = $this->get_attribute_taxonomies();
if ( $attribute_taxonomies ) {
foreach ( $attribute_taxonomies as $tax ) {
$taxonomy_names[] = $this->attribute_taxonomy_name( $tax->attribute_name );
}
}
return $taxonomy_names;
}
/** Coupon Helpers ********************************************************/
/**
* Get coupon types.
*
* @access public
* @return array
*/
public function get_coupon_discount_types() {
if ( ! isset( $this->coupon_discount_types ) ) {
$this->coupon_discount_types = apply_filters( 'woocommerce_coupon_discount_types', array(
'fixed_cart' => __( 'Cart Discount', 'woocommerce' ),
'percent' => __( 'Cart % Discount', 'woocommerce' ),
'fixed_product' => __( 'Product Discount', 'woocommerce' ),
'percent_product' => __( 'Product % Discount', 'woocommerce' )
) );
}
return $this->coupon_discount_types;
}
/**
* Get a coupon type's name.
*
* @access public
* @param string $type (default: '')
* @return string
*/
public function get_coupon_discount_type( $type = '' ) {
$types = (array) $this->get_coupon_discount_types();
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.
*
* To fail silently, set the error_message to an empty string
*
* @access public
* @param string $name the nonce name
* @param string $action then nonce action
* @param string $method the http request method _POST, _GET or _REQUEST
* @param string $error_message custom error message, or false for default message, or an empty string to fail silently
* @return bool
*/
public function verify_nonce( $action, $method='_POST', $error_message = false ) {
$name = '_n';
$action = 'woocommerce-' . $action;
if ( $error_message === false ) $error_message = __( 'Action failed. Please refresh the page and retry.', 'woocommerce' );
if ( ! in_array( $method, array( '_GET', '_POST', '_REQUEST' ) ) ) $method = '_POST';
if ( isset($_REQUEST[$name] ) && wp_verify_nonce( $_REQUEST[$name], $action ) ) return true;
if ( $error_message ) $this->add_error( $error_message );
return false;
}
/** Shortcode Helpers *********************************************************/
/**
* Shortcode Wrapper
*
* @access public
* @param mixed $function
* @param array $atts (default: array())
* @return string
*/
public function shortcode_wrapper(
$function,
$atts = array(),
$wrapper = array(
'class' => 'woocommerce',
'before' => null,
'after' => null
)
){
ob_start();
$before = empty( $wrapper['before'] ) ? '<div class="' . $wrapper['class'] . '">' : $wrapper['before'];
$after = empty( $wrapper['after'] ) ? '</div>' : $wrapper['after'];
echo $before;
call_user_func( $function, $atts );
echo $after;
return ob_get_clean();
}
/** Transients ************************************************************/
/**
* Clear all transients cache for product data.
*
* @access public
* @param int $post_id (default: 0)
* @return void
*/
public function clear_product_transients( $post_id = 0 ) {
global $wpdb;
$post_id = absint( $post_id );
$wpdb->show_errors();
// Clear core transients
$transients_to_clear = array(
'wc_products_onsale',
'wc_hidden_product_ids',
'wc_hidden_product_ids_search',
'wc_attribute_taxonomies',
'wc_term_counts'
);
foreach( $transients_to_clear as $transient ) {
delete_transient( $transient );
}
// Clear transients for which we don't have the name
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_uf_pid_%') OR `option_name` LIKE ('_transient_timeout_wc_uf_pid_%')" );
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_ln_count_%') OR `option_name` LIKE ('_transient_timeout_wc_ln_count_%')" );
$wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_ship_%') OR `option_name` LIKE ('_transient_timeout_wc_ship_%')" );
// Clear product specific transients
$post_transients_to_clear = array(
'wc_product_children_ids_',
'wc_product_total_stock_',
'wc_average_rating_',
'wc_rating_count_',
'woocommerce_product_type_', // No longer used
'wc_product_type_', // No longer used
);
if ( $post_id > 0 ) {
foreach( $post_transients_to_clear as $transient ) {
delete_transient( $transient . $post_id );
$wpdb->query( $wpdb->prepare( "DELETE FROM `$wpdb->options` WHERE `option_name` = %s OR `option_name` = %s", '_transient_' . $transient . $post_id, '_transient_timeout_' . $transient . $post_id ) );
}
clean_post_cache( $post_id );
} else {
foreach( $post_transients_to_clear as $transient ) {
$wpdb->query( $wpdb->prepare( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE %s OR `option_name` LIKE %s", '_transient_' . $transient . '%', '_transient_timeout_' . $transient . '%' ) );
}
}
}
/** Body Classes **********************************************************/
/**
* Add a class to the webpage body.
*
* @access public
* @param string $class
* @return void
*/
public function add_body_class( $class ) {
$this->_body_classes[] = sanitize_html_class( strtolower($class) );
}
/**
* Output classes on the body tag.
*
* @access public
* @param mixed $classes
* @return array
*/
public function output_body_class( $classes ) {
if ( sizeof( $this->_body_classes ) > 0 ) $classes = array_merge( $classes, $this->_body_classes );
if ( is_singular('product') ) {
$key = array_search( 'singular', $classes );
if ( $key !== false ) unset( $classes[$key] );
}
return $classes;
}
/** Post Classes **********************************************************/
/**
* Adds extra post classes for products
*
* @since 2.0
* @access public
* @param array $classes
* @param string|array $class
* @param int $post_id
* @return array
*/
public function post_class( $classes, $class, $post_id ) {
$product = get_product( $post_id );
if ( $product ) {
if ( $product->is_on_sale() ) {
$classes[] = 'sale';
}
if ( $product->is_featured() ) {
$classes[] = 'featured';
}
$classes[] = $product->stock_status;
}
return $classes;
}
/** Inline JavaScript Helper **********************************************/
/**
* Add some JavaScript inline to be output in the footer.
*
* @access public
* @param string $code
* @return void
*/
public function add_inline_js( $code ) {
$this->_inline_js .= "\n" . $code . "\n";
}
/**
* Output any queued inline JS.
*
* @access public
* @return void
*/
public function output_inline_js() {
if ( $this->_inline_js ) {
echo "<!-- WooCommerce JavaScript-->\n<script type=\"text/javascript\">\njQuery(document).ready(function($) {";
// Sanitize
$this->_inline_js = wp_check_invalid_utf8( $this->_inline_js );
$this->_inline_js = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", $this->_inline_js );
$this->_inline_js = str_replace( "\r", '', $this->_inline_js );
// Output
echo $this->_inline_js;
echo "});\n</script>\n";
$this->_inline_js = '';
}
}
/** Deprecated functions *********************************************************/
/**
@ -1617,6 +1257,241 @@ class Woocommerce {
}
}
/**
* Clear all transients cache for product data.
*
* @deprecated 2.1.0 Access via the helpers
* @access public
* @param int $post_id (default: 0)
* @return void
*/
public function clear_product_transients( $post_id = 0 ) {
_deprecated_function( 'Woocommerce->clear_product_transients', '2.1', 'WC_Transient_Helper->clear_product_transients' );
$this->get_helper( 'transient' )->clear_product_transients( $post_id );
}
/**
* Add some JavaScript inline to be output in the footer.
*
* @deprecated 2.1.0 Access via the helpers
* @access public
* @param string $code
* @return void
*/
public function add_inline_js( $code ) {
_deprecated_function( 'Woocommerce->add_inline_js', '2.1', 'WC_Inline_Javascript_Helper->add_inline_js' );
$this->get_helper( 'inline-javascript' )->add_inline_js( $code );
}
/**
* Output any queued inline JS.
*
* @deprecated 2.1.0 Access via the helpers
* @access public
* @return void
*/
public function output_inline_js() {
_deprecated_function( 'Woocommerce->output_inline_js', '2.1', 'WC_Inline_Javascript_Helper->output_inline_js' );
$this->get_helper( 'inline-javascript' )->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' );
return $this->get_helper( 'nonce' )->nonce_field( $action, $referer, $echo );
}
/**
* 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' );
return $this->get_helper( 'nonce' )->nonce_url( $action, $url );
}
/**
* Check a nonce and sets woocommerce error in case it is invalid.
*
* To fail silently, set the error_message to an empty string
*
* @deprecated 2.1.0 Access via the helpers
* @access public
* @param string $name the nonce name
* @param string $action then nonce action
* @param string $method the http request method _POST, _GET or _REQUEST
* @param string $error_message custom error message, or false for default message, or an empty string to fail silently
* @return bool
*/
public function verify_nonce( $action, $method='_POST', $error_message = false ) {
_deprecated_function( 'Woocommerce->verify_nonce', '2.1', 'WC_Nonce_Helper->verify_nonce' );
return $this->get_helper( 'nonce' )->verify_nonce( $action, $method, $error_message );
}
/**
* Shortcode Wrapper
*
* @deprecated 2.1.0 Access via the helpers
* @access public
* @param mixed $function
* @param array $atts (default: array())
* @return string
*/
public function shortcode_wrapper(
$function,
$atts = array(),
$wrapper = array(
'class' => 'woocommerce',
'before' => null,
'after' => null
)
) {
_deprecated_function( 'Woocommerce->shortcode_wrapper', '2.1', 'WC_Shortcode_Helper->shortcode_wrapper' );
return $this->get_helper( 'shortcode' )->shortcode_wrapper( $function, $atts, $wrapper );
}
/**
* Get attribute taxonomies.
*
* @deprecated 2.1.0 Access via the helpers
* @access public
* @return object
*/
public function get_attribute_taxonomies() {
_deprecated_function( 'Woocommerce->get_attribute_taxonomies', '2.1', 'WC_Attribute_Helper->get_attribute_taxonomies' );
return $this->get_helper( 'attribute' )->get_attribute_taxonomies();
}
/**
* Get a product attributes name.
*
* @deprecated 2.1.0 Access via the helpers
* @access public
* @param mixed $name
* @return string
*/
public function attribute_taxonomy_name( $name ) {
_deprecated_function( 'Woocommerce->attribute_taxonomy_name', '2.1', 'WC_Attribute_Helper->attribute_taxonomy_name' );
return $this->get_helper( 'attribute' )->attribute_taxonomy_name( $name );
}
/**
* Get a product attributes label.
*
* @deprecated 2.1.0 Access via the helpers
* @access public
* @param mixed $name
* @return string
*/
public function attribute_label( $name ) {
_deprecated_function( 'Woocommerce->attribute_label', '2.1', 'WC_Attribute_Helper->attribute_label' );
return $this->get_helper( 'attribute' )->attribute_label( $name );
}
/**
* Get a product attributes orderby setting.
*
* @deprecated 2.1.0 Access via the helpers
* @access public
* @param mixed $name
* @return string
*/
public function attribute_orderby( $name ) {
_deprecated_function( 'Woocommerce->attribute_orderby', '2.1', 'WC_Attribute_Helper->attribute_orderby' );
return $this->get_helper( 'attribute' )->attribute_orderby( $name );
}
/**
* Get an array of product attribute taxonomies.
*
* @deprecated 2.1.0 Access via the helpers
* @access public
* @return array
*/
public function get_attribute_taxonomy_names() {
_deprecated_function( 'Woocommerce->get_attribute_taxonomy_names', '2.1', 'WC_Attribute_Helper->get_attribute_taxonomy_names' );
return $this->get_helper( 'attribute' )->get_attribute_taxonomy_names();
}
/**
* Get coupon types.
*
* @deprecated 2.1.0 Access via the helpers
* @access public
* @return array
*/
public function get_coupon_discount_types() {
_deprecated_function( 'Woocommerce->get_coupon_discount_types', '2.1', 'WC_Coupon_Helper->get_coupon_discount_types' );
return $this->get_helper( 'coupon' )->get_coupon_discount_types();
}
/**
* Get a coupon type's name.
*
* @deprecated 2.1.0 Access via the helpers
* @access public
* @param string $type (default: '')
* @return string
*/
public function get_coupon_discount_type( $type = '' ) {
_deprecated_function( 'Woocommerce->get_coupon_discount_type', '2.1', 'WC_Coupon_Helper->get_coupon_discount_type' );
return $this->get_helper( 'coupon' )->get_coupon_discount_type( $type );
}
/**
* Adds extra post classes for products
*
* @deprecated 2.1.0 Access via the helpers
* @since 2.0
* @access public
* @param array $classes
* @param string|array $class
* @param int $post_id
* @return array
*/
public function post_class( $classes, $class, $post_id ) {
_deprecated_function( 'Woocommerce->post_class', '2.1', 'WC_Post_Class_Helper->post_class' );
return $this->get_helper( 'post-class' )->post_class( $classes, $class, $post_id );
}
/**
* Add a class to the webpage body.
*
* @access public
* @param string $class
* @return void
*/
public function add_body_class( $class ) {
_deprecated_function( 'Woocommerce->add_body_class', '2.1', 'WC_Body_Class_Helper->add_body_class' );
$this->get_helper( 'body-class' )->add_body_class( $class );
}
/**
* Output classes on the body tag.
*
* @access public
* @param mixed $classes
* @return array
*/
public function output_body_class( $classes ) {
_deprecated_function( 'Woocommerce->output_body_class', '2.1', 'WC_Body_Class_Helper->output_body_class' );
return $this->get_helper( 'body-class' )->output_body_class( $classes );
}
}
/**