Skip to:
Content

BuddyPress.org

Ticket #6504: 6504.diff

File 6504.diff, 3.3 KB (added by sbrajesh, 10 years ago)

Do not attach actions that requires logged in privilege to wp_ajax_nopriv hook

  • src/bp-templates/bp-legacy/buddypress-functions.php

     
    134134                }
    135135
    136136                /** Ajax **************************************************************/
     137                //these ajax actions don't require users to be logged in
     138                $non_privileged_actions = array(
    137139
    138                 $actions = array(
    139 
    140140                        // Directory filters
    141141                        'blogs_filter'    => 'bp_legacy_theme_object_template_loader',
    142142                        'forums_filter'   => 'bp_legacy_theme_object_template_loader',
    143143                        'groups_filter'   => 'bp_legacy_theme_object_template_loader',
    144144                        'members_filter'  => 'bp_legacy_theme_object_template_loader',
     145                       
     146                        // Activity
     147                        'activity_get_older_updates'  => 'bp_legacy_theme_activity_template_loader',
     148                        'activity_widget_filter'      => 'bp_legacy_theme_activity_template_loader',
     149                        'get_single_activity_content' => 'bp_legacy_theme_get_single_activity_content',
     150                       
     151                );
     152               
     153
     154
     155                /**
     156                 * Register all of these AJAX handlers
     157                 *
     158                 * The "wp_ajax_" action is used for logged in users, and "wp_ajax_nopriv_"
     159                 * executes for users that aren't logged in. This is for backpat with BP <1.6.
     160                 */
     161                foreach( $non_privileged_actions as $name => $function ) {
     162                        //we need these actions for both the logged in as well as logged out users
     163                        add_action( 'wp_ajax_'        . $name, $function );
     164                        add_action( 'wp_ajax_nopriv_' . $name, $function );
     165                }
     166               
     167                //only for logged in users
     168                $actions = array(
     169
    145170                        'messages_filter' => 'bp_legacy_theme_messages_template_loader',
    146171                        'invite_filter'   => 'bp_legacy_theme_invite_template_loader',
    147172                        'requests_filter' => 'bp_legacy_theme_requests_template_loader',
     
    152177                        'reject_friendship' => 'bp_legacy_theme_ajax_reject_friendship',
    153178
    154179                        // Activity
    155                         'activity_get_older_updates'  => 'bp_legacy_theme_activity_template_loader',
    156180                        'activity_mark_fav'           => 'bp_legacy_theme_mark_activity_favorite',
    157181                        'activity_mark_unfav'         => 'bp_legacy_theme_unmark_activity_favorite',
    158                         'activity_widget_filter'      => 'bp_legacy_theme_activity_template_loader',
    159182                        'delete_activity'             => 'bp_legacy_theme_delete_activity',
    160183                        'delete_activity_comment'     => 'bp_legacy_theme_delete_activity_comment',
    161                         'get_single_activity_content' => 'bp_legacy_theme_get_single_activity_content',
    162184                        'new_activity_comment'        => 'bp_legacy_theme_new_activity_comment',
    163185                        'post_update'                 => 'bp_legacy_theme_post_update',
    164186                        'bp_spam_activity'            => 'bp_legacy_theme_spam_activity',
     
    181203                if ( bp_is_active( 'messages', 'star' ) ) {
    182204                        $actions['messages_star'] = 'bp_legacy_theme_ajax_messages_star_handler';
    183205                }
    184 
    185                 /**
    186                  * Register all of these AJAX handlers
    187                  *
    188                  * The "wp_ajax_" action is used for logged in users, and "wp_ajax_nopriv_"
    189                  * executes for users that aren't logged in. This is for backpat with BP <1.6.
    190                  */
     206               
    191207                foreach( $actions as $name => $function ) {
    192208                        add_action( 'wp_ajax_'        . $name, $function );
    193                         add_action( 'wp_ajax_nopriv_' . $name, $function );
    194209                }
    195210
    196211                add_filter( 'bp_ajax_querystring', 'bp_legacy_theme_ajax_querystring', 10, 2 );