Skip to:
Content

BuddyPress.org

Ticket #8596: 8596.patch

File 8596.patch, 5.9 KB (added by oztaser, 3 years ago)
  • src/bp-activity/bp-activity-functions.php

    diff --git a/src/bp-activity/bp-activity-functions.php b/src/bp-activity/bp-activity-functions.php
    index e8487a78f..5fb770878 100644
    a b function bp_activity_get_activity_id( $args = '' ) { 
    28612861         * @param array                $r     Parsed function arguments.
    28622862         * @param array                $args  Arguments passed to the function.
    28632863         */
    2864         return apply_filters( 'bp_activity_get_activity_id', BP_Activity_Activity::get_id(
    2865                 $r['user_id'],
    2866                 $r['component'],
    2867                 $r['type'],
    2868                 $r['item_id'],
    2869                 $r['secondary_item_id'],
    2870                 $r['action'],
    2871                 $r['content'],
    2872                 $r['date_recorded']
    2873         ), $r, $args );
     2864        return apply_filters( 'bp_activity_get_activity_id', BP_Activity_Activity::get_id( $r ), $r, $args );
    28742865}
    28752866
    28762867/**
  • src/bp-activity/classes/class-bp-activity-activity.php

    diff --git a/src/bp-activity/classes/class-bp-activity-activity.php b/src/bp-activity/classes/class-bp-activity-activity.php
    index cf084c16f..67065853d 100644
    a b class BP_Activity_Activity { 
    11711171         * Get the first activity ID that matches a set of criteria.
    11721172         *
    11731173         * @since 1.2.0
     1174         * @since 10.0.0 Parameters were made optional.
    11741175         *
    1175          * @todo Should parameters be optional?
    1176          *
    1177          * @param int    $user_id           User ID to filter by.
    1178          * @param string $component         Component to filter by.
    1179          * @param string $type              Activity type to filter by.
    1180          * @param int    $item_id           Associated item to filter by.
    1181          * @param int    $secondary_item_id Secondary associated item to filter by.
    1182          * @param string $action            Action to filter by.
    1183          * @param string $content           Content to filter by.
    1184          * @param string $date_recorded     Date to filter by.
     1176         * @param string|array $args {
     1177         *     An array of arguments. All items are optional.
     1178         *     @type int    $user_id           User ID to filter by.
     1179         *     @type string $component         Component to filter by.
     1180         *     @type string $type              Activity type to filter by.
     1181         *     @type int    $item_id           Associated item to filter by.
     1182         *     @type int    $secondary_item_id Secondary associated item to filter by.
     1183         *     @type string $action            Action to filter by.
     1184         *     @type string $content           Content to filter by.
     1185         *     @type string $date_recorded     Date to filter by.
     1186         * }
    11851187         * @return int|false Activity ID on success, false if none is found.
    11861188         */
    1187         public static function get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) {
     1189        public static function get_id( $args = '' ) {
    11881190                global $wpdb;
    11891191
    11901192                $bp = buddypress();
     1193                $r  = bp_parse_args(
     1194                        $args,
     1195                        array(
     1196                                'user_id'           => false,
     1197                                'component'         => false,
     1198                                'type'              => false,
     1199                                'item_id'           => false,
     1200                                'secondary_item_id' => false,
     1201                                'action'            => false,
     1202                                'content'           => false,
     1203                                'date_recorded'     => false,
     1204                        )
     1205                );
    11911206
    11921207                $where_args = false;
    11931208
    1194                 if ( ! empty( $user_id ) ) {
    1195                         $where_args[] = $wpdb->prepare( "user_id = %d", $user_id );
     1209                if ( ! empty( $r['user_id'] ) ) {
     1210                        $where_args[] = $wpdb->prepare( "user_id = %d", $r['user_id'] );
    11961211                }
    11971212
    1198                 if ( ! empty( $component ) ) {
    1199                         $where_args[] = $wpdb->prepare( "component = %s", $component );
     1213                if ( ! empty( $r['component'] ) ) {
     1214                        $where_args[] = $wpdb->prepare( "component = %s", $r['component'] );
    12001215                }
    12011216
    1202                 if ( ! empty( $type ) ) {
    1203                         $where_args[] = $wpdb->prepare( "type = %s", $type );
     1217                if ( ! empty( $r['type'] ) ) {
     1218                        $where_args[] = $wpdb->prepare( "type = %s", $r['type'] );
    12041219                }
    12051220
    1206                 if ( ! empty( $item_id ) ) {
    1207                         $where_args[] = $wpdb->prepare( "item_id = %d", $item_id );
     1221                if ( ! empty( $r['item_id'] ) ) {
     1222                        $where_args[] = $wpdb->prepare( "item_id = %d", $r['item_id'] );
    12081223                }
    12091224
    1210                 if ( ! empty( $secondary_item_id ) ) {
    1211                         $where_args[] = $wpdb->prepare( "secondary_item_id = %d", $secondary_item_id );
     1225                if ( ! empty( $r['secondary_item_id'] ) ) {
     1226                        $where_args[] = $wpdb->prepare( "secondary_item_id = %d", $r['secondary_item_id'] );
    12121227                }
    12131228
    1214                 if ( ! empty( $action ) ) {
    1215                         $where_args[] = $wpdb->prepare( "action = %s", $action );
     1229                if ( ! empty( $r['action'] ) ) {
     1230                        $where_args[] = $wpdb->prepare( "action = %s", $r['action'] );
    12161231                }
    12171232
    1218                 if ( ! empty( $content ) ) {
    1219                         $where_args[] = $wpdb->prepare( "content = %s", $content );
     1233                if ( ! empty( $r['content'] ) ) {
     1234                        $where_args[] = $wpdb->prepare( "content = %s", $r['content'] );
    12201235                }
    12211236
    1222                 if ( ! empty( $date_recorded ) ) {
    1223                         $where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded );
     1237                if ( ! empty( $r['date_recorded'] ) ) {
     1238                        $where_args[] = $wpdb->prepare( "date_recorded = %s", $r['date_recorded'] );
    12241239                }
    12251240
    12261241                if ( ! empty( $where_args ) ) {
  • tests/phpunit/testcases/activity/class.BP_Activity_Activity.php

    diff --git a/tests/phpunit/testcases/activity/class.BP_Activity_Activity.php b/tests/phpunit/testcases/activity/class.BP_Activity_Activity.php
    index 154f390ca..e84674c18 100644
    a b class BP_Tests_Activity_Class extends BP_UnitTestCase { 
    464464                        'item_id' => 1888,
    465465                ) );
    466466
    467                 $activity = BP_Activity_Activity::get_id( false, false, false, 523, false, false, false, false );
     467                $args = array(
     468                        'item_id' => 523,
     469                );
     470
     471                $activity = BP_Activity_Activity::get_id( $args );
    468472                $this->assertEquals( $a1, $activity );
    469473        }
    470474
    class BP_Tests_Activity_Class extends BP_UnitTestCase { 
    479483                        'secondary_content' => 1888,
    480484                ) );
    481485
    482                 $activity = BP_Activity_Activity::get_id( false, false, false, false, 523, false, false, false );
     486                $args = array(
     487                        'secondary_item_id' => 523,
     488                );
     489
     490                $activity = BP_Activity_Activity::get_id( $args );
    483491                $this->assertEquals( $a1, $activity );
    484492        }
    485493