add post meta when post is being published

Posted: September 24, 2015 in Uncategorized
Tags:

/****************notification post type****************************/
function push_notification($post_id,$post) {

$blogusers = get_users( ‘blog_id=1&orderby=nicename&role=subscriber’ );
// Array of WP_User objects.
foreach ( $blogusers as $user ) {
$user_noti = get_user_meta($user->ID,’_user_noti’, true);
if(empty($user_noti)){ $user_noti = array(); }
if (in_array($post_id,$user_noti)) {
}
else{
array_push($user_noti,$post_id);
}
update_user_meta($user->ID,’_user_noti’,$user_noti);
//update_user_meta( $user->ID,’_user_noti’, $meta_value, $prev_value );
}

/*update_post_meta($post_id,’test’,$user->ID );*/

}
add_action(‘publish_notification’,’push_notification’,11,1);

function no_notification()
{

remove_action(‘publish_notification’,’push_notification’,11,1);
}
add_action(‘publish_to_publish’,’no_notification’);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s