Пример #1
0
 /**
  * Generic function to test the topic counts on a deleted reply
  */
 public function test_bbp_topic_deleted_reply_counts()
 {
     $f = $this->factory->forum->create();
     $t = $this->factory->topic->create(array('post_parent' => $f, 'post_author' => bbp_get_current_user_id(), 'topic_meta' => array('forum_id' => $f)));
     $r1 = $this->factory->reply->create(array('post_parent' => $t, 'post_author' => bbp_get_current_user_id(), 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     $u = $this->factory->user->create();
     $count = bbp_update_topic_reply_count($t);
     $this->assertSame(1, $count);
     $count = bbp_update_topic_reply_count_hidden($t);
     $this->assertSame(0, $count);
     $count = bbp_update_topic_voice_count($t);
     $this->assertSame(1, $count);
     $r2 = $this->factory->reply->create(array('post_parent' => $t, 'post_author' => $u, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     $count = bbp_update_topic_reply_count($t);
     $this->assertSame(2, $count);
     $count = bbp_update_topic_reply_count_hidden($t);
     $this->assertSame(0, $count);
     $count = bbp_update_topic_voice_count($t);
     $this->assertSame(2, $count);
     // ToDo: Update this to use bbp_delete_reply().
     bbp_clean_post_cache($t);
     wp_delete_post($r2, true);
     $count = bbp_get_topic_reply_count($t, true);
     $this->assertSame(1, $count);
     $count = bbp_get_topic_reply_count_hidden($t, true);
     $this->assertSame(0, $count);
     $count = bbp_get_topic_voice_count($t, true);
     $this->assertSame(1, $count);
 }
Пример #2
0
 /**
  * Generic function to test the forum counts with a new topic
  */
 public function test_bbp_forum_new_topic_counts()
 {
     $f = $this->factory->forum->create();
     $t1 = $this->factory->topic->create(array('post_parent' => $f, 'post_author' => bbp_get_current_user_id(), 'topic_meta' => array('forum_id' => $f)));
     $u = $this->factory->user->create();
     // Cheating here, but we need $_SERVER['SERVER_NAME'] to be set.
     $this->setUp_wp_mail(false);
     // Simulate the 'bbp_new_topic' action.
     do_action('bbp_new_topic', $t1, $f, false, bbp_get_current_user_id(), $t1);
     // Reverse our changes.
     $this->tearDown_wp_mail(false);
     $count = bbp_get_forum_topic_count($f, true, true);
     $this->assertSame(1, $count);
     $count = bbp_get_forum_topic_count_hidden($f, true, true);
     $this->assertSame(0, $count);
     $t2 = $this->factory->topic->create(array('post_parent' => $f, 'post_author' => $u, 'topic_meta' => array('forum_id' => $f)));
     // Cheating here, but we need $_SERVER['SERVER_NAME'] to be set.
     $this->setUp_wp_mail(false);
     // Simulate the 'bbp_new_topic' action.
     do_action('bbp_new_topic', $t2, $f, false, $u, $t2);
     // Reverse our changes.
     $this->tearDown_wp_mail(false);
     $count = bbp_get_forum_topic_count($f, true, true);
     $this->assertSame(2, $count);
     $count = bbp_get_forum_topic_count_hidden($f, true, true);
     $this->assertSame(0, $count);
 }
Пример #3
0
 /**
  * Generic function to test the forum counts with a new topic
  */
 public function test_bbp_forum_new_topic_counts()
 {
     remove_action('bbp_insert_topic', 'bbp_insert_topic_update_counts', 10);
     $f = $this->factory->forum->create();
     $t1 = $this->factory->topic->create(array('post_parent' => $f, 'post_author' => bbp_get_current_user_id(), 'topic_meta' => array('forum_id' => $f)));
     $u = $this->factory->user->create();
     // Don't attempt to send an email. This is for speed and PHP errors.
     remove_action('bbp_new_topic', 'bbp_notify_forum_subscribers', 11, 4);
     // Simulate the 'bbp_new_topic' action.
     do_action('bbp_new_topic', $t1, $f, false, bbp_get_current_user_id(), $t1);
     $count = bbp_get_forum_topic_count($f, true, true);
     $this->assertSame(1, $count);
     $count = bbp_get_forum_topic_count_hidden($f, true, true);
     $this->assertSame(0, $count);
     $t2 = $this->factory->topic->create(array('post_parent' => $f, 'post_author' => $u, 'topic_meta' => array('forum_id' => $f)));
     // Simulate the 'bbp_new_topic' action.
     do_action('bbp_new_topic', $t2, $f, false, $u, $t2);
     $count = bbp_get_forum_topic_count($f, true, true);
     $this->assertSame(2, $count);
     $count = bbp_get_forum_topic_count_hidden($f, true, true);
     $this->assertSame(0, $count);
     // Re-add removed actions.
     add_action('bbp_insert_topic', 'bbp_insert_topic_update_counts', 10, 2);
     add_action('bbp_new_topic', 'bbp_notify_forum_subscribers', 11, 4);
 }
 public static function EnrolledCourse($student_id, $course_id, $status)
 {
     global $wpdb;
     $group_id = get_post_meta($course_id, 'buddypress_id', true);
     // Get BuddyPress
     $bp = buddypress();
     $group = $wpdb->get_row($wpdb->prepare("SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $group_id));
     groups_invite_user(array('user_id' => $student_id, 'group_id' => $group_id, 'inviter_id' => $group->creator_id, 'date_modified' => bp_core_current_time(), 'is_confirmed' => 1));
     $forums = bbp_get_group_forum_ids($group_id);
     bbp_add_user_forum_subscription(bbp_get_current_user_id(), $forums[0]);
 }
Пример #5
0
 /**
  * @covers ::bbp_current_user_id
  * @covers ::bbp_get_current_user_id
  */
 public function test_bbp_get_current_user_id()
 {
     $int_value = $this->keymaster_userdata->ID;
     $formatted_value = bbp_number_format($int_value);
     // Integer.
     $user_id = bbp_get_current_user_id();
     $this->assertSame($this->keymaster_id, $user_id);
     // Output.
     $this->expectOutputString($formatted_value);
     bbp_current_user_id($this->keymaster_id);
 }
    /**
     * Outputs the "Set as private reply" checkbox
     *
     * @since 1.0
     *
     * @return void
     */
    public function checkbox()
    {
        ?>
		<p>

			<input name="bbp_private_reply" id="bbp_private_reply" type="checkbox"<?php 
        checked('1', $this->is_private(bbp_get_reply_id()));
        ?>
 value="1" tabindex="<?php 
        bbp_tab_index();
        ?>
" />

			<?php 
        if (bbp_is_reply_edit() && get_the_author_meta('ID') != bbp_get_current_user_id()) {
            ?>

				<label for="bbp_private_reply"><?php 
            _e('Set author\'s post as private.', 'bbp_private_replies');
            ?>
</label>

			<?php 
        } else {
            ?>

				<label for="bbp_private_reply"><?php 
            _e('Set as private reply', 'bbp_private_replies');
            ?>
</label>

			<?php 
        }
        ?>

		</p>
<?php 
    }
Пример #7
0
/**
 * Check if current page is the currently logged in users author edit page
 *
 * @since bbPress (r3918)
 * @uses bbp_is_single_user_edit() Check query variable
 * @uses is_user_logged_in() Must be logged in to be home
 * @uses bbp_get_displayed_user_id()
 * @uses bbp_get_current_user_id()
 * @return bool True if it's the user's home, false if not
 */
function bbp_is_user_home_edit()
{
    // Assume false
    $retval = false;
    if (bbp_is_single_user_edit() && is_user_logged_in()) {
        $retval = (bool) (bbp_get_displayed_user_id() == bbp_get_current_user_id());
    }
    return (bool) apply_filters('bbp_is_user_home_edit', $retval);
}
Пример #8
0
							<?php 
        do_action('bbp_theme_before_topic_form_subscriptions');
        ?>

							<p>
								<input name="bbp_topic_subscription" id="bbp_topic_subscription" type="checkbox" value="bbp_subscribe" <?php 
        bbp_form_topic_subscribed();
        ?>
 tabindex="<?php 
        bbp_tab_index();
        ?>
" />

								<?php 
        if (bbp_is_topic_edit() && $post->post_author != bbp_get_current_user_id()) {
            ?>

									<label for="bbp_topic_subscription"><?php 
            _e('Notify the author of follow-up replies via email', 'bbpress');
            ?>
</label>

								<?php 
        } else {
            ?>

									<label for="bbp_topic_subscription"><?php 
            _e('Notify me of follow-up replies via email', 'bbpress');
            ?>
</label>
Пример #9
0
 /**
  * @covers ::bbp_check_for_blacklist
  */
 public function test_should_return_true_for_keymasterss_to_bypass_blacklist_check()
 {
     // Create a keymaster user.
     $old_current_user = 0;
     $this->old_current_user = get_current_user_id();
     $this->set_current_user($this->factory->user->create(array('role' => 'subscriber')));
     $this->keymaster_id = get_current_user_id();
     bbp_set_user_role($this->keymaster_id, bbp_get_keymaster_role());
     $t = $this->factory->topic->create(array('post_author' => bbp_get_current_user_id(), 'post_title' => 'Sting', 'post_content' => 'Beware, there maybe bees hibernating.'));
     $anonymous_data = false;
     $author_id = bbp_get_topic_author_id($t);
     $title = bbp_get_topic_title($t);
     $content = bbp_get_topic_content($t);
     update_option('blacklist_keys', "hibernating\nfoo");
     $result = bbp_check_for_blacklist($anonymous_data, $author_id, $title, $content);
     $this->assertTrue($result);
     // Retore the original user.
     $this->set_current_user($this->old_current_user);
 }
Пример #10
0
/**
 * Check if the user can access a specific forum
 *
 * @since bbPress (r3127)
 *
 * @uses bbp_get_current_user_id()
 * @uses bbp_get_forum_id()
 * @uses bbp_allow_anonymous()
 * @uses bbp_parse_args()
 * @uses bbp_get_user_id()
 * @uses current_user_can()
 * @uses is_super_admin()
 * @uses bbp_is_forum_public()
 * @uses bbp_is_forum_private()
 * @uses bbp_is_forum_hidden()
 * @uses current_user_can()
 * @uses apply_filters()
 *
 * @return bool
 */
function bbp_user_can_view_forum($args = '')
{
    // Default arguments
    $defaults = array('user_id' => bbp_get_current_user_id(), 'forum_id' => bbp_get_forum_id(), 'check_ancestors' => false);
    $r = bbp_parse_args($args, $defaults, 'user_can_view_forum');
    extract($r);
    // Validate parsed values
    $user_id = bbp_get_user_id($user_id, false, false);
    $forum_id = bbp_get_forum_id($forum_id);
    $retval = false;
    // User is a super admin
    if (is_super_admin()) {
        $retval = true;
    } elseif (bbp_is_forum_public($forum_id, $check_ancestors)) {
        $retval = true;
    } elseif (bbp_is_forum_private($forum_id, $check_ancestors) && current_user_can('read_private_forums')) {
        $retval = true;
    } elseif (bbp_is_forum_hidden($forum_id, $check_ancestors) && current_user_can('read_hidden_forums')) {
        $retval = true;
    }
    return apply_filters('bbp_user_can_view_forum', $retval, $forum_id, $user_id);
}
Пример #11
0
bbp_displayed_user_field('user_email', 'edit');
?>
" class="regular-text" tabindex="<?php 
bbp_tab_index();
?>
" />

			<?php 
// Handle address change requests
$new_email = get_option(bbp_get_displayed_user_id() . '_new_email');
if (!empty($new_email) && $new_email !== bbp_get_displayed_user_field('user_email', 'edit')) {
    ?>

				<span class="updated inline">
					<?php 
    printf(wp_kses(__('There is a pending email address change to <code>%1$s</code>. <a href="%2$s">Cancel</a>', 'monsoon'), array('code' => array(), 'a' => array())), $new_email['newemail'], esc_url(self_admin_url('user.php?dismiss=' . bbp_get_current_user_id() . '_new_email')));
    ?>
				</span>
			<?php 
}
?>
		</div>

		<div id="password">
			<label for="pass1"><?php 
esc_html_e('New Password', 'monsoon');
?>
</label>
			<fieldset class="bbp-form password">
				<input type="password" name="pass1" id="pass1" size="16" value="" autocomplete="off" tabindex="<?php 
bbp_tab_index();
Пример #12
0
						<?php 
        do_action('bbp_theme_before_topic_form_subscriptions');
        ?>

						<p>
							<input name="bbp_topic_subscription" id="bbp_topic_subscription" type="checkbox" value="bbp_subscribe" <?php 
        bbp_form_topic_subscribed();
        ?>
 tabindex="<?php 
        bbp_tab_index();
        ?>
" />

							<?php 
        if (bbp_is_topic_edit() && bbp_get_topic_author_id() !== bbp_get_current_user_id()) {
            ?>

								<label for="bbp_topic_subscription"><?php 
            _e('Notify the author of follow-up replies via email', 'bbpress');
            ?>
</label>

							<?php 
        } else {
            ?>

								<label for="bbp_topic_subscription"><?php 
            _e('Notify me of follow-up replies via email', 'bbpress');
            ?>
</label>
Пример #13
0
?>
" class="regular-text" tabindex="<?php 
bbp_tab_index();
?>
" />

			<?php 
// Handle address change requests
$new_email = get_option(bbp_get_displayed_user_id() . '_new_email');
if (!empty($new_email) && $new_email !== bbp_get_displayed_user_field('user_email', 'edit')) {
    ?>

				<span class="updated inline">

					<?php 
    printf(__('There is a pending email address change to <code>%1$s</code>. <a href="%2$s">Cancel</a>', 'bbpress'), $new_email['newemail'], esc_url(self_admin_url('user.php?dismiss=' . bbp_get_current_user_id() . '_new_email')));
    ?>

				</span>

			<?php 
}
?>

		</div>

		<div id="password">
			<label for="pass1"><?php 
_e('New Password', 'bbpress');
?>
</label>
Пример #14
0
    ?>
    <div class="fullwidth">
			<a id="author-avatar" href="<?php 
    bbp_user_profile_url(bbp_get_current_user_id());
    ?>
">
				<?php 
    echo get_avatar(bbp_get_current_user_id(), '64');
    ?>
			</a>
			<h4>Welcome back, <?php 
    bbp_user_profile_link(bbp_get_current_user_id());
    ?>
!</h4>
				<a href="<?php 
    echo bbp_get_user_profile_url(bbp_get_current_user_id());
    ?>
">Your Profile</a>
				 | 
				<a href="<?php 
    echo wp_logout_url();
    ?>
" title="Log Out">Logout</a>
			<div class="clear"></div>
		</div>
		
		<?php 
} else {
    ?>
			
    <div class="one_third">
Пример #15
0
/**
 * Return checked value of topic subscription
 *
 * @since 2.0.0 bbPress (r2976)
 *
 * @uses bbp_is_topic_edit() To check if it's the topic edit page
 * @uses bbp_is_user_subscribed_to_topic() To check if the user is
 *                                          subscribed to the topic
 * @uses apply_filters() Calls 'bbp_get_form_topic_subscribed' with the
 *                        option
 * @return string Checked value of topic subscription
 */
function bbp_get_form_topic_subscribed()
{
    // Get _POST data
    if (bbp_is_topic_form_post_request() && isset($_POST['bbp_topic_subscription'])) {
        $topic_subscribed = (bool) $_POST['bbp_topic_subscription'];
        // Get edit data
    } elseif (bbp_is_topic_edit() || bbp_is_reply_edit()) {
        // Get current posts author
        $post_author = bbp_get_global_post_field('post_author', 'raw');
        // Post author is not the current user
        if (bbp_get_current_user_id() !== $post_author) {
            $topic_subscribed = bbp_is_user_subscribed_to_topic($post_author);
            // Post author is the current user
        } else {
            $topic_subscribed = bbp_is_user_subscribed_to_topic(bbp_get_current_user_id());
        }
        // Get current status
    } elseif (bbp_is_single_topic()) {
        $topic_subscribed = bbp_is_user_subscribed_to_topic(bbp_get_current_user_id());
        // No data
    } else {
        $topic_subscribed = false;
    }
    // Get checked output
    $checked = checked($topic_subscribed, true, false);
    return apply_filters('bbp_get_form_topic_subscribed', $checked, $topic_subscribed);
}
Пример #16
0
/**
 * Handles the front end forum submission
 *
 * @param string $action The requested action to compare this function to
 * @uses bbp_add_error() To add an error message
 * @uses bbp_verify_nonce_request() To verify the nonce and check the request
 * @uses bbp_is_anonymous() To check if an anonymous post is being made
 * @uses current_user_can() To check if the current user can publish forum
 * @uses bbp_get_current_user_id() To get the current user id
 * @uses bbp_filter_anonymous_post_data() To filter anonymous data
 * @uses bbp_set_current_anonymous_user_data() To set the anonymous user cookies
 * @uses is_wp_error() To check if the value retrieved is a {@link WP_Error}
 * @uses esc_attr() For sanitization
 * @uses bbp_is_forum_category() To check if the forum is a category
 * @uses bbp_is_forum_closed() To check if the forum is closed
 * @uses bbp_is_forum_private() To check if the forum is private
 * @uses bbp_check_for_flood() To check for flooding
 * @uses bbp_check_for_duplicate() To check for duplicates
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses remove_filter() To remove kses filters if needed
 * @uses apply_filters() Calls 'bbp_new_forum_pre_title' with the content
 * @uses apply_filters() Calls 'bbp_new_forum_pre_content' with the content
 * @uses bbPress::errors::get_error_codes() To get the {@link WP_Error} errors
 * @uses wp_insert_post() To insert the forum
 * @uses do_action() Calls 'bbp_new_forum' with the forum id, forum id,
 *                    anonymous data and reply author
 * @uses bbp_stick_forum() To stick or super stick the forum
 * @uses bbp_unstick_forum() To unstick the forum
 * @uses bbp_get_forum_permalink() To get the forum permalink
 * @uses wp_safe_redirect() To redirect to the forum link
 * @uses bbPress::errors::get_error_messages() To get the {@link WP_Error} error
 *                                              messages
 */
function bbp_new_forum_handler($action = '')
{
    // Bail if action is not bbp-new-forum
    if ('bbp-new-forum' !== $action) {
        return;
    }
    // Nonce check
    if (!bbp_verify_nonce_request('bbp-new-forum')) {
        bbp_add_error('bbp_new_forum_nonce', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
        return;
    }
    // Define local variable(s)
    $view_all = $anonymous_data = false;
    $forum_parent_id = $forum_author = 0;
    $forum_title = $forum_content = '';
    /** Forum Author **********************************************************/
    // User cannot create forums
    if (!current_user_can('publish_forums')) {
        bbp_add_error('bbp_forum_permissions', __('<strong>ERROR</strong>: You do not have permission to create new forums.', 'bbpress'));
        return;
    }
    // Forum author is current user
    $forum_author = bbp_get_current_user_id();
    // Remove kses filters from title and content for capable users and if the nonce is verified
    if (current_user_can('unfiltered_html') && !empty($_POST['_bbp_unfiltered_html_forum']) && wp_create_nonce('bbp-unfiltered-html-forum_new') === $_POST['_bbp_unfiltered_html_forum']) {
        remove_filter('bbp_new_forum_pre_title', 'wp_filter_kses');
        remove_filter('bbp_new_forum_pre_content', 'bbp_encode_bad', 10);
        remove_filter('bbp_new_forum_pre_content', 'bbp_filter_kses', 30);
    }
    /** Forum Title ***********************************************************/
    if (!empty($_POST['bbp_forum_title'])) {
        $forum_title = esc_attr(strip_tags($_POST['bbp_forum_title']));
    }
    // Filter and sanitize
    $forum_title = apply_filters('bbp_new_forum_pre_title', $forum_title);
    // No forum title
    if (empty($forum_title)) {
        bbp_add_error('bbp_forum_title', __('<strong>ERROR</strong>: Your forum needs a title.', 'bbpress'));
    }
    /** Forum Content *********************************************************/
    if (!empty($_POST['bbp_forum_content'])) {
        $forum_content = $_POST['bbp_forum_content'];
    }
    // Filter and sanitize
    $forum_content = apply_filters('bbp_new_forum_pre_content', $forum_content);
    // No forum content
    if (empty($forum_content)) {
        bbp_add_error('bbp_forum_content', __('<strong>ERROR</strong>: Your forum description cannot be empty.', 'bbpress'));
    }
    /** Forum Parent **********************************************************/
    // Forum parent was passed (the norm)
    if (!empty($_POST['bbp_forum_parent_id'])) {
        $forum_parent_id = bbp_get_forum_id($_POST['bbp_forum_parent_id']);
    }
    // Filter and sanitize
    $forum_parent_id = apply_filters('bbp_new_forum_pre_parent_id', $forum_parent_id);
    // No forum parent was passed (should never happen)
    if (empty($forum_parent_id)) {
        bbp_add_error('bbp_new_forum_missing_parent', __('<strong>ERROR</strong>: Your forum must have a parent.', 'bbpress'));
        // Forum exists
    } elseif (!empty($forum_parent_id)) {
        // Forum is a category
        if (bbp_is_forum_category($forum_parent_id)) {
            bbp_add_error('bbp_new_forum_forum_category', __('<strong>ERROR</strong>: This forum is a category. No forums can be created in this forum.', 'bbpress'));
        }
        // Forum is closed and user cannot access
        if (bbp_is_forum_closed($forum_parent_id) && !current_user_can('edit_forum', $forum_parent_id)) {
            bbp_add_error('bbp_new_forum_forum_closed', __('<strong>ERROR</strong>: This forum has been closed to new forums.', 'bbpress'));
        }
        // Forum is private and user cannot access
        if (bbp_is_forum_private($forum_parent_id) && !current_user_can('read_private_forums')) {
            bbp_add_error('bbp_new_forum_forum_private', __('<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new forums in it.', 'bbpress'));
        }
        // Forum is hidden and user cannot access
        if (bbp_is_forum_hidden($forum_parent_id) && !current_user_can('read_hidden_forums')) {
            bbp_add_error('bbp_new_forum_forum_hidden', __('<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new forums in it.', 'bbpress'));
        }
    }
    /** Forum Flooding ********************************************************/
    if (!bbp_check_for_flood($anonymous_data, $forum_author)) {
        bbp_add_error('bbp_forum_flood', __('<strong>ERROR</strong>: Slow down; you move too fast.', 'bbpress'));
    }
    /** Forum Duplicate *******************************************************/
    if (!bbp_check_for_duplicate(array('post_type' => bbp_get_forum_post_type(), 'post_author' => $forum_author, 'post_content' => $forum_content, 'anonymous_data' => $anonymous_data))) {
        bbp_add_error('bbp_forum_duplicate', __('<strong>ERROR</strong>: This forum already exists.', 'bbpress'));
    }
    /** Forum Blacklist *******************************************************/
    if (!bbp_check_for_blacklist($anonymous_data, $forum_author, $forum_title, $forum_content)) {
        bbp_add_error('bbp_forum_blacklist', __('<strong>ERROR</strong>: Your forum cannot be created at this time.', 'bbpress'));
    }
    /** Forum Moderation ******************************************************/
    $post_status = bbp_get_public_status_id();
    if (!bbp_check_for_moderation($anonymous_data, $forum_author, $forum_title, $forum_content)) {
        $post_status = bbp_get_pending_status_id();
    }
    /** Additional Actions (Before Save) **************************************/
    do_action('bbp_new_forum_pre_extras', $forum_parent_id);
    // Bail if errors
    if (bbp_has_errors()) {
        return;
    }
    /** No Errors *************************************************************/
    // Add the content of the form to $forum_data as an array
    // Just in time manipulation of forum data before being created
    $forum_data = apply_filters('bbp_new_forum_pre_insert', array('post_author' => $forum_author, 'post_title' => $forum_title, 'post_content' => $forum_content, 'post_parent' => $forum_parent_id, 'post_status' => $post_status, 'post_type' => bbp_get_forum_post_type(), 'comment_status' => 'closed'));
    // Insert forum
    $forum_id = wp_insert_post($forum_data);
    /** No Errors *************************************************************/
    if (!empty($forum_id) && !is_wp_error($forum_id)) {
        /** Trash Check *******************************************************/
        // If the forum is trash, or the forum_status is switched to
        // trash, trash it properly
        if (get_post_field('post_status', $forum_id) === bbp_get_trash_status_id() || $forum_data['post_status'] === bbp_get_trash_status_id()) {
            // Trash the reply
            wp_trash_post($forum_id);
            // Force view=all
            $view_all = true;
        }
        /** Spam Check ********************************************************/
        // If reply or forum are spam, officially spam this reply
        if ($forum_data['post_status'] === bbp_get_spam_status_id()) {
            add_post_meta($forum_id, '_bbp_spam_meta_status', bbp_get_public_status_id());
            // Force view=all
            $view_all = true;
        }
        /** Update counts, etc... *********************************************/
        do_action('bbp_new_forum', array('forum_id' => $forum_id, 'post_parent' => $forum_parent_id, 'forum_author' => $forum_author, 'last_topic_id' => 0, 'last_reply_id' => 0, 'last_active_id' => 0, 'last_active_time' => 0, 'last_active_status' => bbp_get_public_status_id()));
        /** Additional Actions (After Save) ***********************************/
        do_action('bbp_new_forum_post_extras', $forum_id);
        /** Redirect **********************************************************/
        // Redirect to
        $redirect_to = bbp_get_redirect_to();
        // Get the forum URL
        $redirect_url = bbp_get_forum_permalink($forum_id, $redirect_to);
        // Add view all?
        if (bbp_get_view_all() || !empty($view_all)) {
            // User can moderate, so redirect to forum with view all set
            if (current_user_can('moderate')) {
                $redirect_url = bbp_add_view_all($redirect_url);
                // User cannot moderate, so redirect to forum
            } else {
                $redirect_url = bbp_get_forum_permalink($forum_id);
            }
        }
        // Allow to be filtered
        $redirect_url = apply_filters('bbp_new_forum_redirect_to', $redirect_url, $redirect_to);
        /** Successful Save ***************************************************/
        // Redirect back to new forum
        wp_safe_redirect($redirect_url);
        // For good measure
        exit;
        // Errors
    } else {
        $append_error = is_wp_error($forum_id) && $forum_id->get_error_message() ? $forum_id->get_error_message() . ' ' : '';
        bbp_add_error('bbp_forum_error', __('<strong>ERROR</strong>: The following problem(s) have been found with your forum:' . $append_error, 'bbpress'));
    }
}
    /**
     * Displays the output, the login form
     *
     * @since bbPress (r2827)
     *
     * @param mixed $args Arguments
     * @param array $instance Instance
     * @uses apply_filters() Calls 'bbp_login_widget_title' with the title
     * @uses get_template_part() To get the login/logged in form
     */
    public function widget($args = array(), $instance = array())
    {
        // Get widget settings
        $settings = $this->parse_settings($instance);
        // Typical WordPress filter
        $settings['title'] = apply_filters('widget_title', $settings['title'], $instance, $this->id_base);
        // bbPress filters
        $settings['title'] = apply_filters('bbp_login_widget_title', $settings['title'], $instance, $this->id_base);
        $settings['register'] = apply_filters('bbp_login_widget_register', $settings['register'], $instance, $this->id_base);
        $settings['lostpass'] = apply_filters('bbp_login_widget_lostpass', $settings['lostpass'], $instance, $this->id_base);
        echo $args['before_widget'];
        if (!empty($settings['title'])) {
            echo $args['before_title'] . $settings['title'] . $args['after_title'];
        }
        if (!is_user_logged_in()) {
            ?>
			<form method="post" action="<?php 
            bbp_wp_login_action(array('context' => 'login_post'));
            ?>
" class="bbp-login-form">
				<fieldset>
					<legend><?php 
            _e('Log In', 'bbpress');
            ?>
</legend>

					<div class="bbp-username form-group">
						<label for="user_login" class="sr-only"><?php 
            _e('Username', 'bbpress');
            ?>
: </label>
						<div class="input-group">
							<span class="input-group-addon">
								<span class="glyphicon ipt-icomoon-user"></span>
							</span>
							<input placeholder="<?php 
            _e('Username', 'bbpress');
            ?>
" class="form-control" type="text" name="log" value="<?php 
            bbp_sanitize_val('user_login', 'text');
            ?>
" size="20" id="user_login" tabindex="<?php 
            bbp_tab_index();
            ?>
" />
						</div>
					</div>

					<div class="bbp-password form-group">
						<label for="user_pass" class="sr-only"><?php 
            _e('Password', 'bbpress');
            ?>
: </label>
						<div class="input-group">
							<span class="input-group-addon">
								<span class="glyphicon ipt-icomoon-console"></span>
							</span>
							<input placeholder="<?php 
            _e('Password', 'bbpress');
            ?>
" class="form-control" type="password" name="pwd" value="<?php 
            bbp_sanitize_val('user_pass', 'password');
            ?>
" size="20" id="user_pass" tabindex="<?php 
            bbp_tab_index();
            ?>
" />
						</div>
					</div>

					<?php 
            do_action('login_form');
            ?>

					<div class="bbp-remember-me checkbox">
						<input type="checkbox" name="rememberme" value="forever" <?php 
            checked(bbp_get_sanitize_val('rememberme', 'checkbox'), true, true);
            ?>
 id="rememberme" tabindex="<?php 
            bbp_tab_index();
            ?>
" />
						<label for="rememberme"><?php 
            _e('Remember Me', 'bbpress');
            ?>
</label>
					</div>

					<div class="bbp-submit-wrapper btn-group">
						<?php 
            if (!empty($settings['lostpass'])) {
                ?>
							<a href="<?php 
                echo esc_url($settings['lostpass']);
                ?>
" title="<?php 
                esc_attr_e('Lost Password', 'bbpress');
                ?>
" class="bbp-lostpass-link btn btn-default"><span class="glyphicon ipt-icomoon-info"></span></a>
						<?php 
            }
            ?>
						<?php 
            if (!empty($settings['register'])) {
                ?>
							<a href="<?php 
                echo esc_url($settings['register']);
                ?>
" title="<?php 
                esc_attr_e('Register', 'bbpress');
                ?>
" class="bbp-register-link btn btn-default"><span class="glyphicon ipt-icomoon-signup"></span> <?php 
                _e('Register', 'bbpress');
                ?>
</a>
						<?php 
            }
            ?>
						<button class="btn btn-primary" type="submit" name="user-submit" id="user-submit" tabindex="<?php 
            bbp_tab_index();
            ?>
" class="button submit user-submit"><span class="glyphicon ipt-icomoon-switch"></span> <?php 
            _e('Log In', 'bbpress');
            ?>
</button>
					</div>
					<?php 
            bbp_user_login_fields();
            ?>
				</fieldset>
			</form>

		<?php 
        } else {
            ?>

			<div class="bbp-logged-in">
				<a href="<?php 
            bbp_user_profile_url(bbp_get_current_user_id());
            ?>
" class="submit user-submit thumbnail pull-left"><?php 
            echo get_avatar(bbp_get_current_user_id(), '64');
            ?>
</a>
				<h4><?php 
            bbp_user_profile_link(bbp_get_current_user_id());
            ?>
</h4>
				<div class="btn-group">
					<a class="btn btn-default btn-sm" href="<?php 
            bbp_user_profile_edit_url(bbp_get_current_user_id());
            ?>
" title="<?php 
            printf(esc_attr__("Edit Your Profile", 'ipt_kb'));
            ?>
"><span class="glyphicon glyphicon-edit"></span> <?php 
            _e('Edit', 'bbpress');
            ?>
</a>
					<?php 
            bbp_logout_link();
            ?>
				</div>

				<div class="clearfix"></div>

				<div class="list-group">
					<a href="<?php 
            bbp_user_profile_url(bbp_get_current_user_id());
            ?>
" class="list-group-item bbp-user-forum-role <?php 
            if (bbp_is_user_home() && bbp_is_single_user_profile()) {
                echo 'active';
            }
            ?>
">
						<span class="glyphicon ipt-icomoon-user4"></span> <?php 
            printf(__('%s Forum Role', 'ipt_kb'), '<span class="badge">' . bbp_get_user_display_role(bbp_get_current_user_id()) . '</span>');
            ?>
					</a>
					<a href="<?php 
            bbp_user_topics_created_url(bbp_get_current_user_id());
            ?>
" class="list-group-item bbp-user-topic-count <?php 
            if (bbp_is_user_home() && bbp_is_single_user_topics()) {
                echo 'active';
            }
            ?>
">
						<span class="glyphicon ipt-icomoon-bubbles4"></span> <?php 
            printf(__('%s Topics Started', 'ipt_kb'), '<span class="badge">' . bbp_get_user_topic_count_raw(bbp_get_current_user_id()) . '</span>');
            ?>
					</a>
					<a href="<?php 
            bbp_user_replies_created_url(bbp_get_current_user_id());
            ?>
" class="list-group-item bbp-user-reply-count <?php 
            if (bbp_is_user_home() && bbp_is_single_user_replies()) {
                echo 'active';
            }
            ?>
">
						<span class="glyphicon ipt-icomoon-reply"></span> <?php 
            printf(__('%s Replies Created', 'ipt_kb'), '<span class="badge">' . bbp_get_user_reply_count_raw(bbp_get_current_user_id()) . '</span>');
            ?>
					</a>
					<?php 
            if (bbp_is_favorites_active()) {
                ?>
					<a href="<?php 
                bbp_favorites_permalink(bbp_get_current_user_id());
                ?>
" class="list-group-item bbp-user-favorite-count <?php 
                if (bbp_is_user_home() && bbp_is_favorites()) {
                    echo 'active';
                }
                ?>
" title="<?php 
                printf(esc_attr__("Your Favorites", 'ipt_kb'));
                ?>
">
						<span class="glyphicon ipt-icomoon-heart"></span> <?php 
                printf(__('%s Favorites', 'ipt_kb'), '<span class="badge">' . count(bbp_get_user_favorites_topic_ids(bbp_get_current_user_id())) . '</span>');
                ?>
					</a>
					<?php 
            }
            ?>
					<?php 
            if (bbp_is_subscriptions_active()) {
                ?>
					<a href="<?php 
                bbp_subscriptions_permalink(bbp_get_current_user_id());
                ?>
" class="list-group-item bbp-user-subscribe-count <?php 
                if (bbp_is_user_home() && bbp_is_subscriptions()) {
                    echo 'active';
                }
                ?>
" title="<?php 
                printf(esc_attr__("Your Subscriptions", 'ipt_kb'));
                ?>
">
						<span class="glyphicon ipt-icomoon-bookmarks"></span> <?php 
                printf(__('%s Subscriptions', 'ipt_kb'), '<span class="badge">' . count(bbp_get_user_subscribed_topic_ids(bbp_get_current_user_id())) . '</span>');
                ?>
					</a>
					<?php 
            }
            ?>
				</div>
			</div>

		<?php 
        }
        echo $args['after_widget'];
    }
Пример #18
0
/**
 * Checks if user is not active.
 * 
 * @since bbPress (r3502)
 * 
 * @uses is_user_logged_in() To check if user is logged in
 * @uses bbp_get_displayed_user_id() To get current user ID
 * @uses bbp_is_user_active() To check if user is active
 *
 * @param int $user_id The user ID to check. Defaults to current user ID
 * @return bool True if inactive, false if active
 */
function bbp_is_user_inactive($user_id = 0)
{
    // Default to current user
    if (empty($user_id) && is_user_logged_in()) {
        $user_id = bbp_get_current_user_id();
    }
    // No user to check
    if (empty($user_id)) {
        return false;
    }
    // Return the inverse of active
    return !bbp_is_user_active($user_id);
}
Пример #19
0
    /**
     * Displays the output, the login form
     *
     * @since bbPress (r2827)
     *
     * @param mixed $args Arguments
     * @param array $instance Instance
     * @uses apply_filters() Calls 'bbp_login_widget_title' with the title
     * @uses get_template_part() To get the login/logged in form
     */
    public function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('bbp_login_widget_title', $instance['title']);
        $register = apply_filters('bbp_login_widget_register', $instance['register']);
        $lostpass = apply_filters('bbp_login_widget_lostpass', $instance['lostpass']);
        echo $before_widget;
        if (!empty($title)) {
            echo $before_title . $title . $after_title;
        }
        if (!is_user_logged_in()) {
            ?>

			<form method="post" action="<?php 
            bbp_wp_login_action(array('context' => 'login_post'));
            ?>
" class="bbp-login-form">
				<fieldset>
					<legend><?php 
            _e('Log In', 'bbpress');
            ?>
</legend>

					<div class="bbp-username">
						<label for="user_login"><?php 
            _e('Username', 'bbpress');
            ?>
: </label>
						<input type="text" name="log" value="<?php 
            bbp_sanitize_val('user_login', 'text');
            ?>
" size="20" id="user_login" tabindex="<?php 
            bbp_tab_index();
            ?>
" />
					</div>

					<div class="bbp-password">
						<label for="user_pass"><?php 
            _e('Password', 'bbpress');
            ?>
: </label>
						<input type="password" name="pwd" value="<?php 
            bbp_sanitize_val('user_pass', 'password');
            ?>
" size="20" id="user_pass" tabindex="<?php 
            bbp_tab_index();
            ?>
" />
					</div>

					<div class="bbp-remember-me">
						<input type="checkbox" name="rememberme" value="forever" <?php 
            checked(bbp_get_sanitize_val('rememberme', 'checkbox'), true, true);
            ?>
 id="rememberme" tabindex="<?php 
            bbp_tab_index();
            ?>
" />
						<label for="rememberme"><?php 
            _e('Remember Me', 'bbpress');
            ?>
</label>
					</div>

					<div class="bbp-submit-wrapper">

						<?php 
            do_action('login_form');
            ?>

						<button type="submit" name="user-submit" id="user-submit" tabindex="<?php 
            bbp_tab_index();
            ?>
" class="button submit user-submit"><?php 
            _e('Log In', 'bbpress');
            ?>
</button>

						<?php 
            bbp_user_login_fields();
            ?>

					</div>

					<?php 
            if (!empty($register) || !empty($lostpass)) {
                ?>

						<div class="bbp-login-links">

							<?php 
                if (!empty($register)) {
                    ?>

								<a href="<?php 
                    echo esc_url($register);
                    ?>
" title="<?php 
                    _e('Register', 'bbpress');
                    ?>
" class="bbp-register-link"><?php 
                    _e('Register', 'bbpress');
                    ?>
</a>

							<?php 
                }
                ?>

							<?php 
                if (!empty($lostpass)) {
                    ?>

								<a href="<?php 
                    echo esc_url($lostpass);
                    ?>
" title="<?php 
                    _e('Lost Password', 'bbpress');
                    ?>
" class="bbp-lostpass-link"><?php 
                    _e('Lost Password', 'bbpress');
                    ?>
</a>

							<?php 
                }
                ?>

						</div>

					<?php 
            }
            ?>

				</fieldset>
			</form>

		<?php 
        } else {
            ?>

			<div class="bbp-logged-in">
				<a href="<?php 
            bbp_user_profile_url(bbp_get_current_user_id());
            ?>
" class="submit user-submit"><?php 
            echo get_avatar(bbp_get_current_user_id(), '40');
            ?>
</a>
				<h4><?php 
            bbp_user_profile_link(bbp_get_current_user_id());
            ?>
</h4>

				<?php 
            bbp_logout_link();
            ?>
			</div>

		<?php 
        }
        echo $after_widget;
    }
 /**
  * Subscribe/Unsubscribe a user from a topic
  *
  * @since bbPress (r3732)
  *
  * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
  * @uses bbp_get_current_user_id() To get the current user id
  * @uses current_user_can() To check if the current user can edit the user
  * @uses bbp_get_topic() To get the topic
  * @uses check_ajax_referer() To verify the nonce & check the referer
  * @uses bbp_is_user_subscribed() To check if the topic is in user's
  *                                 subscriptions
  * @uses bbp_remove_user_subscriptions() To remove the topic from user's
  *                                        subscriptions
  * @uses bbp_add_user_subscriptions() To add the topic from user's subscriptions
  */
 public function ajax_subscription()
 {
     if (!bbp_is_subscriptions_active()) {
         return;
     }
     $user_id = bbp_get_current_user_id();
     $id = intval($_POST['id']);
     if (!current_user_can('edit_user', $user_id)) {
         die('-1');
     }
     $topic = bbp_get_topic($id);
     if (empty($topic)) {
         die('0');
     }
     check_ajax_referer('toggle-subscription_' . $topic->ID);
     if (bbp_is_user_subscribed($user_id, $topic->ID)) {
         if (bbp_remove_user_subscription($user_id, $topic->ID)) {
             die('1');
         }
     } else {
         if (bbp_add_user_subscription($user_id, $topic->ID)) {
             die('1');
         }
     }
     die('0');
 }
						<?php 
        do_action('bbp_theme_before_reply_form_subscription');
        ?>

						<p>

							<input name="bbp_topic_subscription" id="bbp_topic_subscription" type="checkbox" value="bbp_subscribe"<?php 
        bbp_form_topic_subscribed();
        ?>
 tabindex="<?php 
        bbp_tab_index();
        ?>
" />

							<?php 
        if (bbp_is_reply_edit() && get_the_author_meta('ID') != bbp_get_current_user_id()) {
            ?>

								<label for="bbp_topic_subscription"><?php 
            _e('Notify the author of follow-up replies via email', 'bbpress');
            ?>
</label>

							<?php 
        } else {
            ?>

								<label for="bbp_topic_subscription"><?php 
            _e('Notify me of follow-up replies via email', 'bbpress');
            ?>
</label>
Пример #22
0
/**
 * Check if the user can access a specific forum
 *
 * @since 2.0.0 bbPress (r3127)
 *
 * @uses bbp_get_current_user_id()
 * @uses bbp_get_forum_id()
 * @uses bbp_allow_anonymous()
 * @uses bbp_parse_args()
 * @uses bbp_get_user_id()
 * @uses current_user_can()
 * @uses bbp_is_user_keymaster()
 * @uses bbp_is_forum_public()
 * @uses bbp_is_forum_private()
 * @uses bbp_is_forum_hidden()
 * @uses current_user_can()
 * @uses apply_filters()
 *
 * @return bool
 */
function bbp_user_can_view_forum($args = array())
{
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('user_id' => bbp_get_current_user_id(), 'forum_id' => bbp_get_forum_id(), 'check_ancestors' => false), 'user_can_view_forum');
    // Validate parsed values
    $user_id = bbp_get_user_id($r['user_id'], false, false);
    $forum_id = bbp_get_forum_id($r['forum_id']);
    $retval = false;
    // User is a keymaster
    if (!empty($user_id) && bbp_is_user_keymaster($user_id)) {
        $retval = true;
        // Forum is public, and user can read forums or is not logged in
    } elseif (bbp_is_forum_public($forum_id, $r['check_ancestors'])) {
        $retval = true;
        // Forum is private, and user can see it
    } elseif (bbp_is_forum_private($forum_id, $r['check_ancestors']) && user_can($user_id, 'read_private_forums')) {
        $retval = true;
        // Forum is hidden, and user can see it
    } elseif (bbp_is_forum_hidden($forum_id, $r['check_ancestors']) && user_can($user_id, 'read_hidden_forums')) {
        $retval = true;
    }
    return apply_filters('bbp_user_can_view_forum', $retval, $forum_id, $user_id);
}
Пример #23
0
/**
 * Handle all the extra meta stuff from posting a new topic
 *
 * @param int $topic_id Optional. Topic id
 * @param int $forum_id Optional. Forum id
 * @param bool|array $anonymous_data Optional logged-out user data.
 * @param int $author_id Author id
 * @param bool $is_edit Optional. Is the post being edited? Defaults to false.
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_forum_id() To get the forum id
 * @uses bbp_get_current_user_id() To get the current user id
 * @yses bbp_get_topic_forum_id() To get the topic forum id
 * @uses update_post_meta() To update the topic metas
 * @uses set_transient() To update the flood check transient for the ip
 * @uses bbp_update_user_last_posted() To update the users last posted time
 * @uses bbp_is_subscriptions_active() To check if the subscriptions feature is
 *                                      activated or not
 * @uses bbp_is_user_subscribed() To check if the user is subscribed
 * @uses bbp_remove_user_subscription() To remove the user's subscription
 * @uses bbp_add_user_subscription() To add the user's subscription
 * @uses bbp_update_topic_forum_id() To update the topic's forum id
 * @uses bbp_update_topic_topic_id() To update the topic's topic id
 * @uses bbp_update_topic_last_reply_id() To update the last reply id topic meta
 * @uses bbp_update_topic_last_active_id() To update the topic last active id
 * @uses bbp_update_topic_last_active_time() To update the last active topic meta
 * @uses bbp_update_topic_reply_count() To update the topic reply count
 * @uses bbp_update_topic_reply_count_hidden() To udpate the topic hidden reply count
 * @uses bbp_update_topic_voice_count() To update the topic voice count
 * @uses bbp_update_topic_walker() To udpate the topic's ancestors
 */
function bbp_update_topic($topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false)
{
    // Validate the ID's passed from 'bbp_new_topic' action
    $topic_id = bbp_get_topic_id($topic_id);
    $forum_id = bbp_get_forum_id($forum_id);
    // Bail if there is no topic
    if (empty($topic_id)) {
        return;
    }
    // Check author_id
    if (empty($author_id)) {
        $author_id = bbp_get_current_user_id();
    }
    // Check forum_id
    if (empty($forum_id)) {
        $forum_id = bbp_get_topic_forum_id($topic_id);
    }
    // If anonymous post, store name, email, website and ip in post_meta.
    // It expects anonymous_data to be sanitized.
    // Check bbp_filter_anonymous_post_data() for sanitization.
    if (!empty($anonymous_data) && is_array($anonymous_data)) {
        // Parse arguments against default values
        $r = bbp_parse_args($anonymous_data, array('bbp_anonymous_name' => '', 'bbp_anonymous_email' => '', 'bbp_anonymous_website' => ''), 'update_topic');
        // Update all anonymous metas
        foreach ($r as $anon_key => $anon_value) {
            update_post_meta($topic_id, '_' . $anon_key, (string) $anon_value, false);
        }
        // Set transient for throttle check (only on new, not edit)
        if (empty($is_edit)) {
            set_transient('_bbp_' . bbp_current_author_ip() . '_last_posted', time());
        }
    } else {
        if (empty($is_edit) && !current_user_can('throttle')) {
            bbp_update_user_last_posted($author_id);
        }
    }
    // Handle Subscription Checkbox
    if (bbp_is_subscriptions_active() && !empty($author_id)) {
        $subscribed = bbp_is_user_subscribed($author_id, $topic_id);
        $subscheck = !empty($_POST['bbp_topic_subscription']) && 'bbp_subscribe' === $_POST['bbp_topic_subscription'] ? true : false;
        // Subscribed and unsubscribing
        if (true === $subscribed && false === $subscheck) {
            bbp_remove_user_subscription($author_id, $topic_id);
            // Subscribing
        } elseif (false === $subscribed && true === $subscheck) {
            bbp_add_user_subscription($author_id, $topic_id);
        }
    }
    // Forum topic meta
    bbp_update_topic_forum_id($topic_id, $forum_id);
    bbp_update_topic_topic_id($topic_id, $topic_id);
    // Update associated topic values if this is a new topic
    if (empty($is_edit)) {
        // Update poster IP if not editing
        update_post_meta($topic_id, '_bbp_author_ip', bbp_current_author_ip(), false);
        // Last active time
        $last_active = current_time('mysql');
        // Reply topic meta
        bbp_update_topic_last_reply_id($topic_id, 0);
        bbp_update_topic_last_active_id($topic_id, $topic_id);
        bbp_update_topic_last_active_time($topic_id, $last_active);
        bbp_update_topic_reply_count($topic_id, 0);
        bbp_update_topic_reply_count_hidden($topic_id, 0);
        bbp_update_topic_voice_count($topic_id);
        // Walk up ancestors and do the dirty work
        bbp_update_topic_walker($topic_id, $last_active, $forum_id, 0, false);
    }
}
Пример #24
0
 /**
  * AJAX handler to Subscribe/Unsubscribe a user from a topic
  *
  * @since bbPress (r3732)
  *
  * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
  * @uses bbp_is_user_logged_in() To check if user is logged in
  * @uses bbp_get_current_user_id() To get the current user id
  * @uses current_user_can() To check if the current user can edit the user
  * @uses bbp_get_topic() To get the topic
  * @uses wp_verify_nonce() To verify the nonce
  * @uses bbp_is_user_subscribed() To check if the topic is in user's subscriptions
  * @uses bbp_remove_user_subscriptions() To remove the topic from user's subscriptions
  * @uses bbp_add_user_subscriptions() To add the topic from user's subscriptions
  * @uses bbp_ajax_response() To return JSON
  */
 public function ajax_subscription()
 {
     // Bail if subscriptions are not active
     if (!bbp_is_subscriptions_active()) {
         bbp_ajax_response(false, __('Subscriptions are no longer active.', 'bbpress'), 300);
     }
     // Bail if user is not logged in
     if (!is_user_logged_in()) {
         bbp_ajax_response(false, __('Please login to subscribe to this topic.', 'bbpress'), 301);
     }
     // Get user and topic data
     $user_id = bbp_get_current_user_id();
     $id = intval($_POST['id']);
     // Bail if user cannot add favorites for this user
     if (!current_user_can('edit_user', $user_id)) {
         bbp_ajax_response(false, __('You do not have permission to do this.', 'bbpress'), 302);
     }
     // Get the topic
     $topic = bbp_get_topic($id);
     // Bail if topic cannot be found
     if (empty($topic)) {
         bbp_ajax_response(false, __('The topic could not be found.', 'bbpress'), 303);
     }
     // Bail if user did not take this action
     if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'toggle-subscription_' . $topic->ID)) {
         bbp_ajax_response(false, __('Are you sure you meant to do that?', 'bbpress'), 304);
     }
     // Take action
     $status = bbp_is_user_subscribed($user_id, $topic->ID) ? bbp_remove_user_subscription($user_id, $topic->ID) : bbp_add_user_subscription($user_id, $topic->ID);
     // Bail if action failed
     if (empty($status)) {
         bbp_ajax_response(false, __('The request was unsuccessful. Please try again.', 'bbpress'), 305);
     }
     // Put subscription attributes in convenient array
     $attrs = array('topic_id' => $topic->ID, 'user_id' => $user_id);
     // Action succeeded
     bbp_ajax_response(true, bbp_get_user_subscribe_link($attrs, $user_id, false), 200);
 }
Пример #25
0
 /**
  * Process bulk dropdown form submission from the WordPress Users
  * Table
  *
  * @uses current_user_can() to check for 'promote users' capability
  * @uses bbp_get_dynamic_roles() to get forum roles
  * @uses bbp_get_user_role() to get a user's current forums role
  * @uses bbp_set_user_role() to set the user's new forums role
  * @return bool Always false
  */
 public function user_role_bulk_change()
 {
     // Bail if no users specified
     if (empty($_REQUEST['users'])) {
         return;
     }
     // Bail if this isn't a bbPress action
     if (empty($_REQUEST['bbp-new-role']) || empty($_REQUEST['bbp-change-role'])) {
         return;
     }
     // Check that the new role exists
     $dynamic_roles = bbp_get_dynamic_roles();
     if (empty($dynamic_roles[$_REQUEST['bbp-new-role']])) {
         return;
     }
     // Bail if nonce check fails
     check_admin_referer('bbp-bulk-users', 'bbp-bulk-users-nonce');
     // Bail if current user cannot promote users
     if (!current_user_can('promote_users')) {
         return;
     }
     // Get the current user ID
     $current_user_id = (int) bbp_get_current_user_id();
     // Run through user ids
     foreach ((array) $_REQUEST['users'] as $user_id) {
         $user_id = (int) $user_id;
         // Don't let a user change their own role
         if ($user_id === $current_user_id) {
             continue;
         }
         // Set up user and role data
         $user_role = bbp_get_user_role($user_id);
         $new_role = sanitize_text_field($_REQUEST['bbp-new-role']);
         // Only keymasters can set other keymasters
         if (in_array(bbp_get_keymaster_role(), array($user_role, $new_role)) && !bbp_is_user_keymaster()) {
             continue;
         }
         // Set the new forums role
         if ($new_role !== $user_role) {
             bbp_set_user_role($user_id, $new_role);
         }
     }
 }
Пример #26
0
 /**
  * Subscribe/Unsubscribe a user from a topic
  *
  * @since bbPress (r2668)
  *
  * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
  * @uses bbp_get_current_user_id() To get the current user id
  * @uses current_user_can() To check if the current user can edit the user
  * @uses bbp_get_topic() To get the topic
  * @uses check_ajax_referer() To verify the nonce & check the referer
  * @uses bbp_is_user_subscribed() To check if the topic is in user's
  *                                 subscriptions
  * @uses bbp_remove_user_subscriptions() To remove the topic from user's
  *                                        subscriptions
  * @uses bbp_add_user_subscriptions() To add the topic from user's subscriptions
  */
 function bbp_skeleton_dim_subscription()
 {
     if (!bbp_is_subscriptions_active()) {
         return;
     }
     $user_id = bbp_get_current_user_id();
     $id = intval($_POST['id']);
     if (!current_user_can('edit_user', $user_id)) {
         die('-1');
     }
     if (!($topic = bbp_get_topic($id))) {
         die('0');
     }
     check_ajax_referer("toggle-subscription_{$topic->ID}");
     if (bbp_is_user_subscribed($user_id, $topic->ID)) {
         if (bbp_remove_user_subscription($user_id, $topic->ID)) {
             die('1');
         }
     } else {
         if (bbp_add_user_subscription($user_id, $topic->ID)) {
             die('1');
         }
     }
     die('0');
 }
Пример #27
0
						<?php 
        do_action('bbp_theme_before_reply_form_subscription');
        ?>

						<p>

							<input name="bbp_topic_subscription" id="bbp_topic_subscription" type="checkbox" value="bbp_subscribe"<?php 
        bbp_form_topic_subscribed();
        ?>
 tabindex="<?php 
        bbp_tab_index();
        ?>
" />

							<?php 
        if (bbp_is_reply_edit() && bbp_get_reply_author_id() !== bbp_get_current_user_id()) {
            ?>

								<label for="bbp_topic_subscription"><?php 
            esc_html_e('Notify the author of follow-up replies via email', 'monsoon');
            ?>
</label>

							<?php 
        } else {
            ?>

								<label for="bbp_topic_subscription"><?php 
            esc_html_e('Notify me of follow-up replies via email', 'monsoon');
            ?>
</label>
Пример #28
0
 /**
  * Wrapper for recoding bbPress actions to the BuddyPress activity stream
  *
  * @since bbPress (r3395)
  * @param type $args Array of arguments for bp_activity_add()
  * @uses bbp_get_current_user_id()
  * @uses bp_core_current_time()
  * @uses bbp_parse_args()
  * @uses aplly_filters()
  * @uses bp_activity_add()
  * @return type Activity ID if successful, false if not
  */
 private function record_activity($args = '')
 {
     // Default activity args
     $activity = bbp_parse_args($args, array('id' => null, 'user_id' => bbp_get_current_user_id(), 'type' => '', 'action' => '', 'item_id' => '', 'secondary_item_id' => '', 'content' => '', 'primary_link' => '', 'component' => $this->component, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false), 'record_activity');
     // Add the activity
     return bp_activity_add($activity);
 }
Пример #29
0
function kleo_bp_replace_placeholders($output)
{
    $initial_output = $output;
    if (strpos($output, '##profile_link##') !== false) {
        if (!is_user_logged_in()) {
            return '';
        }
        if (function_exists('bp_is_active')) {
            $logged_in_link = bp_loggedin_user_domain('/');
            $output = str_replace('##profile_link##', $logged_in_link, $output);
        } elseif (class_exists('bbPress')) {
            //$logged_in_link = bb_get_profile_link();
            $logged_in_link = bbp_get_user_profile_url(bbp_get_current_user_id());
            $output = str_replace('##profile_link##', $logged_in_link, $output);
        }
    }
    if (strpos($output, '##member_name##') !== false) {
        if (!is_user_logged_in()) {
            return '';
        }
        if (function_exists('bp_is_active')) {
            $logged_in_username = bp_get_loggedin_user_fullname();
            $output = str_replace('##member_name##', $logged_in_username, $output);
        } elseif (class_exists('bbPress')) {
            $logged_in_username = bbp_get_user_nicename(bbp_get_current_user_id());
            $output = str_replace('##member_name##', $logged_in_username, $output);
        }
    }
    $output = apply_filters('kleo_bp_replace_placeholders', $output, $initial_output);
    return $output;
}
/**
 * Checks if user is a keymaster
 *
 * @since bbPress (r4783)
 *
 * @param int $user_id 
 * @return bool True if keymaster, false if not
 */
function bbp_is_user_keymaster($user_id = 0)
{
    // Default to current user ID if none is passed
    $_user_id = (int) (!empty($user_id)) ? $user_id : bbp_get_current_user_id();
    // Filter and return
    return (bool) apply_filters('bbp_is_user_keymaster', user_can($_user_id, 'keep_gate'), $_user_id, $user_id);
}