当前位置: 首页>>代码示例>>PHP>>正文


PHP bbp_add_user_favorite函数代码示例

本文整理汇总了PHP中bbp_add_user_favorite函数的典型用法代码示例。如果您正苦于以下问题:PHP bbp_add_user_favorite函数的具体用法?PHP bbp_add_user_favorite怎么用?PHP bbp_add_user_favorite使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了bbp_add_user_favorite函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: bbPress_ajax_favorite

 function bbPress_ajax_favorite()
 {
     $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-favorite_' . $topic->ID);
     if (bbp_is_user_favorite($user_id, $topic->ID)) {
         if (bbp_remove_user_favorite($user_id, $topic->ID)) {
             die('1');
         }
     } else {
         if (bbp_add_user_favorite($user_id, $topic->ID)) {
             die('1');
         }
     }
     die('0');
 }
开发者ID:perusoa,项目名称:anthony-peruso-website,代码行数:22,代码来源:bbpress.php

示例2: bbp_split_topic_handler


//.........这里部分代码省略.........
        return;
    }
    /** No Errors - Do the Spit ***********************************************/
    // Update counts, etc...
    do_action('bbp_pre_split_topic', $from_reply->ID, $source_topic->ID, $destination_topic->ID);
    /** Date Check ************************************************************/
    // Check if the destination topic is older than the from reply
    if (strtotime($from_reply->post_date) < strtotime($destination_topic->post_date)) {
        // Set destination topic post_date to 1 second before from reply
        $destination_post_date = date('Y-m-d H:i:s', strtotime($from_reply->post_date) - 1);
        // Update destination topic
        wp_update_post(array('ID' => $destination_topic_id, 'post_date' => $destination_post_date, 'post_date_gmt' => get_gmt_from_date($destination_post_date)));
    }
    /** Subscriptions *********************************************************/
    // Copy the subscribers
    if (!empty($_POST['bbp_topic_subscribers']) && "1" === $_POST['bbp_topic_subscribers'] && bbp_is_subscriptions_active()) {
        // Get the subscribers
        $subscribers = bbp_get_topic_subscribers($source_topic->ID);
        if (!empty($subscribers)) {
            // Add subscribers to new topic
            foreach ((array) $subscribers as $subscriber) {
                bbp_add_user_subscription($subscriber, $destination_topic->ID);
            }
        }
    }
    /** Favorites *************************************************************/
    // Copy the favoriters if told to
    if (!empty($_POST['bbp_topic_favoriters']) && "1" === $_POST['bbp_topic_favoriters']) {
        // Get the favoriters
        $favoriters = bbp_get_topic_favoriters($source_topic->ID);
        if (!empty($favoriters)) {
            // Add the favoriters to new topic
            foreach ((array) $favoriters as $favoriter) {
                bbp_add_user_favorite($favoriter, $destination_topic->ID);
            }
        }
    }
    /** Tags ******************************************************************/
    // Copy the tags if told to
    if (!empty($_POST['bbp_topic_tags']) && "1" === $_POST['bbp_topic_tags']) {
        // Get the source topic tags
        $source_topic_tags = wp_get_post_terms($source_topic->ID, bbp_get_topic_tag_tax_id(), array('fields' => 'names'));
        if (!empty($source_topic_tags)) {
            wp_set_post_terms($destination_topic->ID, $source_topic_tags, bbp_get_topic_tag_tax_id(), true);
        }
    }
    /** Split Replies *********************************************************/
    // get_posts() is not used because it doesn't allow us to use '>='
    // comparision without a filter.
    $replies = (array) $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_date >= %s AND {$wpdb->posts}.post_parent = %d AND {$wpdb->posts}.post_type = %s ORDER BY {$wpdb->posts}.post_date ASC", $from_reply->post_date, $source_topic->ID, bbp_get_reply_post_type()));
    // Make sure there are replies to loop through
    if (!empty($replies) && !is_wp_error($replies)) {
        // Calculate starting point for reply positions
        switch ($split_option) {
            // Get topic reply count for existing topic
            case 'existing':
                $reply_position = bbp_get_topic_reply_count($destination_topic->ID);
                break;
                // Account for new lead topic
            // Account for new lead topic
            case 'reply':
                $reply_position = 1;
                break;
        }
        // Save reply ids
        $reply_ids = array();
开发者ID:jenia-buianov,项目名称:all_my_sites,代码行数:67,代码来源:functions.php

示例3: bbp_favorites_handler

/**
 * Handles the front end adding and removing of favorite topics
 *
 * @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_favorite() To check if the topic is in user's favorites
 * @uses bbp_remove_user_favorite() To remove the user favorite
 * @uses bbp_add_user_favorite() To add the user favorite
 * @uses do_action() Calls 'bbp_favorites_handler' with success, user id, topic
 *                    id and action
 * @uses bbp_is_favorites() To check if it's the favorites page
 * @uses bbp_get_favorites_link() To get the favorites page link
 * @uses bbp_get_topic_permalink() To get the topic permalink
 * @uses wp_safe_redirect() To redirect to the url
 */
function bbp_favorites_handler()
{
    if (!bbp_is_favorites_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_favorite_add', 'bbp_favorite_remove');
    // Bail if actions aren't meant for this function
    if (!in_array($_GET['action'], $possible_actions)) {
        return;
    }
    // What action is taking place?
    $action = $_GET['action'];
    $topic_id = intval($_GET['topic_id']);
    $user_id = bbp_get_user_id(0, true, true);
    // Check for empty topic
    if (empty($topic_id)) {
        bbp_add_error('bbp_favorite_topic_id', __('<strong>ERROR</strong>: No topic was found! Which topic are you marking/unmarking as favorite?', 'bbpress'));
        // Check nonce
    } elseif (!bbp_verify_nonce_request('toggle-favorite_' . $topic_id)) {
        bbp_add_error('bbp_favorite_nonce', __('<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_favorite_permissions', __('<strong>ERROR</strong>: You don\'t have the permission to edit favorites of that user!', 'bbpress'));
    }
    // Bail if errors
    if (bbp_has_errors()) {
        return;
    }
    /** No errors *************************************************************/
    $is_favorite = bbp_is_user_favorite($user_id, $topic_id);
    $success = false;
    if (true == $is_favorite && 'bbp_favorite_remove' == $action) {
        $success = bbp_remove_user_favorite($user_id, $topic_id);
    } elseif (false == $is_favorite && 'bbp_favorite_add' == $action) {
        $success = bbp_add_user_favorite($user_id, $topic_id);
    }
    // Do additional favorites actions
    do_action('bbp_favorites_handler', $success, $user_id, $topic_id, $action);
    // Success!
    if (true == $success) {
        // Redirect back from whence we came
        if (bbp_is_favorites()) {
            $redirect = bbp_get_favorites_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_favorite && 'bbp_favorite_remove' == $action) {
        bbp_add_error('bbp_favorite_remove', __('<strong>ERROR</strong>: There was a problem removing that topic from favorites!', 'bbpress'));
    } elseif (false == $is_favorite && 'bbp_favorite_add' == $action) {
        bbp_add_error('bbp_favorite_add', __('<strong>ERROR</strong>: There was a problem favoriting that topic!', 'bbpress'));
    }
}
开发者ID:hscale,项目名称:webento,代码行数:86,代码来源:functions.php

示例4: ajax_favorite

 /**
  * AJAX handler to add or remove a topic from a user's favorites
  *
  * @since bbPress (r3732)
  *
  * @uses bbp_is_favorites_active() To check if favorites 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 & check the referer
  * @uses bbp_is_user_favorite() To check if the topic is user's favorite
  * @uses bbp_remove_user_favorite() To remove the topic from user's favorites
  * @uses bbp_add_user_favorite() To add the topic from user's favorites
  * @uses bbp_ajax_response() To return JSON
  */
 public function ajax_favorite()
 {
     // Bail if favorites are not active
     if (!bbp_is_favorites_active()) {
         bbp_ajax_response(false, __('Favorites 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 make this topic a favorite.', 'bbpress'), 301);
     }
     // Get user and topic data
     $user_id = bbp_get_current_user_id();
     $id = !empty($_POST['id']) ? intval($_POST['id']) : 0;
     // 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-favorite_' . $topic->ID)) {
         bbp_ajax_response(false, __('Are you sure you meant to do that?', 'bbpress'), 304);
     }
     // Take action
     $status = bbp_is_user_favorite($user_id, $topic->ID) ? bbp_remove_user_favorite($user_id, $topic->ID) : bbp_add_user_favorite($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_favorites_link($attrs, $user_id, false), 200);
 }
开发者ID:danielcoats,项目名称:schoolpress,代码行数:54,代码来源:bbpress-functions.php

示例5: convert_table


//.........这里部分代码省略.........
                         /** Forum Subscriptions *********************************/
                         case 'forum_subscriptions':
                             $user_id = $insert_post['user_id'];
                             if (is_numeric($user_id)) {
                                 foreach ($insert_postmeta as $key => $value) {
                                     // Only extract values from the key _bbp_forum_subscriptions
                                     if ('_bbp_forum_subscriptions' == $key) {
                                         // Get the new forum ID
                                         $forum_id = $this->callback_forumid($value);
                                         // Add the topic ID to the users subscribed forums
                                         bbp_add_user_forum_subscription($user_id, $forum_id);
                                     }
                                 }
                             }
                             break;
                             /** Subscriptions *********************************/
                         /** Subscriptions *********************************/
                         case 'topic_subscriptions':
                             $user_id = $insert_post['user_id'];
                             if (is_numeric($user_id)) {
                                 foreach ($insert_postmeta as $key => $value) {
                                     // Only extract values from the key _bbp_subscriptions
                                     if ('_bbp_subscriptions' == $key) {
                                         // Get the new topic ID
                                         $topic_id = $this->callback_topicid($value);
                                         // Add the topic ID to the users subscribed topics
                                         bbp_add_user_topic_subscription($user_id, $topic_id);
                                     }
                                 }
                             }
                             break;
                             /** Favorites *********************************/
                         /** Favorites *********************************/
                         case 'favorites':
                             $user_id = $insert_post['user_id'];
                             if (is_numeric($user_id)) {
                                 // Loop through the array
                                 foreach ($insert_postmeta as $key => $value) {
                                     // Only extract values from the key _bbp_favorites
                                     if ('_bbp_favorites' == $key) {
                                         // Our array may contain comma delimited favorites so lets explode these
                                         $insert_postmeta = explode(",", $insert_postmeta['_bbp_favorites']);
                                         // Loop through our updated exploded array
                                         foreach ($insert_postmeta as $key => $value) {
                                             // Get the new topic ID
                                             $topic_id = $this->callback_topicid($value);
                                             // Add the topic ID to the users favorites
                                             bbp_add_user_favorite($user_id, $topic_id);
                                         }
                                     }
                                 }
                             }
                             break;
                             /** Forum, Topic, Reply ***************************/
                         /** Forum, Topic, Reply ***************************/
                         default:
                             $post_id = wp_insert_post($insert_post);
                             if (is_numeric($post_id)) {
                                 foreach ($insert_postmeta as $key => $value) {
                                     add_post_meta($post_id, $key, $value, true);
                                     /**
                                      * If we are using the sync_table add
                                      * the meta '_id' keys to the table
                                      *
                                      * Forums:  _bbp_old_forum_id         // The old forum ID
                                      *          _bbp_old_forum_parent_id  // The old forum parent ID
                                      *
                                      * Topics:  _bbp_forum_id             // The new forum ID
                                      *          _bbp_old_topic_id         // The old topic ID
                                      *          _bbp_old_closed_status_id // The old topic open/closed status
                                      *          _bbp_old_sticky_status_id // The old topic sticky status
                                      *
                                      * Replies: _bbp_forum_id             // The new forum ID
                                      *          _bbp_topic_id             // The new topic ID
                                      *          _bbp_old_reply_id         // The old reply ID
                                      *          _bbp_old_reply_to_id      // The old reply to ID
                                      */
                                     if ('_id' == substr($key, -3) && true === $this->sync_table) {
                                         $this->wpdb->insert($this->sync_table_name, array('value_type' => 'post', 'value_id' => $post_id, 'meta_key' => $key, 'meta_value' => $value));
                                     }
                                     /**
                                      * Replies need to save their old reply_to ID for
                                      * hierarchical replies association. Later we update
                                      * the _bbp_reply_to value with the new bbPress
                                      * value using convert_reply_to_parents()
                                      */
                                     if ('reply' == $to_type && '_bbp_old_reply_to_id' == $key) {
                                         add_post_meta($post_id, '_bbp_reply_to', $value);
                                     }
                                 }
                             }
                             break;
                     }
                     $has_insert = true;
                 }
             }
         }
     }
     return !$has_insert;
 }
开发者ID:CompositeUK,项目名称:clone.bbPress,代码行数:101,代码来源:converter.php

示例6: test_bbp_add_user_favorite

 /**
  * @covers ::bbp_add_user_favorite
  */
 public function test_bbp_add_user_favorite()
 {
     $u = $this->factory->user->create();
     $t = $this->factory->topic->create_many(3);
     // Add topic favorites.
     update_user_option($u, '_bbp_favorites', $t[0]);
     // Add user favorite.
     bbp_add_user_favorite($u, $t[1]);
     $favorites = bbp_get_user_favorites_topic_ids($u);
     $this->assertEquals(array($t[0], $t[1]), $favorites);
     // Add user favorite.
     bbp_add_user_favorite($u, $t[2]);
     $favorites = bbp_get_user_favorites_topic_ids($u);
     $this->assertEquals(array($t[0], $t[1], $t[2]), $favorites);
 }
开发者ID:joeyblake,项目名称:bbpress,代码行数:18,代码来源:favorites.php

示例7: import

 /**
  * Perform the export
  *
  * @access public
  * @since 1.0
  * @uses bbp_Export::csv_rows_out()
  * @return void
  */
 public function import()
 {
     if (!$this->can_import()) {
         wp_die(__('You do not have permission to import data.', 'bbp-export-import'), __('Error', 'bbp-export-import'));
     }
     $csv_array = $this->csv_to_array($_FILES['bbp_csv_file']['tmp_name'], ';');
     foreach ($csv_array as $key => $line) {
         $post_args = $line;
         $meta_args = array();
         // Setup author date
         if ($post_args['anonymous'] == '1') {
             $meta_args['anonymous_email'] = $line['post_author'];
         } else {
             $user = get_user_by('email', $post_args['post_author']);
             if (!$user) {
                 // The user doesn't exist, so create them
                 $user = wp_insert_user(array('user_email' => $post_args['post_author'], 'user_login' => $post_args['user_login']));
             }
             $post_args['post_author'] = $user->ID;
         }
         // Decode content
         $post_args['post_content'] = html_entity_decode($post_args['post_content']);
         $topic_type = bbp_get_topic_post_type();
         $reply_type = bbp_get_reply_post_type();
         // Remove the post args we don't want sent to wp_insert_post
         unset($post_args['anonymous']);
         unset($post_args['user_login']);
         switch ($line['post_type']) {
             case $topic_type:
                 // Set the forum parent for topics
                 $post_args['post_parent'] = $this->forum_id;
                 $meta_args['voice_count'] = $line['voices'];
                 $meta_args['reply_count'] = $post_args['reply_count'];
                 $topic_id = bbp_insert_topic($post_args, $meta_args);
                 // Subscribe the original poster to the topic
                 bbp_add_user_subscription($post_args['post_author'], $topic_id);
                 // Add the topic to the user's favorites
                 if (bbp_is_user_favorite($post_args['post_author'], $topic_id)) {
                     bbp_add_user_favorite($post_args['post_author'], $topic_id);
                 }
                 // Set topic as resolved if GetShopped Support Forum is active
                 if ($post_args['resolved'] == '1') {
                     add_post_meta($topic_id, '_bbps_topic_status', '2');
                 }
                 break;
             case $reply_type:
                 // Set the forum parent for replies. The topic ID is created above when the replie's topic is first created
                 $post_args['post_parent'] = $topic_id;
                 $reply_id = bbp_insert_reply($post_args, $meta_args);
                 // Subscribe reply author, if not already
                 if (!bbp_is_user_subscribed($post_args['post_author'], $topic_id)) {
                     bbp_add_user_subscription($post_args['post_author'], $topic_id);
                 }
                 // Mark as favorite
                 if (bbp_is_user_favorite($post_args['post_author'], $topic_id)) {
                     bbp_add_user_favorite($post_args['post_author'], $topic_id);
                 }
                 // Check if the next row is a topic, meaning we have reached the last reply and need to update the last active time
                 if ($csv_array[$key + 1]['post_type'] == bbp_get_topic_post_type()) {
                     bbp_update_forum_last_active_time($this->forum_id, $post_args['post_date']);
                 }
                 break;
         }
     }
     // Recount forum topic / reply counts
     bbp_admin_repair_forum_topic_count();
     bbp_admin_repair_forum_reply_count();
     wp_redirect(admin_url('post.php?post=' . $this->forum_id . '&action=edit'));
     exit;
 }
开发者ID:markc,项目名称:bbPress-Export-and-Import,代码行数:78,代码来源:import.php

示例8: test_bbp_add_user_favorite

 /**
  * @covers ::bbp_add_user_favorite
  */
 public function test_bbp_add_user_favorite()
 {
     $u = $this->factory->user->create();
     $t = $this->factory->topic->create_many(3);
     // Add topic favorites.
     add_post_meta($t[0], '_bbp_favorite', $u, false);
     // Add user favorite.
     bbp_add_user_favorite($u, $t[1]);
     $favorites = bbp_get_user_favorites_topic_ids($u);
     $this->assertEqualSets(array($t[0], $t[1]), $favorites);
     // Add user favorite.
     bbp_add_user_favorite($u, $t[2]);
     $favorites = bbp_get_user_favorites_topic_ids($u);
     $this->assertEqualSets(array($t[0], $t[1], $t[2]), $favorites);
 }
开发者ID:CompositeUK,项目名称:clone.bbPress,代码行数:18,代码来源:favorites.php


注:本文中的bbp_add_user_favorite函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。