This JS snippet complements the work done with Interaction Layers to show/hide various helper icons (cookie notices, chat widgets, back to top buttons, etc.) so that they do not cover the footer area.
<?phpdefine('TARGET_PAGE_SLUGS',['visitors']);define('TARGET_PAGE_IDS',[]);/** * Output user profile data container in page body * * Generates a hidden div with user profile data * (name, email, phone, pending email, nonce) * for JavaScript consumption. * Only runs on specified target pages for logged-in users. * * @since 1.0.0 */add_action('wp_body_open',function(){// Only output for logged-in usersif(!is_user_logged_in()){return;}// Check if current page matches target slugs or IDs$current_page_slug= get_post_field('post_name', get_queried_object_id());$current_page_id= get_queried_object_id();$is_target_page=in_array($current_page_slug,TARGET_PAGE_SLUGS)||in_array($current_page_id,TARGET_PAGE_IDS);if(!$is_target_page){return;}// Get current user data$current_user= wp_get_current_user();$user_id=$current_user->ID;$display_name=$current_user->display_name;$email=$current_user->user_email;$phone= get_user_meta($user_id,'phone_no',true);// Custom meta field// Check for pending email change$pending_email_data= get_user_meta($user_id,'_new_email',true);$pending_email='';if($pending_email_data&&isset($pending_email_data['newemail'])){$pending_email=$pending_email_data['newemail'];}// Generate nonce$nonce= wp_create_nonce('edit_profile_action');// Output data containerecho'<div id="user-profile-data" style="display:none;" data-user-id="'. esc_attr($user_id).'" data-nonce="'. esc_attr($nonce).'" data-display-name="'. esc_attr($display_name).'" data-email="'. esc_attr($email).'" data-phone="'. esc_attr($phone).'" data-pending-email="'. esc_attr($pending_email).'"></div>';});/** * Handle email confirmation from link * * Processes the email change confirmation when user * clicks the link sent to their new email address. * Verifies hash, updates user email, * removes pending change meta, * and redirects back to profile page. * * @since 1.0.0 */add_action('init',function(){// Handle email confirmationif(isset($_GET['newuseremail'])&& is_user_logged_in()){$hash= sanitize_text_field($_GET['newuseremail']);$current_user_id= get_current_user_id();// Get pending email data$pending_email_data= get_user_meta($current_user_id,'_new_email',true);if(!$pending_email_data||!isset($pending_email_data['hash'])){ wp_die('Invalid or expired confirmation link');}// Verify hash matchesif($pending_email_data['hash']!==$hash){ wp_die('Invalid confirmation link');}// Update email wp_update_user(array('ID'=> $current_user_id,'user_email'=> $pending_email_data['newemail']));// Delete pending email data delete_user_meta($current_user_id,'_new_email');// Redirect back to profile page with success indicator wp_redirect(home_url('/visitors/?email_updated=1'));exit;}});/** * Handle email change cancellation via AJAX * * Removes pending email change when user clicks cancel link. * Verifies nonce, deletes _new_email user meta, and * returns JSON success response. * * @since 1.0.0 */add_action('admin_post_cancel_email_change','handle_cancel_email_change');add_action('admin_post_nopriv_cancel_email_change','handle_cancel_email_change');functionhandle_cancel_email_change(){if(!is_user_logged_in()){wp_send_json_error('Unauthorized');}if(!isset($_POST['nonce'])||!wp_verify_nonce($_POST['nonce'],'edit_profile_action')){wp_send_json_error('Invalid nonce');}$current_user_id=get_current_user_id();delete_user_meta($current_user_id,'_new_email');wp_send_json_success();}
PHP
This code snippet is used in the following tutorial(s):
This website uses cookies to enhance your experience. Some are essential for site functionality, while others help us analyze and improve your usage experience. Please review your options and make your choice.
If you are under 16 years old, please ensure that you have received consent from your parent or guardian for any non-essential cookies.
Your privacy is important to us. You can adjust your cookie settings at any time. For more information about how we use data, please read our privacy policy. You may change your preferences at any time by clicking on the settings button below.
Note that if you choose to disable some types of cookies, it may impact your experience of the site and the services we are able to offer.
Essential cookies and services enable basic functions and are necessary for the proper functioning of the website. These cookies and services do not require user permission according to GDPR.
These cookies and services are necessary for the proper functioning of the website, but their use requires user consent. These may include, but are not limited to: payment gateways, captcha services, embedded booking services.
This category includes all cookies, domains, and services that do not fall into the other specified categories or have not been explicitly categorized.
This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.