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/engagements.php

    r6421 r6422  
    1010// Exit if accessed directly
    1111defined( 'ABSPATH' ) || exit;
     12
     13/** User Relationships ********************************************************/
     14
     15/**
     16 * Set a user id on an object
     17 *
     18 * @since 2.6.0 bbPress (r6109)
     19 *
     20 * @param int    $object_id The object id
     21 * @param int    $user_id   The user id
     22 * @param string $meta_key  The relationship key
     23 * @param string $meta_type The relationship type
     24 *
     25 * @uses add_post_meta() To set the term on the object
     26 * @uses apply_filters() Calls 'bbp_add_user_to_object' with the object id, user
     27 *                        id, and taxonomy
     28 * @return bool Returns true if the user taxonomy term is added to the object,
     29 *               otherwise false
     30 */
     31function bbp_add_user_to_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
     32    $retval = add_metadata( $meta_type, $object_id, $meta_key, $user_id, false );
     33
     34    return (bool) apply_filters( 'bbp_add_user_to_object', (bool) $retval, $object_id, $user_id, $meta_key, $meta_type );
     35}
     36
     37/**
     38 * Remove a user id from an object
     39 *
     40 * @since 2.6.0 bbPress (r6109)
     41 *
     42 * @param int    $object_id The post id
     43 * @param int    $user_id   The user id
     44 * @param string $meta_key  The relationship key
     45 * @param string $meta_type The relationship type
     46 *
     47 * @uses delete_post_meta() To remove the term from the object
     48 * @uses apply_filters() Calls 'bbp_remove_user_from_object' with the object
     49 *                        id, user id, and taxonomy
     50 * @return bool Returns true is the user taxonomy term is removed from the object,
     51 *               otherwise false
     52 */
     53function bbp_remove_user_from_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
     54    $retval = delete_metadata( $meta_type, $object_id, $meta_key, $user_id, false );
     55
     56    return (bool) apply_filters( 'bbp_remove_user_from_object', (bool) $retval, $object_id, $user_id, $meta_key, $meta_type );
     57}
     58
     59/**
     60 * Get user taxonomy terms for an object
     61 *
     62 * @since 2.6.0 bbPress (r6109)
     63 *
     64 * @param int    $object_id The object id
     65 * @param string $meta_key  The key used to index this relationship
     66 * @param string $meta_type The type of meta to look in
     67 *
     68 * @uses get_post_meta() To get the user taxonomy terms
     69 * @uses apply_filters() Calls 'bbp_get_users_for_object' with the user
     70 *                        taxonomy terms, object id, and taxonomy
     71 * @return array Returns the user taxonomy terms of the object
     72 */
     73function bbp_get_users_for_object( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {
     74    $meta   = get_metadata( $meta_type, $object_id, $meta_key, false );
     75    $retval = wp_parse_id_list( $meta );
     76
     77    return (array) apply_filters( 'bbp_get_users_for_object', (array) $retval, $object_id, $meta_key, $meta_type );
     78}
     79
     80/**
     81 * Check if the user id is set on an object
     82 *
     83 * @since 2.6.0 bbPress (r6109)
     84 *
     85 * @param int    $object_id The object id
     86 * @param int    $user_id   The user id
     87 * @param string $meta_key  The relationship key
     88 * @param string $meta_type The relationship type
     89 *
     90 * @uses get_post_meta() To check if the user id is set on the object
     91 * @uses apply_filters() Calls 'bbp_is_object_of_user' with the object id,
     92 *                        user id, and taxonomy
     93 * @return bool Returns true if the user id is set on the object for the
     94 *               taxonomy, otherwise false
     95 */
     96function bbp_is_object_of_user( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post' ) {
     97    $user_ids = bbp_get_users_for_object( $object_id, $meta_key, $meta_type );
     98    $retval   = is_numeric( array_search( $user_id, $user_ids, true ) );
     99
     100    return (bool) apply_filters( 'bbp_is_object_of_user', (bool) $retval, $object_id, $user_id, $meta_key, $meta_type );
     101}
     102
     103/** Engagements ***************************************************************/
    12104
    13105/**
Note: See TracChangeset for help on using the changeset viewer.