Skip to:
Content

bbPress.org

Changeset 4551


Ignore:
Timestamp:
12/06/2012 10:29:35 AM (9 years ago)
Author:
johnjamesjacoby
Message:

Introduce bbp_post_request() and bbp_get_request() sub-actions:

  • Update actions and sub-actions to use these new handlers.
  • Update new/edit forum/topic/reply handlers to use these.
  • Update phpdoc as needed.
  • Remove duplicate 'bp_actions' request hooks from BuddyPress group forums.
  • Does not include admin-side requests.
Location:
trunk/includes
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/core/actions.php

    r4549 r4551  
    267267 * bbPress needs to redirect the user around in a few different circumstances:
    268268 *
    269  * 1. Form submission within a theme (new and edit)
     269 * 1. POST and GET requests
    270270 * 2. Accessing private or hidden content (forums/topics/replies)
    271271 * 3. Editing forums, topics, replies, users, and tags
    272272 * 4. bbPress specific AJAX requests
    273273 */
    274 add_action( 'bbp_template_redirect', 'bbp_forum_enforce_blocked',   -1 );
    275 add_action( 'bbp_template_redirect', 'bbp_forum_enforce_hidden',    -1 );
    276 add_action( 'bbp_template_redirect', 'bbp_forum_enforce_private',   -1 );
    277 add_action( 'bbp_template_redirect', 'bbp_new_forum_handler',       10 );
    278 add_action( 'bbp_template_redirect', 'bbp_new_reply_handler',       10 );
    279 add_action( 'bbp_template_redirect', 'bbp_new_topic_handler',       10 );
    280 add_action( 'bbp_template_redirect', 'bbp_edit_topic_tag_handler',  1  );
    281 add_action( 'bbp_template_redirect', 'bbp_edit_user_handler',       1  );
    282 add_action( 'bbp_template_redirect', 'bbp_edit_forum_handler',      1  );
    283 add_action( 'bbp_template_redirect', 'bbp_edit_reply_handler',      1  );
    284 add_action( 'bbp_template_redirect', 'bbp_edit_topic_handler',      1  );
    285 add_action( 'bbp_template_redirect', 'bbp_merge_topic_handler',     1  );
    286 add_action( 'bbp_template_redirect', 'bbp_split_topic_handler',     1  );
    287 add_action( 'bbp_template_redirect', 'bbp_toggle_topic_handler',    1  );
    288 add_action( 'bbp_template_redirect', 'bbp_move_reply_handler',      1  );
    289 add_action( 'bbp_template_redirect', 'bbp_toggle_reply_handler',    1  );
    290 add_action( 'bbp_template_redirect', 'bbp_favorites_handler',       1  );
    291 add_action( 'bbp_template_redirect', 'bbp_subscriptions_handler',   1  );
    292 add_action( 'bbp_template_redirect', 'bbp_do_ajax',                 1  );
    293 add_action( 'bbp_template_redirect', 'bbp_check_user_edit',         10 );
    294 add_action( 'bbp_template_redirect', 'bbp_check_forum_edit',        10 );
    295 add_action( 'bbp_template_redirect', 'bbp_check_topic_edit',        10 );
    296 add_action( 'bbp_template_redirect', 'bbp_check_reply_edit',        10 );
    297 add_action( 'bbp_template_redirect', 'bbp_check_topic_tag_edit',    10 );
     274add_action( 'bbp_template_redirect', 'bbp_forum_enforce_blocked', 1  );
     275add_action( 'bbp_template_redirect', 'bbp_forum_enforce_hidden',  1  );
     276add_action( 'bbp_template_redirect', 'bbp_forum_enforce_private', 1  );
     277add_action( 'bbp_template_redirect', 'bbp_post_request',          10 );
     278add_action( 'bbp_template_redirect', 'bbp_get_request',           10 );
     279add_action( 'bbp_template_redirect', 'bbp_check_user_edit',       10 );
     280add_action( 'bbp_template_redirect', 'bbp_check_forum_edit',      10 );
     281add_action( 'bbp_template_redirect', 'bbp_check_topic_edit',      10 );
     282add_action( 'bbp_template_redirect', 'bbp_check_reply_edit',      10 );
     283add_action( 'bbp_template_redirect', 'bbp_check_topic_tag_edit',  10 );
     284
     285// Theme-side POST requests
     286add_action( 'bbp_post_request', 'bbp_do_ajax',                1  );
     287add_action( 'bbp_post_request', 'bbp_edit_topic_tag_handler', 1  );
     288add_action( 'bbp_post_request', 'bbp_edit_user_handler',      1  );
     289add_action( 'bbp_post_request', 'bbp_edit_forum_handler',     1  );
     290add_action( 'bbp_post_request', 'bbp_edit_reply_handler',     1  );
     291add_action( 'bbp_post_request', 'bbp_edit_topic_handler',     1  );
     292add_action( 'bbp_post_request', 'bbp_merge_topic_handler',    1  );
     293add_action( 'bbp_post_request', 'bbp_split_topic_handler',    1  );
     294add_action( 'bbp_post_request', 'bbp_move_reply_handler',     1  );
     295add_action( 'bbp_post_request', 'bbp_new_forum_handler',      10 );
     296add_action( 'bbp_post_request', 'bbp_new_reply_handler',      10 );
     297add_action( 'bbp_post_request', 'bbp_new_topic_handler',      10 );
     298
     299// Theme-side GET requests
     300add_action( 'bbp_get_request', 'bbp_toggle_topic_handler',   1  );
     301add_action( 'bbp_get_request', 'bbp_toggle_reply_handler',   1  );
     302add_action( 'bbp_get_request', 'bbp_favorites_handler',      1  );
     303add_action( 'bbp_get_request', 'bbp_subscriptions_handler',  1  );
    298304
    299305// Maybe convert the users password
  • trunk/includes/core/sub-actions.php

    r4305 r4551  
    319319
    320320/**
     321 * The main action used for handling theme-side POST requests
     322 *
     323 * @since bbPress (r4550)
     324 * @uses do_action()
     325 */
     326function bbp_post_request() {
     327
     328    // Bail if not a POST action
     329    if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     330        return;
     331
     332    // Bail if action is not bbp-new-reply
     333    if ( empty( $_POST['action'] ) )
     334        return;
     335
     336    do_action( 'bbp_post_request', $_POST['action'] );
     337}
     338
     339/**
     340 * The main action used for handling theme-side GET requests
     341 *
     342 * @since bbPress (r4550)
     343 * @uses do_action()
     344 */
     345function bbp_get_request() {
     346
     347    // Bail if not a POST action
     348    if ( 'GET' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     349        return;
     350
     351    // Bail if action is not bbp-new-reply
     352    if ( empty( $_GET['action'] ) )
     353        return;
     354
     355    do_action( 'bbp_get_request', $_GET['action'] );
     356}
     357
     358/** Filters *******************************************************************/
     359
     360/**
    321361 * Filter the plugin locale and domain.
    322362 *
     
    329369    return apply_filters( 'bbp_plugin_locale', $locale, $domain );
    330370}
    331 
    332 /** Filters *******************************************************************/
    333371
    334372/**
  • trunk/includes/extend/buddypress/group.php

    r4544 r4551  
    5555        $this->template_file        = 'groups/single/plugins';
    5656        $this->display_hook         = 'bp_template_content';
    57 
    58         // Add handlers to bp_actions
    59         add_action( 'bp_actions', 'bbp_new_forum_handler'  );
    60         add_action( 'bp_actions', 'bbp_new_topic_handler'  );
    61         add_action( 'bp_actions', 'bbp_new_reply_handler'  );
    62         add_action( 'bp_actions', 'bbp_edit_forum_handler' );
    63         add_action( 'bp_actions', 'bbp_edit_topic_handler' );
    64         add_action( 'bp_actions', 'bbp_edit_reply_handler' );
    6557
    6658        // Possibly redirect
  • trunk/includes/forums/functions.php

    r4525 r4551  
    7878 * Handles the front end forum submission
    7979 *
     80 * @param string $action The requested action to compare this function to
    8081 * @uses bbPress:errors::add() To log various error messages
    8182 * @uses bbp_verify_nonce_request() To verify the nonce and check the request
     
    107108 *                                              messages
    108109 */
    109 function bbp_new_forum_handler() {
    110 
    111     // Bail if not a POST action
    112     if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    113         return;
     110function bbp_new_forum_handler( $action = '' ) {
    114111
    115112    // Bail if action is not bbp-new-forum
    116     if ( empty( $_POST['action'] ) || ( 'bbp-new-forum' !== $_POST['action'] ) )
     113    if ( 'bbp-new-forum' !== $action )
    117114        return;
    118115
     
    339336 * Handles the front end edit forum submission
    340337 *
     338 * @param string $action The requested action to compare this function to
    341339 * @uses bbPress:errors::add() To log various error messages
    342340 * @uses bbp_get_forum() To get the forum
     
    368366 *                                              messages
    369367 */
    370 function bbp_edit_forum_handler() {
    371 
    372     // Bail if not a POST action
    373     if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    374         return;
     368function bbp_edit_forum_handler( $action = '' ) {
    375369
    376370    // Bail if action is not bbp-edit-forum
    377     if ( empty( $_POST['action'] ) || ( 'bbp-edit-forum' !== $_POST['action'] ) )
     371    if ( 'bbp-edit-forum' !== $action )
    378372        return;
    379373
  • trunk/includes/replies/functions.php

    r4522 r4551  
    7878 * @since bbPress (r2574)
    7979 *
     80 * @param string $action The requested action to compare this function to
    8081 * @uses bbp_add_error() To add an error message
    8182 * @uses bbp_verify_nonce_request() To verify the nonce and check the request
     
    103104 *                                              message
    104105 */
    105 function bbp_new_reply_handler() {
    106 
    107     // Bail if not a POST action
    108     if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    109         return;
     106function bbp_new_reply_handler( $action = '' ) {
    110107
    111108    // Bail if action is not bbp-new-reply
    112     if ( empty( $_POST['action'] ) || ( 'bbp-new-reply' !== $_POST['action'] ) )
     109    if ( 'bbp-new-reply' !== $action )
    113110        return;
    114111
     
    349346 * Handles the front end edit reply submission
    350347 *
     348 * @param string $action The requested action to compare this function to
    351349 * @uses bbp_add_error() To add an error message
    352350 * @uses bbp_get_reply() To get the reply
     
    376374 *                                             message
    377375 */
    378 function bbp_edit_reply_handler() {
    379 
    380     // Bail if not a POST action
    381     if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    382         return;
     376function bbp_edit_reply_handler( $action = '' ) {
    383377
    384378    // Bail if action is not bbp-edit-reply
    385     if ( empty( $_POST['action'] ) || ( 'bbp-edit-reply' !== $_POST['action'] ) )
     379    if ( 'bbp-edit-reply' !== $action )
    386380        return;
    387381
     
    10181012 * @since bbPress (r4521)
    10191013 *
     1014 * @param string $action The requested action to compare this function to
    10201015 * @uses bbPress:errors::add() To log various error messages
    10211016 * @uses bbp_get_reply() To get the reply
     
    10431038 * @uses wp_safe_redirect() To redirect to the topic link
    10441039 */
    1045 function bbp_move_reply_handler() {
    1046 
    1047     // Bail if not a POST action
    1048     if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    1049         return;
     1040function bbp_move_reply_handler( $action = '' ) {
    10501041
    10511042    // Bail if action is not 'bbp-move-reply'
    1052     if ( empty( $_POST['action'] ) || ( 'bbp-move-reply' !== $_POST['action'] ) )
     1043    if ( 'bbp-move-reply' !== $action )
    10531044        return;
    10541045
     
    13141305 * @since bbPress (r2740)
    13151306 *
     1307 * @param string $action The requested action to compare this function to
    13161308 * @uses bbp_get_reply() To get the reply
    13171309 * @uses current_user_can() To check if the user is capable of editing or
     
    13321324 * @uses bbPress::errors:add() To log the error messages
    13331325 */
    1334 function bbp_toggle_reply_handler() {
    1335 
    1336     // Bail if not a GET action
    1337     if ( 'GET' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    1338         return;
     1326function bbp_toggle_reply_handler( $action = '' ) {
    13391327
    13401328    // Bail if required GET actions aren't passed
    1341     if ( empty( $_GET['reply_id'] ) || empty( $_GET['action'] ) )
     1329    if ( empty( $_GET['reply_id'] ) )
    13421330        return;
    13431331
     
    13491337
    13501338    // Bail if actions aren't meant for this function
    1351     if ( !in_array( $_GET['action'], $possible_actions ) )
     1339    if ( !in_array( $action, $possible_actions ) )
    13521340        return;
    13531341
    13541342    $failure   = '';                         // Empty failure string
    13551343    $view_all  = false;                      // Assume not viewing all
    1356     $action    = $_GET['action'];            // What action is taking place?
    13571344    $reply_id  = (int) $_GET['reply_id'];    // What's the reply id?
    13581345    $success   = false;                      // Flag
  • trunk/includes/topics/functions.php

    r4524 r4551  
    8080 * Handles the front end topic submission
    8181 *
     82 * @param string $action The requested action to compare this function to
    8283 * @uses bbPress:errors::add() To log various error messages
    8384 * @uses bbp_verify_nonce_request() To verify the nonce and check the referer
     
    109110 *                                              messages
    110111 */
    111 function bbp_new_topic_handler() {
    112 
    113     // Bail if not a POST action
    114     if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    115         return;
     112function bbp_new_topic_handler( $action = '' ) {
    116113
    117114    // Bail if action is not bbp-new-topic
    118     if ( empty( $_POST['action'] ) || ( 'bbp-new-topic' !== $_POST['action'] ) )
     115    if ( 'bbp-new-topic' !== $action )
    119116        return;
    120117
     
    386383 * Handles the front end edit topic submission
    387384 *
     385 * @param string $action The requested action to compare this function to
    388386 * @uses bbPress:errors::add() To log various error messages
    389387 * @uses bbp_get_topic() To get the topic
     
    417415 *                                              messages
    418416 */
    419 function bbp_edit_topic_handler() {
    420 
    421     // Bail if not a POST action
    422     if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    423         return;
     417function bbp_edit_topic_handler( $action = '' ) {
    424418
    425419    // Bail if action is not bbp-edit-topic
    426     if ( empty( $_POST['action'] ) || ( 'bbp-edit-topic' !== $_POST['action'] ) )
     420    if ( 'bbp-edit-topic' !== $action )
    427421        return;
    428422
     
    10331027 * @since bbPress (r2756)
    10341028 *
     1029 * @param string $action The requested action to compare this function to
    10351030 * @uses bbPress:errors::add() To log various error messages
    10361031 * @uses bbp_get_topic() To get the topics
     
    10641059 * @uses wp_safe_redirect() To redirect to the topic link
    10651060 */
    1066 function bbp_merge_topic_handler() {
    1067 
    1068     // Bail if not a POST action
    1069     if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    1070         return;
     1061function bbp_merge_topic_handler( $action = '' ) {
    10711062
    10721063    // Bail if action is not bbp-merge-topic
    1073     if ( empty( $_POST['action'] ) || ( 'bbp-merge-topic' !== $_POST['action'] ) )
     1064    if ( 'bbp-merge-topic' !== $action )
    10741065        return;
    10751066
     
    13181309 * @since bbPress (r2756)
    13191310 *
     1311 * @param string $action The requested action to compare this function to
    13201312 * @uses bbPress:errors::add() To log various error messages
    13211313 * @uses bbp_get_reply() To get the reply
     
    13491341 * @uses wp_safe_redirect() To redirect to the topic link
    13501342 */
    1351 function bbp_split_topic_handler() {
    1352 
    1353     // Bail if not a POST action
    1354     if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    1355         return;
     1343function bbp_split_topic_handler( $action = '' ) {
    13561344
    13571345    // Bail if action is not 'bbp-split-topic'
    1358     if ( empty( $_POST['action'] ) || ( 'bbp-split-topic' !== $_POST['action'] ) )
     1346    if ( 'bbp-split-topic' !== $action )
    13591347        return;
    13601348
     
    16891677 * @since bbPress (r2768)
    16901678 *
     1679 * @param string $action The requested action to compare this function to
    16911680 * @uses bbp_verify_nonce_request() To verify the nonce and check the request
    16921681 * @uses current_user_can() To check if the current user can edit/delete tags
     
    17021691 * @uses wp_safe_redirect() To redirect to the url
    17031692 */
    1704 function bbp_edit_topic_tag_handler() {
    1705 
    1706     // Bail if not a POST action
    1707     if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    1708         return;
     1693function bbp_edit_topic_tag_handler( $action = '' ) {
    17091694
    17101695    // Bail if required POST actions aren't passed
    1711     if ( empty( $_POST['tag-id'] ) || empty( $_POST['action'] ) )
     1696    if ( empty( $_POST['tag-id'] ) )
    17121697        return;
    17131698
     
    17201705
    17211706    // Bail if actions aren't meant for this function
    1722     if ( !in_array( $_POST['action'], $possible_actions ) )
     1707    if ( !in_array( $action, $possible_actions ) )
    17231708        return;
    17241709
    17251710    // Setup vars
    1726     $action = $_POST['action'];
    17271711    $tag_id = (int) $_POST['tag-id'];
    17281712    $tag    = get_term( $tag_id, bbp_get_topic_tag_tax_id() );
     
    19201904 * @since bbPress (r2727)
    19211905 *
     1906 * @param string $action The requested action to compare this function to
    19221907 * @uses bbp_get_topic() To get the topic
    19231908 * @uses current_user_can() To check if the user is capable of editing or
     
    19451930 * @uses bbPress::errors:add() To log the error messages
    19461931 */
    1947 function bbp_toggle_topic_handler() {
    1948 
    1949     // Bail if not a GET action
    1950     if ( 'GET' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    1951         return;
     1932function bbp_toggle_topic_handler( $action = '' ) {
    19521933
    19531934    // Bail if required GET actions aren't passed
    1954     if ( empty( $_GET['topic_id'] ) || empty( $_GET['action'] ) )
     1935    if ( empty( $_GET['topic_id'] ) )
    19551936        return;
    19561937
     
    19641945
    19651946    // Bail if actions aren't meant for this function
    1966     if ( !in_array( $_GET['action'], $possible_actions ) )
     1947    if ( !in_array( $action, $possible_actions ) )
    19671948        return;
    19681949
    19691950    $failure   = '';                         // Empty failure string
    19701951    $view_all  = false;                      // Assume not viewing all
    1971     $action    = $_GET['action'];            // What action is taking place?
    19721952    $topic_id  = (int) $_GET['topic_id'];    // What's the topic id?
    19731953    $success   = false;                      // Flag
  • trunk/includes/users/functions.php

    r4346 r4551  
    417417 * Handles the front end adding and removing of favorite topics
    418418 *
     419 * @param string $action The requested action to compare this function to
    419420 * @uses bbp_get_user_id() To get the user id
    420421 * @uses bbp_verify_nonce_request() To verify the nonce and check the request
     
    431432 * @uses wp_safe_redirect() To redirect to the url
    432433 */
    433 function bbp_favorites_handler() {
     434function bbp_favorites_handler( $action = '' ) {
    434435
    435436    if ( !bbp_is_favorites_active() )
    436437        return false;
    437438
    438     // Bail if not a GET action
    439     if ( 'GET' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    440         return;
    441 
    442     // Bail if required GET actions aren't passed
    443     if ( empty( $_GET['topic_id'] ) || empty( $_GET['action'] ) )
     439    // Bail if no topic ID is passed
     440    if ( empty( $_GET['topic_id'] ) )
    444441        return;
    445442
     
    451448
    452449    // Bail if actions aren't meant for this function
    453     if ( !in_array( $_GET['action'], $possible_actions ) )
     450    if ( !in_array( $action, $possible_actions ) )
    454451        return;
    455452
    456453    // What action is taking place?
    457     $action      = $_GET['action'];
    458454    $topic_id    = intval( $_GET['topic_id'] );
    459455    $user_id     = bbp_get_user_id( 0, true, true );
     
    735731 * Handles the front end subscribing and unsubscribing topics
    736732 *
     733 * @param string $action The requested action to compare this function to
    737734 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
    738735 * @uses bbp_get_user_id() To get the user id
     
    751748 * @uses wp_safe_redirect() To redirect to the url
    752749 */
    753 function bbp_subscriptions_handler() {
     750function bbp_subscriptions_handler( $action = '' ) {
    754751
    755752    if ( !bbp_is_subscriptions_active() )
    756753        return false;
    757754
    758     // Bail if not a GET action
    759     if ( 'GET' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    760         return;
    761 
    762     // Bail if required GET actions aren't passed
    763     if ( empty( $_GET['topic_id'] ) || empty( $_GET['action'] ) )
     755    // Bail if no topic ID is passed
     756    if ( empty( $_GET['topic_id'] ) )
    764757        return;
    765758
     
    771764
    772765    // Bail if actions aren't meant for this function
    773     if ( !in_array( $_GET['action'], $possible_actions ) )
     766    if ( !in_array( $action, $possible_actions ) )
    774767        return;
    775768
    776769    // Get required data
    777     $action   = $_GET['action'];
    778770    $user_id  = bbp_get_user_id( 0, true, true );
    779771    $topic_id = intval( $_GET['topic_id'] );
     
    841833 * Handles the front end user editing
    842834 *
     835 * @param string $action The requested action to compare this function to
    843836 * @uses is_multisite() To check if it's a multisite
    844837 * @uses bbp_is_user_home() To check if the user is at home (the display page
     
    867860 * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
    868861 */
    869 function bbp_edit_user_handler() {
    870 
    871     // Bail if not a POST action
    872     if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    873         return;
     862function bbp_edit_user_handler( $action = '' ) {
    874863
    875864    // Bail if action is not 'bbp-update-user'
    876     if ( empty( $_POST['action'] ) || ( 'bbp-update-user' !== $_POST['action'] ) )
     865    if ( 'bbp-update-user' !== $action )
    877866        return;
    878867
Note: See TracChangeset for help on using the changeset viewer.