public static function SavePost($post_id, $post, $update)
 {
     if (wp_is_post_revision($post_id) || $post->post_status != 'publish' || $post->post_type != 'namaste_course') {
         return;
     }
     $meta = get_post_meta($post_id, 'buddypress_id', true);
     if (empty($meta)) {
         $group_id = groups_create_group(array('creator_id' => get_current_user_id(), 'name' => $post->post_title, 'description' => 'Обсуждение курса ' . $post->post_title, 'enable_forum' => 1));
         update_post_meta($post_id, 'buddypress_id', $group_id);
         groups_edit_group_settings($group_id, 1, 'private', 'mods');
         $forum_id = bbp_insert_forum($forum_data = array('post_status' => bbp_get_private_status_id(), 'post_type' => bbp_get_forum_post_type(), 'post_author' => bbp_get_current_user_id(), 'post_content' => 'Обсуждение курса ' . $post->post_title, 'post_title' => $post->post_title), $forum_meta = array());
         bbp_update_group_forum_ids($group_id, (array) $forum_id);
         bbp_update_forum_group_ids($forum_id, (array) $group_id);
     }
     bbp_add_user_forum_subscription(bbp_get_current_user_id(), $forum_id);
     update_post_meta($forum_id, '_forum_course_id', $post_id);
 }
コード例 #2
0
ファイル: groups.php プロジェクト: luskyj89/mt-wordpress
 /**
  * Save the Group Forum data on edit
  *
  * @since bbPress (r3465)
  * @param int $group_id (to handle Group Admin UI hook bp_group_admin_edit_after )
  * @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($group_id = 0)
 {
     // Bail if not a POST action
     if (!bbp_is_post_request()) {
         return;
     }
     // Admin Nonce check
     if (is_admin()) {
         check_admin_referer('groups_edit_save_' . $this->slug, 'forum_group_admin_ui');
         // Theme-side Nonce check
     } elseif (!bbp_verify_nonce_request('groups_edit_save_' . $this->slug)) {
         bbp_add_error('bbp_edit_group_forum_screen_save', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
         return;
     }
     $edit_forum = !empty($_POST['bbp-edit-group-forum']) ? true : false;
     $forum_id = 0;
     $group_id = !empty($group_id) ? $group_id : bp_get_current_group_id();
     // Keymasters have the ability to reconfigure forums
     if (bbp_is_user_keymaster()) {
         $forum_ids = !empty($_POST['bbp_group_forum_id']) ? (array) (int) $_POST['bbp_group_forum_id'] : array();
         // Use the existing forum IDs
     } else {
         $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 ID and forum ID relationships
     bbp_update_group_forum_ids($group_id, (array) $forum_ids);
     bbp_update_forum_group_ids($forum_id, (array) $group_id);
     // Update the group forum setting
     $group = $this->toggle_group_forum($group_id, $edit_forum);
     // 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));
         // Setup forum args with forum ID
         $new_forum_args = array('forum_id' => $forum_id);
         // If in admin, also include the group ID
         if (is_admin() && !empty($group_id)) {
             $new_forum_args['group_id'] = $group_id;
         }
         // Run the BP-specific functions for new groups
         $this->new_forum($new_forum_args);
     }
     // Redirect after save when not in admin
     if (!is_admin()) {
         bp_core_redirect(trailingslashit(bp_get_group_permalink(buddypress()->groups->current_group) . '/admin/' . $this->slug));
     }
 }
コード例 #3
0
ファイル: functions.php プロジェクト: hscale/webento
/**
 * Remove a group from a forum
 *
 * @param type $group_id
 * @since bbPress (r3653)
 */
function bbp_remove_group_id_from_forum($forum_id = 0, $group_id = 0)
{
    // Validate forum_id
    $forum_id = bbp_get_forum_id($forum_id);
    // Use current group if none is set
    if (empty($group_id)) {
        $group_id = bp_get_current_group_id();
    }
    // Get current group IDs
    $group_ids = bbp_get_forum_group_ids($forum_id);
    // Maybe update the groups forums
    if (in_array($group_id, $group_ids)) {
        $group_ids = array_diff(array_values($group_ids), (array) $group_id);
        return bbp_update_forum_group_ids($forum_id, $group_ids);
    }
}