function wff_group_creation_button() { if (bp_is_groups_component() && bp_is_directory() && is_user_logged_in() && bp_user_can_create_groups()) { ?> <div class="btn btn-primary create-group-button hidden-xs"> <i class="fa fa-user-plus"></i> <?php bp_group_create_button(); ?> </div> <?php } }
<?php do_action('bp_before_directory_groups_page'); ?> <div class="padder"> <?php do_action('bp_before_directory_groups'); ?> <form action="" method="post" id="groups-directory-form" class="dir-form"> <h3><?php _e('Groups Directory', 'buddypress'); if (is_user_logged_in() && bp_user_can_create_groups()) { ?> <a class="button" href="<?php echo trailingslashit(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create'); ?> "><?php _e('Create a Group', 'buddypress'); ?> </a><?php } ?> </h3> <?php do_action('bp_before_directory_groups_content'); ?>
/** * Display the Groups admin index screen. * * This screen contains a list of all BuddyPress groups. * * @since 1.7.0 * * @global BP_Groups_List_Table $bp_groups_list_table Group screen list table. * @global string $plugin_page Currently viewed plugin page. */ function bp_groups_admin_index() { global $bp_groups_list_table, $plugin_page; $messages = array(); // If the user has just made a change to a group, build status messages if (!empty($_REQUEST['deleted'])) { $deleted = !empty($_REQUEST['deleted']) ? (int) $_REQUEST['deleted'] : 0; if ($deleted > 0) { $messages[] = sprintf(_n('%s group has been permanently deleted.', '%s groups have been permanently deleted.', $deleted, 'buddypress'), number_format_i18n($deleted)); } } // Prepare the group items for display $bp_groups_list_table->prepare_items(); /** * Fires before the display of messages for the edit form. * * Useful for plugins to modify the messages before display. * * @since 1.7.0 * * @param array $messages Array of messages to be displayed. */ do_action('bp_groups_admin_index', $messages); ?> <div class="wrap"> <?php screen_icon('buddypress-groups'); ?> <h2> <?php _e('Groups', 'buddypress'); ?> <?php if (is_user_logged_in() && bp_user_can_create_groups()) { ?> <a class="add-new-h2" href="<?php echo trailingslashit(bp_get_groups_directory_permalink() . 'create'); ?> "><?php _e('Add New', 'buddypress'); ?> </a> <?php } ?> <?php if (!empty($_REQUEST['s'])) { ?> <span class="subtitle"><?php printf(__('Search results for “%s”', 'buddypress'), wp_html_excerpt(esc_html(stripslashes($_REQUEST['s'])), 50)); ?> </span> <?php } ?> </h2> <?php // If the user has just made a change to an group, display the status messages ?> <?php if (!empty($messages)) { ?> <div id="moderated" class="<?php echo !empty($_REQUEST['error']) ? 'error' : 'updated'; ?> "><p><?php echo implode("<br/>\n", $messages); ?> </p></div> <?php } ?> <?php // Display each group on its own row ?> <?php $bp_groups_list_table->views(); ?> <form id="bp-groups-form" action="" method="get"> <?php $bp_groups_list_table->search_box(__('Search all Groups', 'buddypress'), 'bp-groups'); ?> <input type="hidden" name="page" value="<?php echo esc_attr($plugin_page); ?> " /> <?php $bp_groups_list_table->display(); ?> </form> </div> <?php }
/** * Get the Create a Group button. * * @since BuddyPress (2.0.0) * * @return string */ function bp_get_group_create_button() { if (!is_user_logged_in()) { return false; } if (!bp_user_can_create_groups()) { return false; } $button_args = array('id' => 'create_group', 'component' => 'groups', 'link_text' => __('Create a Group', 'buddypress'), 'link_title' => __('Create a Group', 'buddypress'), 'link_class' => 'button group-create bp-title-button', 'link_href' => trailingslashit(bp_get_root_domain()) . trailingslashit(bp_get_groups_root_slug()) . trailingslashit('create'), 'wrapper' => false); return bp_get_button(apply_filters('bp_get_group_create_button', $button_args)); }
/** * Get the Create a Group button. * * @since 2.0.0 * * @return string */ function bp_get_group_create_button() { if (!is_user_logged_in()) { return false; } if (!bp_user_can_create_groups()) { return false; } $button_args = array('id' => 'create_group', 'component' => 'groups', 'link_text' => __('Create a Group', 'buddypress'), 'link_title' => __('Create a Group', 'buddypress'), 'link_class' => 'group-create no-ajax', 'link_href' => trailingslashit(bp_get_groups_directory_permalink() . 'create'), 'wrapper' => false, 'block_self' => false); /** * Filters the HTML button for creating a group. * * @since 2.0.0 * * @param string $button HTML button for creating a group. */ return bp_get_button(apply_filters('bp_get_group_create_button', $button_args)); }
<?php do_action('bp_before_directory_groups_page'); ?> <section id="grouptitle"> <div class="container"> <div class="row"> <div class="col-md-9 col-sm-8"> <div class="pagetitle"> <h1>Courses</h1> </div> </div> <div class="col-md-3 col-sm-4"> <?php if (is_user_logged_in() && bp_user_can_create_groups() && !newwriting_is_lurker()) { ?> <a class="button create-group-button full" href="<?php echo trailingslashit(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create'); ?> "><?php _e('Create a Course', 'vibe'); ?> </a> <?php } ?> </div> </div> </div>
/** * Check the current user's capability to edit an avatar for a given object. * * @since 2.3.0 * * @param string $capability The capability to check. * @param array $args An array containing the item_id and the object to check. * * @return bool */ function bp_attachments_current_user_can($capability, $args = array()) { $can = false; if ('edit_avatar' === $capability || 'edit_cover_image' === $capability) { /** * Needed avatar arguments are set. */ if (isset($args['item_id']) && isset($args['object'])) { // Group profile photo if (bp_is_active('groups') && 'group' === $args['object']) { if (bp_is_group_create()) { $can = (bool) groups_is_user_creator(bp_loggedin_user_id(), $args['item_id']) || bp_current_user_can('bp_moderate'); } else { $can = (bool) groups_is_user_admin(bp_loggedin_user_id(), $args['item_id']) || bp_current_user_can('bp_moderate'); } // User profile photo } elseif (bp_is_active('xprofile') && 'user' === $args['object']) { $can = bp_loggedin_user_id() === (int) $args['item_id'] || bp_current_user_can('bp_moderate'); } /** * No avatar arguments, fallback to bp_user_can_create_groups() * or bp_is_item_admin() */ } else { if (bp_is_group_create()) { $can = bp_user_can_create_groups(); } else { $can = bp_is_item_admin(); } } } return apply_filters('bp_attachments_current_user_can', $can, $capability, $args); }
/** * Set up the component entries in the WordPress Admin Bar. * * @see BP_Component::setup_nav() for a description of the $wp_admin_nav * parameter array. * * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a description. */ public function setup_admin_bar($wp_admin_nav = array()) { // Menus for logged in user. if (is_user_logged_in()) { // Setup the logged in user variables. $groups_link = trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug()); // Pending group invites. $count = groups_get_invite_count_for_user(); $title = _x('Groups', 'My Account Groups', 'buddypress'); $pending = _x('No Pending Invites', 'My Account Groups sub nav', 'buddypress'); if (!empty($count['total'])) { $title = sprintf(_x('Groups <span class="count">%s</span>', 'My Account Groups nav', 'buddypress'), bp_core_number_format($count)); $pending = sprintf(_x('Pending Invites <span class="count">%s</span>', 'My Account Groups sub nav', 'buddypress'), bp_core_number_format($count)); } // Add the "My Account" sub menus. $wp_admin_nav[] = array('parent' => buddypress()->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => $title, 'href' => $groups_link); // My Groups. $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-memberships', 'title' => _x('Memberships', 'My Account Groups sub nav', 'buddypress'), 'href' => $groups_link); // Invitations. $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-invites', 'title' => $pending, 'href' => trailingslashit($groups_link . 'invites')); // Create a Group. if (bp_user_can_create_groups()) { $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-create', 'title' => _x('Create a Group', 'My Account Groups sub nav', 'buddypress'), 'href' => trailingslashit(bp_get_groups_directory_permalink() . 'create')); } } parent::setup_admin_bar($wp_admin_nav); }
/** * Catch and process group creation form submissions. */ function groups_action_create_group() { global $bp; // If we're not at domain.org/groups/create/ then return false if (!bp_is_groups_component() || !bp_is_current_action('create')) { return false; } if (!is_user_logged_in()) { return false; } if (!bp_user_can_create_groups()) { bp_core_add_message(__('Sorry, you are not allowed to create groups.', 'buddypress'), 'error'); bp_core_redirect(trailingslashit(bp_get_root_domain() . '/' . bp_get_groups_root_slug())); } // Make sure creation steps are in the right order groups_action_sort_creation_steps(); // If no current step is set, reset everything so we can start a fresh group creation $bp->groups->current_create_step = bp_action_variable(1); if (!bp_get_groups_current_create_step()) { unset($bp->groups->current_create_step); unset($bp->groups->completed_create_steps); setcookie('bp_new_group_id', false, time() - 1000, COOKIEPATH); setcookie('bp_completed_create_steps', false, time() - 1000, COOKIEPATH); $reset_steps = true; $keys = array_keys($bp->groups->group_creation_steps); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . array_shift($keys) . '/'); } // If this is a creation step that is not recognized, just redirect them back to the first screen if (bp_get_groups_current_create_step() && empty($bp->groups->group_creation_steps[bp_get_groups_current_create_step()])) { bp_core_add_message(__('There was an error saving group details. Please try again.', 'buddypress'), 'error'); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/'); } // Fetch the currently completed steps variable if (isset($_COOKIE['bp_completed_create_steps']) && !isset($reset_steps)) { $bp->groups->completed_create_steps = json_decode(base64_decode(stripslashes($_COOKIE['bp_completed_create_steps']))); } // Set the ID of the new group, if it has already been created in a previous step if (isset($_COOKIE['bp_new_group_id'])) { $bp->groups->new_group_id = (int) $_COOKIE['bp_new_group_id']; $bp->groups->current_group = groups_get_group(array('group_id' => $bp->groups->new_group_id)); // Only allow the group creator to continue to edit the new group if (!bp_is_group_creator($bp->groups->current_group, bp_loggedin_user_id())) { bp_core_add_message(__('Only the group creator may continue editing this group.', 'buddypress'), 'error'); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/'); } } // If the save, upload or skip button is hit, lets calculate what we need to save if (isset($_POST['save'])) { // Check the nonce check_admin_referer('groups_create_save_' . bp_get_groups_current_create_step()); if ('group-details' == bp_get_groups_current_create_step()) { if (empty($_POST['group-name']) || empty($_POST['group-desc']) || !strlen(trim($_POST['group-name'])) || !strlen(trim($_POST['group-desc']))) { bp_core_add_message(__('Please fill in all of the required fields', 'buddypress'), 'error'); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/'); } $new_group_id = isset($bp->groups->new_group_id) ? $bp->groups->new_group_id : 0; if (!($bp->groups->new_group_id = groups_create_group(array('group_id' => $new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug(sanitize_title(esc_attr($_POST['group-name']))), 'date_created' => bp_core_current_time(), 'status' => 'public')))) { bp_core_add_message(__('There was an error saving group details, please try again.', 'buddypress'), 'error'); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/'); } } if ('group-settings' == bp_get_groups_current_create_step()) { $group_status = 'public'; $group_enable_forum = 1; if (!isset($_POST['group-show-forum'])) { $group_enable_forum = 0; } else { // Create the forum if enable_forum = 1 if (bp_is_active('forums') && !groups_get_groupmeta($bp->groups->new_group_id, 'forum_id')) { groups_new_group_forum(); } } if ('private' == $_POST['group-status']) { $group_status = 'private'; } else { if ('hidden' == $_POST['group-status']) { $group_status = 'hidden'; } } if (!($bp->groups->new_group_id = groups_create_group(array('group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum)))) { bp_core_add_message(__('There was an error saving group details, please try again.', 'buddypress'), 'error'); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/'); } // Set the invite status // Checked against a whitelist for security $allowed_invite_status = apply_filters('groups_allowed_invite_status', array('members', 'mods', 'admins')); $invite_status = !empty($_POST['group-invite-status']) && in_array($_POST['group-invite-status'], (array) $allowed_invite_status) ? $_POST['group-invite-status'] : 'members'; groups_update_groupmeta($bp->groups->new_group_id, 'invite_status', $invite_status); } if ('group-invites' === bp_get_groups_current_create_step()) { if (!empty($_POST['friends'])) { foreach ((array) $_POST['friends'] as $friend) { groups_invite_user(array('user_id' => $friend, 'group_id' => $bp->groups->new_group_id)); } } groups_send_invites(bp_loggedin_user_id(), $bp->groups->new_group_id); } do_action('groups_create_group_step_save_' . bp_get_groups_current_create_step()); do_action('groups_create_group_step_complete'); // Mostly for clearing cache on a generic action name /** * Once we have successfully saved the details for this step of the creation process * we need to add the current step to the array of completed steps, then update the cookies * holding the information */ $completed_create_steps = isset($bp->groups->completed_create_steps) ? $bp->groups->completed_create_steps : array(); if (!in_array(bp_get_groups_current_create_step(), $completed_create_steps)) { $bp->groups->completed_create_steps[] = bp_get_groups_current_create_step(); } // Reset cookie info setcookie('bp_new_group_id', $bp->groups->new_group_id, time() + 60 * 60 * 24, COOKIEPATH); setcookie('bp_completed_create_steps', base64_encode(json_encode($bp->groups->completed_create_steps)), time() + 60 * 60 * 24, COOKIEPATH); // If we have completed all steps and hit done on the final step we // can redirect to the completed group $keys = array_keys($bp->groups->group_creation_steps); if (count($bp->groups->completed_create_steps) == count($keys) && bp_get_groups_current_create_step() == array_pop($keys)) { unset($bp->groups->current_create_step); unset($bp->groups->completed_create_steps); // Once we compelete all steps, record the group creation in the activity stream. groups_record_activity(array('type' => 'created_group', 'item_id' => $bp->groups->new_group_id)); do_action('groups_group_create_complete', $bp->groups->new_group_id); bp_core_redirect(bp_get_group_permalink($bp->groups->current_group)); } else { /** * Since we don't know what the next step is going to be (any plugin can insert steps) * we need to loop the step array and fetch the next step that way. */ foreach ($keys as $key) { if ($key == bp_get_groups_current_create_step()) { $next = 1; continue; } if (isset($next)) { $next_step = $key; break; } } bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . $next_step . '/'); } } // Remove invitations if ('group-invites' === bp_get_groups_current_create_step() && !empty($_REQUEST['user_id']) && is_numeric($_REQUEST['user_id'])) { if (!check_admin_referer('groups_invite_uninvite_user')) { return false; } $message = __('Invite successfully removed', 'buddypress'); $error = false; if (!groups_uninvite_user((int) $_REQUEST['user_id'], $bp->groups->new_group_id)) { $message = __('There was an error removing the invite', 'buddypress'); $error = 'error'; } bp_core_add_message($message, $error); bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/group-invites/'); } // Group avatar is handled separately if ('group-avatar' == bp_get_groups_current_create_step() && isset($_POST['upload'])) { if (!isset($bp->avatar_admin)) { $bp->avatar_admin = new stdClass(); } if (!empty($_FILES) && isset($_POST['upload'])) { // Normally we would check a nonce here, but the group save nonce is used instead // Pass the file to the avatar upload handler if (bp_core_avatar_handle_upload($_FILES, 'groups_avatar_upload_dir')) { $bp->avatar_admin->step = 'crop-image'; // Make sure we include the jQuery jCrop file for image cropping add_action('wp_print_scripts', 'bp_core_add_jquery_cropper'); } } // If the image cropping is done, crop the image and save a full/thumb version if (isset($_POST['avatar-crop-submit']) && isset($_POST['upload'])) { // Normally we would check a nonce here, but the group save nonce is used instead if (!bp_core_avatar_handle_crop(array('object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']))) { bp_core_add_message(__('There was an error saving the group profile photo, please try uploading again.', 'buddypress'), 'error'); } else { bp_core_add_message(__('The group profile photo was uploaded successfully!', 'buddypress')); } } } bp_core_load_template(apply_filters('groups_template_create_group', 'groups/create')); }
/** * Set up the Toolbar * * @global BuddyPress $bp The one true BuddyPress instance */ public function setup_admin_bar($wp_admin_nav = array()) { global $bp; // Prevent debug notices $wp_admin_nav = array(); // Menus for logged in user if (is_user_logged_in()) { // Setup the logged in user variables $user_domain = bp_loggedin_user_domain(); $groups_link = trailingslashit($user_domain . $this->slug); // Pending group invites $count = groups_get_invites_for_user(bp_loggedin_user_id()); $title = __('Groups', 'buddypress'); $pending = __('No Pending Invites', 'buddypress'); if (!empty($count['total'])) { $title = sprintf(__('Groups <span class="count">%s</span>', 'buddypress'), $count['total']); $pending = sprintf(__('Pending Invites <span class="count">%s</span>', 'buddypress'), $count['total']); } // Add the "My Account" sub menus $wp_admin_nav[] = array('parent' => $bp->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => $title, 'href' => trailingslashit($groups_link)); // My Groups $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-memberships', 'title' => __('Memberships', 'buddypress'), 'href' => trailingslashit($groups_link)); // Invitations $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-invites', 'title' => $pending, 'href' => trailingslashit($groups_link . 'invites')); // Create a Group if (bp_user_can_create_groups()) { $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-create', 'title' => __('Create a Group', 'buddypress'), 'href' => trailingslashit(bp_get_groups_directory_permalink() . 'create')); } } parent::setup_admin_bar($wp_admin_nav); }
function display($page = 1) { global $bp, $groups_template; $parent_template = $groups_template; $hide_button = false; if (isset($_REQUEST['grpage'])) { $page = (int) $_REQUEST['grpage']; } else { if (!is_numeric($page)) { $page = 1; } else { $page = (int) $page; } } /** Respect BuddyPress group creation restriction */ if (function_exists('bp_user_can_create_groups')) { $hide_button = !bp_user_can_create_groups(); } bp_has_groups_hierarchy(array('type' => 'alphabetical', 'parent_id' => $bp->groups->current_group->id, 'page' => $page)); ?> <div class="group"> <?php if (($bp->is_item_admin || $bp->groups->current_group->can_create_subitems) && !$hide_button) { ?> <div class="generic-button group-button"> <a title="<?php printf(__('Create a %s', 'bp-group-hierarchy'), __('Member Group', 'bp-group-hierarchy')); ?> " href="<?php echo $bp->root_domain . '/' . bp_get_groups_root_slug() . '/' . 'create' . '/?parent_id=' . $bp->groups->current_group->id; ?> "><?php printf(__('Create a %s', 'bp-group-hierarchy'), __('Member Group', 'bp-group-hierarchy')); ?> </a> </div><br /><br /> <?php } ?> <?php if ($groups_template && count($groups_template->groups) > 0) { ?> <div id="pag-top" class="pagination"> <div class="pag-count" id="group-dir-count-top"> <?php bp_groups_pagination_count(); ?> </div> <div class="pagination-links" id="group-dir-pag-top"> <?php bp_groups_pagination_links(); ?> </div> </div> <ul id="groups-list" class="item-list"> <?php while (bp_groups()) { bp_the_group(); ?> <?php $subgroup = $groups_template->group; ?> <?php if ($subgroup->status == 'hidden' && !(groups_is_user_member($bp->loggedin_user->id, $subgroup->id) || groups_is_user_admin($bp->loggedin_user->id, $bp->groups->current_group->id))) { continue; } ?> <li id="tree-childof_<?php bp_group_id(); ?> "> <div class="item-avatar"> <a href="<?php bp_group_permalink(); ?> "><?php bp_group_avatar('type=thumb&width=50&height=50'); ?> </a> </div> <div class="item"> <div class="item-title"><a href="<?php bp_group_permalink(); ?> "><?php bp_group_name(); ?> </a></div> <div class="item-meta"><span class="activity"><?php printf(__('active %s', 'buddypress'), bp_get_group_last_active()); ?> </span></div> <div class="item-desc"><?php bp_group_description_excerpt(); ?> </div> <?php do_action('bp_directory_groups_item'); ?> </div> <div class="action"> <?php do_action('bp_directory_groups_actions'); ?> <div class="meta"> <?php bp_group_type(); ?> / <?php bp_group_member_count(); ?> </div> </div> <div class="clear"></div> </li> <?php } ?> </ul> <div id="pag-bottom" class="pagination"> <div class="pag-count" id="group-dir-count-bottom"> <?php bp_groups_pagination_count(); ?> </div> <div class="pagination-links" id="group-dir-pag-bottom"> <?php bp_groups_pagination_links(); ?> </div> </div> <script type="text/javascript"> jQuery('#nav-hierarchy-personal-li').attr('id','group-hierarchy-personal-li'); jQuery('#nav-hierarchy-groups-li').attr('id','group-hierarchy-group-li'); </script> <?php } else { ?> <p><?php _e('No member groups were found.', 'bp-group-hierarchy'); ?> </p> <?php } ?> </div> <?php // reset the $groups_template global and continue with the page $groups_template = $parent_template; }
/** * Update the global $post with create screen data * * @since BuddyPress (1.7) */ public function create_dummy_post() { // Title based on ability to create groups if (is_user_logged_in() && bp_user_can_create_groups()) { $title = '<a class="button" href="' . trailingslashit(bp_get_root_domain() . '/' . bp_get_groups_root_slug()) . '">' . __('Groups', 'buddypress') . '</a> ' . __('Create a Group', 'buddypress'); } else { $title = __('Groups', 'buddypress'); } bp_theme_compat_reset_post(array('ID' => 0, 'post_title' => $title, 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => 'bp_group', 'post_status' => 'publish', 'is_archive' => true, 'comment_status' => 'closed')); }
function bp_group_create_get_output() { if (!bp_user_can_create_groups()) { return false; } $this->_show_group_maps_admin_body(); }