Skip to:
Content

BuddyPress.org

Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#2674 closed enhancement (fixed)

bp-activity-classes.php: add a sql statements filter

Reported by: aesqe's profile aesqe Owned by:
Milestone: 1.5 Priority: trivial
Severity: Version:
Component: Activity Keywords: filter
Cc: aesqe@…

Description

in file "activity/bp-activity-classes.php", line 123, could someone please add a filter for the SQL WHERE statements?

something like this:

$where_sql = 'WHERE ' . join( ' AND ', apply_filters("bp_activity_get_where_conditions", $where_conditions));

thanks :)

Change History (8)

#1 @paulhastings0
14 years ago

...eh... too many people have been testing the current RC. I think we should punt this to 1.3.

#2 @DJPaul
14 years ago

  • Milestone changed from 1.2.6 to 1.3

Punting to 1.3 pending review

#3 @aesqe
14 years ago

might be better if the whole string could be filtered, with $where_conditions included as second argument:

$where_sql = apply_filters("bp_activity_get_where_conditions", 'WHERE ' . join(' AND ', $where_conditions), $where_conditions );

#4 follow-up: @DJPaul
14 years ago

Fixed in [3617]

#5 @DJPaul
14 years ago

  • Resolution set to fixed
  • Status changed from new to closed

#6 in reply to: ↑ 4 @aesqe
14 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Thanks DJPaul, but a filter on $where_sql, before all the DB queries are performed, would be of much more use to me :/ Any chance you could add another filter just for $where_sql? It's used both in fetching $activities and $total_activities_sql and it would save me from using preg_replace on the whole SQL statement.

I hope I'm not asking too much :)

#7 follow-up: @DJPaul
13 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

These queries are typically built from associative arrays, which are passed to these filters. You can either preg_replace the main query, or re-construct the query from the entire array, customising as necessary. It's not appropriate for a specialised filter just for the 'where' part of the statement, because someone may turn around and ask for the same for the 'limit' part, and so on.

#8 in reply to: ↑ 7 @aesqe
13 years ago

Replying to DJPaul:

These queries are typically built from associative arrays, which are passed to these filters.

Maybe I'm looking at the wrong thing, but in the trunk version of bp-activity-classes.php, $where_sql is not passed to the 'bp_activity_get_user_join_filter':

$wpdb->get_results(
	apply_filters(
		'bp_activity_get_user_join_filter',
		$wpdb->prepare(
			"{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}", 
			$select_sql, $from_sql, $where_sql, $sort, $pag_sql
		)
	)
);

if it were passed to the filter, that's all I would need :)

anyhow, the code above looks kind of wrong, are you sure it's not supposed to be:

$wpdb->get_results(
	apply_filters(
		'bp_activity_get_user_join_filter',
		$wpdb->prepare(
			"%s %s %s ORDER BY a.date_recorded %s %s", 
			$select_sql, $from_sql, $where_sql, $sort, $pag_sql
		),
		$select_sql, $from_sql, $where_sql, $sort, $pag_sql
	)
);

or

$wpdb->get_results(
	apply_filters(
		'bp_activity_get_user_join_filter',
		"{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}", 
		$select_sql, $from_sql, $where_sql, $sort, $pag_sql
	)
);

(and I apologize in advance if I'm misreading something :|)

Note: See TracTickets for help on using tickets.