/**
 * Auto-update the user_nicename for a given user.
 *
 * Runs during the bulk upgrade process in the Dashboard
 *
 * @since 0.9.0
 *
 * @param int $user_id User id
 *
 * @uses ba_eas_auto_update_user_nicename() To auto-update the nicename.
 */
function ba_eas_auto_update_user_nicename_bulk($user_id = 0)
{
    ba_eas_auto_update_user_nicename($user_id, true);
}
Exemplo n.º 2
0
/**
 * Auto-update the user_nicename for a given user.
 *
 * Runs during the bulk upgrade process in the Dashboard.
 *
 * @since 0.9.0
 *
 * @param string $value The option value passed to the settings API.
 *
 * @return bool False to prevent the setting from being saved to the db.
 */
function ba_eas_auto_update_user_nicename_bulk($value = false)
{
    // Nonce check.
    check_admin_referer('edit-author-slug-options');
    // Default the structure to the auto-update structure.
    $structure = ba_eas()->default_user_nicename;
    // If a bulk update structure was passed, use that.
    if (isset($_POST['_ba_eas_bulk_update_structure'])) {
        $structure = sanitize_key($_POST['_ba_eas_bulk_update_structure']);
    }
    // Sanitize the option value.
    $value = (bool) absint($value);
    // Bail if the user didn't ask to run the bulk update.
    if (!$value) {
        return false;
    }
    // Get an array of ids of all users.
    $users = get_users(array('fields' => 'ID'));
    /**
     * Filters the array of user ids who will have their user nicenames updated.
     *
     * @since 1.1.0
     *
     * @param array $users The array of user ids to update.
     */
    $users = (array) apply_filters('ba_eas_auto_update_user_nicename_bulk_user_ids', $users);
    // Set the default updated count.
    $updated = 0;
    // Loop through all the users and maybe update their nicenames.
    foreach ($users as $user_id) {
        // Maybe update the user nicename.
        $id = ba_eas_auto_update_user_nicename($user_id, true, $structure);
        // If updating was a success, the bump the updated count.
        if (!empty($id) && !is_wp_error($id)) {
            $updated++;
        }
    }
    // Add a message to the settings page denoting user how many users were updated.
    add_settings_error('_ba_eas_bulk_auto_update', 'bulk_user_nicenames_updated', sprintf(__('%d user author slug(s) updated.', 'edit-author-slug'), $updated), 'updated');
    // Return false to short-circuit the update_option routine, and prevent saving.
    return false;
}