File: /volume1/web/Marchisa-Toman/wp-content/themes/enfold-child/functions - Copy (5).php
<?php
/*
* Add your own functions here. You can also copy some of the theme functions into this file.
* Wordpress will use those functions instead of the original functions then.
*/
/*function change_menu($items)
{
foreach($items as $item){
if( $item->title == "Logout"){
$item->url = $item->url . "&_wpnonce=" . wp_create_nonce( 'log-out' );
}
}
return $items;
}
add_filter('wp_nav_menu_objects', 'change_menu'); */
/*add_action( 'login_form_logout', function ()
{
$user = wp_get_current_user();
wp_logout();
if ( ! empty( $_REQUEST['redirect_to'] ) )
{
$redirect_to = $requested_redirect_to = $_REQUEST['redirect_to'];
} else
{
$redirect_to = 'wp-login.php?loggedout=true';
$requested_redirect_to = '';
} */
/**
* Filters the log out redirect URL.
*
* @since 4.2.0
*
* @param string $redirect_to The redirect destination URL.
* @param string $requested_redirect_to The requested redirect destination URL passed as a parameter.
* @param WP_User $user The WP_User object for the user that's logging out.
*/
/* $redirect_to = apply_filters( 'logout_redirect', $redirect_to, $requested_redirect_to, $user );
wp_safe_redirect( $redirect_to );
exit;
}); */
function italian_zoom_invitee($user_id)
{
$single = TRUE ;
$language_spoken = get_user_meta($user_id,"language_spoken",$single) ;
if(($language_spoken) AND ($language_spoken == "I"))
{
return TRUE;
}
else
{
return FALSE;
}
}
function english_zoom_invitee($user_id)
{
$single = TRUE ;
$language_spoken = get_user_meta($user_id,"language_spoken",$single) ;
if(($language_spoken) AND (($language_spoken == "E") OR ($language_spoken == "B") ))
{
return TRUE;
}
else
{
return FALSE;
}
}
add_action( 'admin_post_nopriv_construct_generic_email', 'process_construct_generic_email' );
add_action( 'admin_post_construct_generic_email', 'process_construct_generic_email' );
function process_construct_generic_email()
{
global $wpdb;
echo('<div style="margin-left:50px;margin-top:50px;">Constructing Email<br/></div>');
echo('<div style="margin-left:50px;margin-top-50px;">');
$email_header_id = $_POST['email_header_id'] ;
$email_body_id = $_POST['email_body_id'] ;
$email_footer_id = $_POST['email_footer_id'] ;
$email_name = $_POST['email_name'] ;
$language = $_POST['language'] ;
$entered_by_user_id = get_current_user_id();
$profile_user_data = get_userdata( $entered_by_user_id );
$first_name = $profile_user_data->first_name ;
$last_name = $profile_user_data->last_name ;
$full_name = $first_name.' '.$last_name ;
$post_type = 'em_content' ;
$post_status = 'publish' ;
if($language == "Italian")
{
$em_header_category = 12 ;
$em_body_category = 13 ;
$em_footer_category = 14 ;
}
else /* English */
{
$em_header_category = 8 ;
$em_body_category = 11 ;
$em_footer_category = 10 ;
}
$get_content_error = false ;
/* Get Email Header */
$header_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = $email_header_id AND post_status = '$post_status' AND post_type = '$post_type'" ));
if (!empty($header_row))
{
$email_header_content = $header_row->post_content ;
$email_header = trim($email_header_content) ;
}
else
{
echo('EMAIL HEADER NOT FOUND<br/>') ;
$get_content_error = true ;
}
/* Get Email Body */
$body_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = $email_body_id AND post_status = '$post_status' AND post_type = '$post_type'" ));
if (!empty($body_row))
{
$email_body_content = $body_row->post_content ;
$email_body = trim($email_body_content) ;
$email_title = $body_row->post_title ;
}
else
{
$get_content_error = true ;
}
/* Get Email Footer */
$footer_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = $email_footer_id AND post_status = '$post_status' AND post_type = '$post_type'" ));
if (!empty($footer_row))
{
$email_footer_content = $footer_row->post_content ;
$email_footer = trim($email_footer_content) ;
}
else
{
echo('EMAIL FOOTER NOT FOUND<br/>') ;
$get_content_error = true ;
}
if(!$get_content_error)
{
/* Insert email into Emails table */
$email_complete = trim($email_header).trim($email_body).trim($email_footer) ;
$entered_by = $full_name ;
$entered_date = date("Y-m-d H:i:s");
$insert_status = $wpdb->insert(
'user_emails',
array(
'title' => $email_title , /* String */
'name' => $email_name , /* String */
'email_header_id' => $email_header_id , /* Integer */
'email_body_id' => $email_body_id , /* Integer */
'email_footer_id' => $email_footer_id , /* Integer */
'date_created' => $entered_date , /* String */
'created_by' => $entered_by, /* string */
'email_complete_content' => $email_complete, /*String */
'language' => $language /* string */
),
array('%s','%s','%d','%d','%d','%s','%s','%s','%s')
);
if(!$insert_status)
{
echo('ERROR in trying to insert email into user_emails table<br/>') ;
}
else
{
echo('SUCCESS in inserting email into database<br/>') ;
}
}
else
{
echo('ERROR in trying to retrieve header, body, and footer from wp-posts table<br/>') ;
}
echo('<br/><br/><a href="/administration-menu/">Return to Administration Menu</a>');
echo('</div>');
}
add_action( 'admin_post_nopriv_select_generic_email', 'process_select_generic_email' );
add_action( 'admin_post_select_generic_email', 'process_select_generic_email' );
function process_select_generic_email()
{
global $wpdb;
$email_id = $_POST['email_id'] ;
$email_target = $_POST['email_target'] ;
$selected_by_user_id = get_current_user_id();
$profile_user_data = get_userdata( $selected_by_user_id );
$first_name = $profile_user_data->first_name ;
$last_name = $profile_user_data->last_name ;
$full_name = $first_name.' '.$last_name ;
$email_selected_by = $full_name ;
$email_selected_date = date("Y-m-d H:i:s");
echo('<div style="margin-left:50px;margin-top:50px;">Inserting Selected Email into Queue<br/></div>');
echo('<div style="margin-left:50px;margin-top:50px;">Selected Email will target '.$email_target.'<br/></div>');
echo('<div style="margin-left:50px;margin-top:50px;">');
/* Delete all records in queued_user_email to ensure only one exists */
$delete_status = $wpdb->query( "DELETE FROM queued_user_email") ;
if(!$delete_status)
{
echo('FAILURE to delete previous queued email<br/>') ;
}
/* Insert selected email into Queued Emails table */
$insert_status = $wpdb->insert(
'queued_user_email',
array(
'id' => $email_id , /* Integer */
'selected_by' => $email_selected_by , /* string */
'queued_date' => $email_selected_date, /* String */
'email_target' =>$email_target
),
array('%d','%s','%s','%s')
);
if(!$insert_status)
{
echo('ERROR in trying to insert email into queued_user_email database table<br/>') ;
}
else
{
echo('SUCCESS in inserting queued email into database table<br/>') ;
}
echo('<br/><br/><a href="/administration-menu/">Return to Administration Menu</a>');
echo('</div>');
}
add_action( 'admin_post_nopriv_send_generic_emails', 'process_send_generic_emails' );
add_action( 'admin_post_send_generic_emails', 'process_send_generic_emails' );
function process_send_generic_emails()
{
global $wpdb;
$single = TRUE ;
$email_id = $_POST['email_id'];
$email_subject_form = $_POST['email_subject_form'];
$send_emails = true ;
$recipients = email_target_name();
if($recipients == "email_tester")
{
$test_or_prod = "TEST" ;
}
else
{
$test_or_prod = "PROD" ;
}
if(isset($_POST['user_id']))
{
/* Retrieving each selected user_id and loading local array */
$arr_idx = -1 ;
foreach ($_POST['user_id'] as $user_id)
{
$arr_idx = $arr_idx + 1 ;
$user_id_arr[$arr_idx] = $user_id ;
}
$number_user_ids = $arr_idx - 1 ;
$last_array_idx = $arr_idx ;
}
else
{
$send_emails = FALSE ; /* no user_ids selected */
}
$include_photo = $_POST['include_photo'] ;
if(isset($include_photo) AND ($include_photo == "Yes"))
{
$include_profile_photo = TRUE ;
}
else
{
$include_profile_photo = FALSE ;
}
/* Test for missing input fields */
echo('<div style="margin-left:50px;margin-top:50px;">Sending Emails<br/></div>');
echo('<div style="margin-left:50px;margin-top:50px;">');
/* retrieve email from user_email */
$email_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM user_emails WHERE id = $email_id " ));
if (!empty($email_row))
{
$email_header_id = $email_row->email_header_id ;
$email_body_id = $email_row->email_body_id ;
$email_footer_id = $email_row->email_footer_id ;
$email_title = $email_row->title ;
$email_language = $email_row->language ;
}
else
{
echo('EMAIL NOT FOUND<br/>') ;
$send_emails = false ;
}
/* get Email Header */
$post_type = 'em_content' ;
$post_status = 'publish' ;
$header_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = $email_header_id AND post_status = '$post_status' AND post_type = '$post_type'" ));
if (!empty($header_row))
{
$email_header= $header_row->post_content ;
}
else
{
echo('EMAIL HEADER NOT FOUND<br/>') ;
$send_emails = false ;
}
/* get email body */
$post_type = 'em_content' ;
$post_status = 'publish' ;
$body_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = $email_body_id AND post_status = '$post_status' AND post_type = '$post_type'" ));
if (!empty($body_row))
{
$email_body = $body_row->post_content ;
$email_title = $body_row->post_title ;
$email_subject_post = $email_title ;
}
else
{
echo('EMAIL BODY NOT FOUND<br/>') ;
$send_emails = false ;
}
/* get email footer */
$post_type = 'em_content' ;
$post_status = 'publish' ;
$footer_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = $email_footer_id AND post_status = '$post_status' AND post_type = '$post_type'" ));
if (!empty($footer_row))
{
$email_footer = $footer_row->post_content ;
}
else
{
echo('EMAIL FOOTER NOT FOUND<br/>') ;
$send_emails = false ;
}
if(isset($email_subject_form))
{
$subject_len = strlen($email_subject_form) ;
if($subject_len > 2)
{
$email_subject = $email_subject_form ;
}
else
{
$email_subject = $email_subject_post ;
}
}
else
{
$email_subject = $email_subject_post ;
}
if($recipients == "email_tester")
{
$email_subject_qualified = 'MT-TST --'.$email_subject ;
}
else
{
$email_subject_qualified = $email_subject ;
}
$subject = $email_subject_qualified ;
$email_sender_account = '<tom.marchisa@marchisa-toman.com>';
$email_sender = "Tom Marchisa" ;
$email_sender_header = 'From: Tom Marchisa '.$email_sender_account ;
/* display to-be-sent-email */
if($send_emails)
{
echo('</div>');
echo('<div style="margin-left:50px;margin-top:50px;">');
echo('The following Email will be sent <span style="font-weight:bold;font-size:1.1em;"> '.$email_sender_header.'</span><br/>');
echo('The Subject line will be:<span style="font-weight:bold;font-size:1.1em;"> '.$subject.'</span><br/><br/>');
echo('Email will be sent to: <span style="font-weight:bold;font-size:1.1em;"> '.$recipients.'</span><br/><br/>');
echo('</div>');
echo('<div style="border-width:2px;border-style:solid;border-color:black;padding:10px;">');
$body_header = $email_header ;
$salutation = 'Hi First Name,<br/><br/>';
$body_pre1 = $body_header.$salutation ;
/* add 2 blank lines after post content */
$email_body1 = trim($email_body) ;
$body1 = $body_pre1.$email_body1.$email_footer ;
echo('FINAL EMAIL='.$body1.'<br/><br/>') ;
echo('</div>');
date_default_timezone_set('America/Los_Angeles');
$email_sent_date = date("Y-m-d H:i:s");
$user_cnt = 0 ;
$sent_cnt = 0 ;
echo('<table>');
echo('<tr><td>Count</td><td>Status</td><td>User ID</td><td>Email Address</td><td>User Name</td><td>Username</td></tr>');
/* loop through local array of targeted users with values sent via POST variable */
$upper_limit = $last_array_idx ;
$users_loop = -1 ;
while($users_loop < $upper_limit)
{
$users_loop = $users_loop + 1 ;
$user_id = $user_id_arr[$users_loop] ;
$user_info = get_userdata($user_id);
$email_address = $user_info->user_email;
$current_name = $user_info->display_name ;
$first_name = $user_info->first_name ;
$username = $user_info->user_login ;
$table_user_id = $user_id ;
$sent_text = "Email Sent" ;
$body_header = $email_header ;
if($email_language == "Italian")
{
$salutation_pre = "Ciao" ;
}
else
{
$salutation_pre = "Hi" ;
}
$salutation = $salutation_pre.' '. $first_name.',<br/><br/>';
/* add profile photo if form says so */
if($include_profile_photo)
{
$key = 'user_profile_photo' ;
$image_post_id = get_user_meta($user_id, $key, $single);
if(!$image_post_id)
{
$photo_url='https://www.marchisa-toman.com/wp_content/uploads/2022/04/no-photo-submitted.jpg' ;
}
else
{
$key = '_wp_attached_file' ;
$photo_url1 = get_post_meta($image_post_id,$key,$single);
$photo_url = 'https://www.marchisa-toman.com/wp-content/uploads/'.$photo_url1 ;
}
$photo_code = '<img style="padding:10px;" src="'.$photo_url.'" width="100"/>' ;
$body_pre = $body_header.$salutation.$photo_code ;
}
else
{
$body_pre = $body_header.$salutation ;
}
$body = trim($body_pre).trim($email_body).trim($email_footer) ;
$to = $email_address ;
$headers[] = $email_sender_header ;
$headers[] = 'Bcc: tomtomanmarchisa@gmail.com';
$headers[] = 'Content-Type: text/html; charset=UTF-8';
$sent_cnt = $sent_cnt + 1 ;
wp_mail( $to, $subject, $body, $headers );
sleep(2) ;
$insert_status = insert_sent_email_into_db($user_id,$email_sent_date,$email_sender,$test_or_prod,$email_header_id,$email_body_id,$email_footer_id,$email_id,$email_language,$body) ;
if(!$insert_status)
{
echo('EMAIL NOT INSERTED for '.$user_id.'<br/>');
}
echo('<tr><td>'.$sent_cnt.' . </td><td>'.$sent_text.'</td><td>'.$table_user_id.'</td><td>'.$email_address.'</td><td>'.$current_name.'</td><td>'.$username.'</td></tr>') ;
} /* FOR EACH User in array */
echo('</table>');
echo('Sent Email count = '.$sent_cnt.' ');
} /* Send Emails */
else
{
echo('Emails NOT sent <br/><br/>');
}
echo('<br/><br/><a href="/administration-menu/">Return to Administration Menu</a>');
echo('</div>');
}
function insert_sent_email_into_db($user_id,$sent_date,$sent_from,$test_or_production,$email_header_id,$email_body_id,$email_footer_id,$email_id,$email_language,$body)
{
global $wpdb;
$wpdb->show_errors();
$insert_status = $wpdb->insert(
'user_emails_sent',
array(
'user_id' => $user_id ,
'sent_date' => $sent_date ,
'sent_from' => $sent_from ,
'test_or_production' => $test_or_production ,
'email_header_id' => $email_header_id ,
'email_body_id' => $email_body_id ,
'email_footer_id' => $email_footer_id,
'user_emails_id' => $email_id,
'language' => $email_language,
'email_body' => $body
),
array('%d','%s','%s','%s','%d','%d','%d','%d','%s','%s')
);
if(!($insert_status)) /* Failure to Insert */
{
return FALSE ;
$wpdb->hide_errors();
}
else
{
return TRUE ;
$wpdb->hide_errors();
}
}
function get_common_ancestor($zoom_event_id)
{
global $wpdb ;
$one_row = $wpdb->get_row( $wpdb->prepare("SELECT * FROM zoom_events WHERE event_id = $zoom_event_id" ));
if ( !empty($one_row) )
{
$common_ancestor = $one_row->common_ancestor ;
}
else
{
$common_ancestor = "???" ;
}
return $common_ancestor ;
}
function get_relationship_to_common_ancestor($user_id_passed,$zoom_event_id_passed)
{
global $wpdb ;
$user_id = $user_id_passed ;
$zoom_event_id = $zoom_event_id_passed ;
$one_row = $wpdb->get_row( $wpdb->prepare("SELECT * FROM user_zoom_events_xref WHERE event_id = $zoom_event_id AND user_id = $user_id" ));
if ( !empty($one_row) )
{
$relationship_to_common_ancestor = $one_row->relationship_to_common_ancestor ;
}
else
{
$relationship_to_common_ancestor = "???" ;
}
return $relationship_to_common_ancestor ;
}
function email_target_name()
{
global $wpdb ;
$queued_emails = $wpdb->get_results ( "SELECT * FROM queued_user_email " );
if(!empty($queued_emails) )
{
foreach ($queued_emails as $queued_email) /* there will be only 1 */
{
$email_target = $queued_email->email_target ;
}
}
else
{
$email_target = "NONE" ;
}
return $email_target ;
}
function get_ancestor_map_link($user_id_passed)
{
/* $map_id is in format [wpgmza id="4"] */
/* need to pass back only numeric */
global $wpdb ;
$map_id = "N/A" ;
$one_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM italian_ancestors_towns_map_xref WHERE user_id = $user_id_passed " ) );
if ( !empty($one_row) )
{
$map_shortcode = $one_row->map_id ;
$map_id_len = strlen($map_shortcode) ;
if($map_id_len == 15) /* single digit ID */
{
$map_id = substr($map_shortcode,12,1) ;
}
else
{
$map_id = substr($map_shortcode,12,2) ;
}
}
return $map_id ;
}
add_action( 'admin_post_nopriv_find_pages_w_text', 'process_srchform_data' );
add_action( 'admin_post_find_pages_w_text', 'process_srchform_data' );
function process_srchform_data()
{
// Handle request then generate response using echo or leaving PHP and using HTML
$search_text = $_POST['search_text'];
echo('<div style="margin-left:50px;margin-top:50px;">Searching for <scan style="font-size:1.3em;font-weight:bold;">'.$search_text.'</scan> in Page Content<br/><br/></div>');
echo('<div style="margin-left:50px;margin-top-50px;">');
$found_cnt = 0 ;
$page_cnt = 0 ;
global $wpdb;
$all_pages = $wpdb->get_results ( "SELECT * FROM wp_posts WHERE post_type = 'page' AND post_status = 'publish' " );
if ( !empty($all_pages) )
{
$search_text_upper = strtoupper($search_text) ;
foreach ( $all_pages as $all_page )
{
$page_cnt = $page_cnt + 1 ;
$post_id = $all_page->ID ;
$post_title = $all_page->post_title ;
$post_slug = $all_page->post_name ;
$post_content = $all_page->post_content ;
$post_content_upper = strtoupper($post_content) ;
$found_text = strpos($post_content_upper,$search_text_upper) ;
if($found_text !== false)
{
$found_cnt = $found_cnt + 1 ;
if($found_cnt == 1)
{
echo('<table>');
echo('<tr><td>#</td><td>Page Title</td><td>Slug</td><td>Edit Link</td></tr>');
}
$page_url = '/'.$post_slug.'/';
$page_link = '<a href="'.$page_url.'" target="_blank" rel="noopener noreferrer">'.$post_slug.'</a>';
if( $post = get_page_by_path( $post_slug, OBJECT, 'page' ) )
{
$option_post_id = $post->ID;
}
$edit_link = '<a href="/wp-admin/post.php?post='.$option_post_id.'&action=edit&classic-editor" target="_Blank" rel="noopener noreferrer">View '.$post_title.' in Editor</a>';
echo('<tr><td>'.$found_cnt.'</td><td>'.$post_title.'</td><td>'.$page_link.'</td><td>'.$edit_link.'</td></tr>');
}
}
if($found_cnt !== 0)
{
echo('</table>');
}
else
{
echo('NO PAGES with <scan style="font-size:1.3em;font-weight:bold;">'.$search_text.'</scan> in Page Content<br/>');
}
}
else
{
echo('Problem accessing wp-posts table<br/><br/>');
}
echo('<br/><br/><a href="/find-text-in-post-page-content">Return to Search Form</a>');
echo('</div>');
}
add_action( 'admin_post_nopriv_find_pages_w_image_tags', 'process_imgsrchform_data' );
add_action( 'admin_post_find_pages_w_image_tags', 'process_imgsrchform_data' );
function process_imgsrchform_data()
{
// Handle request then generate response using echo or leaving PHP and using HTML
$search_text = $_POST['search_text'];
echo('<div style="margin-left:50px;margin-top:50px;">Searching for <scan style="font-size:1.3em;font-weight:bold;">'.$search_text.'</scan> in Page Content<br/><br/></div>');
echo('<div style="margin-left:50px;margin-top-50px;">');
$found_cnt = 0 ;
$page_cnt = 0 ;
global $wpdb;
$all_pages = $wpdb->get_results ( "SELECT * FROM wp_posts WHERE post_type = 'page' AND post_status = 'publish' " );
if ( !empty($all_pages) )
{
$search_text_upper = strtoupper($search_text) ;
foreach ( $all_pages as $all_page )
{
$page_cnt = $page_cnt + 1 ;
$post_id = $all_page->ID ;
$post_title = $all_page->post_title ;
$post_slug = $all_page->post_name ;
$post_content = $all_page->post_content ;
$post_content_orig_case = $post_content ;
$post_content_upper = strtoupper($post_content) ;
$found_text = strpos($post_content_upper,$search_text_upper) ;
if($found_text !== false)
{
$found_cnt = $found_cnt + 1 ;
if($found_cnt == 1)
{
echo('<table>');
echo('<tr><td>#</td><td>Page Title</td><td>Slug</td><td>Edit Link</td><td>Src Pos</td><td>JPG Pos</td><td>IMG Tag</td></tr>');
}
$page_url = '/'.$post_slug.'/';
$found_jpg_pos_tmp = strpos($post_content_upper,".JPG");
if(!$found_jpg_pos_tmp)
{
$found_jpg_pos = 0 ;
}
else
{
$found_jpg_pos = $found_jpg_pos_tmp ;
}
$tag_len = $found_jpg_pos - $found_text + 4 ;
if($found_jpg_pos !== 0)
{
if($tag_len < 150)
{
$image_tag = substr($post_content_orig_case,$found_text,$tag_len) ;
}
else
{
$image_tag = substr($post_content_orig_case,$found_text,150) ;
}
}
else
{
$image_tag = "No JPG" ;
}
$page_link = '<a href="'.$page_url.'" target="_blank" rel="noopener noreferrer">'.$post_slug.'</a>';
if( $post = get_page_by_path( $post_slug, OBJECT, 'page' ) )
{
$option_post_id = $post->ID;
}
$edit_link = '<a href="/wp-admin/post.php?post='.$option_post_id.'&action=edit&classic-editor" target="_Blank" rel="noopener noreferrer">View '.$post_title.' in Editor</a>';
echo('<tr><td>'.$found_cnt.'</td><td>'.$post_title.'</td><td>'.$page_link.'</td><td>'.$edit_link.'</td><td>'.$found_text.'</td><td>'.$found_jpg_pos.'</td><td>'.$image_tag.'</td></tr>');
}
}
if($found_cnt !== 0)
{
echo('</table>');
}
else
{
echo('NO PAGES with <scan style="font-size:1.3em;font-weight:bold;">'.$search_text.'</scan> in Page Content<br/>');
}
}
else
{
echo('Problem accessing wp-posts table<br/><br/>');
}
echo('<br/><br/><a href="/find-image-tags-in-post-pages">Return to Search Form</a>');
echo('</div>');
}
function is_admin_acct()
{
$my_user_id = get_current_user_id();
/* Tom */
if($my_user_id == 1)
{
$admin_user = TRUE ;
}
else
{
$admin_user = FALSE ;
}
return $admin_user ;
}
function is_email_tester()
{
$my_user_id = get_current_user_id();
/* Tom */
if($my_user_id == 1)
{
$email_tester = TRUE ;
}
else
{
$email_tester = FALSE ;
}
return $email_tester ;
}
function get_image_width($image_url)
{
$filename = $image_url ;
$filename_for_imagesize = substr($filename,1) ; /* remove leading slash */
list($width) = getimagesize($filename_for_imagesize);
return $width ;
}
function get_image_height($image_url)
{
$filename = $image_url ;
$filename_for_imagesize = substr($filename,1) ; /* remove leading slash */
list($width, $height) = getimagesize($filename_for_imagesize);
return $height ;
}
add_action( 'admin_post_nopriv_find_snippets_w_text', 'process_srchsnippet_data' );
add_action( 'admin_post_find_snippets_w_text', 'process_srchsnippet_data' );
function process_srchsnippet_data()
{
// Handle request then generate response using echo or leaving PHP and using HTML
$search_text = $_POST['search_text'];
echo('<div style="margin-left:50px;margin-top:50px;">Searching for <scan style="font-size:1.3em;font-weight:bold;">'.$search_text.'</scan> in XYZ-ICS Snippet Content<br/><br/></div>');
echo('<div style="margin-left:50px;margin-top-50px;">');
$found_cnt = 0 ;
$snippet_cnt = 0 ;
global $wpdb;
$all_snippets = $wpdb->get_results ( "SELECT * FROM wp_xyz_ics_short_code WHERE status = 1 " );
if ( !empty($all_snippets) )
{
$search_text_upper = strtoupper($search_text) ;
foreach ( $all_snippets as $all_snippet )
{
$snippet_cnt = $snippet_cnt + 1 ;
$snippet_id = $all_snippet->id ;
$snippet_title = $all_snippet->title ;
$snippet_content = $all_snippet->content ;
$snippet_content_upper = strtoupper($snippet_content) ;
$found_text = strpos($snippet_content_upper,$search_text_upper) ;
if($found_text !== false)
{
$found_cnt = $found_cnt + 1 ;
if($found_cnt == 1)
{
echo('<table>');
echo('<tr><td>#</td><td>Snippet Title</td><td>Edit Link</td></tr>');
}
/* $edit_link = '<a href="/wp-admin/post.php?post='.$option_post_id.'&action=edit&classic-editor" target="_Blank" rel="noopener noreferrer">View '.$post_title.' in Editor</a>'; */
/* $edit_link= '<a href=/wp-admin/admin.php?page=xyz-wp-insert-code-snippet-manage&action=snippet-edit&snippetId='.$snippet_id.'&type=0&snippet_type=2&pageno=1" target="_blank">View '.$snippet_title.' in Editor</a>' ; */
$edit_link= '<a href=/wp-admin/admin.php?page=xyz-wp-insert-code-snippet-manage&action=snippet-edit&snippetId='.$snippet_id.'&type=0&snippet_type=2&pageno=1" target="_blank">View '.$snippet_title.' in Editor</a>' ;
echo('<tr><td>'.$found_cnt.'</td><td>'.$snippet_title.'</td><td>'.$edit_link.'</td></tr>');
}
}
if($found_cnt !== 0)
{
echo('</table>');
}
else
{
echo('NO SNIPPETS with <scan style="font-size:1.3em;font-weight:bold;">'.$search_text.'</scan> in Snippet Content<br/>');
}
}
else
{
echo('Problem accessing wp_xyz_ics_short_code table<br/><br/>');
}
echo('<br/><br/><a href="/find-text-in-snippet-content">Return to Search Form</a>');
echo('</div>');
}
/* Set a Custom Reply-To Email
*
* Original doc: https://wpmailsmtp.com/docs/setting-a-custom-reply-to-email/
*/
function wp_mail_smtp_dev_reply_to( $args )
{
$reply_to = 'Reply-To: Tom Marchisa <tmarchisa@gmail.com>';
if ( ! empty( $args[ 'headers' ] ) )
{
if ( ! is_array( $args[ 'headers' ] ) ) {
$args[ 'headers' ] = array_filter( explode( "\n", str_replace( "\r\n", "\n", $args[ 'headers' ] ) ) );
}
// Filter out all other Reply-To headers.
$args[ 'headers' ] = array_filter( $args[ 'headers' ], function ( $header )
{
return strpos( strtolower( $header ), 'reply-to' ) !== 0;
} );
}
else
{
$args[ 'headers' ] = [];
}
$args[ 'headers' ][] = $reply_to;
return $args;
}
add_filter( 'wp_mail', 'wp_mail_smtp_dev_reply_to', PHP_INT_MAX );
?>