update_user_meta example

global $user_ID;
    // Short-circuit it.     if ( ! get_user_option( 'default_password_nag' ) ) {
        return;
    }

    // get_user_setting() = JS-saved UI setting. Else no-js-fallback code.     if ( 'hide' === get_user_setting( 'default_password_nag' )
        || isset( $_GET['default_password_nag'] ) && '0' === $_GET['default_password_nag']
    ) {
        delete_user_setting( 'default_password_nag' );
        update_user_meta( $user_ID, 'default_password_nag', false );
    }
}

/** * @since 2.8.0 * * @param int $user_ID * @param WP_User $old_data */
function default_password_nag_edit_user( $user_ID$old_data ) {
    // Short-circuit it.
$found = true;
                    }
                    ?> <option value="<?php echo $blog->userblog_id; ?>"<?php selected( $primary_blog$blog->userblog_id ); ?>><?php echo esc_url( get_home_url( $blog->userblog_id ) ); ?></option> <?php                 }
                ?> </select> <?php             if ( ! $found ) {
                $blog = reset( $all_blogs );
                update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
            }
        } elseif ( 1 === count( $all_blogs ) ) {
            $blog = reset( $all_blogs );
            echo esc_url( get_home_url( $blog->userblog_id ) );
            if ( $blog->userblog_id !== $primary_blog ) { // Set the primary blog again if it's out of sync with blog list.                 update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
            }
        } else {
            _e( 'Not available' );
        }
        ?>

    public function add_role( $role ) {
        if ( empty( $role ) ) {
            return;
        }

        if ( in_array( $role$this->roles, true ) ) {
            return;
        }

        $this->caps[ $role ] = true;
        update_user_meta( $this->ID, $this->cap_key, $this->caps );
        $this->get_role_caps();
        $this->update_user_level_from_caps();

        /** * Fires immediately after the user has been given a new role. * * @since 4.3.0 * * @param int $user_id The user ID. * @param string $role The new role. */
        
$url = post_preview();

        wp_redirect( $url );
        exit;

    case 'toggle-custom-fields':
        check_admin_referer( 'toggle-custom-fields', 'toggle-custom-fields-nonce' );

        $current_user_id = get_current_user_id();
        if ( $current_user_id ) {
            $enable_custom_fields = (bool) get_user_meta( $current_user_id, 'enable_custom_fields', true );
            update_user_meta( $current_user_id, 'enable_custom_fields', ! $enable_custom_fields );
        }

        wp_safe_redirect( wp_get_referer() );
        exit;

    default:
        /** * Fires for a given custom post action request. * * The dynamic portion of the hook name, `$action`, refers to the custom post action. * * @since 4.6.0 * * @param int $post_id Post ID sent with the request. */
$action = isset( $_POST['action'] ) ? $_POST['action'] : 'splash';

$blogs = get_blogs_of_user( $current_user->ID );

$updated = false;
if ( 'updateblogsettings' === $action && isset( $_POST['primary_blog'] ) ) {
    check_admin_referer( 'update-my-sites' );

    $blog = get_site( (int) $_POST['primary_blog'] );
    if ( $blog && isset( $blog->domain ) ) {
        update_user_meta( $current_user->ID, 'primary_blog', (int) $_POST['primary_blog'] );
        $updated = true;
    } else {
        wp_die( __( 'The primary site you chose does not exist.' ) );
    }
}

// Used in the HTML title tag. $title       = __( 'My Sites' );
$parent_file = 'index.php';

get_current_screen()->add_help_tab(
    

        $user_id        = username_exists( $user_name );
        $user_password  = trim( $user_password );
        $email_password = false;
        $user_created   = false;

        if ( ! $user_id && empty( $user_password ) ) {
            $user_password = wp_generate_password( 12, false );
            $message       = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.' );
            $user_id       = wp_create_user( $user_name$user_password$user_email );
            update_user_meta( $user_id, 'default_password_nag', true );
            $email_password = true;
            $user_created   = true;
        } elseif ( ! $user_id ) {
            // Password has been provided.             $message      = '<em>' . __( 'Your chosen password.' ) . '</em>';
            $user_id      = wp_create_user( $user_name$user_password$user_email );
            $user_created = true;
        } else {
            $message = __( 'User already exists. Password inherited.' );
        }

        
<?php _e( 'Feature Filter' ); ?></button> <form class="search-form"></form> <div class="favorites-form"> <?php             $action = 'save_wporg_username_' . get_current_user_id();
            if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] )$action ) ) {
                $user = isset( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' );
                update_user_meta( get_current_user_id(), 'wporg_favorites', $user );
            } else {
                $user = get_user_option( 'wporg_favorites' );
            }
            ?> <p class="install-help"><?php _e( 'If you have marked themes as favorites on WordPress.org, you can browse them here.' ); ?></p> <p> <label for="wporg-username-input"><?php _e( 'Your WordPress.org username:' ); ?></label> <input type="hidden" id="wporg-username-nonce" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( $action ) ); ?>" /> <input type="search" id="wporg-username-input" value="<?php echo esc_attr( $user ); ?>" /> <input type="button" class="button favorites-form-submit" value="<?php esc_attr_e( 'Get Favorites' ); ?>" /> </p> </div> <div class="filter-drawer"> <div class="buttons"> <button type="button" class="apply-filters button">
return;
    }

    if ( ! is_multisite() ) {
        return $blogs[ get_current_blog_id() ];
    }

    $primary_blog = get_user_meta( $user_id, 'primary_blog', true );
    $first_blog   = current( $blogs );
    if ( false !== $primary_blog ) {
        if ( ! isset( $blogs[ $primary_blog ] ) ) {
            update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id );
            $primary = get_site( $first_blog->userblog_id );
        } else {
            $primary = get_site( $primary_blog );
        }
    } else {
        // TODO: Review this call to add_user_to_blog too - to get here the user must have a role on this blog?         $result = add_user_to_blog( $first_blog->userblog_id, $user_id, 'subscriber' );

        if ( ! is_wp_error( $result ) ) {
            update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id );
            $primary = $first_blog;
        }


    /** * Updates the user's sessions in the usermeta table. * * @since 4.0.0 * * @param array $sessions Sessions. */
    protected function update_sessions( $sessions ) {
        if ( $sessions ) {
            update_user_meta( $this->user_id, 'session_tokens', $sessions );
        } else {
            delete_user_meta( $this->user_id, 'session_tokens' );
        }
    }

    /** * Destroys all sessions for this user, except the single session with the given verifier. * * @since 4.0.0 * * @param string $verifier Verifier of the session to keep. */
// Include the list of installed plugins so we can get relevant results.                 $args['installed_plugins'] = array_keys( $installed_plugins );
                break;

            case 'favorites':
                $action = 'save_wporg_username_' . get_current_user_id();
                if ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] )$action ) ) {
                    $user = isset( $_GET['user'] ) ? wp_unslash( $_GET['user'] ) : get_user_option( 'wporg_favorites' );

                    // If the save url parameter is passed with a falsey value, don't save the favorite user.                     if ( ! isset( $_GET['save'] ) || $_GET['save'] ) {
                        update_user_meta( get_current_user_id(), 'wporg_favorites', $user );
                    }
                } else {
                    $user = get_user_option( 'wporg_favorites' );
                }
                if ( $user ) {
                    $args['user'] = $user;
                } else {
                    $args = false;
                }

                add_action( 'install_plugins_favorites', 'install_plugins_favorites_form', 9, 0 );
                

function update_user_option( $user_id$option_name$newvalue$is_global = false ) {
    global $wpdb;

    if ( ! $is_global ) {
        $option_name = $wpdb->get_blog_prefix() . $option_name;
    }

    return update_user_meta( $user_id$option_name$newvalue );
}

/** * Deletes user option with global blog capability. * * User options are just like user metadata except that they have support for * global blog options. If the 'is_global' parameter is false, which it is by default, * it will prepend the WordPress table prefix to the option name. * * @since 3.0.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $user_id User ID * @param string $option_name User option name. * @param bool $is_global Optional. Whether option name is global or blog specific. * Default false (blog specific). * @return bool True on success, false on failure. */
$current_ip_address = WP_Community_Events::get_unsafe_client_ip();

    /* * If the user's location is based on their IP address, then update their * location when their IP address changes. This allows them to see events * in their current city when travelling. Otherwise, they would always be * shown events in the city where they were when they first loaded the * Dashboard, which could have been months or years ago. */
    if ( $saved_ip_address && $current_ip_address && $current_ip_address !== $saved_ip_address ) {
        $saved_location['ip'] = $current_ip_address;
        update_user_meta( $user_id, 'community-events-location', $saved_location );
    }

    $events_client = new WP_Community_Events( $user_id$saved_location );

    wp_localize_script(
        'dashboard',
        'communityEventsData',
        array(
            'nonce'       => wp_create_nonce( 'community_events' ),
            'cache'       => $events_client->get_cached_events(),
            'time_format' => get_option( 'time_format' ),
        )
// Set $nav_menu_selected_id to 0 if no menus. if ( $one_theme_location_no_menus ) {
    $nav_menu_selected_id = 0;
} elseif ( empty( $nav_menu_selected_id ) && ! empty( $nav_menus ) && ! $add_new_screen ) {
    // If we have no selection yet, and we have menus, set to the first one in the list.     $nav_menu_selected_id = $nav_menus[0]->term_id;
}

// Update the user's setting. if ( $nav_menu_selected_id !== $recently_edited && is_nav_menu( $nav_menu_selected_id ) ) {
    update_user_meta( $current_user->ID, 'nav_menu_recently_edited', $nav_menu_selected_id );
}

// If there's a menu, get its name. if ( ! $nav_menu_selected_title && is_nav_menu( $nav_menu_selected_id ) ) {
    $_menu_object            = wp_get_nav_menu_object( $nav_menu_selected_id );
    $nav_menu_selected_title = ! is_wp_error( $_menu_object ) ? $_menu_object->name : '';
}

// Generate truncated menu names. foreach ( (array) $nav_menus as $key => $_nav_menu ) {
    $nav_menus[ $key ]->truncated_name = wp_html_excerpt( $_nav_menu->name, 40, '&hellip;' );
}
<?php _e( 'Some screen elements can be shown or hidden by using the checkboxes.' ); ?> <?php _e( 'Expand or collapse the elements by clicking on their headings, and arrange them by dragging their headings or by clicking on the up and down arrows.' ); ?> </p> <div class="metabox-prefs-container"> <?php
        meta_box_prefs( $this );

        if ( 'dashboard' === $this->id && has_action( 'welcome_panel' ) && current_user_can( 'edit_theme_options' ) ) {
            if ( isset( $_GET['welcome'] ) ) {
                $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1;
                update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked );
            } else {
                $welcome_checked = (int) get_user_meta( get_current_user_id(), 'show_welcome_panel', true );
                if ( 2 === $welcome_checked && wp_get_current_user()->user_email !== get_option( 'admin_email' ) ) {
                    $welcome_checked = false;
                }
            }
            echo '<label for="wp_welcome_panel-hide">';
            echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />';
            echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n";
        }
        ?>
// Remove all permissions that may exist for the site.     $table_prefix = $wpdb->get_blog_prefix();
    delete_metadata( 'user', 0, $table_prefix . 'user_level', null, true );   // Delete all.     delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true ); // Delete all.
    // Install default site content.     wp_install_defaults( $args['user_id'] );

    // Set the site administrator.     add_user_to_blog( $site->id, $args['user_id'], 'administrator' );
    if ( ! user_can( $args['user_id'], 'manage_network' ) && ! get_user_meta( $args['user_id'], 'primary_blog', true ) ) {
        update_user_meta( $args['user_id'], 'primary_blog', $site->id );
    }

    if ( $switch ) {
        restore_current_blog();
    }

    wp_installing( $orig_installing );

    return true;
}

Home | Imprint | This part of the site doesn't use cookies.