Skip to:
Content
Pages
Categories
Search
Top
Bottom

Modifying BP Class output with an add_action function


  • Dickson Waudo
    Participant

    @dicksonmedia

    I have been developing this plugin for a while now, and was actually running until the new version of BP came out, then alot of thins broke. But mostly it was my poor coding. I hard coded changes in BP and on upgrade VOILA!! I knew that. So anyway moving on and getting alot better at WP and BP plugin development. I have made my plugins more BP and WP aware when possible and also theme aware.

    I am trying to slightly modify the out put of the bp_has_groups template tag by adding an extra SQL query to the BP_Groups_Groups:get_active function. I have easily modified out put of functions outside the BP Objected Oriented classes with “add_action” But I am having difficulty doing the same for functions called inside the BP classes.

    currently (and this works) I have the coded appended to the bottom of the get_active function
    ` if ( $bp->current_component == $bp->schools->slug && !empty($bp->current_action ) && !empty($bp->action_variables[0] ) && !empty($bp->action_variables[1] ) ){

    $browse_sql = “AND m.city_id = ‘$city_id'”;
    $paged_groups = $wpdb->get_results( “SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->schools->table_name} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = ‘last_activity’ AND gm1.meta_key = ‘total_member_count’ {$browse_sql} {$hidden_sql} {$search_sql} ORDER BY last_activity DESC {$pag_sql}” );
    $total_groups = $wpdb->get_var( “SELECT COUNT(DISTINCT m.group_id) FROM {$bp->schools->table_name} m LEFT JOIN {$bp->groups->table_name_groupmeta} gm ON m.group_id = gm.group_id INNER JOIN {$bp->groups->table_name} g ON m.group_id = g.id WHERE gm.meta_key = ‘last_activity’ {$browse_sql} {$hidden_sql} {$search_sql} ” );

    }`

    On future upgrades this little line will be overwritten (I have a handy dandy copy to put it right back) but I’d rather not especially if I will be releasing this to the public.

    I would like some help in getting this into a function and calling that function using the
    `add_action( $tag, $function_to_add, $priority, $accepted_args );`

    From the W Codex
    $function_to_add
    (callback) (required) The name of the function you wish to be called. Note: any of the syntaxes explained in the PHP documentation for the ‘callback’ type are valid.
    Default: None

    Am hoping @travel-junkie cna check this out, he’s been a great help before. Any help is appreciated

Viewing 6 replies - 1 through 6 (of 6 total)
  • seems in this special case you want an apply_filters in place of the {$browse_sql} var, then at least you can move the logic and sql code to that called function.

    though you will always need to copy it back during any upgrade since it is a core file – you could create your own patch file to run each time


    Dickson Waudo
    Participant

    @dicksonmedia

    @nuprn1 thats a nice idea, I don’t know about the apply_filter though. the `$browse_sql` var is a new var that I initiate in just that function and within the scope of the if statement. Reasons being I added a whole other table to be queried in `$paged_groups` and `$total_groups` array being returned by the `get_active` function.

    Its a small line of code, easily replaced on upgrade and works perfectly fine for me right now, I just wanted to be able to access, append/modify and object oriented class function from an outside function (that doesn’t make sense) lol. Something like whatever I have in my what if statement gets its own function and the arguments from the get_active function and processes my query after get active is complete (sorta), its not a private function so I can access it outside the BP_Groups_Group class, just don’t know how I can do an add_action or an apply_filter


    r-a-y
    Keymaster

    @r-a-y

    If you’re making a change to BP_Groups_Groups:get_active(), I would recommend doing what Rich says and coding an alternative group get function by filtering “groups_get_groups” (available in the groups_get_groups() function in bp-groups.php).

    That way, you won’t have to hack the bp-groups-classes.php file in the future. It is more work, but it’s up to you.


    Dickson Waudo
    Participant

    @dicksonmedia

    @r-a-y Thats sounds a little better, I thought I would have to filter the `bp_has_groups` function, I guess I didn’t quite figure the code out. I’ll try that. Thank you everybody let you know how it goes


    Dickson Waudo
    Participant

    @dicksonmedia

    @nuprn1 @r-a-y Just a little update,

    Finally got around to it, actually the lastest Buddypress update kinda forced me to and it worked like a charm. I had to educate my self on wordpress’s apply_filters and add_filters.

    I wrote a custum function that filtered the results of the groups_get_groups function, basically removing my “handy dandy” code from the core files into my cutome plugin class file. Thanks for all your help.


    r-a-y
    Keymaster

    @r-a-y

    Good to know you figured it out!
    BuddyPress has forced me to learn a lot more about WordPress as well. A win-win!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Modifying BP Class output with an add_action function’ is closed to new replies.
Skip to toolbar