Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author DBAR Productions

    (@dbar-productions)

    Right now, I don’t have any hooks on the admin side that would trigger after a new sheet is added. However, it’s very easy to add a hook in WordPress to check for ANY Posted forms. This is how I process signups on the front-end, by hooking into an early stage of WordPress and checking for Post submission, instead of checking & processing forms inside of the shortcode functions (which is bad practice).

    You should use the WordPress action hook ‘wp_loaded’ to call a function that then checks the global $_POST to see if the form you want to trigger the action from was submitted or not.

    On the admin side, creating a sign-up sheet is split into 2 parts, with 2 different forms. There is the sheet form which defines the type of sheet, description, and contact info. The second form is where you define all the tasks, and that form functions slightly differently depending on the type of sheet you created (single, recurring, etc.).

    Either of those can also be edited at any time for any sheet, so you might need to add some sort of check to see if it’s a new sheet, or simply an existing one that is being edited, before you send out the emails.

    Also note that there is no list of volunteers available for you to send mass emails to. The plugin can be set to allow people to sign up with or without requiring them to be logged in to a user account. So, you will either need to maintain your own mailing list of volunteers, or you will need to grab emails from all WordPress users you want to email. I suppose you could also search through the signup table in the database that my plugin creates, and get emails from people who have previously signed up. You would just have to make sure you set the options in the plugin to NOT delete expired signups so you can keep a record of everyone who signed up for something. Probably best to set up a special user role or capability for your volunteers, and then just grab WordPress users from the database that have the role/capability with the get_users function.

    To figure out the POST and GET variables to check, to determine if it’s sheet or tasks that have been submitted, and if you are adding a new sheet or editing an existing one, look at lines 351 to 357 in the class-pta_sus_admin.php file. Most likely, you will want to wait to send the emails until after the tasks are added, in case you want to include any of that info in the emails. If you send the emails right after the sheet is created, there won’t be any task info yet.

    Here is some example code you can use in either your theme’s functions.php file or in a new plugin you create:

    function pta_sus_send_volunteer_emails() {
    	// Check if tasks form was submitted
    	if( $tasks_submitted = (isset($_POST['tasks_mode']) && $_POST['tasks_mode'] == 'submitted'); ) {
    		// Check if adding tasks to a new sheet or editing existing
    		if(!isset($_GET['sheet_id']) || empty($_GET['sheet_id'])) {
    			// Not editing
    
    			// Your emails code goes here
    		}
    	}
    }
    add_action('wp_loaded', 'pta_sus_send_volunteer_emails'));

    If you are not comfortable coding this function yourself, please contact me privately through my plugins site:
    https://stephensherrardplugins.com/contact/
    and we can discuss some custom programming for hire work to add this function for you.

    Thread Starter wenkunst

    (@wenkunst)

    Thanx for your quick and long answer, this is very helpful!

    I’m away a few days and after that I will have a look at your suggestions and discus this with my client. I think I will contact you for some custom programming!

    Thread Starter wenkunst

    (@wenkunst)

    A short follow up:

    I made a quick and dirty way to email all volunteers after adding a new sheet:

    First I made a new role ‘volunteer’. Make sure when you add new volunteers they have this role.

    function pta_sus_send_volunteer_emails() {
    	// Check if tasks form was submitted
    	if( $tasks_submitted = (isset($_POST['tasks_mode']) && $_POST['tasks_mode'] == 'submitted') ) {
    		// Check if adding tasks to a new sheet or editing existing
    		if(!isset($_GET['sheet_id']) || empty($_GET['sheet_id'])) {
    			// Not editing
    
    			// get list of volunteers
    			$blogusers = get_users( 'blog_id=1&role=volunteer' );
    			// Array of WP_User objects.
    			foreach ( $blogusers as $user ) {
    				//create list of bcc addresses
    				$BCCheader.= esc_html( $user->user_email ) . ', ';
    			}
    
    			$headers = array();
                $headers[]  = "From: " . get_bloginfo('name') . " <[email protected]>";
                $headers[]  = "Reply-To: [email protected]";
                $headers[]  = "Content-Type: text/html; charset=utf-8";
                $headers[]  = "Content-Transfer-Encoding: 8bit";
                $headers[]  = 'Bcc: ' . $BCCheader;
    
    			$message = 'Hi there, new sheet added!';
    
    // you can use for instance: $_POST['sheet_id'] and $_POST['sheet_title'] in your message
    
    	        wp_mail($to, $subject, $message, $headers);
    
    		}
    	}
    }
    add_action('wp_loaded', 'pta_sus_send_volunteer_emails');
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Send out mails to volunteers when adding a new sheet’ is closed to new replies.