sorry buddypress 2.1 wordpress 4.0
Try this in bp-custom.php
function wirelab_check_activity_login() {
if( ! is_user_logged_in() ) {
wp_die("To view this page you must first log in.");
}
}
add_action('bp_before_directory_activity', 'wirelab_check_activity_login');
Really! Running a die function midway through rendering a document, in fact what point is there to that extension of PHP die() in rendering html if ones intending on breaking a page beyond redemption. it’s a debugging function you can’t use it in a production site where rendering a page.
Thanks for your input, lol.
Would you find this more acceptable?
function wirelab_check_activity_login() {
if( ! is_user_logged_in() && bp_is_activity() ) {
wp_redirect( 'url to login page' );
exit;
}
}
add_action('bp', 'wirelab_check_activity_login');
yep think so 😉 OP take note please, not sure where you picked up on the use of die() but you don’t want to be doing that 🙂
and WP really trying to fathom how ability to render markup in a php function that effectively renders all further action null is at all useful or maybe we’re meant to render a full DOM via it? 🙂
Hi,
Sorry i need a bit more help as I failed to get it to work. So I created a bp-custom.php under wp-content/plugins
and added the following below, however my activity-stream page was still accessible without login
<?php
// hacks and mods will go here
function wirelab_check_activity_login() {
if( ! is_user_logged_in() && bp_is_activity() ) {
wp_redirect( '/wp-login.php' );
exit;
}
}
add_action('bp', 'wirelab_check_activity_login');
?>
Try this instead:
function wirelab_check_activity_login() {
if ( bp_is_activity_component() && ! is_user_logged_in() ) {
wp_redirect( get_option('siteurl') . '/wp-login.php' );
exit;
}
}
add_action('get_header', 'wirelab_check_activity_login');
Sorry no luck. My bp-custom.php reads as below
<?php
function wirelab_check_activity_login() {
if ( bp_is_activity_component() && ! is_user_logged_in() ) {
wp_redirect( get_option('siteurl') . '/wp-login.php' );
exit;
}
}
add_action('get_header', 'wirelab_check_activity_login');
?>
Update: I added the function to my child theme functions.php and it seems to be working now.