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
This commit is contained in:
parent
0381e51fd6
commit
7886fac111
|
@ -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);
|
||||
|
|
|
@ -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,6 +575,8 @@ 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
|
||||
|
@ -580,6 +584,8 @@ function delete_post_meta($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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue