From 7886fac1112c948feb6df04463f26e5105fc5cc5 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 10 Sep 2009 14:43:45 +0000 Subject: [PATCH] More add/delete/update actions. Props Demitrious Kelly. see #10750 git-svn-id: http://svn.automattic.com/wordpress/trunk@11909 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/plugin.php | 13 ++++++++++--- wp-includes/post.php | 15 +++++++++++++-- wp-includes/user.php | 17 +++++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index a9ab4bcaa..0f54a8bfb 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -314,8 +314,10 @@ function activate_plugin($plugin, $redirect = '') { @include(WP_PLUGIN_DIR . '/' . $plugin); $current[] = $plugin; sort($current); + do_action( 'activate_plugin', trim( $plugin) ); update_option('active_plugins', $current); - do_action('activate_' . $plugin); + do_action( 'activate_' . trim( $plugin ) ); + do_action( 'activated_plugin', trim( $plugin) ); ob_end_clean(); } @@ -343,9 +345,14 @@ function deactivate_plugins($plugins, $silent= false) { $plugin = plugin_basename($plugin); if( ! is_plugin_active($plugin) ) continue; + if ( ! $silent ) + do_action( 'deactivate_plugin', trim( $plugin ) ); array_splice($current, array_search( $plugin, $current), 1 ); // Fixed Array-fu! - if ( ! $silent ) //Used by Plugin updater to internally deactivate plugin, however, not to notify plugins of the fact to prevent plugin output. - do_action('deactivate_' . trim( $plugin )); + //Used by Plugin updater to internally deactivate plugin, however, not to notify plugins of the fact to prevent plugin output. + if ( ! $silent ) { + do_action( 'deactivate_' . trim( $plugin ) ); + do_action( 'deactivated_plugin', trim( $plugin ) ); + } } update_option('active_plugins', $current); diff --git a/wp-includes/post.php b/wp-includes/post.php index 9b50b6ec4..a56ba14d4 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -532,6 +532,8 @@ function add_post_meta($post_id, $meta_key, $meta_value, $unique = false) { wp_cache_delete($post_id, 'post_meta'); + do_action( 'added_post_meta', $wpdb->insert_id, $post_id, $meta_key, $meta_value ); + return true; } @@ -573,12 +575,16 @@ function delete_post_meta($post_id, $meta_key, $meta_value = '') { if ( !$meta_id ) return false; + do_action( 'delete_post_meta', $meta_id, $post_id, $meta_key, $meta_value ); + if ( empty( $meta_value ) ) $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $post_id, $meta_key ) ); else $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s AND meta_value = %s", $post_id, $meta_key, $meta_value ) ); wp_cache_delete($post_id, 'post_meta'); + + do_action( 'deleted_post_meta', $meta_id, $post_id, $meta_key, $meta_value ); return true; } @@ -651,9 +657,9 @@ function update_post_meta($post_id, $meta_key, $meta_value, $prev_value = '') { if ( !$meta_key ) return false; - if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $wpdb->postmeta WHERE meta_key = %s AND post_id = %d", $meta_key, $post_id ) ) ) { + $meta_id = $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = %s AND post_id = %d", $meta_key, $post_id ) ); + if ( ! $meta_id ) return add_post_meta($post_id, $meta_key, $meta_value); - } $meta_value = maybe_serialize( stripslashes_deep($meta_value) ); @@ -665,8 +671,13 @@ function update_post_meta($post_id, $meta_key, $meta_value, $prev_value = '') { $where['meta_value'] = $prev_value; } + do_action( 'update_post_meta', $meta_id, $post_id, $meta_key, $meta_value ); + $wpdb->update( $wpdb->postmeta, $data, $where ); wp_cache_delete($post_id, 'post_meta'); + + do_action( 'updated_post_meta', $meta_id, $post_id, $meta_key, $meta_value ); + return true; } diff --git a/wp-includes/user.php b/wp-includes/user.php index 483b3bccf..9454b4ac7 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -307,6 +307,11 @@ function delete_usermeta( $user_id, $meta_key, $meta_value = '' ) { $meta_value = serialize($meta_value); $meta_value = trim( $meta_value ); + $cur = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) ); + + if ( $cur && $cur->umeta_id ) + do_action( 'delete_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value ); + if ( ! empty($meta_value) ) $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s AND meta_value = %s", $user_id, $meta_key, $meta_value) ); else @@ -314,6 +319,9 @@ function delete_usermeta( $user_id, $meta_key, $meta_value = '' ) { wp_cache_delete($user_id, 'users'); + if ( $cur && $cur->umeta_id ) + do_action( 'deleted_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value ); + return true; } @@ -399,6 +407,10 @@ function update_usermeta( $user_id, $meta_key, $meta_value ) { } $cur = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) ); + + if ( $cur ) + do_action( 'update_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value ); + if ( !$cur ) $wpdb->insert($wpdb->usermeta, compact('user_id', 'meta_key', 'meta_value') ); else if ( $cur->meta_value != $meta_value ) @@ -408,6 +420,11 @@ function update_usermeta( $user_id, $meta_key, $meta_value ) { wp_cache_delete($user_id, 'users'); + if ( !$cur ) + do_action( 'added_usermeta', $wpdb->insert_id, $user_id, $meta_key, $meta_value ); + else + do_action( 'updated_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value ); + return true; }