/**
         * Display a dropdown to bulk change the member type of selected user(s).
         *
         * @since 2.7.0
         *
         * @param string $which Where this dropdown is displayed - top or bottom.
         */
        public function users_table_output_type_change_select($which = 'top')
        {
            // Bail if current user cannot promote users.
            if (!bp_current_user_can('promote_users')) {
                return;
            }
            // `$which` is only passed in WordPress 4.6+. Avoid duplicating controls in earlier versions.
            static $displayed = false;
            if (version_compare(bp_get_major_wp_version(), '4.6', '<') && $displayed) {
                return;
            }
            $displayed = true;
            $id_name = 'bottom' === $which ? 'bp_change_type2' : 'bp_change_type';
            $types = bp_get_member_types(array(), 'objects');
            ?>

		<label class="screen-reader-text" for="<?php 
            echo $id_name;
            ?>
"><?php 
            _e('Change member type to&hellip;', 'buddypress');
            ?>
</label>
		<select name="<?php 
            echo $id_name;
            ?>
" id="<?php 
            echo $id_name;
            ?>
" style="display:inline-block;float:none;">
			<option value=""><?php 
            _e('Change member type to&hellip;', 'buddypress');
            ?>
</option>

			<?php 
            foreach ($types as $type) {
                ?>

				<option value="<?php 
                echo esc_attr($type->name);
                ?>
"><?php 
                echo esc_html($type->labels['singular_name']);
                ?>
</option>

			<?php 
            }
            ?>

			<option value="remove_member_type"><?php 
            _e('No Member Type', 'buddypress');
            ?>
</option>

		</select>
		<?php 
            wp_nonce_field('bp-bulk-users-change-type-' . bp_loggedin_user_id(), 'bp-bulk-users-change-type-nonce');
            submit_button(__('Change', 'buddypress'), 'button', 'bp_change_member_type', false);
        }
/**
 * Check if the current WordPress version is using Plupload 2.1.1
 *
 * Plupload 2.1.1 was introduced in WordPress 3.9. Our bp-plupload.js
 * script requires it. So we need to make sure the current WordPress
 * match with our needs.
 *
 * @since  2.3.0
 *
 * @return bool True if WordPress is 3.9+, false otherwise.
 */
function bp_attachments_is_wp_version_supported()
{
    return (bool) version_compare(bp_get_major_wp_version(), '3.9', '>=');
}
 /**
  * Set up the signups admin page.
  *
  * Loaded before the page is rendered, this function does all initial
  * setup, including: processing form requests, registering contextual
  * help, and setting up screen options.
  *
  * @since 2.0.0
  *
  * @global $bp_members_signup_list_table
  */
 public function signups_admin_load()
 {
     global $bp_members_signup_list_table;
     // Build redirection URL.
     $redirect_to = remove_query_arg(array('action', 'error', 'updated', 'activated', 'notactivated', 'deleted', 'notdeleted', 'resent', 'notresent', 'do_delete', 'do_resend', 'do_activate', '_wpnonce', 'signup_ids'), $_SERVER['REQUEST_URI']);
     $doaction = bp_admin_list_table_current_bulk_action();
     /**
      * Fires at the start of the signups admin load.
      *
      * @since 2.0.0
      *
      * @param string $doaction Current bulk action being processed.
      * @param array  $_REQUEST Current $_REQUEST global.
      */
     do_action('bp_signups_admin_load', $doaction, $_REQUEST);
     /**
      * Filters the allowed actions for use in the user signups admin page.
      *
      * @since 2.0.0
      *
      * @param array $value Array of allowed actions to use.
      */
     $allowed_actions = apply_filters('bp_signups_admin_allowed_actions', array('do_delete', 'do_activate', 'do_resend'));
     // Prepare the display of the Community Profile screen.
     if (!in_array($doaction, $allowed_actions) || -1 == $doaction) {
         if (is_network_admin()) {
             $bp_members_signup_list_table = self::get_list_table_class('BP_Members_MS_List_Table', 'ms-users');
         } else {
             $bp_members_signup_list_table = self::get_list_table_class('BP_Members_List_Table', 'users');
         }
         // The per_page screen option.
         add_screen_option('per_page', array('label' => _x('Pending Accounts', 'Pending Accounts per page (screen options)', 'buddypress')));
         get_current_screen()->add_help_tab(array('id' => 'bp-signups-overview', 'title' => __('Overview', 'buddypress'), 'content' => '<p>' . __('This is the administration screen for pending accounts on your site.', 'buddypress') . '</p>' . '<p>' . __('From the screen options, you can customize the displayed columns and the pagination of this screen.', 'buddypress') . '</p>' . '<p>' . __('You can reorder the list of your pending accounts by clicking on the Username, Email or Registered column headers.', 'buddypress') . '</p>' . '<p>' . __('Using the search form, you can find pending accounts more easily. The Username and Email fields will be included in the search.', 'buddypress') . '</p>'));
         get_current_screen()->add_help_tab(array('id' => 'bp-signups-actions', 'title' => __('Actions', 'buddypress'), 'content' => '<p>' . __('Hovering over a row in the pending accounts list will display action links that allow you to manage pending accounts. You can perform the following actions:', 'buddypress') . '</p>' . '<ul><li>' . __('"Email" takes you to the confirmation screen before being able to send the activation link to the desired pending account. You can only send the activation email once per day.', 'buddypress') . '</li>' . '<li>' . __('"Delete" allows you to delete a pending account from your site. You will be asked to confirm this deletion.', 'buddypress') . '</li></ul>' . '<p>' . __('By clicking on a Username you will be able to activate a pending account from the confirmation screen.', 'buddypress') . '</p>' . '<p>' . __('Bulk actions allow you to perform these 3 actions for the selected rows.', 'buddypress') . '</p>'));
         // Help panel - sidebar links.
         get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p>' . __('<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress') . '</p>');
         // Add accessible hidden headings and text for the Pending Users screen.
         if (bp_get_major_wp_version() >= 4.4) {
             get_current_screen()->set_screen_reader_content(array('heading_views' => __('Filter users list', 'buddypress'), 'heading_pagination' => __('Pending users list navigation', 'buddypress'), 'heading_list' => __('Pending users list', 'buddypress')));
         }
     } else {
         if (!empty($_REQUEST['signup_ids'])) {
             $signups = wp_parse_id_list($_REQUEST['signup_ids']);
         }
         // Handle resent activation links.
         if ('do_resend' == $doaction) {
             // Nonce check.
             check_admin_referer('signups_resend');
             $resent = BP_Signup::resend($signups);
             if (empty($resent)) {
                 $redirect_to = add_query_arg('error', $doaction, $redirect_to);
             } else {
                 $query_arg = array('updated' => 'resent');
                 if (!empty($resent['resent'])) {
                     $query_arg['resent'] = count($resent['resent']);
                 }
                 if (!empty($resent['errors'])) {
                     $query_arg['notsent'] = count($resent['errors']);
                     set_transient('_bp_admin_signups_errors', $resent['errors'], 30);
                 }
                 $redirect_to = add_query_arg($query_arg, $redirect_to);
             }
             bp_core_redirect($redirect_to);
             // Handle activated accounts.
         } elseif ('do_activate' == $doaction) {
             // Nonce check.
             check_admin_referer('signups_activate');
             $activated = BP_Signup::activate($signups);
             if (empty($activated)) {
                 $redirect_to = add_query_arg('error', $doaction, $redirect_to);
             } else {
                 $query_arg = array('updated' => 'activated');
                 if (!empty($activated['activated'])) {
                     $query_arg['activated'] = count($activated['activated']);
                 }
                 if (!empty($activated['errors'])) {
                     $query_arg['notactivated'] = count($activated['errors']);
                     set_transient('_bp_admin_signups_errors', $activated['errors'], 30);
                 }
                 $redirect_to = add_query_arg($query_arg, $redirect_to);
             }
             bp_core_redirect($redirect_to);
             // Handle sign-ups delete.
         } elseif ('do_delete' == $doaction) {
             // Nonce check.
             check_admin_referer('signups_delete');
             $deleted = BP_Signup::delete($signups);
             if (empty($deleted)) {
                 $redirect_to = add_query_arg('error', $doaction, $redirect_to);
             } else {
                 $query_arg = array('updated' => 'deleted');
                 if (!empty($deleted['deleted'])) {
                     $query_arg['deleted'] = count($deleted['deleted']);
                 }
                 if (!empty($deleted['errors'])) {
                     $query_arg['notdeleted'] = count($deleted['errors']);
                     set_transient('_bp_admin_signups_errors', $deleted['errors'], 30);
                 }
                 $redirect_to = add_query_arg($query_arg, $redirect_to);
             }
             bp_core_redirect($redirect_to);
             // Plugins can update other stuff from here.
         } else {
             $this->redirect = $redirect_to;
             /**
              * Fires at end of signups admin load if doaction does not match any actions.
              *
              * @since 2.0.0
              *
              * @param string $doaction Current bulk action being processed.
              * @param array  $_REQUEST Current $_REQUEST global.
              * @param string $redirect Determined redirect url to send user to.
              */
             do_action('bp_members_admin_update_signups', $doaction, $_REQUEST, $this->redirect);
             bp_core_redirect($this->redirect);
         }
     }
 }
/**
 * Set up the Groups admin page.
 *
 * Loaded before the page is rendered, this function does all initial setup,
 * including: processing form requests, registering contextual help, and
 * setting up screen options.
 *
 * @since 1.7.0
 *
 * @global BP_Groups_List_Table $bp_groups_list_table Groups screen list table.
 */
function bp_groups_admin_load()
{
    global $bp_groups_list_table;
    // Build redirection URL.
    $redirect_to = remove_query_arg(array('action', 'action2', 'gid', 'deleted', 'error', 'updated', 'success_new', 'error_new', 'success_modified', 'error_modified'), $_SERVER['REQUEST_URI']);
    $doaction = bp_admin_list_table_current_bulk_action();
    $min = bp_core_get_minified_asset_suffix();
    /**
     * Fires at top of groups admin page.
     *
     * @since 1.7.0
     *
     * @param string $doaction Current $_GET action being performed in admin screen.
     */
    do_action('bp_groups_admin_load', $doaction);
    // Edit screen.
    if ('do_delete' == $doaction && !empty($_GET['gid'])) {
        check_admin_referer('bp-groups-delete');
        $group_ids = wp_parse_id_list($_GET['gid']);
        $count = 0;
        foreach ($group_ids as $group_id) {
            if (groups_delete_group($group_id)) {
                $count++;
            }
        }
        $redirect_to = add_query_arg('deleted', $count, $redirect_to);
        bp_core_redirect($redirect_to);
    } elseif ('edit' == $doaction && !empty($_GET['gid'])) {
        // Columns screen option.
        add_screen_option('layout_columns', array('default' => 2, 'max' => 2));
        get_current_screen()->add_help_tab(array('id' => 'bp-group-edit-overview', 'title' => __('Overview', 'buddypress'), 'content' => '<p>' . __('This page is a convenient way to edit the details associated with one of your groups.', 'buddypress') . '</p>' . '<p>' . __('The Name and Description box is fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to hide or unhide, or to choose a 1- or 2-column layout for this screen.', 'buddypress') . '</p>'));
        // Help panel - sidebar links.
        get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p><a href="https://buddypress.org/support">' . __('Support Forums', 'buddypress') . '</a></p>');
        // Register metaboxes for the edit screen.
        add_meta_box('submitdiv', _x('Save', 'group admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_status', get_current_screen()->id, 'side', 'high');
        add_meta_box('bp_group_settings', _x('Settings', 'group admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_settings', get_current_screen()->id, 'side', 'core');
        add_meta_box('bp_group_add_members', _x('Add New Members', 'group admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_add_new_members', get_current_screen()->id, 'normal', 'core');
        add_meta_box('bp_group_members', _x('Manage Members', 'group admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_members', get_current_screen()->id, 'normal', 'core');
        // Group Type metabox. Only added if group types have been registered.
        $group_types = bp_groups_get_group_types();
        if (!empty($group_types)) {
            add_meta_box('bp_groups_admin_group_type', _x('Group Type', 'groups admin edit screen', 'buddypress'), 'bp_groups_admin_edit_metabox_group_type', get_current_screen()->id, 'side', 'core');
        }
        /**
         * Fires after the registration of all of the default group meta boxes.
         *
         * @since 1.7.0
         */
        do_action('bp_groups_admin_meta_boxes');
        // Enqueue JavaScript files.
        wp_enqueue_script('postbox');
        wp_enqueue_script('dashboard');
        // Index screen.
    } else {
        // Create the Groups screen list table.
        $bp_groups_list_table = new BP_Groups_List_Table();
        // The per_page screen option.
        add_screen_option('per_page', array('label' => _x('Groups', 'Groups per page (screen options)', 'buddypress')));
        // Help panel - overview text.
        get_current_screen()->add_help_tab(array('id' => 'bp-groups-overview', 'title' => __('Overview', 'buddypress'), 'content' => '<p>' . __('You can manage groups much like you can manage comments and other content. This screen is customizable in the same ways as other management screens, and you can act on groups by using the on-hover action links or the Bulk Actions.', 'buddypress') . '</p>'));
        get_current_screen()->add_help_tab(array('id' => 'bp-groups-overview-actions', 'title' => __('Group Actions', 'buddypress'), 'content' => '<p>' . __('Clicking "Visit" will take you to the group&#8217;s public page. Use this link to see what the group looks like on the front end of your site.', 'buddypress') . '</p>' . '<p>' . __('Clicking "Edit" will take you to a Dashboard panel where you can manage various details about the group, such as its name and description, its members, and other settings.', 'buddypress') . '</p>' . '<p>' . __('If you click "Delete" under a specific group, or select a number of groups and then choose Delete from the Bulk Actions menu, you will be led to a page where you&#8217;ll be asked to confirm the permanent deletion of the group(s).', 'buddypress') . '</p>'));
        // Help panel - sidebar links.
        get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p>' . __('<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress') . '</p>');
        // Add accessible hidden heading and text for Groups screen pagination.
        if (bp_get_major_wp_version() >= 4.4) {
            get_current_screen()->set_screen_reader_content(array('heading_pagination' => __('Groups list navigation', 'buddypress')));
        }
    }
    $bp = buddypress();
    // Enqueue CSS and JavaScript.
    wp_enqueue_script('bp_groups_admin_js', $bp->plugin_url . "bp-groups/admin/js/admin{$min}.js", array('jquery', 'wp-ajax-response', 'jquery-ui-autocomplete'), bp_get_version(), true);
    wp_localize_script('bp_groups_admin_js', 'BP_Group_Admin', array('add_member_placeholder' => __('Start typing a username to add a new member.', 'buddypress'), 'warn_on_leave' => __('If you leave this page, you will lose any unsaved changes you have made to the group.', 'buddypress')));
    wp_enqueue_style('bp_groups_admin_css', $bp->plugin_url . "bp-groups/admin/css/admin{$min}.css", array(), bp_get_version());
    wp_style_add_data('bp_groups_admin_css', 'rtl', true);
    if ($min) {
        wp_style_add_data('bp_groups_admin_css', 'suffix', $min);
    }
    if ($doaction && 'save' == $doaction) {
        // Get group ID.
        $group_id = isset($_REQUEST['gid']) ? (int) $_REQUEST['gid'] : '';
        $redirect_to = add_query_arg(array('gid' => (int) $group_id, 'action' => 'edit'), $redirect_to);
        // Check this is a valid form submission.
        check_admin_referer('edit-group_' . $group_id);
        // Get the group from the database.
        $group = groups_get_group($group_id);
        // If the group doesn't exist, just redirect back to the index.
        if (empty($group->slug)) {
            wp_redirect($redirect_to);
            exit;
        }
        // Check the form for the updated properties.
        // Store errors.
        $error = 0;
        $success_new = $error_new = $success_modified = $error_modified = array();
        // Group name and description are handled with
        // groups_edit_base_group_details().
        if (!groups_edit_base_group_details($group_id, $_POST['bp-groups-name'], $_POST['bp-groups-description'], 0)) {
            $error = $group_id;
            // Using negative integers for different error messages... eek!
            if (empty($_POST['bp-groups-name']) && empty($_POST['bp-groups-description'])) {
                $error = -3;
            } elseif (empty($_POST['bp-groups-name'])) {
                $error = -1;
            } elseif (empty($_POST['bp-groups-description'])) {
                $error = -2;
            }
        }
        // Enable discussion forum.
        $enable_forum = isset($_POST['group-show-forum']) ? 1 : 0;
        /**
         * Filters the allowed status values for the group.
         *
         * @since 1.0.2
         *
         * @param array $value Array of allowed group statuses.
         */
        $allowed_status = apply_filters('groups_allowed_status', array('public', 'private', 'hidden'));
        $status = in_array($_POST['group-status'], (array) $allowed_status) ? $_POST['group-status'] : 'public';
        /**
         * Filters the allowed invite status values for the group.
         *
         * @since 1.5.0
         *
         * @param array $value Array of allowed invite statuses.
         */
        $allowed_invite_status = apply_filters('groups_allowed_invite_status', array('members', 'mods', 'admins'));
        $invite_status = in_array($_POST['group-invite-status'], (array) $allowed_invite_status) ? $_POST['group-invite-status'] : 'members';
        if (!groups_edit_group_settings($group_id, $enable_forum, $status, $invite_status)) {
            $error = $group_id;
        }
        // Process new members.
        $user_names = array();
        if (!empty($_POST['bp-groups-new-members'])) {
            $user_names = array_merge($user_names, explode(',', $_POST['bp-groups-new-members']));
        }
        if (!empty($user_names)) {
            foreach (array_values($user_names) as $user_name) {
                $un = trim($user_name);
                // Make sure the user exists before attempting
                // to add to the group.
                $user = get_user_by('slug', $un);
                if (empty($user)) {
                    $error_new[] = $un;
                } else {
                    if (!groups_join_group($group_id, $user->ID)) {
                        $error_new[] = $un;
                    } else {
                        $success_new[] = $un;
                    }
                }
            }
        }
        // Process member role changes.
        if (!empty($_POST['bp-groups-role']) && !empty($_POST['bp-groups-existing-role'])) {
            // Before processing anything, make sure you're not
            // attempting to remove the all user admins.
            $admin_count = 0;
            foreach ((array) $_POST['bp-groups-role'] as $new_role) {
                if ('admin' == $new_role) {
                    $admin_count++;
                    break;
                }
            }
            if (!$admin_count) {
                $redirect_to = add_query_arg('no_admins', 1, $redirect_to);
                $error = $group_id;
            } else {
                // Process only those users who have had their roles changed.
                foreach ((array) $_POST['bp-groups-role'] as $user_id => $new_role) {
                    $user_id = (int) $user_id;
                    $existing_role = isset($_POST['bp-groups-existing-role'][$user_id]) ? $_POST['bp-groups-existing-role'][$user_id] : '';
                    if ($existing_role != $new_role) {
                        $result = false;
                        switch ($new_role) {
                            case 'mod':
                                // Admin to mod is a demotion. Demote to
                                // member, then fall through.
                                if ('admin' == $existing_role) {
                                    groups_demote_member($user_id, $group_id);
                                }
                            case 'admin':
                                // If the user was banned, we must
                                // unban first.
                                if ('banned' == $existing_role) {
                                    groups_unban_member($user_id, $group_id);
                                }
                                // At this point, each existing_role
                                // is a member, so promote.
                                $result = groups_promote_member($user_id, $group_id, $new_role);
                                break;
                            case 'member':
                                if ('admin' == $existing_role || 'mod' == $existing_role) {
                                    $result = groups_demote_member($user_id, $group_id);
                                } elseif ('banned' == $existing_role) {
                                    $result = groups_unban_member($user_id, $group_id);
                                }
                                break;
                            case 'banned':
                                $result = groups_ban_member($user_id, $group_id);
                                break;
                            case 'remove':
                                $result = groups_remove_member($user_id, $group_id);
                                break;
                        }
                        // Store the success or failure.
                        if ($result) {
                            $success_modified[] = $user_id;
                        } else {
                            $error_modified[] = $user_id;
                        }
                    }
                }
            }
        }
        /**
         * Fires before redirect so plugins can do something first on save action.
         *
         * @since 1.6.0
         *
         * @param int $group_id ID of the group being edited.
         */
        do_action('bp_group_admin_edit_after', $group_id);
        // Create the redirect URL.
        if ($error) {
            // This means there was an error updating group details.
            $redirect_to = add_query_arg('error', (int) $error, $redirect_to);
        } else {
            // Group details were update successfully.
            $redirect_to = add_query_arg('updated', 1, $redirect_to);
        }
        if (!empty($success_new)) {
            $success_new = implode(',', array_filter($success_new, 'urlencode'));
            $redirect_to = add_query_arg('success_new', $success_new, $redirect_to);
        }
        if (!empty($error_new)) {
            $error_new = implode(',', array_filter($error_new, 'urlencode'));
            $redirect_to = add_query_arg('error_new', $error_new, $redirect_to);
        }
        if (!empty($success_modified)) {
            $success_modified = implode(',', array_filter($success_modified, 'urlencode'));
            $redirect_to = add_query_arg('success_modified', $success_modified, $redirect_to);
        }
        if (!empty($error_modified)) {
            $error_modified = implode(',', array_filter($error_modified, 'urlencode'));
            $redirect_to = add_query_arg('error_modified', $error_modified, $redirect_to);
        }
        /**
         * Filters the URL to redirect to after successfully editing a group.
         *
         * @since 1.7.0
         *
         * @param string $redirect_to URL to redirect user to.
         */
        wp_redirect(apply_filters('bp_group_admin_edit_redirect', $redirect_to));
        exit;
        // If a referrer and a nonce is supplied, but no action, redirect back.
    } elseif (!empty($_GET['_wp_http_referer'])) {
        wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
        exit;
    }
}
/**
 * Set up the Activity admin page.
 *
 * Does the following:
 *   - Register contextual help and screen options for this admin page.
 *   - Enqueues scripts and styles.
 *   - Catches POST and GET requests related to Activity.
 *
 * @since 1.6.0
 *
 * @global object                 $bp                     BuddyPress global settings.
 * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list table.
 */
function bp_activity_admin_load()
{
    global $bp_activity_list_table;
    $bp = buddypress();
    $doaction = bp_admin_list_table_current_bulk_action();
    $min = bp_core_get_minified_asset_suffix();
    /**
     * Fires at top of Activity admin page.
     *
     * @since 1.6.0
     *
     * @param string $doaction Current $_GET action being performed in admin screen.
     */
    do_action('bp_activity_admin_load', $doaction);
    // Edit screen.
    if ('edit' == $doaction && !empty($_GET['aid'])) {
        // Columns screen option.
        add_screen_option('layout_columns', array('default' => 2, 'max' => 2));
        get_current_screen()->add_help_tab(array('id' => 'bp-activity-edit-overview', 'title' => __('Overview', 'buddypress'), 'content' => '<p>' . __('You edit activities made on your site similar to the way you edit a comment. This is useful if you need to change which page the activity links to, or when you notice that the author has made a typographical error.', 'buddypress') . '</p>' . '<p>' . __('The two big editing areas for the activity title and content are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Primary Item/Secondary Item, Link, Type, Author ID) or to choose a 1- or 2-column layout for this screen.', 'buddypress') . '</p>' . '<p>' . __('You can also moderate the activity from this screen using the Status box, where you can also change the timestamp of the activity.', 'buddypress') . '</p>'));
        get_current_screen()->add_help_tab(array('id' => 'bp-activity-edit-advanced', 'title' => __('Item, Link, Type', 'buddypress'), 'content' => '<p>' . __('<strong>Primary Item/Secondary Item</strong> - These identify the object that created the activity. For example, the fields could reference a comment left on a specific site. Some types of activity may only use one, or none, of these fields.', 'buddypress') . '</p>' . '<p>' . __('<strong>Link</strong> - Used by some types of activity (e.g blog posts and comments, and forum topics and replies) to store a link back to the original content.', 'buddypress') . '</p>' . '<p>' . __('<strong>Type</strong> - Each distinct kind of activity has its own type. For example, <code>created_group</code> is used when a group is created and <code>joined_group</code> is used when a user joins a group.', 'buddypress') . '</p>' . '<p>' . __('For information about when and how BuddyPress uses all of these settings, see the Managing Activity link in the panel to the side.', 'buddypress') . '</p>'));
        // Help panel - sidebar links.
        get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p>' . __('<a href="https://codex.buddypress.org/administrator-guide/activity-stream-management-panels/">Managing Activity</a>', 'buddypress') . '</p>' . '<p>' . __('<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress') . '</p>');
        // Register metaboxes for the edit screen.
        add_meta_box('submitdiv', _x('Status', 'activity admin edit screen', 'buddypress'), 'bp_activity_admin_edit_metabox_status', get_current_screen()->id, 'side', 'core');
        add_meta_box('bp_activity_itemids', _x('Primary Item/Secondary Item', 'activity admin edit screen', 'buddypress'), 'bp_activity_admin_edit_metabox_itemids', get_current_screen()->id, 'normal', 'core');
        add_meta_box('bp_activity_link', _x('Link', 'activity admin edit screen', 'buddypress'), 'bp_activity_admin_edit_metabox_link', get_current_screen()->id, 'normal', 'core');
        add_meta_box('bp_activity_type', _x('Type', 'activity admin edit screen', 'buddypress'), 'bp_activity_admin_edit_metabox_type', get_current_screen()->id, 'normal', 'core');
        add_meta_box('bp_activity_userid', _x('Author ID', 'activity admin edit screen', 'buddypress'), 'bp_activity_admin_edit_metabox_userid', get_current_screen()->id, 'normal', 'core');
        /**
         * Fires after the registration of all of the default activity meta boxes.
         *
         * @since 2.4.0
         */
        do_action('bp_activity_admin_meta_boxes');
        // Enqueue JavaScript files.
        wp_enqueue_script('postbox');
        wp_enqueue_script('dashboard');
        wp_enqueue_script('comment');
        // Index screen.
    } else {
        // Create the Activity screen list table.
        $bp_activity_list_table = new BP_Activity_List_Table();
        // The per_page screen option.
        add_screen_option('per_page', array('label' => _x('Activity', 'Activity items per page (screen options)', 'buddypress')));
        // Help panel - overview text.
        get_current_screen()->add_help_tab(array('id' => 'bp-activity-overview', 'title' => __('Overview', 'buddypress'), 'content' => '<p>' . __('You can manage activities made on your site similar to the way you manage comments and other content. This screen is customizable in the same ways as other management screens, and you can act on activities using the on-hover action links or the Bulk Actions.', 'buddypress') . '</p>' . '<p>' . __('There are many different types of activities. Some are generated automatically by BuddyPress and other plugins, and some are entered directly by a user in the form of status update. To help manage the different activity types, use the filter dropdown box to switch between them.', 'buddypress') . '</p>'));
        // Help panel - moderation text.
        get_current_screen()->add_help_tab(array('id' => 'bp-activity-moderating', 'title' => __('Moderating Activity', 'buddypress'), 'content' => '<p>' . __('In the <strong>Activity</strong> column, above each activity it says &#8220;Submitted on,&#8221; followed by the date and time the activity item was generated on your site. Clicking on the date/time link will take you to that activity on your live site. Hovering over any activity gives you options to reply, edit, spam mark, or delete that activity.', 'buddypress') . '</p>' . '<p>' . __("In the <strong>In Response To</strong> column, if the activity was in reply to another activity, it shows that activity's author's picture and name, and a link to that activity on your live site. If there is a small bubble, the number in it shows how many other activities are related to this one; these are usually comments. Clicking the bubble will filter the activity screen to show only related activity items.", 'buddypress') . '</p>'));
        // Help panel - sidebar links.
        get_current_screen()->set_help_sidebar('<p><strong>' . __('For more information:', 'buddypress') . '</strong></p>' . '<p>' . __('<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress') . '</p>');
        // Add accessible hidden heading and text for Activity screen pagination.
        if (bp_get_major_wp_version() >= 4.4) {
            get_current_screen()->set_screen_reader_content(array('heading_pagination' => __('Activity list navigation', 'buddypress')));
        }
    }
    // Enqueue CSS and JavaScript.
    wp_enqueue_script('bp_activity_admin_js', $bp->plugin_url . "bp-activity/admin/js/admin{$min}.js", array('jquery', 'wp-ajax-response'), bp_get_version(), true);
    wp_localize_script('bp_activity_admin_js', 'bp_activity_admin_vars', array('page' => get_current_screen()->id));
    wp_enqueue_style('bp_activity_admin_css', $bp->plugin_url . "bp-activity/admin/css/admin{$min}.css", array(), bp_get_version());
    wp_style_add_data('bp_activity_admin_css', 'rtl', true);
    if ($min) {
        wp_style_add_data('bp_activity_admin_css', 'suffix', $min);
    }
    /**
     * Fires after the activity js and style has been enqueued.
     *
     * @since 2.4.0
     */
    do_action('bp_activity_admin_enqueue_scripts');
    // Handle spam/un-spam/delete of activities.
    if (!empty($doaction) && !in_array($doaction, array('-1', 'edit', 'save'))) {
        // Build redirection URL.
        $redirect_to = remove_query_arg(array('aid', 'deleted', 'error', 'spammed', 'unspammed'), wp_get_referer());
        $redirect_to = add_query_arg('paged', $bp_activity_list_table->get_pagenum(), $redirect_to);
        // Get activity IDs.
        $activity_ids = array_map('absint', (array) $_REQUEST['aid']);
        /**
         * Filters list of IDs being spammed/un-spammed/deleted.
         *
         * @since 1.6.0
         *
         * @param array $activity_ids Activity IDs to spam/un-spam/delete.
         */
        $activity_ids = apply_filters('bp_activity_admin_action_activity_ids', $activity_ids);
        // Is this a bulk request?
        if ('bulk_' == substr($doaction, 0, 5) && !empty($_REQUEST['aid'])) {
            // Check this is a valid form submission.
            check_admin_referer('bulk-activities');
            // Trim 'bulk_' off the action name to avoid duplicating a ton of code.
            $doaction = substr($doaction, 5);
            // This is a request to delete, spam, or un-spam, a single item.
        } elseif (!empty($_REQUEST['aid'])) {
            // Check this is a valid form submission.
            check_admin_referer('spam-activity_' . $activity_ids[0]);
        }
        // Initialise counters for how many of each type of item we perform an action on.
        $deleted = $spammed = $unspammed = 0;
        // Store any errors that occurs when updating the database items.
        $errors = array();
        // "We'd like to shoot the monster, could you move, please?"
        foreach ($activity_ids as $activity_id) {
            // @todo: Check the permissions on each
            // if ( ! current_user_can( 'bp_edit_activity', $activity_id ) )
            // continue;
            // Get the activity from the database.
            $activity = new BP_Activity_Activity($activity_id);
            if (empty($activity->component)) {
                $errors[] = $activity_id;
                continue;
            }
            switch ($doaction) {
                case 'delete':
                    if ('activity_comment' == $activity->type) {
                        bp_activity_delete_comment($activity->item_id, $activity->id);
                    } else {
                        bp_activity_delete(array('id' => $activity->id));
                    }
                    $deleted++;
                    break;
                case 'ham':
                    /**
                     * Remove moderation and blacklist checks in case we want to ham an activity
                     * which contains one of these listed keys.
                     */
                    remove_action('bp_activity_before_save', 'bp_activity_check_moderation_keys', 2, 1);
                    remove_action('bp_activity_before_save', 'bp_activity_check_blacklist_keys', 2, 1);
                    bp_activity_mark_as_ham($activity);
                    $result = $activity->save();
                    // Check for any error during activity save.
                    if (!$result) {
                        $errors[] = $activity->id;
                    } else {
                        $unspammed++;
                    }
                    break;
                case 'spam':
                    bp_activity_mark_as_spam($activity);
                    $result = $activity->save();
                    // Check for any error during activity save.
                    if (!$result) {
                        $errors[] = $activity->id;
                    } else {
                        $spammed++;
                    }
                    break;
                default:
                    break;
            }
            // Release memory.
            unset($activity);
        }
        /**
         * Fires before redirect for plugins to do something with activity.
         *
         * Passes an activity array counts how many were spam, not spam, deleted, and IDs that were errors.
         *
         * @since 1.6.0
         *
         * @param array  $value        Array holding spam, not spam, deleted counts, error IDs.
         * @param string $redirect_to  URL to redirect to.
         * @param array  $activity_ids Original array of activity IDs.
         */
        do_action('bp_activity_admin_action_after', array($spammed, $unspammed, $deleted, $errors), $redirect_to, $activity_ids);
        // Add arguments to the redirect URL so that on page reload, we can easily display what we've just done.
        if ($spammed) {
            $redirect_to = add_query_arg('spammed', $spammed, $redirect_to);
        }
        if ($unspammed) {
            $redirect_to = add_query_arg('unspammed', $unspammed, $redirect_to);
        }
        if ($deleted) {
            $redirect_to = add_query_arg('deleted', $deleted, $redirect_to);
        }
        // If an error occurred, pass back the activity ID that failed.
        if (!empty($errors)) {
            $redirect_to = add_query_arg('error', implode(',', array_map('absint', $errors)), $redirect_to);
        }
        /**
         * Filters redirect URL after activity spamming/un-spamming/deletion occurs.
         *
         * @since 1.6.0
         *
         * @param string $redirect_to URL to redirect to.
         */
        wp_redirect(apply_filters('bp_activity_admin_action_redirect', $redirect_to));
        exit;
        // Save the edit.
    } elseif ($doaction && 'save' == $doaction) {
        // Build redirection URL.
        $redirect_to = remove_query_arg(array('action', 'aid', 'deleted', 'error', 'spammed', 'unspammed'), $_SERVER['REQUEST_URI']);
        // Get activity ID.
        $activity_id = (int) $_REQUEST['aid'];
        // Check this is a valid form submission.
        check_admin_referer('edit-activity_' . $activity_id);
        // Get the activity from the database.
        $activity = new BP_Activity_Activity($activity_id);
        // If the activity doesn't exist, just redirect back to the index.
        if (empty($activity->component)) {
            wp_redirect($redirect_to);
            exit;
        }
        // Check the form for the updated properties.
        // Store any error that occurs when updating the database item.
        $error = 0;
        // Activity spam status.
        $prev_spam_status = $new_spam_status = false;
        if (!empty($_POST['activity_status'])) {
            $prev_spam_status = $activity->is_spam;
            $new_spam_status = 'spam' == $_POST['activity_status'] ? true : false;
        }
        // Activity action.
        if (isset($_POST['bp-activities-action'])) {
            $activity->action = $_POST['bp-activities-action'];
        }
        // Activity content.
        if (isset($_POST['bp-activities-content'])) {
            $activity->content = $_POST['bp-activities-content'];
        }
        // Activity primary link.
        if (!empty($_POST['bp-activities-link'])) {
            $activity->primary_link = $_POST['bp-activities-link'];
        }
        // Activity user ID.
        if (!empty($_POST['bp-activities-userid'])) {
            $activity->user_id = (int) $_POST['bp-activities-userid'];
        }
        // Activity item primary ID.
        if (isset($_POST['bp-activities-primaryid'])) {
            $activity->item_id = (int) $_POST['bp-activities-primaryid'];
        }
        // Activity item secondary ID.
        if (isset($_POST['bp-activities-secondaryid'])) {
            $activity->secondary_item_id = (int) $_POST['bp-activities-secondaryid'];
        }
        // Activity type.
        if (!empty($_POST['bp-activities-type'])) {
            $actions = bp_activity_admin_get_activity_actions();
            // Check that the new type is a registered activity type.
            if (in_array($_POST['bp-activities-type'], $actions)) {
                $activity->type = $_POST['bp-activities-type'];
            }
        }
        // Activity timestamp.
        if (!empty($_POST['aa']) && !empty($_POST['mm']) && !empty($_POST['jj']) && !empty($_POST['hh']) && !empty($_POST['mn']) && !empty($_POST['ss'])) {
            $aa = $_POST['aa'];
            $mm = $_POST['mm'];
            $jj = $_POST['jj'];
            $hh = $_POST['hh'];
            $mn = $_POST['mn'];
            $ss = $_POST['ss'];
            $aa = $aa <= 0 ? date('Y') : $aa;
            $mm = $mm <= 0 ? date('n') : $mm;
            $jj = $jj > 31 ? 31 : $jj;
            $jj = $jj <= 0 ? date('j') : $jj;
            $hh = $hh > 23 ? $hh - 24 : $hh;
            $mn = $mn > 59 ? $mn - 60 : $mn;
            $ss = $ss > 59 ? $ss - 60 : $ss;
            // Reconstruct the date into a timestamp.
            $gmt_date = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss);
            $activity->date_recorded = $gmt_date;
        }
        // Has the spam status has changed?
        if ($new_spam_status != $prev_spam_status) {
            if ($new_spam_status) {
                bp_activity_mark_as_spam($activity);
            } else {
                bp_activity_mark_as_ham($activity);
            }
        }
        // Save.
        $result = $activity->save();
        // Clear the activity stream first page cache, in case this activity's timestamp was changed.
        wp_cache_delete('bp_activity_sitewide_front', 'bp');
        // Check for any error during activity save.
        if (false === $result) {
            $error = $activity->id;
        }
        /**
         * Fires before redirect so plugins can do something first on save action.
         *
         * @since 1.6.0
         *
         * @param array $value Array holding activity object and ID that holds error.
         */
        do_action_ref_array('bp_activity_admin_edit_after', array(&$activity, $error));
        // If an error occurred, pass back the activity ID that failed.
        if ($error) {
            $redirect_to = add_query_arg('error', $error, $redirect_to);
        } else {
            $redirect_to = add_query_arg('updated', $activity->id, $redirect_to);
        }
        /**
         * Filters URL to redirect to after saving.
         *
         * @since 1.6.0
         *
         * @param string $redirect_to URL to redirect to.
         */
        wp_redirect(apply_filters('bp_activity_admin_edit_redirect', $redirect_to));
        exit;
        // If a referrer and a nonce is supplied, but no action, redirect back.
    } elseif (!empty($_GET['_wp_http_referer'])) {
        wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
        exit;
    }
}
Example #6
0
 /**
  * Sets up theme defaults and registers support for various WordPress and BuddyPress features.
  *
  * Note that this function is hooked into the after_setup_theme hook, which runs
  * before the init hook. The init hook is too late for some features, such as indicating
  * support post thumbnails.
  *
  * To override bp_dtheme_setup() in a child theme, add your own bp_dtheme_setup to your child theme's
  * functions.php file.
  *
  * @global BuddyPress $bp The one true BuddyPress instance
  * @since BuddyPress (1.5)
  */
 function bp_dtheme_setup()
 {
     // Load the AJAX functions for the theme
     require TEMPLATEPATH . '/_inc/ajax.php';
     // This theme styles the visual editor with editor-style.css to match the theme style.
     add_editor_style();
     // This theme comes with all the BuddyPress goodies
     add_theme_support('buddypress');
     // This theme uses post thumbnails
     add_theme_support('post-thumbnails');
     // Add default posts and comments RSS feed links to head
     add_theme_support('automatic-feed-links');
     // Add responsive layout support to bp-default without forcing child
     // themes to inherit it if they don't want to
     add_theme_support('bp-default-responsive');
     // This theme uses wp_nav_menu() in one location.
     register_nav_menus(array('primary' => __('Primary Navigation', 'buddypress')));
     // This theme allows users to set a custom background
     // Backward-compatibility with WP < 3.4 will be removed in a future release
     if (bp_get_major_wp_version() >= 3.4) {
         $custom_background_args = array('wp-head-callback' => 'bp_dtheme_custom_background_style');
         add_theme_support('custom-background', $custom_background_args);
     } else {
         add_custom_background('bp_dtheme_custom_background_style');
     }
     // Add custom header support if allowed
     if (!defined('BP_DTHEME_DISABLE_CUSTOM_HEADER')) {
         define('HEADER_TEXTCOLOR', 'FFFFFF');
         // The height and width of your custom header. You can hook into the theme's own filters to change these values.
         // Add a filter to bp_dtheme_header_image_width and bp_dtheme_header_image_height to change these values.
         define('HEADER_IMAGE_WIDTH', apply_filters('bp_dtheme_header_image_width', 1250));
         define('HEADER_IMAGE_HEIGHT', apply_filters('bp_dtheme_header_image_height', 133));
         // We'll be using post thumbnails for custom header images on posts and pages. We want them to be 1250 pixels wide by 133 pixels tall.
         // Larger images will be auto-cropped to fit, smaller ones will be ignored.
         set_post_thumbnail_size(HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true);
         // Add a way for the custom header to be styled in the admin panel that controls custom headers.
         // Backward-compatibility with WP < 3.4 will be removed in a future release
         if (bp_get_major_wp_version() >= 3.4) {
             $custom_header_args = array('wp-head-callback' => 'bp_dtheme_header_style', 'admin-head-callback' => 'bp_dtheme_admin_header_style');
             add_theme_support('custom-header', $custom_header_args);
         } else {
             add_custom_image_header('bp_dtheme_header_style', 'bp_dtheme_admin_header_style');
         }
     }
     if (!is_admin()) {
         // Register buttons for the relevant component templates
         // Friends button
         if (bp_is_active('friends')) {
             add_action('bp_member_header_actions', 'bp_add_friend_button', 5);
         }
         // Activity button
         if (bp_is_active('activity')) {
             add_action('bp_member_header_actions', 'bp_send_public_message_button', 20);
         }
         // Messages button
         if (bp_is_active('messages')) {
             add_action('bp_member_header_actions', 'bp_send_private_message_button', 20);
         }
         // Group buttons
         if (bp_is_active('groups')) {
             add_action('bp_group_header_actions', 'bp_group_join_button', 5);
             add_action('bp_group_header_actions', 'bp_group_new_topic_button', 20);
             add_action('bp_directory_groups_actions', 'bp_group_join_button');
         }
         // Blog button
         if (bp_is_active('blogs')) {
             add_action('bp_directory_blogs_actions', 'bp_blogs_visit_blog_button');
         }
     }
 }
    /**
     * Markup for the Group Type bulk change select.
     *
     * @since 2.7.0
     *
     * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
     */
    public function add_group_type_bulk_change_select($which)
    {
        // `$which` is only passed in WordPress 4.6+. Avoid duplicating controls in earlier versions.
        static $displayed = false;
        if (version_compare(bp_get_major_wp_version(), '4.6', '<') && $displayed) {
            return;
        }
        $displayed = true;
        $id_name = 'bottom' === $which ? 'bp_change_type2' : 'bp_change_type';
        $types = bp_groups_get_group_types(array(), 'objects');
        ?>
		<div class="alignleft actions">
			<label class="screen-reader-text" for="<?php 
        echo $id_name;
        ?>
"><?php 
        _e('Change group type to&hellip;', 'buddypress');
        ?>
</label>
			<select name="<?php 
        echo $id_name;
        ?>
" id="<?php 
        echo $id_name;
        ?>
" style="display:inline-block;float:none;">
				<option value=""><?php 
        _e('Change group type to&hellip;', 'buddypress');
        ?>
</option>

				<?php 
        foreach ($types as $type) {
            ?>

					<option value="<?php 
            echo esc_attr($type->name);
            ?>
"><?php 
            echo esc_html($type->labels['singular_name']);
            ?>
</option>

				<?php 
        }
        ?>

				<option value="remove_group_type"><?php 
        _e('No Group Type', 'buddypress');
        ?>
</option>

			</select>
			<?php 
        wp_nonce_field('bp-bulk-groups-change-type-' . bp_loggedin_user_id(), 'bp-bulk-groups-change-type-nonce');
        submit_button(__('Change', 'buddypress'), 'button', 'bp_change_group_type', false);
        ?>
		</div>
		<?php 
    }
/**
 * User specific functions - sets background image handling
 *
 * @since 1.0
 */
function status_setup_user_theme()
{
    //add_custom_background('status_apply_custom_user_settings', '');
    if (bp_get_major_wp_version() >= 3.4) {
        // Not sure if "wp-head-callback" doesn't work what it says on the tin,
        // or if there's some other thing wrong...
        add_theme_support('custom-background', array('wp-head-callback' => 'status_apply_custom_user_settings'));
        // Either way, it's not crucial
        add_action('wp_head', 'status_apply_custom_user_settings', 999);
        // Callback parameter doesn't seem to be called, for some reason...
    } else {
        add_custom_background('status_apply_custom_user_settings', '');
    }
}