diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php
index e8487a78f..5fb770878 100644
|
|
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 src/bp-activity/classes/class-bp-activity-activity.php src/bp-activity/classes/class-bp-activity-activity.php
index cf084c16f..c51ab747b 100644
|
|
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 | |
| 1192 | $function_args = func_get_args(); |
| 1193 | |
| 1194 | // Backward compatibility with old method of passing arguments. |
| 1195 | if ( ! is_array( $args ) || count( $function_args ) > 1 ) { |
| 1196 | _deprecated_argument( |
| 1197 | __METHOD__, |
| 1198 | '10.0.0', |
| 1199 | sprintf( |
| 1200 | /* translators: 1: the name of the method. 2: the name of the file. */ |
| 1201 | esc_html__( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), |
| 1202 | __METHOD__, |
| 1203 | __FILE__ |
| 1204 | ) |
| 1205 | ); |
| 1206 | |
| 1207 | $old_args_keys = array( |
| 1208 | 0 => 'user_id', |
| 1209 | 1 => 'component', |
| 1210 | 2 => 'type', |
| 1211 | 3 => 'item_id', |
| 1212 | 4 => 'secondary_item_id', |
| 1213 | 5 => 'action', |
| 1214 | 6 => 'content', |
| 1215 | 7 => 'date_recorded', |
| 1216 | ); |
| 1217 | |
| 1218 | $args = bp_core_parse_args_array( $old_args_keys, $function_args ); |
| 1219 | } |
| 1220 | |
1190 | 1221 | $bp = buddypress(); |
| 1222 | $r = bp_parse_args( |
| 1223 | $args, |
| 1224 | array( |
| 1225 | 'user_id' => false, |
| 1226 | 'component' => false, |
| 1227 | 'type' => false, |
| 1228 | 'item_id' => false, |
| 1229 | 'secondary_item_id' => false, |
| 1230 | 'action' => false, |
| 1231 | 'content' => false, |
| 1232 | 'date_recorded' => false, |
| 1233 | ) |
| 1234 | ); |
1191 | 1235 | |
1192 | 1236 | $where_args = false; |
1193 | 1237 | |
1194 | | if ( ! empty( $user_id ) ) { |
1195 | | $where_args[] = $wpdb->prepare( "user_id = %d", $user_id ); |
| 1238 | if ( ! empty( $r['user_id'] ) ) { |
| 1239 | $where_args[] = $wpdb->prepare( "user_id = %d", $r['user_id'] ); |
1196 | 1240 | } |
1197 | 1241 | |
1198 | | if ( ! empty( $component ) ) { |
1199 | | $where_args[] = $wpdb->prepare( "component = %s", $component ); |
| 1242 | if ( ! empty( $r['component'] ) ) { |
| 1243 | $where_args[] = $wpdb->prepare( "component = %s", $r['component'] ); |
1200 | 1244 | } |
1201 | 1245 | |
1202 | | if ( ! empty( $type ) ) { |
1203 | | $where_args[] = $wpdb->prepare( "type = %s", $type ); |
| 1246 | if ( ! empty( $r['type'] ) ) { |
| 1247 | $where_args[] = $wpdb->prepare( "type = %s", $r['type'] ); |
1204 | 1248 | } |
1205 | 1249 | |
1206 | | if ( ! empty( $item_id ) ) { |
1207 | | $where_args[] = $wpdb->prepare( "item_id = %d", $item_id ); |
| 1250 | if ( ! empty( $r['item_id'] ) ) { |
| 1251 | $where_args[] = $wpdb->prepare( "item_id = %d", $r['item_id'] ); |
1208 | 1252 | } |
1209 | 1253 | |
1210 | | if ( ! empty( $secondary_item_id ) ) { |
1211 | | $where_args[] = $wpdb->prepare( "secondary_item_id = %d", $secondary_item_id ); |
| 1254 | if ( ! empty( $r['secondary_item_id'] ) ) { |
| 1255 | $where_args[] = $wpdb->prepare( "secondary_item_id = %d", $r['secondary_item_id'] ); |
1212 | 1256 | } |
1213 | 1257 | |
1214 | | if ( ! empty( $action ) ) { |
1215 | | $where_args[] = $wpdb->prepare( "action = %s", $action ); |
| 1258 | if ( ! empty( $r['action'] ) ) { |
| 1259 | $where_args[] = $wpdb->prepare( "action = %s", $r['action'] ); |
1216 | 1260 | } |
1217 | 1261 | |
1218 | | if ( ! empty( $content ) ) { |
1219 | | $where_args[] = $wpdb->prepare( "content = %s", $content ); |
| 1262 | if ( ! empty( $r['content'] ) ) { |
| 1263 | $where_args[] = $wpdb->prepare( "content = %s", $r['content'] ); |
1220 | 1264 | } |
1221 | 1265 | |
1222 | | if ( ! empty( $date_recorded ) ) { |
1223 | | $where_args[] = $wpdb->prepare( "date_recorded = %s", $date_recorded ); |
| 1266 | if ( ! empty( $r['date_recorded'] ) ) { |
| 1267 | $where_args[] = $wpdb->prepare( "date_recorded = %s", $r['date_recorded'] ); |
1224 | 1268 | } |
1225 | 1269 | |
1226 | 1270 | if ( ! empty( $where_args ) ) { |
diff --git tests/phpunit/testcases/activity/class.BP_Activity_Activity.php tests/phpunit/testcases/activity/class.BP_Activity_Activity.php
index 154f390ca..e84674c18 100644
|
|
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 | |