Resources

My Agape try

Your Agape try


Support Forum

You must be logged in to post Login Register

Search 
Search Forums:


 




email noticication of private post publish to one user only

UserPost

12:36 pm
September 30, 2011


katarsis20032002

Member

posts 3

1

Hello, i want to add an action to 'publish_post' hook that send a notification when a post is publish. My problem is that i want to notify only the user that  can view de new post. (is limited by Role Scoper )


There is any way that this user (that role scoper permit read the recent post) have an optin that i can use in this snippet for example?

function email_members($post_ID)  {
    global $wpdb;
    $usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;");
    $users = implode(",", $usersarray);
    mail($users, "New WordPress recipe online!", 'A new recipe have been published on http://www.wprecipes.com';);
    return $post_ID;
}

add_action('publish_post', 'email_members');

In the example above i want that $users variable will be the user i permit through role scoper read the post . how can i do this ? any idea?
thanks a lot!!!

10:29 pm
October 4, 2011


Kevin

Admin

posts 2502

2

You can retrieve applicable user IDs as follows:

global $scoper;
$user_ids = $scoper->users_who_can( 'edit_published_posts', COL_ID_RS, 'post', $post_ID );

If this is for a custom post type with a different capability requirement, change that argument accordingly. But don't change the 'post' argument, which corresponds to the posts db table.

7:22 am
October 5, 2011


katarsis20032002

Member

posts 3

3

Thnaks a lot, Kevin! I ´ll try this.

yesterday I found the way,  but isn´t very shinny (i'am not very shinny!! i'am not a developer!):


/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

ENVIAR MAIL NOTIFICACIÓN POR RUTINA NUEVA O INFORME NUEVO

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

function email_notificacion_informe_rutina()  {

//globalizo la bse de datos y el objeto $post para tomar la información que preciso

global $wpdb, $post;


//aca veo el tipo de post y solo aplico la acción si el tipo de post es informes o rutinas

$tipo_post=$post->post_type;

if ($tipo_post !=='post') {

return;


} else {


//tomo el id del usuario con derecho para ver el post (rutina o informe) y que queremos mandar un mail de notificaci´n

$query= "SELECT user_id FROM wp_user2role2object_rs WHERE obj_or_term_id=" . $post->ID; 

$userid_rs= $wpdb->get_var($query);

//con el dato anterior (id usuario) tengo el mail del mismo

$usermail_rs = get_the_author_meta('user_email', $userid_rs);

//Luego enviamos el mail$headers='From: My Name';

wp_mail($usermail_rs, "Check our new post!", 'A new post has been published on http://www.YOURBLOGURL.com. ' );


};

}

add_action('publish_post', 'email_notificacion_informe_rutina');


This work for me, but i try your funcion that is the rigth way..


thanks again, and, is there any,  i´ll waiting for suggestions

Katarasis


About the Agapetry forum

Currently Online:

14 Guests

Maximum Online: 150

Forums:

Groups: 2

Forums: 7

Topics: 1244

Posts: 5649

Members:

There are 1254 members

There are 1 guests


Kevin has made 2502 posts

Top Posters:

metal450 - 178

Ragnar - 108

YikYak - 70

whiteorb - 49

Daisy - 35

Administrator: Kevin | Moderators: Kevin