Search
 
SCRIPT & CODE EXAMPLE
 

PHP

wordpress add meta user

<?php
// Add to a WordPress User some metaData (so you can control it somewhere else)
$user_id = 1;
$metaData = 'subscribed';
add_user_meta( $user_id, '_subscribedService1', $metaData);
?>
Comment

wordpress user meta fields

<?php
/**
 * The field on the editing screens.
 *
 * @param $user WP_User user object
 */
function wporg_usermeta_form_field_birthday( $user )
{
    ?>
    <h3>It's Your Birthday</h3>
    <table class="form-table">
        <tr>
            <th>
                <label for="birthday">Birthday</label>
            </th>
            <td>
                <input type="date"
                       class="regular-text ltr"
                       id="birthday"
                       name="birthday"
                       value="<?= esc_attr( get_user_meta( $user->ID, 'birthday', true ) ) ?>"
                       title="Please use YYYY-MM-DD as the date format."
                       pattern="(19[0-9][0-9]|20[0-9][0-9])-(1[0-2]|0[1-9])-(3[01]|[21][0-9]|0[1-9])"
                       required>
                <p class="description">
                    Please enter your birthday date.
                </p>
            </td>
        </tr>
    </table>
    <?php
}
  
/**
 * The save action.
 *
 * @param $user_id int the ID of the current user.
 *
 * @return bool Meta ID if the key didn't exist, true on successful update, false on failure.
 */
function wporg_usermeta_form_field_birthday_update( $user_id )
{
    // check that the current user have the capability to edit the $user_id
    if ( ! current_user_can( 'edit_user', $user_id ) ) {
        return false;
    }
  
    // create/update user meta for the $user_id
    return update_user_meta(
        $user_id,
        'birthday',
        $_POST['birthday']
    );
}
  
// Add the field to user's own profile editing screen.
add_action(
    'show_user_profile',
    'wporg_usermeta_form_field_birthday'
);
  
// Add the field to user profile editing screen.
add_action(
    'edit_user_profile',
    'wporg_usermeta_form_field_birthday'
);
  
// Add the save action to user's own profile editing screen update.
add_action(
    'personal_options_update',
    'wporg_usermeta_form_field_birthday_update'
);
  
// Add the save action to user profile editing screen update.
add_action(
    'edit_user_profile_update',
    'wporg_usermeta_form_field_birthday_update'
);
Comment

PREVIOUS NEXT
Code Example
Php :: php remove control characters from string 
Php :: eloquent where parentheses 
Php :: php location header 
Php :: array helper array_push laravel 
Php :: whereHas site:https://laravel.com/docs/ 
Php :: how to get public folder path in laravel 
Php :: laravel migration alter column unique 
Php :: Make a Woo required field not required 
Php :: laravel validation in controller 
Php :: how to log object laravel logger 
Php :: Only variables should be passed by reference in 
Php :: php strftime datetime 
Php :: not get child all data in relationship with parent laravel eloquent 
Php :: get curret timedate php 
Php :: array key value php 
Php :: php-pdo-returning-single-row 
Php :: convert std to array php 
Php :: adeleye ayodeji 
Php :: How to change site url using wp-config.php 
Php :: laravel blade foreach index value 
Php :: php function crop image 
Php :: Laravel - Query Builder Raw Query selectRaw 
Php :: check date PHP 
Php :: create model laravel 
Php :: php function uppercase first letter 
Php :: custom pagination laravel css 
Php :: show images laravel 8 showJobImage($filename) 
Php :: laravel maximum execution time of 30 seconds exceeded 
Php :: location php ini mac os 
Php :: How to Connect MySQL Database with PHP Websites 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =