BuddyDev

Search

Change profile photo shortcode

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #50932

    Hi

    I am tyring to create a shortcode for the change profile photo section, I intend adding the shortcode to a custom page but the code keeps causing a fatal error.

    I am using buddypress 12.0 RC1 for testing

     function bp_custom_avatar_shortcode() {
        if (!(int) bp_get_option('bp-disable-avatar-uploads')) {
            ob_start();
            ?>
            <form action="" method="post" id="avatar-upload-form" class="standard-form" enctype="multipart/form-data">
                <?php if ('upload-image' == bp_get_avatar_admin_step()) : ?>
                    <?php wp_nonce_field('bp_avatar_upload'); ?>
                    <p><?php _e('Click below to select a JPG, GIF, or PNG format photo from your computer and then click \'Upload Image\' to proceed.', 'buddypress'); ?></p>
                    <p id="avatar-upload">
                        <label for="file" class="bp-screen-reader-text"><?php _e('Select an image', 'buddypress'); ?></label>
                        <input type="file" name="file" id="file" />
                        <input type="submit" name="upload" id="upload" value="<?php esc_attr_e('Upload Image', 'buddypress'); ?>" />
                        <input type="hidden" name="action" id="action" value="bp_avatar_upload" />
                    </p>
                    <?php if (bp_get_user_has_avatar()) : ?>
                        <p><?php _e("If you'd like to delete your current profile photo but not upload a new one, please use the delete profile photo button.", 'buddypress'); ?></p>
                        <p><a class="button edit" href="<?php bp_avatar_delete_link(); ?>"><?php _e('Delete My Profile Photo', 'buddypress'); ?></a></p>
                    <?php endif; ?>
                <?php endif; ?>
                <?php if ('crop-image' == bp_get_avatar_admin_step()) : ?>
                    <h5><?php _e('Crop Your New Profile Photo', 'buddypress'); ?></h5>
                    <img src="<?php bp_avatar_to_crop(); ?>" id="avatar-to-crop" class="avatar" alt="<?php esc_attr_e('Profile photo to crop', 'buddypress'); ?>" />
                    <div id="avatar-crop-pane">
                        <img src="<?php bp_avatar_to_crop(); ?>" id="avatar-crop-preview" class="avatar" alt="<?php esc_attr_e('Profile photo preview', 'buddypress'); ?>" />
                    </div>
                    <input type="submit" name="avatar-crop-submit" id="avatar-crop-submit" value="<?php esc_attr_e('Crop Image', 'buddypress'); ?>" />
                    <input type="hidden" name="image_src" id="image_src" value="<?php bp_avatar_to_crop_src(); ?>" />
                    <input type="hidden" id="x" name="x" />
                    <input type="hidden" id="y" name="y" />
                    <input type="hidden" id="w" name="w" />
                    <input type="hidden" id="h" name="h" />
                    <?php wp_nonce_field('bp_avatar_cropstore'); ?>
                <?php endif; ?>
            </form>
            <?php
            bp_avatar_get_templates();
            $output = ob_get_clean();
            return $output;
        } else {
            return '<p>' . __('Your profile photo will be used on your profile and throughout the site. To change your profile photo, please create an account with <a href="https://gravatar.com">Gravatar</a> using the same email address as you used to register with this site.', 'buddypress') . '</p>';
        }
    }
    add_shortcode('change-bp-profile-avatar', 'bp_custom_avatar_shortcode'); 

    I also tried

     function bp_custom_avatar_shortcode() {
        // Check if BuddyPress is active and avatar uploads are enabled
        if (!bp_is_active() || (int) bp_get_option('bp-disable-avatar-uploads')) {
            return '<p>' . __('Your profile photo will be used on your profile and throughout the site. To change your profile photo, please create an account with <a href="https://gravatar.com">Gravatar</a> using the same email address as you used to register with this site.', 'buddypress') . '</p>';
        }
    
        // Start output buffering
        ob_start();
    
        // Display the appropriate form based on the avatar upload step
        if ('upload-image' === bp_get_avatar_admin_step()) {
            bp_get_template_part('members/single/profile/change-avatar/upload-image');
        } elseif ('crop-image' === bp_get_avatar_admin_step()) {
            bp_get_template_part('members/single/profile/change-avatar/crop-image');
        }
    
        // Capture the buffered output
        $output = ob_get_clean();
    
        // Return the output
        return $output;
    }
    
    add_shortcode('change-bp-profile-avatar', 'bp_custom_avatar_shortcode'); 
  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #50935

    Hi Tosin,
    Thank you for your question.

    I am sorry but our team lacks the time to assist you with it. I would suggest trying wp.org support.

    At the moment, we are providing assistance for our own plugins/themes. Our time is invested in a major upcoming project and that leaves little time to assist beyond our own plugins/themes.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved