Up to 50 percent off

Profile Update Trigger

This topic contains 7 reply and 2 voices, and was last updated by Alexis Media 11 years, 3 months ago
Viewing 7 Posts - 1 through 7 (of 7 total)
Author Posts
August 2, 2013 at 12:35 am 6574
Alexis Media 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.
August 2, 2013 at 1:06 am 6575
Tareq Hasan Tareq Hasan

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

August 3, 2013 at 1:10 am 6609
Alexis Media Alexis Media

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?

August 3, 2013 at 1:21 am 6612
Alexis Media Alexis Media

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?

August 3, 2013 at 1:25 am 6613
Alexis Media Alexis Media

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

August 3, 2013 at 1:32 am 6614
Tareq Hasan Tareq Hasan

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]

August 3, 2013 at 1:53 am 6615
Alexis Media Alexis Media

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.

August 3, 2013 at 1:56 am 6616
Alexis Media Alexis Media

and that does seem to work. thank you.

Viewing 7 Posts - 1 through 7 (of 7 total)