本文整理汇总了PHP中BP_Groups_Group::save方法的典型用法代码示例。如果您正苦于以下问题:PHP BP_Groups_Group::save方法的具体用法?PHP BP_Groups_Group::save怎么用?PHP BP_Groups_Group::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BP_Groups_Group
的用法示例。
在下文中一共展示了BP_Groups_Group::save方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: foreach
function update_object($group_id, $fields)
{
$group = new BP_Groups_Group($group_id);
foreach ($fields as $field_name => $value) {
if (isset($group->field_name)) {
$group->field_name = $value;
}
}
$group->save();
return $group;
}
示例2: save
function save()
{
global $bp, $wpdb;
$this->slug = $this->true_slug;
parent::save();
if ($this->id) {
$sql = $wpdb->prepare("UPDATE {$bp->groups->table_name} SET\r\n\t\t\t\t\tparent_id = %d\r\n\t\t\t\tWHERE\r\n\t\t\t\t\tid = %d\r\n\t\t\t\t", $this->parent_id, $this->id);
if (false === $wpdb->query($sql)) {
return false;
}
if (!$this->id) {
$this->id = $wpdb->insert_id;
}
$this->path = $this->buildPath();
$this->slug = $this->path;
return true;
}
return false;
}
示例3: save
function save()
{
global $bp, $wpdb;
$this->slug = $this->true_slug;
parent::save();
if ($this->id) {
do_action_ref_array('bp_group_hierarchy_before_save', array(&$this));
$sql = $wpdb->prepare("UPDATE {$bp->groups->table_name} SET\r\n\t\t\t\t\tparent_id = %d\r\n\t\t\t\tWHERE\r\n\t\t\t\t\tid = %d\r\n\t\t\t\t", $this->parent_id, $this->id);
if (false === $wpdb->query($sql)) {
return false;
}
if (!$this->id) {
$this->id = $wpdb->insert_id;
}
$this->path = $this->buildPath();
$this->slug = $this->path;
do_action_ref_array('bp_group_hierarchy_after_save', array(&$this));
return true;
}
return false;
}
示例4: groups_create_group
/**
* Create a group.
*
* @since 1.0.0
*
* @param array|string $args {
* An array of arguments.
* @type int|bool $group_id Pass a group ID to update an existing item, or
* 0 / false to create a new group. Default: 0.
* @type int $creator_id The user ID that creates the group.
* @type string $name The group name.
* @type string $description Optional. The group's description.
* @type string $slug The group slug.
* @type string $status The group's status. Accepts 'public', 'private' or
'hidden'. Defaults to 'public'.
* @type int $enable_forum Optional. Whether the group has a forum enabled.
* If the legacy forums are enabled for this group
* or if a bbPress forum is enabled for the group,
* set this to 1. Default: 0.
* @type string $date_created The GMT time, in Y-m-d h:i:s format, when the group
* was created. Defaults to the current time.
* }
* @return int|bool The ID of the group on success. False on error.
*/
function groups_create_group($args = '')
{
$defaults = array('group_id' => 0, 'creator_id' => 0, 'name' => '', 'description' => '', 'slug' => '', 'status' => 'public', 'enable_forum' => 0, 'date_created' => bp_core_current_time());
$args = wp_parse_args($args, $defaults);
extract($args, EXTR_SKIP);
// Pass an existing group ID
if (!empty($group_id)) {
$group = groups_get_group(array('group_id' => (int) $group_id));
$name = !empty($name) ? $name : $group->name;
$slug = !empty($slug) ? $slug : $group->slug;
$description = !empty($description) ? $description : $group->description;
// Groups need at least a name
if (empty($name)) {
return false;
}
// Create a new group
} else {
// Instantiate new group object
$group = new BP_Groups_Group();
}
// Set creator ID
if ($creator_id) {
$group->creator_id = (int) $creator_id;
} elseif (is_user_logged_in()) {
$group->creator_id = bp_loggedin_user_id();
}
if (!$group->creator_id) {
return false;
}
// Validate status
if (!groups_is_valid_status($status)) {
return false;
}
// Set group name
$group->name = $name;
$group->description = $description;
$group->slug = $slug;
$group->status = $status;
$group->enable_forum = (int) $enable_forum;
$group->date_created = $date_created;
// Save group
if (!$group->save()) {
return false;
}
// If this is a new group, set up the creator as the first member and admin
if (empty($group_id)) {
$member = new BP_Groups_Member();
$member->group_id = $group->id;
$member->user_id = $group->creator_id;
$member->is_admin = 1;
$member->user_title = __('Group Admin', 'buddypress');
$member->is_confirmed = 1;
$member->date_modified = bp_core_current_time();
$member->save();
/**
* Fires after the creation of a new group and a group creator needs to be made.
*
* @since 1.5.0
*
* @param int $id ID of the newly created group.
* @param BP_Groups_Member $member Instance of the member who is assigned
* as group creator.
* @param BP_Groups_Group $group Instance of the group being created.
*/
do_action('groups_create_group', $group->id, $member, $group);
} else {
/**
* Fires after the update of a group.
*
* @since 1.5.0
*
* @param int $id ID of the updated group.
* @param BP_Groups_Group $group Instance of the group being updated.
*/
do_action('groups_update_group', $group->id, $group);
}
//.........这里部分代码省略.........
示例5: test_save_clear_cache
/**
* @group save
* @group cache
*/
public function test_save_clear_cache()
{
$g = $this->factory->group->create();
// Prime cache
groups_get_group(array('group_id' => $g));
$this->assertNotEmpty(wp_cache_get($g, 'bp_groups'));
$group = new BP_Groups_Group($g);
$group->name = 'Foo';
$group->save();
$this->assertFalse(wp_cache_get($g, 'bp_groups'));
}
示例6: groups_create_group
function groups_create_group($args = '')
{
extract($args);
/**
* Possible parameters (pass as assoc array):
* 'group_id'
* 'creator_id'
* 'name'
* 'description'
* 'slug'
* 'status'
* 'enable_forum'
* 'date_created'
*/
if (!empty($group_id)) {
$group = groups_get_group(array('group_id' => $group_id));
} else {
$group = new BP_Groups_Group();
}
if (!empty($creator_id)) {
$group->creator_id = $creator_id;
} else {
$group->creator_id = bp_loggedin_user_id();
}
if (isset($name)) {
$group->name = $name;
}
if (isset($description)) {
$group->description = $description;
}
if (isset($slug) && groups_check_slug($slug)) {
$group->slug = $slug;
}
if (isset($status)) {
if (groups_is_valid_status($status)) {
$group->status = $status;
}
}
if (isset($enable_forum)) {
$group->enable_forum = $enable_forum;
} else {
if (empty($group_id) && !isset($enable_forum)) {
$group->enable_forum = 1;
}
}
if (isset($date_created)) {
$group->date_created = $date_created;
}
if (!$group->save()) {
return false;
}
// If this is a new group, set up the creator as the first member and admin
if (empty($group_id)) {
$member = new BP_Groups_Member();
$member->group_id = $group->id;
$member->user_id = $group->creator_id;
$member->is_admin = 1;
$member->user_title = __('Group Admin', 'buddypress');
$member->is_confirmed = 1;
$member->date_modified = bp_core_current_time();
$member->save();
groups_update_groupmeta($group->id, 'last_activity', bp_core_current_time());
do_action('groups_create_group', $group->id, $member, $group);
} else {
do_action('groups_update_group', $group->id, $group);
}
do_action('groups_created_group', $group->id, $group);
return $group->id;
}
示例7: groups_create_group
/**
* Create a group.
*
* @since BuddyPress (1.0.0)
*
* @param array $args {
* An array of arguments.
* @type int|bool $group_id Pass a group ID to update an existing item, or
* 0 / false to create a new group. Default: 0.
* @type int $creator_id The user ID that creates the group.
* @type string $name The group name.
* @type string $description Optional. The group's description.
* @type string $slug The group slug.
* @type string $status The group's status. Accepts 'public', 'private' or
'hidden'. Defaults to 'public'.
* @type int $enable_forum Optional. Whether the group has a forum enabled.
* If the legacy forums are enabled for this group or if a bbPress
* forum is enabled for the group, set this to 1. Default: 0.
* @type string $date_created The GMT time, in Y-m-d h:i:s format,
* when the group was created. Defaults to the current time.
* }
* @return int|bool The ID of the group on success. False on error.
*/
function groups_create_group($args = '')
{
$defaults = array('group_id' => 0, 'creator_id' => 0, 'name' => '', 'description' => '', 'slug' => '', 'status' => 'public', 'enable_forum' => 0, 'date_created' => bp_core_current_time());
$args = wp_parse_args($args, $defaults);
extract($args, EXTR_SKIP);
// Pass an existing group ID
if (!empty($group_id)) {
$group = groups_get_group(array('group_id' => (int) $group_id));
$name = !empty($name) ? $name : $group->name;
$slug = !empty($slug) ? $slug : $group->slug;
$description = !empty($description) ? $description : $group->description;
// Groups need at least a name
if (empty($name)) {
return false;
}
// Create a new group
} else {
// Instantiate new group object
$group = new BP_Groups_Group();
}
// Set creator ID
if ($creator_id) {
$group->creator_id = (int) $creator_id;
} elseif (is_user_logged_in()) {
$group->creator_id = bp_loggedin_user_id();
}
if (!$group->creator_id) {
return false;
}
// Validate status
if (!groups_is_valid_status($status)) {
return false;
}
// Set group name
$group->name = $name;
$group->description = $description;
$group->slug = $slug;
$group->status = $status;
$group->enable_forum = (int) $enable_forum;
$group->date_created = $date_created;
// Save group
if (!$group->save()) {
return false;
}
// If this is a new group, set up the creator as the first member and admin
if (empty($group_id)) {
$member = new BP_Groups_Member();
$member->group_id = $group->id;
$member->user_id = $group->creator_id;
$member->is_admin = 1;
$member->user_title = __('Group Admin', 'buddypress');
$member->is_confirmed = 1;
$member->date_modified = bp_core_current_time();
$member->save();
groups_update_groupmeta($group->id, 'last_activity', bp_core_current_time());
do_action('groups_create_group', $group->id, $member, $group);
} else {
do_action('groups_update_group', $group->id, $group);
}
do_action('groups_created_group', $group->id, $group);
return $group->id;
}
示例8: groups_edit_group_settings
function groups_edit_group_settings($group_id, $enable_forum, $status, $invite_status = false)
{
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 (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());
do_action('groups_settings_updated', $group->id);
return true;
}
示例9: groups_edit_group_settings
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;
}
示例10: bp_group_organizer_admin_page
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')) {
//.........这里部分代码省略.........
示例11: demodata_create_group
function demodata_create_group($groupname, $num)
{
// set up the new group
$group_obj = new BP_Groups_Group();
$group_obj->name = $groupname;
$group_obj->slug = sanitize_title($groupname);
$group_obj->description = "Demo group " . $num . " created by Demo Data Creator plugin.";
$group_obj->status = 'public';
$group_obj->is_invitation_only = 0;
$group_obj->enable_wire = 1;
$group_obj->enable_forum = 1;
$group_obj->enable_photos = 1;
$group_obj->photos_admin_only = 0;
$group_obj->date_created = time();
// save the group
$saved = $group_obj->save();
if ($saved) {
return $group_obj->id;
} else {
return false;
}
}
示例12: groups_edit_group_settings
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;
}
示例13: test_wp_idea_stream_groups_member_banned_hidden_group
/**
* @group remove_from_group
*/
public function test_wp_idea_stream_groups_member_banned_hidden_group()
{
$bp = buddypress();
$group = new BP_Groups_Group($this->group_id);
$group->status = 'hidden';
$group->save();
// Set current group
$bp->groups->current_group = groups_get_group(array('group_id' => $this->group_id, 'populate_extras' => true));
$u = $this->factory->user->create();
groups_join_group($this->group_id, $u);
$idea1 = $this->factory->idea->create(array('author' => $u, 'metas' => array('group_id' => $this->group_id), 'status' => 'private'));
$idea2 = $this->factory->idea->create(array('author' => $u, 'metas' => array('group_id' => $this->group_id), 'status' => 'private'));
$bp->is_item_admin = true;
groups_ban_member($u, $this->group_id);
// Check metas
$this->assertEmpty(wp_idea_stream_ideas_get_meta($idea1, 'group_id'));
$this->assertEmpty(wp_idea_stream_ideas_get_meta($idea2, 'group_id'));
$ideas = wp_idea_stream_ideas_get_ideas(array('include' => array($idea1, $idea2)));
$public_ideas = wp_filter_object_list($ideas['ideas'], array('post_status' => 'publish'), 'and', 'ID');
$this->assertEqualSets(array($idea1, $idea2), $public_ideas, 'When a member is banned from the group, ideas should always be public');
// Reset item admin
$bp->is_item_admin = false;
}
示例14: edit_screen_save
/**
* Save the Group Forum data on edit
*
* @since bbPress (r3465)
* @uses bbp_new_forum_handler() To check for forum creation
* @uses bbp_edit_forum_handler() To check for forum edit
*/
public function edit_screen_save()
{
// Bail if not a POST action
if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
return;
}
check_admin_referer('groups_edit_save_' . $this->slug);
$edit_forum = !empty($_POST['bbp-edit-group-forum']) ? true : false;
$forum_id = 0;
$group_id = bp_get_current_group_id();
$forum_ids = array_values(bbp_get_group_forum_ids($group_id));
// Normalize group forum relationships now
if (!empty($forum_ids)) {
// Loop through forums, and make sure they exist
foreach ($forum_ids as $forum_id) {
// Look for forum
$forum = bbp_get_forum($forum_id);
// No forum exists, so break the relationship
if (empty($forum)) {
$this->remove_forum(array('forum_id' => $forum_id));
unset($forum_ids[$forum_id]);
}
}
// No support for multiple forums yet
$forum_id = (int) (is_array($forum_ids) ? $forum_ids[0] : $forum_ids);
}
// Update the group forum setting
$group = new BP_Groups_Group($group_id);
$group->enable_forum = $edit_forum;
$group->save();
// Create a new forum
if (empty($forum_id) && true === $edit_forum) {
// 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));
// Run the BP-specific functions for new groups
$this->new_forum(array('forum_id' => $forum_id));
}
// Redirect after save
bp_core_redirect(trailingslashit(bp_get_group_permalink(buddypress()->groups->current_group) . '/admin/' . $this->slug));
}