Skip to:
Content

BuddyPress.org

Ticket #3985: 3985-01.patch

File 3985-01.patch, 46.4 KB (added by DJPaul, 12 years ago)
  • bp-core/bp-core-cssjs.php

    function bp_core_add_cropper_inline_css() { 
    129129 *
    130130 * Adds AJAX target URL so themes can access the WordPress AJAX functionality.
    131131 *
    132  * @package BuddyPress Core
     132 * @since 1.1
    133133 */
    134134function bp_core_add_ajax_url_js() {
    135135?>
    136136
    137         <script type="text/javascript">var ajaxurl = "<?php echo site_url( 'wp-load.php' ); ?>";</script>
     137        <script type="text/javascript">var ajaxurl = '<?php echo admin_url( 'admin-ajax.php' ); ?>';</script>
    138138
    139139<?php
    140140}
  • bp-core/bp-core-functions.php

    function bp_core_load_buddypress_textdomain() { 
    699699}
    700700add_action ( 'bp_init', 'bp_core_load_buddypress_textdomain', 2 );
    701701
    702 function bp_core_add_ajax_hook() {
    703         // Theme only, we already have the wp_ajax_ hook firing in wp-admin
    704         if ( !defined( 'WP_ADMIN' ) && isset( $_REQUEST['action'] ) )
    705                 do_action( 'wp_ajax_' . $_REQUEST['action'] );
    706 }
    707 add_action( 'bp_init', 'bp_core_add_ajax_hook', 20 );
    708 
    709702/**
    710703 * Initializes {@link BP_Embed} after everything is loaded.
    711704 *
  • bp-core/deprecated/1.6.php

    function bp_core_is_user_spammer( $user_id = 0 ) { 
    5353 * Blogs functions
    5454 */
    5555
    56 /*
     56/**
    5757 * @deprecated 1.6
    5858 * @deprecated No longer used; see bp_blogs_transition_activity_status()
    5959 */
    function bp_blogs_manage_comment( $comment_id, $comment_status ) { 
    6565 * Core functions
    6666 */
    6767
    68 /*
     68/**
    6969 * @deprecated 1.6
    7070 * @deprecated No longer used; see BP_Admin::admin_menus()
    7171 */
    function bp_core_add_admin_menu() { 
    7373        _deprecated_function( __FUNCTION__, '1.6', 'No longer used' );
    7474}
    7575
     76/**
     77 * @deprecated 1.6
     78 * @deprecated No longer used. We do ajax properly now.
     79 */
     80function bp_core_add_ajax_hook() {
     81        _deprecated_function( __FUNCTION__, '1.6', 'No longer used' );
     82}
    7683
    7784/**
    7885 * Members functions
  • bp-themes/bp-default/_inc/ajax.php

     
    11<?php
    2 
    3 /***
     2/**
    43 * AJAX Functions
    54 *
    6  * All of these functions enhance the responsiveness of the user interface in the default
    7  * theme by adding AJAX functionality.
     5 * All of these functions enhance the responsiveness of the user interface in
     6 * the default theme by adding AJAX functionality.
     7 *
     8 * For more information on how the custom AJAX functions work, see
     9 * http://codex.wordpress.org/AJAX_in_Plugins.
     10 *
     11 * @package BuddyPress
     12 * @since 1.2
     13 * @subpackage BP-Default
    814 */
    915
    10 /***
     16// Exit if accessed directly
     17if ( ! defined( 'ABSPATH' ) ) exit;
     18
     19/**
     20 * Register AJAX handlers for BP Default theme functionality.
     21 *
     22 * This function is registered to the after_setup_theme hook with priority 20 as
     23 * this file is included in a function hooked to after_setup_theme at priority 10.
     24 *
     25 * @since BuddyPress (1.6)
     26 */
     27function bp_dtheme_register_actions() {
     28        $actions = array(
     29                // Directory filters
     30                'blogs_filter'    => 'bp_dtheme_object_template_loader',
     31                'forums_filter'   => 'bp_dtheme_object_template_loader',
     32                'groups_filter'   => 'bp_dtheme_object_template_loader',
     33                'members_filter'  => 'bp_dtheme_object_template_loader',
     34                'messages_filter' => 'bp_dtheme_messages_template_loader',
     35
     36                // Friends
     37                'accept_friendship' => 'bp_dtheme_ajax_accept_friendship',
     38                'addremove_friend'  => 'bp_dtheme_ajax_addremove_friend',
     39                'reject_friendship' => 'bp_dtheme_ajax_reject_friendship',
     40
     41                // Activity
     42                'activity_get_older_updates'  => 'bp_dtheme_activity_template_loader',
     43                'activity_mark_fav'           => 'bp_dtheme_mark_activity_favorite',
     44                'activity_mark_unfav'         => 'bp_dtheme_unmark_activity_favorite',
     45                'activity_widget_filter'      => 'bp_dtheme_activity_template_loader',
     46                'delete_activity'             => 'bp_dtheme_delete_activity',
     47                'delete_activity_comment'     => 'bp_dtheme_delete_activity_comment',
     48                'get_single_activity_content' => 'bp_dtheme_get_single_activity_content',
     49                'new_activity_comment'        => 'bp_dtheme_new_activity_comment',
     50                'post_update'                 => 'bp_dtheme_post_update',
     51                'bp_spam_activity'            => 'bp_dtheme_spam_activity',
     52                'bp_spam_activity_comment'    => 'bp_dtheme_spam_activity',
     53
     54                // Groups
     55                'groups_invite_user' => 'bp_dtheme_ajax_invite_user',
     56                'joinleave_group'    => 'bp_dtheme_ajax_joinleave_group',
     57
     58                // Messages
     59                'messages_autocomplete_results' => 'bp_dtheme_ajax_messages_autocomplete_results',
     60                'messages_close_notice'         => 'bp_dtheme_ajax_close_notice',
     61                'messages_delete'               => 'bp_dtheme_ajax_messages_delete',
     62                'messages_markread'             => 'bp_dtheme_ajax_message_markread',
     63                'messages_markunread'           => 'bp_dtheme_ajax_message_markunread',
     64                'messages_send_reply'           => 'bp_dtheme_ajax_messages_send_reply',
     65        );
     66
     67        /**
     68         * Register all of these AJAX handlers
     69         *
     70         * The "wp_ajax_" action is used for logged in users, and "wp_ajax_nopriv_"
     71         * executes for users that aren't logged in. This is for backpat with BP <1.6.
     72         */
     73        foreach( $actions as $name => $function ) {
     74                add_action( 'wp_ajax_'        . $name, $function );
     75                add_action( 'wp_ajax_nopriv_' . $name, $function );
     76        }
     77}
     78add_action( 'after_setup_theme', 'bp_dtheme_register_actions', 20 );
     79
     80/**
    1181 * This function looks scarier than it actually is. :)
    1282 * Each object loop (activity/members/groups/blogs/forums) contains default parameters to
    1383 * show specific information based on the page we are currently looking at.
    1484 * The following function will take into account any cookies set in the JS and allow us
    1585 * to override the parameters sent. That way we can change the results returned without reloading the page.
    1686 * By using cookies we can also make sure that user settings are retained across page loads.
     87 *
     88 * @return string Query string for the activity/members/groups/blogs/forums loops
     89 * @since BuddyPress (1.2)
    1790 */
    1891function bp_dtheme_ajax_querystring( $query_string, $object ) {
    19         global $bp;
    20 
    2192        if ( empty( $object ) )
    22                 return false;
     93                return '';
    2394
    24         /* Set up the cookies passed on this AJAX request. Store a local var to avoid conflicts */
    25         if ( !empty( $_POST['cookie'] ) )
     95        // Set up the cookies passed on this AJAX request. Store a local var to avoid conflicts
     96        if ( ! empty( $_POST['cookie'] ) )
    2697                $_BP_COOKIE = wp_parse_args( str_replace( '; ', '&', urldecode( $_POST['cookie'] ) ) );
    2798        else
    2899                $_BP_COOKIE = &$_COOKIE;
    29100
    30         $qs = false;
     101        $qs = array();
    31102
    32         /***
     103        /**
    33104         * Check if any cookie values are set. If there are then override the default params passed to the
    34105         * template loop
    35106         */
    36         if ( !empty( $_BP_COOKIE['bp-' . $object . '-filter'] ) && '-1' != $_BP_COOKIE['bp-' . $object . '-filter'] ) {
    37                 $qs[] = 'type=' . $_BP_COOKIE['bp-' . $object . '-filter'];
    38                 $qs[] = 'action=' . $_BP_COOKIE['bp-' . $object . '-filter']; // Activity stream filtering on action
     107
     108        // Activity stream filtering on action
     109        if ( ! empty( $_BP_COOKIE['bp-' . $object . '-filter'] ) && '-1' != $_BP_COOKIE['bp-' . $object . '-filter'] ) {
     110                $qs[] = 'type='   . $_BP_COOKIE['bp-' . $object . '-filter'];
     111                $qs[] = 'action=' . $_BP_COOKIE['bp-' . $object . '-filter'];
    39112        }
    40113
    41         if ( !empty( $_BP_COOKIE['bp-' . $object . '-scope'] ) ) {
     114        if ( ! empty( $_BP_COOKIE['bp-' . $object . '-scope'] ) ) {
    42115                if ( 'personal' == $_BP_COOKIE['bp-' . $object . '-scope'] ) {
    43116                        $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
    44117                        $qs[] = 'user_id=' . $user_id;
    45118                }
    46                 if ( 'all' != $_BP_COOKIE['bp-' . $object . '-scope'] && !bp_displayed_user_id() && !$bp->is_single_item )
    47                         $qs[] = 'scope=' . $_BP_COOKIE['bp-' . $object . '-scope']; // Activity stream scope only on activity directory.
     119
     120                // Activity stream scope only on activity directory.
     121                if ( 'all' != $_BP_COOKIE['bp-' . $object . '-scope'] && ! bp_displayed_user_id() && ! bp_is_single_item() )
     122                        $qs[] = 'scope=' . $_BP_COOKIE['bp-' . $object . '-scope'];
    48123        }
    49124
    50         /* If page and search_terms have been passed via the AJAX post request, use those */
    51         if ( !empty( $_POST['page'] ) && '-1' != $_POST['page'] )
     125        // If page and search_terms have been passed via the AJAX post request, use those.
     126        if ( ! empty( $_POST['page'] ) && '-1' != $_POST['page'] )
    52127                $qs[] = 'page=' . $_POST['page'];
    53128
    54129        $object_search_text = bp_get_search_default_text( $object );
    55         if ( !empty( $_POST['search_terms'] ) && $object_search_text != $_POST['search_terms'] && 'false' != $_POST['search_terms'] && 'undefined' != $_POST['search_terms'] )
     130        if ( ! empty( $_POST['search_terms'] ) && $object_search_text != $_POST['search_terms'] && 'false' != $_POST['search_terms'] && 'undefined' != $_POST['search_terms'] )
    56131                $qs[] = 'search_terms=' . $_POST['search_terms'];
    57132
    58         /* Now pass the querystring to override default values. */
     133        // Now pass the querystring to override default values.
    59134        $query_string = empty( $qs ) ? '' : join( '&', (array) $qs );
    60135
    61136        $object_filter = '';
    function bp_dtheme_ajax_querystring( $query_string, $object ) { 
    82157}
    83158add_filter( 'bp_ajax_querystring', 'bp_dtheme_ajax_querystring', 10, 2 );
    84159
    85 /* This function will simply load the template loop for the current object. On an AJAX request */
     160/**
     161 * Load the template loop for the current object.
     162 *
     163 * @return string Prints template loop for the specified object
     164 * @since BuddyPress (1.2)
     165 */
    86166function bp_dtheme_object_template_loader() {
    87 
    88167        // Bail if not a POST action
    89168        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    90169                return;
    function bp_dtheme_object_template_loader() { 
    95174         * context. Without this check, templates will load the 'single' version
    96175         * of themselves rather than the directory version.
    97176         */
    98         if ( !bp_current_action() )
     177
     178        if ( ! bp_current_action() )
    99179                bp_update_is_directory( true, bp_current_component() );
    100180
    101181        // Sanitize the post object
    function bp_dtheme_object_template_loader() { 
    103183
    104184        // Locate the object template
    105185        locate_template( array( "$object/$object-loop.php" ), true );
     186        exit;
    106187}
    107 add_action( 'wp_ajax_members_filter',  'bp_dtheme_object_template_loader'   );
    108 add_action( 'wp_ajax_groups_filter',   'bp_dtheme_object_template_loader'   );
    109 add_action( 'wp_ajax_blogs_filter',    'bp_dtheme_object_template_loader'   );
    110 add_action( 'wp_ajax_forums_filter',   'bp_dtheme_object_template_loader'   );
    111 add_action( 'wp_ajax_messages_filter', 'bp_dtheme_messages_template_loader' );
    112 
    113 /*
    114  * Load messages when searched on the private message page
    115  */
    116188
     189/**
     190 * Load messages template loop when searched on the private message page
     191 *
     192 * @return string Prints template loop for the Messages component
     193 * @since BuddyPress (1.6)
     194 */
    117195function bp_dtheme_messages_template_loader(){
    118     locate_template( array( 'members/single/messages/messages-loop.php' ), true );
     196        locate_template( array( 'members/single/messages/messages-loop.php' ), true );
     197        exit;
    119198}
    120199
    121 // This function will load the activity loop template when activity is requested via AJAX
     200/**
     201 * Load the activity loop template when activity is requested via AJAX,
     202 *
     203 * @return string JSON object containing 'contents' (output of the template loop for the Activity component) and 'feed_url' (URL to the relevant RSS feed).
     204 * @since BuddyPress (1.2)
     205 */
    122206function bp_dtheme_activity_template_loader() {
    123 
    124207        // Bail if not a POST action
    125208        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    126209                return;
    127210
    128211        $scope = '';
    129         if ( !empty( $_POST['scope'] ) )
     212        if ( ! empty( $_POST['scope'] ) )
    130213                $scope = $_POST['scope'];
    131214
    132215        // We need to calculate and return the feed URL for each scope
    function bp_dtheme_activity_template_loader() { 
    149232                        break;
    150233        }
    151234
    152         /* Buffer the loop in the template to a var for JS to spit out. */
     235        // Buffer the loop in the template to a var for JS to spit out.
    153236        ob_start();
    154237        locate_template( array( 'activity/activity-loop.php' ), true );
    155238        $result['contents'] = ob_get_contents();
    156239        $result['feed_url'] = apply_filters( 'bp_dtheme_activity_feed_url', $feed_url, $scope );
    157240        ob_end_clean();
    158241
    159         echo json_encode( $result );
     242        exit( json_encode( $result ) );
    160243}
    161 add_action( 'wp_ajax_activity_widget_filter', 'bp_dtheme_activity_template_loader' );
    162 add_action( 'wp_ajax_activity_get_older_updates', 'bp_dtheme_activity_template_loader' );
    163244
    164 /* AJAX update posting */
     245/**
     246 * Processes Activity updates received via a POST request.
     247 *
     248 * @return string HTML
     249 * @since BuddyPress (1.2)
     250 */
    165251function bp_dtheme_post_update() {
    166 
    167252        // Bail if not a POST action
    168253        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    169254                return;
    function bp_dtheme_post_update() { 
    171256        // Check the nonce
    172257        check_admin_referer( 'post_update', '_wpnonce_post_update' );
    173258
    174         if ( !is_user_logged_in() ) {
    175                 echo '-1';
    176                 return false;
    177         }
     259        if ( ! is_user_logged_in() )
     260                exit( '-1' );
    178261
    179         if ( empty( $_POST['content'] ) ) {
    180                 echo '-1<div id="message" class="error"><p>' . __( 'Please enter some content to post.', 'buddypress' ) . '</p></div>';
    181                 return false;
    182         }
     262        if ( empty( $_POST['content'] ) )
     263                exit( '-1<div id="message" class="error"><p>' . __( 'Please enter some content to post.', 'buddypress' ) . '</p></div>' );
    183264
    184265        $activity_id = 0;
    185266        if ( empty( $_POST['object'] ) && bp_is_active( 'activity' ) ) {
    186267                $activity_id = bp_activity_post_update( array( 'content' => $_POST['content'] ) );
    187268
    188269        } elseif ( $_POST['object'] == 'groups' ) {
    189                 if ( !empty( $_POST['item_id'] ) && bp_is_active( 'groups' ) )
     270                if ( ! empty( $_POST['item_id'] ) && bp_is_active( 'groups' ) )
    190271                        $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $_POST['item_id'] ) );
    191272
    192273        } else {
    193274                $activity_id = apply_filters( 'bp_activity_custom_update', $_POST['object'], $_POST['item_id'], $_POST['content'] );
    194275        }
    195276
    196         if ( empty( $activity_id ) ) {
    197                 echo '-1<div id="message" class="error"><p>' . __( 'There was a problem posting your update, please try again.', 'buddypress' ) . '</p></div>';
    198                 return false;
     277        if ( empty( $activity_id ) )
     278                exit( '-1<div id="message" class="error"><p>' . __( 'There was a problem posting your update, please try again.', 'buddypress' ) . '</p></div>' );
     279
     280        if ( bp_has_activities ( 'include=' . $activity_id ) ) {
     281                while ( bp_activities() ) {
     282                        bp_the_activity();
     283                        locate_template( array( 'activity/entry.php' ), true );
     284                }
    199285        }
    200286
    201         if ( bp_has_activities ( 'include=' . $activity_id ) ) : ?>
    202                 <?php while ( bp_activities() ) : bp_the_activity(); ?>
    203                         <?php locate_template( array( 'activity/entry.php' ), true ); ?>
    204                 <?php endwhile; ?>
    205          <?php endif;
     287        exit;
    206288}
    207 add_action( 'wp_ajax_post_update', 'bp_dtheme_post_update' );
    208289
    209 /* AJAX activity comment posting */
     290/**
     291 * Posts new Activity comments received via a POST request.
     292 *
     293 * @global BP_Activity_Template $activities_template
     294 * @return string HTML
     295 * @since BuddyPress (1.2)
     296 */
    210297function bp_dtheme_new_activity_comment() {
     298        global $activities_template;
    211299
    212300        // Bail if not a POST action
    213301        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    function bp_dtheme_new_activity_comment() { 
    216304        // Check the nonce
    217305        check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
    218306
    219         if ( !is_user_logged_in() ) {
    220                 echo '-1';
    221                 return false;
    222         }
     307        if ( ! is_user_logged_in() )
     308                exit( '-1' );
    223309
    224         if ( empty( $_POST['content'] ) ) {
    225                 echo '-1<div id="message" class="error"><p>' . __( 'Please do not leave the comment area blank.', 'buddypress' ) . '</p></div>';
    226                 return false;
    227         }
     310        if ( empty( $_POST['content'] ) )
     311                exit( '-1<div id="message" class="error"><p>' . __( 'Please do not leave the comment area blank.', 'buddypress' ) . '</p></div>' );
    228312
    229         if ( empty( $_POST['form_id'] ) || empty( $_POST['comment_id'] ) || !is_numeric( $_POST['form_id'] ) || !is_numeric( $_POST['comment_id'] ) ) {
    230                 echo '-1<div id="message" class="error"><p>' . __( 'There was an error posting that reply, please try again.', 'buddypress' ) . '</p></div>';
    231                 return false;
    232         }
     313        if ( empty( $_POST['form_id'] ) || empty( $_POST['comment_id'] ) || ! is_numeric( $_POST['form_id'] ) || ! is_numeric( $_POST['comment_id'] ) )
     314                exit( '-1<div id="message" class="error"><p>' . __( 'There was an error posting that reply, please try again.', 'buddypress' ) . '</p></div>' );
    233315
    234316        $comment_id = bp_activity_new_comment( array(
    235317                'activity_id' => $_POST['form_id'],
    236318                'content'     => $_POST['content'],
    237                 'parent_id'   => $_POST['comment_id']
     319                'parent_id'   => $_POST['comment_id'],
    238320        ) );
    239321
    240         if ( !$comment_id ) {
    241                 echo '-1<div id="message" class="error"><p>' . __( 'There was an error posting that reply, please try again.', 'buddypress' ) . '</p></div>';
    242                 return false;
    243         }
    244 
    245         global $activities_template;
     322        if ( ! $comment_id )
     323                exit( '-1<div id="message" class="error"><p>' . __( 'There was an error posting that reply, please try again.', 'buddypress' ) . '</p></div>' );
    246324
    247325        // Load the new activity item into the $activities_template global
    248326        bp_has_activities( 'display_comments=stream&hide_spam=false&include=' . $comment_id );
    function bp_dtheme_new_activity_comment() { 
    253331
    254332        $template = locate_template( 'activity/comment.php', false, false );
    255333
    256         // Backward compatibility. In older versions of BP, the markup was
    257         // generated in the PHP instead of a template. This ensures that
    258         // older themes (which are not children of bp-default and won't
    259         // have the new template) will still work.
     334        /**
     335         * Backward compatibility. In older versions of BP, the markup was
     336         * generated in the PHP instead of a template. This ensures that
     337         * older themes (which are not children of bp-default and won't
     338         * have the new template) will still work.
     339         */
    260340        if ( empty( $template ) )
    261341                $template = BP_PLUGIN_DIR . '/bp-themes/bp-default/activity/comment.php';
    262342
    263343        load_template( $template, false );
    264344
    265345        unset( $activities_template );
     346        exit;
    266347}
    267 add_action( 'wp_ajax_new_activity_comment', 'bp_dtheme_new_activity_comment' );
    268348
    269 /* AJAX delete an activity */
     349/**
     350 * Deletes an Activity item received via a POST request.
     351 *
     352 * @return mixed String on error, void on success
     353 * @since BuddyPress (1.2)
     354 */
    270355function bp_dtheme_delete_activity() {
    271 
    272356        // Bail if not a POST action
    273357        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    274358                return;
    function bp_dtheme_delete_activity() { 
    276360        // Check the nonce
    277361        check_admin_referer( 'bp_activity_delete_link' );
    278362
    279         if ( !is_user_logged_in() ) {
    280                 echo '-1';
    281                 return false;
    282         }
     363        if ( ! is_user_logged_in() )
     364                exit( '-1' );
    283365
    284         if ( empty( $_POST['id'] ) || !is_numeric( $_POST['id'] ) ) {
    285                 echo '-1';
    286                 return false;
    287         }
     366        if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) )
     367                exit( '-1' );
    288368
    289369        $activity = new BP_Activity_Activity( (int) $_POST['id'] );
    290370
    291371        // Check access
    292         if ( empty( $activity->user_id ) || !bp_activity_user_can_delete( $activity ) ) {
    293                 echo '-1';
    294                 return false;
    295         }
     372        if ( empty( $activity->user_id ) || ! bp_activity_user_can_delete( $activity ) )
     373                exit( '-1' );
    296374
    297375        // Call the action before the delete so plugins can still fetch information about it
    298376        do_action( 'bp_activity_before_action_delete_activity', $activity->id, $activity->user_id );
    299377
    300         if ( !bp_activity_delete( array( 'id' => $activity->id, 'user_id' => $activity->user_id ) ) ) {
    301                 echo '-1<div id="message" class="error"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>';
    302                 return false;
    303         }
     378        if ( ! bp_activity_delete( array( 'id' => $activity->id, 'user_id' => $activity->user_id ) ) )
     379                exit( '-1<div id="message" class="error"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>' );
    304380
    305381        do_action( 'bp_activity_action_delete_activity', $activity->id, $activity->user_id );
    306 
    307         return true;
     382        exit;
    308383}
    309 add_action( 'wp_ajax_delete_activity', 'bp_dtheme_delete_activity' );
    310384
    311 /* AJAX delete an activity comment */
     385/**
     386 * Deletes an Activity comment received via a POST request
     387 *
     388 * @return mixed String on error, void on success
     389 * @since BuddyPress (1.2)
     390 */
    312391function bp_dtheme_delete_activity_comment() {
    313 
    314392        // Bail if not a POST action
    315393        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    316394                return;
    function bp_dtheme_delete_activity_comment() { 
    318396        // Check the nonce
    319397        check_admin_referer( 'bp_activity_delete_link' );
    320398
    321         if ( !is_user_logged_in() ) {
    322                 echo '-1';
    323                 return false;
    324         }
     399        if ( ! is_user_logged_in() )
     400                exit( '-1' );
    325401
    326402        $comment = new BP_Activity_Activity( $_POST['id'] );
    327403
    328         /* Check access */
    329         if ( !bp_current_user_can( 'bp_moderate' ) && $comment->user_id != bp_loggedin_user_id() )
    330                 return false;
     404        // Check access
     405        if ( ! bp_current_user_can( 'bp_moderate' ) && $comment->user_id != bp_loggedin_user_id() )
     406                exit( '-1' );
    331407
    332         if ( empty( $_POST['id'] ) || !is_numeric( $_POST['id'] ) )
    333                 return false;
     408        if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) )
     409                exit( '-1' );
    334410
    335         /* Call the action before the delete so plugins can still fetch information about it */
     411        // Call the action before the delete so plugins can still fetch information about it
    336412        do_action( 'bp_activity_before_action_delete_activity', $_POST['id'], $comment->user_id );
    337413
    338         if ( !bp_activity_delete_comment( $comment->item_id, $comment->id ) ) {
    339                 echo '-1<div id="message" class="error"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>';
    340                 return false;
    341         }
     414        if ( ! bp_activity_delete_comment( $comment->item_id, $comment->id ) )
     415                exit( '-1<div id="message" class="error"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>' );
    342416
    343417        do_action( 'bp_activity_action_delete_activity', $_POST['id'], $comment->user_id );
    344 
    345         return true;
     418        exit;
    346419}
    347 add_action( 'wp_ajax_delete_activity_comment', 'bp_dtheme_delete_activity_comment' );
    348420
    349421/**
    350  * AJAX spam an activity item or an activity comment
     422 * AJAX spam an activity item or comment
    351423 *
    352  * @global object $bp BuddyPress global settings
    353  * @since 1.6
     424 * @global BuddyPress $bp The one true BuddyPress instance
     425 * @return mixed String on error, void on success
     426 * @since BuddyPress (1.6)
    354427 */
    355428function bp_dtheme_spam_activity() {
    356429        global $bp;
    function bp_dtheme_spam_activity() { 
    360433                return;
    361434
    362435        // Check that user is logged in, Activity Streams are enabled, and Akismet is present.
    363         if ( !is_user_logged_in() || !bp_is_active( 'activity' ) || empty( $bp->activity->akismet ) ) {
    364                 echo '-1';
    365                 return false;
    366         }
     436        if ( ! is_user_logged_in() || ! bp_is_active( 'activity' ) || empty( $bp->activity->akismet ) )
     437                exit( '-1' );
    367438
    368439        // Check an item ID was passed
    369         if ( empty( $_POST['id'] ) || !is_numeric( $_POST['id'] ) ) {
    370                 echo '-1';
    371                 return false;
    372         }
     440        if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) )
     441                exit( '-1' );
    373442
    374443        // Is the current user allowed to spam items?
    375         if ( !bp_activity_user_can_mark_spam() )
    376                 return false;
     444        if ( ! bp_activity_user_can_mark_spam() )
     445                exit( '-1' );
    377446
    378447        // Load up the activity item
    379448        $activity = new BP_Activity_Activity( (int) $_POST['id'] );
    380         if ( empty( $activity->component ) ) {
    381                 echo '-1';
    382                 return false;
    383         }
     449        if ( empty( $activity->component ) )
     450                exit( '-1' );
    384451
    385452        // Check nonce
    386453        check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id );
    function bp_dtheme_spam_activity() { 
    393460        $activity->save();
    394461
    395462        do_action( 'bp_activity_action_spam_activity', $activity->id, $activity->user_id );
    396         return true;
     463        exit;
    397464}
    398 add_action( 'wp_ajax_spam_activity',         'bp_dtheme_spam_activity' );
    399 add_action( 'wp_ajax_spam_activity_comment', 'bp_dtheme_spam_activity' );
    400465
    401 /* AJAX mark an activity as a favorite */
     466/**
     467 * Mark an activity as a favourite via a POST request.
     468 *
     469 * @return string HTML
     470 * @since BuddyPress (1.2)
     471 */
    402472function bp_dtheme_mark_activity_favorite() {
    403 
    404473        // Bail if not a POST action
    405474        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    406475                return;
    407476
    408477        bp_activity_add_user_favorite( $_POST['id'] );
    409         _e( 'Remove Favorite', 'buddypress' );
     478        exit( __( 'Remove Favorite', 'buddypress' ) );
    410479}
    411 add_action( 'wp_ajax_activity_mark_fav', 'bp_dtheme_mark_activity_favorite' );
    412480
    413 /* AJAX mark an activity as not a favorite */
     481/**
     482 * Un-favourite an activity via a POST request.
     483 *
     484 * @return string HTML
     485 * @since BuddyPress (1.2)
     486 */
    414487function bp_dtheme_unmark_activity_favorite() {
    415 
    416488        // Bail if not a POST action
    417489        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    418490                return;
    419491
    420492        bp_activity_remove_user_favorite( $_POST['id'] );
    421         _e( 'Favorite', 'buddypress' );
     493        exit( __( 'Favorite', 'buddypress' ) );
    422494}
    423 add_action( 'wp_ajax_activity_mark_unfav', 'bp_dtheme_unmark_activity_favorite' );
    424495
    425496/**
    426  * AJAX handler for Read More link on long activity items
     497 * Fetches full an activity's full, non-excerpted content via a POST request.
     498 * Used for the 'Read More' link on long activity items.
    427499 *
    428  * @package BuddyPress
     500 * @return string HTML
    429501 * @since BuddyPress (1.5)
    430502 */
    431503function bp_dtheme_get_single_activity_content() {
    function bp_dtheme_get_single_activity_content() { 
    438510                'display_comments' => 'stream'
    439511        ) );
    440512
    441         $activity = !empty( $activity_array['activities'][0] ) ? $activity_array['activities'][0] : false;
     513        $activity = ! empty( $activity_array['activities'][0] ) ? $activity_array['activities'][0] : false;
    442514
    443515        if ( empty( $activity ) )
    444                 exit(); // todo: error?
     516                exit; // @todo: error?
    445517
    446518        do_action_ref_array( 'bp_dtheme_get_single_activity_content', array( &$activity ) );
    447519
    function bp_dtheme_get_single_activity_content() { 
    449521        remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
    450522        $content = apply_filters( 'bp_get_activity_content_body', $activity->content );
    451523
    452         echo $content;
    453         exit();
     524        exit( $content );
    454525}
    455 add_action( 'wp_ajax_get_single_activity_content', 'bp_dtheme_get_single_activity_content' );
    456526
    457 /* AJAX invite a friend to a group functionality */
     527/**
     528 * Invites a friend to join a group via a POST request.
     529 *
     530 * @return unknown
     531 * @since BuddyPress (1.2)
     532 * @todo Audit return types
     533 */
    458534function bp_dtheme_ajax_invite_user() {
    459 
    460535        // Bail if not a POST action
    461536        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    462537                return;
    463538
    464539        check_ajax_referer( 'groups_invite_uninvite_user' );
    465540
    466         if ( !$_POST['friend_id'] || !$_POST['friend_action'] || !$_POST['group_id'] )
    467                 return false;
     541        if ( ! $_POST['friend_id'] || ! $_POST['friend_action'] || ! $_POST['group_id'] )
     542                return;
    468543
    469         if ( !bp_groups_user_can_send_invites( $_POST['group_id'] ) )
    470                 return false;
     544        if ( ! bp_groups_user_can_send_invites( $_POST['group_id'] ) )
     545                return;
    471546
    472         if ( !friends_check_friendship( bp_loggedin_user_id(), $_POST['friend_id'] ) )
    473                 return false;
     547        if ( ! friends_check_friendship( bp_loggedin_user_id(), $_POST['friend_id'] ) )
     548                return;
    474549
    475550        if ( 'invite' == $_POST['friend_action'] ) {
    476 
    477                 if ( !groups_invite_user( array( 'user_id' => $_POST['friend_id'], 'group_id' => $_POST['group_id'] ) ) )
    478                         return false;
     551                if ( ! groups_invite_user( array( 'user_id' => $_POST['friend_id'], 'group_id' => $_POST['group_id'] ) ) )
     552                        return;
    479553
    480554                $user = new BP_Core_User( $_POST['friend_id'] );
    481555
    function bp_dtheme_ajax_invite_user() { 
    487561                                <a class="button remove" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . $_POST['group_id'] . '/invites/remove/' . $user->id, 'groups_invite_uninvite_user' ) . '" id="uid-' . esc_attr( $user->id ) . '">' . __( 'Remove Invite', 'buddypress' ) . '</a>
    488562                          </div>';
    489563                echo '</li>';
     564                exit;
    490565
    491         } else if ( 'uninvite' == $_POST['friend_action'] ) {
     566        } elseif ( 'uninvite' == $_POST['friend_action'] ) {
     567                if ( ! groups_uninvite_user( $_POST['friend_id'], $_POST['group_id'] ) )
     568                        return;
    492569
    493                 if ( !groups_uninvite_user( $_POST['friend_id'], $_POST['group_id'] ) )
    494                         return false;
    495 
    496                 return true;
     570                exit;
    497571
    498572        } else {
    499                 return false;
     573                return;
    500574        }
    501575}
    502 add_action( 'wp_ajax_groups_invite_user', 'bp_dtheme_ajax_invite_user' );
    503576
    504 /* AJAX add/remove a user as a friend when clicking the button */
     577/**
     578 * Friend/un-friend a user via a POST request.
     579 *
     580 * @return string HTML
     581 * @since BuddyPress (1.2)
     582 */
    505583function bp_dtheme_ajax_addremove_friend() {
    506 
    507584        // Bail if not a POST action
    508585        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    509586                return;
    510587
    511588        if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $_POST['fid'] ) ) {
     589                check_ajax_referer( 'friends_remove_friend' );
    512590
    513                 check_ajax_referer('friends_remove_friend');
    514 
    515                 if ( !friends_remove_friend( bp_loggedin_user_id(), $_POST['fid'] ) ) {
    516                         echo __("Friendship could not be canceled.", 'buddypress');
    517                 } else {
     591                if ( ! friends_remove_friend( bp_loggedin_user_id(), $_POST['fid'] ) )
     592                        echo __( 'Friendship could not be canceled.', 'buddypress' );
     593                else
    518594                        echo '<a id="friend-' . $_POST['fid'] . '" class="add" rel="add" title="' . __( 'Add Friend', 'buddypress' ) . '" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $_POST['fid'], 'friends_add_friend' ) . '">' . __( 'Add Friend', 'buddypress' ) . '</a>';
    519                 }
    520595
    521         } else if ( 'not_friends' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $_POST['fid'] ) ) {
     596        } elseif ( 'not_friends' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $_POST['fid'] ) ) {
     597                check_ajax_referer( 'friends_add_friend' );
    522598
    523                 check_ajax_referer('friends_add_friend');
     599                if ( ! friends_add_friend( bp_loggedin_user_id(), $_POST['fid'] ) )
     600                        echo __(' Friendship could not be requested.', 'buddypress' );
     601                else
     602                        echo '<a id="friend-' . $_POST['fid'] . '" class="remove" rel="remove" title="' . __( 'Cancel Friendship Request', 'buddypress' ) . '" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . (int) $_POST['fid'] . '/', 'friends_withdraw_friendship' ) . '" class="requested">' . __( 'Cancel Friendship Request', 'buddypress' ) . '</a>';
    524603
    525                 if ( !friends_add_friend( bp_loggedin_user_id(), $_POST['fid'] ) ) {
    526                         echo __("Friendship could not be requested.", 'buddypress');
    527                 } else {
    528                         echo '<a id="friend-' . $_POST['fid'] . '" class="remove" rel="remove" title="' . __( 'Cancel Friendship Request', 'buddypress' ) . '" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . (int)$_POST['fid'] . '/', 'friends_withdraw_friendship' ) . '" class="requested">' . __( 'Cancel Friendship Request', 'buddypress' ) . '</a>';
    529                 }
    530         } else if( 'pending' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), (int)$_POST['fid'] ) ) {
    531                
    532                 check_ajax_referer('friends_withdraw_friendship');
    533                
    534                 if ( friends_withdraw_friendship( bp_loggedin_user_id(), (int)$_POST['fid'] ) ) {
     604        } elseif ( 'pending' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), (int) $_POST['fid'] ) ) {               
     605                check_ajax_referer( 'friends_withdraw_friendship' );
     606
     607                if ( friends_withdraw_friendship( bp_loggedin_user_id(), (int) $_POST['fid'] ) )
    535608                        echo '<a id="friend-' . $_POST['fid'] . '" class="add" rel="add" title="' . __( 'Add Friend', 'buddypress' ) . '" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $_POST['fid'], 'friends_add_friend' ) . '">' . __( 'Add Friend', 'buddypress' ) . '</a>';
    536                 } else {
     609                else
    537610                        echo __("Friendship request could not be cancelled.", 'buddypress');
    538                 }
     611
    539612        } else {
    540613                echo __( 'Request Pending', 'buddypress' );
    541614        }
    542615
    543         return false;
     616        exit;
    544617}
    545 add_action( 'wp_ajax_addremove_friend', 'bp_dtheme_ajax_addremove_friend' );
    546618
    547 /* AJAX accept a user as a friend when clicking the "accept" button */
     619/**
     620 * Accept a user friendship request via a POST request.
     621 *
     622 * @return mixed String on error, void on success
     623 * @since BuddyPress (1.2)
     624 */
    548625function bp_dtheme_ajax_accept_friendship() {
    549 
    550626        // Bail if not a POST action
    551627        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    552628                return;
    553629
    554630        check_admin_referer( 'friends_accept_friendship' );
    555631
    556         if ( !friends_accept_friendship( $_POST['id'] ) )
     632        if ( ! friends_accept_friendship( $_POST['id'] ) )
    557633                echo "-1<div id='message' class='error'><p>" . __( 'There was a problem accepting that request. Please try again.', 'buddypress' ) . '</p></div>';
    558634
    559         return true;
     635        exit;
    560636}
    561 add_action( 'wp_ajax_accept_friendship', 'bp_dtheme_ajax_accept_friendship' );
    562637
    563 /* AJAX reject a user as a friend when clicking the "reject" button */
     638/**
     639 * Reject a user friendship request via a POST request.
     640 *
     641 * @return mixed String on error, void on success
     642 * @since BuddyPress (1.2)
     643 */
    564644function bp_dtheme_ajax_reject_friendship() {
    565645        // Bail if not a POST action
    566646        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    function bp_dtheme_ajax_reject_friendship() { 
    568648
    569649        check_admin_referer( 'friends_reject_friendship' );
    570650
    571         if ( !friends_reject_friendship( $_POST['id'] ) )
     651        if ( ! friends_reject_friendship( $_POST['id'] ) )
    572652                echo "-1<div id='message' class='error'><p>" . __( 'There was a problem rejecting that request. Please try again.', 'buddypress' ) . '</p></div>';
    573653
    574         return true;
     654        exit;
    575655}
    576 add_action( 'wp_ajax_reject_friendship', 'bp_dtheme_ajax_reject_friendship' );
    577656
    578 /* AJAX join or leave a group when clicking the "join/leave" button */
     657/**
     658 * Join or leave a group when clicking the "join/leave" button via a POST request.
     659 *
     660 * @return string HTML
     661 * @since BuddyPress (1.2)
     662 */
    579663function bp_dtheme_ajax_joinleave_group() {
    580 
    581664        // Bail if not a POST action
    582665        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    583666                return;
    584667
    585668        if ( groups_is_user_banned( bp_loggedin_user_id(), $_POST['gid'] ) )
    586                 return false;
    587 
    588         if ( !$group = groups_get_group( array( 'group_id' => $_POST['gid'] ) ) )
    589                 return false;
     669                return;
    590670
    591         if ( !groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
     671        if ( ! $group = groups_get_group( array( 'group_id' => $_POST['gid'] ) ) )
     672                return;
    592673
     674        if ( ! groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
    593675                if ( 'public' == $group->status ) {
    594 
    595676                        check_ajax_referer( 'groups_join_group' );
    596677
    597                         if ( !groups_join_group( $group->id ) ) {
     678                        if ( ! groups_join_group( $group->id ) )
    598679                                _e( 'Error joining group', 'buddypress' );
    599                         } else {
     680                        else
    600681                                echo '<a id="group-' . esc_attr( $group->id ) . '" class="leave-group" rel="leave" title="' . __( 'Leave Group', 'buddypress' ) . '" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>';
    601                         }
    602 
    603                 } else if ( 'private' == $group->status ) {
    604682
     683                } elseif ( 'private' == $group->status ) {
    605684                        check_ajax_referer( 'groups_request_membership' );
    606685
    607                         if ( !groups_send_membership_request( bp_loggedin_user_id(), $group->id ) ) {
     686                        if ( ! groups_send_membership_request( bp_loggedin_user_id(), $group->id ) )
    608687                                _e( 'Error requesting membership', 'buddypress' );
    609                         } else {
     688                        else
    610689                                echo '<a id="group-' . esc_attr( $group->id ) . '" class="membership-requested" rel="membership-requested" title="' . __( 'Membership Requested', 'buddypress' ) . '" href="' . bp_get_group_permalink( $group ) . '">' . __( 'Membership Requested', 'buddypress' ) . '</a>';
    611                         }
    612690                }
    613691
    614692        } else {
    615 
    616693                check_ajax_referer( 'groups_leave_group' );
    617694
    618                 if ( !groups_leave_group( $group->id ) ) {
     695                if ( ! groups_leave_group( $group->id ) )
    619696                        _e( 'Error leaving group', 'buddypress' );
    620                 } else {
    621                         if ( 'public' == $group->status ) {
    622                                 echo '<a id="group-' . esc_attr( $group->id ) . '" class="join-group" rel="join" title="' . __( 'Join Group', 'buddypress' ) . '" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ) . '">' . __( 'Join Group', 'buddypress' ) . '</a>';
    623                         } else if ( 'private' == $group->status ) {
    624                                 echo '<a id="group-' . esc_attr( $group->id ) . '" class="request-membership" rel="join" title="' . __( 'Request Membership', 'buddypress' ) . '" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_send_membership_request' ) . '">' . __( 'Request Membership', 'buddypress' ) . '</a>';
    625                         }
    626                 }
     697                elseif ( 'public' == $group->status )
     698                        echo '<a id="group-' . esc_attr( $group->id ) . '" class="join-group" rel="join" title="' . __( 'Join Group', 'buddypress' ) . '" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ) . '">' . __( 'Join Group', 'buddypress' ) . '</a>';
     699                elseif ( 'private' == $group->status )
     700                        echo '<a id="group-' . esc_attr( $group->id ) . '" class="request-membership" rel="join" title="' . __( 'Request Membership', 'buddypress' ) . '" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_send_membership_request' ) . '">' . __( 'Request Membership', 'buddypress' ) . '</a>';
    627701        }
     702
     703        exit;
    628704}
    629 add_action( 'wp_ajax_joinleave_group', 'bp_dtheme_ajax_joinleave_group' );
    630705
    631 /* AJAX close and keep closed site wide notices from an admin in the sidebar */
     706/**
     707 * Close and keep closed site wide notices from an admin in the sidebar, via a POST request.
     708 *
     709 * @return mixed String on error, void on success
     710 * @since BuddyPress (1.2)
     711 */
    632712function bp_dtheme_ajax_close_notice() {
    633         global $userdata;
    634 
    635713        // Bail if not a POST action
    636714        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    637715                return;
    638716
    639         if ( !isset( $_POST['notice_id'] ) ) {
    640                 echo "-1<div id='message' class='error'><p>" . __('There was a problem closing the notice.', 'buddypress') . '</p></div>';
    641         } else {
    642                 $notice_ids = bp_get_user_meta( $userdata->ID, 'closed_notices', true );
     717        if ( ! isset( $_POST['notice_id'] ) ) {
     718                echo "-1<div id='message' class='error'><p>" . __( 'There was a problem closing the notice.', 'buddypress' ) . '</p></div>';
    643719
     720        } else {
     721                $user_id      = get_current_user_id();
     722                $notice_ids   = bp_get_user_meta( $user_id, 'closed_notices', true );
    644723                $notice_ids[] = (int) $_POST['notice_id'];
    645724
    646                 bp_update_user_meta( $userdata->ID, 'closed_notices', $notice_ids );
     725                bp_update_user_meta( $user_id, 'closed_notices', $notice_ids );
    647726        }
     727
     728        exit;
    648729}
    649 add_action( 'wp_ajax_messages_close_notice', 'bp_dtheme_ajax_close_notice' );
    650730
    651 /* AJAX send a private message reply to a thread */
     731/**
     732 * Send a private message reply to a thread via a POST request.
     733 *
     734 * @return string HTML
     735 * @since BuddyPress (1.2)
     736 */
    652737function bp_dtheme_ajax_messages_send_reply() {
    653         global $bp;
    654 
    655738        // Bail if not a POST action
    656739        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    657740                return;
    function bp_dtheme_ajax_messages_send_reply() { 
    666749                                <?php do_action( 'bp_before_message_meta' ); ?>
    667750                                <?php echo bp_loggedin_user_avatar( 'type=thumb&width=30&height=30' ); ?>
    668751
    669                                 <strong><a href="<?php echo bp_loggedin_user_domain(); ?>"><?php echo $bp->loggedin_user->fullname ?></a> <span class="activity"><?php printf( __( 'Sent %s', 'buddypress' ), bp_core_time_since( bp_core_current_time() ) ); ?></span></strong>
     752                                <strong><a href="<?php echo bp_loggedin_user_domain(); ?>"><?php bp_loggedin_user_fullname(); ?></a> <span class="activity"><?php printf( __( 'Sent %s', 'buddypress' ), bp_core_time_since( bp_core_current_time() ) ); ?></span></strong>
    670753
    671754                                <?php do_action( 'bp_after_message_meta' ); ?>
    672755                        </div>
    function bp_dtheme_ajax_messages_send_reply() { 
    685768        } else {
    686769                echo "-1<div id='message' class='error'><p>" . __( 'There was a problem sending that reply. Please try again.', 'buddypress' ) . '</p></div>';
    687770        }
     771
     772        exit;
    688773}
    689 add_action( 'wp_ajax_messages_send_reply', 'bp_dtheme_ajax_messages_send_reply' );
    690774
    691 /* AJAX mark a private message as unread in your inbox */
     775/**
     776 * Mark a private message as unread in your inbox via a POST request.
     777 *
     778 * @return mixed String on error, void on success
     779 * @since BuddyPress (1.2)
     780 */
    692781function bp_dtheme_ajax_message_markunread() {
    693 
    694782        // Bail if not a POST action
    695783        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    696784                return;
    697785
    698         if ( !isset($_POST['thread_ids']) ) {
    699                 echo "-1<div id='message' class='error'><p>" . __('There was a problem marking messages as unread.', 'buddypress' ) . '</p></div>';
     786        if ( ! isset($_POST['thread_ids']) ) {
     787                echo "-1<div id='message' class='error'><p>" . __( 'There was a problem marking messages as unread.', 'buddypress' ) . '</p></div>';
     788
    700789        } else {
    701790                $thread_ids = explode( ',', $_POST['thread_ids'] );
    702791
    function bp_dtheme_ajax_message_markunread() { 
    704793                        BP_Messages_Thread::mark_as_unread($thread_ids[$i]);
    705794                }
    706795        }
     796
     797        exit;
    707798}
    708 add_action( 'wp_ajax_messages_markunread', 'bp_dtheme_ajax_message_markunread' );
    709799
    710 /* AJAX mark a private message as read in your inbox */
     800/**
     801 * Mark a private message as read in your inbox via a POST request.
     802 *
     803 * @return mixed String on error, void on success
     804 * @since BuddyPress (1.2)
     805 */
    711806function bp_dtheme_ajax_message_markread() {
    712 
    713807        // Bail if not a POST action
    714808        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    715809                return;
    716810
    717         if ( !isset($_POST['thread_ids']) ) {
     811        if ( ! isset($_POST['thread_ids']) ) {
    718812                echo "-1<div id='message' class='error'><p>" . __('There was a problem marking messages as read.', 'buddypress' ) . '</p></div>';
     813
    719814        } else {
    720815                $thread_ids = explode( ',', $_POST['thread_ids'] );
    721816
    function bp_dtheme_ajax_message_markread() { 
    723818                        BP_Messages_Thread::mark_as_read($thread_ids[$i]);
    724819                }
    725820        }
     821
     822        exit;
    726823}
    727 add_action( 'wp_ajax_messages_markread', 'bp_dtheme_ajax_message_markread' );
    728824
    729 /* AJAX delete a private message or array of messages in your inbox */
     825/**
     826 * Delete a private message(s) in your inbox via a POST request.
     827 *
     828 * @return string HTML
     829 * @since BuddyPress (1.2)
     830 */
    730831function bp_dtheme_ajax_messages_delete() {
    731 
    732832        // Bail if not a POST action
    733833        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
    734834                return;
    735835
    736         if ( !isset($_POST['thread_ids']) ) {
     836        if ( ! isset($_POST['thread_ids']) ) {
    737837                echo "-1<div id='message' class='error'><p>" . __( 'There was a problem deleting messages.', 'buddypress' ) . '</p></div>';
     838
    738839        } else {
    739840                $thread_ids = explode( ',', $_POST['thread_ids'] );
    740841
    function bp_dtheme_ajax_messages_delete() { 
    743844
    744845                _e( 'Messages deleted.', 'buddypress' );
    745846        }
     847
     848        exit;
    746849}
    747 add_action( 'wp_ajax_messages_delete', 'bp_dtheme_ajax_messages_delete' );
    748850
    749851/**
    750  * bp_dtheme_ajax_messages_autocomplete_results()
     852 * AJAX handler for autocomplete. Displays friends only, unless BP_MESSAGES_AUTOCOMPLETE_ALL is defined.
    751853 *
    752  * AJAX handler for autocomplete. Displays friends only, unless BP_MESSAGES_AUTOCOMPLETE_ALL is defined
    753  *
    754  * @global object object $bp Global BuddyPress settings object
    755  * @return none
     854 * @global BuddyPress $bp The one true BuddyPress instance
     855 * @return string HTML
     856 * @since BuddyPress (1.2)
    756857 */
    757858function bp_dtheme_ajax_messages_autocomplete_results() {
    758859        global $bp;
    function bp_dtheme_ajax_messages_autocomplete_results() { 
    762863                $autocomplete_all = $bp->messages->autocomplete_all;
    763864
    764865        $pag_page = 1;
    765 
    766         $limit = $_GET['limit'] ? $_GET['limit'] : apply_filters( 'bp_autocomplete_max_results', 10 );
     866        $limit    = $_GET['limit'] ? $_GET['limit'] : apply_filters( 'bp_autocomplete_max_results', 10 );
    767867
    768868        // Get the user ids based on the search terms
    769         if ( !empty( $autocomplete_all ) ) {
     869        if ( ! empty( $autocomplete_all ) ) {
    770870                $users = BP_Core_User::search_users( $_GET['q'], $limit, $pag_page );
    771871
    772                 if ( !empty( $users['users'] ) ) {
     872                if ( ! empty( $users['users'] ) ) {
    773873                        // Build an array with the correct format
    774874                        $user_ids = array();
    775875                        foreach( $users['users'] as $user ) {
    function bp_dtheme_ajax_messages_autocomplete_results() { 
    779879
    780880                        $user_ids = apply_filters( 'bp_core_autocomplete_ids', $user_ids, $_GET['q'], $limit );
    781881                }
     882
    782883        } else {
    783884                if ( bp_is_active( 'friends' ) ) {
    784885                        $users = friends_search_friends( $_GET['q'], bp_loggedin_user_id(), $limit, 1 );
    function bp_dtheme_ajax_messages_autocomplete_results() { 
    786887                        // Keeping the bp_friends_autocomplete_list filter for backward compatibility
    787888                        $users = apply_filters( 'bp_friends_autocomplete_list', $users, $_GET['q'], $limit );
    788889
    789                         if ( !empty( $users['friends'] ) )
     890                        if ( ! empty( $users['friends'] ) )
    790891                                $user_ids = apply_filters( 'bp_friends_autocomplete_ids', $users['friends'], $_GET['q'], $limit );
    791892                }
    792893        }
    793894
    794         if ( !empty( $user_ids ) ) {
     895        if ( ! empty( $user_ids ) ) {
    795896                foreach ( $user_ids as $user_id ) {
    796897                        $ud = get_userdata( $user_id );
    797                         if ( !$ud )
     898                        if ( ! $ud )
    798899                                continue;
    799900
    800901                        if ( bp_is_username_compatibility_mode() )
    function bp_dtheme_ajax_messages_autocomplete_results() { 
    802903                        else
    803904                                $username = $ud->user_nicename;
    804905
    805                         echo '<span id="link-' . $username . '" href="' . bp_core_get_user_domain( $user_id ) . '"></span>' . bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'width' => 15, 'height' => 15, 'alt' => $ud->display_name ) ) . ' &nbsp;' . bp_core_get_user_displayname( $user_id ) . ' (' . $username . ')
    806                         ';
     906                        echo '<span id="link-' . $username . '" href="' . bp_core_get_user_domain( $user_id ) . '"></span>' . bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'width' => 15, 'height' => 15, 'alt' => $ud->display_name ) ) . ' &nbsp;' . bp_core_get_user_displayname( $user_id ) . ' (' . $username . ')';
    807907                }
    808908        }
    809 }
    810 add_action( 'wp_ajax_messages_autocomplete_results', 'bp_dtheme_ajax_messages_autocomplete_results' );
    811909
    812 ?>
     910        exit;
     911}
     912?>
     913 No newline at end of file
  • bp-themes/bp-default/_inc/global.js

    jq(document).ready( function() { 
    272272                        target.addClass( 'loading' );
    273273
    274274                        jq.post( ajaxurl, {
    275                                 action: 'spam_activity',
     275                                action: 'bp_spam_activity',
    276276                                'cookie': encodeURIComponent( document.cookie ),
    277277                                'id': li.attr( 'id' ).substr( 9, li.attr( 'id' ).length ),
    278278                                '_wpnonce': target.attr( 'href' ).split( '_wpnonce=' )[1]
    jq(document).ready( function() { 
    534534                        comment_li.parents( '.activity-comments' ).append( comment_li.parents( '.activity-comments' ).children( 'form' ) );
    535535
    536536                        jq.post( ajaxurl, {
    537                                 action: 'spam_activity_comment',
     537                                action: 'bp_spam_activity_comment',
    538538                                'cookie': encodeURIComponent( document.cookie ),
    539539                                '_wpnonce': link_href.split( '_wpnonce=' )[1],
    540540                                'id': link_href.split( 'cid=' )[1].split( '&' )[0]