Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/02/2018 04:32:31 AM (6 years ago)
Author:
r-a-y
Message:

XProfile: Conditionally load action and screen functions.

This commit conditionally loads action and screen function code for the
XProfile component, utilizing the 'bp_late_include' hook introduced in
r11884.

Previously, we loaded these functions at all times, which is unnecessary
when a user is not on a BuddyPress extended profile page. Now, we only load
this code when needed.

See #7218.

Location:
trunk/src/bp-xprofile/screens
Files:
1 added
1 moved

Legend:

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

    r11927 r11928  
    11<?php
    22/**
    3  * BuddyPress XProfile Screens.
    4  *
    5  * Screen functions are the controllers of BuddyPress. They will execute when
    6  * their specific URL is caught. They will first save or manipulate data using
    7  * business functions, then pass on the user to a template file.
     3 * XProfile: User's "Profile > Edit" screen handler
    84 *
    95 * @package BuddyPress
    106 * @subpackage XProfileScreens
    11  * @since 1.5.0
     7 * @since 3.0.0
    128 */
    13 
    14 // Exit if accessed directly.
    15 defined( 'ABSPATH' ) || exit;
    16 
    17 /**
    18  * Handles the display of the profile page by loading the correct template file.
    19  *
    20  * @since 1.0.0
    21  *
    22  */
    23 function xprofile_screen_display_profile() {
    24     $new = isset( $_GET['new'] ) ? $_GET['new'] : '';
    25 
    26     /**
    27      * Fires right before the loading of the XProfile screen template file.
    28      *
    29      * @since 1.0.0
    30      *
    31      * @param string $new $_GET parameter holding the "new" parameter.
    32      */
    33     do_action( 'xprofile_screen_display_profile', $new );
    34 
    35     /**
    36      * Filters the template to load for the XProfile screen.
    37      *
    38      * @since 1.0.0
    39      *
    40      * @param string $template Path to the XProfile template to load.
    41      */
    42     bp_core_load_template( apply_filters( 'xprofile_template_display_profile', 'members/single/home' ) );
    43 }
    449
    4510/**
     
    190155    bp_core_load_template( apply_filters( 'xprofile_template_edit_profile', 'members/single/home' ) );
    191156}
    192 
    193 /**
    194  * Handles the uploading and cropping of a user avatar. Displays the change avatar page.
    195  *
    196  * @since 1.0.0
    197  *
    198  */
    199 function xprofile_screen_change_avatar() {
    200 
    201     // Bail if not the correct screen.
    202     if ( ! bp_is_my_profile() && ! bp_current_user_can( 'bp_moderate' ) ) {
    203         return false;
    204     }
    205 
    206     // Bail if there are action variables.
    207     if ( bp_action_variables() ) {
    208         bp_do_404();
    209         return;
    210     }
    211 
    212     $bp = buddypress();
    213 
    214     if ( ! isset( $bp->avatar_admin ) ) {
    215         $bp->avatar_admin = new stdClass();
    216     }
    217 
    218     $bp->avatar_admin->step = 'upload-image';
    219 
    220     if ( !empty( $_FILES ) ) {
    221 
    222         // Check the nonce.
    223         check_admin_referer( 'bp_avatar_upload' );
    224 
    225         // Pass the file to the avatar upload handler.
    226         if ( bp_core_avatar_handle_upload( $_FILES, 'xprofile_avatar_upload_dir' ) ) {
    227             $bp->avatar_admin->step = 'crop-image';
    228 
    229             // Make sure we include the jQuery jCrop file for image cropping.
    230             add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' );
    231         }
    232     }
    233 
    234     // If the image cropping is done, crop the image and save a full/thumb version.
    235     if ( isset( $_POST['avatar-crop-submit'] ) ) {
    236 
    237         // Check the nonce.
    238         check_admin_referer( 'bp_avatar_cropstore' );
    239 
    240         $args = array(
    241             'item_id'       => bp_displayed_user_id(),
    242             'original_file' => $_POST['image_src'],
    243             'crop_x'        => $_POST['x'],
    244             'crop_y'        => $_POST['y'],
    245             'crop_w'        => $_POST['w'],
    246             'crop_h'        => $_POST['h']
    247         );
    248 
    249         if ( ! bp_core_avatar_handle_crop( $args ) ) {
    250             bp_core_add_message( __( 'There was a problem cropping your profile photo.', 'buddypress' ), 'error' );
    251         } else {
    252 
    253             /**
    254              * Fires right before the redirect, after processing a new avatar.
    255              *
    256              * @since 1.1.0
    257              * @since 2.3.4 Add two new parameters to inform about the user id and
    258              *              about the way the avatar was set (eg: 'crop' or 'camera').
    259              *
    260              * @param string $item_id Inform about the user id the avatar was set for.
    261              * @param string $value   Inform about the way the avatar was set ('crop').
    262              */
    263             do_action( 'xprofile_avatar_uploaded', (int) $args['item_id'], 'crop' );
    264             bp_core_add_message( __( 'Your new profile photo was uploaded successfully.', 'buddypress' ) );
    265             bp_core_redirect( bp_displayed_user_domain() );
    266         }
    267     }
    268 
    269     /**
    270      * Fires right before the loading of the XProfile change avatar screen template file.
    271      *
    272      * @since 1.0.0
    273      */
    274     do_action( 'xprofile_screen_change_avatar' );
    275 
    276     /**
    277      * Filters the template to load for the XProfile change avatar screen.
    278      *
    279      * @since 1.0.0
    280      *
    281      * @param string $template Path to the XProfile change avatar template to load.
    282      */
    283     bp_core_load_template( apply_filters( 'xprofile_template_change_avatar', 'members/single/home' ) );
    284 }
    285 
    286 /**
    287  * Displays the change cover image page.
    288  *
    289  * @since 2.4.0
    290  */
    291 function xprofile_screen_change_cover_image() {
    292 
    293     // Bail if not the correct screen.
    294     if ( ! bp_is_my_profile() && ! bp_current_user_can( 'bp_moderate' ) ) {
    295         return false;
    296     }
    297 
    298     /**
    299      * Fires right before the loading of the XProfile change cover image screen template file.
    300      *
    301      * @since 2.4.0
    302      */
    303     do_action( 'xprofile_screen_change_cover_image' );
    304 
    305     /**
    306      * Filters the template to load for the XProfile cover image screen.
    307      *
    308      * @since 2.4.0
    309      *
    310      * @param string $template Path to the XProfile cover image template to load.
    311      */
    312     bp_core_load_template( apply_filters( 'xprofile_template_cover_image', 'members/single/home' ) );
    313 }
    314 
    315 /**
    316  * Show the xprofile settings template.
    317  *
    318  * @since 2.0.0
    319  */
    320 function bp_xprofile_screen_settings() {
    321 
    322     // Redirect if no privacy settings page is accessible.
    323     if ( bp_action_variables() || ! bp_is_active( 'xprofile' ) ) {
    324         bp_do_404();
    325         return;
    326     }
    327 
    328     /**
    329      * Filters the template to load for the XProfile settings screen.
    330      *
    331      * @since 2.0.0
    332      *
    333      * @param string $template Path to the XProfile change avatar template to load.
    334      */
    335     bp_core_load_template( apply_filters( 'bp_settings_screen_xprofile', '/members/single/settings/profile' ) );
    336 }
Note: See TracChangeset for help on using the changeset viewer.