I'm trying to send notifications for who followed some author when he published new post!

But it always sent to only one user not to all the followers!

So how can i send to all followers ids?



Now it working after change $user_id to $author

$followers = get_user_meta($author, '_pwuf_followers', true);

Good luck!

function to_followers_only_notify( $new_status, $old_status, $post ) {

    global $post;

    if ( 'publish' !== $new_status or 'publish' === $old_status )

        $user_id = get_current_user_id();
        $followers = get_user_meta($user_id, '_pwuf_followers', true);
        $followers = array_unique($followers);

        $post = get_post($post->ID);
        $author = $post->post_author;
        $author_name = get_the_author_meta( 'display_name', $author );

        $title = '<strong>'.$author_name.'</strong> ' . __('Published new post', 'dw-notifications'). ' <strong>'.$post->post_title.'</strong>';
        $link =  get_permalink($post->ID);
        $image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'post');
        $notif = array('title'=>$title, 'link' => $link, 'image' => $image);

        if ( !empty( $followers ) && is_array( $followers ) ) {

            $follower_ids = array();
            foreach( $followers as $follower ) {
                if ( is_numeric( $follower ) ) {

                    if(!$post->post_author || $post->post_author == $follower) continue;

                    $follower_ids[] = $follower;

            dwnotif_add_notification($follower_ids, $notif);

add_action( 'transition_post_status', 'to_followers_only_notify', 10, 3 );
  • How are followers implemented? WordPress doesn't have followers out of the box – Tom J Nowell Feb 12 at 15:16
  • 1
    hmmm googling suggests this is a 3rd party plugin by Pippins Plugins, pippinsplugins.com/series/creating-a-user-follow-system-plugin but also that you yourself asked this very question, and included more information than here on stackoverflow here: stackoverflow.com/questions/51266194/…, and got a working answer – Tom J Nowell Feb 12 at 15:17
  • Thnx tom, yeah but it was for notify users when someone followed the others! Now i need to notify the users that followed an author when he published new post. So how can i get first the users followers ids of the post author ID to send for them the notification, did you get it now :) – Adham Mohamed Feb 12 at 15:25
  • Question updated, I just missed to change the $user_id to $author – Adham Mohamed Feb 12 at 16:01
  • Keep in mind that 3rd party plugins aren't on topic on this stack, but yes, the author ID is the user ID – Tom J Nowell Feb 12 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.