Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/27/2024 07:16:17 PM (2 years ago)
Author:
espellcaste
Message:

Allow creating messages with non-empty content.

Use of the PHP empty function to check if the message content is empty is not ideal when creating a message. Update the logic to consider any string as non-empty.

Props emaralive, niftythree.

See #9175
Closes https://github.com/buddypress/buddypress/pull/330

File:
1 edited

Legend:

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

    r13890 r13986  
    5757        );
    5858
     59        // Check if the message content is empty.
     60        $content       = $r['content'];
     61        $empty_content = false;
     62
     63        // Any string is considered non-empty.
     64        if ( ! is_string( $content ) || '' === $content ) {
     65                $empty_content = true;
     66        }
     67
    5968        // Bail if no sender or no content.
    60         if ( empty( $r['sender_id'] ) || empty( $r['content'] ) ) {
     69        if ( empty( $r['sender_id'] ) || $empty_content ) {
    6170                if ( 'wp_error' === $r['error_type'] ) {
    6271                        if ( empty( $r['sender_id'] ) ) {
     
    6978
    7079                        return new WP_Error( $error_code, $feedback );
    71 
    72                 } else {
    73                         return false;
    74                 }
     80                }
     81
     82                return false;
    7583        }
    7684
Note: See TracChangeset for help on using the changeset viewer.