Skip to:
Content

BuddyPress.org

Changeset 12554


Ignore:
Timestamp:
02/29/2020 03:33:10 PM (3 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

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/js/avatar.js

    r12548 r12554  
    5151            } );
    5252
    53             $( 'body.wp-admin' ).on( 'click', '.bp-xprofile-avatar-user-edit', function() {
     53            $( 'body.wp-admin' ).on( 'click', '.bp-members-avatar-user-edit', function() {
    5454                self.resetViews();
    5555            } );
     
    7979                $( '.main-column p #upload' ).remove();
    8080
    81             // Admin Extended Profile.
    82             } else if ( $( '#bp_xprofile_user_admin_avatar a.bp-xprofile-avatar-user-admin' ).length ) {
    83                 $( '#bp_xprofile_user_admin_avatar a.bp-xprofile-avatar-user-admin' ).remove();
     81            // Member Admin.
     82            } else if ( $( '#bp_members_user_admin_avatar a.bp-members-avatar-user-admin' ).length ) {
     83                $( '#bp_members_user_admin_avatar a.bp-members-avatar-user-admin' ).remove();
    8484            }
    8585        },
  • trunk/src/bp-members/admin/css/admin-rtl.css

    r11718 r12554  
    3030div#community-profile-page li.bp-groups-profile-stats:before,
    3131div#community-profile-page li.bp-blogs-profile-stats:before,
    32 div#community-profile-page a.bp-xprofile-avatar-user-admin:before,
    33 div#community-profile-page a.bp-xprofile-avatar-user-edit:before {
     32div#community-profile-page a.bp-members-avatar-user-admin:before,
     33div#community-profile-page a.bp-members-avatar-user-edit:before {
    3434    font: 400 20px/1 dashicons;
    3535    speak: none;
     
    6262}
    6363
    64 div#community-profile-page a.bp-xprofile-avatar-user-admin:before {
     64div#community-profile-page a.bp-members-avatar-user-admin:before {
    6565    content: "\f182";
    6666}
    6767
    68 div#community-profile-page a.bp-xprofile-avatar-user-edit:before {
     68div#community-profile-page a.bp-members-avatar-user-edit:before {
    6969    content: "\f107";
    7070}
    7171
    72 div#community-profile-page div#bp_xprofile_user_admin_avatar div.avatar {
     72div#community-profile-page div#bp_members_user_admin_avatar div.avatar {
    7373    width: 150px;
    7474    margin: 0 auto;
    7575}
    7676
    77 div#community-profile-page div#bp_xprofile_user_admin_avatar div.avatar img {
     77div#community-profile-page div#bp_members_user_admin_avatar div.avatar img {
    7878    max-width: 100%;
    7979    height: auto;
    8080}
    8181
    82 div#community-profile-page div#bp_xprofile_user_admin_avatar a {
     82div#community-profile-page div#bp_members_user_admin_avatar a {
    8383    display: block;
    8484    margin: 1em 0;
  • trunk/src/bp-members/admin/css/admin.css

    r11718 r12554  
    3030div#community-profile-page li.bp-groups-profile-stats:before,
    3131div#community-profile-page li.bp-blogs-profile-stats:before,
    32 div#community-profile-page a.bp-xprofile-avatar-user-admin:before,
    33 div#community-profile-page a.bp-xprofile-avatar-user-edit:before {
     32div#community-profile-page a.bp-members-avatar-user-admin:before,
     33div#community-profile-page a.bp-members-avatar-user-edit:before {
    3434    font: 400 20px/1 dashicons;
    3535    speak: none;
     
    6262}
    6363
    64 div#community-profile-page a.bp-xprofile-avatar-user-admin:before {
     64div#community-profile-page a.bp-members-avatar-user-admin:before {
    6565    content: "\f182";
    6666}
    6767
    68 div#community-profile-page a.bp-xprofile-avatar-user-edit:before {
     68div#community-profile-page a.bp-members-avatar-user-edit:before {
    6969    content: "\f107";
    7070}
    7171
    72 div#community-profile-page div#bp_xprofile_user_admin_avatar div.avatar {
     72div#community-profile-page div#bp_members_user_admin_avatar div.avatar {
    7373    width: 150px;
    7474    margin: 0 auto;
    7575}
    7676
    77 div#community-profile-page div#bp_xprofile_user_admin_avatar div.avatar img {
     77div#community-profile-page div#bp_members_user_admin_avatar div.avatar img {
    7878    max-width: 100%;
    7979    height: auto;
    8080}
    8181
    82 div#community-profile-page div#bp_xprofile_user_admin_avatar a {
     82div#community-profile-page div#bp_members_user_admin_avatar a {
    8383    display: block;
    8484    margin: 1em 0;
  • trunk/src/bp-members/classes/class-bp-members-admin.php

    r12479 r12554  
    643643            $js = apply_filters( 'bp_members_admin_js', $js );
    644644            wp_enqueue_script( 'bp-members-js', $js, array( 'jquery' ), bp_get_version(), true );
     645
     646            if ( ! bp_core_get_root_option( 'bp-disable-avatar-uploads' ) && buddypress()->avatar->show_avatars ) {
     647                /**
     648                 * Get Thickbox.
     649                 *
     650                 * We cannot simply use add_thickbox() here as WordPress is not playing
     651                 * nice with Thickbox width/height see https://core.trac.wordpress.org/ticket/17249
     652                 * Using media-upload might be interesting in the future for the send to editor stuff
     653                 * and we make sure the tb_window is wide enough
     654                 */
     655                wp_enqueue_style ( 'thickbox' );
     656                wp_enqueue_script( 'media-upload' );
     657
     658                // Get Avatar Uploader.
     659                bp_attachments_enqueue_scripts( 'BP_Attachment_Avatar' );
     660            }
    645661        }
    646662
     
    724740     *
    725741     * @since 2.0.0
     742     * @since 6.0.0 The `delete_avatar` action is now managed into this method.
    726743     */
    727744    public function user_admin_load() {
     
    820837            }
    821838
     839            // Set the screen id.
     840            $screen_id = get_current_screen()->id;
     841
    822842            // User Stat metabox.
    823843            add_meta_box(
     
    825845                sprintf( _x( "%s's Stats", 'members user-admin edit screen', 'buddypress' ), $display_name ),
    826846                array( $this, 'user_admin_stats_metabox' ),
    827                 get_current_screen()->id,
     847                $screen_id,
    828848                sanitize_key( $this->stats_metabox->context ),
    829849                sanitize_key( $this->stats_metabox->priority )
    830850            );
     851
     852            if ( buddypress()->avatar->show_avatars ) {
     853                // Avatar Metabox.
     854                add_meta_box(
     855                    'bp_members_user_admin_avatar',
     856                    _x( 'Profile Photo', 'members user-admin edit screen', 'buddypress' ),
     857                    array( $this, 'user_admin_avatar_metabox' ),
     858                    $screen_id,
     859                    'side',
     860                    'low'
     861                );
     862            }
    831863
    832864            // Member Type metabox. Only added if member types have been registered.
     
    837869                    _x( 'Member Type', 'members user-admin edit screen', 'buddypress' ),
    838870                    array( $this, 'user_admin_member_type_metabox' ),
    839                     get_current_screen()->id,
     871                    $screen_id,
    840872                    'side',
    841873                    'core'
     
    875907            bp_core_redirect( $redirect_to );
    876908
     909        // Eventually delete avatar.
     910        } elseif ( 'delete_avatar' === $doaction ) {
     911
     912            // Check the nonce.
     913            check_admin_referer( 'delete_avatar' );
     914
     915            $redirect_to = remove_query_arg( '_wpnonce', $redirect_to );
     916
     917            if ( bp_core_delete_existing_avatar( array( 'item_id' => $user_id ) ) ) {
     918                $redirect_to = add_query_arg( 'updated', 'avatar', $redirect_to );
     919            } else {
     920                $redirect_to = add_query_arg( 'error', 'avatar', $redirect_to );
     921            }
     922
     923            bp_core_redirect( $redirect_to );
     924
    877925        // Update other stuff once above ones are done.
    878926        } else {
     
    11711219        </ul>
    11721220
     1221        <?php
     1222    }
     1223
     1224    /**
     1225     * Render the Avatar metabox to moderate inappropriate images.
     1226     *
     1227     * @since 6.0.0
     1228     *
     1229     * @param WP_User|null $user The WP_User object for the user being edited.
     1230     */
     1231    public function user_admin_avatar_metabox( $user = null ) {
     1232
     1233        if ( empty( $user->ID ) ) {
     1234            return;
     1235        } ?>
     1236
     1237        <div class="avatar">
     1238
     1239            <?php echo bp_core_fetch_avatar( array(
     1240                'item_id' => $user->ID,
     1241                'object'  => 'user',
     1242                'type'    => 'full',
     1243                'title'   => $user->display_name
     1244            ) ); ?>
     1245
     1246            <?php if ( bp_get_user_has_avatar( $user->ID ) ) :
     1247
     1248                $query_args = array(
     1249                    'user_id' => $user->ID,
     1250                    'action'  => 'delete_avatar'
     1251                );
     1252
     1253                if ( ! empty( $_REQUEST['wp_http_referer'] ) ) {
     1254                    $wp_http_referer = wp_unslash( $_REQUEST['wp_http_referer'] );
     1255                    $wp_http_referer = remove_query_arg( array( 'action', 'updated' ), $wp_http_referer );
     1256                    $wp_http_referer = wp_validate_redirect( esc_url_raw( $wp_http_referer ) );
     1257                    $query_args['wp_http_referer'] = urlencode( $wp_http_referer );
     1258                }
     1259
     1260                $community_url = add_query_arg( $query_args, $this->edit_profile_url );
     1261                $delete_link   = wp_nonce_url( $community_url, 'delete_avatar' ); ?>
     1262
     1263                <a href="<?php echo esc_url( $delete_link ); ?>" class="bp-members-avatar-user-admin"><?php esc_html_e( 'Delete Profile Photo', 'buddypress' ); ?></a>
     1264
     1265            <?php endif;
     1266
     1267            // Load the Avatar UI templates if user avatar uploads are enabled.
     1268            if ( ! bp_core_get_root_option( 'bp-disable-avatar-uploads' ) ) : ?>
     1269                <a href="#TB_inline?width=800px&height=400px&inlineId=bp-members-avatar-editor" class="thickbox bp-members-avatar-user-edit"><?php esc_html_e( 'Edit Profile Photo', 'buddypress' ); ?></a>
     1270                <div id="bp-members-avatar-editor" style="display:none;">
     1271                    <?php bp_attachments_get_template_part( 'avatars/index' ); ?>
     1272                </div>
     1273            <?php endif; ?>
     1274
     1275        </div>
    11731276        <?php
    11741277    }
  • 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.