Make 'public', and rewrite, optional for attributes

#6852
This commit is contained in:
Mike Jolley 2014-12-19 17:58:49 +00:00
parent e7f0233c8e
commit 8df8c9b482
5 changed files with 64 additions and 41 deletions

View File

@ -51,10 +51,11 @@ class WC_Admin_Attributes {
}
// Grab the submitted data
$attribute_label = ( isset( $_POST['attribute_label'] ) ) ? (string) stripslashes( $_POST['attribute_label'] ) : '';
$attribute_name = ( isset( $_POST['attribute_name'] ) ) ? wc_sanitize_taxonomy_name( stripslashes( (string) $_POST['attribute_name'] ) ) : '';
$attribute_type = ( isset( $_POST['attribute_type'] ) ) ? (string) stripslashes( $_POST['attribute_type'] ) : '';
$attribute_orderby = ( isset( $_POST['attribute_orderby'] ) ) ? (string) stripslashes( $_POST['attribute_orderby'] ) : '';
$attribute_label = isset( $_POST['attribute_label'] ) ? (string) stripslashes( $_POST['attribute_label'] ) : '';
$attribute_name = isset( $_POST['attribute_name'] ) ? wc_sanitize_taxonomy_name( stripslashes( (string) $_POST['attribute_name'] ) ) : '';
$attribute_type = isset( $_POST['attribute_type'] ) ? (string) stripslashes( $_POST['attribute_type'] ) : '';
$attribute_orderby = isset( $_POST['attribute_orderby'] ) ? (string) stripslashes( $_POST['attribute_orderby'] ) : '';
$attribute_public = isset( $_POST['attribute_public'] ) ? 1 : 0;
// Auto-generate the label or slug if only one of both was provided
if ( ! $attribute_label ) {
@ -112,6 +113,7 @@ class WC_Admin_Attributes {
'attribute_name' => $attribute_name,
'attribute_type' => $attribute_type,
'attribute_orderby' => $attribute_orderby,
'attribute_public' => $attribute_public
);
$wpdb->insert( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute );
@ -129,6 +131,7 @@ class WC_Admin_Attributes {
'attribute_name' => $attribute_name,
'attribute_type' => $attribute_type,
'attribute_orderby' => $attribute_orderby,
'attribute_public' => $attribute_public
);
$wpdb->update( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute, array( 'attribute_id' => $attribute_id ) );
@ -232,6 +235,7 @@ class WC_Admin_Attributes {
$att_label = $attribute_to_edit->attribute_label;
$att_name = $attribute_to_edit->attribute_name;
$att_orderby = $attribute_to_edit->attribute_orderby;
$att_public = $attribute_to_edit->attribute_public;
?>
<div class="wrap woocommerce">
<div class="icon32 icon32-attributes" id="icon-woocommerce"><br/></div>
@ -257,6 +261,15 @@ class WC_Admin_Attributes {
<p class="description"><?php _e( 'Unique slug/reference for the attribute; must be shorter than 28 characters.', 'woocommerce' ); ?></p>
</td>
</tr>
<tr class="form-field form-required">
<th scope="row" valign="top">
<label for="attribute_public"><?php _e( 'Enable Archives?', 'woocommerce' ); ?></label>
</th>
<td>
<input name="attribute_public" id="attribute_public" type="checkbox" value="1" <?php checked( $att_public, 1 ); ?> />
<p class="description"><?php _e( 'Enable this if you want this attribute to have product archives in your store.', 'woocommerce' ); ?></p>
</td>
</tr>
<tr class="form-field form-required">
<th scope="row" valign="top">
<label for="attribute_type"><?php _e( 'Type', 'woocommerce' ); ?></label>
@ -329,7 +342,7 @@ class WC_Admin_Attributes {
<div class="row-actions"><span class="edit"><a href="<?php echo esc_url( add_query_arg( 'edit', $tax->attribute_id, 'edit.php?post_type=product&amp;page=product_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, 'edit.php?post_type=product&amp;page=product_attributes' ), 'woocommerce-delete-attribute_' . $tax->attribute_id ) ); ?>"><?php _e( 'Delete', 'woocommerce' ); ?></a></span></div>
</td>
<td><?php echo esc_html( $tax->attribute_name ); ?></td>
<td><?php echo esc_html( ucfirst( $tax->attribute_type ) ); ?></td>
<td><?php echo esc_html( ucfirst( $tax->attribute_type ) ); ?> <?php echo $tax->attribute_public ? '(' . __( 'Public', 'woocommerce' ) . ')' : ''; ?></td>
<td><?php
switch ( $tax->attribute_orderby ) {
case 'name' :
@ -400,6 +413,12 @@ class WC_Admin_Attributes {
<p class="description"><?php _e( 'Unique slug/reference for the attribute; must be shorter than 28 characters.', 'woocommerce' ); ?></p>
</div>
<div class="form-field">
<label for="attribute_public"><input name="attribute_public" id="attribute_public" type="checkbox" value="1" /> <?php _e( 'Enable Archives?', 'woocommerce' ); ?></label>
<p class="description"><?php _e( 'Enable this if you want this attribute to have product archives in your store.', 'woocommerce' ); ?></p>
</div>
<div class="form-field">
<label for="attribute_type"><?php _e( 'Type', 'woocommerce' ); ?></label>
<select name="attribute_type" id="attribute_type">

View File

@ -101,7 +101,7 @@ class WC_Admin_Importers {
// Create the taxonomy
if ( ! $exists_in_db ) {
$wpdb->insert( $wpdb->prefix . "woocommerce_attribute_taxonomies", array( 'attribute_name' => $nicename, 'attribute_type' => 'select', 'attribute_orderby' => 'menu_order' ), array( '%s', '%s', '%s' ) );
$wpdb->insert( $wpdb->prefix . "woocommerce_attribute_taxonomies", array( 'attribute_name' => $nicename, 'attribute_type' => 'select', 'attribute_orderby' => 'menu_order', 'attribute_public' => 0 ), array( '%s', '%s', '%s' ) );
}
// Register the taxonomy now so that the import works!

View File

@ -325,6 +325,7 @@ CREATE TABLE {$wpdb->prefix}woocommerce_attribute_taxonomies (
attribute_label longtext NULL,
attribute_type varchar(200) NOT NULL,
attribute_orderby varchar(200) NOT NULL,
attribute_public int(1) NOT NULL DEFAULT 1,
PRIMARY KEY (attribute_id),
KEY attribute_name (attribute_name)
) $collate;

View File

@ -161,44 +161,46 @@ class WC_Post_types {
if ( $attribute_taxonomies = wc_get_attribute_taxonomies() ) {
foreach ( $attribute_taxonomies as $tax ) {
if ( $name = wc_attribute_taxonomy_name( $tax->attribute_name ) ) {
$label = ! empty( $tax->attribute_label ) ? $tax->attribute_label : $tax->attribute_name;
$label = ! empty( $tax->attribute_label ) ? $tax->attribute_label : $tax->attribute_name;
$wc_product_attributes[ $name ] = $tax;
register_taxonomy( $name,
apply_filters( 'woocommerce_taxonomy_objects_' . $name, array( 'product' ) ),
apply_filters( 'woocommerce_taxonomy_args_' . $name, array(
'hierarchical' => true,
'update_count_callback' => '_update_post_term_count',
'labels' => array(
'name' => $label,
'singular_name' => $label,
'search_items' => sprintf( __( 'Search %s', 'woocommerce' ), $label ),
'all_items' => sprintf( __( 'All %s', 'woocommerce' ), $label ),
'parent_item' => sprintf( __( 'Parent %s', 'woocommerce' ), $label ),
'parent_item_colon' => sprintf( __( 'Parent %s:', 'woocommerce' ), $label ),
'edit_item' => sprintf( __( 'Edit %s', 'woocommerce' ), $label ),
'update_item' => sprintf( __( 'Update %s', 'woocommerce' ), $label ),
'add_new_item' => sprintf( __( 'Add New %s', 'woocommerce' ), $label ),
'new_item_name' => sprintf( __( 'New %s', 'woocommerce' ), $label )
),
'show_ui' => false,
'query_var' => true,
'capabilities' => array(
'manage_terms' => 'manage_product_terms',
'edit_terms' => 'edit_product_terms',
'delete_terms' => 'delete_product_terms',
'assign_terms' => 'assign_product_terms',
$taxonomy_data = array(
'hierarchical' => true,
'update_count_callback' => '_update_post_term_count',
'labels' => array(
'name' => $label,
'singular_name' => $label,
'search_items' => sprintf( __( 'Search %s', 'woocommerce' ), $label ),
'all_items' => sprintf( __( 'All %s', 'woocommerce' ), $label ),
'parent_item' => sprintf( __( 'Parent %s', 'woocommerce' ), $label ),
'parent_item_colon' => sprintf( __( 'Parent %s:', 'woocommerce' ), $label ),
'edit_item' => sprintf( __( 'Edit %s', 'woocommerce' ), $label ),
'update_item' => sprintf( __( 'Update %s', 'woocommerce' ), $label ),
'add_new_item' => sprintf( __( 'Add New %s', 'woocommerce' ), $label ),
'new_item_name' => sprintf( __( 'New %s', 'woocommerce' ), $label )
),
'show_in_nav_menus' => apply_filters( 'woocommerce_attribute_show_in_nav_menus', false, $name ),
'rewrite' => array(
'slug' => ( empty( $permalinks['attribute_base'] ) ? '' : trailingslashit( $permalinks['attribute_base'] ) ) . sanitize_title( $tax->attribute_name ),
'with_front' => false,
'hierarchical' => true
),
) )
'show_ui' => false,
'query_var' => false,
'rewrite' => false,
'sort' => false,
'public' => 1 === $tax->attribute_public,
'show_in_nav_menus' => 1 === $tax->attribute_public && apply_filters( 'woocommerce_attribute_show_in_nav_menus', false, $name ),
'capabilities' => array(
'manage_terms' => 'manage_product_terms',
'edit_terms' => 'edit_product_terms',
'delete_terms' => 'delete_product_terms',
'assign_terms' => 'assign_product_terms',
)
);
if ( 1 === $tax->attribute_public ) {
$taxonomy_data['rewrite'] = array(
'slug' => empty( $permalinks['attribute_base'] ? '' : trailingslashit( $permalinks['attribute_base'] ) ) . sanitize_title( $tax->attribute_name ),
'with_front' => false,
'hierarchical' => true
);
}
register_taxonomy( $name, apply_filters( "woocommerce_taxonomy_objects_{$name}", array( 'product' ) ), apply_filters( "woocommerce_taxonomy_args_{$name}", $taxonomy_data ) );
}
}

View File

@ -160,6 +160,7 @@ class WC_Helper_Product {
'attribute_name' => $attribute_name,
'attribute_type' => 'select',
'attribute_orderby' => 'menu_order',
'attribute_public' => 0,
);
$wpdb->insert( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute );
$return['attribute_id'] = $wpdb->insert_id;