Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/16/2015 10:54:11 PM (9 years ago)
Author:
imath
Message:

Avatar UI: use it in wp-admin/extended profile.

Clicking on the "Edit Profile Photo" link from the avatar metabox will open a thickbox window in which the Avatar UI will be displayed.

See #6290

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-admin.php

    r9691 r9759  
    674674     */
    675675    private function setup_actions() {
     676        // Enqueue scripts
     677        add_action( 'bp_members_admin_enqueue_scripts',  array( $this, 'enqueue_scripts'    ), 10, 1 );
    676678
    677679        // Register the metabox in Member's community admin profile
     
    680682        // Saves the profile actions for user ( avatar, profile fields )
    681683        add_action( 'bp_members_admin_update_user',      array( $this, 'user_admin_load'    ), 10, 4 );
     684    }
     685
     686    /**
     687     * Enqueue needed scripts.
     688     *
     689     * @access public
     690     * @since BuddyPress (2.3.0)
     691     */
     692    public function enqueue_scripts( $screen_id ) {
     693        if ( ( false === strpos( $screen_id, 'users_page_bp-profile-edit' ) && false === strpos( $screen_id, 'profile_page_bp-profile-edit' ) ) || bp_core_get_root_option( 'bp-disable-avatar-uploads' ) ) {
     694            return;
     695        }
     696
     697        /**
     698         * Get Thickbox
     699         *
     700         * We cannot simply use add_thickbox() here as WordPress is not playing
     701         * nice with Thickbox width/height see https://core.trac.wordpress.org/ticket/17249
     702         * Using media-upload might be interesting in the future for the send to editor stuff
     703         * and we make sure the tb_window is wide enougth
     704         */
     705        wp_enqueue_style ( 'thickbox' );
     706        wp_enqueue_script( 'media-upload' );
     707
     708        // Get Avatar Uploader
     709        bp_attachments_enqueue_scripts( 'BP_Attachment_Avatar' );
    682710    }
    683711
     
    10381066                <a href="<?php echo esc_url( $delete_link ); ?>" title="<?php esc_attr_e( 'Delete Profile Photo', 'buddypress' ); ?>" class="bp-xprofile-avatar-user-admin"><?php esc_html_e( 'Delete Profile Photo', 'buddypress' ); ?></a></li>
    10391067
     1068            <?php endif;
     1069
     1070            // Load the Avatar UI templates if user avatar uploads are enabled
     1071            if ( ! bp_core_get_root_option( 'bp-disable-avatar-uploads' ) ) : ?>
     1072                <a href="#TB_inline?width=800px&height=400px&inlineId=bp-xprofile-avatar-editor" title="<?php esc_attr_e( 'Edit Profile Photo', 'buddypress' );?>" class="thickbox bp-xprofile-avatar-user-edit"><?php esc_html_e( 'Edit Profile Photo', 'buddypress' ); ?></a>
     1073                <div id="bp-xprofile-avatar-editor" style="display:none;">
     1074                    <?php bp_attachments_get_template_part( 'avatars/index' ); ?>
     1075                </div>
    10401076            <?php endif; ?>
    10411077
Note: See TracChangeset for help on using the changeset viewer.