Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/29/2020 04:27:09 PM (5 years ago)
Author:
imath
Message:

Make sure activities requiring content are not inserted empty into db

The activity type activity_update requires a content. If it is not set (eg: this can happen after sanitization), the activity won't be inserted into the database. Plugin developers can use the bp_activity_type_requires_content filter to force the activity type their plugin generated to also require content.

Props oztaser

Fixes #8236

File:
1 edited

Legend:

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

    r12586 r12604  
    269269            } else {
    270270                if ( empty( $this->component ) ) {
    271                     $this->errors->add( 'bp_activity_missing_component' );
     271                    $this->errors->add( 'bp_activity_missing_component', __( 'You need to define a component parameter to insert activity.', 'buddypress' ) );
    272272                } else {
    273                     $this->errors->add( 'bp_activity_missing_type' );
     273                    $this->errors->add( 'bp_activity_missing_type', __( 'You need to define a type parameter to insert activity.', 'buddypress' ) );
    274274                }
     275
     276                return $this->errors;
     277            }
     278        }
     279
     280        /**
     281         * Use this filter to make the content of your activity required.
     282         *
     283         * @since 6.0.0
     284         *
     285         * @param bool   $value True if the content of the activity type is required.
     286         *                      False otherwise.
     287         * @param string $type  The type of the activity we are about to insert.
     288         */
     289        $type_requires_content = (bool) apply_filters( 'bp_activity_type_requires_content', $this->type === 'activity_update', $this->type );
     290        if ( $type_requires_content && ! $this->content ) {
     291            if ( 'bool' === $this->error_type ) {
     292                return false;
     293            } else {
     294                $this->errors->add( 'bp_activity_missing_content', __( 'Please enter some content to post.', 'buddypress' ) );
    275295
    276296                return $this->errors;
Note: See TracChangeset for help on using the changeset viewer.