Skip to:
Content
Pages
Categories
Search
Top
Bottom

Is there a way to change the user profile url in bbPress?


  • coopersita
    Participant

    @coopersita

    In bbPress, the URL for a user’s public profile page is something like https://example.com/forums/users/{username}.

    The problem is that because of how users register (another plugin), their username is sometimes their name or email. We’d like for people to be able to post somewhat anonymously, so we’d like the URL to be https://example.com/forums/users/{display_name} or similar, so if they change their display name, they can remain somewhat anonymous.

    Is that possible?

    Alternatively, is there a way to post completely anonymously, but in a way that is available only for logged-in users?

Viewing 3 replies - 1 through 3 (of 3 total)

  • Robin W
    Moderator

    @robin-w

    Alternatively, is there a way to post completely anonymously, but in a way that is available only for logged-in users?

    I think you’ve asked this before, but not sure I responded.

    It is technically possible, but lots of code and beyond free help. In any case I’d suspect that someone would post thinking it was anonymous, but forget to tick the box that says anonymous, or use the wrong form, and by mistake post something outrageous that then appears in their name, cue them accusing your site of destroying their reputation, you accusing whoever wrote the code of it not being robust, and all hell breaking loose. So not code that I would write.

    your other suggestion is also possible, but you’d need to catch everywhere the username is used, and again risk it being exposed in some code that isn’t expected.

    I s’pose my gut answer is just enable anonymous posting, and use the ‘hold for moderation’ in the moderation part of my style pack plugin to approve anonymous posts. Then tell your users that they must log out to post anonymously.


    coopersita
    Participant

    @coopersita

    Thanks. I actually rolled my own solution with the post anonymously checkbox. I’m not too concerned that people will post with their names by mistake and be too upset. Here’s the code I’m using in case someone else is looking. For this setup to work, you just need to create an “anonymous’ user, so all topics that are flagged will be attributed to the user and the original user id is saved as a meta field so the system isn’t abused (so mostly anonymous, but not completely):

    //Anonymous publishing in forums
             //add fields to form (checkbox)
             add_action ( 'bbp_theme_after_topic_form_content','bbp_extra_fields');
             //save fields and change author
             add_action ( 'save_post_topic', 'bbp_save_extra_fields', 10, 2);
             //display original author for admins above topic
             add_action('bbp_template_before_replies_loop', 'bbp_show_extra_fields');
    
        function bbp_extra_fields() {
           $value = get_post_meta( bbp_get_topic_id(), 'is_anonymous', true);
            echo "<input type='checkbox' name='is_anonymous' id='is_anonymous' value='yes' ".checked('yes', $value)."> &nbsp;";
            echo '<label for="is_anonymous">Post this topic anonymously</label>';
            echo '<p><strong>Note:</strong> By checking this box, your identity will be hidden from other participants, but not from moderators nor admins. </p>';
        }
        
        function bbp_save_extra_fields( $post_id, $post) {
            if(isset($_POST['is_anonymous']) && $_POST['is_anonymous'] === 'yes') {
                $anon_ID = 1; // Id of dedicated anonymous user
                // update post if it's not anonymous already
                if($post->post_author != $anon_ID) {
                    update_post_meta($post_id, 'is_anonymous', $post->post_author);
                    wp_update_post( array(
                        'ID' => $post_id,
                        'post_author' => $anon_ID 
                    ) );
                }
            }
        }
        
        function bbp_show_extra_fields() {
            if(current_user_can('delete_others_topics')) {
              $topic_id = bbp_get_topic_id();
              $anon_author = get_post_meta( $topic_id, 'is_anonymous', true);
              if($anon_author) {
                    $user = get_user_by('ID', intval($anon_author));
                    if($user) {
                        echo "Original Author: <a href='".site_url()."/forums/users/".$user->user_login."'>".$user->display_name."</a><br>";
                    }
                }
            }
        }

    The code is only for posting topics. I’m not sure if for my use case replies would also need to be anonymous. We mostly want people to be able to ask questions openly without fear of being recognized by their peers (some users know each other).


    Robin W
    Moderator

    @robin-w

    🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar