Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/01/2016 09:00:21 PM (10 years ago)
Author:
r-a-y
Message:

Activity: Introduce error handling to the BP_Activity_Activity class.

To support frontend user messages for activity failures, we need the
ability to add errors.

This commit:

  • Introduces the $errors object and $error_type property to the BP_Activity_Activity class.
  • Adds an 'error_type' parameter to all applicable, activity functions.
  • Modifies bp-legacy to output an error message for activity failures.

See #6719.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/classes/class-bp-activity-activity.php

    r10853 r10858  
    135135
    136136        /**
     137         * Error holder.
     138         *
     139         * @since 2.6.0
     140         *
     141         * @var WP_Error
     142         */
     143        public $errors;
     144
     145        /**
     146         * Error type to return. Either 'bool' or 'wp_error'.
     147         *
     148         * @since 2.6.0
     149         *
     150         * @var string
     151         */
     152        public $error_type = 'bool';
     153
     154        /**
    137155         * Constructor method.
    138156         *
     
    142160         */
    143161        public function __construct( $id = false ) {
     162                // Instantiate errors object.
     163                $this->errors = new WP_Error;
     164
    144165                if ( !empty( $id ) ) {
    145166                        $this->id = (int) $id;
     
    236257                do_action_ref_array( 'bp_activity_before_save', array( &$this ) );
    237258
     259                if ( 'wp_error' === $this->error_type && $this->errors->get_error_code() ) {
     260                        return $this->errors;
     261                }
     262
    238263                if ( empty( $this->component ) || empty( $this->type ) ) {
    239                         return false;
     264                        if ( 'bool' === $this->error_type ) {
     265                                return false;
     266                        } else {
     267                                if ( empty( $this->component ) ) {
     268                                        $this->errors->add( 'bp_activity_missing_component' );
     269                                } else {
     270                                        $this->errors->add( 'bp_activity_missing_type' );
     271                                }
     272
     273                                return $this->errors;
     274                        }
    240275                }
    241276
Note: See TracChangeset for help on using the changeset viewer.