Skip to:
Content

BuddyPress.org

Ticket #6714: 6714.01.patch

File 6714.01.patch, 2.9 KB (added by dcavins, 4 years ago)

Example of new params in bp_core_add_message.

  • src/bp-core/bp-core-functions.php

    diff --git src/bp-core/bp-core-functions.php src/bp-core/bp-core-functions.php
    index 280f371..1160190 100644
    function bp_core_time_since( $older_date, $newer_date = false ) { 
    12741274 * @param string $message Feedback message to be displayed.
    12751275 * @param string $type    Message type. 'updated', 'success', 'error', 'warning'.
    12761276 *                        Default: 'success'.
     1277 * @param string $context Why is this message happening?
     1278 * @param array  $args    Message args when helpful.
    12771279 */
    1278 function bp_core_add_message( $message, $type = '' ) {
     1280function bp_core_add_message( $message, $type = '', $context = '', $args = array() ) {
    12791281
    12801282        // Success is the default
    12811283        if ( empty( $type ) ) {
    12821284                $type = 'success';
    12831285        }
    12841286
     1287        // Allow filters to interact with the $message and $type values.
     1288        $message = apply_filters( 'bp_core_add_message_message', $message, $type, $context, $args );
     1289        $type    = apply_filters( 'bp_core_add_message_type', $type, $message, $context, $args );
     1290
    12851291        // Send the values to the cookie for page reload display
    12861292        @setcookie( 'bp-message',      $message, time() + 60 * 60 * 24, COOKIEPATH );
    12871293        @setcookie( 'bp-message-type', $type,    time() + 60 * 60 * 24, COOKIEPATH );
  • src/bp-xprofile/bp-xprofile-screens.php

    diff --git src/bp-xprofile/bp-xprofile-screens.php src/bp-xprofile/bp-xprofile-screens.php
    index fa42da5..e0fd1e8 100644
    function xprofile_screen_edit_profile() { 
    106106
    107107                // There are errors.
    108108                if ( !empty( $errors ) ) {
    109                         bp_core_add_message( __( 'Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress' ), 'error' );
     109                        bp_core_add_message( __( 'Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress' ), 'error', 'saving_profile_field_group', array( 'updated_profile_field_group' => bp_action_variable( 1 ), 'reason' => 'required_fields_missing' ) );
    110110
    111111                // No errors.
    112112                } else {
    function xprofile_screen_edit_profile() { 
    172172
    173173                        // Set the feedback messages.
    174174                        if ( !empty( $errors ) ) {
    175                                 bp_core_add_message( __( 'There was a problem updating some of your profile information. Please try again.', 'buddypress' ), 'error' );
     175                                bp_core_add_message( __( 'There was a problem updating some of your profile information. Please try again.', 'buddypress' ), 'error', 'saving_profile_field_group', array( 'updated_profile_field_group' => bp_action_variable( 1 ), 'reason' => 'field_failed_to_save' ) );
    176176                        } else {
    177                                 bp_core_add_message( __( 'Changes saved.', 'buddypress' ) );
     177                                bp_core_add_message( __( 'Changes saved.', 'buddypress' ), 'success', 'saving_profile_field_group', array( 'updated_profile_field_group' => bp_action_variable( 1 ) ) );
    178178                        }
    179179
    180180                        // Redirect back to the edit screen to display the updates and message.