/**
 * Process a request to view a single message thread.
 */
function messages_action_conversation()
{
    // Bail if not viewing a single conversation
    if (!bp_is_messages_component() || !bp_is_current_action('view')) {
        return false;
    }
    // Get the thread ID from the action variable
    $thread_id = (int) bp_action_variable(0);
    if (!messages_is_valid_thread($thread_id) || !messages_check_thread_access($thread_id) && !bp_current_user_can('bp_moderate')) {
        bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug()));
    }
    // Check if a new reply has been submitted
    if (isset($_POST['send'])) {
        // Check the nonce
        check_admin_referer('messages_send_message', 'send_message_nonce');
        $new_reply = messages_new_message(array('thread_id' => $thread_id, 'subject' => !empty($_POST['subject']) ? $_POST['subject'] : false, 'content' => $_POST['content']));
        // Send the reply
        if (!empty($new_reply)) {
            bp_core_add_message(__('Your reply was sent successfully', 'buddypress'));
        } else {
            bp_core_add_message(__('There was a problem sending your reply. Please try again.', 'buddypress'), 'error');
        }
        bp_core_redirect(bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id . '/');
    }
    // Mark message read
    messages_mark_thread_read($thread_id);
    /**
     * Fires after processing a view request for a single message thread.
     *
     * @since BuddyPress (1.7.0)
     */
    do_action('messages_action_conversation');
}
 public function test_should_return_false_if_site_admin_only_and_current_user_cannot_bp_moderate()
 {
     // Should already be set to a 0 user.
     $this->assertFalse(bp_current_user_can('bp_moderate'));
     $args = array('name' => 'Foo', 'slug' => 'foo', 'site_admin_only' => true);
     $this->assertFalse(bp_core_new_nav_item($args));
 }
/**
 * Register our default taxonomies.
 *
 * @since 2.2.0
 */
function bp_register_default_taxonomies()
{
    // Member Type.
    register_taxonomy(bp_get_member_type_tax_name(), 'user', array('public' => false));
    // Email type.
    register_taxonomy(bp_get_email_tax_type(), bp_get_email_post_type(), apply_filters('bp_register_email_tax_type', array('description' => _x('BuddyPress email types', 'email type taxonomy description', 'buddypress'), 'labels' => bp_get_email_tax_type_labels(), 'meta_box_cb' => 'bp_email_tax_type_metabox', 'public' => false, 'query_var' => false, 'rewrite' => false, 'show_in_menu' => false, 'show_tagcloud' => false, 'show_ui' => bp_is_root_blog() && bp_current_user_can('bp_moderate'))));
}
function messages_action_view_message()
{
    global $thread_id, $bp;
    if (!bp_is_messages_component() || !bp_is_current_action('view')) {
        return false;
    }
    $thread_id = (int) bp_action_variable(0);
    if (!$thread_id || !messages_is_valid_thread($thread_id) || !messages_check_thread_access($thread_id) && !bp_current_user_can('bp_moderate')) {
        bp_core_redirect(bp_displayed_user_domain() . bp_get_messages_slug());
    }
    // Check if a new reply has been submitted
    if (isset($_POST['send'])) {
        // Check the nonce
        check_admin_referer('messages_send_message', 'send_message_nonce');
        // Send the reply
        if (messages_new_message(array('thread_id' => $thread_id, 'subject' => $_POST['subject'], 'content' => $_POST['content']))) {
            bp_core_add_message(__('Your reply was sent successfully', 'buddypress'));
        } else {
            bp_core_add_message(__('There was a problem sending your reply, please try again', 'buddypress'), 'error');
        }
        bp_core_redirect(bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id . '/');
    }
    // Mark message read
    messages_mark_thread_read($thread_id);
    // Decrease the unread count in the nav before it's rendered
    $name = sprintf(__('Messages <span>%s</span>', 'buddypress'), bp_get_total_unread_messages_count());
    $bp->bp_nav[$bp->messages->slug]['name'] = $name;
    do_action('messages_action_view_message');
    bp_core_new_subnav_item(array('name' => sprintf(__('From: %s', 'buddypress'), BP_Messages_Thread::get_last_sender($thread_id)), 'slug' => 'view', 'parent_url' => trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug()), 'parent_slug' => bp_get_messages_slug(), 'screen_function' => true, 'position' => 40, 'user_has_access' => bp_is_my_profile(), 'link' => bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . (int) $thread_id));
    bp_core_load_template(apply_filters('messages_template_view_message', 'members/single/home'));
}
function messages_action_conversation()
{
    if (!bp_is_messages_component() || !bp_is_current_action('view')) {
        return false;
    }
    $thread_id = (int) bp_action_variable(0);
    if (!$thread_id || !messages_is_valid_thread($thread_id) || !messages_check_thread_access($thread_id) && !bp_current_user_can('bp_moderate')) {
        bp_core_redirect(trailingslashit(bp_displayed_user_domain() . bp_get_messages_slug()));
    }
    // Check if a new reply has been submitted
    if (isset($_POST['send'])) {
        // Check the nonce
        check_admin_referer('messages_send_message', 'send_message_nonce');
        // Send the reply
        if (messages_new_message(array('thread_id' => $thread_id, 'subject' => !empty($_POST['subject']) ? $_POST['subject'] : false, 'content' => $_POST['content']))) {
            bp_core_add_message(__('Your reply was sent successfully', 'buddypress'));
        } else {
            bp_core_add_message(__('There was a problem sending your reply, please try again', 'buddypress'), 'error');
        }
        bp_core_redirect(bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . $thread_id . '/');
    }
    // Mark message read
    messages_mark_thread_read($thread_id);
    do_action('messages_action_conversation');
}
/**
 * Creates the administration interface menus and checks to see if the DB
 * tables are set up.
 *
 * @package BuddyPress XProfile
 * @uses bp_current_user_can() returns true if the current user is a site admin, false if not
 * @uses add_users_page() Adds a submenu tab to a top level tab in the admin area
 * @return
 */
function xprofile_add_admin_menu()
{
    if (!bp_current_user_can('bp_moderate')) {
        return false;
    }
    add_users_page(__('Profile Fields', 'buddypress'), __('Profile Fields', 'buddypress'), 'manage_options', 'bp-profile-setup', 'xprofile_admin');
}
/**
 * Maps XProfile caps to built in WordPress caps
 *
 * @since 1.6
 *
 * @param array $caps Capabilities for meta capability
 * @param string $cap Capability name
 * @param int $user_id User id
 * @param mixed $args Arguments
 * @uses get_post() To get the post
 * @uses get_post_type_object() To get the post type object
 * @uses apply_filters() Calls 'bp_map_meta_caps' with caps, cap, user id and
 *                        args
 * @return array Actual capabilities for meta capability
 */
function bp_xprofile_map_meta_caps($caps, $cap, $user_id, $args)
{
    switch ($cap) {
        case 'bp_xprofile_change_field_visibility':
            $caps = array('exist');
            // Must allow for logged-out users during registration
            // You may pass args manually: $field_id, $profile_user_id
            $field_id = isset($args[0]) ? (int) $args[0] : bp_get_the_profile_field_id();
            $profile_user_id = isset($args[1]) ? (int) $args[1] : bp_displayed_user_id();
            // Visibility on the fullname field is not editable
            if (1 == $field_id) {
                $caps[] = 'do_not_allow';
                break;
            }
            // Has the admin disabled visibility modification for this field?
            if ('disabled' == bp_xprofile_get_meta($field_id, 'field', 'allow_custom_visibility')) {
                $caps[] = 'do_not_allow';
                break;
            }
            // Friends don't let friends edit each other's visibility
            if ($profile_user_id != bp_displayed_user_id() && !bp_current_user_can('bp_moderate')) {
                $caps[] = 'do_not_allow';
                break;
            }
            break;
    }
    return apply_filters('bp_xprofile_map_meta_caps', $caps, $cap, $user_id, $args);
}
/**
 * Process user deletion requests.
 *
 * Note: No longer called here. See the Settings component.
 */
function bp_core_action_delete_user()
{
    $userID = bp_displayed_user_id();
    echo "Buddypress:";
    echo $userID;
    $now = current_time('mysql');
    $args = array('date_query' => array('after' => '5 minute ago', 'before' => $now, 'inclusive' => true), 'post_id' => $postID, 'user_id' => $userID, 'count' => true);
    $userActivityCount = get_comments($args);
    if (!bp_current_user_can('bp_moderate') || bp_is_my_profile() || !bp_displayed_user_id() || $userActivityCount != 0) {
        return false;
    }
    if (bp_is_current_component('admin') && bp_is_current_action('delete-user') && $userActivityCount == 0) {
        // Check the nonce.
        check_admin_referer('delete-user');
        $errors = false;
        $style = "<style> #account-delete-form .submit{ display:none !important;} </style>";
        if ($userActivityCount != 0) {
            $errors = true;
            return $style;
        }
        do_action('bp_core_before_action_delete_user', $errors);
        if (bp_core_delete_account(bp_displayed_user_id()) || $userActivityCount == 0) {
            bp_core_add_message(sprintf(__('%s has been deleted from the system.', 'buddypress'), bp_get_displayed_user_fullname()));
        } else {
            bp_core_add_message(sprintf(__('There was an error deleting %s from the system. Please try again.', 'buddypress'), bp_get_displayed_user_fullname()), 'error');
            $errors = true;
        }
        do_action('bp_core_action_delete_user', $errors);
        if ($errors) {
            bp_core_redirect(bp_displayed_user_domain());
        } else {
            bp_core_redirect(bp_loggedin_user_domain());
        }
    }
}
/**
 * Load the Forums directory.
 */
function bp_forums_directory_forums_setup()
{
    // Get BuddyPress once
    $bp = buddypress();
    if (bp_is_forums_component() && (!bp_current_action() || 'tag' == bp_current_action() && bp_action_variables()) && !bp_current_item()) {
        if (!bp_forums_has_directory()) {
            return false;
        }
        if (!bp_forums_is_installed_correctly()) {
            bp_core_add_message(__('The forums component has not been set up yet.', 'buddypress'), 'error');
            bp_core_redirect(bp_get_root_domain());
        }
        bp_update_is_directory(true, 'forums');
        do_action('bbpress_init');
        // Check to see if the user has posted a new topic from the forums page.
        if (isset($_POST['submit_topic']) && bp_is_active('forums')) {
            check_admin_referer('bp_forums_new_topic');
            $bp->groups->current_group = groups_get_group(array('group_id' => $_POST['topic_group_id']));
            if (!empty($bp->groups->current_group->id)) {
                // Auto join this user if they are not yet a member of this group
                if (!bp_current_user_can('bp_moderate') && 'public' == $bp->groups->current_group->status && !groups_is_user_member(bp_loggedin_user_id(), $bp->groups->current_group->id)) {
                    groups_join_group($bp->groups->current_group->id);
                }
                $error_message = '';
                $forum_id = groups_get_groupmeta($bp->groups->current_group->id, 'forum_id');
                if (!empty($forum_id)) {
                    if (empty($_POST['topic_title'])) {
                        $error_message = __('Please provide a title for your forum topic.', 'buddypress');
                    } else {
                        if (empty($_POST['topic_text'])) {
                            $error_message = __('Forum posts cannot be empty. Please enter some text.', 'buddypress');
                        }
                    }
                    if ($error_message) {
                        bp_core_add_message($error_message, 'error');
                        $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum';
                    } else {
                        if (!($topic = groups_new_group_forum_topic($_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id))) {
                            bp_core_add_message(__('There was an error when creating the topic', 'buddypress'), 'error');
                            $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum';
                        } else {
                            bp_core_add_message(__('The topic was created successfully', 'buddypress'));
                            $redirect = bp_get_group_permalink($bp->groups->current_group) . 'forum/topic/' . $topic->topic_slug . '/';
                        }
                    }
                    bp_core_redirect($redirect);
                } else {
                    bp_core_add_message(__('Please pick the group forum where you would like to post this topic.', 'buddypress'), 'error');
                    bp_core_redirect(add_query_arg('new', '', bp_get_forums_directory_permalink()));
                }
            } else {
                bp_core_add_message(__('Please pick the group forum where you would like to post this topic.', 'buddypress'), 'error');
                bp_core_redirect(add_query_arg('new', '', bp_get_forums_directory_permalink()));
            }
        }
        do_action('bp_forums_directory_forums_setup');
        bp_core_load_template(apply_filters('bp_forums_template_directory_forums_setup', 'forums/index'));
    }
}
/**
 * Creates the administration interface menus and checks to see if the DB
 * tables are set up.
 *
 * @uses bp_current_user_can() returns true if the current user is a site admin, false if not.
 * @uses add_users_page() Adds a submenu tab to a top level tab in the admin area.
 *
 * @return bool
 */
function xprofile_add_admin_menu()
{
    // Bail if current user cannot moderate community.
    if (!bp_current_user_can('bp_moderate')) {
        return false;
    }
    add_users_page(_x('Profile Fields', 'xProfile admin page title', 'buddypress'), _x('Profile Fields', 'Admin Users menu', 'buddypress'), 'manage_options', 'bp-profile-setup', 'xprofile_admin');
}
/**
 * Creates the administration interface menus and checks to see if the DB
 * tables are set up.
 *
 * @package BuddyPress XProfile
 * @global object $bp Global BuddyPress settings object
 * @global $wpdb WordPress DB access object.
 * @uses bp_current_user_can() returns true if the current user is a site admin, false if not
 * @uses bp_xprofile_install() runs the installation of DB tables for the xprofile component
 * @uses wp_enqueue_script() Adds a JS file to the JS queue ready for output
 * @uses add_submenu_page() Adds a submenu tab to a top level tab in the admin area
 * @uses xprofile_install() Runs the DB table installation function
 * @return
 */
function xprofile_add_admin_menu()
{
    global $wpdb, $bp;
    if (!bp_current_user_can('bp_moderate')) {
        return false;
    }
    $hook = add_submenu_page('bp-general-settings', __('Profile Fields', 'buddypress'), __('Profile Fields', 'buddypress'), 'manage_options', 'bp-profile-setup', 'xprofile_admin');
    add_action("admin_print_styles-{$hook}", 'bp_core_add_admin_menu_styles');
}
/**
 * Registers the Activity component admin screen
 *
 * @since 1.6
 */
function bp_activity_add_admin_menu()
{
    if (!bp_current_user_can('bp_moderate')) {
        return;
    }
    // Add our screen
    $hook = add_menu_page(__('Activity', 'buddypress'), __('Activity', 'buddypress'), 'manage_options', 'bp-activity', 'bp_activity_admin');
    // Hook into early actions to load custom CSS and our init handler.
    add_action("load-{$hook}", 'bp_activity_admin_load');
}
Example #13
0
function bp_forums_add_admin_menu()
{
    global $bp;
    if (!bp_current_user_can('bp_moderate')) {
        return false;
    }
    // Add the administration tab under the "Site Admin" tab for site administrators
    $hook = add_submenu_page('bp-general-settings', __('Forums', 'buddypress'), __('Forums', 'buddypress'), 'manage_options', 'bb-forums-setup', "bp_forums_bbpress_admin");
    add_action("admin_print_styles-{$hook}", 'bp_core_add_admin_menu_styles');
}
/**
 * bp_core_allow_default_theme()
 *
 * On multiblog installations you must first allow themes to be activated and show
 * up on the theme selection screen. This function will let the BuddyPress bundled
 * themes show up on the root blog selection screen and bypass this step. It also
 * means that the themes won't show for selection on other blogs.
 *
 * @package BuddyPress Core
 */
function bp_core_allow_default_theme($themes)
{
    global $wpdb;
    if (!bp_current_user_can('bp_moderate')) {
        return $themes;
    }
    if ($wpdb->blogid == bp_get_root_blog_id()) {
        $themes['bp-default'] = 1;
    }
    return $themes;
}
/**
 * Enforce limitations on viewing private message contents
 *
 * @since BuddyPress (2.3.2)
 *
 * @see bp_has_message_threads() for description of parameters
 *
 * @param array|string $args See {@link bp_has_message_threads()}.
 */
function bp_messages_enforce_current_user($args = array())
{
    // Non-community moderators can only ever see their own messages
    if (is_user_logged_in() && !bp_current_user_can('bp_moderate')) {
        $_user_id = (int) bp_loggedin_user_id();
        if ($_user_id !== (int) $args['user_id']) {
            $args['user_id'] = $_user_id;
        }
    }
    // Return possibly modified $args array
    return $args;
}
Example #16
0
/**
 * On multiblog installations you must first allow themes to be activated and
 * show up on the theme selection screen. This function will let the BuddyPress
 * bundled themes show up on the root blog selection screen and bypass this
 * step. It also means that the themes won't show for selection on other blogs.
 *
 * @deprecated BuddyPress (1.7)
 * @package BuddyPress Core
 */
function bp_core_allow_default_theme($themes)
{
    _deprecated_function(__FUNCTION__, '1.7');
    if (!bp_current_user_can('bp_moderate')) {
        return $themes;
    }
    if (bp_get_root_blog_id() != get_current_blog_id()) {
        return $themes;
    }
    if (isset($themes['bp-default'])) {
        return $themes;
    }
    $themes['bp-default'] = true;
    return $themes;
}
Example #17
0
 /**
  * @ticket BP6501
  */
 public function test_bp_current_user_can_should_respect_blog_id_passed_in_args_array()
 {
     if (!is_multisite()) {
         $this->markTestSkipped(__METHOD__ . ' requires multisite.');
     }
     $b = $this->factory->blog->create();
     $u = $this->factory->user->create();
     $this->set_current_user($u);
     add_filter('user_has_cap', array($this, 'grant_cap_foo'), 10, 2);
     $can = bp_current_user_can('foo', array('blog_id' => bp_get_root_blog_id()));
     $cant = bp_current_user_can('foo', array('blog_id' => $b));
     remove_filter('user_has_cap', array($this, 'grant_cap_foo'), 10, 2);
     $this->assertTrue($can);
     $this->assertFalse($cant);
 }
/**
 * Add the Activity top-level menu link when viewing single activity item.
 *
 * @since 2.6.0
 *
 * @return null Null if user does not have access to editing functionality.
 */
function bp_activity_admin_menu()
{
    global $wp_admin_bar;
    // Only show if viewing a single activity item.
    if (!bp_is_single_activity()) {
        return;
    }
    // Only show this menu to super admins
    if (!bp_current_user_can('bp_moderate')) {
        return;
    }
    $activity_edit_link = add_query_arg(array('page' => 'bp-activity', 'aid' => bp_current_action(), 'action' => 'edit'), bp_get_admin_url('admin.php'));
    // Add the top-level Edit Activity button.
    $wp_admin_bar->add_menu(array('id' => 'activity-admin', 'title' => __('Edit Activity', 'buddypress'), 'href' => esc_url($activity_edit_link)));
}
/**
 * This function runs when an action is set for a screen:
 * example.com/members/andy/profile/change-avatar/ [delete-avatar]
 *
 * The function will delete the active avatar for a user.
 *
 * @package BuddyPress Xprofile
 * @uses bp_core_delete_avatar() Deletes the active avatar for the logged in user.
 * @uses add_action() Runs a specific function for an action when it fires.
 */
function xprofile_action_delete_avatar()
{
    if (!bp_is_user_change_avatar() || !bp_is_action_variable('delete-avatar', 0)) {
        return false;
    }
    // Check the nonce
    check_admin_referer('bp_delete_avatar_link');
    if (!bp_is_my_profile() && !bp_current_user_can('bp_moderate')) {
        return false;
    }
    if (bp_core_delete_existing_avatar(array('item_id' => bp_displayed_user_id()))) {
        bp_core_add_message(__('Your avatar was deleted successfully!', 'buddypress'));
    } else {
        bp_core_add_message(__('There was a problem deleting that avatar, please try again.', 'buddypress'), 'error');
    }
    bp_core_redirect(wp_get_referer());
}
/**
 * Maps XProfile caps to built in WordPress caps.
 *
 * @since 1.6.0
 *
 * @param array  $caps    Capabilities for meta capability.
 * @param string $cap     Capability name.
 * @param int    $user_id User id.
 * @param mixed  $args    Arguments.
 *
 * @return array Actual capabilities for meta capability.
 */
function bp_xprofile_map_meta_caps($caps, $cap, $user_id, $args)
{
    switch ($cap) {
        case 'bp_xprofile_change_field_visibility':
            $caps = array('exist');
            // You may pass args manually: $field_id, $profile_user_id.
            $field_id = 0;
            $profile_user_id = isset($args[1]) ? (int) $args[1] : bp_displayed_user_id();
            if (!empty($args[0])) {
                $field_id = (int) $args[0];
            } elseif (isset($GLOBALS['profile_template']) && $GLOBALS['profile_template']->in_the_loop) {
                $field_id = bp_get_the_profile_field_id();
            }
            // Visibility on the fullname field is not editable.
            if (1 == $field_id) {
                $caps[] = 'do_not_allow';
                break;
            }
            // Has the admin disabled visibility modification for this field?
            if ('disabled' == bp_xprofile_get_meta($field_id, 'field', 'allow_custom_visibility')) {
                $caps[] = 'do_not_allow';
                break;
            }
            // Friends don't let friends edit each other's visibility.
            if ($profile_user_id != bp_displayed_user_id() && !bp_current_user_can('bp_moderate')) {
                $caps[] = 'do_not_allow';
                break;
            }
            break;
    }
    /**
     * Filters the XProfile caps to built in WordPress caps.
     *
     * @since 1.6.0
     *
     * @param array  $caps    Capabilities for meta capability.
     * @param string $cap     Capability name.
     * @param int    $user_id User ID being mapped.
     * @param mixed  $args    Capability arguments.
     */
    return apply_filters('bp_xprofile_map_meta_caps', $caps, $cap, $user_id, $args);
}
Example #21
0
 /**
  * @group bp_xprofile_change_field_visibility
  */
 public function test_bp_current_user_can_should_pass_null_in_args_parameter_if_empty()
 {
     $u = $this->factory->user->create();
     $this->set_current_user($u);
     /**
      * Fake bp_get_the_profile_field_id() to pretend we're in the field loop and
      * to avoid notices when checking 'bp_xprofile_change_field_visibility' cap
      */
     $GLOBALS['field'] = new stdClass();
     $GLOBALS['field']->id = 1;
     // Capture the cap's $args
     add_filter('bp_xprofile_map_meta_caps', array($this, 'check_cap_args'), 10, 4);
     // Use a cap check that depends on a null value for a cap's args
     bp_current_user_can('bp_xprofile_change_field_visibility');
     // Assert!
     $this->assertEquals(null, $this->test_args[0]);
     // Reset
     remove_filter('bp_xprofile_map_meta_caps', array($this, 'check_cap_args'), 10, 4);
     unset($GLOBALS['field'], $this->test_args);
 }
/**
 * Add the Group Admin top-level menu when viewing group pages.
 *
 * @since 1.5.0
 *
 * @todo Add dynamic menu items for group extensions.
 *
 * @return false|null False if not on a group page, or if user does not have
 *                    access to group admin options.
 */
function bp_groups_group_admin_menu()
{
    global $wp_admin_bar;
    $bp = buddypress();
    // Only show if viewing a group.
    if (!bp_is_group() || bp_is_group_create()) {
        return false;
    }
    // Only show this menu to group admins and super admins.
    if (!bp_current_user_can('bp_moderate') && !bp_group_is_admin()) {
        return false;
    }
    // Unique ID for the 'Edit Group' menu.
    $bp->group_admin_menu_id = 'group-admin';
    // Add the top-level Group Admin button.
    $wp_admin_bar->add_menu(array('id' => $bp->group_admin_menu_id, 'title' => __('Edit Group', 'buddypress'), 'href' => bp_get_group_permalink($bp->groups->current_group)));
    // Index of the Manage tabs parent slug.
    $nav_index = $bp->groups->current_group->slug . '_manage';
    // Check if current group has Manage tabs.
    if (empty($bp->bp_options_nav[$nav_index])) {
        return;
    }
    // Build the Group Admin menus.
    foreach ($bp->bp_options_nav[$nav_index] as $menu) {
        /**
         * Should we add the current manage link in the Group's "Edit" Admin Bar menu ?
         *
         * All core items will be added, plugins can use a new parameter in the BP Group Extension API
         * to also add the link to the "edit screen" of their group component. To do so, set the
         * the 'show_in_admin_bar' argument of your edit screen to true
         */
        if ($menu['show_in_admin_bar']) {
            $title = sprintf(_x('Edit Group %s', 'Group WP Admin Bar manage links', 'buddypress'), $menu['name']);
            // Title is specific for delete.
            if ('delete-group' == $menu['slug']) {
                $title = sprintf(_x('%s Group', 'Group WP Admin Bar delete link', 'buddypress'), $menu['name']);
            }
            $wp_admin_bar->add_menu(array('parent' => $bp->group_admin_menu_id, 'id' => $menu['slug'], 'title' => $title, 'href' => bp_get_groups_action_link('admin/' . $menu['slug'])));
        }
    }
}
function messages_screen_notices()
{
    global $notice_id;
    if (!bp_current_user_can('bp_moderate')) {
        return false;
    }
    $notice_id = (int) bp_action_variable(1);
    if (!empty($notice_id) && is_numeric($notice_id)) {
        $notice = new BP_Messages_Notice($notice_id);
        if (bp_is_action_variable('deactivate', 0)) {
            if (!$notice->deactivate()) {
                bp_core_add_message(__('There was a problem deactivating that notice.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('Notice deactivated.', 'buddypress'));
            }
        } else {
            if (bp_is_action_variable('activate', 0)) {
                if (!$notice->activate()) {
                    bp_core_add_message(__('There was a problem activating that notice.', 'buddypress'), 'error');
                } else {
                    bp_core_add_message(__('Notice activated.', 'buddypress'));
                }
            } else {
                if (bp_is_action_variable('delete')) {
                    if (!$notice->delete()) {
                        bp_core_add_message(__('There was a problem deleting that notice.', 'buddypress'), 'buddypress');
                    } else {
                        bp_core_add_message(__('Notice deleted.', 'buddypress'));
                    }
                }
            }
        }
        bp_core_redirect(bp_loggedin_user_domain() . bp_get_messages_slug() . '/notices');
    }
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    do_action('messages_screen_notices');
    bp_core_load_template(apply_filters('messages_template_notices', 'members/single/home'));
}
/**
 * Adds the Group Admin top-level menu to group pages
 *
 * @package BuddyPress
 * @since 1.5
 *
 * @todo Add dynamic menu items for group extensions
 */
function bp_groups_group_admin_menu()
{
    global $wp_admin_bar, $bp;
    // Only show if viewing a group
    if (!bp_is_group()) {
        return false;
    }
    // Only show this menu to group admins and super admins
    if (!bp_current_user_can('bp_moderate') && !bp_group_is_admin()) {
        return false;
    }
    // Group avatar
    $avatar = bp_core_fetch_avatar(array('object' => 'group', 'type' => 'thumb', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'width' => 16, 'height' => 16));
    // Unique ID for the 'My Account' menu
    $bp->group_admin_menu_id = !empty($avatar) ? 'group-admin-with-avatar' : 'group-admin';
    // Add the top-level Group Admin button
    $wp_admin_bar->add_menu(array('id' => $bp->group_admin_menu_id, 'title' => $avatar . bp_get_current_group_name(), 'href' => bp_get_group_permalink($bp->groups->current_group)));
    // Group Admin > Edit details
    $wp_admin_bar->add_menu(array('parent' => $bp->group_admin_menu_id, 'id' => 'edit-details', 'title' => __('Edit Details', 'buddypress'), 'href' => bp_get_groups_action_link('admin/edit-details')));
    // Group Admin > Group settings
    $wp_admin_bar->add_menu(array('parent' => $bp->group_admin_menu_id, 'id' => 'group-settings', 'title' => __('Edit Settings', 'buddypress'), 'href' => bp_get_groups_action_link('admin/group-settings')));
    // Group Admin > Group avatar
    if (!(int) bp_get_option('bp-disable-avatar-uploads')) {
        $wp_admin_bar->add_menu(array('parent' => $bp->group_admin_menu_id, 'id' => 'group-avatar', 'title' => __('Edit Avatar', 'buddypress'), 'href' => bp_get_groups_action_link('admin/group-avatar')));
    }
    // Group Admin > Manage invitations
    if (bp_is_active('friends')) {
        $wp_admin_bar->add_menu(array('parent' => $bp->group_admin_menu_id, 'id' => 'manage-invitations', 'title' => __('Manage Invitations', 'buddypress'), 'href' => bp_get_groups_action_link('send-invites')));
    }
    // Group Admin > Manage members
    $wp_admin_bar->add_menu(array('parent' => $bp->group_admin_menu_id, 'id' => 'manage-members', 'title' => __('Manage Members', 'buddypress'), 'href' => bp_get_groups_action_link('admin/manage-members')));
    // Group Admin > Membership Requests
    if (bp_get_group_status($bp->groups->current_group) == 'private') {
        $wp_admin_bar->add_menu(array('parent' => $bp->group_admin_menu_id, 'id' => 'membership-requests', 'title' => __('Membership Requests', 'buddypress'), 'href' => bp_get_groups_action_link('admin/membership-requests')));
    }
    // Delete Group
    $wp_admin_bar->add_menu(array('parent' => $bp->group_admin_menu_id, 'id' => 'delete-group', 'title' => __('Delete Group', 'buddypress'), 'href' => bp_get_groups_action_link('admin/delete-group')));
}
/**
 * Process user deletion requests.
 *
 * Note: No longer called here. See the Settings component.
 */
function bp_core_action_delete_user()
{
    if (!bp_current_user_can('bp_moderate') || bp_is_my_profile() || !bp_displayed_user_id()) {
        return false;
    }
    if (bp_is_current_component('admin') && bp_is_current_action('delete-user')) {
        // Check the nonce
        check_admin_referer('delete-user');
        $errors = false;
        do_action('bp_core_before_action_delete_user', $errors);
        if (bp_core_delete_account(bp_displayed_user_id())) {
            bp_core_add_message(sprintf(__('%s has been deleted from the system.', 'buddypress'), bp_get_displayed_user_fullname()));
        } else {
            bp_core_add_message(sprintf(__('There was an error deleting %s from the system. Please try again.', 'buddypress'), bp_get_displayed_user_fullname()), 'error');
            $errors = true;
        }
        do_action('bp_core_action_delete_user', $errors);
        if ($errors) {
            bp_core_redirect(bp_displayed_user_domain());
        } else {
            bp_core_redirect(bp_loggedin_user_domain());
        }
    }
}
Example #26
0
/**
 * Add the Group Admin top-level menu when viewing group pages.
 *
 * @since BuddyPress (1.5.0)
 *
 * @todo Add dynamic menu items for group extensions.
 *
 * @return bool|null False if not on a group page, or if user does not have
 *        access to group admin options.
 */
function bp_groups_group_admin_menu()
{
    global $wp_admin_bar, $bp;
    // Only show if viewing a group
    if (!bp_is_group()) {
        return false;
    }
    // Only show this menu to group admins and super admins
    if (!bp_current_user_can('bp_moderate') && !bp_group_is_admin()) {
        return false;
    }
    // Unique ID for the 'Edit Group' menu
    $bp->group_admin_menu_id = 'group-admin';
    // Add the top-level Group Admin button
    $wp_admin_bar->add_menu(array('id' => $bp->group_admin_menu_id, 'title' => __('Edit Group', 'buddypress'), 'href' => bp_get_group_permalink($bp->groups->current_group)));
    // Group Admin > Edit details
    $wp_admin_bar->add_menu(array('parent' => $bp->group_admin_menu_id, 'id' => 'edit-details', 'title' => __('Edit Details', 'buddypress'), 'href' => bp_get_groups_action_link('admin/edit-details')));
    // Group Admin > Group settings
    $wp_admin_bar->add_menu(array('parent' => $bp->group_admin_menu_id, 'id' => 'group-settings', 'title' => __('Edit Settings', 'buddypress'), 'href' => bp_get_groups_action_link('admin/group-settings')));
    // Group Admin > Group avatar
    if (!(int) bp_get_option('bp-disable-avatar-uploads') && $bp->avatar->show_avatars) {
        $wp_admin_bar->add_menu(array('parent' => $bp->group_admin_menu_id, 'id' => 'group-avatar', 'title' => __('Edit Profile Photo', 'buddypress'), 'href' => bp_get_groups_action_link('admin/group-avatar')));
    }
    // Group Admin > Manage invitations
    if (bp_is_active('friends')) {
        $wp_admin_bar->add_menu(array('parent' => $bp->group_admin_menu_id, 'id' => 'manage-invitations', 'title' => __('Manage Invitations', 'buddypress'), 'href' => bp_get_groups_action_link('send-invites')));
    }
    // Group Admin > Manage members
    $wp_admin_bar->add_menu(array('parent' => $bp->group_admin_menu_id, 'id' => 'manage-members', 'title' => __('Manage Members', 'buddypress'), 'href' => bp_get_groups_action_link('admin/manage-members')));
    // Group Admin > Membership Requests
    if (bp_get_group_status($bp->groups->current_group) == 'private') {
        $wp_admin_bar->add_menu(array('parent' => $bp->group_admin_menu_id, 'id' => 'membership-requests', 'title' => __('Membership Requests', 'buddypress'), 'href' => bp_get_groups_action_link('admin/membership-requests')));
    }
    // Delete Group
    $wp_admin_bar->add_menu(array('parent' => $bp->group_admin_menu_id, 'id' => 'delete-group', 'title' => __('Delete Group', 'buddypress'), 'href' => bp_get_groups_action_link('admin/delete-group')));
}
/**
 * Display the Group delete confirmation screen.
 *
 * We include a separate confirmation because group deletion is truly
 * irreversible.
 *
 * @since 1.7.0
 */
function bp_groups_admin_delete()
{
    if (!bp_current_user_can('bp_moderate')) {
        die('-1');
    }
    $group_ids = isset($_REQUEST['gid']) ? $_REQUEST['gid'] : 0;
    if (!is_array($group_ids)) {
        $group_ids = explode(',', $group_ids);
    }
    $group_ids = wp_parse_id_list($group_ids);
    $groups = groups_get_groups(array('include' => $group_ids, 'show_hidden' => true, 'per_page' => null));
    // Create a new list of group ids, based on those that actually exist
    $gids = array();
    foreach ($groups['groups'] as $group) {
        $gids[] = $group->id;
    }
    $base_url = remove_query_arg(array('action', 'action2', 'paged', 's', '_wpnonce', 'gid'), $_SERVER['REQUEST_URI']);
    ?>

	<div class="wrap">
		<?php 
    screen_icon('buddypress-groups');
    ?>
		<h2><?php 
    _e('Delete Groups', 'buddypress');
    ?>
</h2>
		<p><?php 
    _e('You are about to delete the following groups:', 'buddypress');
    ?>
</p>

		<ul class="bp-group-delete-list">
		<?php 
    foreach ($groups['groups'] as $group) {
        ?>
			<li><?php 
        echo esc_html($group->name);
        ?>
</li>
		<?php 
    }
    ?>
		</ul>

		<p><strong><?php 
    _e('This action cannot be undone.', 'buddypress');
    ?>
</strong></p>

		<a class="button-primary" href="<?php 
    echo esc_url(wp_nonce_url(add_query_arg(array('action' => 'do_delete', 'gid' => implode(',', $gids)), $base_url), 'bp-groups-delete'));
    ?>
"><?php 
    _e('Delete Permanently', 'buddypress');
    ?>
</a>
		<a class="button" href="<?php 
    echo esc_attr($base_url);
    ?>
"><?php 
    _e('Cancel', 'buddypress');
    ?>
</a>
	</div>

	<?php 
}
 function total_group_count($user_id = 0)
 {
     global $bp, $wpdb;
     if (empty($user_id)) {
         $user_id = bp_displayed_user_id();
     }
     if ($user_id != bp_loggedin_user_id() && !bp_current_user_can('bp_moderate')) {
         return $wpdb->get_var($wpdb->prepare("SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id));
     } else {
         return $wpdb->get_var($wpdb->prepare("SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id));
     }
 }
/**
 * Handles the deleting of a user
 */
function bp_settings_action_delete_account()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Bail if no submit action
    if (!isset($_POST['delete-account-understand'])) {
        return;
    }
    // Bail if not in settings
    if (!bp_is_settings_component() || !bp_is_current_action('delete-account')) {
        return false;
    }
    // 404 if there are any additional action variables attached
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    // Bail if account deletion is disabled
    if (bp_disable_account_deletion() && !bp_current_user_can('delete_users')) {
        return false;
    }
    // Nonce check
    check_admin_referer('delete-account');
    // Get username now because it might be gone soon!
    $username = bp_get_displayed_user_fullname();
    // delete the users account
    if (bp_core_delete_account(bp_displayed_user_id())) {
        // Add feedback ater deleting a user
        bp_core_add_message(sprintf(__('%s was successfully deleted.', 'buddypress'), $username), 'success');
        // Redirect to the root domain
        bp_core_redirect(bp_get_root_domain());
    }
}
 /**
  * Set up the Toolbar.
  *
  * @param array $wp_admin_nav Array of Admin Bar items.
  */
 public function setup_admin_bar($wp_admin_nav = array())
 {
     // Menus for logged in user
     if (is_user_logged_in()) {
         // Setup the logged in user variables
         $settings_link = trailingslashit(bp_loggedin_user_domain() . bp_get_settings_slug());
         // Add main Settings menu
         $wp_admin_nav[] = array('parent' => buddypress()->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => __('Settings', 'buddypress'), 'href' => $settings_link);
         // General Account
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-general', 'title' => __('General', 'buddypress'), 'href' => $settings_link);
         // Notifications - only add the tab when there is something to display there.
         if (has_action('bp_notification_settings')) {
             $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-notifications', 'title' => __('Email', 'buddypress'), 'href' => trailingslashit($settings_link . 'notifications'));
         }
         // Delete Account
         if (!bp_current_user_can('bp_moderate') && !bp_core_get_root_option('bp-disable-account-deletion')) {
             $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-delete-account', 'title' => __('Delete Account', 'buddypress'), 'href' => trailingslashit($settings_link . 'delete-account'));
         }
     }
     parent::setup_admin_bar($wp_admin_nav);
 }