Hi gavyn,
Welcome to BuddyDev support forums.
I am not familiar with the code of BuddyX theme.Here is some code that doe sit (but in a reverse way, disables at other places except group).
https://buddydev.com/support/forums/topic/hiding-whats-new-form-in-member-activity-but-not-in-groups/page/2/#post-44896If you are comfortable with code, Please customize it from your use case. If you are not comfortable with code customization, Please let me know. I will update it for default BuddyPress which you can check and see if that works for BuddyX.
Regards
Brajeshfunction restrict_activity_updates_to_admins( $activity_content ) { // Check if the current user is logged in if ( is_user_logged_in() ) { // Get the current user's roles $user = wp_get_current_user(); $roles = $user->roles; // Allow administrators to post updates if ( in_array( 'administrator', $roles ) ) { return $activity_content; // Admins can post } else { // Block non-admins from posting bp_core_add_message( __( 'Only administrators can post activity updates.', 'buddypress' ), 'error' ); bp_core_redirect( wp_get_referer() ? wp_get_referer() : home_url() ); return false; } } return $activity_content; } add_filter( 'bp_activity_content_before_save', 'restrict_activity_updates_to_admins' );
This is my code to limit access to posting for admins only. I just want to make it so that the post forum doesn’t even show up for non admns.
Hi,
Please try the following code.// Disables activity post form on group pages for non-admins /** * Checks 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 = bp_group_admin_ids( groups_get_current_group(), 'array' ); $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 );
It should only show the post form to the group admin.
Regards
BrajeshHi,
I am glad you were able to resolve it.Regards
Brajesh
The topic ‘ [Resolved] Limiting activity posting in user groups to admins onnly’ is closed to new replies.