本文整理汇总了PHP中bbp_remove_user_subscription函数的典型用法代码示例。如果您正苦于以下问题:PHP bbp_remove_user_subscription函数的具体用法?PHP bbp_remove_user_subscription怎么用?PHP bbp_remove_user_subscription使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bbp_remove_user_subscription函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bbp_remove_topic_from_all_subscriptions
/**
* Remove a deleted topic from all users' subscriptions
*
* @since bbPress (r2652)
*
* @param int $topic_id Get the topic id to remove
* @uses bbp_is_subscriptions_active() To check if the subscriptions are active
* @uses bbp_get_topic_id To get the topic id
* @uses bbp_get_topic_subscribers() To get the topic subscribers
* @uses bbp_remove_user_subscription() To remove the user subscription
*/
function bbp_remove_topic_from_all_subscriptions($topic_id = 0)
{
// Subscriptions are not active
if (!bbp_is_subscriptions_active()) {
return;
}
$topic_id = bbp_get_topic_id($topic_id);
// Bail if no topic
if (empty($topic_id)) {
return;
}
// Get users
$users = (array) bbp_get_topic_subscribers($topic_id);
// Users exist
if (!empty($users)) {
// Loop through users
foreach ($users as $user) {
// Remove each user
bbp_remove_user_subscription($user, $topic_id);
}
}
}
示例2: bbp_update_reply
/**
* Handle all the extra meta stuff from posting a new reply or editing a reply
*
* @param int $reply_id Optional. Reply id
* @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.
* @param int $reply_to Optional. Reply to id
* @uses bbp_get_reply_id() To get the reply id
* @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
* @uses bbp_get_reply_topic_id() To get the reply topic id
* @uses bbp_get_topic_forum_id() To get the topic forum id
* @uses update_post_meta() To update the reply 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_reply_forum_id() To update the reply forum id
* @uses bbp_update_reply_topic_id() To update the reply topic id
* @uses bbp_update_reply_to() To update the reply to id
* @uses bbp_update_reply_walker() To update the reply's ancestors' counts
*/
function bbp_update_reply($reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $author_id = 0, $is_edit = false, $reply_to = 0)
{
// Validate the ID's passed from 'bbp_new_reply' action
$reply_id = bbp_get_reply_id($reply_id);
$topic_id = bbp_get_topic_id($topic_id);
$forum_id = bbp_get_forum_id($forum_id);
$reply_to = bbp_validate_reply_to($reply_to);
// Bail if there is no reply
if (empty($reply_id)) {
return;
}
// Check author_id
if (empty($author_id)) {
$author_id = bbp_get_current_user_id();
}
// Check topic_id
if (empty($topic_id)) {
$topic_id = bbp_get_reply_topic_id($reply_id);
}
// Check forum_id
if (!empty($topic_id) && 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_reply');
// Update all anonymous metas
foreach ($r as $anon_key => $anon_value) {
update_post_meta($reply_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) && !empty($topic_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);
}
}
// Reply meta relating to reply position in tree
bbp_update_reply_forum_id($reply_id, $forum_id);
bbp_update_reply_topic_id($reply_id, $topic_id);
bbp_update_reply_to($reply_id, $reply_to);
// Update associated topic values if this is a new reply
if (empty($is_edit)) {
// Update poster IP if not editing
update_post_meta($reply_id, '_bbp_author_ip', bbp_current_author_ip(), false);
// Last active time
$last_active_time = current_time('mysql');
// Walk up ancestors and do the dirty work
bbp_update_reply_walker($reply_id, $last_active_time, $forum_id, $topic_id, false);
}
}
示例3: bbp_subscriptions_handler
/**
* Handles the front end subscribing and unsubscribing topics
*
* @uses bbp_is_subscriptions_active() To check if the subscriptions are active
* @uses bbp_get_user_id() To get the user id
* @uses bbp_verify_nonce_request() To verify the nonce and check the request
* @uses current_user_can() To check if the current user can edit the user
* @uses bbPress:errors:add() To log the error messages
* @uses bbp_is_user_subscribed() To check if the topic is in user's
* subscriptions
* @uses bbp_remove_user_subscription() To remove the user subscription
* @uses bbp_add_user_subscription() To add the user subscription
* @uses do_action() Calls 'bbp_subscriptions_handler' with success, user id,
* topic id and action
* @uses bbp_is_subscription() To check if it's the subscription page
* @uses bbp_get_subscription_link() To get the subscription page link
* @uses bbp_get_topic_permalink() To get the topic permalink
* @uses wp_safe_redirect() To redirect to the url
*/
function bbp_subscriptions_handler()
{
if (!bbp_is_subscriptions_active()) {
return false;
}
// Bail if not a GET action
if ('GET' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
return;
}
// Bail if required GET actions aren't passed
if (empty($_GET['topic_id']) || empty($_GET['action'])) {
return;
}
// Setup possible get actions
$possible_actions = array('bbp_subscribe', 'bbp_unsubscribe');
// Bail if actions aren't meant for this function
if (!in_array($_GET['action'], $possible_actions)) {
return;
}
// Get required data
$action = $_GET['action'];
$user_id = bbp_get_user_id(0, true, true);
$topic_id = intval($_GET['topic_id']);
// Check for empty topic
if (empty($topic_id)) {
bbp_add_error('bbp_subscription_topic_id', __('<strong>ERROR</strong>: No topic was found! Which topic are you subscribing/unsubscribing to?', 'bbpress'));
// Check nonce
} elseif (!bbp_verify_nonce_request('toggle-subscription_' . $topic_id)) {
bbp_add_error('bbp_subscription_topic_id', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
// Check current user's ability to edit the user
} elseif (!current_user_can('edit_user', $user_id)) {
bbp_add_error('bbp_subscription_permissions', __('<strong>ERROR</strong>: You don\'t have the permission to edit favorites of that user!', 'bbpress'));
}
// Bail if we have errors
if (bbp_has_errors()) {
return;
}
/** No errors *************************************************************/
$is_subscription = bbp_is_user_subscribed($user_id, $topic_id);
$success = false;
if (true == $is_subscription && 'bbp_unsubscribe' == $action) {
$success = bbp_remove_user_subscription($user_id, $topic_id);
} elseif (false == $is_subscription && 'bbp_subscribe' == $action) {
$success = bbp_add_user_subscription($user_id, $topic_id);
}
// Do additional subscriptions actions
do_action('bbp_subscriptions_handler', $success, $user_id, $topic_id, $action);
// Success!
if (true == $success) {
// Redirect back from whence we came
if (bbp_is_subscriptions()) {
$redirect = bbp_get_subscriptions_permalink($user_id);
} elseif (bbp_is_single_user()) {
$redirect = bbp_get_user_profile_url();
} elseif (is_singular(bbp_get_topic_post_type())) {
$redirect = bbp_get_topic_permalink($topic_id);
} elseif (is_single() || is_page()) {
$redirect = get_permalink();
}
wp_safe_redirect($redirect);
// For good measure
exit;
// Fail! Handle errors
} elseif (true == $is_subscription && 'bbp_unsubscribe' == $action) {
bbp_add_error('bbp_unsubscribe', __('<strong>ERROR</strong>: There was a problem unsubscribing from that topic!', 'bbpress'));
} elseif (false == $is_subscription && 'bbp_subscribe' == $action) {
bbp_add_error('bbp_subscribe', __('<strong>ERROR</strong>: There was a problem subscribing to that topic!', 'bbpress'));
}
}
示例4: bbps_unclaim_topic
function bbps_unclaim_topic()
{
$user_id = $_GET['user_id'];
$topic_id = $_GET['topic_id'];
//subscribe the user to the topic - this is a bbpress function
bbp_remove_user_subscription($user_id, $topic_id);
//reupdate the postmeta with an id of 0 this is unclaimed now
delete_post_meta($topic_id, '_bbps_topic_claimed');
}
示例5: bbp_skeleton_dim_subscription
/**
* 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');
}
示例6: ajax_subscription
/**
* 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);
}
示例7: ajax_subscription
/**
* 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');
}
示例8: test_bbp_remove_user_subscription
/**
* @covers ::bbp_remove_user_subscription
*/
public function test_bbp_remove_user_subscription()
{
$u = $this->factory->user->create();
$f = $this->factory->forum->create();
$t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
// Add forum subscription.
bbp_add_user_subscription($u, $f);
$this->assertTrue(bbp_is_user_subscribed_to_forum($u, $f));
// Remove forum subscription.
bbp_remove_user_subscription($u, $f);
$this->assertFalse(bbp_is_user_subscribed_to_forum($u, $f));
// Add topic subscription.
bbp_add_user_subscription($u, $t);
$this->assertTrue(bbp_is_user_subscribed_to_topic($u, $t));
// Remove topic subscription.
bbp_remove_user_subscription($u, $t);
$this->assertFalse(bbp_is_user_subscribed_to_topic($u, $t));
}