Skip to:
Content

BuddyPress.org

Changeset 13466


Ignore:
Timestamp:
04/30/2023 07:40:12 AM (17 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

See #8873 (trunk)
Closes https://github.com/buddypress/buddypress/pull/93

File:
1 edited

Legend:

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

    r13436 r13466  
    668668        $history = BP_Akismet::get_activity_history( $item->id );
    669669
    670         if ( empty( $history ) )
    671             return;
    672 
    673         echo '<div class="akismet-history"><div>';
    674         /* translators: 1: the human diff time. 2: the akismet history data. */
    675         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] ) );
    676         echo '</div></div>';
     670        if ( empty( $history ) ) {
     671            $message = '&mdash;';
     672        } else {
     673            /* translators: 1: the human diff time. 2: the akismet history data. */
     674            $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'] ) );
     675        }
     676
     677        printf( '<div class="akismet-history"><div>%s</div></div>', wp_kses( $message, array( 'span' => true ) ) );
    677678    }
    678679
     
    708709    public function get_activity_history( $activity_id = 0 ) {
    709710        $history = bp_activity_get_meta( $activity_id, '_bp_akismet_history' );
    710         if ( $history === false )
     711        if ( $history && is_array( $history ) && isset( $history['time'] ) ) {
     712            $history['time'] = (int) $history['time'];
     713        } else {
    711714            $history = array();
    712 
    713         // Sort it by the time recorded.
    714         usort( $history, 'akismet_cmp_time' );
     715        }
    715716
    716717        return $history;
Note: See TracChangeset for help on using the changeset viewer.