Skip to:
Content

BuddyPress.org

Changeset 511


Ignore:
Timestamp:
11/07/2008 06:01:12 PM (18 years ago)
Author:
apeatling
Message:

Added wp_redirect() to all confirmation messages to stop double posting
Added group delete option for group administrators

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-templatetags.php

    r438 r511  
    174174
    175175function bp_activity_insert_time_since( $content, $date ) {
     176        if ( !$content || !$date )
     177                return false;
     178               
    176179        return sprintf( $content, '  ' . bp_core_time_since( strtotime( $date ) ) . ' ' . __('ago', 'buddypress') );
    177180}
  • trunk/bp-blogs.php

    r508 r511  
    485485}
    486486
     487function bp_blogs_get_random_blog() {
     488        return BP_Blogs_Blog::get_random();
     489}
     490
    487491function bp_blogs_get_all_posts() {
    488492        return BP_Blogs_Post::get_all();
    489493}
    490494
    491 function bp_blogs_get_random_blog() {
     495function bp_blogs_redirect_to_random_blog() {
    492496        global $bp, $wpdb;
    493497       
    494498        if ( $bp['current_component'] == $bp['blogs']['slug'] && isset( $_GET['random-blog'] ) ) {
    495                 $blogs = bp_blogs_get_all_blogs();
    496 
    497                 wp_redirect( get_blog_option( $blogs[rand( 0, count($blogs) - 1)], 'siteurl') );
    498         }
    499 }
    500 add_action( 'wp', 'bp_blogs_get_random_blog', 6 );
     499                $blog_id = bp_blogs_get_random_blog();
     500
     501                wp_redirect( get_blog_option( $blog_id, 'siteurl') );
     502        }
     503}
     504add_action( 'wp', 'bp_blogs_redirect_to_random_blog', 6 );
    501505
    502506
  • trunk/bp-blogs/bp-blogs-classes.php

    r508 r511  
    111111                return $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM " . $bp['blogs']['table_name'] ) );
    112112        }
     113       
     114        function get_random() {
     115                global $bp, $wpdb;
     116               
     117                return $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM " . $bp['blogs']['table_name'] . " ORDER BY rand() LIMIT 1" ) );
     118        }
     119       
    113120}
    114121
  • trunk/bp-core.php

    r508 r511  
    77define( 'MEMBERS_SLUG', 'members' );
    88
    9 /* These components are accessed via the root, and not under a blog name or home base.
     9/* These components are accessed via the root, and not under a blog name or member home.
    1010   e.g Groups is accessed via: http://domain.com/groups/group-name NOT http://domain.com/andy/groups/group-name */
    1111define( 'BP_CORE_ROOT_COMPONENTS', 'groups' . ',' . MEMBERS_SLUG );
     
    119119        /* Sets up container used for the avatar of the current component being viewed. Rendered by bp_get_options_avatar() */
    120120        $bp['bp_options_avatar'] = '';
    121        
    122         /* Sets up container for callback messages rendered by bp_core_render_notice() */
    123         $bp['message'] = '';
    124        
    125         /* Sets up container for callback message type rendered by bp_core_render_notice() */
    126         $bp['message_type'] = ''; // error/success
    127121
    128122        /* Fetch the full name for the logged in and current user */
     
    146140add_action( 'wp', 'bp_core_setup_globals', 1 );
    147141add_action( '_admin_menu', 'bp_core_setup_globals', 1 ); // must be _admin_menu hook.
     142
     143
     144function bp_core_setup_session() {
     145        // Start a session for error/success feedback on redirect and for signup functions.
     146        session_start();
     147       
     148        // Render any error/success feedback on the template
     149        if ( $_SESSION['message'] != '' )
     150                add_action( 'template_notices', 'bp_core_render_notice' );
     151}
     152add_action( 'wp', 'bp_core_setup_session', 3 );
    148153
    149154
     
    423428       
    424429        if ( $bp['current_component'] == MEMBERS_SLUG && isset( $_GET['random'] ) ) {
    425                 $users = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM " . $wpdb->base_prefix . "users WHERE user_status = 0 AND spam = 0 AND deleted = 0" ) );
    426 
    427                 $ud = get_userdata( $users[rand( 0, count($users) - 1)] );
     430                $user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->base_prefix . "users WHERE user_status = 0 AND spam = 0 AND deleted = 0 ORDER BY rand() LIMIT 1" ) );
     431
     432                $ud = get_userdata( $user_id );
    428433                wp_redirect( $bp['root_domain'] . '/' . MEMBERS_SLUG . '/' . $ud->user_login );
    429434        }
     
    763768}
    764769
     770function bp_core_add_message( $message, $type = false ) {
     771        if ( !$type )
     772                $type = 'success';
     773       
     774        $_SESSION['message'] = $message;
     775        $_SESSION['message_type'] = $type;
     776}
     777
    765778/**
    766779 * bp_core_render_notice()
     
    768781 * Renders a feedback notice (either error or success message) to the theme template.
    769782 * The hook action 'template_notices' is used to call this function, it is not called directly.
    770  * The message and message type are stored in the $bp global, and are set up right before
    771  * the add_action( 'template_notices', 'bp_core_render_notice' ); is called where needed.
    772783 *
    773784 * @package BuddyPress Core
     
    775786 */
    776787function bp_core_render_notice() {
    777         global $bp;
    778 
    779         if ( $bp['message'] != '' ) {
    780                 $type = ( $bp['message_type'] == 'success' ) ? 'updated' : 'error';
     788        if ( $_SESSION['message'] ) {
     789                $type = ( $_SESSION['message_type'] == 'success' ) ? 'updated' : 'error';
    781790        ?>
    782791                <div id="message" class="<?php echo $type; ?>">
    783                         <p><?php echo $bp['message']; ?></p>
     792                        <p><?php echo $_SESSION['message']; ?></p>
    784793                </div>
    785794        <?php
     795                unset( $_SESSION['message'] );
     796                unset( $_SESSION['message_type'] );
    786797        }
    787798}
  • trunk/bp-friends.php

    r502 r511  
    122122               
    123123                if ( friends_accept_friendship( $bp['action_variables'][1] ) ) {
    124                         $bp['message'] = __('Friendship accepted', 'buddypress');
    125                         $bp['message_type'] = 'success';
     124                        bp_core_add_message( __('Friendship accepted', 'buddypress') );
    126125                } else {
    127                         $bp['message'] = __('Friendship could not be accepted', 'buddypress');
    128                         $bp['message_type'] = 'error';                                 
     126                        bp_core_add_message( __('Friendship could not be accepted', 'buddypress'), 'error' );
    129127                }
    130                 add_action( 'template_notices', 'bp_core_render_notice' );
     128                wp_redirect( $_SERVER['HTTP_REFERER'] );
    131129               
    132130        } else if ( isset($bp['action_variables']) && in_array( 'reject', $bp['action_variables'] ) && is_numeric($bp['action_variables'][1]) ) {
    133131               
    134132                if ( friends_reject_friendship( $bp['action_variables'][1] ) ) {
    135                         $bp['message'] = __('Friendship rejected', 'buddypress');
    136                         $bp['message_type'] = 'success';
     133                        bp_core_add_message( __('Friendship rejected', 'buddypress') );
    137134                } else {
    138                         $bp['message'] = __('Friendship could not be rejected', 'buddypress');
    139                         $bp['message_type'] = 'error';                         
    140                 }
    141                 add_action( 'template_notices', 'bp_core_render_notice' );
    142                
    143         }
     135                        bp_core_add_message( __('Friendship could not be rejected', 'buddypress'), 'error' );
     136                }       
     137                wp_redirect( $_SERVER['HTTP_REFERER'] );       
     138        }
     139       
    144140        bp_catch_uri( 'friends/requests' );
    145141}
  • trunk/bp-groups.php

    r508 r511  
    260260
    261261                if ( $member->save() ) {
    262                         $bp['message'] = __('Group invite accepted', 'buddypress');
    263                         $bp['message_type'] = 'success';
     262                        bp_core_add_message( __('Group invite accepted', 'buddypress') );
    264263                } else {
    265                         $bp['message'] = __('Group invite could not be accepted', 'buddypress');
    266                         $bp['message_type'] = 'error';                                 
     264                        bp_core_add_message( __('Group invite could not be accepted', 'buddypress'), 'error' );                 
    267265                }
    268                 add_action( 'template_notices', 'bp_core_render_notice' );
     266                wp_redirect( $_SERVER['HTTP_REFERER'] );
     267               
    269268        } else if ( isset($bp['action_variables']) && in_array( 'reject', $bp['action_variables'] ) && is_numeric($bp['action_variables'][1]) ) {
    270269                if ( BP_Groups_Member::delete( $bp['loggedin_userid'], $bp['action_variables'][1] ) ) {
    271                         $bp['message'] = __('Group invite rejected', 'buddypress');
    272                         $bp['message_type'] = 'success';
     270                        bp_core_add_message( __('Group invite rejected', 'buddypress') );
    273271                } else {
    274                         $bp['message'] = __('Group invite could not be rejected', 'buddypress');
    275                         $bp['message_type'] = 'error';                         
     272                        bp_core_add_message( __('Group invite could not be rejected', 'buddypress'), 'error' );                 
    276273                }
    277                 add_action( 'template_notices', 'bp_core_render_notice' );
    278         }
     274                wp_redirect( $_SERVER['HTTP_REFERER'] );
     275        }
     276       
    279277        bp_catch_uri( 'groups/list-invites' ); 
    280278}
     
    308306                        //var_dump($create_group_step, $_COOKIE['group_obj_id']);
    309307                        if ( !$group_obj_id = &groups_manage_group( $create_group_step, $_COOKIE['group_obj_id'] ) ) {
    310                                 $bp['message'] = __('There was an error saving group details. Please try again.', 'buddypress');
    311                                 $bp['message_type'] = 'error';
    312                
    313                                 add_action( 'template_notices', 'bp_core_render_notice' );
     308                                bp_core_add_message( __('There was an error saving group details. Please try again.', 'buddypress'), 'error' );
     309                                wp_redirect( $_SERVER['HTTP_REFERER'] );
    314310                        } else {
    315311                                $create_group_step++;
     
    364360                                bp_catch_uri( 'groups/group-home' );
    365361                        } else {
    366                                 $bp['message'] = __('Wire message successfully posted.', 'buddypress');
    367                                 $bp['message_type'] = 'success';
    368 
    369                                 add_action( 'template_notices', 'bp_core_render_notice' );
    370                                 if ( !strpos( $_SERVER['HTTP_REFERER'], 'wire' ) ) {
    371                                         bp_catch_uri( 'groups/group-home' );
     362                                bp_core_add_message( __('Wire message successfully posted.', 'buddypress') );
     363                               
     364                                if ( !strpos( $_SERVER['HTTP_REFERER'], $bp['wire']['slug'] ) ) {
     365                                        wp_redirect( bp_group_permalink( $group_obj, false ) );
    372366                                } else {
    373                                         bp_catch_uri( 'groups/wire' );
     367                                        wp_redirect( bp_group_permalink( $group_obj, false ) . '/' . $bp['wire']['slug'] );
    374368                                }
    375369                        }
     
    381375                                bp_catch_uri( 'groups/group-home' );
    382376                        } else {
    383                                 $bp['message'] = __('Wire message successfully deleted.', 'buddypress');
    384                                 $bp['message_type'] = 'success';
    385 
    386                                 add_action( 'template_notices', 'bp_core_render_notice' );
    387 
    388                                 if ( !strpos( $_SERVER['HTTP_REFERER'], 'wire' ) ) {
    389                                         bp_catch_uri( 'groups/group-home' );
     377                                bp_core_add_message( __('Wire message successfully deleted.', 'buddypress') );
     378                               
     379                                if ( !strpos( $_SERVER['HTTP_REFERER'], $bp['wire']['slug'] ) ) {
     380                                        wp_redirect( bp_group_permalink( $group_obj, false ) );
    390381                                } else {
    391                                         bp_catch_uri( 'groups/wire' );
    392                                 }                                                                       
     382                                        wp_redirect( bp_group_permalink( $group_obj, false ) . '/' . $bp['wire']['slug'] );
     383                                }
    393384                        }
    394385               
     
    429420                        groups_send_invites($group_obj);
    430421                       
    431                         $bp['message'] = __('Group invites sent.', 'buddypress');
    432                         $bp['message_type'] = 'success';
    433                        
    434                         add_action( 'template_notices', 'bp_core_render_notice' );
    435                         bp_catch_uri( 'groups/group-home' );
     422                        bp_core_add_message( __('Group invites sent.', 'buddypress') );
     423                        wp_redirect( bp_group_permalink( $group_obj, false ) );
    436424                } else {
    437425                        // Show send invite page
     
    449437                        // remove the user from the group.
    450438                        if ( !groups_leave_group( $group_obj->id ) ) {
    451                                 $bp['message'] = __('There was an error leaving the group. Please try again.', 'buddypress');
    452                                 $bp['message_type'] = 'error';                                                                         
     439                                bp_core_add_message(  __('There was an error leaving the group. Please try again.', 'buddypress'), 'error' );
     440                                wp_redirect( bp_group_permalink( $group_obj, false) );
    453441                        } else {
    454                                 $bp['message'] = __('You left the group successfully.', 'buddypress');
    455                                 $bp['message_type'] = 'success';       
     442                                bp_core_add_message( __('You left the group successfully.', 'buddypress') );
     443                                wp_redirect( $bp['loggedin_domain'] . $bp['groups']['slug'] );
    456444                        }
    457                         add_action( 'template_notices', 'bp_core_render_notice' );
    458                
    459                         $bp['current_action'] = 'group-home';
    460                         bp_catch_uri( 'groups/group-home' );
    461                
    462445                } else if ( isset($bp['action_variables']) && $bp['action_variables'][0] == 'no' ) {
    463                         bp_catch_uri( 'groups/group-home' );
     446                        wp_redirect( bp_group_permalink( $group_obj, false) );
    464447                } else {
    465448                        // Show leave group page
     
    476459       
    477460        if ( $group_obj->status == 'private' ) {
    478                
    479461                // If the user has submitted a request, send it.
    480462                if ( isset( $_POST['group-request-send']) ) {
    481463                        if ( !groups_send_membership_request( $bp['loggedin_userid'], $group_obj->id ) ) {
    482                                 $bp['message'] = __( 'There was an error sending your group membership request, please try again.', 'buddypress' );
    483                                 $bp['message_type'] = 'error';
     464                                bp_core_add_message( __( 'There was an error sending your group membership request, please try again.', 'buddypress' ), 'error' );
    484465                        } else {
    485                                 $bp['message'] = __( 'Your membership request was sent to the group administrator successfully. You will be notified when the group administrator responds to your request.', 'buddypress' );
    486                                 $bp['message_type'] = 'success';
     466                                bp_core_add_message( __( 'Your membership request was sent to the group administrator successfully. You will be notified when the group administrator responds to your request.', 'buddypress' ) );
    487467                        }
    488                         add_action( 'template_notices', 'bp_core_render_notice' );
    489 
    490468                }
    491469                bp_catch_uri( 'groups/request-membership' );
     
    501479
    502480function groups_screen_group_admin_edit_details() {
    503         global $bp;
     481        global $bp, $group_obj;
    504482       
    505483        if ( $bp['current_component'] == $bp['groups']['slug'] && $bp['action_variables'][0] == 'edit-details' ) {
     
    507485                if ( !$bp['is_item_admin'] )
    508486                        return false;
    509                        
     487               
    510488                // If the edit form has been submitted, save the edited details
    511489                if ( isset( $_POST['save'] ) ) {
    512490                        if ( !groups_edit_base_group_details( $_POST['group-id'], $_POST['group-name'], $_POST['group-desc'], $_POST['group-news'], (int)$_POST['group-notify-members'] ) ) {
    513                                 $bp['message'] = __( 'There was an error updating group details, please try again.', 'buddypress' );
    514                                 $bp['message_type'] = 'error';
     491                                bp_core_add_message( __( 'There was an error updating group details, please try again.', 'buddypress' ), 'error' );
    515492                        } else {
    516                                 $bp['message'] = __( 'Group details were successfully updated.', 'buddypress' );
    517                                 $bp['message_type'] = 'success';
     493                                bp_core_add_message( __( 'Group details were successfully updated.', 'buddypress' ) );
    518494                        }
    519                         add_action( 'template_notices', 'bp_core_render_notice' );
     495                        wp_redirect( $_SERVER['HTTP_REFERER'] );
    520496                }
    521497
     
    523499        }
    524500}
    525 add_action( 'wp', 'groups_screen_group_admin_edit_details', 3 );
     501add_action( 'wp', 'groups_screen_group_admin_edit_details', 4 );
    526502
    527503
     
    543519                       
    544520                        if ( !groups_edit_group_settings( $_POST['group-id'], $enable_wire, $enable_forum, $enable_photos, $photos_admin_only, $status ) ) {
    545                                 $bp['message'] = __( 'There was an error updating group settings, please try again.', 'buddypress' );
    546                                 $bp['message_type'] = 'error';
     521                                bp_core_add_message( __( 'There was an error updating group settings, please try again.', 'buddypress' ), 'error' );
    547522                        } else {
    548                                 $bp['message'] = __( 'Group settings were successfully updated.', 'buddypress' );
    549                                 $bp['message_type'] = 'success';
     523                                bp_core_add_message( __( 'Group settings were successfully updated.', 'buddypress' ) );
    550524                        }
    551                         add_action( 'template_notices', 'bp_core_render_notice' );
     525                       
     526                        wp_redirect( $_SERVER['HTTP_REFERER'] );
    552527                }
    553528               
     
    555530        }
    556531}
    557 add_action( 'wp', 'groups_screen_group_admin_settings', 3 );
     532add_action( 'wp', 'groups_screen_group_admin_settings', 4 );
    558533
    559534
     
    576551                                // Accept the membership request
    577552                                if ( !groups_accept_membership_request( $membership_id ) ) {
    578                                         $bp['message'] = __( 'There was an error accepting the membership request, please try again.', 'buddypress' );
    579                                         $bp['message_type'] = 'error';
     553                                        bp_core_add_message( __( 'There was an error accepting the membership request, please try again.', 'buddypress' ), 'error' );
    580554                                } else {
    581                                         $bp['message'] = __( 'Group membership request accepted', 'buddypress' );
    582                                         $bp['message_type'] = 'success';
     555                                        bp_core_add_message( __( 'Group membership request accepted', 'buddypress' ) );
    583556                                }
    584557                        } else if ( $request_action == 'reject' && is_numeric($membership_id) ) {
    585558                                // Reject the membership request
    586559                                if ( !groups_reject_membership_request( $membership_id ) ) {
    587                                         $bp['message'] = __( 'There was an error rejecting the membership request, please try again.', 'buddypress' );
    588                                         $bp['message_type'] = 'error';
     560                                        bp_core_add_message( __( 'There was an error rejecting the membership request, please try again.', 'buddypress' ), 'error' );
    589561                                } else {
    590                                         $bp['message'] = __( 'Group membership request rejected', 'buddypress' );
    591                                         $bp['message_type'] = 'success';
     562                                        bp_core_add_message( __( 'Group membership request rejected', 'buddypress' ) );
    592563                                }       
    593564                        }
    594                         add_action( 'template_notices', 'bp_core_render_notice' );
     565                        wp_redirect( $_SERVER['HTTP_REFERER'] );
    595566                }
    596567               
     
    598569        }
    599570}
    600 add_action( 'wp', 'groups_screen_group_admin_requests', 3 );
    601 
     571add_action( 'wp', 'groups_screen_group_admin_requests', 4 );
     572
     573function groups_screen_group_admin_delete_group() {
     574        global $bp, $group_obj;
     575       
     576        if ( $bp['current_component'] == $bp['groups']['slug'] && $bp['action_variables'][0] == 'delete-group' ) {
     577               
     578                if ( !$bp['is_item_admin'] )
     579                        return false;
     580               
     581                if ( isset( $_POST['delete-group-button'] ) && isset( $_POST['delete-group-understand'] ) ) {
     582                        // Group admin has deleted the group, now do it.
     583                        if ( !groups_delete_group( $_POST['group-id']) ) {
     584                                bp_core_add_message( __( 'There was an error deleting the group, please try again.', 'buddypress' ), 'error' );
     585                        } else {
     586                                bp_core_add_message( __( 'The group was deleted successfully', 'buddypress' ) );
     587                                wp_redirect( site_url() . '/' . $bp['groups']['slug'] . '/' );
     588                        }
     589                        wp_redirect( $_SERVER['HTTP_REFERER'] );
     590                } else {
     591                        bp_catch_uri( 'groups/admin/delete-group' );
     592                }
     593        }
     594}
     595add_action( 'wp', 'groups_screen_group_admin_delete_group', 4 );
    602596
    603597function groups_screen_notification_settings() {
     
    660654        if ( !groups_is_user_member( $bp['loggedin_userid'], $group_obj->id ) ) {
    661655                if ( !groups_join_group($group_obj->id) ) {
    662                         $bp['message'] = __('There was an error joining the group. Please try again.', 'buddypress');
    663                         $bp['message_type'] = 'error';
     656                        bp_core_add_message( __('There was an error joining the group. Please try again.', 'buddypress'), 'error' );
    664657                } else {
    665                         $bp['message'] = __('You joined the group!', 'buddypress');
    666                         $bp['message_type'] = 'success';       
     658                        bp_core_add_message( __('You joined the group!', 'buddypress') );
    667659                }
    668 
    669                 add_action( 'template_notices', 'bp_core_render_notice' );
     660                wp_redirect( $_SERVER['HTTP_REFERER'] );
    670661        }
    671662
     
    11921183}
    11931184
     1185function groups_is_group_admin( $user_id, $group_id ) {
     1186        return BP_Groups_Member::check_is_admin( $user_id, $group_id );
     1187}
     1188
    11941189function groups_new_wire_post( $group_id, $content ) {
    11951190        if ( $wire_post_id = bp_wire_new_post( $group_id, $content ) ) {
     
    12291224        if ( !$group->save() )
    12301225                return false;
    1231        
     1226
    12321227        if ( $notify_members )
    12331228                groups_notification_group_updated( $group->id );
     
    13121307}
    13131308
    1314 function groups_get_random_group() {
     1309function groups_redirect_to_random_group() {
    13151310        global $bp, $wpdb;
    13161311       
    13171312        if ( $bp['current_component'] == $bp['groups']['slug'] && isset( $_GET['random'] ) ) {
    1318                 $groups = groups_get_all();
    1319 
    1320                 wp_redirect( $bp['root_domain'] . '/' . $bp['groups']['slug'] . '/' . $groups[rand( 0, count($groups) - 1)]->slug );
    1321         }
    1322 }
    1323 add_action( 'wp', 'groups_get_random_group', 6 );
     1313                $group = groups_get_random_group();
     1314
     1315                wp_redirect( $bp['root_domain'] . '/' . $bp['groups']['slug'] . '/' . $group->slug );
     1316        }
     1317}
     1318add_action( 'wp', 'groups_redirect_to_random_group', 6 );
     1319
     1320function groups_delete_group( $group_id ) {
     1321        global $bp;
     1322       
     1323        // Check the user is the group admin.
     1324        if ( !groups_is_group_admin( $bp['loggedin_userid'], $group_id ) )
     1325                return false;
     1326       
     1327        // Get the group object
     1328        $group = new BP_Groups_Group( $group_id );
     1329       
     1330        if ( !$group->delete() )
     1331                return false;
     1332       
     1333        return true;
     1334}
    13241335
    13251336function groups_check_for_membership_request( $user_id, $group_id ) {
     
    13411352function groups_get_all() {
    13421353        return BP_Groups_Group::get_all();
     1354}
     1355
     1356function groups_get_random_group() {
     1357        return BP_Groups_Group::get_random();
    13431358}
    13441359
     
    13491364//
    13501365
    1351 function groups_delete_groupmeta( $group_id, $meta_key, $meta_value = '' ) {
     1366function groups_delete_groupmeta( $group_id, $meta_key = false, $meta_value = false ) {
    13521367        global $wpdb, $bp;
    13531368       
     
    13621377        $meta_value = trim( $meta_value );
    13631378
    1364         if ( !empty($meta_value) )
    1365                 $wpdb->query( $wpdb->prepare("DELETE FROM " . $bp['groups']['table_name_groupmeta'] . " WHERE groups_id = %d AND meta_key = %s AND meta_value = %s", $group_id, $meta_key, $meta_value) );
    1366         else
    1367                 $wpdb->query( $wpdb->prepare("DELETE FROM " . $bp['groups']['table_name_groupmeta'] . " WHERE group_id = %d AND meta_key = %s", $group_id, $meta_key) );
    1368 
     1379        if ( !$meta_key ) {
     1380                $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['groups']['table_name_groupmeta'] . " WHERE group_id = %d", $group_id ) );           
     1381        } else if ( !$meta_value ) {
     1382                $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['groups']['table_name_groupmeta'] . " WHERE group_id = %d AND meta_key = %s AND meta_value = %s", $group_id, $meta_key, $meta_value ) );
     1383        } else {
     1384                $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['groups']['table_name_groupmeta'] . " WHERE group_id = %d AND meta_key = %s", $group_id, $meta_key ) );
     1385        }
     1386       
    13691387        // TODO need to look into using this.
    13701388        // wp_cache_delete($group_id, 'groups');
  • trunk/bp-groups/bp-groups-classes.php

    r508 r511  
    164164                        );
    165165                }
    166 
    167                 if ( !$result = $wpdb->query($sql) )
     166               
     167                if ( $wpdb->query($sql) === false )
    168168                        return false;
    169169               
     
    228228                return false;
    229229        }
     230       
     231        function delete() {
     232                global $wpdb, $bp;
     233               
     234                // Delete groupmeta for the group
     235                groups_delete_groupmeta( $this->id );
     236
     237                // Modify group count usermeta for members
     238                for ( $i = 0; $i < count($this->user_dataset); $i++ ) {
     239                        $user = $this->user_dataset[$i];
     240
     241                        if ( $total_count = get_usermeta( $user->user_id, 'total_group_count' ) != '' ) {
     242                                update_usermeta( $user->user_id, 'total_group_count', (int)$total_count - 1 );
     243                        }
     244                       
     245                        // Now delete the group member record
     246                        BP_Groups_Member::delete( $user->user_id, $this->id, false );
     247                }
     248               
     249                // Delete the wire posts for this group if the wire is installed
     250                if ( function_exists('bp_wire_install') ) {
     251                        BP_Wire_Post::delete_all_for_item( $this->id, $bp['groups']['table_name_wire'] );
     252                }
     253               
     254                do_action( 'bp_groups_delete_group_content', $this->id );
     255               
     256                // Finally remove the group entry from the DB
     257                if ( !$wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['groups']['table_name'] . " WHERE id = %d", $this->id ) ) )
     258                        return false;
     259
     260                return true;
     261        }
     262       
    230263
    231264        /* Static Functions */
    232        
    233         function delete( $group_id ) {
    234                 global $wpdb, $bp;
    235                
    236                 if ( $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['groups']['table_name'] . " WHERE id = %d", $group_id ) ) )
    237                         return false;
    238                
    239                 /* Remove groupmeta */
    240                 groups_delete_groupmeta( $group_id );
    241                
    242                 return true;
    243         }
    244        
     265               
    245266        function group_exists( $slug, $table_name = false ) {
    246267                global $wpdb, $bp;
     
    379400               
    380401                return $wpdb->get_results( $wpdb->prepare( "SELECT id, slug FROM " . $bp['groups']['table_name'] . " WHERE status = 'public'" ) );
     402        }
     403       
     404        function get_random() {
     405                global $wpdb, $bp;
     406               
     407                return $wpdb->get_row( $wpdb->prepare( "SELECT id, slug FROM " . $bp['groups']['table_name'] . " WHERE status = 'public' ORDER BY rand() LIMIT 1" ) );         
    381408        }
    382409}
     
    476503        /* Static Functions */
    477504
    478         function delete( $user_id, $group_id ) {
     505        function delete( $user_id, $group_id, $check_empty = true ) {
    479506                global $wpdb, $bp;
    480507               
    481508                $delete_result = $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );
    482        
    483                 // Check to see if there are any members left for the group, if not, delete it.
    484                 if ( !BP_Groups_Group::has_members( $group_id ) ) {
    485                         BP_Groups_Group::delete( $group_id );
    486                 }
    487                
     509
    488510                return $delete_result;
    489511        }
  • trunk/bp-groups/bp-groups-templatetags.php

    r505 r511  
    414414        <li<?php if ( $current_tab == 'edit-details' || $current_tab == '' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/edit-details"><?php _e('Edit Details', 'buddypress') ?></a></li>
    415415        <li<?php if ( $current_tab == 'group-settings' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/group-settings"><?php _e('Group Settings', 'buddypress') ?></a></li>
    416         <!--<li<?php if ( $current_tab == 'manage-members' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/manage-members"><?php _e('Manage Members', 'buddypress') ?></a></li>-->
    417         <!--<li<?php if ( $current_tab == 'delete-group' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/delete-group"><?php _e('Delete Group', 'buddypress') ?></a></li>-->
     416        <li<?php if ( $current_tab == 'manage-members' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/manage-members"><?php _e('Manage Members', 'buddypress') ?></a></li>
     417       
    418418        <?php if ( $groups_template->group->status == 'private' ) : ?>
    419419        <li<?php if ( $current_tab == 'membership-requests' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/membership-requests"><?php _e('Membership Requests', 'buddypress') ?></a></li>
    420420        <?php endif; ?>
     421       
     422        <li<?php if ( $current_tab == 'delete-group' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/delete-group"><?php _e('Delete Group', 'buddypress') ?></a></li>
     423       
    421424<?php
    422425        do_action( 'bp_groups_admin_tabs' );
     
    575578                                                bp_group_send_invite_form( $group_obj );
    576579                                        } else {
    577                                                 $group_link = bp_group_permalink( $group, false );
     580                                                $group_link = bp_group_permalink( $group_obj, false );
    578581                                                ?>
    579582                                                <div id="message" class="info">
  • trunk/bp-messages.php

    r462 r511  
    117117
    118118function messages_check_installed() {   
    119         global $wpdb, $bp, $userdata;
     119        global $wpdb, $bp;
    120120
    121121        if ( is_site_admin() ) {
     
    174174
    175175function messages_screen_compose() {
     176       
     177        if ( isset($_POST['send_to']) || ( isset($_POST['send-notice']) && is_site_admin() ) ) {
     178                messages_send_message( $_POST['send_to'], $_POST['subject'], $_POST['content'], $_POST['thread_id'], false, true );
     179        }
     180       
    176181        bp_catch_uri( 'messages/compose' );
    177182}
     
    193198                if ( $bp['action_variables'][0] == 'deactivate' ) {
    194199                        if ( !$notice->deactivate() ) {
    195                                 $bp['message'] = __('There was a problem deactivating that notice.', 'buddypress');     
     200                                bp_core_add_message( __('There was a problem deactivating that notice.', 'buddypress'), 'error' );     
    196201                        } else {
    197                                 $bp['message'] = __('Notice deactivated.', 'buddypress');
    198                                 $bp['message_type'] = 'success';
     202                                bp_core_add_message( __('Notice deactivated.', 'buddypress') );
    199203                        }
    200204                } else if ( $bp['action_variables'][0] == 'activate' ) {
    201205                        if ( !$notice->activate() ) {
    202                                 $bp['message'] = __('There was a problem activating that notice.', 'buddypress');
     206                                bp_core_add_message( __('There was a problem activating that notice.', 'buddypress'), 'error' );
    203207                        } else {
    204                                 $bp['message'] = __('Notice activated.', 'buddypress');
    205                                 $bp['message_type'] = 'success';
     208                                bp_core_add_message( __('Notice activated.', 'buddypress') );
    206209                        }
    207210                } else if ( $bp['action_variables'][0] == 'delete' ) {
    208211                        if ( !$notice->delete() ) {
    209                                 $bp['message'] = __('There was a problem deleting that notice.', 'buddypress');
     212                                bp_core_add_message( __('There was a problem deleting that notice.', 'buddypress'), 'buddypress' );
    210213                        } else {
    211                                 $bp['message'] = __('Notice deleted.', 'buddypress');
    212                                 $bp['message_type'] = 'success';
     214                                bp_core_add_message( __('Notice deleted.', 'buddypress') );
    213215                        }
    214216                }
    215217        }
    216                
    217         add_action( 'template_notices', 'bp_core_render_notice' );
    218218        bp_catch_uri( 'messages/notices' );     
    219219}
     
    279279
    280280        if ( !$thread_id || !is_numeric($thread_id) || !BP_Messages_Thread::check_access($thread_id) ) {
    281                 $bp['current_action'] = 'inbox';
    282                 bp_catch_uri( 'messages/index' );
     281                wp_redirect( $_SERVER['HTTP_REFERER'] );
    283282        } else {
    284283                // delete message
    285284                if ( !BP_Messages_Thread::delete($thread_id) ) {
    286                         $bp['message'] = __('There was an error deleting that message.', 'buddypress');
    287                         add_action( 'template_notices', 'bp_core_render_notice' );
    288 
    289                         $bp['current_action'] = 'inbox';
    290                         bp_catch_uri( 'messages/index' );
    291                 } else {
    292                         $bp['message'] = __('Message deleted.', 'buddypress');
    293                         $bp['message_type'] = 'success';
    294                         add_action( 'template_notices', 'bp_core_render_notice' );
    295 
    296                         $bp['current_action'] = 'inbox';
    297                         bp_catch_uri( 'messages/index' );
     285                        bp_core_add_message( __('There was an error deleting that message.', 'buddypress'), 'error' );
     286                        wp_redirect( $_SERVER['HTTP_REFERER'] );
     287                } else {
     288                        bp_core_add_message( __('Message deleted.', 'buddypress') );
     289                        wp_redirect( $_SERVER['HTTP_REFERER'] );
    298290                }
    299291        }
     
    315307        } else {
    316308                if ( !BP_Messages_Thread::delete( explode(',', $thread_ids ) ) ) {
    317                         $message = __('There was an error deleting messages.', 'buddypress');
    318                         add_action( 'template_notices', 'bp_core_render_notice' );
    319 
    320                         $bp['current_action'] = 'inbox';
    321                         bp_catch_uri( 'messages/index' );
    322                 } else {
    323                         $bp['message'] = __('Messages deleted.', 'buddypress');
    324                         $bp['message_type'] = 'success';
    325                         add_action( 'template_notices', 'bp_core_render_notice' );
    326 
    327                         $bp['current_action'] = 'inbox';
    328                         bp_catch_uri( 'messages/index' );
     309                        bp_core_add_message( __('There was an error deleting messages.', 'buddypress'), 'error' );
     310                        wp_redirect( $_SERVER['HTTP_REFERER'] );
     311                } else {
     312                        bp_core_add_message( __('Messages deleted.', 'buddypress') );
     313                        wp_redirect( $_SERVER['HTTP_REFERER'] );
    329314                }
    330315        }
     
    360345
    361346/**************************************************************************
    362  messages_write_new()
    363  
    364  Handle and display the write new messages screen.
    365  **************************************************************************/
    366 
    367 function messages_write_new( $username = '', $subject = '', $content = '', $type = '', $message = '' ) { ?>
    368         <?php
    369         global $messages_write_new_action;
    370         ?>
    371        
    372         <div class="wrap">
    373                 <h2><?php _e('Compose Message', 'buddypress') ?></h2>
    374                
    375                 <?php
    376                         if ( $message != '' ) {
    377                                 $type = ( $type == 'error' ) ? 'error' : 'updated';
    378                 ?>
    379                         <div id="message" class="<?php echo $type; ?> fade">
    380                                 <p><?php echo $message; ?></p>
    381                         </div>
    382                 <?php } ?>
    383                                                
    384                 <form action="<?php echo $messages_write_new_action ?>" method="post" id="send_message_form">
    385                 <div id="poststuff">
    386                         <p>                     
    387                         <div id="titlediv">
    388                                 <h3><?php _e("Send To", 'buddypress') ?> <small>(Use username - autocomplete coming soon)</small></h3>
    389                                 <div id="titlewrap">
    390                                         <input type="text" name="send_to" id="send_to" value="<?php echo $username; ?>" />
    391                                         <?php if ( is_site_admin() ) : ?><br /><input type="checkbox" id="send-notice" name="send-notice" value="1" /> This is a notice to all users.<?php endif; ?>
    392                                 </div>
    393                         </div>
    394                         </p>
    395 
    396                         <p>
    397                         <div id="titlediv">
    398                                 <h3><?php _e("Subject", 'buddypress') ?></h3>
    399                                 <div id="titlewrap">
    400                                         <input type="text" name="subject" id="subject" value="<?php echo $subject; ?>" />
    401                                 </div>
    402                         </div>
    403                         </p>
    404                        
    405                         <p>
    406                                 <div id="postdivrich" class="postarea">
    407                                         <h3><?php _e("Message", 'buddypress') ?></h3>
    408                                         <div id="editorcontainer">
    409                                                 <textarea name="content" id="message_content" rows="15" cols="40"><?php echo $content; ?></textarea>
    410                                         </div>
    411                                 </div>
    412                         </p>
    413                        
    414                         <p class="submit">
    415                                         <input type="submit" value="<?php _e("Send", 'buddypress') ?> &raquo;" name="send" id="send" style="font-weight: bold" />
    416                         </p>
    417                 </div>
    418                 </form>
    419                 <script type="text/javascript">
    420                         document.getElementById("send_to").focus();
    421                 </script>
    422                
    423         </div>
    424         <?php
    425 }
    426 
    427 /**************************************************************************
    428347 messages_send_message()
    429348 
     
    432351
    433352function messages_send_message( $recipients, $subject, $content, $thread_id, $from_ajax = false, $from_template = false, $is_reply = false ) {
    434         global $userdata;
    435         global $messages_write_new_action;
    436353        global $pmessage;
    437354        global $message, $type;
     
    440357        if ( isset( $_POST['send-notice'] ) ) {
    441358                messages_send_notice( $subject, $content, $from_template );
    442         } else {
    443                 if ( $recipients == '' ) {
    444                         if ( !$from_ajax ) {
    445                                 messages_write_new( '', $subject, $content, 'error', __('Please enter at least one valid user to send this message to.', 'buddypress'), $messages_write_new_action );
     359                return true;
     360        }
     361
     362        messages_add_callback_values( $recipients, $subject, $content );
     363
     364        if ( $recipients == '' ) {
     365                if ( !$from_ajax ) {   
     366                        bp_core_add_message( __('Please enter at least one valid user to send this message to.', 'buddypress'), 'error' );
     367                        wp_redirect( $_SERVER['HTTP_REFERER'] );
     368                } else {
     369                        return array('status' => 0, 'message' => __('There was an error sending the reply, please try again.', 'buddypress'));
     370                }
     371        } else if ( $subject == '' || $content == '' ) {
     372                if ( !$from_ajax ) {
     373                        bp_core_add_message( __('Please make sure you fill in all the fields.', 'buddypress'), 'error' );
     374                        wp_redirect( $_SERVER['HTTP_REFERER'] );
     375                } else {
     376                        return array('status' => 0, 'message' => __('Please make sure you have typed a message before sending a reply.', 'buddypress'));
     377                }
     378        } else {
     379                $pmessage = new BP_Messages_Message;
     380
     381                $pmessage->sender_id = $bp['loggedin_userid'];
     382                $pmessage->subject = $subject;
     383                $pmessage->message = $content;
     384                $pmessage->thread_id = $thread_id;
     385                $pmessage->date_sent = time();
     386                $pmessage->message_order = 0; // TODO
     387                $pmessage->sender_is_group = 0;
     388               
     389                if ( $is_reply ) {
     390                        $thread = new BP_Messages_Thread($thread_id);
     391                        $pmessage->recipients = $thread->get_recipients();
     392                } else {
     393                        $pmessage->recipients = BP_Messages_Message::get_recipient_ids( explode( ',', $recipients ) );
     394                }
     395
     396                if ( !is_null( $pmessage->recipients ) ) {
     397                        if ( !$pmessage->send() ) {
     398                                $message = __('Message could not be sent, please try again.', 'buddypress');
     399                                $type = 'error';
     400               
     401                                if ( $from_ajax ) {
     402                                        return array('status' => 0, 'message' => $message);
     403                                } else {
     404                                        bp_core_add_message( $message, $type );
     405                                        wp_redirect( $_SERVER['HTTP_REFERER'] );
     406                                }
    446407                        } else {
    447                                 return array('status' => 0, 'message' => __('There was an error sending the reply, please try again.', 'buddypress'));
    448                         }
    449                 } else if ( $subject == '' || $content == '' ) {
    450                         if ( !$from_ajax ) {
    451                                 messages_write_new( $to_user, $subject, $content, 'error', __('Please make sure you fill in all the fields.', 'buddypress'), $messages_write_new_action );
    452                         } else {
    453                                 return array('status' => 0, 'message' => __('Please make sure you have typed a message before sending a reply.', 'buddypress'));
    454                         }
    455                 } else {
    456                         $pmessage = new BP_Messages_Message;
    457 
    458                         $pmessage->sender_id = $userdata->ID;
    459                         $pmessage->subject = $subject;
    460                         $pmessage->message = $content;
    461                         $pmessage->thread_id = $thread_id;
    462                         $pmessage->date_sent = time();
    463                         $pmessage->message_order = 0; // TODO
    464                         $pmessage->sender_is_group = 0;
    465                        
    466                         if ( $is_reply ) {
    467                                 $thread = new BP_Messages_Thread($thread_id);
    468                                 $pmessage->recipients = $thread->get_recipients();
    469                         } else {
    470                                 $pmessage->recipients = BP_Messages_Message::get_recipient_ids( explode( ',', $recipients ) );
    471                         }
    472                        
    473                         unset($_GET['mode']);
    474 
    475                         if ( !is_null( $pmessage->recipients ) ) {
    476                                 if ( !$pmessage->send() ) {
    477                                         $message = __('Message could not be sent, please try again.', 'buddypress');
    478                                         $type = 'error';
    479                        
    480                                         if ( $from_ajax ) {
    481                                                 return array('status' => 0, 'message' => $message);
    482                                         } else if ( $from_template ) {
    483                                                 unset($_POST['send_to']);
    484                                                 $bp['message'] = $message;
    485                                                 $bp['message_type'] = $type;
    486                                                
    487                                                 bp_core_render_notice();
    488                                                 messages_write_new();
    489                                         } else {
    490                                                 messages_box( 'inbox', __('Inbox', 'buddypress'), $message, $type );   
    491                                         }
    492                                 } else {
    493                                         $message = __('Message sent successfully!', 'buddypress') . ' <a href="' . $bp['loggedin_domain'] . $bp['messages']['slug'] . '/view/' . $pmessage->thread_id . '">' . __('View Message', 'buddypress') . '</a> &raquo;';
    494                                         $type = 'success';
    495                                        
    496                                         // Send notices to the recipients
    497                                         for ( $i = 0; $i < count($pmessage->recipients); $i++ ) {
    498                                                 if ( $pmessage->recipients[$i] != $bp['loggedin_userid'] ) {
    499                                                         bp_core_add_notification( $pmessage->id, $pmessage->recipients[$i], 'messages', 'new_message' );       
    500                                                 }
    501                                         }
    502                                        
    503                                         do_action( 'bp_messages_message_sent', array( 'item_id' => $pmessage->id, 'recipient_ids' => $pmessage->recipients, 'thread_id' => $pmessage->thread_id, 'component_name' => 'messages', 'component_action' => 'message_sent', 'is_private' => 1 ) );
    504                        
    505                                         if ( $from_ajax ) {
    506                                                 return array('status' => 1, 'message' => $message, 'reply' => $pmessage);
    507                                         } else if ( $from_template ) {
    508                                                 unset($_POST['send_to']);
    509                                                 $bp['message'] = $message;
    510                                                 $bp['message_type'] = $type;
    511                                                
    512                                                 bp_core_render_notice();
    513                                                 messages_write_new();
    514                                         } else {
    515                                                 messages_box( 'inbox', __('Inbox', 'buddypress'), $message, $type );
     408                                $message = __('Message sent successfully!', 'buddypress') . ' <a href="' . $bp['loggedin_domain'] . $bp['messages']['slug'] . '/view/' . $pmessage->thread_id . '">' . __('View Message', 'buddypress') . '</a> &raquo;';
     409                                $type = 'success';
     410                               
     411                                // Send notices to the recipients
     412                                for ( $i = 0; $i < count($pmessage->recipients); $i++ ) {
     413                                        if ( $pmessage->recipients[$i] != $bp['loggedin_userid'] ) {
     414                                                bp_core_add_notification( $pmessage->id, $pmessage->recipients[$i], 'messages', 'new_message' );       
    516415                                        }
    517416                                }
    518                         } else {
    519                                 unset($_POST['send_to']);
    520                                 unset($_POST['send-notice']);
    521                        
    522                                 $message = __('Message could not be sent, please try again.', 'buddypress');
    523                                 $type = 'error';
    524                        
     417                               
     418                                do_action( 'bp_messages_message_sent', array( 'item_id' => $pmessage->id, 'recipient_ids' => $pmessage->recipients, 'thread_id' => $pmessage->thread_id, 'component_name' => 'messages', 'component_action' => 'message_sent', 'is_private' => 1 ) );
     419               
    525420                                if ( $from_ajax ) {
    526                                         return array('status' => 0, 'message' => $message);
    527                                 } else if ( $from_template ) {
    528                                         $bp['message'] = $message;
    529                                         $bp['message_type'] = $type;
    530                                        
    531                                         bp_core_render_notice();
    532                                         messages_write_new();
     421                                        return array('status' => 1, 'message' => $message, 'reply' => $pmessage);
    533422                                } else {
    534                                         messages_box( 'inbox', __('Inbox', 'buddypress'), $message, $type );   
     423                                        bp_core_add_message( $message );
     424                                        wp_redirect( $bp['loggedin_domain'] . $bp['messages']['slug'] . '/inbox' );
    535425                                }
    536426                        }
    537                 }
    538         }
     427                } else {
     428                        $message = __('Message could not be sent, please try again.', 'buddypress');
     429                        $type = 'error';
     430               
     431                        if ( $from_ajax ) {
     432                                return array('status' => 0, 'message' => $message);
     433                        } else {
     434                                bp_core_add_message( $message, $type );
     435                                wp_redirect( $bp['loggedin_domain'] . $bp['messages']['slug'] . '/compose' );
     436                        }
     437                }
     438        }
     439
     440}
     441
     442function messages_add_callback_values( $recipients, $subject, $content ) {
     443        $_SESSION['send_to'] = $recipients;
     444        $_SESSION['subject'] = $subject;
     445        $_SESSION['content'] = $content;
    539446}
    540447
     
    570477                do_action( 'bp_messages_notice_sent', $subject, $message );
    571478        }
    572                
    573479}
    574480
     
    615521
    616522function messages_view_thread( $thread_id ) {
    617         global $userdata, $bp;
     523        global $bp;
    618524
    619525        $thread = new BP_Messages_Thread( $thread_id, true );
     
    634540                                                                <img src="<?php echo $bp['messages']['image_base'] ?>/email_open.gif" alt="Message" style="vertical-align: top;" /> &nbsp;
    635541                                                                <?php _e('Sent between ', 'buddypress') ?> <?php echo BP_Messages_Thread::get_recipient_links($thread->recipients) ?>
    636                                                                 <?php _e('and', 'buddypress') ?> <?php echo bp_core_get_userlink($userdata->ID) ?>.
     542                                                                <?php _e('and', 'buddypress') ?> <?php echo bp_core_get_userlink($bp['loggedin_userid']) ?>.
    637543                                                        </td>
    638544                                                </tr>
     
    665571                                                                <div class="avatar-box">
    666572                                                                        <?php if ( function_exists('bp_core_get_avatar') )
    667                                                                                 echo bp_core_get_avatar($userdata->ID, 1);
     573                                                                                echo bp_core_get_avatar($bp['loggedin_userid'], 1);
    668574                                                                        ?>
    669575                                       
  • trunk/bp-messages/bp-messages-templatetags.php

    r439 r511  
    190190}
    191191
    192 function bp_compose_message_form() {
    193         global $bp;
    194         global $messages_write_new_action;
    195                
    196         $messages_write_new_action = $bp['loggedin_domain'] . $bp['messages']['slug'] . '/compose/';
    197        
    198         if ( isset($_POST['send_to']) || ( isset($_POST['send-notice']) && is_site_admin() ) ) {
    199                 messages_send_message( $_POST['send_to'], $_POST['subject'], $_POST['content'], $_POST['thread_id'], false, true );
    200         } else {
    201                 messages_write_new();
    202         }
    203 }
    204 
    205192function bp_messages_pagination() {
    206193        global $messages_template;
     
    212199       
    213200        echo $bp['loggedin_domain'] . $bp['messages']['slug'] . '/' . $bp['current_action'];
     201}
     202
     203function bp_messages_username_value() {
     204        echo $_SESSION['send_to'];
     205}
     206
     207function bp_messages_subject_value() {
     208        echo $_SESSION['subject'];
     209}
     210
     211function bp_messages_content_value() {
     212        echo $_SESSION['content'];
    214213}
    215214
  • trunk/bp-wire.php

    r476 r511  
    8585        global $bp;
    8686       
    87         if ( $bp['current_action'] != 'post' )
     87        if ( $bp['current_component'] != $bp['xprofile']['slug'] && $bp['current_action'] != 'post' )
    8888                return false;
    8989       
    90         if ( $wire_post_id = bp_wire_new_post( $bp['current_userid'], $_POST['wire-post-textarea'], $bp['profile']['table_name_wire'] ) ) {
    91                 $bp['message'] = __('Wire message successfully posted.', 'buddypress');
    92                 $bp['message_type'] = 'success';
    93 
    94                 do_action( 'bp_xprofile_new_wire_post', array( 'item_id' => $wire_post_id, 'component_name' => 'profile', 'component_action' => 'new_wire_post', 'is_private' => 0 ) );
    95                 add_action( 'template_notices', 'bp_core_render_notice' );
     90        if ( !$wire_post_id = bp_wire_new_post( $bp['current_userid'], $_POST['wire-post-textarea'], $bp['profile']['table_name_wire'] ) ) {
     91                bp_core_add_message( __('Wire message could not be posted. Please try again.', 'buddypress'), 'error' );
     92        } else {
     93                bp_core_add_message( __('Wire message successfully posted.', 'buddypress') );
     94                do_action( 'bp_xprofile_new_wire_post', array( 'item_id' => $wire_post_id, 'component_name' => 'profile', 'component_action' => 'new_wire_post', 'is_private' => 0 ) );
    9695        }
    9796       
    9897        if ( !strpos( $_SERVER['HTTP_REFERER'], $bp['wire']['slug'] ) ) {
    99                 $bp['current_component'] = $bp['profile']['slug'];
    100                 $bp['current_action'] = 'public';
    101                 bp_catch_uri( 'profile/index' );
     98                wp_redirect( $bp['current_domain'] );
    10299        } else {
    103                 bp_catch_uri( 'wire/latest' );
    104         }       
     100                wp_redirect( $bp['current_domain']. $bp['wire']['slug'] );
     101        }
    105102}
    106103add_action( 'wp', 'bp_wire_action_post', 3 );
     
    109106        global $bp;
    110107       
    111         if ( $bp['current_action'] != 'delete' )
     108        if ( $bp['current_component'] != $bp['xprofile']['slug'] && $bp['current_action'] != 'delete' )
    112109                return false;
    113110       
    114111        if ( bp_wire_delete_post( $bp['action_variables'][0], $bp['profile']['table_name_wire'] ) ) {
    115                 $bp['message'] = __('Wire message successfully deleted.', 'buddypress');
    116                 $bp['message_type'] = 'success';
    117                
    118                 do_action( 'bp_xprofile_delete_wire_post' );
    119                 add_action( 'template_notices', 'bp_core_render_notice' );                                                                     
     112                bp_core_add_message( __('Wire message successfully deleted.', 'buddypress'), false, true );
     113                do_action( 'bp_xprofile_delete_wire_post' );                                           
    120114        }
    121115       
    122116        if ( !strpos( $_SERVER['HTTP_REFERER'], $bp['wire']['slug'] ) ) {
    123                 $bp['current_component'] = $bp['profile']['slug'];
    124                 $bp['current_action'] = 'public';
    125                 bp_catch_uri( 'profile/index' );
     117                wp_redirect( $bp['current_domain'] );
    126118        } else {
    127                 bp_catch_uri( 'wire/latest' );
     119                wp_redirect( $bp['current_domain']. $bp['wire']['slug'] );
    128120        }
    129121}
  • trunk/bp-wire/bp-wire-classes.php

    r476 r511  
    100100                return array( 'wire_posts' => $wire_posts, 'count' => $count );
    101101        }
     102       
     103        function delete_all_for_item( $item_id, $table_name ) {
     104                global $wpdb, $bp;
     105               
     106                return $wpdb->query( $wpdb->prepare( "DELETE FROM {$table_name} WHERE item_id = %d", $item_id ) );
     107        }
    102108}
    103109
  • trunk/bp-xprofile.php

    r502 r511  
    126126function xprofile_setup_globals() {
    127127        global $bp, $wpdb;
    128        
    129         /* Need to start a session for signup metadata purposes */
    130         session_start();
    131128       
    132129        $bp['profile'] = array(
Note: See TracChangeset for help on using the changeset viewer.