/**
 * Register styles commonly used by BuddyPress.
 *
 * @since 2.1.0
 */
function bp_core_register_common_styles()
{
    $min = bp_core_get_minified_asset_suffix();
    $url = buddypress()->plugin_url . 'bp-core/css/';
    /**
     * Filters the URL for the Admin Bar stylesheet.
     *
     * @since 1.1.0
     *
     * @param string $value URL for the Admin Bar stylesheet.
     */
    $admin_bar_file = apply_filters('bp_core_admin_bar_css', "{$url}admin-bar{$min}.css");
    /**
     * Filters the BuddyPress Core stylesheet files to register.
     *
     * @since 2.1.0
     *
     * @param array $value Array of stylesheet file information to register.
     */
    $styles = apply_filters('bp_core_register_common_styles', array('bp-admin-bar' => array('file' => $admin_bar_file, 'dependencies' => array('admin-bar')), 'bp-avatar' => array('file' => "{$url}avatar{$min}.css", 'dependencies' => array('jcrop'))));
    foreach ($styles as $id => $style) {
        wp_register_style($id, $style['file'], $style['dependencies'], bp_get_version());
        wp_style_add_data($id, 'rtl', true);
        if ($min) {
            wp_style_add_data($id, 'suffix', $min);
        }
    }
}
/**
 * Enqueue the jQuery libraries for handling drag/drop/sort.
 *
 * @since 1.5.0
 */
function xprofile_add_admin_js()
{
    if (!empty($_GET['page']) && strpos($_GET['page'], 'bp-profile-setup') !== false) {
        wp_enqueue_script('jquery-ui-core');
        wp_enqueue_script('jquery-ui-tabs');
        wp_enqueue_script('jquery-ui-mouse');
        wp_enqueue_script('jquery-ui-draggable');
        wp_enqueue_script('jquery-ui-droppable');
        wp_enqueue_script('jquery-ui-sortable');
        $min = bp_core_get_minified_asset_suffix();
        wp_enqueue_script('xprofile-admin-js', buddypress()->plugin_url . "bp-xprofile/admin/js/admin{$min}.js", array('jquery', 'jquery-ui-sortable'), bp_get_version());
        // Localize strings.
        // supports_options_field_types is a dynamic list of field
        // types that support options, for use in showing/hiding the
        // "please enter options for this field" section.
        $strings = array('do_settings_section_field_types' => array(), 'do_autolink' => '');
        foreach (bp_xprofile_get_field_types() as $field_type => $field_type_class) {
            $field = new $field_type_class();
            if ($field->do_settings_section()) {
                $strings['do_settings_section_field_types'][] = $field_type;
            }
        }
        // Load 'autolink' setting into JS so that we can provide smart defaults when switching field type.
        if (!empty($_GET['field_id'])) {
            $field_id = intval($_GET['field_id']);
            // Pull the raw data from the DB so we can tell whether the admin has saved a value yet.
            $strings['do_autolink'] = bp_xprofile_get_meta($field_id, 'field', 'do_autolink');
        }
        wp_localize_script('xprofile-admin-js', 'XProfileAdmin', $strings);
    }
}
/**
 * Enqueue @mentions JS.
 *
 * @since 2.1.0
 */
function bp_activity_mentions_script()
{
    if (!bp_activity_maybe_load_mentions_scripts()) {
        return;
    }
    // Special handling for New/Edit screens in wp-admin.
    if (is_admin()) {
        if (!get_current_screen() || !in_array(get_current_screen()->base, array('page', 'post')) || !post_type_supports(get_current_screen()->post_type, 'editor')) {
            return;
        }
    }
    $min = bp_core_get_minified_asset_suffix();
    wp_enqueue_script('bp-mentions', buddypress()->plugin_url . "bp-activity/js/mentions{$min}.js", array('jquery', 'jquery-atwho'), bp_get_version(), true);
    wp_enqueue_style('bp-mentions-css', buddypress()->plugin_url . "bp-activity/css/mentions{$min}.css", array(), bp_get_version());
    wp_style_add_data('bp-mentions-css', 'rtl', true);
    if ($min) {
        wp_style_add_data('bp-mentions-css', 'suffix', $min);
    }
    // If the script has been enqueued, let's attach our mentions TinyMCE init callback.
    add_filter('tiny_mce_before_init', 'bp_add_mentions_on_tinymce_init', 10, 2);
    /**
     * Fires at the end of the Activity Mentions script.
     *
     * This is the hook where BP components can add their own prefetched results
     * friends to the page for quicker @mentions lookups.
     *
     * @since 2.1.0
     */
    do_action('bp_activity_mentions_prime_results');
}
 /**
  * Working as a group, we get things done better.
  *
  * @since 1.0.3
  */
 public function __construct()
 {
     $widget_ops = array('description' => __('A dynamic list of recently active, popular, and newest groups', 'buddypress'), 'classname' => 'widget_bp_groups_widget buddypress widget');
     parent::__construct(false, _x('(BuddyPress) Groups', 'widget name', 'buddypress'), $widget_ops);
     if (is_active_widget(false, false, $this->id_base) && !is_admin() && !is_network_admin()) {
         $min = bp_core_get_minified_asset_suffix();
         wp_enqueue_script('groups_widget_groups_list-js', buddypress()->plugin_url . "bp-groups/js/widget-groups{$min}.js", array('jquery'), bp_get_version());
     }
 }
/**
 * Initialize the Customizer for emails.
 *
 * @since 2.5.0
 *
 * @param WP_Customize_Manager $wp_customize The Customizer object.
 */
function bp_email_init_customizer(WP_Customize_Manager $wp_customize)
{
    // Require WP 4.0+.
    if (!method_exists($wp_customize, 'add_panel')) {
        return;
    }
    if (!bp_is_email_customizer() && (!defined('DOING_AJAX') || !DOING_AJAX)) {
        return;
    }
    $wp_customize->add_panel('bp_mailtpl', array('description' => __('Customize the appearance of emails sent by BuddyPress.', 'buddypress'), 'title' => _x('BuddyPress Emails', 'screen heading', 'buddypress')));
    $sections = bp_email_get_customizer_sections();
    foreach ($sections as $section_id => $args) {
        $wp_customize->add_section($section_id, $args);
    }
    $settings = bp_email_get_customizer_settings();
    foreach ($settings as $setting_id => $args) {
        $wp_customize->add_setting($setting_id, $args);
    }
    /**
     * BP_Customizer_Control_Range class.
     */
    if (!buddypress()->do_autoload) {
        require_once dirname(__FILE__) . '/classes/class-bp-customizer-control-range.php';
    }
    /**
     * Fires to let plugins register extra Customizer controls for emails.
     *
     * @since 2.5.0
     *
     * @param WP_Customize_Manager $wp_customize The Customizer object.
     */
    do_action('bp_email_customizer_register_sections', $wp_customize);
    $controls = bp_email_get_customizer_controls();
    foreach ($controls as $control_id => $args) {
        $wp_customize->add_control(new $args['class']($wp_customize, $control_id, $args));
    }
    /*
     * Hook actions/filters for further configuration.
     */
    add_filter('customize_section_active', 'bp_email_customizer_hide_sections', 12, 2);
    if (is_customize_preview()) {
        /*
         * Enqueue scripts/styles for the Customizer's preview window.
         *
         * Scripts can't be registered in bp_core_register_common_styles() etc because
         * the Customizer loads very, very early.
         */
        $bp = buddypress();
        $min = bp_core_get_minified_asset_suffix();
        wp_enqueue_script('bp-customizer-receiver-emails', "{$bp->plugin_url}bp-core/admin/js/customizer-receiver-emails{$min}.js", array('customize-preview'), bp_get_version(), true);
        // Include the preview loading style
        add_action('wp_footer', array($wp_customize, 'customize_preview_loading_style'));
    }
}
/**
 * Enqueue the CSS for messages autocomplete.
 *
 * @todo Why do we call wp_print_styles()?
 */
function messages_add_autocomplete_css()
{
    if (bp_is_messages_component() && bp_is_current_action('compose')) {
        $min = bp_core_get_minified_asset_suffix();
        $url = buddypress()->plugin_url . 'bp-messages/css/';
        wp_enqueue_style('bp-messages-autocomplete', "{$url}autocomplete/jquery.autocompletefb{$min}.css", array(), bp_get_version());
        wp_style_add_data('bp-messages-autocomplete', 'rtl', true);
        if ($min) {
            wp_style_add_data('bp-messages-autocomplete', 'suffix', $min);
        }
        wp_print_styles();
    }
}
/**
 * Add inline styles for BP activity embeds.
 *
 * @since  2.6.0
 */
function bp_activity_embed_add_inline_styles()
{
    if (false === bp_is_single_activity()) {
        return;
    }
    $min = bp_core_get_minified_asset_suffix();
    if (is_rtl()) {
        $css = bp_locate_template_asset("css/embeds-activity-rtl{$min}.css");
    } else {
        $css = bp_locate_template_asset("css/embeds-activity{$min}.css");
    }
    // Bail if file wasn't found.
    if (false === $css) {
        return;
    }
    // Grab contents of CSS file and do some rudimentary CSS protection.
    $css = file_get_contents($css['file']);
    $css = wp_kses($css, array("\\'", '\\"'));
    printf('<style type="text/css">%s</style>', $css);
}
 /**
  * Add some specific styling to the Edit User and Edit User's Profile page.
  *
  * @since 2.0.0
  */
 public function enqueue_scripts()
 {
     if (!in_array(get_current_screen()->id, $this->screen_id)) {
         return;
     }
     $min = bp_core_get_minified_asset_suffix();
     $css = $this->css_url . "admin{$min}.css";
     /**
      * Filters the CSS URL to enqueue in the Members admin area.
      *
      * @since 2.0.0
      *
      * @param string $css URL to the CSS admin file to load.
      */
     $css = apply_filters('bp_members_admin_css', $css);
     wp_enqueue_style('bp-members-css', $css, array(), bp_get_version());
     wp_style_add_data('bp-members-css', 'rtl', true);
     if ($min) {
         wp_style_add_data('bp-members-css', 'suffix', $min);
     }
     // Only load JavaScript for BuddyPress profile.
     if (get_current_screen()->id == $this->user_page) {
         $js = $this->js_url . "admin{$min}.js";
         /**
          * Filters the JS URL to enqueue in the Members admin area.
          *
          * @since 2.0.0
          *
          * @param string $js URL to the JavaScript admin file to load.
          */
         $js = apply_filters('bp_members_admin_js', $js);
         wp_enqueue_script('bp-members-js', $js, array('jquery'), bp_get_version(), true);
     }
     /**
      * Fires after all of the members JavaScript and CSS are enqueued.
      *
      * @since 2.0.0
      *
      * @param string $id        ID of the current screen.
      * @param array  $screen_id Array of allowed screens to add scripts and styles to.
      */
     do_action('bp_members_admin_enqueue_scripts', get_current_screen()->id, $this->screen_id);
 }
/**
 * 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;
    }
}
/**
 * Add an admin notice to installations that are not running PHP 5.3+.
 *
 * @since 2.7.0
 */
function bp_core_admin_php53_admin_notice()
{
    // If not on the Plugins page, stop now.
    if ('plugins' !== get_current_screen()->parent_base) {
        return;
    }
    if (!current_user_can('update_core')) {
        return;
    }
    if (bp_core_admin_is_running_php53_or_greater()) {
        return;
    }
    $notice_id = 'bp28-php53';
    if (bp_get_option("bp-dismissed-notice-{$notice_id}")) {
        return;
    }
    $bp = buddypress();
    $min = bp_core_get_minified_asset_suffix();
    wp_enqueue_script('bp-dismissible-admin-notices', "{$bp->plugin_url}bp-core/admin/js/dismissible-admin-notices{$min}.js", array('jquery'), bp_get_version(), true);
    $php_version = PHP_VERSION;
    ?>

	<div id="message" class="error notice is-dismissible bp-is-dismissible" data-noticeid="<?php 
    echo esc_attr($notice_id);
    ?>
">
		<p><strong><?php 
    esc_html_e('Your site is not ready for BuddyPress 2.8.', 'buddypress');
    ?>
</strong></p>
		<p><?php 
    printf(esc_html__('Your site is currently running PHP version %s, while BuddyPress 2.8 will require version 5.3+.', 'buddypress'), $php_version);
    ?>
 <?php 
    printf(__('See <a href="%s">the Codex guide</a> for more information.', 'buddypress'), 'https://codex.buddypress.org/getting-started/buddypress-2-8-will-require-php-5-3/');
    ?>
</p>
		<?php 
    wp_nonce_field("bp-dismissible-notice-{$notice_id}", "bp-dismissible-nonce-{$notice_id}");
    ?>
	</div>
	<?php 
}
Example #11
0
 /**
  * Register JS commonly used by BuddyPress wp-admin screens.
  *
  * @since 2.5.0
  */
 public function admin_register_scripts()
 {
     $min = bp_core_get_minified_asset_suffix();
     $url = $this->js_url;
     /**
      * Filters the BuddyPress admin JS files to register.
      *
      * @since 2.5.0
      *
      * @param array $value Array of admin JS file information to register.
      */
     $scripts = apply_filters('bp_core_admin_register_scripts', array('bp-customizer-controls' => array('file' => "{$url}customizer-controls{$min}.js", 'dependencies' => array('jquery'), 'footer' => true)));
     $version = bp_get_version();
     foreach ($scripts as $id => $script) {
         wp_register_script($id, $script['file'], $script['dependencies'], $version, $script['footer']);
     }
 }
/**
 * 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;
    }
}
 /**
  * Enqueue the required JavaScript files
  *
  * @since 1.7.0
  */
 public function enqueue_scripts()
 {
     $min = bp_core_get_minified_asset_suffix();
     // Locate the BP JS file.
     $asset = $this->locate_asset_in_stack("buddypress{$min}.js", 'js');
     // Enqueue the global JS, if found - AJAX will not work
     // without it.
     if (isset($asset['location'], $asset['handle'])) {
         wp_enqueue_script($asset['handle'], $asset['location'], bp_core_get_js_dependencies(), $this->version);
     }
     /**
      * Filters core JavaScript strings for internationalization before AJAX usage.
      *
      * @since 2.0.0
      *
      * @param array $value Array of key/value pairs for AJAX usage.
      */
     $params = apply_filters('bp_core_get_js_strings', array('accepted' => __('Accepted', 'buddypress'), 'close' => __('Close', 'buddypress'), 'comments' => __('comments', 'buddypress'), 'leave_group_confirm' => __('Are you sure you want to leave this group?', 'buddypress'), 'mark_as_fav' => __('Favorite', 'buddypress'), 'my_favs' => __('My Favorites', 'buddypress'), 'rejected' => __('Rejected', 'buddypress'), 'remove_fav' => __('Remove Favorite', 'buddypress'), 'show_all' => __('Show all', 'buddypress'), 'show_all_comments' => __('Show all comments for this thread', 'buddypress'), 'show_x_comments' => __('Show all %d comments', 'buddypress'), 'unsaved_changes' => __('Your profile has unsaved changes. If you leave the page, the changes will be lost.', 'buddypress'), 'view' => __('View', 'buddypress')));
     wp_localize_script($asset['handle'], 'BP_DTheme', $params);
     // Maybe enqueue comment reply JS.
     if (is_singular() && bp_is_blog_page() && get_option('thread_comments')) {
         wp_enqueue_script('comment-reply');
     }
     // Maybe enqueue password verify JS (register page or user settings page).
     if (bp_is_register_page() || function_exists('bp_is_user_settings_general') && bp_is_user_settings_general()) {
         // Locate the Register Page JS file.
         $asset = $this->locate_asset_in_stack("password-verify{$min}.js", 'js', 'bp-legacy-password-verify');
         $dependencies = array_merge(bp_core_get_js_dependencies(), array('password-strength-meter'));
         // Enqueue script.
         wp_enqueue_script($asset['handle'] . '-password-verify', $asset['location'], $dependencies, $this->version);
     }
     // Star private messages.
     if (bp_is_active('messages', 'star') && bp_is_user_messages()) {
         wp_localize_script($asset['handle'], 'BP_PM_Star', array('strings' => array('text_unstar' => __('Unstar', 'buddypress'), 'text_star' => __('Star', 'buddypress'), 'title_unstar' => __('Starred', 'buddypress'), 'title_star' => __('Not starred', 'buddypress'), 'title_unstar_thread' => __('Remove all starred messages in this thread', 'buddypress'), 'title_star_thread' => __('Star the first message in this thread', 'buddypress')), 'is_single_thread' => (int) bp_is_messages_conversation(), 'star_counter' => 0, 'unstar_counter' => 0));
     }
 }
 /**
  * Enqueue scripts.
  *
  * @since 2.6.0
  */
 public function enqueue_scripts()
 {
     $min = bp_core_get_minified_asset_suffix();
     wp_enqueue_script('bp_core_widget_friends-js', buddypress()->plugin_url . "bp-friends/js/widget-friends{$min}.js", array('jquery'), bp_get_version());
 }
Example #15
0
/**
 * Enqueue the BuddyBar CSS.
 *
 * @deprecated 2.1.0
 */
function bp_core_load_buddybar_css()
{
    if (bp_use_wp_admin_bar() || (int) bp_get_option('hide-loggedout-adminbar') && !is_user_logged_in() || defined('BP_DISABLE_ADMIN_BAR') && BP_DISABLE_ADMIN_BAR) {
        return;
    }
    $min = bp_core_get_minified_asset_suffix();
    if (file_exists(get_stylesheet_directory() . '/_inc/css/adminbar.css')) {
        // Backwards compatibility
        $stylesheet = get_stylesheet_directory_uri() . '/_inc/css/adminbar.css';
    } else {
        $stylesheet = buddypress()->plugin_url . "bp-core/css/buddybar{$min}.css";
    }
    wp_enqueue_style('bp-admin-bar', apply_filters('bp_core_buddybar_rtl_css', $stylesheet), array(), bp_get_version());
    wp_style_add_data('bp-admin-bar', 'rtl', true);
    if ($min) {
        wp_style_add_data('bp-admin-bar', 'suffix', $min);
    }
}
    /**
     * Display the widget.
     *
     * @since 1.9.0
     *
     * @param array $args Widget arguments.
     * @param array $instance The widget settings, as saved by the user.
     */
    function widget($args, $instance)
    {
        global $members_template;
        extract($args);
        if (!bp_displayed_user_id()) {
            return;
        }
        $min = bp_core_get_minified_asset_suffix();
        wp_enqueue_script('bp_core_widget_friends-js', buddypress()->plugin_url . "bp-friends/js/widget-friends{$min}.js", array('jquery'), bp_get_version());
        $user_id = bp_displayed_user_id();
        $link = trailingslashit(bp_displayed_user_domain() . bp_get_friends_slug());
        $instance['title'] = sprintf(__("%s's Friends", 'buddypress'), bp_get_displayed_user_fullname());
        if (empty($instance['friend_default'])) {
            $instance['friend_default'] = 'active';
        }
        /**
         * Filters the Friends widget title.
         *
         * @since 1.8.0
         * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.
         *
         * @param string $title    The widget title.
         * @param array  $instance The settings for the particular instance of the widget.
         * @param string $id_base  Root ID for all widgets of this type.
         */
        $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
        echo $before_widget;
        $title = $instance['link_title'] ? '<a href="' . esc_url($link) . '">' . esc_html($title) . '</a>' : esc_html($title);
        echo $before_title . $title . $after_title;
        $members_args = array('user_id' => absint($user_id), 'type' => sanitize_text_field($instance['friend_default']), 'max' => absint($instance['max_friends']), 'populate_extras' => 1);
        // Back up the global.
        $old_members_template = $members_template;
        ?>

		<?php 
        if (bp_has_members($members_args)) {
            ?>
			<div class="item-options" id="friends-list-options">
				<a href="<?php 
            bp_members_directory_permalink();
            ?>
" id="newest-friends" <?php 
            if ($instance['friend_default'] == 'newest') {
                ?>
class="selected"<?php 
            }
            ?>
><?php 
            _e('Newest', 'buddypress');
            ?>
</a>
				| <a href="<?php 
            bp_members_directory_permalink();
            ?>
" id="recently-active-friends" <?php 
            if ($instance['friend_default'] == 'active') {
                ?>
class="selected"<?php 
            }
            ?>
><?php 
            _e('Active', 'buddypress');
            ?>
</a>
				| <a href="<?php 
            bp_members_directory_permalink();
            ?>
" id="popular-friends" <?php 
            if ($instance['friend_default'] == 'popular') {
                ?>
class="selected"<?php 
            }
            ?>
><?php 
            _e('Popular', 'buddypress');
            ?>
</a>
			</div>

			<ul id="friends-list" class="item-list">
				<?php 
            while (bp_members()) {
                bp_the_member();
                ?>
					<li class="vcard">
						<div class="item-avatar">
							<a href="<?php 
                bp_member_permalink();
                ?>
" title="<?php 
                bp_member_name();
                ?>
"><?php 
                bp_member_avatar();
                ?>
</a>
						</div>

						<div class="item">
							<div class="item-title fn"><a href="<?php 
                bp_member_permalink();
                ?>
" title="<?php 
                bp_member_name();
                ?>
"><?php 
                bp_member_name();
                ?>
</a></div>
							<div class="item-meta">
								<span class="activity">
								<?php 
                if ('newest' == $instance['friend_default']) {
                    bp_member_registered();
                }
                if ('active' == $instance['friend_default']) {
                    bp_member_last_active();
                }
                if ('popular' == $instance['friend_default']) {
                    bp_member_total_friend_count();
                }
                ?>
								</span>
							</div>
						</div>
					</li>

				<?php 
            }
            ?>
			</ul>
			<?php 
            wp_nonce_field('bp_core_widget_friends', '_wpnonce-friends');
            ?>
			<input type="hidden" name="friends_widget_max" id="friends_widget_max" value="<?php 
            echo absint($instance['max_friends']);
            ?>
" />

		<?php 
        } else {
            ?>

			<div class="widget-error">
				<?php 
            _e('Sorry, no members were found.', 'buddypress');
            ?>
			</div>

		<?php 
        }
        ?>

		<?php 
        echo $after_widget;
        // Restore the global.
        $members_template = $old_members_template;
    }