Forum Replies Created
-
Resolved. Turns out WordPress page conditionals are not true during ajax requests. You can create conditionals using wp_get_referer() as a workaround. I created my own conditional, if anyone wants to create a page conditional to filter a custom activity loop with the parse args filter, here is a good starting point:
//for page 'test-1' unction bp6801_is_test_1_page() { $is_test_1_page = false; if ( is_page( 'test-1' ) ) { $is_test_1_page = true; } elseif ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { $referer_page_id = url_to_postid( wp_get_referer() ); $referer_page = get_post( $referer_page_id ); if ( $referer_page instanceof WP_Post && 'test-1' === $referer_page->post_name ) { $is_test_1_page = true; } } return $is_test_1_page; }
Thanks Henry. I’ve got more info on this to help the core team fix this issue.
I think all WordPress conditionals are not working correctly inside the bp_after_has_activities_parse_args filter. Only BuddyPress conditionals are working inside it.
I also have custom member pages too using bp_after_has_members_parse_args, but WordPress conditionals inside that are all working fine, example:
// filter member pages function cm_members_filter( $retval ) { if ( is_page('custom-page-3') ) { $retval['per_page'] = 1; } if ( is_page('custom-page-4') ) { $retval['per_page'] = 5; } if ( is_search() ) { $retval['per_page'] = 3; } return $retval; } add_filter( 'bp_after_has_members_parse_args', 'cm_members_filter' );
It is just the activity parse args that is having problems with WordPress conditionals. I can provide further info to help figure out why WordPress conditionals don’t work correctly inside bp_after_has_activities_parse_args, it has something to do with the way ajax is used on the load more button to load more items:
If I remove activity ajax features by removing <div class=”activity”></div> or by removing bp-templates/bp-legacy/js/buddypress.min.js. The load more button now works like a pagination next page button (similar to the members directory pagination). This makes the WordPress conditionals work fine and all my custom activity pages are now filtering correctly.
So to conclude, WordPress conditionals are working OK inside bp_after_has_members_parse_args, but they are not working correctly inside bp_after_has_activities_parse_args unless the activity ajax is removed.
Thanks shanebp. I just found out the plugin was updated 8 months ago on GitHub to allow for this:
https://github.com/r-a-y/buddypress-followers/commit/be48a8ee7d1baa0b3cf73f98597c3c12ff3e16b3
But for some reason they haven’t updated the plugin in the WordPress.org plugin directory for over a year.
That did it.
I was looking for a while how to do this but I must of missed that page.
Thanks @shanebp
I’ve almost got it working:
function cm_load_template_filter() { bp_register_template_stack( 'cm_get_template_location'); } add_filter( 'bp_located_template', 'cm_load_template_filter'); function cm_get_template_location() { return dirname( __FILE__ ) . '/templates/'; }
This works most of the time but it doesn’t work in a few areas such as when I click load more to load more activity items. What else do I need to do to add to this code?
This one is probably better:
function profile_target_blank( $field_value, $field_type, $field_id ){ if($field_type == 'url') { $field_value = str_replace('rel="nofollow"', 'rel="nofollow" target="_blank"', $field_value); } return $field_value; } add_filter('bp_get_the_profile_field_value', 'profile_target_blank', 11, 3);
You need to add the target=”_blank” attribute to the profile field value anchors.
I think the best way to do this is by using str_replace. Add this to your functions.php or bp-custom.php
function profile_target_blank( $field_value, $field_type, $field_id ){ $field_value = str_replace('rel="nofollow"', 'rel="nofollow" target="_blank"', $field_value); return $field_value; } add_filter('bp_get_the_profile_field_value', 'profile_target_blank', 11, 3);
I’ve tested this and it works. This should open a new browser window/tab for all profile fields that have a URL’s.