Tagged: activity, groups, hiding, whats-new-form
The script will work fine for BuddyPress legacy Template pack. You are most probably not using it.
Please visit Dashboard->Settings->BuddyPress->Options and look for the Template pack option.
Let us know which template pack it is.
Regards
BrajeshHi Yuriix,
Sure.
Please have a look.
https://i.ibb.co/8xS4Ncm/Selection-484.pngRegards
BrajeshHello Yuriix,
Thank you for sharing the details. It seems your theme hiding that setting. Please try the following code it will work with legacy template pack.
/** * Filter ajax post request */ function buddydev_restrict_post_update() { // Always allow site admin. if ( is_super_admin() || function_exists( 'bp_nouveau' ) ) { return; } $object = empty( $_POST['object'] ) ? '' : sanitize_key( $_POST['object'] ); if ( ! $object || 'user' == $object || bp_is_user_activity() ) { // Allowed user ids. $allowed_user_ids = array( 10 ); if ( ! in_array( get_current_user_id(), $allowed_user_ids ) ) { exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'You are not allowed to post activity.' ) . '</p></div>' ); } } } add_action( 'wp_ajax_post_update', 'buddydev_restrict_post_update', 9 );
You can assign comma(,) separated user_ids for allowed users.
Please give it a try and let me know if it helps or not.
Regards
RaviHello Yuriix,
Please try the following code:
/** * Check if user can post activity * * @return bool */ function buddydev_user_can_post_activity() { if ( bp_is_group_activity() ) { return true; } // Replace ids by your allowed user ids. $allowed_user_ids = array( 24, 2 ); $can = false; if ( is_super_admin() || in_array( get_current_user_id(), $allowed_user_ids ) ) { $can = true; } return $can; } add_action( 'bp_before_activity_post_form', function() { if ( ! buddydev_user_can_post_activity() ) { ob_start(); } } ); add_action( 'bp_after_activity_post_form', function() { if ( ! buddydev_user_can_post_activity() ) { ob_get_clean(); $css = '#buddypress form#whats-new-form {display: none};'; wp_add_inline_style( 'bp-legacy-css', $css ); } } ); add_action( 'bp_enqueue_scripts', function () { if ( ! buddydev_user_can_post_activity() ) { $css = '#buddypress form#whats-new-form {display: none};'; wp_add_inline_style( 'bp-parent-css', $css ); } }, 15 ); /** * Filter ajax post request */ function buddydev_restrict_post_update() { // Always allow site admin. if ( buddydev_user_can_post_activity() || function_exists( 'bp_nouveau' ) ) { return; } $object = empty( $_POST['object'] ) ? '' : sanitize_key( $_POST['object'] ); if ( ! $object || 'user' == $object || bp_is_user_activity() ) { exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'You are not allowed to post activity.' ) . '</p></div>' ); } } add_action( 'wp_ajax_post_update', 'buddydev_restrict_post_update', 9 );
Please replace the old code with this and give it a try.
Note: It will hide the posting form on the activity directory as well. But users can post group activity within the group.
Regards
Ravi
The topic ‘ [Resolved] Hiding “whats-new-form” in member activity but NOT in Groups’ is closed to new replies.