• Hi all currently I get data displaying the users posts on the users admin table for each user row in a custom column. I’d like to be able to have a button instead of the row content to be able to click and send an email with the ouput of my user posts function.. I know wp_mail is the route..

    Thanks! — Function below

    function new_modify_user_table_row_send_inv($value='', $column_name, $user_id ) {
        if ($column_name =='send_inventory') {
    			$posts = get_posts(array('author' => $user_id));
    			$tmpdata = array();
    			if(isset($posts) && !empty($posts))
    				foreach($posts as $post){
    					$tmpdata[] = "<li>".$post->post_title."</li>"."TEST";
    				}
            		$varnew = implode("\n",$tmpdata);
    	}
       return $varnew;
    }
    add_filter( 'manage_users_custom_column', 'new_modify_user_table_row_send_inv', 90, 3 );
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The easiest option would be to place links to a custom page which contain the user ID as part of the URL parameter. The page would be based on a template whose code takes the user ID, generates the email content, gets the proper email address, then sends the message via wp_mail(). There’s a way to add additional row action links under each user (links that appear on username hover, edit and delete by default).

    Leaving the table page just to send an email is not the best user experience. A better option would be to use AJAX to achieve the same functionality. Of course this involves JS or jQuery and is more complex to code. The AJAX callback server side essentially does the same thing as the custom page described earlier. But in this case one stays on the list table page. You can display a modal or hook into the list table messaging to confirm the mail was sent. A much better user experience.

Viewing 1 replies (of 1 total)
  • The topic ‘Email data from php output’ is closed to new replies.