Replies
I have disabled HPOS but im still experiencing the expiry issue for sticky posts, I have sticky post expiry set to 7 days expiration but paid post are becoming unsticky within few minutes instead of 7 days
- Tosin on May 21, 2023 at 12:26 pm in reply to: Discussion on dealing with buddypress inactive users or dead profiles #49579
Thanks for the feddback Brajesh
Although I know nothing about CLI based solutions this is what I have now
function check_inactive_users_and_assign_role() { // Check if the current page is the BuddyPress sitewide activity directory page if ( function_exists( 'bp_is_activity_directory' ) && bp_is_activity_directory() ) { // Check if user is logged in if ( is_user_logged_in() ) { $users = get_users( array( 'fields' => 'ID', // Only retrieve the user IDs for efficiency 'role__not_in' => array( 'administrator' ), // Exclude users with the 'administrator' role 'number' => -1, // Retrieve all users at once ) ); foreach ( $users as $user_id ) { $last_activity = bp_get_user_last_activity( $user_id ); // Get the last activity timestamp if ( ! empty( $last_activity ) ) { $inactive_time = time() - strtotime( $last_activity ); // Calculate the time difference in seconds // Check if the user has been inactive for a year (31536000 seconds) if ( $inactive_time >= 31536000 ) { $ghost_member_role = 'ghost_member'; // The role slug for Ghost Member // Add the user to the Ghost Member role $user_obj = new WP_User( $user_id ); $user_obj->add_role( $ghost_member_role ); } } } } } } add_action( 'bp_loaded', 'check_inactive_users_and_assign_role' );
Maybe running this first code once a week might be better
/** * (Buddypress)- Remove users from the "Ghost Member" after login */ function remove_ghost_member_role_on_login( $user_login, $user ) { $ghost_member_role = get_role( 'ghost_member' ); // Get the Ghost Member role object if ( $ghost_member_role && in_array( $ghost_member_role->name, $user->roles ) ) { $user_obj = new WP_User( $user->ID ); $user_obj->remove_role( $ghost_member_role->name ); } } add_action( 'wp_login', 'remove_ghost_member_role_on_login', 10, 2 );
Since I dont have an efficient way for inactive user clean up without affecting site performance, maybe the method of cleanup should change, what would you suggest.
1. Automatic cleanup via code
2. Manual cleanup by clicking a button in admin area
3. Community cleanup by community members reporting other inactive users
4. Mix of both automatic cleanup and community clean up or the 3Personally I would have preferred automatic approach to save time
what’s your opinion
thanks
- Tosin on May 18, 2023 at 12:22 pm in reply to: Discussion on dealing with buddypress inactive users or dead profiles #49560
Now how will the code affect site performance if the site has a least one million registered members. If the site has a large number of registered members, iterating through all users using get_users() and checking their activity status can potentially impact site performance, especially if the operation is performed on every page load.
Will this code be better
function schedule_inactive_users_check() { if ( ! wp_next_scheduled( 'check_inactive_users_event' ) ) { wp_schedule_event( time(), 'daily', 'check_inactive_users_event' ); } } add_action( 'bp_loaded', 'schedule_inactive_users_check' ); function check_inactive_users_and_assign_role() { $users = get_users( array( 'number' => 100 ) ); // Get 100 users at a time foreach ( $users as $user ) { $last_activity = bp_get_user_last_activity( $user->ID ); // Get the last activity timestamp if ( ! empty( $last_activity ) ) { $inactive_time = time() - strtotime( $last_activity ); // Calculate the time difference in seconds // Check if the user has been inactive for a year (31536000 seconds) if ( $inactive_time >= 31536000 ) { $ghost_member_role = 'ghost_member'; // The role slug for Ghost Member // Add the user to the Ghost Member role $user_obj = new WP_User( $user->ID ); $user_obj->add_role( $ghost_member_role ); } } } } function run_inactive_users_check() { check_inactive_users_and_assign_role(); // Check if there are more users to process if ( count( get_users() ) > 0 ) { wp_schedule_single_event( time() + 10, 'run_inactive_users_check' ); // Schedule the next batch after 10 seconds } } add_action( 'check_inactive_users_event', 'run_inactive_users_check' );
- Tosin on May 18, 2023 at 12:18 pm in reply to: Discussion on dealing with buddypress inactive users or dead profiles #49559
This is example code for classifying user inactive for a year
function check_inactive_users_and_assign_role() { $users = get_users(); // Get all users foreach ( $users as $user ) { $last_activity = bp_get_user_last_activity( $user->ID ); // Get the last activity timestamp if ( ! empty( $last_activity ) ) { $inactive_time = time() - strtotime( $last_activity ); // Calculate the time difference in seconds // Check if the user has been inactive for a year (31536000 seconds) if ( $inactive_time >= 31536000 ) { $ghost_member_role = 'ghost_member'; // The role slug for Ghost Member // Add the user to the Ghost Member role $user_obj = new WP_User( $user->ID ); $user_obj->add_role( $ghost_member_role ); } } } } add_action( 'bp_loaded', 'check_inactive_users_and_assign_role' );
Hi Brajesh,
I really like this idea, I was wondering if you can also include a field for uploading Audio files
Thanks
This is now resolved there was another popup login form in the same page with similar form ID
- Tosin on May 11, 2023 at 6:13 pm in reply to: [Resolved] Buddyblog pay per post improvement/suggestion #49457
Thanks for the feedback Brajesh
You got the suggestion right
I want a settings in the product section to also enable users to mark old posts or unpaid posts and expired paid posts as sticky.
So when user edits an old post they can select a product price and promote/feature old unpaid post as sticky
NEW WORKFLOW ON POST EDIT
Clicking the (update) button will now redirect the user to cart or checkout page, after successful payment the post will now be updated and also become stickyNOTE – this new workflow will only take effect if a price option was selected in the pay per post field while updating an old post.
Thanks
Thanks
please note that I changed the button ID from wp-submit to bl-login-submit in my child theme
Alternatively how can I disable all internal recording of notifications in database while leaving the notification component enabled, so now all email notifications settings would be enabled
I want to disable the notification component from the settings but still enable email notifications for the following
ENABLE EMAIL NOTIFICATIONS FOR
1. Private messages
2. Activity – @mentions
3. Activity – A member replies to an update or comment you’ve postedPlease note that I still want users to have access to the email notification settings. I noticed that disabling the notification component would also remove the email notification settings for the 3 items stated above