Skip to:
Content

BuddyPress.org


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

Settings: Conditionally load action and screen functions.

This commit conditionally loads action and screen function code for the
Settings 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 settings page. Now, we only load this
code when needed.

See #7218.

Location:
trunk/src/bp-settings/actions
Files:
1 added
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-settings/actions/general.php

    r11925 r11926  
    11<?php
    22/**
    3  * BuddyPress Settings Actions
    4  *
    5  * @todo split actions into separate screen functions
     3 * Settings: Email address and password action handler
     4 *
    65 * @package BuddyPress
    76 * @subpackage SettingsActions
    8  * @since 1.5.0
     7 * @since 3.0.0
    98 */
    10 
    11 // Exit if accessed directly.
    12 defined( 'ABSPATH' ) || exit;
    139
    1410/**
     
    256252
    257253/**
    258  * Handles the changing and saving of user notification settings.
    259  *
    260  * @since 1.6.0
    261  */
    262 function bp_settings_action_notifications() {
    263     if ( ! bp_is_post_request() ) {
    264         return;
    265     }
    266 
    267     // Bail if no submit action.
    268     if ( ! isset( $_POST['submit'] ) ) {
    269         return;
    270     }
    271 
    272     // Bail if not in settings.
    273     if ( ! bp_is_settings_component() || ! bp_is_current_action( 'notifications' ) ) {
    274         return false;
    275     }
    276 
    277     // 404 if there are any additional action variables attached
    278     if ( bp_action_variables() ) {
    279         bp_do_404();
    280         return;
    281     }
    282 
    283     check_admin_referer( 'bp_settings_notifications' );
    284 
    285     bp_settings_update_notification_settings( bp_displayed_user_id(), (array) $_POST['notifications'] );
    286 
    287     // Switch feedback for super admins.
    288     if ( bp_is_my_profile() ) {
    289         bp_core_add_message( __( 'Your notification settings have been saved.',        'buddypress' ), 'success' );
    290     } else {
    291         bp_core_add_message( __( "This user's notification settings have been saved.", 'buddypress' ), 'success' );
    292     }
    293 
    294     /**
    295      * Fires after the notification settings have been saved, and before redirect.
    296      *
    297      * @since 1.5.0
    298      */
    299     do_action( 'bp_core_notification_settings_after_save' );
    300 
    301     bp_core_redirect( bp_displayed_user_domain() . bp_get_settings_slug() . '/notifications/' );
    302 }
    303 add_action( 'bp_actions', 'bp_settings_action_notifications' );
    304 
    305 /**
    306  * Handles the setting of user capabilities, spamming, hamming, role, etc...
    307  *
    308  * @since 1.6.0
    309  */
    310 function bp_settings_action_capabilities() {
    311     if ( ! bp_is_post_request() ) {
    312         return;
    313     }
    314 
    315     // Bail if no submit action.
    316     if ( ! isset( $_POST['capabilities-submit'] ) ) {
    317         return;
    318     }
    319 
    320     // Bail if not in settings.
    321     if ( ! bp_is_settings_component() || ! bp_is_current_action( 'capabilities' ) ) {
    322         return false;
    323     }
    324 
    325     // 404 if there are any additional action variables attached
    326     if ( bp_action_variables() ) {
    327         bp_do_404();
    328         return;
    329     }
    330 
    331     // Only super admins can currently spam users (but they can't spam
    332     // themselves).
    333     if ( ! is_super_admin() || bp_is_my_profile() ) {
    334         return;
    335     }
    336 
    337     // Nonce check.
    338     check_admin_referer( 'capabilities' );
    339 
    340     /**
    341      * Fires before the capabilities settings have been saved.
    342      *
    343      * @since 1.6.0
    344      */
    345     do_action( 'bp_settings_capabilities_before_save' );
    346 
    347     /* Spam **************************************************************/
    348 
    349     $is_spammer = !empty( $_POST['user-spammer'] ) ? true : false;
    350 
    351     if ( bp_is_user_spammer( bp_displayed_user_id() ) != $is_spammer ) {
    352         $status = ( true == $is_spammer ) ? 'spam' : 'ham';
    353         bp_core_process_spammer_status( bp_displayed_user_id(), $status );
    354 
    355         /**
    356          * Fires after processing a user as a spammer.
    357          *
    358          * @since 1.1.0
    359          *
    360          * @param int    $value  ID of the currently displayed user.
    361          * @param string $status Determined status of "spam" or "ham" for the displayed user.
    362          */
    363         do_action( 'bp_core_action_set_spammer_status', bp_displayed_user_id(), $status );
    364     }
    365 
    366     /* Other *************************************************************/
    367 
    368     /**
    369      * Fires after the capabilities settings have been saved and before redirect.
    370      *
    371      * @since 1.6.0
    372      */
    373     do_action( 'bp_settings_capabilities_after_save' );
    374 
    375     // Redirect to the root domain.
    376     bp_core_redirect( bp_displayed_user_domain() . bp_get_settings_slug() . '/capabilities/' );
    377 }
    378 add_action( 'bp_actions', 'bp_settings_action_capabilities' );
    379 
    380 /**
    381  * Handles the deleting of a user.
    382  *
    383  * @since 1.6.0
    384  */
    385 function bp_settings_action_delete_account() {
    386     if ( ! bp_is_post_request() ) {
    387         return;
    388     }
    389 
    390     // Bail if no submit action.
    391     if ( ! isset( $_POST['delete-account-understand'] ) ) {
    392         return;
    393     }
    394 
    395     // Bail if not in settings.
    396     if ( ! bp_is_settings_component() || ! bp_is_current_action( 'delete-account' ) ) {
    397         return false;
    398     }
    399 
    400     // 404 if there are any additional action variables attached
    401     if ( bp_action_variables() ) {
    402         bp_do_404();
    403         return;
    404     }
    405 
    406     // Bail if account deletion is disabled.
    407     if ( bp_disable_account_deletion() && ! bp_current_user_can( 'delete_users' ) ) {
    408         return false;
    409     }
    410 
    411     // Nonce check.
    412     check_admin_referer( 'delete-account' );
    413 
    414     // Get username now because it might be gone soon!
    415     $username = bp_get_displayed_user_fullname();
    416 
    417     // Delete the users account.
    418     if ( bp_core_delete_account( bp_displayed_user_id() ) ) {
    419 
    420         // Add feedback after deleting a user.
    421         bp_core_add_message( sprintf( __( '%s was successfully deleted.', 'buddypress' ), $username ), 'success' );
    422 
    423         // Redirect to the root domain.
    424         bp_core_redirect( bp_get_root_domain() );
    425     }
    426 }
    427 add_action( 'bp_actions', 'bp_settings_action_delete_account' );
    428 
    429 /**
    430254 * Process email change verification or cancel requests.
    431255 *
     
    486310}
    487311add_action( 'bp_actions', 'bp_settings_verify_email_change' );
    488 
    489 /**
    490  * Removes 'Email' sub nav, if no component has registered options there.
    491  *
    492  * @since 2.2.0
    493  */
    494 function bp_settings_remove_email_subnav() {
    495     if ( ! has_action( 'bp_notification_settings' ) ) {
    496         bp_core_remove_subnav_item( BP_SETTINGS_SLUG, 'notifications' );
    497     }
    498 }
    499 add_action( 'bp_actions', 'bp_settings_remove_email_subnav' );
Note: See TracChangeset for help on using the changeset viewer.