• Resolved clickingclients

    (@clickingclients)


    I’m attempting to send some info via email once a record has been updated.

    Ideally I’d like to add Image URL in the body of the text.

    My image upload field has a Name: background_image
    and so I figured I could use [background_image] in the email body.

    This is instead adding the image, rather than the URL into the email.
    As, not all email providers are rendering the image.

    Is this possible?

    Thank you.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author xnau webdesign

    (@xnau)

    There isn’t any way that I know of to force an email client to show images in an email. This is under the control of the end user, so the best you can do is include the image tag like you’re doing. If the end user is set up to show images, it will be displayed. If it’s really important, you can include a note in the email asking them to turn images on.

    Thread Starter clickingclients

    (@clickingclients)

    Thank you.
    Having the actual image in the email isn’t ideally what I’d like.

    It would be great to add image URL in the body of the text.

    Is that possible?

    Plugin Author xnau webdesign

    (@xnau)

    It’s not easy to add the bare image URL to the template, it’s not normally set up to do that. If you don’t mind writing some code, you can do it by adding a custom tag.

    Thread Starter clickingclients

    (@clickingclients)

    That may be the option then.
    If I can figure out a way so it’s not overwritten in updates.
    Thanks again ??

    Thread Starter clickingclients

    (@clickingclients)

    Finished the shortcode to create the media uploaded raw URL.
    I can now add the url into an email.

    [bg_image_link full_path=yes]
    full_path is optional

    // Email tag for image url in PDB value
    add_shortcode('bg_image_link', 'cc_bg_image_link' );
    function cc_bg_image_link( $atts ) {
    	$record_id = get_admin_record_id();
    	
    	$record =  Participants_Db::get_participant($record_id); //need to find how to get First Record or First Participants.
        $full_path = (isset($atts['full_path']) && (sanitize_text_field( $atts['full_path'] ) == 'yes' )) ? get_site_url() . '/' : '/';
    	$uploads_path = $full_path . Participants_Db::files_location();
    	$img_url = $uploads_path . $record['background_image'];
    	
    	return $img_url;
    }
    
    function get_wp_admins_emails(){
        $admin_list = get_users('role=Administrator');
    	$valid_admins = array();
    	$temp_email = "";
    
        foreach ($admin_list as $this_admin) {
    		$temp_email = $this_admin->user_email;
    		$valid_admins[] = $temp_email;        
    	}  
    	return $valid_admins;
    }
    
    /**
    * finds the ID of a record if matching a WP admin email
    * 
    * Returns the first of multiple matches
    * 
    * @return int id number if valid id found
    * @return int|bool false if no valid id found
    */
    function get_admin_record_id(){
    	$adminsEmails = get_wp_admins_emails();
    	foreach ($adminsEmails as $email) {
    		$temp_id = Participants_Db::get_record_id_by_term('email', $email);
    		if(isset($temp_id) && $temp_id > 0 ) {
    			return $temp_id;
    		}
    	}
    	return false;
    }

    Feel free to use/adapt/critique this (perhaps there are obvious flaws I can’t see).

    Thanks again!

    Plugin Author xnau webdesign

    (@xnau)

    looks good!

    There is a method you can use to find the ID of a record in Participants Database:

    Participants_Db::get_record_id_by_term($term, $value, $single = true)

    Where $term is the name of the field. It will return the first match by default, but if you pass in false for $single, it will give you an array of matching IDs.

    This is described in the Plugin API

    Thread Starter clickingclients

    (@clickingclients)

    Good stuff.

    “get_admin_record_id()” is making use of that method get_record_id_by_term().

    So you are suggesting to use $single=false and compare all the admins.

    I was wondering that and I think it should do the trick. I’ll give it a go.

    Thank you.

    Thread Starter clickingclients

    (@clickingclients)

    Actually, on 2nd thoughts, the email address is the unique id I am looking for within PDB. So it only needs to return 1 result, rather than an array.

    Plugin Author xnau webdesign

    (@xnau)

    So, is it working?…looks to me like it will work.

    Thread Starter clickingclients

    (@clickingclients)

    Yes it is. Thank you.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Adding Image URL to Record Update Notification Email’ is closed to new replies.