Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/02/2018 04:32:31 AM (7 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/settings-profile.php

    r11927 r11928  
    11<?php
    22/**
    3  * BuddyPress XProfile Actions.
    4  *
    5  * Action functions are exactly the same as screen functions, however they do not
    6  * have a template screen associated with them. Usually they will send the user
    7  * back to the default screen after execution.
     3 * XProfile: User's "Settings > Profile Visibility" screen handler
    84 *
    95 * @package BuddyPress
    10  * @subpackage XProfileActions
    11  * @since 1.5.0
     6 * @subpackage XProfileScreens
     7 * @since 3.0.0
    128 */
    139
    14 // Exit if accessed directly.
    15 defined( 'ABSPATH' ) || exit;
     10/**
     11 * Show the xprofile settings template.
     12 *
     13 * @since 2.0.0
     14 */
     15function bp_xprofile_screen_settings() {
    1616
    17 /**
    18  * This function runs when an action is set for a screen:
    19  * example.com/members/andy/profile/change-avatar/ [delete-avatar]
    20  *
    21  * The function will delete the active avatar for a user.
    22  *
    23  * @since 1.0.0
    24  *
    25  */
    26 function xprofile_action_delete_avatar() {
    27 
    28     if ( ! bp_is_user_change_avatar() || ! bp_is_action_variable( 'delete-avatar', 0 ) ) {
    29         return false;
     17    // Redirect if no privacy settings page is accessible.
     18    if ( bp_action_variables() || ! bp_is_active( 'xprofile' ) ) {
     19        bp_do_404();
     20        return;
    3021    }
    3122
    32     // Check the nonce.
    33     check_admin_referer( 'bp_delete_avatar_link' );
    34 
    35     if ( ! bp_is_my_profile() && ! bp_current_user_can( 'bp_moderate' ) ) {
    36         return false;
    37     }
    38 
    39     if ( bp_core_delete_existing_avatar( array( 'item_id' => bp_displayed_user_id() ) ) ) {
    40         bp_core_add_message( __( 'Your profile photo was deleted successfully!', 'buddypress' ) );
    41     } else {
    42         bp_core_add_message( __( 'There was a problem deleting your profile photo. Please try again.', 'buddypress' ), 'error' );
    43     }
    44 
    45     bp_core_redirect( wp_get_referer() );
     23    /**
     24     * Filters the template to load for the XProfile settings screen.
     25     *
     26     * @since 2.0.0
     27     *
     28     * @param string $template Path to the XProfile change avatar template to load.
     29     */
     30    bp_core_load_template( apply_filters( 'bp_settings_screen_xprofile', '/members/single/settings/profile' ) );
    4631}
    47 add_action( 'bp_actions', 'xprofile_action_delete_avatar' );
    4832
    4933/**
Note: See TracChangeset for help on using the changeset viewer.