Reply To: hiding activity form for all users except admin
opps ] Let me provide you with an alternative approach that disables the activity form for users, making it more secure. You can achieve this by disabling the form functionality entirely. Here how you can modify the code to accomplish thi
php
Copy code
function disable_activity_form_for_non_admins() {
if ( ! current_user_can( ‘administrator’ ) ) {
remove_action( ‘init’, ‘function_that_creates_activity_form’ );
}
}
add_action( ‘init’, ‘disable_activity_form_for_non_admins’ );
In this code snippet, replace ‘function_that_creates_activity_form’ with the actual function name or hook that creates the activity form. This modification disables the activity form functionality for non-administrative users by removing the action that creates the form during the init hook.
This way the form wont be available in the HTML markup, making it more secure compared to just hiding it with CSS. Remember to place this code in your theme’s functions.php file or in a custom plugin file.
Again make sure to back up your site before making any changes, and test the modified code in a safe environment first to ensure it works as expected. If you encounter any issues or have further questions, feel free to ask!