[buddypress-trac] [BuddyPress Trac] #7343: Add the_group filter to allow group object modification
buddypress-trac
noreply at wordpress.org
Wed May 3 21:08:32 UTC 2017
#7343: Add the_group filter to allow group object modification
--------------------------+----------------------------------
Reporter: ninjew | Owner: dcavins
Type: enhancement | Status: accepted
Priority: normal | Milestone: Under Consideration
Component: Groups | Version:
Severity: normal | Resolution:
Keywords: dev-feedback |
--------------------------+----------------------------------
Comment (by ninjew):
Hello @dcavins and @boonebgorges,
I apologize for missing out the previous reply.
Having an action hook ( ex. do_action( 'bp_groups_group', $this ); )
inside BP_Groups_Group::populate() would be a great solution ( for my case
at least ) if it will allow to add custom data to the group object.
I will try explain my scenario in short:
My geolocation plugin ( GEO my WP ) allows geotagging posts, groups,
members and so on. GEO my WP saves the geolocation information in a custom
table in database. data like address fields, coordinates, object_type (
post, user, group...), object_id ( to relate to the object it belongs to )
and more.
GEO my WP also has a forms builder for admins to build custom proximity
search forms. The forms can search for geotagged data ( posts, members,
groups... ) based on address, radius and other filters. For these forms,
GEO my WP uses the native search query class/function of each object, for
example, WP_Query, bp_has_memebrs(), bp_has_groups(), and modify it to
display results nearby.
GEO my WP forms made of search form and search results template files. The
search results template file contains the original object loop and its
functions, with additional custom functions to display distance, maps, and
other location data.
This is http://demo.geomywp.com/buddypress-members-search-form a demo for
Members search form and http://demo.geomywp.com/search-post-type-with-
categories/ Posts search form created by GEO my WP.
The current version of GEO my WP modifies the main search query in the
FIELDS clause and by adding a JOIN clause to join the locations table and
modify the results by location. Doing so, the results already contains the
location data per object ( because of the FIELDS clause ). So the $post,
$memebr and $group object will have address fields and coords added to it,
which could then be used in the loop. This makes it easy to use the
different functions in the loop.
In new version of GEO my WP that I have been working on, I changed the way
the plugin modify the search queries. Mainly because of the issue
discussed in ticket:7290, but also because it is easier to maintain and
cache. Now the plugin first does the proximity search query on the
location table only to retrieve a list of locations, when each location
contains the location data and the object ID. Then it passes the locations
ID as an array into the "include" argument of the search query ( WP_Query,
bp_has_members().... ), which works well and returns only nearby objects.
However, now the location data is not included in the object results.
Rather, we end up with 2 objects; One contains the objects data and
another contains the locations.
With the new way of querying the locations I need to merge the location
data with each object before it "enters" the results loop. Which is easy
to do for the $post object using the "the_post" filter, but not for
$member or $group. For members and groups I now need to run an additional
custom loop before the results loop to merge the objects with the
locations. This additional loop is not only a waste of memory and
performance, but it also ends up adding the location data into each
object, which is what we are trying to prevent by not having a filter
similar to "the_post".
( Well, this wasn't as short as I wanted it to be :) )
I hope this is not too confusing and that it makes sense.
--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/7343#comment:8>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac
More information about the buddypress-trac
mailing list