Skip to:
Content

BuddyPress.org

Ticket #7684: 7684-1.diff

File 7684-1.diff, 16.2 KB (added by espellcaste, 7 years ago)
  • src/bp-core/bp-core-attachments.php

    diff --git src/bp-core/bp-core-attachments.php src/bp-core/bp-core-attachments.php
    index 64344bf9e..78bb6cfef 100644
    function bp_attachments_cover_image_generate_file( $args = array(), $cover_image 
    11891189 *                     error message otherwise.
    11901190 */
    11911191function bp_attachments_cover_image_ajax_upload() {
    1192         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     1192        if ( ! bp_is_post_request() ) {
    11931193                wp_die();
    11941194        }
    11951195
    add_action( 'wp_ajax_bp_cover_image_upload', 'bp_attachments_cover_image_ajax_up 
    13781378 *                     error message otherwise.
    13791379 */
    13801380function bp_attachments_cover_image_ajax_delete() {
    1381         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     1381        if ( ! bp_is_post_request() ) {
    13821382                wp_send_json_error();
    13831383        }
    13841384
  • src/bp-core/bp-core-avatars.php

    diff --git src/bp-core/bp-core-avatars.php src/bp-core/bp-core-avatars.php
    index 293c8725e..eea116217 100644
    function bp_core_delete_existing_avatar( $args = '' ) { 
    809809 *                     error message otherwise.
    810810 */
    811811function bp_avatar_ajax_delete() {
    812         // Bail if not a POST action.
    813         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     812        if ( ! bp_is_post_request() ) {
    814813                wp_send_json_error();
    815814        }
    816815
    function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) { 
    952951 *                     error message otherwise.
    953952 */
    954953function bp_avatar_ajax_upload() {
    955         // Bail if not a POST action.
    956         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     954        if ( ! bp_is_post_request() ) {
    957955                wp_die();
    958956        }
    959957
    function bp_core_avatar_handle_crop( $args = '' ) { 
    12371235 *                     error message otherwise.
    12381236 */
    12391237function bp_avatar_ajax_set() {
    1240         // Bail if not a POST action.
    1241         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     1238        if ( ! bp_is_post_request() ) {
    12421239                wp_send_json_error();
    12431240        }
    12441241
  • src/bp-settings/bp-settings-actions.php

    diff --git src/bp-settings/bp-settings-actions.php src/bp-settings/bp-settings-actions.php
    index fef2d3122..ecf3cdba1 100644
    defined( 'ABSPATH' ) || exit; 
    2727 * @global BuddyPress $bp
    2828 */
    2929function bp_settings_action_general() {
    30 
    31         // Bail if not a POST action.
    32         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     30        if ( ! bp_is_post_request() ) {
    3331                return;
     32        }
    3433
    3534        // Bail if no submit action.
    36         if ( ! isset( $_POST['submit'] ) )
     35        if ( ! isset( $_POST['submit'] ) ) {
    3736                return;
     37        }
    3838
    3939        // Bail if not in settings.
    40         if ( ! bp_is_settings_component() || ! bp_is_current_action( 'general' ) )
     40        if ( ! bp_is_settings_component() || ! bp_is_current_action( 'general' ) ) {
    4141                return;
     42        }
    4243
    4344        // 404 if there are any additional action variables attached
    4445        if ( bp_action_variables() ) {
    add_action( 'bp_actions', 'bp_settings_action_general' ); 
    259260 * @since 1.6.0
    260261 */
    261262function bp_settings_action_notifications() {
    262 
    263         // Bail if not a POST action.
    264         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     263        if ( ! bp_is_post_request() ) {
    265264                return;
     265        }
    266266
    267267        // Bail if no submit action.
    268         if ( ! isset( $_POST['submit'] ) )
     268        if ( ! isset( $_POST['submit'] ) ) {
    269269                return;
     270        }
    270271
    271272        // Bail if not in settings.
    272         if ( ! bp_is_settings_component() || ! bp_is_current_action( 'notifications' ) )
     273        if ( ! bp_is_settings_component() || ! bp_is_current_action( 'notifications' ) ) {
    273274                return false;
     275        }
    274276
    275277        // 404 if there are any additional action variables attached
    276278        if ( bp_action_variables() ) {
    add_action( 'bp_actions', 'bp_settings_action_notifications' ); 
    306308 * @since 1.6.0
    307309 */
    308310function bp_settings_action_capabilities() {
    309 
    310         // Bail if not a POST action.
    311         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     311        if ( ! bp_is_post_request() ) {
    312312                return;
     313        }
    313314
    314315        // Bail if no submit action.
    315         if ( ! isset( $_POST['capabilities-submit'] ) )
     316        if ( ! isset( $_POST['capabilities-submit'] ) ) {
    316317                return;
     318        }
    317319
    318320        // Bail if not in settings.
    319         if ( ! bp_is_settings_component() || ! bp_is_current_action( 'capabilities' ) )
     321        if ( ! bp_is_settings_component() || ! bp_is_current_action( 'capabilities' ) ) {
    320322                return false;
     323        }
    321324
    322325        // 404 if there are any additional action variables attached
    323326        if ( bp_action_variables() ) {
    add_action( 'bp_actions', 'bp_settings_action_capabilities' ); 
    380383 * @since 1.6.0
    381384 */
    382385function bp_settings_action_delete_account() {
    383 
    384         // Bail if not a POST action.
    385         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     386        if ( ! bp_is_post_request() ) {
    386387                return;
     388        }
    387389
    388390        // Bail if no submit action.
    389         if ( ! isset( $_POST['delete-account-understand'] ) )
     391        if ( ! isset( $_POST['delete-account-understand'] ) ) {
    390392                return;
     393        }
    391394
    392395        // Bail if not in settings.
    393         if ( ! bp_is_settings_component() || ! bp_is_current_action( 'delete-account' ) )
     396        if ( ! bp_is_settings_component() || ! bp_is_current_action( 'delete-account' ) ) {
    394397                return false;
     398        }
    395399
    396400        // 404 if there are any additional action variables attached
    397401        if ( bp_action_variables() ) {
  • src/bp-templates/bp-legacy/buddypress-functions.php

    diff --git src/bp-templates/bp-legacy/buddypress-functions.php src/bp-templates/bp-legacy/buddypress-functions.php
    index d0cd488e0..c7c3cd31a 100644
    function bp_legacy_theme_ajax_querystring( $query_string, $object ) { 
    779779 * @return string|null Prints template loop for the specified object
    780780 */
    781781function bp_legacy_theme_object_template_loader() {
    782         // Bail if not a POST action.
    783         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     782        if ( ! bp_is_post_request() ) {
    784783                return;
     784        }
    785785
    786786        // Bail if no object passed.
    787         if ( empty( $_POST['object'] ) )
     787        if ( empty( $_POST['object'] ) ) {
    788788                return;
     789        }
    789790
    790791        // Sanitize the object.
    791792        $object = sanitize_title( $_POST['object'] );
    792793
    793794        // Bail if object is not an active component to prevent arbitrary file inclusion.
    794         if ( ! bp_is_active( $object ) )
     795        if ( ! bp_is_active( $object ) ) {
    795796                return;
     797        }
    796798
    797799        /**
    798800         * AJAX requests happen too early to be seen by bp_update_is_directory()
    function bp_legacy_theme_requests_template_loader() { 
    859861 *                     for the Activity component) and 'feed_url' (URL to the relevant RSS feed).
    860862 */
    861863function bp_legacy_theme_activity_template_loader() {
    862         // Bail if not a POST action.
    863         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     864        if ( ! bp_is_post_request() ) {
    864865                return;
     866        }
    865867
    866868        $scope = '';
    867869        if ( ! empty( $_POST['scope'] ) )
    function bp_legacy_theme_activity_template_loader() { 
    920922function bp_legacy_theme_post_update() {
    921923        $bp = buddypress();
    922924
    923         // Bail if not a POST action.
    924         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     925        if ( ! bp_is_post_request() ) {
    925926                return;
     927        }
    926928
    927929        // Check the nonce.
    928930        check_admin_referer( 'post_update', '_wpnonce_post_update' );
    function bp_legacy_theme_new_activity_comment() { 
    10091011
    10101012        $bp = buddypress();
    10111013
    1012         // Bail if not a POST action.
    1013         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     1014        if ( ! bp_is_post_request() ) {
    10141015                return;
    10151016        }
    10161017
    function bp_legacy_theme_new_activity_comment() { 
    10781079 * @return mixed String on error, void on success.
    10791080 */
    10801081function bp_legacy_theme_delete_activity() {
    1081         // Bail if not a POST action.
    1082         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     1082        if ( ! bp_is_post_request() ) {
    10831083                return;
     1084        }
    10841085
    10851086        // Check the nonce.
    10861087        check_admin_referer( 'bp_activity_delete_link' );
    function bp_legacy_theme_delete_activity() { 
    11161117 * @return mixed String on error, void on success.
    11171118 */
    11181119function bp_legacy_theme_delete_activity_comment() {
    1119         // Bail if not a POST action.
    1120         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     1120        if ( ! bp_is_post_request() ) {
    11211121                return;
     1122        }
    11221123
    11231124        // Check the nonce.
    11241125        check_admin_referer( 'bp_activity_delete_link' );
    function bp_legacy_theme_delete_activity_comment() { 
    11581159function bp_legacy_theme_spam_activity() {
    11591160        $bp = buddypress();
    11601161
    1161         // Bail if not a POST action.
    1162         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     1162        if ( ! bp_is_post_request() ) {
    11631163                return;
     1164        }
    11641165
    11651166        // Check that user is logged in, Activity Streams are enabled, and Akismet is present.
    11661167        if ( ! is_user_logged_in() || ! bp_is_active( 'activity' ) || empty( $bp->activity->akismet ) )
    function bp_legacy_theme_spam_activity() { 
    12031204 */
    12041205function bp_legacy_theme_mark_activity_favorite() {
    12051206        // Bail if not a POST action.
    1206         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     1207        if ( ! bp_is_post_request() ) {
    12071208                return;
     1209        }
    12081210
    12091211        if ( ! isset( $_POST['nonce'] ) ) {
    12101212                return;
    function bp_legacy_theme_mark_activity_favorite() { 
    12321234 * @return string|null HTML
    12331235 */
    12341236function bp_legacy_theme_unmark_activity_favorite() {
    1235         // Bail if not a POST action.
    1236         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     1237        if ( ! bp_is_post_request() ) {
    12371238                return;
     1239        }
    12381240
    12391241        if ( ! isset( $_POST['nonce'] ) ) {
    12401242                return;
    function bp_legacy_theme_unmark_activity_favorite() { 
    12631265 * @return string|null HTML
    12641266 */
    12651267function bp_legacy_theme_get_single_activity_content() {
    1266         // Bail if not a POST action.
    1267         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     1268        if ( ! bp_is_post_request() ) {
    12681269                return;
     1270        }
    12691271
    12701272        $activity_array = bp_activity_get_specific( array(
    12711273                'activity_ids'     => $_POST['activity_id'],
    function bp_legacy_theme_get_single_activity_content() { 
    13031305 * @todo Audit return types
    13041306 */
    13051307function bp_legacy_theme_ajax_invite_user() {
    1306         // Bail if not a POST action.
    1307         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     1308        if ( ! bp_is_post_request() ) {
    13081309                return;
     1310        }
    13091311
    13101312        check_ajax_referer( 'groups_invite_uninvite_user' );
    13111313
    function bp_legacy_theme_ajax_invite_user() { 
    13861388 * @return string|null HTML
    13871389 */
    13881390function bp_legacy_theme_ajax_addremove_friend() {
    1389 
    1390         // Bail if not a POST action.
    1391         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     1391        if ( ! bp_is_post_request() ) {
    13921392                return;
     1393        }
    13931394
    13941395        // Cast fid as an integer.
    13951396        $friend_id = (int) $_POST['fid'];
    function bp_legacy_theme_ajax_addremove_friend() { 
    14401441 * @return mixed String on error, void on success.
    14411442 */
    14421443function bp_legacy_theme_ajax_accept_friendship() {
    1443         // Bail if not a POST action.
    1444         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     1444        if ( ! bp_is_post_request() ) {
    14451445                return;
     1446        }
    14461447
    14471448        check_admin_referer( 'friends_accept_friendship' );
    14481449
    function bp_legacy_theme_ajax_accept_friendship() { 
    14601461 * @return mixed String on error, void on success.
    14611462 */
    14621463function bp_legacy_theme_ajax_reject_friendship() {
    1463         // Bail if not a POST action.
    1464         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     1464        if ( ! bp_is_post_request() ) {
    14651465                return;
     1466        }
    14661467
    14671468        check_admin_referer( 'friends_reject_friendship' );
    14681469
    function bp_legacy_theme_ajax_reject_friendship() { 
    14801481 * @return string|null HTML
    14811482 */
    14821483function bp_legacy_theme_ajax_joinleave_group() {
    1483         // Bail if not a POST action.
    1484         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     1484        if ( ! bp_is_post_request() ) {
    14851485                return;
     1486        }
    14861487
    14871488        // Cast gid as integer.
    14881489        $group_id = (int) $_POST['gid'];
    function bp_legacy_theme_ajax_joinleave_group() { 
    15511552 * @return mixed String on error, void on success.
    15521553 */
    15531554function bp_legacy_theme_ajax_close_notice() {
    1554         // Bail if not a POST action.
    1555         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     1555        if ( ! bp_is_post_request() ) {
    15561556                return;
     1557        }
    15571558
    15581559        $nonce_check = isset( $_POST['nonce'] ) && wp_verify_nonce( wp_unslash( $_POST['nonce'] ), 'bp_messages_close_notice' );
    15591560
    function bp_legacy_theme_ajax_close_notice() { 
    15831584 * @return string|null HTML
    15841585 */
    15851586function bp_legacy_theme_ajax_messages_send_reply() {
    1586         // Bail if not a POST action.
    1587         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
     1587        if ( ! bp_is_post_request() ) {
    15881588                return;
     1589        }
    15891590
    15901591        check_ajax_referer( 'messages_send_message' );
    15911592
  • src/bp-templates/bp-nouveau/includes/activity/ajax.php

    diff --git src/bp-templates/bp-nouveau/includes/activity/ajax.php src/bp-templates/bp-nouveau/includes/activity/ajax.php
    index 3c5d210c2..730c43769 100644
    bp_nouveau_register_ajax_actions( array( 
    3333 * @return string JSON reply
    3434 */
    3535function bp_nouveau_ajax_mark_activity_favorite() {
    36         // Bail if not a POST action.
    37         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     36        if ( ! bp_is_post_request() ) {
    3837                wp_send_json_error();
    3938        }
    4039
    function bp_nouveau_ajax_mark_activity_favorite() { 
    7473 * @return string JSON reply
    7574 */
    7675function bp_nouveau_ajax_unmark_activity_favorite() {
    77         // Bail if not a POST action.
    78         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     76        if ( ! bp_is_post_request() ) {
    7977                wp_send_json_error();
    8078        }
    8179
    function bp_nouveau_ajax_unmark_activity_favorite() { 
    111109 * @return string JSON reply
    112110 */
    113111function bp_nouveau_ajax_clear_new_mentions() {
    114         // Bail if not a POST action.
    115         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     112        if ( ! bp_is_post_request() ) {
    116113                wp_send_json_error();
    117114        }
    118115
    function bp_nouveau_ajax_delete_activity() { 
    141138        );
    142139
    143140        // Bail if not a POST action.
    144         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     141        if ( ! bp_is_post_request() ) {
    145142                wp_send_json_error( $response );
    146143        }
    147144
    function bp_nouveau_ajax_get_single_activity_content() { 
    213210        );
    214211
    215212        // Bail if not a POST action.
    216         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     213        if ( ! bp_is_post_request() ) {
    217214                wp_send_json_error( $response );
    218215        }
    219216
    function bp_nouveau_ajax_new_activity_comment() { 
    272269        );
    273270
    274271        // Bail if not a POST action.
    275         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     272        if ( ! bp_is_post_request() ) {
    276273                wp_send_json_error( $response );
    277274        }
    278275
    function bp_nouveau_ajax_spam_activity() { 
    497494        );
    498495
    499496        // Bail if not a POST action.
    500         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     497        if ( ! bp_is_post_request() ) {
    501498                wp_send_json_error( $response );
    502499        }
    503500
  • src/bp-templates/bp-nouveau/includes/ajax.php

    diff --git src/bp-templates/bp-nouveau/includes/ajax.php src/bp-templates/bp-nouveau/includes/ajax.php
    index aa5281cdb..e8d31e664 100644
    defined( 'ABSPATH' ) || exit; 
    1515 * @since 1.0.0
    1616 */
    1717function bp_nouveau_ajax_object_template_loader() {
    18         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     18        if ( ! bp_is_post_request() ) {
    1919                wp_send_json_error();
    2020        }
    2121
  • src/bp-templates/bp-nouveau/includes/friends/ajax.php

    diff --git src/bp-templates/bp-nouveau/includes/friends/ajax.php src/bp-templates/bp-nouveau/includes/friends/ajax.php
    index 0cff3204e..ffc9a00ee 100644
    function bp_nouveau_ajax_addremove_friend() { 
    3535        );
    3636
    3737        // Bail if not a POST action.
    38         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     38        if ( ! bp_is_post_request() ) {
    3939                wp_send_json_error( $response );
    4040        }
    4141
  • src/bp-templates/bp-nouveau/includes/groups/ajax.php

    diff --git src/bp-templates/bp-nouveau/includes/groups/ajax.php src/bp-templates/bp-nouveau/includes/groups/ajax.php
    index 89924d718..ab11d29aa 100644
    function bp_nouveau_ajax_joinleave_group() { 
    3939        );
    4040
    4141        // Bail if not a POST action.
    42         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) || empty( $_POST['action'] ) ) {
     42        if ( ! bp_is_post_request() || empty( $_POST['action'] ) ) {
    4343                wp_send_json_error( $response );
    4444        }
    4545
  • src/bp-xprofile/bp-xprofile-actions.php

    diff --git src/bp-xprofile/bp-xprofile-actions.php src/bp-xprofile/bp-xprofile-actions.php
    index f833c2ee1..39785fe86 100644
    add_action( 'bp_actions', 'xprofile_action_delete_avatar' ); 
    5454function bp_xprofile_action_settings() {
    5555
    5656        // Bail if not a POST action.
    57         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
     57        if ( ! bp_is_post_request() ) {
    5858                return;
    5959        }
    6060