• Resolved Harris Marfel

    (@hrace009)


    i try using this hook
    do_action('edit_user_avatar', $current_user);
    it was showing at my front end costume profile.
    I try to chose image and Update profile, it not update and roll back again to previous image.

    but if i try to change it from Back End / Stand alone page using [avatar_upload] it was working well

    can someone light me up?

    here the code on my costume front end profile:

    <?php
    /**
     * Template Name: Profile
     *
     * @package Twenty_Fourteen
     * @subpackage Twenty_Fourteen
     * @since Twenty Fourteen 1.0
     */
    
    get_header(); 
    
    $wpdb->hide_errors(); auth_redirect_login(); nocache_headers();
    global $userdata; get_currentuserinfo(); // grabs the user info and puts into vars
    // check to see if the form has been posted. If so, validate the fields
    if(!empty($_POST['action']))
    {
    require_once(ABSPATH . 'wp-admin/includes/user.php');
    require_once(ABSPATH . WPINC . '/registration.php');
    check_admin_referer('update-profile_' . $user_ID);
    $errors = edit_user($user_ID);
    if ( is_wp_error( $errors ) ) {
    foreach( $errors->get_error_messages() as $message )
    $errmsg = "$message";
    //exit;
    }
    // if there are no errors, then process the ad updates
    if($errmsg == '')
    {
    do_action('personal_options_update');
    $d_url = $_POST['dashboard_url'];
    wp_redirect( get_option("siteurl").'?page_id='.$post->ID.'&updated=true' );
    }
    else {
    $errmsg = '<div class="pwerror">** ' . $errmsg . ' **</div>';
    $errcolor = 'style="background-color:#FFEBE8;border:1px solid #CC0000;"';
    }
    }
    ?>
    
    <div id="main-content" class="main-content">
    
    <?php
    	if ( is_front_page() && twentyfourteen_has_featured_posts() ) {
    		// Include the featured content template.
    		get_template_part( 'featured-content' );
    	}
    ?>
    	<div id="primary" class="content-area">
    		<div id="content" class="site-content" role="main">
    
    <?php if ( isset($_GET['updated']) ) {
    $d_url = $_GET['d'];?>
    <p class="message"><?php _e('Your profile has been updated.','cp')?></p>
    <?php } ?>
    <?php echo $errmsg; ?>
    <form name="profile" action="" method="post">
    <?php wp_nonce_field('update-profile_' . $user_ID) ?>
    <input type="hidden" name="from" value="profile" />
    <input type="hidden" name="action" value="update" />
    <input type="hidden" name="checkuser_id" value="<?php echo $user_ID ?>" />
    <input type="hidden" name="dashboard_url" value="<?php echo get_option("dashboard_url"); ?>" />
    <input type="hidden" name="user_id" id="user_id" value="<?php echo $user_ID; ?>" />
    <table class="pwtable">
      <tr>
        <th colspan="3" scope="col"><h3>User Info</h3></th>
      </tr>
    <tr>
    <th><label for="user_login"><?php _e('Username','cp'); ?></label></th>
    <td><input type="text" name="user_login" class="mid2" id="user_login" value="<?php echo $userdata->user_login; ?>" size="35" maxlength="100" disabled /></td>
    </tr>
    <tr>
    <th><label for="first_name"><?php _e('First Name','cp') ?></label></th>
    <td><input type="text" name="first_name" class="mid2" id="first_name" value="<?php echo $userdata->first_name ?>" size="35" maxlength="100" /></td>
    </tr>
    <tr>
    <th><label for="last_name"><?php _e('Last Name','cp') ?></label></th>
    <td><input type="text" name="last_name" class="mid2" id="last_name" value="<?php echo $userdata->last_name ?>" size="35" maxlength="100" /></td>
    </tr>
    <tr>
    <th><label for="email"><?php _e('Email','cp') ?></label></th>
    <td><input type="text" name="email" class="mid2" id="email" value="<?php echo $userdata->user_email ?>" size="35" maxlength="100" /></td>
    </tr>
    </table>
    <table class="pwtable">
      <tr>
        <th colspan="3" scope="col"><h3>Password</h3></th>
      </tr>
    <?php
    $show_password_fields = apply_filters('show_password_fields', true);
    if ( $show_password_fields ) :
    ?>
    <tr>
    <th><label for="pass1"><?php _e('New Password','cp'); ?></label></th>
    <td>
    <input type="password" name="pass1" class="mid2" id="pass1" size="35" maxlength="50" value="" />
    <small><?php _e('Leave this field blank unless you\'d like to change your password.','cp'); ?></small>
    </td>
    </tr>
    <tr>
    <th><label for="pass1"><?php _e('Password Again','cp'); ?></label></th>
    <td>
    <input type="password" name="pass2" class="mid2" id="pass2" size="35" maxlength="50" value="" />
    <small><?php _e('Type your new password again.','cp'); ?></small></td>
    </tr>
    <tr>
    </tr>
    <?php endif; ?>
    </table>
      <table class="pwtable">
      <tr>
        <th colspan="3" scope="col"><?php do_action('edit_user_avatar', $current_user); ?></th>
      </tr>
    	    <tr>
        <th colspan="3" scope="col"><input type="submit" class="button" value="Update profile" name="submit" /></th>
      </tr>
    </table>
    </form>
    		</div><!-- #content -->
    	</div><!-- #primary -->
    	<?php get_sidebar( 'content' ); ?>
    </div><!-- #main-content -->
    
    <?php
    get_sidebar();
    get_footer();

    function.php

    function my_avatar_filter() {
      // Remove from show_user_profile hook
      remove_action('show_user_profile', array('wp_user_avatar', 'wpua_action_show_user_profile'));
      remove_action('show_user_profile', array('wp_user_avatar', 'wpua_media_upload_scripts'));
    
      // Remove from edit_user_profile hook
      remove_action('edit_user_profile', array('wp_user_avatar', 'wpua_action_show_user_profile'));
      remove_action('edit_user_profile', array('wp_user_avatar', 'wpua_media_upload_scripts'));
    
      // Add to edit_user_avatar hook
      add_action('edit_user_avatar', array('wp_user_avatar', 'wpua_action_show_user_profile'));
      add_action('edit_user_avatar', array('wp_user_avatar', 'wpua_media_upload_scripts'));
    }
    
    // Loads only outside of administration panel
    if(!is_admin()) {
      add_action('init','my_avatar_filter');
    }
    
    remove_action('wpua_before_avatar', 'wpua_do_before_avatar');
    remove_action('wpua_after_avatar', 'wpua_do_after_avatar');
    
    function my_before_avatar() {
      echo '<div id="my-avatar">';
    }
    add_action('wpua_before_avatar', 'my_before_avatar');
    
    function my_after_avatar() {
      echo '</div>';
    }
    add_action('wpua_after_avatar', 'my_after_avatar');

    let me know if you need access to my website.

    Thanks

    https://wordpress.org/plugins/wp-user-avatar/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try changing:

    do_action('edit_user_avatar', $current_user);

    to:

    do_action('edit_user_avatar', $userdata);

    and also:

    <form name="profile" action="" method="post">

    to:

    <form name="profile" action="" method="post" enctype="multipart/form-data">

    Thread Starter Harris Marfel

    (@hrace009)

    thank you bangbay.
    it was work 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Hook Not Work’ is closed to new replies.