[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-messages/actions/ -> notices.php (source)

   1  <?php
   2  /**
   3   * Messages: Edit notice action handler.
   4   *
   5   * @package BuddyPress
   6   * @subpackage MessageActions
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Handle editing of sitewide notices.
  12   *
  13   * @since 2.4.0 This function was split from messages_screen_notices(). See #6505.
  14   *
  15   * @return bool
  16   */
  17  function bp_messages_action_edit_notice() {
  18  
  19      // Bail if not viewing a single notice URL.
  20      if ( ! bp_is_messages_component() || ! bp_is_current_action( 'notices' ) ) {
  21          return false;
  22      }
  23  
  24      // Get the notice ID (1|2|3).
  25      $notice_id = bp_action_variable( 1 );
  26  
  27      // Bail if notice ID is not numeric.
  28      if ( empty( $notice_id ) || ! is_numeric( $notice_id ) ) {
  29          return false;
  30      }
  31  
  32      // Bail if the current user doesn't have administrator privileges.
  33      if ( ! bp_current_user_can( 'bp_moderate' ) ) {
  34          return false;
  35      }
  36  
  37      // Get the action (deactivate|activate|delete).
  38      $action = sanitize_key( bp_action_variable( 0 ) );
  39  
  40      // Check the nonce.
  41      check_admin_referer( "messages_{$action}_notice" );
  42  
  43      // Get the notice from database.
  44      $notice   = new BP_Messages_Notice( $notice_id );
  45      $success  = false;
  46      $feedback = '';
  47  
  48      // Take action.
  49      switch ( $action ) {
  50  
  51          // Deactivate.
  52          case 'deactivate' :
  53              $success  = $notice->deactivate();
  54              $feedback = true === $success
  55                  ? __( 'Notice deactivated successfully.',              'buddypress' )
  56                  : __( 'There was a problem deactivating that notice.', 'buddypress' );
  57              break;
  58  
  59          // Activate.
  60          case 'activate' :
  61              $success  = $notice->activate();
  62              $feedback = true === $success
  63                  ? __( 'Notice activated successfully.',              'buddypress' )
  64                  : __( 'There was a problem activating that notice.', 'buddypress' );
  65              break;
  66  
  67          // Delete.
  68          case 'delete' :
  69              $success  = $notice->delete();
  70              $feedback = true === $success
  71                  ? __( 'Notice deleted successfully.',              'buddypress' )
  72                  : __( 'There was a problem deleting that notice.', 'buddypress' );
  73              break;
  74      }
  75  
  76      // Feedback.
  77      if ( ! empty( $feedback ) ) {
  78  
  79          // Determine message type.
  80          $type = ( true === $success )
  81              ? 'success'
  82              : 'error';
  83  
  84          // Add feedback message.
  85          bp_core_add_message( $feedback, $type );
  86      }
  87  
  88      // Redirect.
  89      $member_notices = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() );
  90      $redirect_to    = trailingslashit( $member_notices . 'notices' );
  91  
  92      bp_core_redirect( $redirect_to );
  93  }
  94  add_action( 'bp_actions', 'bp_messages_action_edit_notice' );
  95  
  96  /**
  97   * Handle user dismissal of sitewide notices.
  98   *
  99   * @since 9.0.0
 100   *
 101   * @return bool False on failure.
 102   */
 103  function bp_messages_action_dismiss_notice() {
 104  
 105      // Bail if not viewing a notice dismissal URL.
 106      if ( ! bp_is_messages_component() || ! bp_is_current_action( 'notices' ) || 'dismiss' !== sanitize_key( bp_action_variable( 0 ) ) ) {
 107          return false;
 108      }
 109  
 110      // Bail if the current user isn't logged in.
 111      if ( ! is_user_logged_in() ) {
 112          return false;
 113      }
 114  
 115      // Check the nonce.
 116      check_admin_referer( 'messages_dismiss_notice' );
 117  
 118      // Dismiss the notice.
 119      $success = bp_messages_dismiss_sitewide_notice();
 120  
 121      // User feedback.
 122      if ( $success ) {
 123          $feedback = __( 'Notice has been dismissed.', 'buddypress' );
 124          $type     = 'success';
 125      } else {
 126          $feedback = __( 'There was a problem dismissing the notice.', 'buddypress');
 127          $type     = 'error';
 128      }
 129  
 130      // Add feedback message.
 131      bp_core_add_message( $feedback, $type );
 132  
 133      // Redirect.
 134      $redirect_to = trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() );
 135  
 136      bp_core_redirect( $redirect_to );
 137  }
 138  add_action( 'bp_actions', 'bp_messages_action_dismiss_notice' );


Generated: Thu Nov 21 01:00:57 2024 Cross-referenced by PHPXref 0.7.1