Set default activity filter for BuddyPress (legacy or nouveau template pack)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Custom functions | |
*/ | |
// Exit if accessed directly | |
defined( 'ABSPATH' ) || exit; | |
function set_default_activity_filter() { | |
$handle = 'bp-nouveau'; | |
$position = 'before'; | |
if ( 'nouveau' !== bp_get_theme_package_id() ) { | |
$handle = 'bp-jquery-cookie'; | |
$position = 'after'; | |
} | |
wp_add_inline_script( $handle, sprintf( ' | |
( function( $ ) { | |
// Replace with the activity type of your choice. | |
var defaultActivityType = \'new_member\'; | |
if ( \'bp-nouveau\' === \'%s\' ) { | |
var activityVars = sessionStorage.getItem( \'bp-activity\' ), store; | |
if ( activityVars ) { | |
store = JSON.parse( activityVars ); | |
if ( ! store.filter || \'0\' === store.filter ) { | |
store.filter = defaultActivityType; | |
sessionStorage.setItem( \'bp-activity\', JSON.stringify( store ) ); | |
} | |
} | |
} else if ( \'undefined\' !== typeof $.cookie ) { | |
if ( \'-1\' === $.cookie( \'bp-activity-filter\' ) || ! $.cookie( \'bp-activity-filter\' ) ) { | |
$.cookie( \'bp-activity-filter\', defaultActivityType, { | |
path: \'/\', | |
secure: ( \'https:\' === window.location.protocol ) | |
} ); | |
} | |
} | |
} )( jQuery ); | |
', $handle ), $position ); | |
} | |
add_action( 'bp_enqueue_scripts', 'set_default_activity_filter', 20 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment