1

I have created a custom user meta field, and that value is being used to get data from an external API and display it on the user profile page. On admin pages I have used the following code to make sure that when an administrator account views a user profile, s/he can view the data displayed from the API.

And then calling the API, and retrieving the cached data from a transient prefixed by the user id yadadada. This all works perfectly, and the data displays properly. But if the administrator then tries to update another user's account custom meta field despite the fact that I pass the correct userid to the update_user_meta function, meta value does not update. Below is the code for the update function.

function af_askFRED_update_fencer_field() {
    $user = wp_get_current_user();
    $userid = $user->ID;

    if (current_user_can('delete_users') && isset($_GET['user_id'])) {
        $userid = $_GET['user_id'];
    }

    $usfaID = $_POST['af_askFRED_usfaID'];
    update_user_meta($userid, 'af_askFRED_usfaID', $usfaID);
    delete_transient($userid.'AF_USFA_KEY');

}

add_action('personal_options_update', 'af_askFRED_update_fencer_field');

NOTE: If I update any other profile field it works perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.