コード例 #1
0
ファイル: forum.php プロジェクト: joeyblake/bbpress
 /**
  * @covers ::bbp_forum_permalink
  * @covers ::bbp_get_forum_permalink
  */
 public function test_bbp_get_forum_permalink()
 {
     if (is_multisite()) {
         $this->markTestSkipped('Skipping URL tests in multiste for now.');
     }
     // Public category.
     $c = $this->factory->forum->create(array('post_title' => 'Public Category'));
     $category = bbp_get_forum_permalink($c);
     $this->assertSame('http://' . WP_TESTS_DOMAIN . '/?forum=public-category', $category);
     // Public forum of public category.
     $f = $this->factory->forum->create(array('post_title' => 'Public Forum', 'post_parent' => $c));
     $forum_permalink = bbp_get_forum_permalink($f);
     $this->expectOutputString($forum_permalink);
     bbp_forum_permalink($f);
     $forum = bbp_get_forum_permalink($f);
     $this->assertSame('http://' . WP_TESTS_DOMAIN . '/?forum=public-category/public-forum', $forum);
     // Private category.
     $c = $this->factory->forum->create(array('post_title' => 'Private Category'));
     $category = bbp_get_forum_permalink($c);
     $forum = bbp_get_forum_permalink($f);
     $this->assertSame('http://' . WP_TESTS_DOMAIN . '/?forum=private-category', $category);
     // Private forum of private category.
     $f = $this->factory->forum->create(array('post_title' => 'Private Forum', 'post_parent' => $c));
     bbp_privatize_forum($c);
     $forum = bbp_get_forum_permalink($f);
     $this->assertSame('http://' . WP_TESTS_DOMAIN . '/?forum=private-category/private-forum', $forum);
     // Hidden category.
     $c = $this->factory->forum->create(array('post_title' => 'Hidden Category'));
     bbp_hide_forum($c);
     $category = bbp_get_forum_permalink($c);
     $this->assertSame('http://' . WP_TESTS_DOMAIN . '/?forum=hidden-category', $category);
     // Hidden forum of hidden category.
     $f = $this->factory->forum->create(array('post_title' => 'Hidden Forum', 'post_parent' => $c));
     $forum = bbp_get_forum_permalink($f);
     $this->assertSame('http://' . WP_TESTS_DOMAIN . '/?forum=hidden-category/hidden-forum', $forum);
 }
コード例 #2
0
/**
 * Handle the saving of core forum metadata (Status, Visibility, and Type)
 *
 * @since bbPress (r3678)
 * @param int $forum_id
 * @uses bbp_is_forum_closed() To check if forum is closed
 * @uses bbp_close_forum() To close forum
 * @uses bbp_open_forum() To open forum
 * @uses bbp_is_forum_category() To check if forum is a category
 * @uses bbp_categorize_forum() To turn forum into a category
 * @uses bbp_normalize_forum() To turn category into forum
 * @uses bbp_get_public_status_id() To get the public status ID
 * @uses bbp_get_private_status_id() To get the private status ID
 * @uses bbp_get_hidden_status_id() To get the hidden status ID
 * @uses bbp_get_forum_visibility() To get the forums visibility
 * @uses bbp_hide_forum() To hide a forum
 * @uses bbp_privatize_forum() To make a forum private
 * @uses bbp_publicize_forum() To make a forum public
 * @return If forum ID is empty
 */
function bbp_save_forum_extras($forum_id = 0)
{
    // Validate the forum ID
    $forum_id = bbp_get_forum_id($forum_id);
    // Bail if forum ID is empty
    if (empty($forum_id) || !bbp_is_forum($forum_id)) {
        return;
    }
    /** Forum Status ******************************************************/
    if (!empty($_POST['bbp_forum_status']) && in_array($_POST['bbp_forum_status'], array('open', 'closed'))) {
        if ('closed' === $_POST['bbp_forum_status'] && !bbp_is_forum_closed($forum_id, false)) {
            bbp_close_forum($forum_id);
        } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_closed($forum_id, false)) {
            bbp_open_forum($forum_id);
        }
    }
    /** Forum Type ********************************************************/
    if (!empty($_POST['bbp_forum_type']) && in_array($_POST['bbp_forum_type'], array('forum', 'category'))) {
        if ('category' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
            bbp_categorize_forum($forum_id);
        } elseif ('forum' === $_POST['bbp_forum_type'] && bbp_is_forum_category($forum_id)) {
            bbp_normalize_forum($forum_id);
        }
    }
    /** Forum Visibility **************************************************/
    if (!empty($_POST['bbp_forum_visibility']) && in_array($_POST['bbp_forum_visibility'], array(bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id()))) {
        // Get forums current visibility
        $visibility = bbp_get_forum_visibility($forum_id);
        // What is the new forum visibility setting?
        switch ($_POST['bbp_forum_visibility']) {
            // Hidden
            case bbp_get_hidden_status_id():
                bbp_hide_forum($forum_id, $visibility);
                break;
                // Private
            // Private
            case bbp_get_private_status_id():
                bbp_privatize_forum($forum_id, $visibility);
                break;
                // Publish (default)
            // Publish (default)
            case bbp_get_public_status_id():
            default:
                bbp_publicize_forum($forum_id, $visibility);
                break;
        }
    }
}
コード例 #3
0
/**
 * Handle the saving of core forum metadata (Status, Visibility, and Type)
 *
 * @since 2.1.0 bbPress (r3678)
 *
 * @param int $forum_id
 * @uses bbp_is_forum_closed() To check if forum is closed
 * @uses bbp_close_forum() To close forum
 * @uses bbp_open_forum() To open forum
 * @uses bbp_is_forum_category() To check if forum is a category
 * @uses bbp_categorize_forum() To turn forum into a category
 * @uses bbp_normalize_forum() To turn category into forum
 * @uses bbp_get_public_status_id() To get the public status ID
 * @uses bbp_get_private_status_id() To get the private status ID
 * @uses bbp_get_hidden_status_id() To get the hidden status ID
 * @uses bbp_get_forum_visibility() To get the forums visibility
 * @uses bbp_hide_forum() To hide a forum
 * @uses bbp_privatize_forum() To make a forum private
 * @uses bbp_publicize_forum() To make a forum public
 * @return If forum ID is empty
 */
function bbp_save_forum_extras($forum_id = 0)
{
    // Validate the forum ID
    $forum_id = bbp_get_forum_id($forum_id);
    // Bail if forum ID is empty
    if (empty($forum_id) || !bbp_is_forum($forum_id)) {
        return;
    }
    /** Forum Status **********************************************************/
    if (!empty($_POST['bbp_forum_status']) && in_array($_POST['bbp_forum_status'], array('open', 'closed'))) {
        if ('closed' === $_POST['bbp_forum_status'] && !bbp_is_forum_closed($forum_id, false)) {
            bbp_close_forum($forum_id);
        } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_open($forum_id, false)) {
            bbp_open_forum($forum_id);
        } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_closed($forum_id, false)) {
            bbp_open_forum($forum_id);
        }
    }
    /** Forum Type ************************************************************/
    if (!empty($_POST['bbp_forum_type']) && in_array($_POST['bbp_forum_type'], array('forum', 'category'))) {
        if ('category' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
            bbp_categorize_forum($forum_id);
        } elseif ('forum' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
            bbp_normalize_forum($forum_id);
        } elseif ('forum' === $_POST['bbp_forum_type'] && bbp_is_forum_category($forum_id)) {
            bbp_normalize_forum($forum_id);
        }
    }
    /** Forum Visibility ******************************************************/
    if (!empty($_POST['bbp_forum_visibility']) && in_array($_POST['bbp_forum_visibility'], array_keys(bbp_get_forum_visibilities()))) {
        // Get forums current visibility
        $old_visibility = bbp_get_forum_visibility($forum_id);
        // Sanitize the new visibility
        $new_visibility = sanitize_key($_POST['bbp_forum_visibility']);
        // What is the new forum visibility setting?
        switch ($new_visibility) {
            // Hidden
            case bbp_get_hidden_status_id():
                bbp_hide_forum($forum_id, $old_visibility);
                break;
                // Private
            // Private
            case bbp_get_private_status_id():
                bbp_privatize_forum($forum_id, $old_visibility);
                break;
                // Publish (default)
            // Publish (default)
            case bbp_get_public_status_id():
            default:
                bbp_publicize_forum($forum_id, $old_visibility);
                break;
        }
        /**
         * Allow custom forum visibility save actions
         *
         * @since 2.6.0 bbPress (r5855)
         *
         * @param int    $forum_id       The forum ID
         * @param string $old_visibility The current forum visibility
         * @param string $new_visibility The new forum visibility
         */
        do_action('bbp_update_forum_visibility', $forum_id, $old_visibility, $new_visibility);
    }
    /** Forum Moderators ******************************************************/
    // Either replace terms
    if (bbp_allow_forum_mods()) {
        if (current_user_can('assign_moderators') && !empty($_POST['bbp_moderators'])) {
            // Escape tag input
            $users = sanitize_text_field($_POST['bbp_moderators']);
            // Explode by comma
            $users = strstr($users, ',') ? explode(',', $users) : (array) $users;
            $user_ids = bbp_get_user_ids_from_nicenames($users);
            // Update forum moderators
            if (!empty($user_ids)) {
                // Remove all moderators
                bbp_remove_moderator($forum_id, null);
                // Add moderators
                foreach ($user_ids as $user_id) {
                    bbp_add_moderator($forum_id, $user_id);
                }
            }
            // ...or remove them.
        } elseif (isset($_POST['bbp_moderators'])) {
            bbp_remove_moderator($forum_id, null);
        }
    }
}
コード例 #4
0
ファイル: groups.php プロジェクト: joeyblake/bbpress
 /**
  * Set forums' status to match the privacy status of the associated group
  *
  * Fired whenever a group is saved
  *
  * @param BP_Groups_Group $group Group object.
  */
 public static function update_group_forum_visibility(BP_Groups_Group $group)
 {
     // Get group forum IDs
     $forum_ids = bbp_get_group_forum_ids($group->id);
     // Bail if no forum IDs available
     if (empty($forum_ids)) {
         return;
     }
     // Loop through forum IDs
     foreach ($forum_ids as $forum_id) {
         // Get forum from ID
         $forum = bbp_get_forum($forum_id);
         // Check for change
         if ($group->status !== $forum->post_status) {
             switch ($group->status) {
                 // Changed to hidden
                 case 'hidden':
                     bbp_hide_forum($forum_id, $forum->post_status);
                     break;
                     // Changed to private
                 // Changed to private
                 case 'private':
                     bbp_privatize_forum($forum_id, $forum->post_status);
                     break;
                     // Changed to public
                 // Changed to public
                 case 'public':
                 default:
                     bbp_publicize_forum($forum_id, $forum->post_status);
                     break;
             }
         }
     }
 }
コード例 #5
0
ファイル: functions.php プロジェクト: joeyblake/bbpress
/**
 * Handle the saving of core forum metadata (Status, Visibility, and Type)
 *
 * @since 2.1.0 bbPress (r3678)
 *
 * @param int $forum_id
 * @uses bbp_is_forum_closed() To check if forum is closed
 * @uses bbp_close_forum() To close forum
 * @uses bbp_open_forum() To open forum
 * @uses bbp_is_forum_category() To check if forum is a category
 * @uses bbp_categorize_forum() To turn forum into a category
 * @uses bbp_normalize_forum() To turn category into forum
 * @uses bbp_get_public_status_id() To get the public status ID
 * @uses bbp_get_private_status_id() To get the private status ID
 * @uses bbp_get_hidden_status_id() To get the hidden status ID
 * @uses bbp_get_forum_visibility() To get the forums visibility
 * @uses bbp_hide_forum() To hide a forum
 * @uses bbp_privatize_forum() To make a forum private
 * @uses bbp_publicize_forum() To make a forum public
 * @return If forum ID is empty
 */
function bbp_save_forum_extras($forum_id = 0)
{
    // Validate the forum ID
    $forum_id = bbp_get_forum_id($forum_id);
    // Bail if forum ID is empty
    if (empty($forum_id) || !bbp_is_forum($forum_id)) {
        return;
    }
    /** Forum Status **********************************************************/
    if (!empty($_POST['bbp_forum_status']) && in_array($_POST['bbp_forum_status'], array('open', 'closed'))) {
        if ('closed' === $_POST['bbp_forum_status'] && !bbp_is_forum_closed($forum_id, false)) {
            bbp_close_forum($forum_id);
        } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_open($forum_id, false)) {
            bbp_open_forum($forum_id);
        } elseif ('open' === $_POST['bbp_forum_status'] && bbp_is_forum_closed($forum_id, false)) {
            bbp_open_forum($forum_id);
        }
    }
    /** Forum Type ************************************************************/
    if (!empty($_POST['bbp_forum_type']) && in_array($_POST['bbp_forum_type'], array('forum', 'category'))) {
        if ('category' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
            bbp_categorize_forum($forum_id);
        } elseif ('forum' === $_POST['bbp_forum_type'] && !bbp_is_forum_category($forum_id)) {
            bbp_normalize_forum($forum_id);
        } elseif ('forum' === $_POST['bbp_forum_type'] && bbp_is_forum_category($forum_id)) {
            bbp_normalize_forum($forum_id);
        }
    }
    /** Forum Visibility ******************************************************/
    if (!empty($_POST['bbp_forum_visibility']) && in_array($_POST['bbp_forum_visibility'], array_keys(bbp_get_forum_visibilities()))) {
        // Get forums current visibility
        $old_visibility = bbp_get_forum_visibility($forum_id);
        // Sanitize the new visibility
        $new_visibility = sanitize_key($_POST['bbp_forum_visibility']);
        // What is the new forum visibility setting?
        switch ($new_visibility) {
            // Hidden
            case bbp_get_hidden_status_id():
                bbp_hide_forum($forum_id, $old_visibility);
                break;
                // Private
            // Private
            case bbp_get_private_status_id():
                bbp_privatize_forum($forum_id, $old_visibility);
                break;
                // Publish (default)
            // Publish (default)
            case bbp_get_public_status_id():
            default:
                bbp_publicize_forum($forum_id, $old_visibility);
                break;
        }
        /**
         * Allow custom forum visibility save actions
         *
         * @since 2.6.0 bbPress (r5855)
         *
         * @param int    $forum_id       The forum ID
         * @param string $old_visibility The current forum visibility
         * @param string $new_visibility The new forum visibility
         */
        do_action('bbp_update_forum_visibility', $forum_id, $old_visibility, $new_visibility);
    }
}