• Resolved ftpwp

    (@ftpwp)


    Hi,

    I want to use the power of UM custom fields to centralize the management of some settings on the UM profile, instead of the WP profile.

    For example: I have a website where the Asgaros forum is installed.
    Asgaros install 1 isolated setting asgarosforum_mention_notify in user’s WP profile.
    I don’t want users going to their WP profile just for that. I want to give them access to this setting in their UM profile.

    For that:
    – I’ve created a checkbox custom field in the UM profile
    – I’ve used the “um_user_after_updating_profile” hook to check what was the value set for the field after updating the UM profile and update accordingly the WP profile; align the 2 settings

    But… I now need to do the same thing BEFORE viewing or opening the UM profile: make sure I align the UM profile on the WP profile in case the setting has been changed on the WP profile.

    So what I need is to find:

    1/ the right hook to use to run my code before the UM user profile is viewed or edited. It should be one run at the very beginning when the code to build the UM user profile page (either in view or edit mode) starts, to still be able to update one custom field value.

    2/ the proper way to update a UM custom field value

    For this 2nd issue, I’ve found this…
    https://wordpress.org/support/topic/what-is-the-php-function-to-save-fields-in-um_user/#post-10965068
    …but so far it’s not working and it’s still not 100% clear to me.

    @wptechnology, I reply to your topic in mine as yours is closed.

    You suggest…

    global $ultimatemember;
    $user_id = um_user('ID');
    um_fetch_user($user_id);
    $toupdate[] = array('name_of_field' => 'its_value');
    UM()->user()->update_profile($toupdate);
    update_user_meta($user_id, 'name_of_field','its_value');

    In my context, 1 checkbox (value = ‘enable’) to update before the profile is viewed or created, I think it would become this (in functions.php – and I will already have the $user_id via the hook)…

    um_fetch_user($user_id);
    $toUpdate[] = array('profile_notif_new_mention' => 'enable');
    UM()->user()->update_profile($toUpdate);
    
    update_user_meta($user_id, 'profile_notif_new_post', 'enable');

    But I have several questions:

    1/ Is global $ultimatemember; still required in my case?

    2/ What’s the differences in between the UM()->user()->update_profile() and the update_user_meta() updates? What does UM()->user()->update_profile() updates that update_user_meta() does not?

    3/ How do we update checkboxes via UM()->user()->update_profile()? Do we really set the value in plain text or via an array like this array (0 => 'value')?

    4/ Same question for update_user_meta(). How do we update checkboxes to respect the UM format? Plain text or by an array like array (0 => 'value')? And do we have to use the [] after the meta_key, like profile_notif_new_post[]?

    I ask you those questions as something must be wrong. I have no error but it’s not working, the checkbox is not ticked in the user’s profile.

    Thanks!

Viewing 5 replies - 16 through 20 (of 20 total)
  • Thread Starter ftpwp

    (@ftpwp)

    What do you call “his forum signature”?

    Please see screenshot.
    https://i.imgur.com/eoAriKr.png

    Thread Starter ftpwp

    (@ftpwp)

    Oh ok. I did not activated the Signature functionality in Asgaros. I even forgot about it. So no, I did not transfer its management in the UM profile but you can probably do it more or less the same way as what I did for the Mention notification settings. You now have the method and an example, it should be much easier.

    Create a memo field in the UM profile, find out the Meta key name of the Signature field in the DB, add the 2 specific codes for the Signature updates based on the Mention notification updates and simply adjust the updates for Memo field (and not checkboxes).

    @ftpwp for your information. The forum signature is not so an isolated option. So this works out of the box without coding.
    Thank you very much!

    Thread Starter ftpwp

    (@ftpwp)

    It’s maybe enabled by default, but then I disabled it.
    I’m not a big fan of signatures. If it stays light it’s ok but some people tend to set giant signatures that pollute the topics, among other as they are constantly repeated, displayed below on every post.

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘Hook right before user’s profile & custom field update?’ is closed to new replies.