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!