Advertisement
nouredinAlhabal

Updating user meta shortcode

Mar 21st, 2021
857
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2.     function wpses_385303_change_validate() {
  3.         if (is_user_logged_in()) {
  4.             $user_id = get_current_user_id();
  5.             $metas = array(
  6.             '_nickname_validated',
  7.             '_first_name_validated',
  8.             '_last_name_validated',
  9.             );
  10.  
  11.  
  12.             //If the form was posted (ie. the button was clicked) in a previous request
  13.             if (isset($_POST['validate_user'])) {
  14.                 if ($_POST['validate_user'] == $user_id) {//A little bit of security
  15.                     foreach($metas as $my_meta) {
  16.                         update_user_meta( $user_id, $my_meta, 'validated' )
  17.                     }
  18.  
  19.                     return "<div class='user_updated'>Updated!</div>";
  20.                 }
  21.             }
  22.         }
  23.  
  24.  
  25.         //Show the form
  26.         return "<form method='post'>
  27.            <input type='hidden' name='validate_user' value='$user_id' />
  28.            <input type='submit' value='Validate' />
  29.            </form>";
  30.  
  31.     }
  32.     add_shortcode('change_validate','wpses_385303_change_validate');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement