Skip to:
Content

bbPress.org

Ticket #1823: 1823.3.patch

File 1823.3.patch, 13.5 KB (added by johnjamesjacoby, 13 years ago)

bbp_*_user_meta functions

  • bbp-includes/bbp-common-functions.php

     
    689689 *                        Do not supply if supplying $anonymous_data.
    690690 * @uses get_option() To get the throttle time
    691691 * @uses get_transient() To get the last posted transient of the ip
    692  * @uses get_user_meta() To get the last posted meta of the user
     692 * @uses bbp_get_user_meta() To get the last posted meta of the user
    693693 * @uses current_user_can() To check if the current user can throttle
    694694 * @return bool True if there is no flooding, false if there is
    695695 */
     
    711711        // User is logged in, so check their last posted time
    712712        } elseif ( !empty( $author_id ) ) {
    713713                $author_id   = (int) $author_id;
    714                 $last_posted = get_user_meta( $author_id, '_bbp_last_posted', true );
     714                $last_posted = bbp_get_user_meta( $author_id, '_bbp_last_posted', true );
    715715
    716716                if ( isset( $last_posted ) && time() < $last_posted + $throttle_time && !current_user_can( 'throttle' ) ) {
    717717                        return false;
  • bbp-includes/bbp-reply-functions.php

     
    592592 * @uses bbp_get_topic_forum_id() To get the topic forum id
    593593 * @uses update_post_meta() To update the reply metas
    594594 * @uses set_transient() To update the flood check transient for the ip
    595  * @uses update_user_meta() To update the last posted meta for the user
     595 * @uses bbp_update_user_meta() To update the last posted meta for the user
    596596 * @uses bbp_is_subscriptions_active() To check if the subscriptions feature is
    597597 *                                      activated or not
    598598 * @uses bbp_is_user_subscribed() To check if the user is subscribed
     
    650650
    651651        } else {
    652652                if ( empty( $is_edit ) && !current_user_can( 'throttle' ) ) {
    653                         update_user_meta( $author_id, '_bbp_last_posted', time() );
     653                        bbp_update_user_meta( $author_id, '_bbp_last_posted', time() );
    654654                }
    655655        }
    656656
  • bbp-includes/bbp-topic-functions.php

     
    694694 * @yses bbp_get_topic_forum_id() To get the topic forum id
    695695 * @uses update_post_meta() To update the topic metas
    696696 * @uses set_transient() To update the flood check transient for the ip
    697  * @uses update_user_meta() To update the last posted meta for the user
     697 * @uses bbp_update_user_meta() To update the last posted meta for the user
    698698 * @uses bbp_is_subscriptions_active() To check if the subscriptions feature is
    699699 *                                      activated or not
    700700 * @uses bbp_is_user_subscribed() To check if the user is subscribed
     
    753753
    754754        } else {
    755755                if ( empty( $is_edit ) && !current_user_can( 'throttle' ) ) {
    756                         update_user_meta( $author_id, '_bbp_last_posted', time() );
     756                        bbp_update_user_meta( $author_id, '_bbp_last_posted', time() );
    757757                }
    758758        }
    759759
  • bbp-includes/bbp-user-functions.php

     
    1010// Exit if accessed directly
    1111if ( !defined( 'ABSPATH' ) ) exit;
    1212
     13/** Meta **********************************************************************/
     14
    1315/**
     16 * Add meta data field to a user.
     17 *
     18 * Post meta data is called "Custom Fields" on the Administration Screens.
     19 *
     20 * @since bbPress (r3900)
     21 * @uses add_meta_data()
     22 * @param int $user_id Post ID.
     23 * @param string $meta_key Metadata name.
     24 * @param mixed $meta_value Metadata value.
     25 * @param bool $unique Optional, default is false. Whether the same key should not be added.
     26 * @return bool False for failure. True for success.
     27 */
     28function bbp_add_user_meta( $user_id, $meta_key, $meta_value, $unique = false ) {
     29        $function = apply_filters( 'bbp_add_user_meta_function', 'add_user_meta' );
     30        return $function( $user_id, $meta_key, $meta_value, $unique );
     31}
     32
     33/**
     34 * Remove metadata matching criteria from a user.
     35 *
     36 * You can match based on the key, or key and value. Removing based on key and
     37 * value, will keep from removing duplicate metadata with the same key. It also
     38 * allows removing all metadata matching key, if needed.
     39 *
     40 * @since bbPress (r3900)
     41 * @uses bbp_delete_user_meta()
     42 * @param int $user_id user ID
     43 * @param string $meta_key Metadata name.
     44 * @param mixed $meta_value Optional. Metadata value.
     45 * @return bool False for failure. True for success.
     46 */
     47function bbp_delete_user_meta( $user_id, $meta_key, $meta_value = '' ) {
     48        $function = apply_filters( 'bbp_delete_user_meta_function', 'delete_user_meta' );
     49        return $function( $user_id, $meta_key, $meta_value );
     50}
     51
     52/**
     53 * Retrieve user meta field for a user.
     54 *
     55 * @since bbPress (r3900)
     56 * @uses bbp_get_user_meta()
     57 * @param int $user_id Post ID.
     58 * @param string $meta_key Optional. The meta key to retrieve. By default, returns data for all keys.
     59 * @param bool $single Whether to return a single value.
     60 * @return mixed Will be an array if $single is false. Will be value of meta data field if $single
     61 *  is true.
     62 */
     63function bbp_get_user_meta( $user_id, $meta_key = '', $single = false ) {
     64        $function = apply_filters( 'bbp_get_user_meta_function', 'get_user_meta', $meta_key );
     65        return $function( $user_id, $meta_key, $single );
     66}
     67
     68/**
     69 * Update user meta field based on user ID.
     70 *
     71 * Use the $prev_value parameter to differentiate between meta fields with the
     72 * same key and user ID.
     73 *
     74 * If the meta field for the user does not exist, it will be added.
     75 *
     76 * @since bbPress (r3900)
     77 * @uses update_user_meta
     78 * @param int $user_id Post ID.
     79 * @param string $meta_key Metadata key.
     80 * @param mixed $meta_value Metadata value.
     81 * @param mixed $prev_value Optional. Previous value to check before removing.
     82 * @return bool False on failure, true if success.
     83 */
     84function bbp_update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) {
     85        $function = apply_filters( 'bbp_update_user_meta_function', 'update_user_meta', $meta_key );
     86        return $function( $user_id, $meta_key, $meta_value, $prev_value );
     87}
     88
     89/** Other *********************************************************************/
     90
     91/**
    1492 * Redirect back to $url when attempting to use the login page
    1593 *
    1694 * @since bbPress (r2815)
     
    304382 *
    305383 * @param int $user_id Optional. User id
    306384 * @uses bbp_get_user_id() To get the user id
    307  * @uses get_user_meta() To get the user favorites
     385 * @uses bbp_get_user_meta() To get the user favorites
    308386 * @uses apply_filters() Calls 'bbp_get_user_favorites_topic_ids' with
    309387 *                        the favorites and user id
    310388 * @return array|bool Results if user has favorites, otherwise false
     
    314392        if ( empty( $user_id ) )
    315393                return false;
    316394
    317         $favorites = (string) get_user_meta( $user_id, bbp_get_favorites_key(), true );
     395        $favorites = (string) bbp_get_user_meta( $user_id, bbp_get_favorites_key(), true );
    318396        $favorites = (array) explode( ',', $favorites );
    319397        $favorites = array_filter( $favorites );
    320398
     
    378456 * @param int $user_id Optional. User id
    379457 * @param int $topic_id Optional. Topic id
    380458 * @uses bbp_get_user_favorites_topic_ids() To get the user favorites
    381  * @uses update_user_meta() To update the user favorites
     459 * @uses bbp_update_user_meta() To update the user favorites
    382460 * @uses do_action() Calls 'bbp_add_user_favorite' with the user id and topic id
    383461 * @return bool Always true
    384462 */
     
    395473                $favorites[] = $topic_id;
    396474                $favorites   = array_filter( $favorites );
    397475                $favorites   = (string) implode( ',', $favorites );
    398                 update_user_meta( $user_id, bbp_get_favorites_key(), $favorites );
     476                bbp_update_user_meta( $user_id, bbp_get_favorites_key(), $favorites );
    399477        }
    400478
    401479        do_action( 'bbp_add_user_favorite', $user_id, $topic_id );
     
    411489 * @param int $user_id Optional. User id
    412490 * @param int $topic_id Optional. Topic id
    413491 * @uses bbp_get_user_favorites_topic_ids() To get the user favorites
    414  * @uses update_user_meta() To update the user favorites
    415  * @uses delete_user_meta() To delete the user favorites meta
     492 * @uses bbp_update_user_meta() To update the user favorites
     493 * @uses bbp_delete_user_meta() To delete the user favorites meta
    416494 * @uses do_action() Calls 'bbp_remove_user_favorite' with the user & topic id
    417495 * @return bool True if the topic was removed from user's favorites, otherwise
    418496 *               false
     
    432510
    433511                if ( !empty( $favorites ) ) {
    434512                        $favorites = implode( ',', $favorites );
    435                         update_user_meta( $user_id, bbp_get_favorites_key(), $favorites );
     513                        bbp_update_user_meta( $user_id, bbp_get_favorites_key(), $favorites );
    436514                } else {
    437                         delete_user_meta( $user_id, bbp_get_favorites_key() );
     515                        bbp_delete_user_meta( $user_id, bbp_get_favorites_key() );
    438516                }
    439517        }
    440518
     
    634712 *
    635713 * @param int $user_id Optional. User id
    636714 * @uses bbp_get_user_id() To get the user id
    637  * @uses get_user_meta() To get the user's subscriptions
     715 * @uses bbp_get_user_meta() To get the user's subscriptions
    638716 * @uses apply_filters() Calls 'bbp_get_user_subscribed_topic_ids' with
    639717 *                        the subscriptions and user id
    640718 * @return array|bool Results if user has subscriptions, otherwise false
     
    644722        if ( empty( $user_id ) )
    645723                return false;
    646724
    647         $subscriptions = (string) get_user_meta( $user_id, bbp_get_subscriptions_key(), true );
     725        $subscriptions = (string) bbp_get_user_meta( $user_id, bbp_get_subscriptions_key(), true );
    648726        $subscriptions = (array) explode( ',', $subscriptions );
    649727        $subscriptions = array_filter( $subscriptions );
    650728
     
    710788 * @param int $topic_id Optional. Topic id
    711789 * @uses bbp_get_user_subscribed_topic_ids() To get the user's subscriptions
    712790 * @uses bbp_get_topic() To get the topic
    713  * @uses update_user_meta() To update the user's subscriptions
     791 * @uses bbp_update_user_meta() To update the user's subscriptions
    714792 * @uses do_action() Calls 'bbp_add_user_subscription' with the user & topic id
    715793 * @return bool Always true
    716794 */
     
    728806                $subscriptions[] = $topic_id;
    729807                $subscriptions   = array_filter( $subscriptions );
    730808                $subscriptions   = (string) implode( ',', $subscriptions );
    731                 update_user_meta( $user_id, bbp_get_subscriptions_key(), $subscriptions );
     809                bbp_update_user_meta( $user_id, bbp_get_subscriptions_key(), $subscriptions );
    732810
    733811                wp_cache_delete( 'bbp_get_topic_subscribers_' . $topic_id, 'bbpress' );
    734812        }
     
    746824 * @param int $user_id Optional. User id
    747825 * @param int $topic_id Optional. Topic id
    748826 * @uses bbp_get_user_subscribed_topic_ids() To get the user's subscriptions
    749  * @uses update_user_meta() To update the user's subscriptions
    750  * @uses delete_user_meta() To delete the user's subscriptions meta
     827 * @uses bbp_update_user_meta() To update the user's subscriptions
     828 * @uses bbp_delete_user_meta() To delete the user's subscriptions meta
    751829 * @uses do_action() Calls 'bbp_remove_user_subscription' with the user id and
    752830 *                    topic id
    753831 * @return bool True if the topic was removed from user's subscriptions,
     
    769847
    770848                if ( !empty( $subscriptions ) ) {
    771849                        $subscriptions = implode( ',', $subscriptions );
    772                         update_user_meta( $user_id, bbp_get_subscriptions_key(), $subscriptions );
     850                        bbp_update_user_meta( $user_id, bbp_get_subscriptions_key(), $subscriptions );
    773851                } else {
    774                         delete_user_meta( $user_id, bbp_get_subscriptions_key() );
     852                        bbp_delete_user_meta( $user_id, bbp_get_subscriptions_key() );
    775853                }
    776854
    777855                wp_cache_delete( 'bbp_get_topic_subscribers_' . $topic_id, 'bbpress' );
     
    9941072
    9951073                // stops users being added to current blog when they are edited
    9961074                if ( $delete_role ) {
    997                         delete_user_meta( $user_id, $blog_prefix . 'capabilities' );
     1075                        bbp_delete_user_meta( $user_id, $blog_prefix . 'capabilities' );
    9981076                }
    9991077
    10001078                if ( is_multisite() && is_network_admin() & !bbp_is_user_home() && current_user_can( 'manage_network_options' ) && !isset( $super_admins ) && empty( $_POST['super_admin'] ) == is_super_admin( $user_id ) ) {
  • bbp-includes/bbp-user-template.php

     
    15501550         *
    15511551         * @param int $user_id
    15521552         * @uses bbp_get_user_id()
    1553          * @uses get_user_meta()
     1553         * @uses bbp_get_user_meta()
    15541554         * @uses apply_filters()
    15551555         * @return string
    15561556         */
     
    15611561                if ( empty( $user_id ) )
    15621562                        return false;
    15631563
    1564                 $count = get_user_meta( $user_id, '_bbp_topic_count', true );
     1564                $count = bbp_get_user_meta( $user_id, '_bbp_topic_count', true );
    15651565
    15661566                return apply_filters( 'bbp_get_user_topic_count', (int) $count, $user_id );
    15671567        }
     
    15851585         *
    15861586         * @param int $user_id
    15871587         * @uses bbp_get_user_id()
    1588          * @uses get_user_meta()
     1588         * @uses bbp_get_user_meta()
    15891589         * @uses apply_filters()
    15901590         * @return string
    15911591         */
     
    15961596                if ( empty( $user_id ) )
    15971597                        return false;
    15981598
    1599                 $count = get_user_meta( $user_id, '_bbp_reply_count', true );
     1599                $count = bbp_get_user_meta( $user_id, '_bbp_reply_count', true );
    16001600
    16011601                return apply_filters( 'bbp_get_user_reply_count', (int) $count, $user_id );
    16021602        }
     
    16201620         *
    16211621         * @param int $user_id
    16221622         * @uses bbp_get_user_id()
    1623          * @uses get_user_meta()
     1623         * @uses bbp_get_user_meta()
    16241624         * @uses apply_filters()
    16251625         * @return string
    16261626         */
     
    16311631                if ( empty( $user_id ) )
    16321632                        return false;
    16331633
    1634                 $topics  = get_user_meta( $user_id, '_bbp_topic_count', true );
    1635                 $replies = get_user_meta( $user_id, '_bbp_reply_count', true );
     1634                $topics  = bbp_get_user_meta( $user_id, '_bbp_topic_count', true );
     1635                $replies = bbp_get_user_meta( $user_id, '_bbp_reply_count', true );
    16361636                $count   = (int) $topics + (int) $replies;
    16371637
    16381638                return apply_filters( 'bbp_get_user_post_count', (int) $count, $user_id );