BuddyDev

Search

Replies

  • Participant
    Level: Guru
    Posts: 885
    Tosin on in reply to: [Resolved] Buddyblog pro and buddypress 12.0.0 beta 1 #51198

    Hi Brajesh,

    I have version 1.4.0 but no new update is available, your changelog at https://buddydev.com/plugins/buddyblog-pro/ says 1.4.0 support bp 12.0.0, i have tested it and Blog tab is not displaying in the user navigation menu

  • Participant
    Level: Guru
    Posts: 885
    Tosin on in reply to: Branded login and buddypress 12.0.0 beta 1 #51132
    This reply has been marked as private.
  • Participant
    Level: Guru
    Posts: 885
    Tosin on in reply to: Branded login and buddypress 12.0.0 beta 1 #51115

    Hi Brajesh,

    This is really heart breaking to know that you are deprecating this awesome plugin, Branded Login has been my number one plugin for buddypress simply because I so much dislike the default wordpress login page, all other alternative plugins to customize the default login pages are just terrible and bloated also using security plugins to change the login url from (wp-login.php) to (login) is also terrible,

    There is not an alternative to your plugin, I would really appreciate your guidance on how you designed your login page for buddydev which looks flawless with your theme’s design.

    Thanks

  • Participant
    Level: Guru
    Posts: 885
    Tosin on in reply to: [Resolved] Buddyblog pro and buddypress 12.0.0 beta 1 #51086

    Gentle reminder sir

    BuddyPress 12.0.0 is now available

  • Participant
    Level: Guru
    Posts: 885
    Tosin on in reply to: Branded login and buddypress 12.0.0 beta 1 #51085

    Gentle reminder sir

    BuddyPress 12.0.0 is now available

  • Participant
    Level: Guru
    Posts: 885
    Tosin on in reply to: [Resolved] Attribute post on account deletion in buddypress #50911

    You are awesome Ravi, thanks a lot

  • Participant
    Level: Guru
    Posts: 885
    Tosin on in reply to: [Resolved] Attribute post on account deletion in buddypress #50889

    it might also be advisable to also use this code to disable comments on posts attributed to the non active user

     function disable_comments_on_single_post_by_user() {
        if (is_singular('post')) {
            $post_id = get_queried_object_id(); // Get the current post ID
    
            // Get the post's author ID and comment status
            $post_author_id = get_post_field('post_author', $post_id);
            $comment_status = get_post_field('comment_status', $post_id);
    
            // Check if the post author's ID matches the specified user ID and comments are open
            if ($post_author_id == 466526 && $comment_status === 'open') {
                // Update post's comment status to 'closed'
                wp_update_post(array(
                    'ID'             => $post_id,
                    'comment_status' => 'closed',
                ));
            }
        }
    }
    add_action('template_redirect', 'disable_comments_on_single_post_by_user');
     
  • Participant
    Level: Guru
    Posts: 885
    Tosin on in reply to: [Resolved] Attribute post on account deletion in buddypress #50888

    Hi Brajesh

    I finally got it to work with this code, kindly review

    I really think this would help with buddyblog when multiple authors delete their account, lots of 404 errors would be prevented

    Also note that the ghostwriter account is just a non active account used to preserve useful content from deleted accounts.

     function reassign_posts_on_user_deletion_to_ghostwriter($user_id) {
        // Check if the deleted user is not the target user (466526)
        if ($user_id !== 466526) {
            $args = array(
                'post_type'      => 'post',
                'author'         => $user_id, // Posts authored by the deleted user
                'posts_per_page' => -1,       // Get all posts
                'fields'         => 'ids',    // Retrieve only post IDs
                'post_status'    => 'publish',// Only published posts
            );
            $posts = get_posts($args);
            // Reassign published posts to user with ID 466526
            foreach ($posts as $post_id) {
                $post_status = get_post_status($post_id);
                if ($post_status === 'publish') {
                    wp_update_post(array(
                        'ID'          => $post_id,
                        'post_author' => 466526,
                    ));
                }
            }
        }
    }
    add_action('bp_core_pre_delete_account', 'reassign_posts_on_user_deletion_to_ghostwriter', 10, 1);
     
  • Participant
    Level: Guru
    Posts: 885

    I don’t want to give up on this so im trying another approach below

     // change the role of inactive members over 1 year to ghost member
    function update_site_ghost_members() {
        // Check if it's the activity directory page and the user is an admin
        if (bp_is_activity_directory() && current_user_can('administrator')) {
            $last_run_timestamp = get_user_meta(0, 'last_ghost_member_role_update', true);
    
            // Check if a month (2592000 seconds = 30 days) has passed since the last run
            if (!$last_run_timestamp || (time() - $last_run_timestamp) >= 2592000) {
                // Get users with specific roles (e.g., 'contributor' and 'subscriber')
                $users = get_users(array(
                    'fields' => 'ID',
                    'role__in' => array('contributor', 'subscriber'),
                ));
    
                foreach ($users as $user_id) {
                    // Check user's last activity using BuddyPress function
                    $last_activity = bp_get_user_last_activity($user_id);
    
                    // Calculate time difference
                    $inactive_time = strtotime('now') - strtotime($last_activity);
    
                    // If inactive for more than one year (31536000 seconds = 1 year)
                    if ($inactive_time > 31536000) {
                        // Assign 'Ghost Member' role to the user
                        $user = new WP_User($user_id);
                        $user->add_role('ghost_member');
                    }
                }
    
                // Update the timestamp to indicate the code ran
                update_user_meta(0, 'last_ghost_member_role_update', time());
            }
        }
    }
    add_action('template_redirect', 'update_site_ghost_members'); 

    running get_users would be awesome in batches

  • Participant
    Level: Guru
    Posts: 885
    Tosin on in reply to: [Resolved] auto follow featured members #50878

    Will this code work

     /** 
     * Custom function to count user posts and cache the result using transients
     */
    function custom_count_user_posts($user_id) {
        $post_count = get_transient('custom_user_post_count_' . $user_id);
    
        if (false === $post_count) {
            $post_count = count_user_posts($user_id);
            set_transient('custom_user_post_count_' . $user_id, $post_count);
        }
    
        return $post_count;
    }
    
    /** BuddyPress Auto Friendship Pro + BuddyPress Featured Members autofollow. */
    function auto_follow_on_welcome_page_load() {
        // Check if the current page slug matches 'welcome'
        if (is_page('welcome')) {
            if (!function_exists('bp_follow_start_following')) {
                return;
            }
    
            $user = wp_get_current_user();
    
            // Check if the user has no last activity and hasn't already performed the follow action
            if (empty(bp_get_user_last_activity($user->ID)) && !get_user_meta($user->ID, 'has_followed_featured_users', true)) {
    
                global $wpdb;
    
                $featured_user_ids = $wpdb->get_col(
                    $wpdb->prepare(
                        "
                        SELECT user_id
                        FROM {$wpdb->usermeta}
                        INNER JOIN {$wpdb->users} ON {$wpdb->usermeta}.user_id = {$wpdb->users}.ID
                        WHERE {$wpdb->usermeta}.meta_key = %s
                        AND {$wpdb->usermeta}.meta_value = %s
                        AND {$wpdb->users}.user_status = %d
                        ",
                        '_is_featured',
                        '1',
                        0
                    )
                );
    
                $users_more_than_2_posts = array();
                foreach ($featured_user_ids as $featured_user_id) {
                    $post_count = custom_count_user_posts($featured_user_id);
                    if ($post_count > 2) {
                        $users_more_than_2_posts[] = $featured_user_id;
                    }
                }
    
                $total_featured_users = count($users_more_than_2_posts);
                $selected_user_ids = $users_more_than_2_posts;
                if ($total_featured_users > 10) {
                    shuffle($users_more_than_2_posts);
                    $selected_user_ids = array_slice($users_more_than_2_posts, 0, 9);
                } else if ($total_featured_users > 5) {
                    shuffle($users_more_than_2_posts);
                    $selected_user_ids = array_slice($users_more_than_2_posts, 0, 6);
                } else if ($total_featured_users < 5) {
                    shuffle($users_more_than_2_posts);
                    $selected_user_ids = array_slice($users_more_than_2_posts, 0, 3);
                }
    
                foreach ($selected_user_ids as $featured_user_id) {
                    bp_follow_start_following(array(
                        'leader_id' => $featured_user_id,
                        'follower_id' => $user->ID,
                    ));
                }
    
                // Set a user meta flag to indicate that the follow action has been performed
                update_user_meta($user->ID, 'has_followed_featured_users', true);
            }
        }
    }
    add_action('template_redirect', 'auto_follow_on_welcome_page_load');