Skip to:
Content

bbPress.org


Ignore:
Timestamp:
05/22/2017 06:09:16 PM (7 years ago)
Author:
johnjamesjacoby
Message:

Users: move user relationships functions into engagements.php.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/users/functions.php

    r6421 r6422  
    183183
    184184    return apply_filters( 'bbp_current_author_ua', $retval );
    185 }
    186 
    187 /** User Relationships ********************************************************/
    188 
    189 /**
    190  * Set a user id on an object
    191  *
    192  * @since 2.6.0 bbPress(r6109)
    193  *
    194  * @param int    $object_id The object id
    195  * @param int    $user_id   The user id
    196  * @param string $meta_key  The relationship key
    197  * @param string $meta_type The relationship type
    198  *
    199  * @uses add_post_meta() To set the term on the object
    200  * @uses apply_filters() Calls 'bbp_add_user_to_object' with the object id, user
    201  *                        id, and taxonomy
    202  * @return bool Returns true if the user taxonomy term is added to the object,
    203  *               otherwise false
    204  */
    205 function bbp_add_user_to_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
    206     $retval = add_metadata( $meta_type, $object_id, $meta_key, $user_id, false );
    207 
    208     return (bool) apply_filters( 'bbp_add_user_to_object', (bool) $retval, $object_id, $user_id, $meta_key, $meta_type );
    209 }
    210 
    211 /**
    212  * Remove a user id from an object
    213  *
    214  * @since 2.6.0 bbPress(r6109)
    215  *
    216  * @param int    $object_id The post id
    217  * @param int    $user_id   The user id
    218  * @param string $meta_key  The relationship key
    219  * @param string $meta_type The relationship type
    220  *
    221  * @uses delete_post_meta() To remove the term from the object
    222  * @uses apply_filters() Calls 'bbp_remove_user_from_object' with the object
    223  *                        id, user id, and taxonomy
    224  * @return bool Returns true is the user taxonomy term is removed from the object,
    225  *               otherwise false
    226  */
    227 function bbp_remove_user_from_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
    228     $retval = delete_metadata( $meta_type, $object_id, $meta_key, $user_id, false );
    229 
    230     return (bool) apply_filters( 'bbp_remove_user_from_object', (bool) $retval, $object_id, $user_id, $meta_key, $meta_type );
    231 }
    232 
    233 /**
    234  * Get user taxonomy terms for an object
    235  *
    236  * @since 2.6.0 bbPress(r6109)
    237  *
    238  * @param int    $object_id The object id
    239  * @param string $meta_key  The key used to index this relationship
    240  * @param string $meta_type The type of meta to look in
    241  *
    242  * @uses get_post_meta() To get the user taxonomy terms
    243  * @uses apply_filters() Calls 'bbp_get_users_for_object' with the user
    244  *                        taxonomy terms, object id, and taxonomy
    245  * @return array Returns the user taxonomy terms of the object
    246  */
    247 function bbp_get_users_for_object( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
    248     $meta   = get_metadata( $meta_type, $object_id, $meta_key, false );
    249     $retval = wp_parse_id_list( $meta );
    250 
    251     return (array) apply_filters( 'bbp_get_users_for_object', (array) $retval, $object_id, $meta_key, $meta_type );
    252 }
    253 
    254 /**
    255  * Check if the user id is set on an object
    256  *
    257  * @since 2.6.0 bbPress(r6109)
    258  *
    259  * @param int    $object_id The object id
    260  * @param int    $user_id   The user id
    261  * @param string $meta_key  The relationship key
    262  * @param string $meta_type The relationship type
    263  *
    264  * @uses get_post_meta() To check if the user id is set on the object
    265  * @uses apply_filters() Calls 'bbp_is_object_of_user' with the object id,
    266  *                        user id, and taxonomy
    267  * @return bool Returns true if the user id is set on the object for the
    268  *               taxonomy, otherwise false
    269  */
    270 function bbp_is_object_of_user( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
    271     $user_ids = bbp_get_users_for_object( $object_id, $meta_key, $meta_type );
    272     $retval   = is_numeric( array_search( $user_id, $user_ids, true ) );
    273 
    274     return (bool) apply_filters( 'bbp_is_object_of_user', (bool) $retval, $object_id, $user_id, $meta_key, $meta_type );
    275185}
    276186
Note: See TracChangeset for help on using the changeset viewer.