Changeset 6723
- Timestamp:
- 10/10/2017 08:40:08 PM (6 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bbpress.php
r6705 r6723 298 298 $this->extend = new stdClass(); // Plugins add data here 299 299 $this->errors = new WP_Error(); // Feedback 300 301 /** Engagements *******************************************************/ 302 303 $this->engagements = new BBP_User_Engagements_Meta(); // Meta strategy interface 300 304 301 305 /** Deprecated ********************************************************/ -
trunk/src/includes/core/abstraction.php
r6680 r6723 334 334 return (int) apply_filters( 'bbp_get_total_users', (int) $count ); 335 335 } 336 337 /** Engagements ***************************************************************/ 338 339 /** 340 * Return the strategy used for storing user engagements 341 * 342 * @since 2.6.0 bbPress (r6722) 343 * 344 * @return string 345 */ 346 function bbp_user_engagements_interface() { 347 return apply_filters( 'bbp_user_engagements_interface', bbpress()->engagements ); 348 } 349 350 /** 351 * Meta strategy for interfacing with User Engagements 352 * 353 * @since 2.6.0 bbPress (r6722) 354 */ 355 class BBP_User_Engagements_Meta { 356 357 /** 358 * Add a user id to an object 359 * 360 * @since 2.6.0 bbPress (r6722) 361 * 362 * @param int $object_id The object id 363 * @param int $user_id The user id 364 * @param string $meta_key The relationship key 365 * @param string $meta_type The relationship type (usually 'post') 366 * @param bool $unique Whether meta key should be unique to the object 367 * 368 * @return bool Returns true on success, false on failure 369 */ 370 public function add_user_to_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post', $unique = false ) { 371 return add_metadata( $meta_type, $object_id, $meta_key, $user_id, $unique ); 372 } 373 374 /** 375 * Remove a user id from an object 376 * 377 * @since 2.6.0 bbPress (r6722) 378 * 379 * @param int $object_id The object id 380 * @param int $user_id The user id 381 * @param string $meta_key The relationship key 382 * @param string $meta_type The relationship type (usually 'post') 383 * 384 * @return bool Returns true on success, false on failure 385 */ 386 public function remove_user_from_object( $object_id = 0, $user_id = 0, $meta_key = '', $meta_type = 'post' ) { 387 return delete_metadata( $meta_type, $object_id, $meta_key, $user_id, false ); 388 } 389 390 /** 391 * Remove a user id from all objects 392 * 393 * @since 2.6.0 bbPress (r6722) 394 * 395 * @param int $user_id The user id 396 * @param string $meta_key The relationship key 397 * @param string $meta_type The relationship type (usually 'post') 398 * 399 * @return bool Returns true on success, false on failure 400 */ 401 public function remove_user_from_all_objects( $user_id = 0, $meta_key = '', $meta_type = 'post' ) { 402 return delete_metadata( $meta_type, null, $meta_key, $user_id, true ); 403 } 404 405 /** 406 * Remove an object from all users 407 * 408 * @since 2.6.0 bbPress (r6722) 409 * 410 * @param int $object_id The object id 411 * @param int $user_id The user id 412 * @param string $meta_key The relationship key 413 * @param string $meta_type The relationship type (usually 'post') 414 * 415 * @return bool Returns true on success, false on failure 416 */ 417 public function remove_object_from_all_users( $object_id = 0, $meta_key = '', $meta_type = 'post' ) { 418 return delete_metadata( $meta_type, $object_id, $meta_key, null, false ); 419 } 420 421 /** 422 * Remove all users from all objects 423 * 424 * @since 2.6.0 bbPress (r6722) 425 * 426 * @param string $meta_key The relationship key 427 * @param string $meta_type The relationship type (usually 'post') 428 * 429 * @return bool Returns true on success, false on failure 430 */ 431 public function remove_all_users_from_all_objects( $meta_key = '', $meta_type = 'post' ) { 432 return delete_metadata( $meta_type, null, $meta_key, null, true ); 433 } 434 435 /** 436 * Get users of an object 437 * 438 * @since 2.6.0 bbPress (r6722) 439 * 440 * @param int $object_id The object id 441 * @param string $meta_key The key used to index this relationship 442 * @param string $meta_type The type of meta to look in 443 * 444 * @return array Returns ids of users 445 */ 446 public function get_users_for_object( $object_id = 0, $meta_key = '', $meta_type = 'post' ) { 447 return wp_parse_id_list( get_metadata( $meta_type, $object_id, $meta_key, false ) ); 448 } 449 } -
trunk/src/includes/users/engagements.php
r6619 r6723 20 20 * @param int $object_id The object id 21 21 * @param int $user_id The user id 22 * @param string $ meta_keyThe relationship key23 * @param string $ meta_typeThe relationship type (usually 'post')22 * @param string $rel_key The relationship key 23 * @param string $rel_type The relationship type (usually 'post') 24 24 * @param bool $unique Whether meta key should be unique to the object 25 25 * 26 26 * @return bool Returns true on success, false on failure 27 27 */ 28 function bbp_add_user_to_object( $object_id = 0, $user_id = 0, $ meta_key = '', $meta_type = 'post', $unique = false ) {29 $retval = add_metadata( $meta_type, $object_id, $meta_key, $user_id, $unique );30 31 // Filter & return 32 return (bool) apply_filters( 'bbp_add_user_to_object', (bool) $retval, $object_id, $user_id, $meta_key, $meta_type, $unique );28 function bbp_add_user_to_object( $object_id = 0, $user_id = 0, $rel_key = '', $rel_type = 'post', $unique = false ) { 29 $retval = bbp_user_engagements_interface()->add_user_to_object( $object_id, $user_id, $rel_key, $rel_type, $unique ); 30 31 // Filter & return 32 return (bool) apply_filters( 'bbp_add_user_to_object', $retval, $object_id, $user_id, $rel_key, $rel_type, $unique ); 33 33 } 34 34 … … 40 40 * @param int $object_id The object id 41 41 * @param int $user_id The user id 42 * @param string $ meta_keyThe relationship key43 * @param string $ meta_typeThe relationship type (usually 'post')42 * @param string $rel_key The relationship key 43 * @param string $rel_type The relationship type (usually 'post') 44 44 * 45 45 * @return bool Returns true on success, false on failure 46 46 */ 47 function bbp_remove_user_from_object( $object_id = 0, $user_id = 0, $ meta_key = '', $meta_type = 'post' ) {48 $retval = delete_metadata( $meta_type, $object_id, $meta_key, $user_id, false );49 50 // Filter & return 51 return (bool) apply_filters( 'bbp_remove_user_from_object', (bool) $retval, $object_id, $user_id, $meta_key, $meta_type );47 function bbp_remove_user_from_object( $object_id = 0, $user_id = 0, $rel_key = '', $rel_type = 'post' ) { 48 $retval = bbp_user_engagements_interface()->remove_user_from_object( $object_id, $user_id, $rel_key, $rel_type ); 49 50 // Filter & return 51 return (bool) apply_filters( 'bbp_remove_user_from_object', $retval, $object_id, $user_id, $rel_key, $rel_type ); 52 52 } 53 53 … … 57 57 * @since 2.6.0 bbPress (r6109) 58 58 * 59 * @param int $user_id 60 * @param string $ meta_key The relationship key61 * @param string $ meta_type The relationship type (usually 'post')59 * @param int $user_id The user id 60 * @param string $rel_key The relationship key 61 * @param string $rel_type The relationship type (usually 'post') 62 62 * 63 63 * @return bool Returns true on success, false on failure 64 64 */ 65 function bbp_remove_user_from_all_objects( $user_id = 0, $ meta_key = '', $meta_type = 'post' ) {66 $retval = delete_metadata( $meta_type, null, $meta_key, $user_id, true );67 68 // Filter & return 69 return (bool) apply_filters( 'bbp_remove_user_from_all_objects', (bool) $retval, $user_id, $meta_key, $meta_type );65 function bbp_remove_user_from_all_objects( $user_id = 0, $rel_key = '', $rel_type = 'post' ) { 66 $retval = bbp_user_engagements_interface()->remove_user_from_all_objects( $user_id, $rel_key, $rel_type ); 67 68 // Filter & return 69 return (bool) apply_filters( 'bbp_remove_user_from_all_objects', $retval, $user_id, $rel_key, $rel_type ); 70 70 } 71 71 … … 77 77 * @param int $object_id The object id 78 78 * @param int $user_id The user id 79 * @param string $ meta_keyThe relationship key80 * @param string $ meta_typeThe relationship type (usually 'post')79 * @param string $rel_key The relationship key 80 * @param string $rel_type The relationship type (usually 'post') 81 81 * 82 82 * @return bool Returns true on success, false on failure 83 83 */ 84 function bbp_remove_object_from_all_users( $object_id = 0, $ meta_key = '', $meta_type = 'post' ) {85 $retval = delete_metadata( $meta_type, $object_id, $meta_key, null, false );86 87 // Filter & return 88 return (bool) apply_filters( 'bbp_remove_object_from_all_users', (bool) $retval, $object_id, $meta_key, $meta_type );84 function bbp_remove_object_from_all_users( $object_id = 0, $rel_key = '', $rel_type = 'post' ) { 85 $retval = bbp_user_engagements_interface()->remove_object_from_all_users( $object_id, $rel_key, $rel_type ); 86 87 // Filter & return 88 return (bool) apply_filters( 'bbp_remove_object_from_all_users', $retval, $object_id, $rel_key, $rel_type ); 89 89 } 90 90 … … 94 94 * @since 2.6.0 bbPress (r6109) 95 95 * 96 * @param string $ meta_key The relationship key97 * @param string $ meta_type The relationship type (usually 'post')96 * @param string $rel_key The relationship key 97 * @param string $rel_type The relationship type (usually 'post') 98 98 * 99 99 * @return bool Returns true on success, false on failure 100 100 */ 101 function bbp_remove_all_users_from_all_objects( $ meta_key = '', $meta_type = 'post' ) {102 $retval = delete_metadata( $meta_type, null, $meta_key, null, true );103 104 // Filter & return 105 return (bool) apply_filters( 'bbp_remove_all_users_from_all_objects', (bool) $retval, $meta_key, $meta_type );101 function bbp_remove_all_users_from_all_objects( $rel_key = '', $rel_type = 'post' ) { 102 $retval = bbp_user_engagements_interface()->remove_all_users_from_all_objects( $rel_key, $rel_type ); 103 104 // Filter & return 105 return (bool) apply_filters( 'bbp_remove_all_users_from_all_objects', $retval, $rel_key, $rel_type ); 106 106 } 107 107 … … 112 112 * 113 113 * @param int $object_id The object id 114 * @param string $ meta_keyThe key used to index this relationship115 * @param string $ meta_typeThe type of meta to look in114 * @param string $rel_key The key used to index this relationship 115 * @param string $rel_type The type of meta to look in 116 116 * 117 117 * @return array Returns ids of users 118 118 */ 119 function bbp_get_users_for_object( $object_id = 0, $meta_key = '', $meta_type = 'post' ) { 120 $meta = get_metadata( $meta_type, $object_id, $meta_key, false ); 121 $retval = wp_parse_id_list( $meta ); 122 123 // Filter & return 124 return (array) apply_filters( 'bbp_get_users_for_object', $retval, $object_id, $meta_key, $meta_type ); 119 function bbp_get_users_for_object( $object_id = 0, $rel_key = '', $rel_type = 'post' ) { 120 $retval = bbp_user_engagements_interface()->get_users_for_object( $object_id, $rel_key, $rel_type ); 121 122 // Filter & return 123 return (array) apply_filters( 'bbp_get_users_for_object', $retval, $object_id, $rel_key, $rel_type ); 125 124 } 126 125 … … 132 131 * @param int $object_id The object id 133 132 * @param int $user_id The user id 134 * @param string $ meta_keyThe relationship key135 * @param string $ meta_typeThe relationship type (usually 'post')133 * @param string $rel_key The relationship key 134 * @param string $rel_type The relationship type (usually 'post') 136 135 * 137 136 * @return bool Returns true if object has a user, false if not 138 137 */ 139 function bbp_is_object_of_user( $object_id = 0, $user_id = 0, $ meta_key = '', $meta_type = 'post' ) {140 $user_ids = bbp_get_users_for_object( $object_id, $ meta_key, $meta_type );138 function bbp_is_object_of_user( $object_id = 0, $user_id = 0, $rel_key = '', $rel_type = 'post' ) { 139 $user_ids = bbp_get_users_for_object( $object_id, $rel_key, $rel_type ); 141 140 $retval = is_numeric( array_search( $user_id, $user_ids, true ) ); 142 141 143 142 // Filter & return 144 return (bool) apply_filters( 'bbp_is_object_of_user', $retval, $object_id, $user_id, $ meta_key, $meta_type );143 return (bool) apply_filters( 'bbp_is_object_of_user', $retval, $object_id, $user_id, $rel_key, $rel_type ); 145 144 } 146 145 … … 981 980 982 981 /** 982 * These functions are no longer used in bbPress due to general performance 983 * concerns on large installations. They are provided here for convenience and 984 * backwards compatibility only. 985 */ 986 987 /** 983 988 * Get a user's object IDs 984 989 * … … 991 996 * 992 997 * @param int $user_id The user id 993 * @param string $ meta_keyThe relationship key994 * @param string $ meta_typeThe relationship type (usually 'post')998 * @param string $rel_key The relationship key 999 * @param string $rel_type The relationship type (usually 'post') 995 1000 * @param array $args The arguments to override defaults 996 1001 * … … 1004 1009 'user_id' => 0, 1005 1010 'object_type' => bbp_get_topic_post_type(), 1006 ' meta_key'=> '',1007 ' meta_type'=> 'post',1011 'rel_key' => '', 1012 'rel_type' => 'post', 1008 1013 'filter' => 'user_object_ids', 1009 1014 'args' => array() … … 1012 1017 // Sanitize arguments 1013 1018 $r['user_id'] = bbp_get_user_id( $r['user_id'] ); 1014 $r[' meta_key'] = sanitize_key( $r['meta_key'] );1015 $r[' meta_type'] = sanitize_key( $r['meta_type'] );1019 $r['rel_key'] = sanitize_key( $r['rel_key'] ); 1020 $r['rel_type'] = sanitize_key( $r['rel_type'] ); 1016 1021 $r['object_type'] = sanitize_key( $r['object_type'] ); 1017 1022 $r['filter'] = sanitize_key( $r['filter'] ); 1018 1023 1019 1024 // Defaults 1020 if ( 'post' === $r[' meta_type'] ) {1025 if ( 'post' === $r['rel_type'] ) { 1021 1026 $defaults = array( 1022 1027 'fields' => 'ids', … … 1024 1029 'posts_per_page' => -1, 1025 1030 'meta_query' => array( array( 1026 'key' => $r[' meta_key'],1031 'key' => $r['rel_key'], 1027 1032 'value' => $r['user_id'], 1028 1033 'compare' => 'NUMERIC' … … 1043 1048 1044 1049 // Queries 1045 if ( 'post' === $r[' meta_type'] ) {1050 if ( 'post' === $r['rel_type'] ) { 1046 1051 $query = new WP_Query( $query_args ); 1047 1052 $object_ids = $query->posts; … … 1064 1069 return bbp_get_user_object_ids( array( 1065 1070 'user_id' => $user_id, 1066 ' meta_key'=> '_bbp_moderator_id',1071 'rel_key' => '_bbp_moderator_id', 1067 1072 'object_type' => bbp_get_forum_post_type(), 1068 1073 'filter' => 'moderator_forum_ids' … … 1081 1086 function bbp_get_user_engaged_topic_ids( $user_id = 0 ) { 1082 1087 return bbp_get_user_object_ids( array( 1083 'user_id' 1084 ' meta_key' => '_bbp_engagement',1085 'filter' 1088 'user_id' => $user_id, 1089 'rel_key' => '_bbp_engagement', 1090 'filter' => 'user_engaged_topic_ids' 1086 1091 ) ); 1087 1092 } … … 1094 1099 * @param int $user_id Optional. User id 1095 1100 * 1096 * @return array Return array of favorite dids, or empty array1101 * @return array Return array of favorite topic ids, or empty array 1097 1102 */ 1098 1103 function bbp_get_user_favorites_topic_ids( $user_id = 0 ) { 1099 1104 return bbp_get_user_object_ids( array( 1100 'user_id' 1101 ' meta_key' => '_bbp_favorite',1102 'filter' 1105 'user_id' => $user_id, 1106 'rel_key' => '_bbp_favorite', 1107 'filter' => 'user_favorites_topic_ids' 1103 1108 ) ); 1104 1109 } … … 1111 1116 * @param int $user_id Optional. User id 1112 1117 * 1113 * @return array Return array of subscribed ids, or empty array1118 * @return array Return array of subscribed forum ids, or empty array 1114 1119 */ 1115 1120 function bbp_get_user_subscribed_forum_ids( $user_id = 0 ) { 1116 1121 return bbp_get_user_object_ids( array( 1117 1122 'user_id' => $user_id, 1118 ' meta_key'=> '_bbp_subscription',1123 'rel_key' => '_bbp_subscription', 1119 1124 'object_type' => bbp_get_forum_post_type(), 1120 1125 'filter' => 'user_subscribed_forum_ids' … … 1129 1134 * @param int $user_id Optional. User id 1130 1135 * 1131 * @return array Return array of subscribed ids, or empty array1136 * @return array Return array of subscribed topic ids, or empty array 1132 1137 */ 1133 1138 function bbp_get_user_subscribed_topic_ids( $user_id = 0 ) { 1134 1139 return bbp_get_user_object_ids( array( 1135 'user_id' 1136 ' meta_key' => '_bbp_subscription',1137 'filter' 1140 'user_id' => $user_id, 1141 'rel_key' => '_bbp_subscription', 1142 'filter' => 'user_subscribed_topic_ids' 1138 1143 ) ); 1139 1144 }
Note: See TracChangeset
for help on using the changeset viewer.