Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/15/2015 11:54:42 PM (11 years ago)
Author:
johnjamesjacoby
Message:

Messages: Separate actions from screen functions

This change extracts action-specific functionality from 2 message specific screen functions (per the component coding standards) by introducing two new functions in bp-messages-actions.php and hooking them to bp_actions. These new functions handle the creation of new private messages and notices, and the editing & deletion of existing notices.

A few additional improvements were also made to these functionalities:

  • String improvements to provide additional clarity to site members performing message related actions
  • Code scrutinization and documentation improvements to better understand what these functions are for and when they were introduced
  • Updates to new helper functions introduced since these functions were first introduced and last updated

Fixes #6505 (in trunk, for 2.4)

File:
1 edited

Legend:

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

    r9946 r9947  
    1717/**
    1818 * Load the Messages > Inbox screen.
     19 *
     20 * @since BuddyPress (1.0.0)
    1921 */
    2022function messages_screen_inbox() {
     23
    2124    if ( bp_action_variables() ) {
    2225        bp_do_404();
     
    4346/**
    4447 * Load the Messages > Sent screen.
     48 *
     49 * @since BuddyPress (1.0.0)
    4550 */
    4651function messages_screen_sentbox() {
     52
    4753    if ( bp_action_variables() ) {
    4854        bp_do_404();
     
    6975/**
    7076 * Load the Messages > Compose screen.
     77 *
     78 * @since BuddyPress (1.0.0)
    7179 */
    7280function messages_screen_compose() {
     
    8088    messages_remove_callback_values();
    8189
    82     // Check if the message form has been submitted
    83     if ( isset( $_POST['send'] ) ) {
    84 
    85         // Check the nonce
    86         check_admin_referer( 'messages_send_message' );
    87 
    88         // Check we have what we need
    89         if ( empty( $_POST['subject'] ) || empty( $_POST['content'] ) ) {
    90             bp_core_add_message( __( 'There was an error sending that message. Please try again.', 'buddypress' ), 'error' );
    91         } else {
    92             // If this is a notice, send it
    93             if ( isset( $_POST['send-notice'] ) ) {
    94                 if ( messages_send_notice( $_POST['subject'], $_POST['content'] ) ) {
    95                     bp_core_add_message( __( 'Notice sent successfully!', 'buddypress' ) );
    96                     bp_core_redirect( bp_loggedin_user_domain() . bp_get_messages_slug() . '/inbox/' );
    97                 } else {
    98                     bp_core_add_message( __( 'There was an error sending that notice. Please try again.', 'buddypress' ), 'error' );
    99                 }
    100             } else {
    101                 // Filter recipients into the format we need - array( 'username/userid', 'username/userid' )
    102                 $autocomplete_recipients = explode( ',', $_POST['send-to-input'] );
    103                 $typed_recipients        = explode( ' ', $_POST['send_to_usernames'] );
    104                 $recipients              = array_merge( (array) $autocomplete_recipients, (array) $typed_recipients );
    105 
    106                 /**
    107                  * Filters the array of recipients to receive the composed message.
    108                  *
    109                  * @since BuddyPress (1.2.10)
    110                  *
    111                  * @param array $recipients Array of recipients to receive message.
    112                  */
    113                 $recipients              = apply_filters( 'bp_messages_recipients', $recipients );
    114                 $thread_id               = messages_new_message( array(
    115                     'recipients' => $recipients,
    116                     'subject'    => $_POST['subject'],
    117                     'content'    => $_POST['content']
    118                 ) );
    119 
    120                 // Send the message
    121                 if ( ! empty( $thread_id ) ) {
    122                     bp_core_add_message( __( 'Message sent successfully!', 'buddypress' ) );
    123                     bp_core_redirect( bp_loggedin_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id . '/' );
    124                 } else {
    125                     bp_core_add_message( __( 'There was an error sending that message. Please try again.', 'buddypress' ), 'error' );
    126                 }
    127             }
    128         }
    129     }
    130 
    13190    /**
    13291     * Fires right before the loading of the Messages compose screen template file.
     
    149108 * Load an individual conversation screen.
    150109 *
     110 * @since BuddyPress (1.0.0)
     111 *
    151112 * @return bool|null False on failure.
    152113 */
     
    154115
    155116    // Bail if not viewing a single message
    156     if ( !bp_is_messages_component() || !bp_is_current_action( 'view' ) ) {
     117    if ( ! bp_is_messages_component() || ! bp_is_current_action( 'view' ) ) {
    157118        return false;
    158119    }
     
    160121    $thread_id = (int) bp_action_variable( 0 );
    161122
    162     if ( empty( $thread_id ) || !messages_is_valid_thread( $thread_id ) || ( !messages_check_thread_access( $thread_id ) && !bp_current_user_can( 'bp_moderate' ) ) ) {
     123    if ( empty( $thread_id ) || ! messages_is_valid_thread( $thread_id ) || ( ! messages_check_thread_access( $thread_id ) && ! bp_current_user_can( 'bp_moderate' ) ) ) {
    163124        bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() ) );
    164125    }
     
    191152 * Load the Messages > Notices screen.
    192153 *
     154 * @since BuddyPress (1.0.0)
     155 *
    193156 * @return false|null False on failure.
    194157 */
    195158function messages_screen_notices() {
    196     global $notice_id;
    197 
    198     $notice_id = (int) bp_action_variable( 1 );
    199 
    200     if ( !empty( $notice_id ) && is_numeric( $notice_id ) ) {
    201         $notice = new BP_Messages_Notice( $notice_id );
    202 
    203         if ( bp_is_action_variable( 'deactivate', 0 ) ) {
    204             if ( !$notice->deactivate() ) {
    205                 bp_core_add_message( __('There was a problem deactivating that notice.', 'buddypress'), 'error' );
    206             } else {
    207                 bp_core_add_message( __('Notice deactivated.', 'buddypress') );
    208             }
    209         } elseif ( bp_is_action_variable( 'activate', 0 ) ) {
    210             if ( !$notice->activate() ) {
    211                 bp_core_add_message( __('There was a problem activating that notice.', 'buddypress'), 'error' );
    212             } else {
    213                 bp_core_add_message( __('Notice activated.', 'buddypress') );
    214             }
    215         } elseif ( bp_is_action_variable( 'delete' ) ) {
    216             if ( !$notice->delete() ) {
    217                 bp_core_add_message( __('There was a problem deleting that notice.', 'buddypress'), 'buddypress' );
    218             } else {
    219                 bp_core_add_message( __('Notice deleted.', 'buddypress') );
    220             }
    221         }
    222         bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices' ) );
    223     }
    224159
    225160    if ( bp_action_variables() ) {
     
    247182/**
    248183 * Render the markup for the Messages section of Settings > Notifications.
     184 *
     185 * @since BuddyPress (1.0.0)
    249186 */
    250187function messages_screen_notification_settings() {
     188
    251189    if ( bp_action_variables() ) {
    252190        bp_do_404();
Note: See TracChangeset for help on using the changeset viewer.