The image does not update immediately after upload and page refresh
-
Hello. I have a little problem and I don’t know if it depends on the plugin or on something else.
When I select a new profile picture and then click the load button, the page reloads. After uploading I still see the old image, so I have to reload the page again to see the changes made.
Why does this happen? Do you have some advice ? This kind of problem only happens with this plugin, any changes you make to my site don’t have to load the page twice to see the changes.
-
Go to Avatars -> Settings and check the box “Always use the browser file uploader to upload avatars”. If the problem no longer persists it’s probably due to a conflict with another plugin that is also requesting the media uploader on the same page.
Hi Daniel. Thanks for the reply. When I published the question I had already checked the setting you suggested.
However, the problem only concerns the [avatar] shortcode. While in [avatar_upload] the original image and thumbnail are instantly updated as soon as the page has been reloaded.
I tried to replicate the [avatar_upload] shortcode for some needs. I understand that images are updated immediately only if
do_action( 'wpua_update', $valid_user->ID );
is present, when this is not there, the image does not update instantly and you have to reload the page several times.Shortcode 1
The first shortcode shows the select file field with the upload button.//SHORTCODE UPLOAD BUTTON ONE-USER-AVATAR function avatar_upload($user) { //Global global $wpua_force_file_uploader, $show_avatars, $wpua_shortcode, $wp_user_avatar, $all_sizes, $blog_id, $post, $wpdb, $current_user, $wp_user_avatar, $wpua_allow_upload, $wpua_edit_avatar, $wpua_functions; // Default user is current user $valid_user = $current_user; //Function do_action( 'wpua_update', $valid_user->ID ); ob_start(); ?> <form id="wpua-edit-<?php echo esc_attr( $user->ID ); ?>" class="wpua-edit" action="" method="post" enctype="multipart/form-data"> <input type="hidden" name="wp-user-avatar" id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wp-user-avatar' : 'wp-user-avatar-existing' ) ?>" value="<?php echo esc_attr( $wpua ); ?>" /> <div class="upload-avatar" id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-upload-button' : 'wpua-upload-button-existing' ); ?>"> <input name="wpua-file" id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-file' : 'wpua-file-existing' ); ?>" type="file" class="wp-input-file"/> <button type="submit" class="button" id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-upload' : 'wpua-upload-existing' ); ?>" name="submit" value="<?php esc_html_e( 'Aggiorna', 'one-user-avatar' ); ?>"> <?php esc_html_e( 'Upload', 'one-user-avatar' ); ?> </button> </div> <div id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-images' : 'wpua-images-existing' ); ?>" class="<?php echo esc_attr( $hide_images ); ?>"> <p id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-remove-button' : 'wpua-remove-button-existing' ); ?>" class="<?php echo esc_attr( $hide_remove ); ?>"> <button type="button" class="button" id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-remove' : 'wpua-remove-existing' ); ?>" name="wpua-remove"><?php esc_html_e( 'Remove Image', 'one-user-avatar' ); ?></button> </p> </div> <input type="hidden" name="wpua_action" value="update" /> <input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr( $user->ID ); ?>" /> <?php wp_nonce_field( 'update-user_' . $user->ID ); ?> <?php submit_button( __( 'Update Profile', 'one-user-avatar' ) ); ?> </form> <?php return ob_get_clean(); } add_shortcode('mts_avatar_upload', 'avatar_upload');
Shortcode 2
The second shortcode has the task of showing only the avatar, just like it happens for [avatar] shortcode.//SHORTCODE SHOW AVATAR ONE-USER-AVATAR function avatar_show($user) { //Global global $wpua_force_file_uploader, $show_avatars, $wpua_shortcode, $wp_user_avatar, $blog_id, $post, $wpdb, $current_user, $wp_user_avatar, $wpua_allow_upload, $wpua_edit_avatar, $wpua_functions, $wpua_is_profile; // Default user is current user $valid_user = $current_user; // If I insert do_action( 'wpua_update', $valid_user->ID ); here then the image is updated instantly after the page refresh. However, if the code string is entered here, that breaks the functioning of the first shortcode. // Call one of the plugin's functions $has_wp_user_avatar = has_wp_user_avatar(@$valid_user->ID); $avatar_thumbnail = $has_wp_user_avatar ? get_wp_user_avatar_src($valid_user->ID, 96) : $avatar_medium_src; // If avatars are enabled, get original avatar image or show blank $avatar_medium_src = 1 == (bool) $show_avatars ? $wpua_functions->wpua_get_avatar_original( @$valid_user->user_email, 'medium' ) : includes_url() . 'images/blank.gif'; // Check if user has wp_user_avatar, if not show image from above $avatar_medium = $has_wp_user_avatar ? get_wp_user_avatar_src( $valid_user->ID, 'medium' ) : $avatar_medium_src; // Check if user has wp_user_avatar, if not show image from above $avatar_thumbnail = $has_wp_user_avatar ? get_wp_user_avatar_src( $valid_user->ID, 96 ) : $avatar_medium_src; $edit_attachment_link = esc_url( add_query_arg( array( 'post' => $wpua, 'action' => 'edit', ), admin_url( 'post.php' ) ) ); ob_start(); ?> <form id="wpua-edit-<?php echo esc_attr( $user->ID ); ?>" class="wpua-edit" action="" method="post" enctype="multipart/form-data"> <p id="<?php echo esc_attr( ( 'add-new-user' == $user ) ? 'wpua-thumbnail' : 'wpua-thumbnail-existing' ); ?>"><img src="<?php echo esc_url( $avatar_thumbnail ); ?>" alt="<?php echo esc_attr( __( 'Thumbnail', 'one-user-avatar' ) ); ?>"/></p> </form> <?php return ob_get_clean(); } add_shortcode('mts_avatar_show', 'avatar_show');
It is not possible to keep the
do_action('wpua_update', $ valid_user-> ID);
without breaking the first shortcode? Or connect the second shortcode to the first in some way so that you can make it work.It seems to me that if you separate the avatar display from
do_action('wpua_update', $ valid_user-> ID);
then the avatar does not update immediately.Do you have any suggestions? Thanks again.
-
This reply was modified 3 years, 1 month ago by
Snake93.
I am posting the first response again as it was held for moderation. Sorry…
Hi Daniel. Thanks for the reply. When I published the question I had already checked the setting you suggested.
However, the problem only concerns the [avatar] shortcode. While in [avatar_upload] the original image and thumbnail are instantly updated as soon as the page has been reloaded.
I have this same problem and would really like a solution.
-
This reply was modified 3 years, 1 month ago by
- The topic ‘The image does not update immediately after upload and page refresh’ is closed to new replies.