From 0d554994e64f057fae2f8cc72a506bb2cdfebf6f Mon Sep 17 00:00:00 2001 From: Coen Jacobs Date: Mon, 17 Jun 2013 16:15:24 +0200 Subject: [PATCH] Add actions for attribute create/update/delete As committed on master branch via: - https://github.com/woothemes/woocommerce/pull/3298 --- admin/woocommerce-admin-attributes.php | 41 +++++++++++++++----------- readme.txt | 1 + 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/admin/woocommerce-admin-attributes.php b/admin/woocommerce-admin-attributes.php index f7a10a073cd..8c4fc28ecc5 100644 --- a/admin/woocommerce-admin-attributes.php +++ b/admin/woocommerce-admin-attributes.php @@ -100,32 +100,35 @@ function woocommerce_attributes() { // Add new attribute if ( 'add' === $action ) { - $wpdb->insert( - $wpdb->prefix . 'woocommerce_attribute_taxonomies', - array( - 'attribute_label' => $attribute_label, - 'attribute_name' => $attribute_name, - 'attribute_type' => $attribute_type, - 'attribute_orderby' => $attribute_orderby, - ) + + $attribute = array( + 'attribute_label' => $attribute_label, + 'attribute_name' => $attribute_name, + 'attribute_type' => $attribute_type, + 'attribute_orderby' => $attribute_orderby, ); + $wpdb->insert( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute ); + + do_action( 'woocommerce_attribute_added', $wpdb->insert_id, $attribute ); + $action_completed = true; } // Edit existing attribute if ( 'edit' === $action ) { - $wpdb->update( - $wpdb->prefix . 'woocommerce_attribute_taxonomies', - array( - 'attribute_label' => $attribute_label, - 'attribute_name' => $attribute_name, - 'attribute_type' => $attribute_type, - 'attribute_orderby' => $attribute_orderby, - ), - array( 'attribute_id' => $attribute_id ) + + $attribute = array( + 'attribute_label' => $attribute_label, + 'attribute_name' => $attribute_name, + 'attribute_type' => $attribute_type, + 'attribute_orderby' => $attribute_orderby, ); + $wpdb->update( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute, array( 'attribute_id' => $attribute_id ) ); + + do_action( 'woocommerce_attribute_updated', $attribute_id, $attribute, $old_attribute_name ); + if ( $old_attribute_name != $attribute_name && ! empty( $old_attribute_name ) ) { // Update taxonomies in the wp term taxonomy table $wpdb->update( @@ -183,6 +186,8 @@ function woocommerce_attributes() { } } + do_action( 'woocommerce_attribute_deleted', $attribute_id, $attribute_name, $taxonomy ); + $action_completed = true; } } @@ -422,4 +427,4 @@ function woocommerce_add_attribute() {