Skip to content

Commit

Permalink
Merge pull request woocommerce#3288 from woothemes/core-class-refactor
Browse files Browse the repository at this point in the history
Further core class refactor
  • Loading branch information
coenjacobs committed Jun 11, 2013
2 parents d7b3438 + 3a0d60d commit ef2edd5
Show file tree
Hide file tree
Showing 74 changed files with 2,155 additions and 1,866 deletions.
4 changes: 2 additions & 2 deletions admin/post-types/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
6 changes: 3 additions & 3 deletions admin/post-types/shop_coupon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down Expand Up @@ -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 ) . '"';
Expand All @@ -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();
" );
}
Expand Down
2 changes: 1 addition & 1 deletion admin/post-types/shop_order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion admin/post-types/writepanels/variation-admin-html.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
$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'] ) {
Expand Down
2 changes: 1 addition & 1 deletion admin/post-types/writepanels/writepanel-coupon_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion admin/post-types/writepanels/writepanel-order_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') . "',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,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'] ) {
Expand Down Expand Up @@ -617,7 +617,7 @@ function variation_row_indexes() {
});
<?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');
Expand Down
10 changes: 5 additions & 5 deletions admin/post-types/writepanels/writepanel-product_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand All @@ -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 ) )
Expand Down Expand Up @@ -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>';
}
Expand Down Expand Up @@ -890,7 +890,7 @@ function attributes_cmp( $a, $b ) {
}

// Clear cache/transients
$woocommerce->clear_product_transients( $clear_id );
$woocommerce->get_helper( 'transient' )->clear_product_transients( $clear_id );
}
}
}
Expand Down Expand Up @@ -1021,7 +1021,7 @@ function attributes_cmp( $a, $b ) {
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);
Expand Down
16 changes: 8 additions & 8 deletions admin/woocommerce-admin-attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand Down Expand Up @@ -133,7 +133,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 )
);

Expand Down Expand Up @@ -177,7 +177,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' );
Expand Down Expand Up @@ -318,12 +318,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>
Expand All @@ -343,9 +343,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;
Expand All @@ -358,7 +358,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 :
Expand Down
2 changes: 1 addition & 1 deletion admin/woocommerce-admin-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions admin/woocommerce-admin-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion admin/woocommerce-admin-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) {
Expand Down
2 changes: 1 addition & 1 deletion admin/woocommerce-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function woocommerce_settings() {
}

// Clear any unwanted data
$woocommerce->clear_product_transients();
$woocommerce->get_helper( 'transient' )->clear_product_transients();

delete_transient( 'woocommerce_cache_excluded_uris' );

Expand Down
2 changes: 1 addition & 1 deletion admin/woocommerce-admin-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,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;
Expand Down
2 changes: 1 addition & 1 deletion classes/abstracts/abstract-wc-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ function admin_options() {
?>
</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();
Expand Down
4 changes: 4 additions & 0 deletions classes/abstracts/abstract-wc-helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

class WC_Helper {
}
6 changes: 3 additions & 3 deletions classes/abstracts/abstract-wc-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function set_stock( $amount = null ) {
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();
}
Expand All @@ -196,7 +196,7 @@ function reduce_stock( $by = 1 ) {
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();
}
Expand All @@ -221,7 +221,7 @@ function increase_stock( $by = 1 ) {
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();
}
Expand Down
Loading

0 comments on commit ef2edd5

Please sign in to comment.