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 = '' ) { |
2861 | 2861 | * @param array $r Parsed function arguments. |
2862 | 2862 | * @param array $args Arguments passed to the function. |
2863 | 2863 | */ |
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 ); |
2874 | 2865 | } |
2875 | 2866 | |
2876 | 2867 | /** |
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 { |
1171 | 1171 | * Get the first activity ID that matches a set of criteria. |
1172 | 1172 | * |
1173 | 1173 | * @since 1.2.0 |
| 1174 | * @since 10.0.0 Parameters were made optional. |
1174 | 1175 | * |
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 | * } |
1185 | 1187 | * @return int|false Activity ID on success, false if none is found. |
1186 | 1188 | */ |
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 = '' ) { |
1188 | 1190 | global $wpdb; |
1189 | 1191 | |
1190 | 1192 | $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 | ); |
1191 | 1206 | |
1192 | 1207 | $where_args = false; |
1193 | 1208 | |
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'] ); |
1196 | 1211 | } |
1197 | 1212 | |
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'] ); |
1200 | 1215 | } |
1201 | 1216 | |
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'] ); |
1204 | 1219 | } |
1205 | 1220 | |
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'] ); |
1208 | 1223 | } |
1209 | 1224 | |
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'] ); |
1212 | 1227 | } |
1213 | 1228 | |
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'] ); |
1216 | 1231 | } |
1217 | 1232 | |
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'] ); |
1220 | 1235 | } |
1221 | 1236 | |
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'] ); |
1224 | 1239 | } |
1225 | 1240 | |
1226 | 1241 | if ( ! empty( $where_args ) ) { |
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 { |
464 | 464 | 'item_id' => 1888, |
465 | 465 | ) ); |
466 | 466 | |
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 ); |
468 | 472 | $this->assertEquals( $a1, $activity ); |
469 | 473 | } |
470 | 474 | |
… |
… |
class BP_Tests_Activity_Class extends BP_UnitTestCase { |
479 | 483 | 'secondary_content' => 1888, |
480 | 484 | ) ); |
481 | 485 | |
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 ); |
483 | 491 | $this->assertEquals( $a1, $activity ); |
484 | 492 | } |
485 | 493 | |