/** * Toggle visibility of main user data editor container * Shows the container that holds both profile edit form and children list editor */document.addEventListener('DOMContentLoaded',function(){const toggleBtn = document.getElementById('toggle-profile-edit');const editorContainer = document.getElementById('edit-user-data');if(toggleBtn && editorContainer){ toggleBtn.addEventListener('click',function(e){ e.preventDefault(); editorContainer.style.display='block';});}});/** * Profile form data pre-population and interaction handlers * * Handles all profile edit form functionality: * - Pre-fills form fields with current user data on page load * - Manages pending email change state (disables field, shows warning) * - Handles form cancel button to hide form without saving * - Handles pending email cancellation via AJAX request */document.addEventListener('DOMContentLoaded',function(){// Get data from backend containerconst profileData = document.getElementById('user-profile-data');if(!profileData)return;const displayName = profileData.dataset.displayName;const email = profileData.dataset.email;const phone = profileData.dataset.phone;const pendingEmail = profileData.dataset.pendingEmail;const nonce = profileData.dataset.nonce;// Get form elementsconst nameInput = document.getElementById('edit-profile-data-name');const emailInput = document.getElementById('edit-profile-data-email');const phoneInput = document.getElementById('edit-profile-data-phone');const nonceInput = document.getElementById('profile-edit-nonce');const pendingMessage = document.getElementById('edit-profile-data-email-message');const cancelBtn = document.getElementById('cancel-profile-edit');const editContainer = document.getElementById('edit-profile-data');const cancelEmailLink = document.getElementById('edit-profile-data-email-cancel');// Pre-fill data immediately on page loadif(nameInput) nameInput.value= displayName;if(phoneInput) phoneInput.value= phone;if(nonceInput) nonceInput.value= nonce;// Handle pending email state on page loadif(pendingEmail){// User has pending email change - disable field and show new email emailInput.disabled=true; emailInput.value= pendingEmail;if(pendingMessage) pendingMessage.style.display='block';}else{// No pending change - show current email and allow editing emailInput.disabled=false; emailInput.value= email;if(pendingMessage) pendingMessage.style.display='none';}// Cancel button - hide form without savingif(cancelBtn && editContainer){ cancelBtn.addEventListener('click',function(){ editContainer.style.display='none';});}// Cancel pending email change via AJAXif(cancelEmailLink){ cancelEmailLink.addEventListener('click',function(e){ e.preventDefault();// Send AJAX request to remove pending email changefetch('/wp-admin/admin-post.php',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded',},body:newURLSearchParams({'action':'cancel_email_change','nonce': nonce})}).then(response => response.json()).then(data =>{if(data.success){// Reload page to refresh form state window.location.reload();}});});}});/** * Profile form visibility toggle on button click * * Shows the profile edit form container when user clicks the edit button. * This handler is separate from the pre-population handler above to maintain * clean separation between page load initialization and user interaction. * Re-populates fields on each toggle to ensure data is current. */document.addEventListener('DOMContentLoaded',function(){// Get data from backend containerconst profileData = document.getElementById('user-profile-data');if(!profileData)return;const displayName = profileData.dataset.displayName;const email = profileData.dataset.email;const pendingEmail = profileData.dataset.pendingEmail;const nonce = profileData.dataset.nonce;// Get form elementsconst toggleBtn = document.getElementById('toggle-profile-edit');const editContainer = document.getElementById('edit-profile-data');const cancelBtn = document.getElementById('cancel-profile-edit');const nameInput = document.getElementById('edit-profile-data-name');const emailInput = document.getElementById('edit-profile-data-email');const nonceInput = document.getElementById('profile-edit-nonce');const pendingMessage = document.getElementById('edit-profile-data-email-message');// Toggle button - show form and populate dataif(toggleBtn && editContainer){ toggleBtn.addEventListener('click',function(e){ e.preventDefault();// Show form editContainer.style.display='block';// Populate fieldsif(nameInput) nameInput.value= displayName;if(emailInput) emailInput.value= email;if(nonceInput) nonceInput.value= nonce;// Handle pending email stateif(pendingEmail){// Disable email field emailInput.disabled=true; emailInput.value= pendingEmail;// Show warning messageif(pendingMessage) pendingMessage.style.display='block';}else{// Enable email field emailInput.disabled=false;// Hide warning messageif(pendingMessage) pendingMessage.style.display='none';}});}// Cancel button - hide form without savingif(cancelBtn && editContainer){ cancelBtn.addEventListener('click',function(){ editContainer.style.display='none';});}});
JavaScript
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.