Skip to:
Content
Pages
Categories
Search
Top
Bottom

One Off Identities or Posting As Multiple Users

  • @glaxton

    Participant

    Hello, this is my first time positing here, so please forgive me if this is in the wrong thread.

    I’m wanting to build a play by post (PBP) website for a D&D / Pathfinder game I’m currently running on a different website.

    I know the typical forum has someone post as a single user, but in a Dungeons and Dragons game, the DM/GM posts as tons of NPCs and other characters.

    The current website we use makes this as simple as selecting a character from a drop menu and the post looks like it’s from them, with their avatar and name.

    Does anything like this exist for bbpress?

    If not, can anyone guide me to documentation for how I might accomplish this.

    Yes, I’m aware of the Switch Users plug-in but that would be a huge pain for how often I would need to switch and I want to make this option for players who run multiple characters as well.

    Thanks in advance

Viewing 8 replies - 1 through 8 (of 8 total)
  • @robin-w

    Moderator

    nothing exists as far as I know. Like everything it could be coded, but beyond free help.

    @glaxton

    Participant

    Yep… I’m aware… That’s why I asked about documentation. If anyone can (usefully) respond with a link to an area of the documentation that deals with user identities at submission or how a post/thread/reply is associated with a given user.

    My current idea is to program the “submit reply” box to have a drop menu that lists a certain selection of names. If I have to create user accounts for each, I can, but I’m thinking instead of making a custom post type called Characters which it populates from. This would allow me to associate multiple characters with one user, give them each avatars, and additional details.

    If a reply MUST be associated with an actual WordPress user, then I can have it associate with the user account submitting, but check if they selected a Character CPT and, if so, show that name and avatar instead.

    @robin-w

    Moderator

    you would start by looking at the topic and reply forms in the templates

    \bbpress\templates\default\bbpress\form-topic.php

    which you can amend and copy to your child theme putting them in a bbpress folder

    these link to the new topic or reply handlers in

    \bbpress\includes\topics\functions.php line 96
    and an equivalent in

    \bbpress\includes\replies\functions.php

    these are called by filters eg

    add_action( ‘bbp_post_request’, ‘bbp_new_topic_handler’, 10 );

    so you could rewrite the new topic handler and call it from a new version of the above action, this could catch the $_POST from your dropdown, and add say an extra meta field, and allocating all topics/replies to a single user_id to prevent needing individual users.

    You can then amend the other templates or use filters to show the drop-down from the meta in the content field.

    @glaxton

    Participant

    Wow! Fantastic guidance! Thank you so much! I will share what I do in here if this is left open to possibly help others.

    @robin-w

    Moderator

    great – do come back of you need odd bits of help, and yes please a solution if you get there is always great to have

    @glaxton

    Participant

    Quick update. I used the CPT UI plugin to create a “Character” Custom Post Type.

    I modified form-reply.php to pull all these Characters and put those into a drop menu (select).

    Each of these CPT’s has their own Post ID, which I’m going to save as “d20_character” in the meta of the Reply.

    Question: Can you tell me the best way to modify the data saved for a reply when the user clicks “Submit”?

    Then in loop-single-reply.php I’m checking for the existence of the “d20_character” meta entry. If that entry exists for a reply, then I am pulling the Post Title of the Character Post by the ID, and the Post Thumbnail (Featured Image) to display that in the bbp-reply-author div instead of the default.

    Question: There are several actions in loop-single-reply.php. What’s the best way to modify those actions on an individual reply basis? I would like the use the same functionality those functions provide, but I need to tell them to use the ID of the Character post associated with the reply instead of the Reply WP User Author.

    Actions: bbp_theme_before_reply_author_details, bbp_reply_author_link, bbp_theme_before_reply_author_admin_details, bbp_theme_after_reply_author_admin_details, bbp_theme_after_reply_author_details

    @robin-w

    Moderator

    I did some thinking around this last night.

    Basically bbpress looks for an author ID in the posts table.

    Now there’s a hook in the topic/reply handlers (topic for topics, reply for replies, so they mirror) after a topic/reply is created.

    do_action( ‘bbp_new_reply_post_extras’, $reply_id );

    so if each of your characters has a WordPress user ID, then you could just hook to this, and change the post author to the worpress user ID.

    so say

    add_action ('bbp_new_reply_post_extras' , 'your function') ;
    
    function your_function ($reply_id) {
    $id = [either use the $_POST if still available and maybe have the value as the WordPress user ID , or get_post_meta for d20_character in the reply_id and do a look up to translate value to WordPress user ID]
    $my_post = array(
          'ID'           =>$reply_id,
          'post_author'   => $id,
          );
     
    // Update the post into the database
      wp_update_post( $my_post );
    
    }

    that way each topic/reply has a real author that happens to be your character chosen in the topic/reply form.
    that would save a ton of coding in the output, and risk of missing one and exposing the real user.

    @glaxton

    Participant

    I did something very similar to what you suggested. I hadn’t found the ‘bbp_new_reply_post_extras’ action so I tied it into wp_insert_post.

    I added a drop-menu/select field inside form-reply.php which I’m able to then access the data through the $_POST['d20_char'] variable in the wp_insert_post action.

    I’m populating that select box by simply running a wp_query and selecting all the CPT Characters and populating them. I will eventually limit that list of Characters based on a User’s role, and who the author of the Character is. DMs can post as Player’s Characters, and players can post as more than 1 character. (I’m not sure yet how I’m going to allow other people to use the website with their players and character lists, but I’ll cross that bridge some day in the future)

    Below is the really rudimentary version of my code. I will be adding a $post->post-type check to make sure I will then only the run code if a reply is being created, and also a check to make sure the POST data I’m looking for is present.

    function rpg_bbp_new_topic_handler( $post_id , $post , $update ) {
    	
    	update_post_meta( $post_id , 'd20_char' , $_POST['d20_char'] );
    	
    } add_action( 'wp_insert_post', 'rpg_bbp_new_topic_handler', 10, 3 );
Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Skip to toolbar