/** * Edit the base details for a group. * * These are the settings that appear on the Settings page of the group's Admin * section (privacy settings, "enable forum", invitation status). * * @param int $group_id ID of the group. * @param bool $enable_forum Whether to enable a forum for the group. * @param string $status Group status. 'public', 'private', 'hidden'. * @param string|bool $invite_status Optional. Who is allowed to send invitations * to the group. 'members', 'mods', or 'admins'. * * @return bool True on success, false on failure. */ function groups_edit_group_settings($group_id, $enable_forum, $status, $invite_status = false) { $group = groups_get_group(array('group_id' => $group_id)); $group->enable_forum = $enable_forum; /*** * Before we potentially switch the group status, if it has been changed to public * from private and there are outstanding membership requests, auto-accept those requests. */ if ('private' == $group->status && 'public' == $status) { groups_accept_all_pending_membership_requests($group->id); } // Now update the status $group->status = $status; if (!$group->save()) { return false; } // If forums have been enabled, and a forum does not yet exist, we need to create one. if ($group->enable_forum) { if (bp_is_active('forums') && !groups_get_groupmeta($group->id, 'forum_id')) { groups_new_group_forum($group->id, $group->name, $group->description); } } // Set the invite status if ($invite_status) { groups_update_groupmeta($group->id, 'invite_status', $invite_status); } groups_update_groupmeta($group->id, 'last_activity', bp_core_current_time()); /** * Fires after the update of a groups settings. * * @since 1.0.0 * * @param int $id ID of the group that was updated. */ do_action('groups_settings_updated', $group->id); return true; }
function bpdd_import_groups($users = false) { $groups = array(); $group_ids = array(); if (empty($users)) { $users = get_users(); } require dirname(__FILE__) . '/data/groups.php'; foreach ($groups as $group) { $cur = groups_create_group(array('creator_id' => $users[array_rand($users)]->ID, 'name' => $group['name'], 'description' => $group['description'], 'slug' => groups_check_slug(sanitize_title(esc_attr($group['name']))), 'status' => $group['status'], 'date_created' => bpdd_get_random_date(30, 5), 'enable_forum' => $group['enable_forum'])); groups_update_groupmeta($cur, 'total_member_count', 1); groups_update_groupmeta($cur, 'last_activity', bpdd_get_random_date(10)); // create forums if Forum Component is active if (bp_is_active('forums') && bp_forums_is_installed_correctly()) { groups_new_group_forum($cur, $group['name'], $group['description']); } $group_ids[] = $cur; } return $group_ids; }
/** * 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')); }
function bp_group_organizer_import_group($group, $args = array()) { if (empty($group['name'])) { return false; } if (isset($group['path'])) { if (bpgo_is_hierarchy_available()) { // Try to place the group in the requested spot, but if the spot doesn't exist (e.g. because of slug conflicts) // then place it as far down the tree as possible $parent_path = $group['path']; do { $parent_path = dirname($parent_path); $parent_id = BP_Groups_Hierarchy::get_id_from_slug($parent_path); } while ($parent_path != '.' && $parent_id == 0); $group['parent_id'] = $parent_id ? $parent_id : 0; } $group['slug'] = basename($group['path']); unset($group['path']); } $group['slug'] = groups_check_slug($group['slug']); $group_id = groups_create_group($group); if (!$group_id) { return false; } groups_update_groupmeta($group_id, 'total_member_count', 1); if (bpgo_is_hierarchy_available()) { $obj_group = new BP_Groups_Hierarchy($group_id); $obj_group->parent_id = (int) $group['parent_id']; $obj_group->save(); } // Create the forum if enable_forum is checked if ($group['enable_forum']) { // Ensure group forums are activated, and group does not already have a forum if (bp_is_active('forums')) { // Check for BuddyPress group forums if (!groups_get_groupmeta($group_id, 'forum_id')) { groups_new_group_forum($group_id, $group['name'], $group['description']); } } else { if (function_exists('bbp_is_group_forums_active') && bbp_is_group_forums_active()) { // Check for bbPress group forums if (count(bbp_get_group_forum_ids($group_id)) == 0) { // Create the group forum - implementation from BBP_Forums_Group_Extension:create_screen_save // Set the default forum status switch ($group['status']) { case 'hidden': $status = bbp_get_hidden_status_id(); break; case 'private': $status = bbp_get_private_status_id(); break; case 'public': default: $status = bbp_get_public_status_id(); break; } // Create the initial forum $forum_id = bbp_insert_forum(array('post_parent' => bbp_get_group_forums_root_id(), 'post_title' => $group['name'], 'post_content' => $group['description'], 'post_status' => $status)); bbp_add_forum_id_to_group($group_id, $forum_id); bbp_add_group_id_to_forum($forum_id, $group_id); } } } } do_action('bp_group_organizer_import_group', $group_id); return $group_id; }
function groups_edit_group_settings( $group_id, $enable_forum, $status ) { global $bp; $group = new BP_Groups_Group( $group_id ); $group->enable_forum = $enable_forum; /*** * Before we potentially switch the group status, if it has been changed to public * from private and there are outstanding membership requests, auto-accept those requests. */ if ( 'private' == $group->status && 'public' == $status ) groups_accept_all_pending_membership_requests( $group->id ); /* Now update the status */ $group->status = $status; if ( !$group->save() ) return false; /* If forums have been enabled, and a forum does not yet exist, we need to create one. */ if ( $group->enable_forum ) { if ( function_exists( 'bp_forums_setup' ) && '' == groups_get_groupmeta( $group->id, 'forum_id' ) ) { groups_new_group_forum( $group->id, $group->name, $group->description ); } } groups_update_groupmeta( $group->id, 'last_activity', gmdate( "Y-m-d H:i:s" ) ); do_action( 'groups_settings_updated', $group->id ); return true; }
function bp_group_organizer_admin_page() { global $wpdb; // Permissions Check if (!current_user_can('manage_options')) { wp_die(__('Cheatin’ uh?')); } // Load all the nav menu interface functions require_once 'includes/group-meta-boxes.php'; require_once 'includes/group-organizer-template.php'; require_once 'includes/group-organizer.php'; // Container for any messages displayed to the user $messages = array(); // Container that stores the name of the active menu $nav_menu_selected_title = ''; // Allowed actions: add, update, delete $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'edit'; $errored = false; switch ($action) { case 'add-group': check_admin_referer('add-group', 'group-settings-column-nonce'); $group['name'] = stripslashes($_POST['group_name']); $group['description'] = stripslashes($_POST['group_desc']); $group['slug'] = groups_check_slug($_POST['group_slug']); $group['status'] = $_POST['group_status']; $group['enable_forum'] = isset($_POST['group_forum']) ? true : false; $group['date_created'] = date('Y-m-d H:i:s'); if ($group['slug'] != $_POST['group_slug']) { $messages[] = '<div class="updated warning"><p>' . sprintf(__('The group slug you specified was unavailable or invalid. This group was created with the slug: <code>%s</code>.', 'bp-group-organizer'), $group['slug']) . '</p></div>'; } if (empty($group['name'])) { $messages[] = '<div class="error"><p>' . __('Group could not be created because one or more required fields were not filled in', 'bp-group-organizer') . '</p></div>'; $errored = true; } if (!$errored) { $group_id = groups_create_group($group); if (!$group_id) { $wpdb->show_errors(); $wpdb->print_error(); $messages[] = '<div class="error"><p>' . __('Group was not successfully created.', 'bp-group-organizer') . '</p></div>'; } else { $messages[] = '<div class="updated"><p>' . __('Group was created successfully.', 'bp-group-organizer') . '</p></div>'; } } if (!empty($group_id)) { groups_update_groupmeta($group_id, 'total_member_count', 1); if (bpgo_is_hierarchy_available()) { $obj_group = new BP_Groups_Hierarchy($group_id); $obj_group->parent_id = (int) $_POST['group_parent']; $obj_group->save(); } // Create the forum if enable_forum is checked if ($group['enable_forum']) { // Ensure group forums are activated, and group does not already have a forum if (bp_is_active('forums')) { // Check for BuddyPress group forums if (!groups_get_groupmeta($group_id, 'forum_id')) { groups_new_group_forum($group_id, $group['name'], $group['description']); } } else { if (function_exists('bbp_is_group_forums_active') && bbp_is_group_forums_active()) { // Check for bbPress group forums if (count(bbp_get_group_forum_ids($group_id)) == 0) { // Create the group forum - implementation from BBP_Forums_Group_Extension:create_screen_save // Set the default forum status switch ($group['status']) { case 'hidden': $status = bbp_get_hidden_status_id(); break; case 'private': $status = bbp_get_private_status_id(); break; case 'public': default: $status = bbp_get_public_status_id(); break; } // Create the initial forum $forum_id = bbp_insert_forum(array('post_parent' => bbp_get_group_forums_root_id(), 'post_title' => $group['name'], 'post_content' => $group['description'], 'post_status' => $status)); bbp_add_forum_id_to_group($group_id, $forum_id); bbp_add_group_id_to_forum($forum_id, $group_id); } } } } do_action('bp_group_organizer_save_new_group_options', $group_id); } break; case 'delete-group': $group_id = (int) $_REQUEST['group_id']; check_admin_referer('delete-group_' . $group_id); break; case 'update': check_admin_referer('update-groups', 'update-groups-nonce'); $groups_order = $_POST['group']; $parent_ids = $_POST['menu-item-parent-id']; $db_ids = $_POST['menu-item-db-id']; foreach ($groups_order as $id => $group) { $group_reference = new BP_Groups_Group($id); if (defined('BP_GROUP_HIERARCHY_IS_INSTALLED') && method_exists('BP_Groups_Hierarchy', 'get_tree')) { // if group hierarchy is installed and available, check for tree changes $group_hierarchy = new BP_Groups_Hierarchy($id); if ($parent_ids[$id] !== null && $group_hierarchy->parent_id != $parent_ids[$id]) { $group_hierarchy->parent_id = $parent_ids[$id]; $group_hierarchy->save(); } else { if ($group_hierarchy->parent_id != $group['parent_id']) { $group_hierarchy->parent_id = $group['parent_id']; $group_hierarchy->save(); } } unset($group_hierarchy); } // check for group attribute changes $attrs_changed = array(); if ($group['name'] != $group_reference->name) { $group_reference->name = stripslashes($group['name']); $attrs_changed[] = 'name'; } if ($group['slug'] != $group_reference->slug) { $slug = groups_check_slug($group['slug']); if ($slug == $group['slug']) { $group_reference->slug = $group['slug']; $attrs_changed[] = 'slug'; } } if ($group['description'] != $group_reference->description) { $group_reference->description = stripslashes($group['description']); $attrs_changed[] = 'description'; } if ($group['status'] != $group_reference->status && groups_is_valid_status($group['status'])) { $group_reference->status = $group['status']; $attrs_changed[] = 'status'; } if (!isset($group['forum_enabled']) || $group['forum_enabled'] != $group_reference->enable_forum) { $group_reference->enable_forum = isset($group['forum_enabled']) ? true : false; $attrs_changed[] = 'enable_forum'; } if (count($attrs_changed) > 0) { $group_reference->save(); } // finally, let plugins run any other changes do_action('group_details_updated', $group_reference->id); do_action('bp_group_organizer_save_group_options', $group, $group_reference); } break; case 'import': if (!isset($_FILES['import_groups'])) { // No files was uploaded } if (!is_uploaded_file($_FILES['import_groups']['tmp_name'])) { // Not an uploaded file $errors = array(UPLOAD_ERR_OK => sprintf(__('File uploaded successfully, but there is a problem. (%d)', 'bp-group-organizer'), UPLOAD_ERR_OK), UPLOAD_ERR_INI_SIZE => sprintf(__('File exceeded PHP\'s maximum upload size. (%d)', 'bp-group-organizer'), UPLOAD_ERR_INI_SIZE), UPLOAD_ERR_FORM_SIZE => sprintf(__('File exceeded the form\'s maximum upload size. (%d)', 'bp-group-organizer'), UPLOAD_ERR_FORM_SIZE), UPLOAD_ERR_PARTIAL => sprintf(__('File was only partially uploaded. (%d)', 'bp-group-organizer'), UPLOAD_ERR_PARTIAL), UPLOAD_ERR_NO_FILE => sprintf(__('No uploaded file was found. (%d)', 'bp-group-organizer'), UPLOAD_ERR_NO_FILE), 6 => sprintf(__('No temporary folder could be found for the uploaded file. (%d)', 'bp-group-organizer'), 6), 7 => sprintf(__('Could not write uploaded file to disk. (%d)', 'bp-group-organizer'), 7), 8 => sprintf(__('Upload was stopped by a PHP extension. (%d)', 'bp-group-organizer'), 8)); $messages[] = '<div class="error"><p>' . sprintf(__('', 'bp-group-organizer'), $errors[$_FILES['import_groups']['error']]) . '</p></div>'; break; } require_once dirname(__FILE__) . '/includes/group-organizer-import.php'; if ($result = bp_group_organizer_import_csv_file($_FILES['import_groups']['tmp_name'], $_POST['import'])) { $messages[] = '<div class="updated"><p>' . implode('<br />', $result) . '</p></div>'; } else { $messages[] = '<div class="error"><p>' . 'ERROR - IMPORT FAILED COMPLETELY' . '</p></div>'; } break; } // Ensure the user will be able to scroll horizontally // by adding a class for the max menu depth. global $_wp_nav_menu_max_depth; $_wp_nav_menu_max_depth = 0; if (isset($_REQUEST['screen']) && $_REQUEST['screen'] == 'import') { $action = 'import'; } else { $action = 'organize'; } if ($action == 'import') { $edit_markup = bp_group_organizer_import_export_page(); } else { $edit_markup = bp_get_groups_to_edit(); } ?> <div class="wrap"> <h2><?php esc_html_e('Group Organizer'); ?> </h2> <?php foreach ($messages as $message) { echo $message . "\n"; } ?> <div <?php if ($action == 'organize') { echo 'id="nav-menus-frame"'; } ?> > <div id="menu-settings-column" class="metabox-holder nav-menus-php"> <form id="group-organizer-meta" action="" class="group-organizer-meta" method="post" enctype="multipart/form-data"> <input type="hidden" name="action" value="add-group" /> <?php wp_nonce_field('add-group', 'group-settings-column-nonce'); ?> <?php if ($action == 'organize') { do_meta_boxes('group-organizer', 'side', null); } ?> </form> </div><!-- /#menu-settings-column --> <div id="menu-management-liquid"> <div id="menu-management" class="nav-menus-php"> <div class="nav-tabs-wrapper"> <div class="nav-tabs"> <a href="<?php echo esc_url(remove_query_arg(array('screen'))); ?> " class="nav-tab <?php if ($action == 'organize') { echo 'nav-tab-active'; } ?> "> <?php printf('<abbr title="%s">%s</abbr>', esc_html__('Drag and drop your groups', 'bp-group-hierarchy'), __('Organize', 'bp-group-organizer')); ?> </a> <a href="<?php echo esc_url(add_query_arg(array('screen' => 'import'))); ?> " class="nav-tab <?php if ($action == 'import') { echo 'nav-tab-active'; } ?> "> <?php printf('<abbr title="%s">%s</abbr>', esc_html__('Import or export groups in bulk', 'bp-group-organizer'), __('Import / Export', 'bp-group-organizer')); ?> </a> </div> </div> <div class="menu-edit"> <?php if ($action == 'organize') { ?> <form id="update-nav-menu" action="" method="post" enctype="multipart/form-data"> <?php } ?> <div id="nav-menu-header"> <div id="submitpost" class="submitbox"> <div class="major-publishing-actions"> <label class="menu-name-label howto open-label" for="menu-name"> <span><?php _e('Group Organizer', 'bp-group-organizer'); ?> </span> </label> <div class="publishing-action"> <?php if ($action == 'organize') { submit_button(__('Save Groups', 'bp-group-organizer'), 'button-primary menu-save', 'save_menu', false, array('id' => 'save_menu_header')); } ?> </div><!-- END .publishing-action --> </div><!-- END .major-publishing-actions --> </div><!-- END #submitpost .submitbox --> <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); wp_nonce_field('update-groups', 'update-groups-nonce'); ?> <input type="hidden" name="action" value="update" /> </div><!-- END #nav-menu-header --> <div id="post-body"> <div id="post-body-content"> <?php if (isset($edit_markup)) { if (!is_wp_error($edit_markup)) { echo $edit_markup; } } else { echo '<div class="post-body-plain">'; echo '<p>' . __('You don\'t yet have any groups.', 'bp-group-organizer') . '</p>'; echo '</div>'; } ?> </div><!-- /#post-body-content --> </div><!-- /#post-body --> <div id="nav-menu-footer"> <div class="major-publishing-actions"> <div class="publishing-action"> <?php if ($action == 'organize') { submit_button(__('Save Groups', 'bp-group-organizer'), 'button-primary menu-save', 'save_menu', false, array('id' => 'save_menu_header')); } ?> </div> </div> </div><!-- /#nav-menu-footer --> <?php if ($action == 'organize') { ?> </form><!-- /#update-nav-menu --> <?php } ?> </div><!-- /.menu-edit --> </div><!-- /#menu-management --> </div><!-- /#menu-management-liquid --> </div><!-- /#nav-menus-frame --> </div><!-- /.wrap--> <?php }
function groups_edit_group_settings($group_id, $enable_wire, $enable_forum, $enable_photos, $photos_admin_only, $status) { global $bp; /* Check the nonce first. */ if (!check_admin_referer('groups_edit_group_settings')) { return false; } $group = new BP_Groups_Group($group_id, false, false); $group->enable_wire = $enable_wire; $group->enable_forum = $enable_forum; $group->enable_photos = $enable_photos; $group->photos_admin_only = $photos_admin_only; $group->status = $status; if (!$group->save()) { return false; } /* If forums have been enabled, and a forum does not yet exist, we need to create one. */ if ($group->enable_forum) { if (function_exists('bp_forums_setup') && '' == groups_get_groupmeta($group->id, 'forum_id')) { groups_new_group_forum($group->id, $group->name, $group->description); } } do_action('groups_settings_updated', $group->id); return true; }
function bp_ning_import_get_discussion_groups() { global $wpdb; $ning_id_array = get_option('bp_ning_user_array'); // Get list of Ning groups for cross reference $groups = bp_ning_import_prepare_json('groups'); $ning_group_id_array = get_option('bp_ning_group_array', array()); // Loop through each discussion. If the topic doesn't have a corresponding group, create one. Then insert the forum items. $discussions = bp_ning_import_prepare_json('discussions'); $counter = 0; foreach ((array) $discussions as $discussion_key => $discussion) { if (!isset($discussion->category)) { continue; } $ning_group_id = $discussion->category; if (isset($ning_group_id_array[$ning_group_id])) { continue; } // todo - what if a topic has no group and no category $slug = sanitize_title(esc_attr($discussion->category)); $ning_group_creator_id = $discussion->contributorName; $creator_id = $ning_id_array[$ning_group_creator_id]; $ndate = strtotime($discussion->createdDate); $date_created = date("Y-m-d H:i:s", $ndate); if (!($group_id = BP_Groups_Group::group_exists($slug))) { $args = array('creator_id' => $creator_id, 'name' => $discussion->category, 'description' => $discussion->category, 'slug' => groups_check_slug($slug), 'status' => 'public', 'enable_forum' => 1, 'date_created' => $date_created); if ($group_id = groups_create_group($args)) { groups_update_groupmeta($group_id, 'last_activity', $date_created); groups_update_groupmeta($group_id, 'total_member_count', 1); groups_new_group_forum($group_id, $discussion->category, $discussion->category); echo "<strong>Created group: {$discussion->category}</strong><br />"; $ning_group_id_array[$ning_group_id] = $group_id; update_option('bp_ning_group_array', $ning_group_id_array); } } else { echo "<strong>Group already exists: {$discussion->category}</strong><br />"; $ning_group_id_array[$ning_group_id] = $group_id; update_option('bp_ning_group_array', $ning_group_id_array); } } }