Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbp_new_forum hook


  • Laviic
    Participant

    @laviic

    Hello,

    I am trying to write a plugin that adds some meta-information to a forum when it gets created. I can see that bbPress has a “bbp_new_forum” and a “bbp_edit_forum” hook, yet those never appear to fire, no matter what i do. I even added a php-die directly in front of their respective “do_action” calls inside the bbPress source code just to find out, that the part of the code that should call the new_forum hook appears to never actually be executed. What are those hooks for then, and what hooks DO get called when you create/edit a bbPress forum?

    Thank you for your help!

    My Version of WordPress is 3.8.1
    My Version of bbPress is 2.5.3

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

  • Laviic
    Participant

    @laviic

    By further digging around i noticed, that the hooks mentioned above indeed DO fire, but not when a new forum is created… They fire when a new TOPIC inside a forum is created.

    This is highly unintuitve. I suggest giving those hooks a more understandable name?


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    That doesn’t seem right. bbp_new_forum will only fire when forums are created outside of wp-admin, like in a BuddyPress Group Forum. If you want to add meta when any new forum is created, you’ll likely need to hook into WordPress’s wp_insert_post action, instead.


    Laviic
    Participant

    @laviic

    You are correct. The execution of the hooks when creating a new topic was a misobservation on my side. Sorry about that!

    The bbp_new_forum hook firing only when a forum is created outside wp-admin is interesting information. Thanks for clearing that up.

    I have already worked around the ‘missing’ hooks by tying into the save_post hook. Its not exactly what i would call elegant, and it requires some additional checks to make sure my callback was executed for the right event, but it does the job.

    So, the only thing that is left for me to ask is: Why isn’t there an intuitively named hook for when one creates a forum from the backend? Or is there one that i am missing? :)

    Thank you for your response!


    antipole
    Participant

    @antipole

    Hi… I am trying this. I want to auto-subscribe all users to new forums and I have tried the following:

    function ovni_subscribe_all_users_to_new_forum($forum_id){  // subscribe all users to a new forum
    	echo 'ovni_subscribe_all_users_to_new_forum fired';
    	// this function will fire on all wp-insert_posts - only act if is for a new forum
    	if ((get_post($forum_id)->post_type == bbp_get_forum_post_type()) && !wp_is_post_revision( $forum_id )){
    		// have just posted a new forum
    		$all_user_ids = get_users();
    		foreach ($all_user_ids as $user){
    			bbp_add_user_forum_subscription($user_id, $forum_id);
    			}
    		}
    	}
     add_action(save_post, ovni_subscribe_all_users_to_new_forum, 90,1);
    

    When I load the New Forum admin page, the echo trace statement appears at the top of the New Forum page, before it has been submitted.

    Can SKS help here please?


    antipole
    Participant

    @antipole

    I am still looking for a solution to this – I want to subscribe users to a new forum when it is created.

    The code above fires when you open the New forum admin page. I guess a new post is created at that time so an object ID is allocated. If you don’t go through and publish, the entry must then get deleted. Anyhow, if you do create the forum by publishing it, the subscriptions do not get created. My guess is that it is too soon in the process of creating a forum to add subscriptions to it.

    I have tried hooking onto the publish action but not got it to fire there. I really need to find a hook much later in the process. As stated above, the bbb_new_forum hook only fires from the front end and that limits it to creating group forums, as far as I can see.

    Any pointers gratefully received. Meanwhile I am having to manually activate some code and run it once after creating a new forum and then deactivate it – very error prone and easily forgotten.

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