Skip to:
Content

bbPress.org

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#2346 closed enhancement (worksforme)

Add action for additional actions while saving forums

Reported by: nofearinc Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.1
Component: API - Actions/Filters Keywords: has-patch
Cc:

Description

I need to implement a new post status 'Special' for forums, it's already visible in the metabox but it is not stored in the database.

While browsing through the bbp_save_forum_extras function in includes/forums my first approach is adding apply_filters to the status array here:

if ( !empty( $_POST['bbp_forum_visibility'] ) && in_array( $_POST['bbp_forum_visibility'], array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id() ) ) ) {

So that I could use any status respectfully:

if ( !empty( $_POST['bbp_forum_visibility'] ) && in_array( $_POST['bbp_forum_visibility'], apply_filters( 'bbp_forum_visibility_status_list', array( bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id() ) ) ) ) {

However, the switch is not really flexible for new status rules so I'd like to propose an action for adding custom rules while saving the forum extras. The function is called under several conditions and would be easier to add a hook there instead of just juggling with priorities and adding custom functions to all rules every time we need to add more changes.

Inherently this could probably apply for topics and replies, but I don't have a practical use case for there right now.

Attachments (1)

forum-functions.diff (326 bytes) - added by nofearinc 9 years ago.
includes/forums/functions.php action added

Download all attachments as: .zip

Change History (3)

@nofearinc
9 years ago

includes/forums/functions.php action added

#1 @johnjamesjacoby
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Any reason why you can't use the 'bbp_new_forum_pre_extras' and 'bbp_edit_forum_pre_extras' actions, priority 11 or higher? Seems it would do the same exact thing?

#2 @nofearinc
9 years ago

For this one I was looking forward to act based on metadata (by verifying if the switch has passed successfully), but generally I'm looking forward to keeping pre/post actions everywhere to facilitate the ability for plugins to work smoothly in different scenarios.

Next week I'll still have to handle a new post_status support as currently there are few small bugs and I had to use pre_get_posts and even the request filter for something that I see as a straight forward request, but there is a chance for me to not use a proper hook somewhere or get stuck in a WP-related issue rather than bbPress specific (would be happy to share use cases).

Note: See TracTickets for help on using tickets.