Home Forums Plugin Support WP User Frontend (Free Version) Profile Update Trigger

This topic is: resolved

This topic contains 7 replies, has 2 voices, and was last updated by  Alexis Media 5 years, 7 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #6574

    Alexis Media
    Participant
    Post count: 54

    I am using the below code to make changes to the author links and such.

    add_filter( 'request', 'wpse5742_request' );
    function wpse5742_request( $query_vars )
    {
        if ( array_key_exists( 'author_name', $query_vars ) ) {
            global $wpdb;
            $author_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key='nickname' AND meta_value = %s", $query_vars['author_name'] ) );
            if ( $author_id ) {
                $query_vars['author'] = $author_id;
                unset( $query_vars['author_name'] );    
            }
        }
        return $query_vars;
    }
    add_filter( 'author_link', 'wpse5742_author_link', 10, 3 );
    function wpse5742_author_link( $link, $author_id, $author_nicename )
    {
        $author_nickname = get_user_meta( $author_id, 'nickname', true );
        if ( $author_nickname ) {
            $link = str_replace( $author_nicename, sanitize_title($author_nickname), $link );
        }
        return $link;
    }
    add_action( 'user_profile_update_errors', 'wpse5742_set_user_nicename_to_nickname', 10, 3 );
    function wpse5742_set_user_nicename_to_nickname( &$errors, $update, &$user )
    {
        if ( ! empty( $user->nickname ) ) {
            $user->user_nicename = sanitize_title( $user->nickname, $user->display_name );
        }
    }

    The issue is this only seems to be triggered from update a profile from wp-admin. I need it to trigger after submitting from the plugin.

    #6575

    Tareq Hasan
    Keymaster
    Post count: 2831

    Take a look at the action hook list, there is one action that triggers when profile updates.

    #6609

    Alexis Media
    Participant
    Post count: 54

    tried replacing “user_profile_update_errors” and “request” with “wpuf_update_profile” and it just locks the page up on saving it. Any other ideas you may have please?

    #6612

    Alexis Media
    Participant
    Post count: 54

    Issue i am having is after a user update thier profile the url wont work till after i go to WP-Admin and save the profile from there. I dont have to make any changes just visit the users profile and click save from the backend. Then the url starts working. Id like this to work from the user editing the profile. What could be going on to trigger this in the backend thats not going on on the front?

    #6613

    Alexis Media
    Participant
    Post count: 54

    Even tried to flush_rewrite_rules with your trigger and it still didnt work.

    #6614

    Tareq Hasan
    Keymaster
    Post count: 2831

    You can't expect to paste a code that works for something and that will work in everywhere and with every plugin. The context is different and they works differently.

    May be this will work-
    [php]
    function wpufe_update_nicename( $user_id ) {
    $user = get_user_by( ‘id', $user_id );

    if ( !empty( $user->nickname ) ) {
    $nice_name = sanitize_title( $user->nickname, $user->display_name );
    wp_update_user( array(‘ID' => $user_id, ‘user_nicename' => $nice_name) );
    }
    }

    add_action( ‘wpuf_update_profile', ‘wpufe_update_nicename' );
    [/php]

    #6615

    Alexis Media
    Participant
    Post count: 54

    You can’t expect to paste a code that works for something and that will work in everywhere and with every plugin. The context is different and they works differently.

    I dont expect it to work right away, is why im here getting help.

    #6616

    Alexis Media
    Participant
    Post count: 54

    and that does seem to work. thank you.

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Profile Update Trigger’ is closed to new replies.