Aurangajeb

Run a JQuery code only for logged-in user (disable a field for logged-in user only)

Oct 13th, 2021
1,432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.46 KB | None | 0 0
  1. add_action( 'wp_footer', function () { ?>
  2.  
  3. <script>
  4.    
  5. jQuery(document).ready(function( $ ){
  6.     // Run this code only for logged-in user   
  7.     if(jQuery('body').hasClass('logged-in')){
  8.         // Disable email field
  9.         $( "#user_email_39" ).prop( "disabled", true );
  10.         // Alert on click the email field
  11.         $(document).on('click',function(e){
  12.             if(e.target.id == "user_email_39"){
  13.                 alert("The input field is disabled.");
  14.             }
  15.         });
  16.     }
  17. });
  18.    
  19.  
  20. </script>
  21. <?php } );
  22.  
Advertisement
Add Comment
Please, Sign In to add comment