fixed coding standards in includes/admin/post-types/class-wc-admin-cpt-product.php

This commit is contained in:
claudiosmweb 2014-04-14 16:15:19 -03:00 committed by Mike Jolley
parent 8ae788f73c
commit 92707eaf55
1 changed files with 237 additions and 165 deletions

View File

@ -8,10 +8,13 @@
* @version 2.1.0 * @version 2.1.0
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'WC_Admin_CPT' ) ) if ( ! class_exists( 'WC_Admin_CPT' ) ) {
include( 'class-wc-admin-cpt.php' ); include( 'class-wc-admin-cpt.php' );
}
if ( ! class_exists( 'WC_Admin_CPT_Product' ) ) : if ( ! class_exists( 'WC_Admin_CPT_Product' ) ) :
@ -132,8 +135,9 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
* @return string * @return string
*/ */
public function enter_title_here( $text, $post ) { public function enter_title_here( $text, $post ) {
if ( $post->post_type == 'product' ) if ( $post->post_type == 'product' ) {
return __( 'Product name', 'woocommerce' ); return __( 'Product name', 'woocommerce' );
}
return $text; return $text;
} }
@ -147,8 +151,9 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
public function product_data_visibility() { public function product_data_visibility() {
global $post; global $post;
if ( $post->post_type != 'product' ) if ( 'product' != $post->post_type ) {
return; return;
}
$current_visibility = ( $current_visibility = get_post_meta( $post->ID, '_visibility', true ) ) ? $current_visibility : 'visible'; $current_visibility = ( $current_visibility = get_post_meta( $post->ID, '_visibility', true ) ) ? $current_visibility : 'visible';
$current_featured = ( $current_featured = get_post_meta( $post->ID, '_featured', true ) ) ? $current_featured : 'no'; $current_featured = ( $current_featured = get_post_meta( $post->ID, '_featured', true ) ) ? $current_featured : 'no';
@ -164,8 +169,9 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
<?php _e( 'Catalog visibility:', 'woocommerce' ); ?> <strong id="catalog-visibility-display"><?php <?php _e( 'Catalog visibility:', 'woocommerce' ); ?> <strong id="catalog-visibility-display"><?php
echo isset( $visibility_options[ $current_visibility ] ) ? esc_html( $visibility_options[ $current_visibility ] ) : esc_html( $current_visibility ); echo isset( $visibility_options[ $current_visibility ] ) ? esc_html( $visibility_options[ $current_visibility ] ) : esc_html( $current_visibility );
if ( $current_featured == 'yes' ) if ( 'yes' == $current_featured ) {
echo ', ' . __( 'Featured', 'woocommerce' ); echo ', ' . __( 'Featured', 'woocommerce' );
}
?></strong> ?></strong>
<a href="#catalog-visibility" class="edit-catalog-visibility hide-if-no-js"><?php _e( 'Edit', 'woocommerce' ); ?></a> <a href="#catalog-visibility" class="edit-catalog-visibility hide-if-no-js"><?php _e( 'Edit', 'woocommerce' ); ?></a>
@ -201,11 +207,14 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
* @param int $post_id * @param int $post_id
*/ */
public function pre_post_update( $post_id ) { public function pre_post_update( $post_id ) {
if ( isset( $_POST['_visibility'] ) ) if ( isset( $_POST['_visibility'] ) ) {
update_post_meta( $post_id, '_visibility', stripslashes( $_POST['_visibility'] ) ); update_post_meta( $post_id, '_visibility', stripslashes( $_POST['_visibility'] ) );
if ( isset( $_POST['_stock_status'] ) ) }
if ( isset( $_POST['_stock_status'] ) ) {
wc_update_product_stock_status( $post_id, wc_clean( $_POST['_stock_status'] ) ); wc_update_product_stock_status( $post_id, wc_clean( $_POST['_stock_status'] ) );
} }
}
/** /**
* Forces certain product data based on the product's type, e.g. grouped products cannot have a parent. * Forces certain product data based on the product's type, e.g. grouped products cannot have a parent.
@ -216,14 +225,17 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
public function wp_insert_post_data( $data ) { public function wp_insert_post_data( $data ) {
global $post; global $post;
if ( $data['post_type'] == 'product' && isset( $_POST['product-type'] ) ) { if ( 'product' == $data['post_type'] && isset( $_POST['product-type'] ) ) {
$product_type = stripslashes( $_POST['product-type'] ); $product_type = stripslashes( $_POST['product-type'] );
switch( $product_type ) : switch ( $product_type ) {
case "grouped" : case 'grouped' :
case "variable" : case 'variable' :
$data['post_parent'] = 0; $data['post_parent'] = 0;
break; break;
endswitch;
default :
break;
}
} }
return $data; return $data;
@ -234,30 +246,33 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
*/ */
public function edit_columns( $existing_columns ) { public function edit_columns( $existing_columns ) {
if ( empty( $existing_columns ) && ! is_array( $existing_columns ) ) if ( empty( $existing_columns ) && ! is_array( $existing_columns ) ) {
$existing_columns = array(); $existing_columns = array();
}
unset( $existing_columns['title'], $existing_columns['comments'], $existing_columns['date'] ); unset( $existing_columns['title'], $existing_columns['comments'], $existing_columns['date'] );
$columns = array(); $columns = array();
$columns["cb"] = "<input type=\"checkbox\" />"; $columns['cb'] = '<input type="checkbox" />';
$columns["thumb"] = '<span class="wc-image tips" data-tip="' . __( 'Image', 'woocommerce' ) . '">' . __( 'Image', 'woocommerce' ) . '</span>'; $columns['thumb'] = '<span class="wc-image tips" data-tip="' . __( 'Image', 'woocommerce' ) . '">' . __( 'Image', 'woocommerce' ) . '</span>';
$columns["name"] = __( 'Name', 'woocommerce' ); $columns['name'] = __( 'Name', 'woocommerce' );
if ( wc_product_sku_enabled() ) if ( wc_product_sku_enabled() ) {
$columns["sku"] = __( 'SKU', 'woocommerce' ); $columns['sku'] = __( 'SKU', 'woocommerce' );
}
if ( get_option( 'woocommerce_manage_stock' ) == 'yes' ) if ( 'yes' == get_option( 'woocommerce_manage_stock' ) ) {
$columns["is_in_stock"] = __( 'Stock', 'woocommerce' ); $columns['is_in_stock'] = __( 'Stock', 'woocommerce' );
}
$columns["price"] = __( 'Price', 'woocommerce' ); $columns['price'] = __( 'Price', 'woocommerce' );
$columns["product_cat"] = __( 'Categories', 'woocommerce' ); $columns['product_cat'] = __( 'Categories', 'woocommerce' );
$columns["product_tag"] = __( 'Tags', 'woocommerce' ); $columns['product_tag'] = __( 'Tags', 'woocommerce' );
$columns["featured"] = '<span class="wc-featured tips" data-tip="' . __( 'Featured', 'woocommerce' ) . '">' . __( 'Featured', 'woocommerce' ) . '</span>'; $columns['featured'] = '<span class="wc-featured tips" data-tip="' . __( 'Featured', 'woocommerce' ) . '">' . __( 'Featured', 'woocommerce' ) . '</span>';
$columns["product_type"] = '<span class="wc-type tips" data-tip="' . __( 'Type', 'woocommerce' ) . '">' . __( 'Type', 'woocommerce' ) . '</span>'; $columns['product_type'] = '<span class="wc-type tips" data-tip="' . __( 'Type', 'woocommerce' ) . '">' . __( 'Type', 'woocommerce' ) . '</span>';
$columns["date"] = __( 'Date', 'woocommerce' ); $columns['date'] = __( 'Date', 'woocommerce' );
return array_merge( $columns, $existing_columns ); return array_merge( $columns, $existing_columns );
} }
@ -269,14 +284,15 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
public function custom_columns( $column ) { public function custom_columns( $column ) {
global $post, $woocommerce, $the_product; global $post, $woocommerce, $the_product;
if ( empty( $the_product ) || $the_product->id != $post->ID ) if ( empty( $the_product ) || $the_product->id != $post->ID ) {
$the_product = get_product( $post ); $the_product = get_product( $post );
}
switch ( $column ) { switch ( $column ) {
case "thumb" : case 'thumb' :
echo '<a href="' . get_edit_post_link( $post->ID ) . '">' . $the_product->get_image() . '</a>'; echo '<a href="' . get_edit_post_link( $post->ID ) . '">' . $the_product->get_image() . '</a>';
break; break;
case "name" : case 'name' :
$edit_link = get_edit_post_link( $post->ID ); $edit_link = get_edit_post_link( $post->ID );
$title = _draft_or_post_title(); $title = _draft_or_post_title();
$post_type_object = get_post_type_object( $post->post_type ); $post_type_object = get_post_type_object( $post->post_type );
@ -288,11 +304,14 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
echo '</strong>'; echo '</strong>';
if ( $post->post_parent > 0 ) if ( $post->post_parent > 0 ) {
echo '&nbsp;&nbsp;&larr; <a href="'. get_edit_post_link( $post->post_parent ) .'">'. get_the_title( $post->post_parent ) .'</a>'; echo '&nbsp;&nbsp;&larr; <a href="'. get_edit_post_link( $post->post_parent ) .'">'. get_the_title( $post->post_parent ) .'</a>';
}
// Excerpt view // Excerpt view
if (isset($_GET['mode']) && $_GET['mode']=='excerpt') echo apply_filters('the_excerpt', $post->post_excerpt); if ( isset( $_GET['mode'] ) && 'excerpt' == $_GET['mode'] ) {
echo apply_filters( 'the_excerpt', $post->post_excerpt );
}
// Get actions // Get actions
$actions = array(); $actions = array();
@ -304,12 +323,15 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
$actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr( __( 'Edit this item inline', 'woocommerce' ) ) . '">' . __( 'Quick&nbsp;Edit', 'woocommerce' ) . '</a>'; $actions['inline hide-if-no-js'] = '<a href="#" class="editinline" title="' . esc_attr( __( 'Edit this item inline', 'woocommerce' ) ) . '">' . __( 'Quick&nbsp;Edit', 'woocommerce' ) . '</a>';
} }
if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) { if ( current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) {
if ( 'trash' == $post->post_status ) if ( 'trash' == $post->post_status ) {
$actions['untrash'] = "<a title='" . esc_attr( __( 'Restore this item from the Trash', 'woocommerce' ) ) . "' href='" . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . "'>" . __( 'Restore', 'woocommerce' ) . "</a>"; $actions['untrash'] = '<a title="' . esc_attr( __( 'Restore this item from the Trash', 'woocommerce' ) ) . '" href="' . wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&amp;action=untrash', $post->ID ) ), 'untrash-post_' . $post->ID ) . '">' . __( 'Restore', 'woocommerce' ) . '</a>';
elseif ( EMPTY_TRASH_DAYS ) } elseif ( EMPTY_TRASH_DAYS ) {
$actions['trash'] = "<a class='submitdelete' title='" . esc_attr( __( 'Move this item to the Trash', 'woocommerce' ) ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash', 'woocommerce' ) . "</a>"; $actions['trash'] = '<a class="submitdelete" title="' . esc_attr( __( 'Move this item to the Trash', 'woocommerce' ) ) . '" href="' . get_delete_post_link( $post->ID ) . '">' . __( 'Trash', 'woocommerce' ) . '</a>';
if ( 'trash' == $post->post_status || !EMPTY_TRASH_DAYS ) }
$actions['delete'] = "<a class='submitdelete' title='" . esc_attr( __( 'Delete this item permanently', 'woocommerce' ) ) . "' href='" . get_delete_post_link( $post->ID, '', true ) . "'>" . __( 'Delete Permanently', 'woocommerce' ) . "</a>";
if ( 'trash' == $post->post_status || ! EMPTY_TRASH_DAYS ) {
$actions['delete'] = '<a class="submitdelete" title="' . esc_attr( __( 'Delete this item permanently', 'woocommerce' ) ) . '" href="' . get_delete_post_link( $post->ID, '', true ) . '">' . __( 'Delete Permanently', 'woocommerce' ) . '</a>';
}
} }
if ( $post_type_object->public ) { if ( $post_type_object->public ) {
if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) { if ( in_array( $post->post_status, array( 'pending', 'draft', 'future' ) ) ) {
@ -330,7 +352,7 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
foreach ( $actions as $action => $link ) { foreach ( $actions as $action => $link ) {
++$i; ++$i;
( $i == $action_count ) ? $sep = '' : $sep = ' | '; ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
echo "<span class='$action'>$link$sep</span>"; echo '<span class="' . $action . '">' . $link . $sep . '</span>';
} }
echo '</div>'; echo '</div>';
@ -361,15 +383,15 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
'; ';
break; break;
case "sku" : case 'sku' :
echo $the_product->get_sku() ? $the_product->get_sku() : '<span class="na">&ndash;</span>'; echo $the_product->get_sku() ? $the_product->get_sku() : '<span class="na">&ndash;</span>';
break; break;
case "product_type" : case 'product_type' :
if( $the_product->product_type == 'grouped' ): if ( 'grouped' == $the_product->product_type ) {
echo '<span class="product-type tips grouped" data-tip="' . __( 'Grouped', 'woocommerce' ) . '"></span>'; echo '<span class="product-type tips grouped" data-tip="' . __( 'Grouped', 'woocommerce' ) . '"></span>';
elseif ( $the_product->product_type == 'external' ): } elseif ( 'external' == $the_product->product_type ) {
echo '<span class="product-type tips external" data-tip="' . __( 'External/Affiliate', 'woocommerce' ) . '"></span>'; echo '<span class="product-type tips external" data-tip="' . __( 'External/Affiliate', 'woocommerce' ) . '"></span>';
elseif ( $the_product->product_type == 'simple' ): } elseif ( 'simple' == $the_product->product_type ) {
if ( $the_product->is_virtual() ) { if ( $the_product->is_virtual() ) {
echo '<span class="product-type tips virtual" data-tip="' . __( 'Virtual', 'woocommerce' ) . '"></span>'; echo '<span class="product-type tips virtual" data-tip="' . __( 'Virtual', 'woocommerce' ) . '"></span>';
@ -379,18 +401,18 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
echo '<span class="product-type tips simple" data-tip="' . __( 'Simple', 'woocommerce' ) . '"></span>'; echo '<span class="product-type tips simple" data-tip="' . __( 'Simple', 'woocommerce' ) . '"></span>';
} }
elseif ( $the_product->product_type == 'variable' ): } elseif ( 'variable' == $the_product->product_type ) {
echo '<span class="product-type tips variable" data-tip="' . __( 'Variable', 'woocommerce' ) . '"></span>'; echo '<span class="product-type tips variable" data-tip="' . __( 'Variable', 'woocommerce' ) . '"></span>';
else: } else {
// Assuming that we have other types in future // Assuming that we have other types in future
echo '<span class="product-type tips ' . $the_product->product_type . '" data-tip="' . ucfirst( $the_product->product_type ) . '"></span>'; echo '<span class="product-type tips ' . $the_product->product_type . '" data-tip="' . ucfirst( $the_product->product_type ) . '"></span>';
endif; }
break; break;
case "price": case 'price' :
echo $the_product->get_price_html() ? $the_product->get_price_html() : '<span class="na">&ndash;</span>'; echo $the_product->get_price_html() ? $the_product->get_price_html() : '<span class="na">&ndash;</span>';
break; break;
case "product_cat" : case 'product_cat' :
case "product_tag" : case 'product_tag' :
if ( ! $terms = get_the_terms( $post->ID, $column ) ) { if ( ! $terms = get_the_terms( $post->ID, $column ) ) {
echo '<span class="na">&ndash;</span>'; echo '<span class="na">&ndash;</span>';
} else { } else {
@ -411,7 +433,7 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
} }
echo '</a>'; echo '</a>';
break; break;
case "is_in_stock" : case 'is_in_stock' :
if ( $the_product->is_in_stock() ) { if ( $the_product->is_in_stock() ) {
echo '<mark class="instock">' . __( 'In stock', 'woocommerce' ) . '</mark>'; echo '<mark class="instock">' . __( 'In stock', 'woocommerce' ) . '</mark>';
@ -419,11 +441,14 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
echo '<mark class="outofstock">' . __( 'Out of stock', 'woocommerce' ) . '</mark>'; echo '<mark class="outofstock">' . __( 'Out of stock', 'woocommerce' ) . '</mark>';
} }
if ( $the_product->managing_stock() ) : if ( $the_product->managing_stock() ) {
echo ' &times; ' . $the_product->get_total_stock(); echo ' &times; ' . $the_product->get_total_stock();
endif; }
break; break;
default :
break;
} }
} }
@ -456,26 +481,26 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
* @return array * @return array
*/ */
public function custom_columns_orderby( $vars ) { public function custom_columns_orderby( $vars ) {
if (isset( $vars['orderby'] )) : if ( isset( $vars['orderby'] ) ) {
if ( 'price' == $vars['orderby'] ) : if ( 'price' == $vars['orderby'] ) {
$vars = array_merge( $vars, array( $vars = array_merge( $vars, array(
'meta_key' => '_price', 'meta_key' => '_price',
'orderby' => 'meta_value_num' 'orderby' => 'meta_value_num'
) ); ) );
endif; }
if ( 'featured' == $vars['orderby'] ) : if ( 'featured' == $vars['orderby'] ) {
$vars = array_merge( $vars, array( $vars = array_merge( $vars, array(
'meta_key' => '_featured', 'meta_key' => '_featured',
'orderby' => 'meta_value' 'orderby' => 'meta_value'
) ); ) );
endif; }
if ( 'sku' == $vars['orderby'] ) : if ( 'sku' == $vars['orderby'] ) {
$vars = array_merge( $vars, array( $vars = array_merge( $vars, array(
'meta_key' => '_sku', 'meta_key' => '_sku',
'orderby' => 'meta_value' 'orderby' => 'meta_value'
) ); ) );
endif; }
endif; }
return $vars; return $vars;
} }
@ -491,8 +516,9 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
public function default_sorting_link( $views ) { public function default_sorting_link( $views ) {
global $post_type, $wp_query; global $post_type, $wp_query;
if ( ! current_user_can('edit_others_pages') ) if ( ! current_user_can('edit_others_pages') ) {
return $views; return $views;
}
$class = ( isset( $wp_query->query['orderby'] ) && $wp_query->query['orderby'] == 'menu_order title' ) ? 'current' : ''; $class = ( isset( $wp_query->query['orderby'] ) && $wp_query->query['orderby'] == 'menu_order title' ) ? 'current' : '';
$query_string = remove_query_arg(array( 'orderby', 'order' )); $query_string = remove_query_arg(array( 'orderby', 'order' ));
@ -509,24 +535,26 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
public function product_filters() { public function product_filters() {
global $typenow, $wp_query; global $typenow, $wp_query;
if ( $typenow != 'product' ) if ( 'product' != $typenow ) {
return; return;
}
// Category Filtering // Category Filtering
wc_product_dropdown_categories(); wc_product_dropdown_categories();
// Type filtering // Type filtering
$terms = get_terms( 'product_type' ); $terms = get_terms( 'product_type' );
$output = "<select name='product_type' id='dropdown_product_type'>"; $output = '<select name="product_type" id="dropdown_product_type">';
$output .= '<option value="">' . __( 'Show all product types', 'woocommerce' ) . '</option>'; $output .= '<option value="">' . __( 'Show all product types', 'woocommerce' ) . '</option>';
foreach ( $terms as $term ) { foreach ( $terms as $term ) {
$output .= "<option value='" . sanitize_title( $term->name ) . "' "; $output .= '<option value="' . sanitize_title( $term->name ) . '" ';
if ( isset( $wp_query->query['product_type'] ) ) if ( isset( $wp_query->query['product_type'] ) ) {
$output .= selected( $term->slug, $wp_query->query['product_type'], false ); $output .= selected( $term->slug, $wp_query->query['product_type'], false );
}
$output .= ">"; $output .= '>';
switch ( $term->name ) { switch ( $term->name ) {
case 'grouped' : case 'grouped' :
@ -549,25 +577,27 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
$output .= " ($term->count)</option>"; $output .= " ($term->count)</option>";
if ( $term->name == 'simple' ) { if ( 'simple' == $term->name ) {
$output .= "<option value='downloadable' "; $output .= '<option value="downloadable" ';
if ( isset( $wp_query->query['product_type'] ) ) if ( isset( $wp_query->query['product_type'] ) ) {
$output .= selected( 'downloadable', $wp_query->query['product_type'], false ); $output .= selected( 'downloadable', $wp_query->query['product_type'], false );
}
$output .= "> &rarr; " . __( 'Downloadable', 'woocommerce' ) . "</option>"; $output .= '> &rarr; ' . __( 'Downloadable', 'woocommerce' ) . '</option>';
$output .= "<option value='virtual' "; $output .= '<option value="virtual" ';
if ( isset( $wp_query->query['product_type'] ) ) if ( isset( $wp_query->query['product_type'] ) ) {
$output .= selected( 'virtual', $wp_query->query['product_type'], false ); $output .= selected( 'virtual', $wp_query->query['product_type'], false );
}
$output .= "> &rarr; " . __( 'Virtual', 'woocommerce' ) . "</option>"; $output .= '> &rarr; ' . __( 'Virtual', 'woocommerce' ) . '</option>';
} }
} }
$output .= "</select>"; $output .= '</select>';
echo apply_filters( 'woocommerce_product_filters', $output ); echo apply_filters( 'woocommerce_product_filters', $output );
} }
@ -580,15 +610,15 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
public function product_filters_query( $query ) { public function product_filters_query( $query ) {
global $typenow, $wp_query; global $typenow, $wp_query;
if ( $typenow == 'product' ) { if ( 'product' == $typenow ) {
if ( isset( $query->query_vars['product_type'] ) ) { if ( isset( $query->query_vars['product_type'] ) ) {
// Subtypes // Subtypes
if ( $query->query_vars['product_type'] == 'downloadable' ) { if ( 'downloadable' == $query->query_vars['product_type'] ) {
$query->query_vars['product_type'] = ''; $query->query_vars['product_type'] = '';
$query->query_vars['meta_value'] = 'yes'; $query->query_vars['meta_value'] = 'yes';
$query->query_vars['meta_key'] = '_downloadable'; $query->query_vars['meta_key'] = '_downloadable';
} elseif ( $query->query_vars['product_type'] == 'virtual' ) { } elseif ( 'virtual' == $query->query_vars['product_type'] ) {
$query->query_vars['product_type'] = ''; $query->query_vars['product_type'] = '';
$query->query_vars['meta_value'] = 'yes'; $query->query_vars['meta_value'] = 'yes';
$query->query_vars['meta_key'] = '_virtual'; $query->query_vars['meta_key'] = '_virtual';
@ -596,7 +626,7 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
} }
// Categories // Categories
if ( isset( $_GET['product_cat'] ) && $_GET['product_cat'] == '0' ) { if ( isset( $_GET['product_cat'] ) && '0' == $_GET['product_cat'] ) {
$query->query_vars['tax_query'][] = array( $query->query_vars['tax_query'][] = array(
'taxonomy' => 'product_cat', 'taxonomy' => 'product_cat',
'field' => 'id', 'field' => 'id',
@ -649,8 +679,9 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
* @return array * @return array
*/ */
public function disable_checked_ontop( $args ) { public function disable_checked_ontop( $args ) {
if ( $args['taxonomy'] == 'product_cat' ) if ( 'product_cat' == $args['taxonomy'] ) {
$args['checked_ontop'] = false; $args['checked_ontop'] = false;
}
return $args; return $args;
} }
@ -663,8 +694,9 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
* @param mixed $post_type * @param mixed $post_type
*/ */
public function bulk_edit( $column_name, $post_type ) { public function bulk_edit( $column_name, $post_type ) {
if ( $column_name != 'price' || $post_type != 'product' ) if ( 'price' != $column_name || 'product' != $post_type ) {
return; return;
}
include( WC()->plugin_path() . '/includes/admin/views/html-bulk-edit-product.php' ); include( WC()->plugin_path() . '/includes/admin/views/html-bulk-edit-product.php' );
} }
@ -677,8 +709,9 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
* @param mixed $post_type * @param mixed $post_type
*/ */
public function quick_edit( $column_name, $post_type ) { public function quick_edit( $column_name, $post_type ) {
if ( $column_name != 'price' || $post_type != 'product' ) if ( 'price' != $column_name || 'product' != $post_type ) {
return; return;
}
include( WC()->plugin_path() . '/includes/admin/views/html-quick-edit-product.php' ); include( WC()->plugin_path() . '/includes/admin/views/html-quick-edit-product.php' );
} }
@ -703,7 +736,7 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
} }
// Check post type is product // Check post type is product
if ( $post->post_type != 'product' ) { if ( 'product' != $post->post_type ) {
return $post_id; return $post_id;
} }
@ -772,18 +805,39 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
} }
} }
if ( isset( $_REQUEST['_weight'] ) ) update_post_meta( $post_id, '_weight', wc_clean( $_REQUEST['_weight'] ) ); if ( isset( $_REQUEST['_weight'] ) ) {
if ( isset( $_REQUEST['_length'] ) ) update_post_meta( $post_id, '_length', wc_clean( $_REQUEST['_length'] ) ); update_post_meta( $post_id, '_weight', wc_clean( $_REQUEST['_weight'] ) );
if ( isset( $_REQUEST['_width'] ) ) update_post_meta( $post_id, '_width', wc_clean( $_REQUEST['_width'] ) ); }
if ( isset( $_REQUEST['_height'] ) ) update_post_meta( $post_id, '_height', wc_clean( $_REQUEST['_height'] ) );
if ( isset( $_REQUEST['_visibility'] ) ) update_post_meta( $post_id, '_visibility', wc_clean( $_REQUEST['_visibility'] ) );
if ( isset( $_REQUEST['_featured'] ) ) update_post_meta( $post_id, '_featured', 'yes' ); else update_post_meta( $post_id, '_featured', 'no' );
if ( isset( $_REQUEST['_tax_status'] ) ) if ( isset( $_REQUEST['_length'] ) ) {
update_post_meta( $post_id, '_length', wc_clean( $_REQUEST['_length'] ) );
}
if ( isset( $_REQUEST['_width'] ) ) {
update_post_meta( $post_id, '_width', wc_clean( $_REQUEST['_width'] ) );
}
if ( isset( $_REQUEST['_height'] ) ) {
update_post_meta( $post_id, '_height', wc_clean( $_REQUEST['_height'] ) );
}
if ( isset( $_REQUEST['_visibility'] ) ) {
update_post_meta( $post_id, '_visibility', wc_clean( $_REQUEST['_visibility'] ) );
}
if ( isset( $_REQUEST['_featured'] ) ) {
update_post_meta( $post_id, '_featured', 'yes' );
} else {
update_post_meta( $post_id, '_featured', 'no' );
}
if ( isset( $_REQUEST['_tax_status'] ) ) {
update_post_meta( $post_id, '_tax_status', wc_clean( $_REQUEST['_tax_status'] ) ); update_post_meta( $post_id, '_tax_status', wc_clean( $_REQUEST['_tax_status'] ) );
}
if ( isset( $_REQUEST['_tax_class'] ) ) if ( isset( $_REQUEST['_tax_class'] ) ) {
update_post_meta( $post_id, '_tax_class', wc_clean( $_REQUEST['_tax_class'] ) ); update_post_meta( $post_id, '_tax_class', wc_clean( $_REQUEST['_tax_class'] ) );
}
if ( $product->is_type('simple') || $product->is_type('external') ) { if ( $product->is_type('simple') || $product->is_type('external') ) {
@ -822,8 +876,9 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
} }
// Handle stock status // Handle stock status
if ( isset( $_REQUEST['_stock_status'] ) ) if ( isset( $_REQUEST['_stock_status'] ) ) {
wc_update_product_stock_status( $post_id, wc_clean( $_REQUEST['_stock_status'] ) ); wc_update_product_stock_status( $post_id, wc_clean( $_REQUEST['_stock_status'] ) );
}
// Handle stock // Handle stock
if ( ! $product->is_type('grouped') ) { if ( ! $product->is_type('grouped') ) {
@ -852,36 +907,45 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
$old_sale_price = $product->sale_price; $old_sale_price = $product->sale_price;
// Save fields // Save fields
if ( ! empty( $_REQUEST['change_weight'] ) && isset( $_REQUEST['_weight'] ) ) if ( ! empty( $_REQUEST['change_weight'] ) && isset( $_REQUEST['_weight'] ) ) {
update_post_meta( $post_id, '_weight', wc_clean( stripslashes( $_REQUEST['_weight'] ) ) ); update_post_meta( $post_id, '_weight', wc_clean( stripslashes( $_REQUEST['_weight'] ) ) );
if ( ! empty( $_REQUEST['change_dimensions'] ) ) {
if ( isset( $_REQUEST['_length'] ) )
update_post_meta( $post_id, '_length', wc_clean( stripslashes( $_REQUEST['_length'] ) ) );
if ( isset( $_REQUEST['_width'] ) )
update_post_meta( $post_id, '_width', wc_clean( stripslashes( $_REQUEST['_width'] ) ) );
if ( isset( $_REQUEST['_height'] ) )
update_post_meta( $post_id, '_height', wc_clean( stripslashes( $_REQUEST['_height'] ) ) );
} }
if ( ! empty( $_REQUEST['_tax_status'] ) ) if ( ! empty( $_REQUEST['change_dimensions'] ) ) {
if ( isset( $_REQUEST['_length'] ) ) {
update_post_meta( $post_id, '_length', wc_clean( stripslashes( $_REQUEST['_length'] ) ) );
}
if ( isset( $_REQUEST['_width'] ) ) {
update_post_meta( $post_id, '_width', wc_clean( stripslashes( $_REQUEST['_width'] ) ) );
}
if ( isset( $_REQUEST['_height'] ) ) {
update_post_meta( $post_id, '_height', wc_clean( stripslashes( $_REQUEST['_height'] ) ) );
}
}
if ( ! empty( $_REQUEST['_tax_status'] ) ) {
update_post_meta( $post_id, '_tax_status', wc_clean( $_REQUEST['_tax_status'] ) ); update_post_meta( $post_id, '_tax_status', wc_clean( $_REQUEST['_tax_status'] ) );
}
if ( ! empty( $_REQUEST['_tax_class'] ) ) { if ( ! empty( $_REQUEST['_tax_class'] ) ) {
$tax_class = wc_clean( $_REQUEST['_tax_class'] ); $tax_class = wc_clean( $_REQUEST['_tax_class'] );
if ( $tax_class == 'standard' ) if ( 'standard' == $tax_class ) {
$tax_class = ''; $tax_class = '';
}
update_post_meta( $post_id, '_tax_class', $tax_class ); update_post_meta( $post_id, '_tax_class', $tax_class );
} }
if ( ! empty( $_REQUEST['_stock_status'] ) ) if ( ! empty( $_REQUEST['_stock_status'] ) ) {
wc_update_product_stock_status( $post_id, wc_clean( $_REQUEST['_stock_status'] ) ); wc_update_product_stock_status( $post_id, wc_clean( $_REQUEST['_stock_status'] ) );
}
if ( ! empty( $_REQUEST['_visibility'] ) ) if ( ! empty( $_REQUEST['_visibility'] ) ) {
update_post_meta( $post_id, '_visibility', stripslashes( $_REQUEST['_visibility'] ) ); update_post_meta( $post_id, '_visibility', stripslashes( $_REQUEST['_visibility'] ) );
}
if ( ! empty( $_REQUEST['_featured'] ) ) if ( ! empty( $_REQUEST['_featured'] ) ) {
update_post_meta( $post_id, '_featured', stripslashes( $_REQUEST['_featured'] ) ); update_post_meta( $post_id, '_featured', stripslashes( $_REQUEST['_featured'] ) );
}
// Handle price - remove dates and set to lowest // Handle price - remove dates and set to lowest
if ( $product->is_type( 'simple' ) || $product->is_type( 'external' ) ) { if ( $product->is_type( 'simple' ) || $product->is_type( 'external' ) ) {
@ -913,6 +977,9 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
$new_price = $old_regular_price - $regular_price; $new_price = $old_regular_price - $regular_price;
} }
break; break;
default :
break;
} }
if ( isset( $new_price ) && $new_price != $old_regular_price ) { if ( isset( $new_price ) && $new_price != $old_regular_price ) {
@ -956,6 +1023,9 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
$new_price = $product->regular_price - $sale_price; $new_price = $product->regular_price - $sale_price;
} }
break; break;
default :
break;
} }
if ( isset( $new_price ) && $new_price != $old_sale_price ) { if ( isset( $new_price ) && $new_price != $old_sale_price ) {
@ -1018,7 +1088,7 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
*/ */
public function upload_dir( $pathdata ) { public function upload_dir( $pathdata ) {
// Change upload dir for downloadable files // Change upload dir for downloadable files
if ( isset( $_POST['type'] ) && $_POST['type'] == 'downloadable_product' ) { if ( isset( $_POST['type'] ) && 'downloadable_product' == $_POST['type'] ) {
if ( empty( $pathdata['subdir'] ) ) { if ( empty( $pathdata['subdir'] ) ) {
$pathdata['path'] = $pathdata['path'] . '/woocommerce_uploads'; $pathdata['path'] = $pathdata['path'] . '/woocommerce_uploads';
$pathdata['url'] = $pathdata['url']. '/woocommerce_uploads'; $pathdata['url'] = $pathdata['url']. '/woocommerce_uploads';
@ -1051,8 +1121,9 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
public function ms_protect_download_rewite_rules( $rewrite ) { public function ms_protect_download_rewite_rules( $rewrite ) {
global $wp_rewrite; global $wp_rewrite;
if ( ! is_multisite() || get_option( 'woocommerce_file_download_method' ) == 'redirect' ) if ( ! is_multisite() || 'redirect' == get_option( 'woocommerce_file_download_method' ) ) {
return $rewrite; return $rewrite;
}
$rule = "\n# WooCommerce Rules - Protect Files from ms-files.php\n\n"; $rule = "\n# WooCommerce Rules - Protect Files from ms-files.php\n\n";
$rule .= "<IfModule mod_rewrite.c>\n"; $rule .= "<IfModule mod_rewrite.c>\n";
@ -1075,8 +1146,9 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
public function process_product_file_download_paths( $product_id, $variation_id, $downloadable_files ) { public function process_product_file_download_paths( $product_id, $variation_id, $downloadable_files ) {
global $wpdb; global $wpdb;
if ( $variation_id ) if ( $variation_id ) {
$product_id = $variation_id; $product_id = $variation_id;
}
$product = get_product( $product_id ); $product = get_product( $product_id );
$existing_download_ids = array_keys( (array) $product->get_files() ); $existing_download_ids = array_keys( (array) $product->get_files() );