Skip to content

Instantly share code, notes, and snippets.

@imath
Created August 26, 2014 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imath/5812cf545d54c6364078 to your computer and use it in GitHub Desktop.
Save imath/5812cf545d54c6364078 to your computer and use it in GitHub Desktop.
hashbuddy fix suggestion in reply to https://buddypress.trac.wordpress.org/ticket/5786
<?php
/**
* NB: Since 2.1 beta 1
*
* Activity Load Newest & Loadmore feature will transport
* search terms through ajax.
*
* @see https://buddypress.trac.wordpress.org/changeset/8817
*/
function hashbuddy_activity_hashtags_querystring( $query_string, $object ) {
// i think there's no need to get $bp global
// global $bp;
// Bail if not an activity query string
if ( 'activity' != $object ) {
return $query_string;
}
// put query string into an array
$hashbuddy_query_string = wp_parse_args( $query_string, array() );
$pattern = '/[#]([\p{L}_0-9a-zA-Z-]+)/iu';
// Try the $_GET var (the 's' one as the 'hash' one doesn't exist in the url)
// this will only work on page load
if ( ! empty( $_GET['s'] ) && preg_match( $pattern, $_GET['s'] ) ) {
// Populate search terms
$hashbuddy_query_string['search_terms'] = $_GET['s'];
// Plugin is forcing comments to also have their own activity
$hashbuddy_query_string['display_comments'] = true;
// Override the query string
$query_string = $hashbuddy_query_string;
}
return $query_string;
/*
Original code
if ( isset( $_GET['hash'] ) ) {
$hash = $_GET['hash'];
// Now pass the querystring to override default values.
$query_string .= '&display_comments=true&search_terms=#' . $hash;
}
return $query_string;*/
}
add_filter( 'bp_ajax_querystring', 'hashbuddy_activity_hashtags_querystring', 11, 2 );
add_filter( 'bp_dtheme_ajax_querystring', 'hashbuddy_activity_hashtags_querystring', 11, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment