Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/29/2020 03:33:10 PM (5 years ago)
Author:
imath
Message:

Move Avatars & Cover from xProfile to Members component : step 2

Move User Avatar's management from the xProfile User Admin to the Members User Admin class.

See #8156

File:
1 edited

Legend:

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

    r11758 r12554  
    5757     */
    5858    private function setup_actions() {
    59         // Enqueue scripts.
    60         add_action( 'bp_members_admin_enqueue_scripts',  array( $this, 'enqueue_scripts'    ), 10, 1 );
    6159
    6260        // Register the metabox in Member's community admin profile.
    6361        add_action( 'bp_members_admin_xprofile_metabox', array( $this, 'register_metaboxes' ), 10, 3 );
    6462
    65         // Saves the profile actions for user ( avatar, profile fields ).
     63        // Saves the profile actions for user ( profile fields ).
    6664        add_action( 'bp_members_admin_update_user',      array( $this, 'user_admin_load'    ), 10, 4 );
    67     }
    68 
    69     /**
    70      * Enqueue needed scripts.
    71      *
    72      * @since 2.3.0
    73      *
    74      * @param int $screen_id Screen ID being displayed.
    75      */
    76     public function enqueue_scripts( $screen_id ) {
    77         if ( ( false === strpos( $screen_id, 'users_page_bp-profile-edit' )
    78             && false === strpos( $screen_id, 'profile_page_bp-profile-edit' ) )
    79             || bp_core_get_root_option( 'bp-disable-avatar-uploads' )
    80             || ! buddypress()->avatar->show_avatars
    81             || ! bp_attachments_is_wp_version_supported() ) {
    82             return;
    83         }
    84 
    85         /**
    86          * Get Thickbox.
    87          *
    88          * We cannot simply use add_thickbox() here as WordPress is not playing
    89          * nice with Thickbox width/height see https://core.trac.wordpress.org/ticket/17249
    90          * Using media-upload might be interesting in the future for the send to editor stuff
    91          * and we make sure the tb_window is wide enough
    92          */
    93         wp_enqueue_style ( 'thickbox' );
    94         wp_enqueue_script( 'media-upload' );
    95 
    96         // Get Avatar Uploader.
    97         bp_attachments_enqueue_scripts( 'BP_Attachment_Avatar' );
    9865    }
    9966
     
    156123            );
    157124        }
    158 
    159         if ( buddypress()->avatar->show_avatars ) {
    160             // Avatar Metabox.
    161             add_meta_box(
    162                 'bp_xprofile_user_admin_avatar',
    163                 _x( 'Profile Photo', 'xprofile user-admin edit screen', 'buddypress' ),
    164                 array( $this, 'user_admin_avatar_metabox' ),
    165                 $screen_id,
    166                 'side',
    167                 'low'
    168             );
    169         }
    170125    }
    171126
     
    177132     *
    178133     * @since 2.0.0
     134     * @since 6.0.0 The `delete_avatar` action is now managed into BP_Members_Admin::user_admin_load().
    179135     *
    180136     * @param string $doaction    Action being run.
     
    185141    public function user_admin_load( $doaction = '', $user_id = 0, $request = array(), $redirect_to = '' ) {
    186142
    187         // Eventually delete avatar.
    188         if ( 'delete_avatar' === $doaction ) {
    189 
    190             check_admin_referer( 'delete_avatar' );
    191 
    192             $redirect_to = remove_query_arg( '_wpnonce', $redirect_to );
    193 
    194             if ( bp_core_delete_existing_avatar( array( 'item_id' => $user_id ) ) ) {
    195                 $redirect_to = add_query_arg( 'updated', 'avatar', $redirect_to );
    196             } else {
    197                 $redirect_to = add_query_arg( 'error', 'avatar', $redirect_to );
    198             }
    199 
    200             bp_core_redirect( $redirect_to );
    201 
    202         } elseif ( isset( $_POST['field_ids'] ) ) {
    203             // Update profile fields.
     143        // Update profile fields.
     144        if ( isset( $_POST['field_ids'] ) ) {
     145
    204146            // Check the nonce.
    205147            check_admin_referer( 'edit-bp-profile_' . $user_id );
     
    435377    }
    436378
    437     /**
    438      * Render the Avatar metabox to moderate inappropriate images.
    439      *
    440      * @since 2.0.0
    441      *
    442      * @param WP_User|null $user The WP_User object for the user being edited.
    443      */
    444     public function user_admin_avatar_metabox( $user = null ) {
    445 
    446         if ( empty( $user->ID ) ) {
    447             return;
    448         } ?>
    449 
    450         <div class="avatar">
    451 
    452             <?php echo bp_core_fetch_avatar( array(
    453                 'item_id' => $user->ID,
    454                 'object'  => 'user',
    455                 'type'    => 'full',
    456                 'title'   => $user->display_name
    457             ) ); ?>
    458 
    459             <?php if ( bp_get_user_has_avatar( $user->ID ) ) :
    460 
    461                 $query_args = array(
    462                     'user_id' => $user->ID,
    463                     'action'  => 'delete_avatar'
    464                 );
    465 
    466                 if ( ! empty( $_REQUEST['wp_http_referer'] ) ) {
    467                     $wp_http_referer = wp_unslash( $_REQUEST['wp_http_referer'] );
    468                     $wp_http_referer = remove_query_arg( array( 'action', 'updated' ), $wp_http_referer );
    469                     $wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) );
    470                     $query_args['wp_http_referer'] = urlencode( $wp_http_referer );
    471                 }
    472 
    473                 $community_url = add_query_arg( $query_args, buddypress()->members->admin->edit_profile_url );
    474                 $delete_link   = wp_nonce_url( $community_url, 'delete_avatar' ); ?>
    475 
    476                 <a href="<?php echo esc_url( $delete_link ); ?>" class="bp-xprofile-avatar-user-admin"><?php esc_html_e( 'Delete Profile Photo', 'buddypress' ); ?></a>
    477 
    478             <?php endif;
    479 
    480             // Load the Avatar UI templates if user avatar uploads are enabled and current WordPress version is supported.
    481             if ( ! bp_core_get_root_option( 'bp-disable-avatar-uploads' ) && bp_attachments_is_wp_version_supported() ) : ?>
    482                 <a href="#TB_inline?width=800px&height=400px&inlineId=bp-xprofile-avatar-editor" class="thickbox bp-xprofile-avatar-user-edit"><?php esc_html_e( 'Edit Profile Photo', 'buddypress' ); ?></a>
    483                 <div id="bp-xprofile-avatar-editor" style="display:none;">
    484                     <?php bp_attachments_get_template_part( 'avatars/index' ); ?>
    485                 </div>
    486             <?php endif; ?>
    487 
    488         </div>
    489         <?php
    490     }
    491 
    492379}
    493380endif; // End class_exists check.
Note: See TracChangeset for help on using the changeset viewer.