• Resolved Snake93

    (@bodybuildinggeneration)


    Hi, thanks for the plugin, it’s great.
    I was wondering if it was possible to put upload, update and other button in different shortcodes. I wanted more control over the position of the buttons.

    For example, this is what I tried to do. The upload button with select image is displayed correctly but does not work. When I click on load the page updates but the changes are not saved.

    Is it possible to introduce that tast inside the shortcode?

    //CUSTOM SHORTCODE
    function short_shortcode() {

    //Global
    global $current_user;

    $user = $current_user;

    ob_start();
    ?>
    <form>
    <p 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” />

    <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(‘Upload’, ‘one-user-avatar’); ?>”>
    <?php esc_html_e(‘Upload’, ‘one-user-avatar’); ?>
    </button>
    </p>
    </form>
    <?php
    return ob_get_clean();
    }
    add_shortcode(‘short’, ‘short_shortcode’);

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Daniel Tara

    (@danieltara)

    You are copying the wrong function. Try using wpua_edit_form() from the class WP_User_Avatar_Shortcode as a base instead. The reason your form isn’t saving is because you are missing a nonce field. The function you copied is supposed to inject its output in the edit profile form, which already has its own nonce field.

    To answer your question, the extra shortcodes that you asked for will not be added, because that would make the process of adding the upload form inside post content a lot more difficult. Instead, I will add a filter so you can override the output of the function that renders the form. Thank you for the suggestion.

    Thread Starter Snake93

    (@bodybuildinggeneration)

    Thanks for the tip. In the end I structured it like this and it worked.

    //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,		
           $errors,
           $wpua_is_profile,
           $wpua_upload_size_limit,
           $wpua_upload_size_limit_with_units;
    	   
    	   
    // 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');
    • This reply was modified 2 years, 8 months ago by Snake93.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Is it possible to put the buttons inside different shortcodes?’ is closed to new replies.