Skip to:
Content

BuddyPress.org

Changeset 13467


Ignore:
Timestamp:
04/30/2023 07:54:12 AM (23 months ago)
Author:
imath
Message:

Improve how the BP_Akismet() class displays an activity history

When the Akismet plugin is active and is used to prevent BP Activity spams, each Activity item gets an Akismet history. This history is only generated for activities being posted once Akismet is on. As a result, there can be old activities with no history. To avoid potential PHP errors/notices, we need to verify the Activity Meta used to store the history is an array and has a time key.

As we are dealing with the latest history entry only, we do not need to sort the Activity Meta.

To display the activity history into its single WP Admin screen, we now need to use the time & message keys of the Activity Meta.

Props mystichrome

Fixes #8873 (11.0 branch)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/11.0/src/bp-activity/classes/class-bp-akismet.php

    r12694 r13467  
    644644        $history = BP_Akismet::get_activity_history( $item->id );
    645645
    646         if ( empty( $history ) )
    647             return;
    648 
    649         echo '<div class="akismet-history"><div>';
    650         /* translators: 1: the human diff time. 2: the akismet history data. */
    651         printf( _x( '%1$s &mdash; %2$s', 'x hours ago - akismet cleared this item', 'buddypress' ), '<span>' . bp_core_time_since( $history[2] ) . '</span>', esc_html( $history[1] ) );
    652         echo '</div></div>';
     646        if ( empty( $history ) ) {
     647            $message = '&mdash;';
     648        } else {
     649            /* translators: 1: the human diff time. 2: the akismet history data. */
     650            $message = sprintf( _x( '%1$s &mdash; %2$s', 'x hours ago - akismet cleared this item', 'buddypress' ), '<span>' . bp_core_time_since( $history['time'] ) . '</span>', esc_html( $history['message'] ) );
     651        }
     652
     653        printf( '<div class="akismet-history"><div>%s</div></div>', wp_kses( $message, array( 'span' => true ) ) );
    653654    }
    654655
     
    684685    public function get_activity_history( $activity_id = 0 ) {
    685686        $history = bp_activity_get_meta( $activity_id, '_bp_akismet_history' );
    686         if ( $history === false )
     687        if ( $history && is_array( $history ) && isset( $history['time'] ) ) {
     688            $history['time'] = (int) $history['time'];
     689        } else {
    687690            $history = array();
    688 
    689         // Sort it by the time recorded.
    690         usort( $history, 'akismet_cmp_time' );
     691        }
    691692
    692693        return $history;
Note: See TracChangeset for help on using the changeset viewer.