Changeset 6544
- Timestamp:
- 06/14/2017 06:45:49 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/phpunit.xml.dist
r6025 r6544 22 22 <array> 23 23 <element key="slowThreshold"> 24 <integer> 100</integer>24 <integer>500</integer> 25 25 </element> 26 26 </array> -
trunk/src/bbpress.php
r6542 r6544 73 73 */ 74 74 public $options = array(); 75 76 /** 77 * @var array Storage of options not in the database 78 */ 79 public $not_options = array(); 75 80 76 81 /** -
trunk/src/includes/admin/classes/class-bbp-converter-base.php
r6514 r6544 518 518 // Add user ID to forums subscribed users 519 519 foreach ( $value as $fav ) { 520 bbp_add_user_ forum_subscription( $user_id, $this->callback_forumid( $fav ) );520 bbp_add_user_subscription( $user_id, $this->callback_forumid( $fav ) ); 521 521 } 522 522 } … … 539 539 // Add user ID to topics subscribed users 540 540 foreach ( $value as $fav ) { 541 bbp_add_user_ topic_subscription( $user_id, $this->callback_topicid( $fav ) );541 bbp_add_user_subscription( $user_id, $this->callback_topicid( $fav ) ); 542 542 } 543 543 } -
trunk/src/includes/admin/settings.php
r6514 r6544 433 433 434 434 // Engagements slug setting 435 '_bbp_user_eng agements_slug' => array(435 '_bbp_user_engs_slug' => array( 436 436 'title' => esc_html__( 'Engagements', 'bbpress' ), 437 437 'callback' => 'bbp_admin_setting_callback_user_engagements_slug', 438 438 'sanitize_callback' => 'bbp_sanitize_slug', 439 'args' => array( 'label_for'=>'_bbp_user_eng agements_slug' )439 'args' => array( 'label_for'=>'_bbp_user_engs_slug' ) 440 440 ) 441 441 ), … … 1288 1288 ?> 1289 1289 1290 <input name="_bbp_user_eng agements_slug" id="_bbp_user_engagements_slug" type="text" class="regular-text code" value="<?php bbp_form_option( '_bbp_user_engagements_slug', 'engagements', true ); ?>"<?php bbp_maybe_admin_setting_disabled( '_bbp_user_engagements_slug' ); ?> />1290 <input name="_bbp_user_engs_slug" id="_bbp_user_engs_slug" type="text" class="regular-text code" value="<?php bbp_form_option( '_bbp_user_engs_slug', 'engagements', true ); ?>"<?php bbp_maybe_admin_setting_disabled( '_bbp_user_engs_slug' ); ?> /> 1291 1291 1292 1292 <?php 1293 1293 // Slug Check 1294 bbp_form_slug_conflict_check( '_bbp_user_eng agements_slug', 'engagements' );1294 bbp_form_slug_conflict_check( '_bbp_user_engs_slug', 'engagements' ); 1295 1295 } 1296 1296 -
trunk/src/includes/admin/tools/repair.php
r6537 r6544 626 626 627 627 /** 628 * Clean the user s'topic subscriptions628 * Clean the user topic subscriptions 629 629 * 630 630 * @since 2.0.0 bbPress (r2668) … … 695 695 696 696 /** 697 * Clean the user s'forum subscriptions697 * Clean the user forum subscriptions 698 698 * 699 699 * @since 2.5.0 bbPress (r5155) -
trunk/src/includes/core/actions.php
r6534 r6544 68 68 add_action( 'bbp_loaded', 'bbp_setup_option_filters', 10 ); 69 69 add_action( 'bbp_loaded', 'bbp_setup_user_option_filters', 12 ); 70 add_action( 'bbp_loaded', 'bbp_register_theme_packages', 14 ); 70 add_action( 'bbp_loaded', 'bbp_pre_load_options', 14 ); 71 add_action( 'bbp_loaded', 'bbp_register_theme_packages', 16 ); 71 72 72 73 /** … … 427 428 add_action( 'bbp_get_request', 'bbp_subscriptions_handler', 1 ); 428 429 add_action( 'bbp_get_request', 'bbp_user_email_change_handler', 1 ); 429 add_action( 'bbp_get_request', 'bbp_forum_subscriptions_handler', 1 );430 430 add_action( 'bbp_get_request', 'bbp_search_results_redirect', 10 ); 431 431 -
trunk/src/includes/core/options.php
r6514 r6544 23 23 24 24 // Filter & return 25 return apply_filters( 'bbp_get_default_options', array(25 return (array) apply_filters( 'bbp_get_default_options', array( 26 26 27 27 /** DB Version ********************************************************/ … … 84 84 85 85 '_bbp_user_slug' => 'users', // User profile slug 86 '_bbp_user_engs_slug' => 'engagements', // User engagements slug 86 87 '_bbp_user_favs_slug' => 'favorites', // User favorites slug 87 88 '_bbp_user_subs_slug' => 'subscriptions', // User subscriptions slug … … 112 113 113 114 '_bbp_enable_akismet' => 1, // Users from all sites can post 114 115 115 116 /** Converter *********************************************************/ 116 117 … … 193 194 // Add filters to each bbPress option 194 195 foreach ( array_keys( bbp_get_default_options() ) as $key ) { 195 add_filter( 'pre_option_' . $key, 'bbp_pre_get_option' ); 196 add_filter( 'pre_option_' . $key, 'bbp_filter_pre_get_option', 10, 2 ); 197 add_filter( 'default_option_' . $key, 'bbp_filter_default_option', 10, 3 ); 196 198 } 197 199 … … 201 203 202 204 /** 203 * Filter default options and allow them to be overloaded from inside the 204 * $bbp->options array. 205 * Filter pre options and maybe overloaded from the $bbp->options array. 206 * 207 * This function should not be called directly. 205 208 * 206 209 * @since 2.0.0 bbPress (r3451) 207 * 208 * @param bool $value Optional. Default value false 210 * @access private 211 * 212 * @param bool $value Default value false 213 * @param string $option Name of the option 214 * 209 215 * @return mixed false if not overloaded, mixed if set 210 216 */ 211 function bbp_pre_get_option( $value = '' ) { 212 213 // Remove the filter prefix 214 $option = str_replace( 'pre_option_', '', current_filter() ); 217 function bbp_filter_pre_get_option( $value = false, $option = '' ) { 215 218 216 219 // Check the options global for preset value … … 223 226 } 224 227 228 /** 229 * Filter default_options set them from inside the $bbp->options array. 230 * 231 * This function should not be called directly. 232 * 233 * @since 2.6.0 bbPress (r3451) 234 * @access private 235 * 236 * @param bool $value Optional. Default value false 237 * @return mixed false if not overloaded, mixed if set 238 */ 239 function bbp_filter_default_option( $default = false, $option = '', $passed_default = false ) { 240 $options = bbp_get_default_options(); 241 242 // Maybe use the default value 243 if ( isset( $options[ $option ] ) ) { 244 245 // Try to use the passed default and fallback to assumed default 246 $default = ( true === $passed_default ) 247 ? $default 248 : $options[ $option ]; 249 } 250 251 // Always return a value, even if false 252 return $default; 253 } 254 255 /** 256 * Loads & caches bbPress options if a persistent cache is not being used. 257 * 258 * @since 2.6.0 259 */ 260 function bbp_pre_load_options() { 261 262 // Bail if using object cache or installing 263 if ( wp_using_ext_object_cache() || wp_installing() ) { 264 return; 265 } 266 267 // Bail if strategy is overloaded to false|null 268 $strategy = apply_filters( 'bbp_pre_load_options', 'notoptions' ); 269 if ( empty( $strategy ) ) { 270 return; 271 } 272 273 // Get variables 274 $bbp = bbpress(); 275 $bbp_options = bbp_get_default_options(); 276 $all_options = wp_load_alloptions(); 277 $not_options = (array) wp_cache_get( 'notoptions', 'options' ); 278 279 // Loop through all bbPress options to maybe cache their non-existence 280 foreach ( $bbp_options as $option => $value ) { 281 282 // Skip if already saved to database 283 if ( isset( $all_options[ $option ] ) ) { 284 continue; 285 286 // Skip if overloaded 287 } elseif ( isset( $bbp->options[ $option ] ) ) { 288 continue; 289 290 // Skip if already in cache 291 } elseif ( wp_cache_get( $option, 'options' ) !== false ) { 292 continue; 293 294 // Needs caching to avoid database hit 295 } else { 296 297 // Store internally, for easier identification later 298 $bbp->not_options[ $option ] = $value; 299 300 // Cache to notoptions 301 if ( 'notoptions' === $strategy ) { 302 $not_options[ $option ] = true; 303 wp_cache_set( 'notoptions', $not_options, 'options' ); 304 305 // Cache to option 306 } elseif ( 'option' === $strategy ) { 307 wp_cache_set( $option, $value, 'options' ); 308 } 309 } 310 } 311 } 312 225 313 /** Active? *******************************************************************/ 226 314 … … 230 318 * @since 2.0.0 bbPress (r2658) 231 319 * 232 * @param $default boolOptional.Default value true320 * @param bool $default Optional.Default value true 233 321 * @uses get_option() To get the favorites option 234 322 * @return bool Is favorites enabled or not … … 245 333 * @since 2.0.0 bbPress (r2658) 246 334 * 247 * @param $default boolOptional.Default value true335 * @param bool $default Optional.Default value true 248 336 * @uses get_option() To get the subscriptions option 249 337 * @return bool Is subscription enabled or not … … 260 348 * @since 2.6.0 bbPress (r6320) 261 349 * 262 * @param $default boolOptional.Default value true350 * @param bool $default Optional.Default value true 263 351 * @uses get_option() To get the engagements option 264 352 * @return bool Is engagements enabled or not … … 275 363 * @since 2.6.0 bbPress (r6441) 276 364 * 277 * @param $default boolOptional. Default value false365 * @param bool $default Optional. Default value false 278 366 * @uses get_option() To get the global content edit option 279 367 * @return bool Is content editing allowed? … … 290 378 * @since 2.6.0 bbPress (r6441) 291 379 * 292 * @param $default boolOptional. Default value false380 * @param bool $default Optional. Default value false 293 381 * @uses get_option() To get the content throttle option 294 382 * @return bool Is content throttling allowed? … … 305 393 * @since 2.2.0 bbPress (r4097) 306 394 * 307 * @param $default boolOptional. Default value true395 * @param bool $default Optional. Default value true 308 396 * @uses get_option() To get the allow tags 309 397 * @return bool Are tags allowed? … … 336 424 * @since 2.4.0 bbPress (r4970) 337 425 * 338 * @param $default boolOptional. Default value true426 * @param bool $default Optional. Default value true 339 427 * @uses get_option() To get the forum-wide search setting 340 428 * @return bool Is forum-wide searching allowed? … … 351 439 * @since 2.4.0 bbPress (r4964) 352 440 * 353 * @param $default boolOptional. Default value false441 * @param bool $default Optional. Default value false 354 442 * @uses get_option() To get the threaded replies setting 355 443 * @return bool Are threaded replies allowed? … … 383 471 * @since 2.0.0 bbPress (r3412) 384 472 * 385 * @param $default boolOptional. Default value true473 * @param bool $default Optional. Default value true 386 474 * @uses get_option() To get the allow revisions 387 475 * @return bool Are revisions allowed? … … 398 486 * @since 2.0.0 bbPress (r2659) 399 487 * 400 * @param $default boolOptional. Default value488 * @param bool $default Optional. Default value 401 489 * @uses get_option() To get the allow anonymous option 402 490 * @return bool Is anonymous posting allowed? … … 413 501 * @since 2.0.0 bbPress (r3378) 414 502 * 415 * @param $default boolOptional. Default value false503 * @param bool $default Optional. Default value false 416 504 * @uses get_option() To get the global access option 417 505 * @return bool Is global access allowed? … … 428 516 * @since 2.2.0 bbPress (r4294) 429 517 * 430 * @param $default stringOptional. Default value empty518 * @param string $default Optional. Default value empty 431 519 * @uses get_option() To get the default forums role option 432 520 * @return string The default forums user role … … 443 531 * @since 2.0.0 bbPress (r3386) 444 532 * 445 * @param $default boolOptional. Default value true533 * @param bool $default Optional. Default value true 446 534 * @uses get_option() To get the WP editor option 447 535 * @return bool Use WP editor? … … 458 546 * @since 2.1.0 bbPress (r3752) 459 547 * 460 * @param $default boolOptional. Default value true548 * @param bool $default Optional. Default value true 461 549 * @uses get_option() To get the oEmbed option 462 550 * @return bool Use oEmbed? … … 473 561 * @since 2.1.0 bbPress (r3829) 474 562 * 475 * @param $default stringOptional. Default value 'default'563 * @param string $default Optional. Default value 'default' 476 564 * @uses get_option() To get the theme-package option 477 565 * @return string ID of the theme-package … … 488 576 * @since 2.0.0 bbPress (r3246) 489 577 * 490 * @param $default boolOptional. Default value 80578 * @param bool $default Optional. Default value 80 491 579 */ 492 580 function bbp_title_max_length( $default = 80 ) { … … 498 586 * @since 2.0.0 bbPress (r3246) 499 587 * 500 * @param $default boolOptional. Default value 80588 * @param bool $default Optional. Default value 80 501 589 * @uses get_option() To get the maximum title length 502 590 * @return int Is anonymous posting allowed? … … 513 601 * @since 2.1.0 bbPress (r3575) 514 602 * 515 * @param $default int Optional. Default value603 * @param int $default Optional. Default value 516 604 */ 517 605 function bbp_group_forums_root_id( $default = 0 ) { … … 523 611 * @since 2.1.0 bbPress (r3575) 524 612 * 525 * @param $default boolOptional. Default value 0613 * @param bool $default Optional. Default value 0 526 614 * @uses get_option() To get the root group forum ID 527 615 * @return int The post ID for the root forum … … 538 626 * @since 2.1.0 bbPress (r3575) 539 627 * 540 * @param $default boolOptional. Default value true628 * @param bool $default Optional. Default value true 541 629 * @uses get_option() To get the group forums option 542 630 * @return bool Is group forums enabled or not … … 553 641 * @since 2.1.0 bbPress (r3575) 554 642 * 555 * @param $default boolOptional. Default value true643 * @param bool $default Optional. Default value true 556 644 * @uses get_option() To get the Akismet option 557 645 * @return bool Is Akismet enabled or not … … 573 661 * @since 2.4.0 bbPress (r4932) 574 662 * 575 * @param $default boolOptional. Default value false663 * @param bool $default Optional. Default value false 576 664 * @uses get_option() To get the admin integration setting 577 665 * @return bool To deeply integrate settings, or not … … 605 693 * @since 2.1.0 bbPress (r3759) 606 694 * 695 * @param string $default Optional. Default value 'forums' 696 * @uses get_option() To get the slug 607 697 * @return string 608 698 */ … … 618 708 * @since 2.1.0 bbPress (r3759) 619 709 * 710 * @param bool $default Optional. Default value true 711 * @uses get_option() To get the setting 620 712 * @return bool 621 713 */ … … 631 723 * @since 2.4.0 bbPress (r4932) 632 724 * 725 * @param string $default Optional. Default value 'forums' 726 * @uses get_option() To get the setting 633 727 * @return string 634 728 */ … … 644 738 * @since 2.1.0 bbPress (r3759) 645 739 * 740 * @param string $default Optional. Default value 'forums' 741 * @uses get_option() To get the slug 646 742 * @return string 647 743 */ 648 744 function bbp_maybe_get_root_slug() { 649 $retval = ''; 650 651 if ( bbp_get_root_slug() && bbp_include_root_slug() ) { 652 $retval = trailingslashit( bbp_get_root_slug() ); 653 } 745 $slug = bbp_get_root_slug(); 746 $retval = ( ! empty( $slug ) && bbp_include_root_slug() ) 747 ? trailingslashit( $slug ) 748 : ''; 654 749 655 750 // Filter & return … … 662 757 * @since 2.1.0 bbPress (r3759) 663 758 * 759 * @param string $default Optional. Default value 'forum' 760 * @uses get_option() To get the slug 664 761 * @return string 665 762 */ … … 675 772 * @since 2.1.0 bbPress (r3759) 676 773 * 774 * @param string $default Optional. Default value 'topics' 775 * @uses get_option() To get the slug 677 776 * @return string 678 777 */ … … 688 787 * @since 2.4.0 bbPress (r4925) 689 788 * 789 * @param string $default Optional. Default value 'replies' 790 * @uses get_option() To get the slug 690 791 * @return string 691 792 */ … … 701 802 * @since 2.1.0 bbPress (r3759) 702 803 * 804 * @param string $default Optional. Default value 'topic' 805 * @uses get_option() To get the slug 703 806 * @return string 704 807 */ … … 714 817 * @since 2.1.0 bbPress (r3759) 715 818 * 819 * @param string $default Optional. Default value 'topic-tag' 820 * @uses get_option() To get the slug 716 821 * @return string 717 822 */ … … 727 832 * @since 2.1.0 bbPress (r3759) 728 833 * 834 * @param string $default Optional. Default value 'reply' 835 * @uses get_option() To get the slug 729 836 * @return string 730 837 */ … … 740 847 * @since 2.1.0 bbPress (r3759) 741 848 * 849 * @param string $default Optional. Default value 'users' 850 * @uses get_option() To get the slug 742 851 * @return string 743 852 */ … … 753 862 * @since 2.2.0 bbPress (r4187) 754 863 * 864 * @param string $default Optional. Default value 'favorites' 865 * @uses get_option() To get the slug 755 866 * @return string 756 867 */ … … 766 877 * @since 2.2.0 bbPress (r4187) 767 878 * 879 * @param string $default Optional. Default value 'subscriptions' 880 * @uses get_option() To get the slug 768 881 * @return string 769 882 */ … … 779 892 * @since 2.6.0 bbPress (r6320) 780 893 * 894 * @param string $default Optional. Default value 'engagements' 895 * @uses get_option() To get the slug 781 896 * @return string 782 897 */ … … 784 899 785 900 // Filter & return 786 return apply_filters( 'bbp_get_user_engagements_slug', get_option( '_bbp_user_eng agements_slug', $default ) );901 return apply_filters( 'bbp_get_user_engagements_slug', get_option( '_bbp_user_engs_slug', $default ) ); 787 902 } 788 903 … … 792 907 * @since 2.1.0 bbPress (r3759) 793 908 * 909 * @param string $default Optional. Default value 'view' 910 * @uses get_option() To get the slug 794 911 * @return string 795 912 */ … … 805 922 * @since 2.3.0 bbPress (r4579) 806 923 * 924 * @param string $default Optional. Default value 'search' 925 * @uses get_option() To get the slug 807 926 * @return string 808 927 */ … … 820 939 * @since 2.1.0 bbPress (r3790) 821 940 * 822 * @param $default stringOptional. Default empty string941 * @param string $default Optional. Default empty string 823 942 * @uses get_option() To get the old bb-config.php location 824 943 * @return string The location of the bb-config.php file, if any -
trunk/src/includes/forums/functions.php
r6534 r6544 1073 1073 1074 1074 /** 1075 * Remove a deleted forum from all user s'subscriptions1075 * Remove a deleted forum from all user subscriptions 1076 1076 * 1077 1077 * @since 2.5.0 bbPress (r5156) … … 1090 1090 } 1091 1091 1092 // Bail if no forum 1092 1093 $forum_id = bbp_get_forum_id( $forum_id ); 1093 1094 // Bail if no forum1095 1094 if ( empty( $forum_id ) ) { 1096 1095 return; 1097 1096 } 1098 1097 1099 // Get users 1100 $users = (array) bbp_get_forum_subscribers( $forum_id ); 1101 1102 // Users exist 1103 if ( ! empty( $users ) ) { 1104 1105 // Loop through users 1106 foreach ( $users as $user ) { 1107 1108 // Remove each user 1109 bbp_remove_user_subscription( $user, $forum_id ); 1110 } 1111 } 1098 // Remove forum from all subscriptions 1099 return bbp_remove_object_from_all_users( $forum_id, '_bbp_subscription', 'post' ); 1112 1100 } 1113 1101 -
trunk/src/includes/forums/template.php
r6528 r6544 2505 2505 * @uses bbp_get_global_post_field() To get current post author 2506 2506 * @uses bbp_get_current_user_id() To get the current user id 2507 * @uses bbp_is_user_subscribed_to_forum() To check if the user is 2508 * subscribed to the forum 2507 * @uses bbp_is_user_subscribed() To check if the user is subscribed 2509 2508 * @uses apply_filters() Calls 'bbp_get_form_forum_subscribed' with the 2510 2509 * option … … 2525 2524 // Post author is not the current user 2526 2525 if ( bbp_get_current_user_id() !== $post_author ) { 2527 $forum_subscribed = bbp_is_user_subscribed _to_forum( $post_author);2526 $forum_subscribed = bbp_is_user_subscribed( $post_author, bbp_get_forum_id() ); 2528 2527 2529 2528 // Post author is the current user 2530 2529 } else { 2531 $forum_subscribed = bbp_is_user_subscribed _to_forum( bbp_get_current_user_id() );2530 $forum_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id(), bbp_get_forum_id() ); 2532 2531 } 2533 2532 2534 2533 // Get current status 2535 2534 } elseif ( bbp_is_single_forum() ) { 2536 $forum_subscribed = bbp_is_user_subscribed _to_forum( bbp_get_current_user_id() );2535 $forum_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id(), bbp_get_forum_id() ); 2537 2536 2538 2537 // No data -
trunk/src/includes/search/functions.php
r6438 r6544 39 39 40 40 /** 41 * Return the search 'squery args41 * Return the search query args 42 42 * 43 43 * @since 2.3.0 bbPress (r4579) -
trunk/src/includes/topics/functions.php
r6534 r6544 2381 2381 2382 2382 /** 2383 * Remove a deleted topic from all user s'favorites2383 * Remove a deleted topic from all user favorites 2384 2384 * 2385 2385 * @since 2.0.0 bbPress (r2652) … … 2414 2414 2415 2415 /** 2416 * Remove a deleted topic from all user s'subscriptions2416 * Remove a deleted topic from all user subscriptions 2417 2417 * 2418 2418 * @since 2.0.0 bbPress (r2652) … … 2431 2431 } 2432 2432 2433 // Bail if no topic 2433 2434 $topic_id = bbp_get_topic_id( $topic_id ); 2434 2435 // Bail if no topic2436 2435 if ( empty( $topic_id ) ) { 2437 2436 return; 2438 2437 } 2439 2438 2440 // Get users 2441 $users = (array) bbp_get_topic_subscribers( $topic_id ); 2442 2443 // Users exist 2444 if ( ! empty( $users ) ) { 2445 2446 // Loop through users 2447 foreach ( $users as $user ) { 2448 2449 // Remove each user 2450 bbp_remove_user_subscription( $user, $topic_id ); 2451 } 2452 } 2439 // Remove all users 2440 return bbp_remove_object_from_all_users( $topic_id, '_bbp_subscription', 'post' ); 2453 2441 } 2454 2442 -
trunk/src/includes/topics/template.php
r6533 r6544 4257 4257 * 4258 4258 * @uses bbp_is_topic_edit() To check if it's the topic edit page 4259 * @uses bbp_is_user_subscribed_to_topic() To check if the user is 4260 * subscribed to the topic 4259 * @uses bbp_is_user_subscribed() To check if the user is subscribed 4261 4260 * @uses apply_filters() Calls 'bbp_get_form_topic_subscribed' with the 4262 4261 * option … … 4277 4276 // Post author is not the current user 4278 4277 if ( bbp_get_current_user_id() !== $post_author ) { 4279 $topic_subscribed = bbp_is_user_subscribed _to_topic( $post_author);4278 $topic_subscribed = bbp_is_user_subscribed( $post_author, bbp_get_topic_id() ); 4280 4279 4281 4280 // Post author is the current user 4282 4281 } else { 4283 $topic_subscribed = bbp_is_user_subscribed _to_topic( bbp_get_current_user_id() );4282 $topic_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id(), bbp_get_topic_id() ); 4284 4283 } 4285 4284 4286 4285 // Get current status 4287 4286 } elseif ( bbp_is_single_topic() ) { 4288 $topic_subscribed = bbp_is_user_subscribed _to_topic( bbp_get_current_user_id() );4287 $topic_subscribed = bbp_is_user_subscribed( bbp_get_current_user_id(), bbp_get_topic_id() ); 4289 4288 4290 4289 // No data -
trunk/src/includes/users/engagements.php
r6534 r6544 57 57 58 58 /** 59 * Remove all users from an object 59 * Remove a user id from all objects 60 * 61 * @since 2.6.0 bbPress (r6109) 62 * 63 * @param int $user_id The user id 64 * @param string $meta_key The relationship key 65 * @param string $meta_type The relationship type (usually 'post') 66 * 67 * @uses delete_metadata() To remove user from all objects 68 * 69 * @return bool Returns true on success, false on failure 70 */ 71 function bbp_remove_user_from_all_objects( $user_id = 0, $meta_key = '', $meta_type = 'post' ) { 72 $retval = delete_metadata( $meta_type, null, $meta_key, $user_id, true ); 73 74 // Filter & return 75 return (bool) apply_filters( 'bbp_remove_user_from_all_objects', (bool) $retval, $user_id, $meta_key, $meta_type ); 76 } 77 78 /** 79 * Remove an object from all users 60 80 * 61 81 * @since 2.6.0 bbPress (r6109) … … 70 90 * @return bool Returns true on success, false on failure 71 91 */ 72 function bbp_remove_ all_users_from_object( $object_id = 0, $meta_key = '', $meta_type = 'post' ) {92 function bbp_remove_object_from_all_users( $object_id = 0, $meta_key = '', $meta_type = 'post' ) { 73 93 $retval = delete_metadata( $meta_type, $object_id, $meta_key, null, false ); 74 94 75 95 // Filter & return 76 return (bool) apply_filters( 'bbp_remove_all_users_from_object', (bool) $retval, $object_id, $meta_key, $meta_type ); 77 } 78 79 /** 80 * Remove a user id from all objects 81 * 82 * @since 2.6.0 bbPress (r6109) 83 * 84 * @param int $user_id The user id 85 * @param string $meta_key The relationship key 86 * @param string $meta_type The relationship type (usually 'post') 87 * 88 * @uses delete_metadata() To remove user from all objects 89 * 90 * @return bool Returns true on success, false on failure 91 */ 92 function bbp_remove_user_from_all_objects( $user_id = 0, $meta_key = '', $meta_type = 'post' ) { 93 $retval = delete_metadata( $meta_type, null, $meta_key, $user_id, true ); 94 95 // Filter & return 96 return (bool) apply_filters( 'bbp_remove_user_from_all_objects', (bool) $retval, $user_id, $meta_key, $meta_type ); 96 return (bool) apply_filters( 'bbp_remove_object_from_all_users', (bool) $retval, $object_id, $meta_key, $meta_type ); 97 97 } 98 98 … … 416 416 417 417 // Delete all engagements 418 bbp_remove_ all_users_from_object( $topic_id, '_bbp_engagement' );418 bbp_remove_object_from_all_users( $topic_id, '_bbp_engagement' ); 419 419 420 420 // Update the voice count for this topic id … … 519 519 520 520 /** 521 * Get a user's favorite topic ids522 *523 * @since 2.0.0 bbPress (r2652)524 *525 * @param int $user_id Optional. User id526 * @uses bbp_get_user_id() To get the user id527 * @uses bbp_get_topic_post_type() To get the topic post type528 * @uses apply_filters() Calls 'bbp_get_user_favorites_topic_ids' with529 * the favorites and user id530 * @return array|bool Results if user has favorites, otherwise null531 */532 function bbp_get_user_favorites_topic_ids( $user_id = 0 ) {533 $user_id = bbp_get_user_id( $user_id );534 $favorites = new WP_Query( array(535 'fields' => 'ids',536 'post_type' => bbp_get_topic_post_type(),537 'nopaging' => true,538 'no_found_rows' => true,539 'meta_query' => array( array(540 'key' => '_bbp_favorite',541 'value' => $user_id,542 'compare' => 'NUMERIC'543 ) )544 ) );545 546 // Filter & return547 return (array) apply_filters( 'bbp_get_user_favorites_topic_ids', $favorites->posts, $user_id );548 }549 550 /**551 521 * Check if a topic is in user's favorites or not 552 522 * … … 556 526 * @param int $topic_id Optional. Topic id 557 527 * @uses bbp_get_user_id() To get the user id 558 * @uses bbp_get_user_favorites_topic_ids() To get the user favorites559 528 * @uses bbp_get_topic() To get the topic 560 529 * @uses bbp_get_topic_id() To get the topic id … … 565 534 */ 566 535 function bbp_is_user_favorite( $user_id = 0, $topic_id = 0 ) { 567 $retval = false; 568 $user_id = bbp_get_user_id( $user_id, true, true ); 569 $favorites = bbp_get_user_favorites_topic_ids( $user_id ); 570 571 if ( ! empty( $favorites ) ) { 572 573 // Checking a specific topic id 574 if ( ! empty( $topic_id ) ) { 575 $topic = bbp_get_topic( $topic_id ); 576 $topic_id = ! empty( $topic ) ? $topic->ID : 0; 577 578 // Using the global topic id 579 } elseif ( bbp_get_topic_id() ) { 580 $topic_id = bbp_get_topic_id(); 581 582 // Use the current post id 583 } elseif ( ! bbp_get_topic_id() ) { 584 $topic_id = get_the_ID(); 585 } 586 587 // Is topic_id in the user's favorites 588 if ( ! empty( $topic_id ) ) { 589 $retval = bbp_is_object_of_user( $topic_id, $user_id, '_bbp_favorite' ); 590 } 591 } 592 593 // Filter & return 594 return (bool) apply_filters( 'bbp_is_user_favorite', $retval, $user_id, $topic_id, $favorites ); 536 $retval = bbp_is_object_of_user( $topic_id, $user_id, '_bbp_favorite' ); 537 538 // Filter & return 539 return (bool) apply_filters( 'bbp_is_user_favorite', $retval, $user_id, $topic_id ); 595 540 } 596 541 … … 612 557 */ 613 558 function bbp_add_user_favorite( $user_id = 0, $topic_id = 0 ) { 559 $user_id = bbp_get_user_id( $user_id, false, false ); 560 $topic_id = bbp_get_topic_id( $topic_id ); 614 561 615 562 // Bail if not enough info … … 646 593 */ 647 594 function bbp_remove_user_favorite( $user_id, $topic_id ) { 595 $user_id = bbp_get_user_id( $user_id, false, false ); 596 $topic_id = bbp_get_topic_id( $topic_id ); 648 597 649 598 // Bail if not enough info … … 776 725 777 726 /** 778 * Get the users who have subscribed to the forum 779 * 780 * @since 2.5.0 bbPress (r5156) 781 * 782 * @param int $forum_id Optional. forum id 783 * @uses bbp_get_users_for_object() To get the forum subscribers 784 * @uses apply_filters() Calls 'bbp_get_forum_subscribers' with the subscribers 785 * @return array|bool Results if the forum has any subscribers, otherwise false 786 */ 787 function bbp_get_forum_subscribers( $forum_id = 0 ) { 788 $forum_id = bbp_get_forum_id( $forum_id ); 789 $users = bbp_get_users_for_object( $forum_id, '_bbp_subscription' ); 790 791 // Filter & return 792 return (array) apply_filters( 'bbp_get_forum_subscribers', $users, $forum_id ); 793 } 794 795 /** 796 * Get the users who have subscribed to the topic 797 * 798 * @since 2.0.0 bbPress (r2668) 799 * 800 * @param int $topic_id Optional. Topic id 801 * @uses bbp_get_users_for_object() To get the topic subscribers 802 * @uses apply_filters() Calls 'bbp_get_topic_subscribers' with the subscribers 803 * @return array|bool Results if the topic has any subscribers, otherwise false 804 */ 805 function bbp_get_topic_subscribers( $topic_id = 0 ) { 806 $topic_id = bbp_get_topic_id( $topic_id ); 807 $users = bbp_get_users_for_object( $topic_id, '_bbp_subscription' ); 808 809 // Filter & return 810 return (array) apply_filters( 'bbp_get_topic_subscribers', $users, $topic_id ); 811 } 812 813 /** 814 * Get a user's subscribed topics 815 * 816 * @since 2.0.0 bbPress (r2668) 817 * 818 * @deprecated 2.5.0 bbPress (r5156) 819 * 820 * @param int $user_id Optional. User id 821 * @uses bbp_get_user_topic_subscriptions() To get the user's subscriptions 822 * @return array|bool Results if user has subscriptions, otherwise false 823 */ 824 function bbp_get_user_subscriptions( $user_id = 0 ) { 825 _deprecated_function( __FUNCTION__, 2.5, 'bbp_get_user_topic_subscriptions()' ); 826 $query = bbp_get_user_topic_subscriptions( $user_id ); 827 828 // Filter & return 829 return apply_filters( 'bbp_get_user_subscriptions', $query, $user_id ); 727 * Get the users who have subscribed 728 * 729 * @since 2.6.0 bbPress (r5156) 730 * 731 * @param int $object_id Optional. ID of forum, topic, or something else 732 * @uses bbp_get_users_for_object() To get the subscribers 733 * @uses apply_filters() Calls 'bbp_get_subscribers' with the subscribers 734 * @return array|bool Results if subscribers, otherwise false 735 */ 736 function bbp_get_subscribers( $object_id = 0, $type = 'post' ) { 737 $users = bbp_get_users_for_object( $object_id, '_bbp_subscription', $type ); 738 739 // Filter & return 740 return (array) apply_filters( 'bbp_get_forum_subscribers', $users, $object_id, $type ); 830 741 } 831 742 … … 883 794 return apply_filters( 'bbp_get_user_forum_subscriptions', $query, $user_id ); 884 795 } 796 797 /** 798 * Check if a topic or forum is in user's subscription list or not 799 * 800 * @since 2.5.0 bbPress (r5156) 801 * 802 * @param int $user_id Optional. User id 803 * @param int $object_id Optional. Topic id 804 * @uses get_post() To get the post object 805 * @uses bbp_get_user_subscribed_forum_ids() To get the user's forum subscriptions 806 * @uses bbp_get_user_subscribed_topic_ids() To get the user's topic subscriptions 807 * @uses bbp_get_forum_post_type() To get the forum post type 808 * @uses bbp_get_topic_post_type() To get the topic post type 809 * @uses apply_filters() Calls 'bbp_is_user_subscribed' with the bool, user id, 810 * forum/topic id and subscriptions 811 * @return bool True if the forum or topic is in user's subscriptions, otherwise false 812 */ 813 function bbp_is_user_subscribed( $user_id = 0, $object_id = 0, $type = 'post' ) { 814 $retval = bbp_is_object_of_user( $object_id, $user_id, '_bbp_subscription', $type ); 815 816 // Filter & return 817 return (bool) apply_filters( 'bbp_is_user_subscribed', $retval, $user_id, $object_id, $type ); 818 } 819 820 /** 821 * Add a user subscription 822 * 823 * @since 2.5.0 bbPress (r5156) 824 * @since 2.6.0 bbPress (r6544) Added $type parameter 825 * 826 * @param int $user_id Optional. User id 827 * @param int $object_id Optional. Topic id 828 * @param string $type Optional. Type of object being subscribed to 829 * 830 * @uses do_action() Calls 'bbp_add_user_subscription' with the user & object id 831 * @return bool Always true 832 */ 833 function bbp_add_user_subscription( $user_id = 0, $object_id = 0, $type = 'post' ) { 834 835 // Bail if not enough info 836 if ( empty( $user_id ) || empty( $object_id ) ) { 837 return false; 838 } 839 840 // Bail if already subscribed 841 if ( bbp_is_user_subscribed( $user_id, $object_id, $type ) ) { 842 return false; 843 } 844 845 // Bail if add fails 846 if ( ! bbp_add_user_to_object( $object_id, $user_id, '_bbp_subscription', $type ) ) { 847 return false; 848 } 849 850 do_action( 'bbp_add_user_subscription', $user_id, $object_id, $type ); 851 852 return true; 853 } 854 855 /** 856 * Remove a user subscription 857 * 858 * @since 2.5.0 bbPress (r5156) 859 * @since 2.6.0 bbPress (r6544) Added $type parameter 860 * 861 * @param int $user_id Optional. User id 862 * @param int $object_id Optional. Topic id 863 * @param string $type Optional. Type of object being subscribed to 864 * 865 * @uses bbp_is_user_subscribed() To check if the user is already subscribed 866 * @uses do_action() Calls 'bbp_remove_user_subscription' with the user id and 867 * topic id 868 * @return bool True if the topic was removed from user's subscriptions, 869 * otherwise false 870 */ 871 function bbp_remove_user_subscription( $user_id = 0, $object_id = 0, $type = 'post' ) { 872 873 // Bail if not enough info 874 if ( empty( $user_id ) || empty( $object_id ) ) { 875 return false; 876 } 877 878 // Bail if not subscribed 879 if ( ! bbp_is_user_subscribed( $user_id, $object_id, $type ) ) { 880 return false; 881 } 882 883 // Bail if remove fails 884 if ( ! bbp_remove_user_from_object( $object_id, $user_id, '_bbp_subscription', $type ) ) { 885 return false; 886 } 887 888 do_action( 'bbp_remove_user_subscription', $user_id, $object_id, $type ); 889 890 return true; 891 } 892 893 /** 894 * Handles the front end toggling of user subscriptions 895 * 896 * @since 2.0.0 bbPress (r2790) 897 * @since 2.6.l bbPress (r6543) 898 * 899 * @param string $action The requested action to compare this function to 900 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 901 * @uses bbp_get_user_id() To get the user id 902 * @uses bbp_verify_nonce_request() To verify the nonce and check the request 903 * @uses current_user_can() To check if the current user can edit the user 904 * @uses bbPress:errors:add() To log the error messages 905 * @uses bbp_is_user_subscribed() To check if the object is in user's 906 * subscriptions 907 * @uses bbp_remove_user_subscription() To remove the user subscription 908 * @uses bbp_add_user_subscription() To add the user subscription 909 * @uses do_action() Calls 'bbp_subscriptions_handler' with success, user id, 910 * object id and action 911 * @uses bbp_is_subscription() To check if it's the subscription page 912 * @uses bbp_redirect() To redirect to the url 913 */ 914 function bbp_subscriptions_handler( $action = '' ) { 915 916 // Default 917 $success = false; 918 919 // Bail if subscriptions not active 920 if ( ! bbp_is_subscriptions_active() ) { 921 return $success; 922 } 923 924 // Bail if no object ID is passed 925 if ( empty( $_GET['object_id'] ) ) { 926 return $success; 927 } 928 929 // Setup possible get actions 930 $possible_actions = array( 931 'bbp_subscribe', 932 'bbp_unsubscribe' 933 ); 934 935 // Bail if actions aren't meant for this function 936 if ( ! in_array( $action, $possible_actions, true ) ) { 937 return $success; 938 } 939 940 // Get required data 941 $user_id = bbp_get_current_user_id(); 942 $object_id = absint( $_GET['object_id'] ); 943 $object_type = ! empty( $_GET['object_type'] ) 944 ? sanitize_key( $_GET['object_type'] ) 945 : 'post'; 946 947 // Check for empty topic 948 if ( empty( $object_id ) ) { 949 bbp_add_error( 'bbp_subscription_object_id', __( '<strong>ERROR</strong>: Not found. What are you subscribing/unsubscribing to?', 'bbpress' ) ); 950 951 // Check nonce 952 } elseif ( ! bbp_verify_nonce_request( 'toggle-subscription_' . $object_id ) ) { 953 bbp_add_error( 'bbp_subscription_object_id', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress' ) ); 954 955 // Check current user's ability to edit the user 956 } elseif ( ! current_user_can( 'edit_user', $user_id ) ) { 957 bbp_add_error( 'bbp_subscription_permission', __( '<strong>ERROR</strong>: You do not have permission to edit subscriptions of that user.', 'bbpress' ) ); 958 } 959 960 // Bail if we have errors 961 if ( bbp_has_errors() ) { 962 return $success; 963 } 964 965 /** No errors *************************************************************/ 966 967 if ( 'bbp_unsubscribe' === $action ) { 968 $success = bbp_remove_user_subscription( $user_id, $object_id, $object_type ); 969 } elseif ( 'bbp_subscribe' === $action ) { 970 $success = bbp_add_user_subscription( $user_id, $object_id, $object_type ); 971 } 972 973 // Do additional subscriptions actions 974 do_action( 'bbp_subscriptions_handler', $success, $user_id, $object_id, $action, $object_type ); 975 976 // Success! 977 if ( true === $success ) { 978 979 // Redirect back from whence we came 980 if ( ! empty( $_REQUEST['redirect_to'] ) ) { 981 $redirect = $_REQUEST['redirect_to']; // Validated later 982 } elseif ( bbp_is_subscriptions() ) { 983 $redirect = bbp_get_subscriptions_permalink( $user_id ); 984 } elseif ( bbp_is_single_user() ) { 985 $redirect = bbp_get_user_profile_url(); 986 } elseif ( is_singular( bbp_get_topic_post_type() ) ) { 987 $redirect = bbp_get_topic_permalink( $object_id ); 988 } elseif ( is_singular( bbp_get_forum_post_type() ) ) { 989 $redirect = bbp_get_forum_permalink( $object_id ); 990 } elseif ( is_single() || is_page() ) { 991 $redirect = get_permalink(); 992 } else { 993 $redirect = get_permalink( $object_id ); 994 } 995 996 bbp_redirect( $redirect ); 997 998 // Fail! Handle errors 999 } elseif ( 'bbp_unsubscribe' === $action ) { 1000 bbp_add_error( 'bbp_unsubscribe', __( '<strong>ERROR</strong>: There was a problem unsubscribing.', 'bbpress' ) ); 1001 } elseif ( 'bbp_subscribe' === $action ) { 1002 bbp_add_error( 'bbp_subscribe', __( '<strong>ERROR</strong>: There was a problem subscribing.', 'bbpress' ) ); 1003 } 1004 1005 return (bool) $success; 1006 } 1007 1008 /** Query Helpers *************************************************************/ 1009 1010 /** 1011 * Get a user's favorite topic ids 1012 * 1013 * @since 2.0.0 bbPress (r2652) 1014 * 1015 * @param int $user_id Optional. User id 1016 * @uses bbp_get_user_id() To get the user id 1017 * @uses bbp_get_topic_post_type() To get the topic post type 1018 * @uses apply_filters() Calls 'bbp_get_user_favorites_topic_ids' with 1019 * the favorites and user id 1020 * @return array|bool Results if user has favorites, otherwise null 1021 */ 1022 function bbp_get_user_favorites_topic_ids( $user_id = 0 ) { 1023 $user_id = bbp_get_user_id( $user_id ); 1024 $favorites = new WP_Query( array( 1025 'fields' => 'ids', 1026 'post_type' => bbp_get_topic_post_type(), 1027 'nopaging' => true, 1028 'no_found_rows' => true, 1029 'meta_query' => array( array( 1030 'key' => '_bbp_favorite', 1031 'value' => $user_id, 1032 'compare' => 'NUMERIC' 1033 ) ) 1034 ) ); 1035 1036 // Filter & return 1037 return (array) apply_filters( 'bbp_get_user_favorites_topic_ids', $favorites->posts, $user_id ); 1038 } 1039 885 1040 886 1041 /** … … 915 1070 916 1071 /** 917 * Get a user's subscribed topic s'ids1072 * Get a user's subscribed topic ids 918 1073 * 919 1074 * @since 2.0.0 bbPress (r2668) … … 944 1099 } 945 1100 946 /** 947 * Check if a topic or forum is in user's subscription list or not 1101 /** Deprecated ****************************************************************/ 1102 1103 /** 1104 * Get a user's subscribed topics 1105 * 1106 * @since 2.0.0 bbPress (r2668) 1107 * @deprecated 2.5.0 bbPress (r5156) 1108 * 1109 * @param int $user_id Optional. User id 1110 * 1111 * @return array|bool Results if user has subscriptions, otherwise false 1112 */ 1113 function bbp_get_user_subscriptions( $user_id = 0 ) { 1114 _deprecated_function( __FUNCTION__, '2.5', 'bbp_get_user_topic_subscriptions()' ); 1115 $query = bbp_get_user_topic_subscriptions( $user_id ); 1116 1117 // Filter & return 1118 return apply_filters( 'bbp_get_user_subscriptions', $query, $user_id ); 1119 } 1120 1121 /** 1122 * Get the users who have subscribed to the forum 948 1123 * 949 1124 * @since 2.5.0 bbPress (r5156) 950 * 951 * @param int $user_id Optional. User id 952 * @param int $object_id Optional. Topic id 953 * @uses get_post() To get the post object 954 * @uses bbp_get_user_subscribed_forum_ids() To get the user's forum subscriptions 955 * @uses bbp_get_user_subscribed_topic_ids() To get the user's topic subscriptions 956 * @uses bbp_get_forum_post_type() To get the forum post type 957 * @uses bbp_get_topic_post_type() To get the topic post type 958 * @uses apply_filters() Calls 'bbp_is_user_subscribed' with the bool, user id, 959 * forum/topic id and subscriptions 960 * @return bool True if the forum or topic is in user's subscriptions, otherwise false 961 */ 962 function bbp_is_user_subscribed( $user_id = 0, $object_id = 0 ) { 963 964 // Assume user is not subscribed 965 $retval = false; 966 967 // Setup ID's array 968 $subscribed_ids = array(); 969 970 // User and object ID's are passed 971 if ( ! empty( $user_id ) && ! empty( $object_id ) ) { 972 973 // Get the post type 974 $post_type = get_post_type( $object_id ); 975 976 // Post exists, so check the types 977 if ( ! empty( $post_type ) ) { 978 979 switch( $post_type ) { 980 981 // Forum 982 case bbp_get_forum_post_type() : 983 $subscribed_ids = bbp_get_user_subscribed_forum_ids( $user_id ); 984 $retval = bbp_is_user_subscribed_to_forum( $user_id, $object_id, $subscribed_ids ); 985 break; 986 987 // Topic (default) 988 case bbp_get_topic_post_type() : 989 default : 990 $subscribed_ids = bbp_get_user_subscribed_topic_ids( $user_id ); 991 $retval = bbp_is_user_subscribed_to_topic( $user_id, $object_id, $subscribed_ids ); 992 break; 993 } 994 } 995 } 996 997 // Filter & return 998 return (bool) apply_filters( 'bbp_is_user_subscribed', $retval, $user_id, $object_id, $subscribed_ids ); 1125 * @deprecated 2.6.0 bbPress (r6543) 1126 * 1127 * @param int $forum_id Optional. forum id 1128 * 1129 * @return array|bool Results if the forum has any subscribers, otherwise false 1130 */ 1131 function bbp_get_forum_subscribers( $forum_id = 0 ) { 1132 $users = bbp_get_users_for_object( $forum_id, '_bbp_subscription' ); 1133 1134 // Filter & return 1135 return (array) apply_filters( 'bbp_get_forum_subscribers', $users, $forum_id ); 1136 } 1137 1138 /** 1139 * Get the users who have subscribed to the topic 1140 * 1141 * @since 2.0.0 bbPress (r2668) 1142 * @deprecated 2.6.0 bbPress (r6543) 1143 * 1144 * @param int $topic_id Optional. Topic id 1145 * 1146 * @return array|bool Results if the topic has any subscribers, otherwise false 1147 */ 1148 function bbp_get_topic_subscribers( $topic_id = 0 ) { 1149 $users = bbp_get_users_for_object( $topic_id, '_bbp_subscription' ); 1150 1151 // Filter & return 1152 return (array) apply_filters( 'bbp_get_topic_subscribers', $users, $topic_id ); 999 1153 } 1000 1154 … … 1003 1157 * 1004 1158 * @since 2.5.0 bbPress (r5156) 1005 * 1006 * @param int $user_id Optional. User id 1007 * @param int $forum_id Optional. Topic id 1008 * @param array $subscribed_ids Optional. Array of forum ID's to check 1009 * @uses bbp_get_user_id() To get the user id 1010 * @uses bbp_get_forum() To get the forum 1011 * @uses bbp_get_forum_id() To get the forum id 1012 * @uses bbp_is_object_of_user() To check if the user has a subscription 1013 * @uses apply_filters() Calls 'bbp_is_user_subscribed_to_forum' with the bool, user id, 1014 * forum id and subsriptions 1159 * @deprecated 2.6.0 bbPress (r6543) 1160 * 1161 * @param int $user_id Optional. User id 1162 * @param int $forum_id Optional. Forum id 1163 * 1015 1164 * @return bool True if the forum is in user's subscriptions, otherwise false 1016 1165 */ 1017 function bbp_is_user_subscribed_to_forum( $user_id = 0, $forum_id = 0, $subscribed_ids = array() ) { 1018 1019 // Assume user is not subscribed 1020 $retval = false; 1021 1022 // Validate user 1023 $user_id = bbp_get_user_id( $user_id, true, true ); 1024 if ( ! empty( $user_id ) ) { 1025 1026 // Get subscription ID's if none passed 1027 if ( empty( $subscribed_ids ) ) { 1028 $subscribed_ids = bbp_get_user_subscribed_forum_ids( $user_id ); 1029 } 1030 1031 // User has forum subscriptions 1032 if ( ! empty( $subscribed_ids ) ) { 1033 1034 // Checking a specific forum id 1035 if ( ! empty( $forum_id ) ) { 1036 $forum = bbp_get_forum( $forum_id ); 1037 $forum_id = ! empty( $forum ) ? $forum->ID : 0; 1038 1039 // Using the global forum id 1040 } elseif ( bbp_get_forum_id() ) { 1041 $forum_id = bbp_get_forum_id(); 1042 1043 // Use the current post id 1044 } elseif ( ! bbp_get_forum_id() ) { 1045 $forum_id = get_the_ID(); 1046 } 1047 1048 // Is forum_id in the user's subscriptions 1049 if ( ! empty( $forum_id ) ) { 1050 $retval = bbp_is_object_of_user( $forum_id, $user_id, '_bbp_subscription' ); 1051 } 1052 } 1053 } 1054 1055 // Filter & return 1056 return (bool) apply_filters( 'bbp_is_user_subscribed_to_forum', $retval, $user_id, $forum_id, $subscribed_ids ); 1166 function bbp_is_user_subscribed_to_forum( $user_id = 0, $forum_id = 0 ) { 1167 return bbp_is_user_subscribed( $user_id, $forum_id ); 1057 1168 } 1058 1169 … … 1061 1172 * 1062 1173 * @since 2.5.0 bbPress (r5156) 1174 * @deprecated 2.6.0 bbPress (r6543) Use bbp_is_user_subscribed() 1063 1175 * 1064 1176 * @param int $user_id Optional. User id 1065 1177 * @param int $topic_id Optional. Topic id 1066 * @param array $subscribed_ids Optional. Array of topic ID's to check1067 * @uses bbp_get_user_id() To get the user id1068 * @uses bbp_get_topic() To get the topic1069 * @uses bbp_get_topic_id() To get the topic id1070 * @uses bbp_is_object_of_user() To check if the user is subscribed1071 * @uses apply_filters() Calls 'bbp_is_user_subscribed_to_topic' with the bool, user id,1072 * topic id and subsriptions1073 1178 * @return bool True if the topic is in user's subscriptions, otherwise false 1074 1179 */ 1075 function bbp_is_user_subscribed_to_topic( $user_id = 0, $topic_id = 0, $subscribed_ids = array() ) { 1076 1077 // Assume user is not subscribed 1078 $retval = false; 1079 1080 // Validate user 1081 $user_id = bbp_get_user_id( $user_id, true, true ); 1082 if ( ! empty( $user_id ) ) { 1083 1084 // Get subscription ID's if none passed 1085 if ( empty( $subscribed_ids ) ) { 1086 $subscribed_ids = bbp_get_user_subscribed_topic_ids( $user_id ); 1087 } 1088 1089 // User has topic subscriptions 1090 if ( ! empty( $subscribed_ids ) ) { 1091 1092 // Checking a specific topic id 1093 if ( ! empty( $topic_id ) ) { 1094 $topic = bbp_get_topic( $topic_id ); 1095 $topic_id = ! empty( $topic ) ? $topic->ID : 0; 1096 1097 // Using the global topic id 1098 } elseif ( bbp_get_topic_id() ) { 1099 $topic_id = bbp_get_topic_id(); 1100 1101 // Use the current post id 1102 } elseif ( ! bbp_get_topic_id() ) { 1103 $topic_id = get_the_ID(); 1104 } 1105 1106 // Is topic_id in the user's subscriptions 1107 if ( ! empty( $topic_id ) ) { 1108 $retval = bbp_is_object_of_user( $topic_id, $user_id, '_bbp_subscription' ); 1109 } 1110 } 1111 } 1112 1113 // Filter & return 1114 return (bool) apply_filters( 'bbp_is_user_subscribed_to_topic', $retval, $user_id, $topic_id, $subscribed_ids ); 1115 } 1116 1117 /** 1118 * Add a user subscription 1180 function bbp_is_user_subscribed_to_topic( $user_id = 0, $topic_id = 0 ) { 1181 return bbp_is_user_subscribed( $user_id, $topic_id ); 1182 } 1183 1184 /** 1185 * Remove a forum from user's subscriptions 1119 1186 * 1120 1187 * @since 2.5.0 bbPress (r5156) 1121 * 1122 * @param int $user_id Optional. User id 1123 * @param int $object_id Optional. Topic id 1124 * @uses get_post() To get the post object 1125 * @uses do_action() Calls 'bbp_add_user_subscription' with the user & object id 1188 * @deprecated 2.6.0 bbPress (r6543) 1189 * 1190 * @param int $user_id Optional. User id 1191 * @param int $forum_id Optional. forum id 1192 * @return bool True if the forum was removed from user's subscriptions, 1193 * otherwise false 1194 */ 1195 function bbp_remove_user_forum_subscription( $user_id = 0, $forum_id = 0 ) { 1196 return bbp_remove_user_subscription( $user_id, $forum_id ); 1197 } 1198 1199 /** 1200 * Remove a topic from user's subscriptions 1201 * 1202 * @since 2.5.0 bbPress (r5156) 1203 * @deprecated 2.6.0 bbPress (r6543) 1204 * 1205 * @param int $user_id Optional. User id 1206 * @param int $topic_id Optional. Topic id 1207 * @return bool True if the topic was removed from user's subscriptions, 1208 * otherwise false 1209 */ 1210 function bbp_remove_user_topic_subscription( $user_id = 0, $topic_id = 0 ) { 1211 return bbp_remove_user_subscription( $user_id, $topic_id ); 1212 } 1213 1214 /** 1215 * Add a forum to user's subscriptions 1216 * 1217 * @since 2.5.0 bbPress (r5156) 1218 * @deprecated 2.6.0 bbPress (r6543) 1219 * 1220 * @param int $user_id Optional. User id 1221 * @param int $forum_id Optional. forum id 1126 1222 * @return bool Always true 1127 1223 */ 1128 function bbp_add_user_subscription( $user_id = 0, $object_id = 0 ) {1129 1130 // Bail if not enough info1131 if ( empty( $user_id ) || empty( $object_id ) ) {1132 return false;1133 }1134 1135 // Get the post type1136 $post_type = get_post_type( $object_id );1137 if ( empty( $post_type ) ) {1138 return false;1139 }1140 1141 // Bail if already subscribed1142 if ( bbp_is_user_subscribed( $user_id, $object_id ) ) {1143 return false;1144 }1145 1146 // Bail if add fails1147 if ( ! bbp_add_user_to_object( $object_id, $user_id, '_bbp_subscription' ) ) {1148 return false;1149 }1150 1151 do_action( 'bbp_add_user_subscription', $user_id, $object_id, $post_type );1152 1153 return true;1154 }1155 1156 /**1157 * Add a forum to user's subscriptions1158 *1159 * @since 2.5.0 bbPress (r5156)1160 *1161 * @param int $user_id Optional. User id1162 * @param int $forum_id Optional. forum id1163 * @uses bbp_get_forum() To get the forum1164 * @uses bbp_add_user_subscription() To add the user subscription1165 * @uses do_action() Calls 'bbp_add_user_subscription' with the user & forum id1166 * @return bool Always true1167 */1168 1224 function bbp_add_user_forum_subscription( $user_id = 0, $forum_id = 0 ) { 1169 1170 // Bail if not enough info 1171 if ( empty( $user_id ) || empty( $forum_id ) ) { 1172 return false; 1173 } 1174 1175 // Bail if no forum 1176 $forum = bbp_get_forum( $forum_id ); 1177 if ( empty( $forum ) ) { 1178 return false; 1179 } 1180 1181 // Bail if already subscribed 1182 if ( bbp_is_user_subscribed( $user_id, $forum_id ) ) { 1183 return false; 1184 } 1185 1186 // Bail if add fails 1187 if ( ! bbp_add_user_subscription( $user_id, $forum_id ) ) { 1188 return false; 1189 } 1190 1191 do_action( 'bbp_add_user_forum_subscription', $user_id, $forum_id ); 1192 1193 return true; 1225 return bbp_add_user_subscription( $user_id, $forum_id ); 1194 1226 } 1195 1227 … … 1203 1235 * 1204 1236 * @since 2.0.0 bbPress (r2668) 1237 * @deprecated 2.6.0 bbPress (r6543) 1205 1238 * 1206 1239 * @param int $user_id Optional. User id 1207 1240 * @param int $topic_id Optional. Topic id 1208 * @uses bbp_add_user_subscription() To add the subscription1209 * @uses do_action() Calls 'bbp_add_user_subscription' with the user & topic id1210 1241 * @return bool Always true 1211 1242 */ 1212 1243 function bbp_add_user_topic_subscription( $user_id = 0, $topic_id = 0 ) { 1213 1214 // Bail if not enough info 1215 if ( empty( $user_id ) || empty( $topic_id ) ) { 1216 return false; 1217 } 1218 1219 // Bail if already subscribed 1220 if ( bbp_is_user_subscribed_to_topic( $user_id, $topic_id ) ) { 1221 return false; 1222 } 1223 1224 // Bail if add fails 1225 if ( ! bbp_add_user_subscription( $user_id, $topic_id ) ) { 1226 return false; 1227 } 1228 1229 do_action( 'bbp_add_user_topic_subscription', $user_id, $topic_id ); 1230 1231 return true; 1232 } 1233 1234 /** 1235 * Remove a user subscription 1236 * 1237 * @since 2.0.0 bbPress (r2668) 1238 * 1239 * @param int $user_id Optional. User id 1240 * @param int $object_id Optional. Topic id 1241 * @uses get_post() To get the post object 1242 * @uses bbp_is_user_subscribed() To check if the user is already subscribed 1243 * @uses do_action() Calls 'bbp_remove_user_subscription' with the user id and 1244 * topic id 1245 * @return bool True if the topic was removed from user's subscriptions, 1246 * otherwise false 1247 */ 1248 function bbp_remove_user_subscription( $user_id = 0, $object_id = 0 ) { 1249 1250 // Bail if not enough info 1251 if ( empty( $user_id ) || empty( $object_id ) ) { 1252 return false; 1253 } 1254 1255 // Get post type 1256 $post_type = get_post_type( $object_id ); 1257 if ( empty( $post_type ) ) { 1258 return false; 1259 } 1260 1261 // Bail if not subscribed 1262 if ( ! bbp_is_user_subscribed( $user_id, $object_id ) ) { 1263 return false; 1264 } 1265 1266 // Bail if remove fails 1267 if ( ! bbp_remove_user_from_object( $object_id, $user_id, '_bbp_subscription' ) ) { 1268 return false; 1269 } 1270 1271 do_action( 'bbp_remove_user_subscription', $user_id, $object_id, $post_type ); 1272 1273 return true; 1274 } 1275 1276 /** 1277 * Remove a forum from user's subscriptions 1244 return bbp_add_user_subscription( $user_id, $topic_id ); 1245 } 1246 1247 /** 1248 * Handles the front end toggling of forum subscriptions 1278 1249 * 1279 1250 * @since 2.5.0 bbPress (r5156) 1280 * 1281 * @param int $user_id Optional. User id 1282 * @param int $forum_id Optional. forum id 1283 * @uses bbp_remove_user_subscription() To remove the subscription 1284 * @uses do_action() Calls 'bbp_remove_user_subscription' with the user id and 1285 * forum id 1286 * @return bool True if the forum was removed from user's subscriptions, 1287 * otherwise false 1288 */ 1289 function bbp_remove_user_forum_subscription( $user_id = 0, $forum_id = 0 ) { 1290 1291 // Bail if not enough info 1292 if ( empty( $user_id ) || empty( $forum_id ) ) { 1293 return false; 1294 } 1295 1296 // Bail if remove fails 1297 if ( ! bbp_remove_user_subscription( $user_id, $forum_id ) ) { 1298 return false; 1299 } 1300 1301 do_action( 'bbp_remove_user_forum_subscription', $user_id, $forum_id ); 1302 1303 return true; 1304 } 1305 1306 /** 1307 * Remove a topic from user's subscriptions 1308 * 1309 * @since 2.5.0 bbPress (r5156) 1310 * 1311 * @param int $user_id Optional. User id 1312 * @param int $topic_id Optional. Topic id 1313 * @uses bbp_remove_user_subscription() To remove the subscription 1314 * @uses do_action() Calls 'bbp_remove_user_topic_subscription' with the user id and 1315 * topic id 1316 * @return bool True if the topic was removed from user's subscriptions, 1317 * otherwise false 1318 */ 1319 function bbp_remove_user_topic_subscription( $user_id = 0, $topic_id = 0 ) { 1320 1321 // Bail if not enough info 1322 if ( empty( $user_id ) || empty( $topic_id ) ) { 1323 return false; 1324 } 1325 1326 // Bail if remove fails 1327 if ( ! bbp_remove_user_subscription( $user_id, $topic_id ) ) { 1328 return false; 1329 } 1330 1331 do_action( 'bbp_remove_user_topic_subscription', $user_id, $topic_id ); 1332 1333 return true; 1334 } 1335 1336 /** 1337 * Handles the front end subscribing and unsubscribing forums 1338 * 1339 * @since 2.5.0 bbPress (r5156) 1340 * 1341 * @param string $action The requested action to compare this function to 1342 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 1343 * @uses bbp_get_user_id() To get the user id 1344 * @uses bbp_verify_nonce_request() To verify the nonce and check the request 1345 * @uses current_user_can() To check if the current user can edit the user 1346 * @uses bbPress:errors:add() To log the error messages 1347 * @uses bbp_is_user_subscribed() To check if the forum is in user's 1348 * subscriptions 1349 * @uses bbp_remove_user_subscription() To remove the user subscription 1350 * @uses bbp_add_user_subscription() To add the user subscription 1351 * @uses do_action() Calls 'bbp_subscriptions_handler' with success, user id, 1352 * forum id and action 1353 * @uses bbp_is_subscription() To check if it's the subscription page 1354 * @uses bbp_get_forum_permalink() To get the forum permalink 1355 * @uses bbp_redirect() To redirect to the url 1251 * @deprecated 2.6.0 bbPress (r6543) 1356 1252 */ 1357 1253 function bbp_forum_subscriptions_handler( $action = '' ) { 1358 1359 // Default 1360 $success = false; 1361 1362 // Bail if subscriptions not active 1363 if ( ! bbp_is_subscriptions_active() ) { 1364 return $success; 1365 } 1366 1367 // Bail if no forum ID is passed 1368 if ( empty( $_GET['forum_id'] ) ) { 1369 return $success; 1370 } 1371 1372 // Setup possible get actions 1373 $possible_actions = array( 1374 'bbp_subscribe', 1375 'bbp_unsubscribe', 1376 ); 1377 1378 // Bail if actions aren't meant for this function 1379 if ( ! in_array( $action, $possible_actions, true ) ) { 1380 return $success; 1381 } 1382 1383 // Get required data 1384 $forum_id = bbp_get_forum_id( $_GET['forum_id'] ); 1385 $user_id = bbp_get_user_id( 0, true, true ); 1386 1387 // Check for empty forum 1388 if ( empty( $forum_id ) ) { 1389 bbp_add_error( 'bbp_subscription_forum_id', __( '<strong>ERROR</strong>: No forum was found. Which forum are you subscribing/unsubscribing to?', 'bbpress' ) ); 1390 1391 // Check nonce 1392 } elseif ( ! bbp_verify_nonce_request( 'toggle-subscription_' . $forum_id ) ) { 1393 bbp_add_error( 'bbp_subscription_forum_id', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress' ) ); 1394 1395 // Check current user's ability to edit the user 1396 } elseif ( ! current_user_can( 'edit_user', $user_id ) ) { 1397 bbp_add_error( 'bbp_subscription_permission', __( '<strong>ERROR</strong>: You do not have permission to edit favorites of that user.', 'bbpress' ) ); 1398 } 1399 1400 // Bail if we have errors 1401 if ( bbp_has_errors() ) { 1402 return $success; 1403 } 1404 1405 /** No errors *************************************************************/ 1406 1407 if ( 'bbp_unsubscribe' === $action ) { 1408 $success = bbp_remove_user_subscription( $user_id, $forum_id ); 1409 } elseif ( 'bbp_subscribe' === $action ) { 1410 $success = bbp_add_user_subscription( $user_id, $forum_id ); 1411 } 1412 1413 // Do additional subscriptions actions 1414 do_action( 'bbp_subscriptions_handler', $success, $user_id, $forum_id, $action ); 1415 1416 // Success! 1417 if ( true === $success ) { 1418 1419 // Redirect back from whence we came 1420 if ( ! empty( $_REQUEST['redirect_to'] ) ) { 1421 $redirect = $_REQUEST['redirect_to']; // Validated later 1422 } elseif ( bbp_is_subscriptions() ) { 1423 $redirect = bbp_get_subscriptions_permalink( $user_id ); 1424 } elseif ( bbp_is_single_user() ) { 1425 $redirect = bbp_get_user_profile_url(); 1426 } elseif ( is_singular( bbp_get_forum_post_type() ) ) { 1427 $redirect = bbp_get_forum_permalink( $forum_id ); 1428 } elseif ( is_single() || is_page() ) { 1429 $redirect = get_permalink(); 1430 } else { 1431 $redirect = get_permalink( $forum_id ); 1432 } 1433 1434 bbp_redirect( $redirect ); 1435 1436 // Fail! Handle errors 1437 } elseif ( 'bbp_unsubscribe' === $action ) { 1438 bbp_add_error( 'bbp_unsubscribe', __( '<strong>ERROR</strong>: There was a problem unsubscribing from that forum.', 'bbpress' ) ); 1439 } elseif ( 'bbp_subscribe' === $action ) { 1440 bbp_add_error( 'bbp_subscribe', __( '<strong>ERROR</strong>: There was a problem subscribing to that forum.', 'bbpress' ) ); 1441 } 1442 1443 return (bool) $success; 1444 } 1445 1446 /** 1447 * Handles the front end subscribing and unsubscribing topics 1448 * 1449 * @since 2.0.0 bbPress (r2790) 1450 * 1451 * @param string $action The requested action to compare this function to 1452 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 1453 * @uses bbp_get_user_id() To get the user id 1454 * @uses bbp_verify_nonce_request() To verify the nonce and check the request 1455 * @uses current_user_can() To check if the current user can edit the user 1456 * @uses bbPress:errors:add() To log the error messages 1457 * @uses bbp_is_user_subscribed() To check if the topic is in user's 1458 * subscriptions 1459 * @uses bbp_remove_user_subscription() To remove the user subscription 1460 * @uses bbp_add_user_subscription() To add the user subscription 1461 * @uses do_action() Calls 'bbp_subscriptions_handler' with success, user id, 1462 * topic id and action 1463 * @uses bbp_is_subscription() To check if it's the subscription page 1464 * @uses bbp_get_topic_permalink() To get the topic permalink 1465 * @uses bbp_redirect() To redirect to the url 1466 */ 1467 function bbp_subscriptions_handler( $action = '' ) { 1468 1469 // Default 1470 $success = false; 1471 1472 // Bail if subscriptions not active 1473 if ( ! bbp_is_subscriptions_active() ) { 1474 return $success; 1475 } 1476 1477 // Bail if no topic ID is passed 1478 if ( empty( $_GET['topic_id'] ) ) { 1479 return $success; 1480 } 1481 1482 // Setup possible get actions 1483 $possible_actions = array( 1484 'bbp_subscribe', 1485 'bbp_unsubscribe', 1486 ); 1487 1488 // Bail if actions aren't meant for this function 1489 if ( ! in_array( $action, $possible_actions, true ) ) { 1490 return $success; 1491 } 1492 1493 // Get required data 1494 $topic_id = bbp_get_topic_id( $_GET['topic_id'] ); 1495 $user_id = bbp_get_user_id( 0, true, true ); 1496 1497 // Check for empty topic 1498 if ( empty( $topic_id ) ) { 1499 bbp_add_error( 'bbp_subscription_topic_id', __( '<strong>ERROR</strong>: No topic was found. Which topic are you subscribing/unsubscribing to?', 'bbpress' ) ); 1500 1501 // Check nonce 1502 } elseif ( ! bbp_verify_nonce_request( 'toggle-subscription_' . $topic_id ) ) { 1503 bbp_add_error( 'bbp_subscription_topic_id', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress' ) ); 1504 1505 // Check current user's ability to edit the user 1506 } elseif ( ! current_user_can( 'edit_user', $user_id ) ) { 1507 bbp_add_error( 'bbp_subscription_permission', __( '<strong>ERROR</strong>: You do not have permission to edit favorites of that user.', 'bbpress' ) ); 1508 } 1509 1510 // Bail if we have errors 1511 if ( bbp_has_errors() ) { 1512 return $success; 1513 } 1514 1515 /** No errors *************************************************************/ 1516 1517 if ( 'bbp_unsubscribe' === $action ) { 1518 $success = bbp_remove_user_subscription( $user_id, $topic_id ); 1519 } elseif ( 'bbp_subscribe' === $action ) { 1520 $success = bbp_add_user_subscription( $user_id, $topic_id ); 1521 } 1522 1523 // Do additional subscriptions actions 1524 do_action( 'bbp_subscriptions_handler', $success, $user_id, $topic_id, $action ); 1525 1526 // Success! 1527 if ( true === $success ) { 1528 1529 // Redirect back from whence we came 1530 if ( ! empty( $_REQUEST['redirect_to'] ) ) { 1531 $redirect = $_REQUEST['redirect_to']; // Validated later 1532 } elseif ( bbp_is_subscriptions() ) { 1533 $redirect = bbp_get_subscriptions_permalink( $user_id ); 1534 } elseif ( bbp_is_single_user() ) { 1535 $redirect = bbp_get_user_profile_url(); 1536 } elseif ( is_singular( bbp_get_topic_post_type() ) ) { 1537 $redirect = bbp_get_topic_permalink( $topic_id ); 1538 } elseif ( is_single() || is_page() ) { 1539 $redirect = get_permalink(); 1540 } else { 1541 $redirect = get_permalink( $topic_id ); 1542 } 1543 1544 bbp_redirect( $redirect ); 1545 1546 // Fail! Handle errors 1547 } elseif ( 'bbp_unsubscribe' === $action ) { 1548 bbp_add_error( 'bbp_unsubscribe', __( '<strong>ERROR</strong>: There was a problem unsubscribing from that topic.', 'bbpress' ) ); 1549 } elseif ( 'bbp_subscribe' === $action ) { 1550 bbp_add_error( 'bbp_subscribe', __( '<strong>ERROR</strong>: There was a problem subscribing to that topic.', 'bbpress' ) ); 1551 } 1552 1553 return (bool) $success; 1554 } 1254 return bbp_subscriptions_handler( $action ); 1255 } -
trunk/src/includes/users/template.php
r6538 r6544 1167 1167 1168 1168 // Validate user and topic ID's 1169 $user_id = bbp_get_user_id( $r['user_id'], true, true ); 1170 $topic_id = bbp_get_topic_id( $r['topic_id'] ); 1171 if ( empty( $user_id ) || empty( $topic_id ) ) { 1169 $user_id = bbp_get_user_id( $r['user_id'], true, true ); 1170 $object_id = bbp_get_topic_id( $r['topic_id'] ); 1171 1172 // Bail if empty 1173 if ( empty( $user_id ) || empty( $object_id ) ) { 1172 1174 return false; 1173 1175 } … … 1179 1181 1180 1182 // Decide which link to show 1181 $is_fav = bbp_is_user_favorite( $user_id, $ topic_id );1183 $is_fav = bbp_is_user_favorite( $user_id, $object_id ); 1182 1184 if ( ! empty( $is_fav ) ) { 1183 $text 1184 $q uery_args = array( 'action' => 'bbp_favorite_remove', 'topic_id' => $topic_id );1185 $text = $r['favorited']; 1186 $q_args = array( 'action' => 'bbp_favorite_remove', 'object_id' => $object_id ); 1185 1187 } else { 1186 $text 1187 $q uery_args = array( 'action' => 'bbp_favorite_add', 'topic_id' => $topic_id );1188 $text = $r['favorite']; 1189 $q_args = array( 'action' => 'bbp_favorite_add', 'object_id' => $object_id ); 1188 1190 } 1189 1191 1190 1192 // Custom redirect 1191 1193 if ( ! empty( $r['redirect_to'] ) ) { 1192 $query_args['redirect_to'] = urlencode( $r['redirect_to'] ); 1193 } 1194 1195 // Create the link based where the user is and if the topic is 1196 // already the user's favorite 1197 if ( bbp_is_favorites() ) { 1198 $permalink = bbp_get_favorites_permalink( $user_id ); 1199 } elseif ( bbp_is_single_topic() || bbp_is_single_reply() ) { 1200 $permalink = bbp_get_topic_permalink( $topic_id ); 1201 } else { 1202 $permalink = get_permalink(); 1203 } 1204 1205 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-favorite_' . $topic_id ) ); 1194 $q_args['redirect_to'] = urlencode( $r['redirect_to'] ); 1195 } 1196 1197 // URL 1198 $url = esc_url( wp_nonce_url( add_query_arg( $q_args ), 'toggle-favorite_' . $object_id ) ); 1206 1199 $sub = $is_fav ? ' class="is-favorite"' : ''; 1207 $html = sprintf( '%s<span id="favorite-%d" %s><a href="%s" class="favorite-toggle" data- topic="%d" data-bbp-nonce="%s">%s</a></span>%s', $r['before'], $topic_id, $sub, $url, $topic_id, wp_create_nonce( 'toggle-favorite_' . $topic_id ), $text, $r['after'] );1200 $html = sprintf( '%s<span id="favorite-%d" %s><a href="%s" class="favorite-toggle" data-object-id="%d" data-bbp-nonce="%s">%s</a></span>%s', $r['before'], $object_id, $sub, $url, $object_id, wp_create_nonce( 'toggle-favorite_' . $object_id ), $text, $r['after'] ); 1208 1201 1209 1202 // Initial output is wrapped in a span, ajax output is hooked to this … … 1213 1206 1214 1207 // Filter & return 1215 return apply_filters( 'bbp_get_user_favorites_link', $html, $r, $user_id, $ topic_id );1208 return apply_filters( 'bbp_get_user_favorites_link', $html, $r, $user_id, $object_id ); 1216 1209 } 1217 1210 … … 1342 1335 * @uses bbp_get_forum_id() To get the forum id 1343 1336 * @uses current_user_can() To check if the current user can edit user 1344 * @uses bbp_is_user_subscribed_to_forum() To check if the user is subscribed to the forum 1345 * @uses bbp_is_user_subscribed_to_topic() To check if the user is subscribed to the topic 1337 * @uses bbp_is_user_subscribed() To check if the user is subscribed 1346 1338 * @uses bbp_is_subscriptions() To check if it's the subscriptions page 1347 1339 * @uses bbp_get_subscriptions_permalink() To get subscriptions link … … 1374 1366 $topic_id = bbp_get_topic_id( $r['topic_id'] ); 1375 1367 $forum_id = bbp_get_forum_id( $r['forum_id'] ); 1368 1369 // Bail if anything is missing 1376 1370 if ( empty( $user_id ) || ( empty( $topic_id ) && empty( $forum_id ) ) ) { 1377 1371 return false; … … 1383 1377 } 1384 1378 1385 // Check if viewing a single forum 1386 if ( empty( $topic_id ) && ! empty( $forum_id ) ) { 1387 1388 // Decide which link to show 1389 $is_subscribed = bbp_is_user_subscribed_to_forum( $user_id, $forum_id ); 1390 if ( ! empty( $is_subscribed ) ) { 1391 $text = $r['unsubscribe']; 1392 $query_args = array( 'action' => 'bbp_unsubscribe', 'forum_id' => $forum_id ); 1393 } else { 1394 $text = $r['subscribe']; 1395 $query_args = array( 'action' => 'bbp_subscribe', 'forum_id' => $forum_id ); 1396 } 1397 1398 // Custom redirect 1399 if ( ! empty( $r['redirect_to'] ) ) { 1400 $query_args['redirect_to'] = urlencode( $r['redirect_to'] ); 1401 } 1402 1403 // Create the link based where the user is and if the user is 1404 // subscribed already 1405 if ( bbp_is_subscriptions() ) { 1406 $permalink = bbp_get_subscriptions_permalink( $user_id ); 1407 } elseif ( bbp_is_single_forum() || bbp_is_single_reply() ) { 1408 $permalink = bbp_get_forum_permalink( $forum_id ); 1409 } else { 1410 $permalink = get_permalink(); 1411 } 1412 1413 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $forum_id ) ); 1414 $sub = $is_subscribed ? ' class="is-subscribed"' : ''; 1415 $html = sprintf( '%s<span id="subscribe-%d" %s><a href="%s" class="subscription-toggle" data-forum="%d" data-bbp-nonce="%s">%s</a></span>%s', $r['before'], $forum_id, $sub, $url, $forum_id, wp_create_nonce( 'toggle-subscription_' . $forum_id ), $text, $r['after'] ); 1416 1417 // Initial output is wrapped in a span, ajax output is hooked to this 1418 if ( ! empty( $wrap ) ) { 1419 $html = '<span id="subscription-toggle">' . $html . '</span>'; 1420 } 1421 1379 // Check if viewing forum or topic (more to do later) 1380 if ( ! empty( $forum_id ) ) { 1381 $object_id = $forum_id; 1382 } elseif ( ! empty( $topic_id ) ) { 1383 $object_id = $topic_id; 1384 } 1385 1386 // Decide which link to show 1387 $is_subscribed = bbp_is_user_subscribed( $user_id, $object_id ); 1388 if ( ! empty( $is_subscribed ) ) { 1389 $text = $r['unsubscribe']; 1390 $q_args = array( 'action' => 'bbp_unsubscribe', 'object_id' => $object_id ); 1422 1391 } else { 1423 1424 // Decide which link to show 1425 $is_subscribed = bbp_is_user_subscribed_to_topic( $user_id, $topic_id ); 1426 if ( ! empty( $is_subscribed ) ) { 1427 $text = $r['unsubscribe']; 1428 $query_args = array( 'action' => 'bbp_unsubscribe', 'topic_id' => $topic_id ); 1429 } else { 1430 $text = $r['subscribe']; 1431 $query_args = array( 'action' => 'bbp_subscribe', 'topic_id' => $topic_id ); 1432 } 1433 1434 // Custom redirect 1435 if ( ! empty( $r['redirect_to'] ) ) { 1436 $query_args['redirect_to'] = urlencode( $r['redirect_to'] ); 1437 } 1438 1439 // Create the link based where the user is and if the user is 1440 // subscribed already 1441 if ( bbp_is_subscriptions() ) { 1442 $permalink = bbp_get_subscriptions_permalink( $user_id ); 1443 } elseif ( bbp_is_single_topic() || bbp_is_single_reply() ) { 1444 $permalink = bbp_get_topic_permalink( $topic_id ); 1445 } else { 1446 $permalink = get_permalink(); 1447 } 1448 1449 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $topic_id ) ); 1450 $sub = $is_subscribed ? ' class="is-subscribed"' : ''; 1451 $html = sprintf( '%s<span id="subscribe-%d" %s><a href="%s" class="subscription-toggle" data-topic="%d" data-bbp-nonce="%s">%s</a></span>%s', $r['before'], $topic_id, $sub, $url, $topic_id, wp_create_nonce( 'toggle-subscription_' . $topic_id ), $text, $r['after'] ); 1452 1453 // Initial output is wrapped in a span, ajax output is hooked to this 1454 if ( ! empty( $wrap ) ) { 1455 $html = '<span id="subscription-toggle">' . $html . '</span>'; 1456 } 1457 } 1458 1459 // Filter & return 1460 return apply_filters( 'bbp_get_user_subscribe_link', $html, $r, $user_id, $topic_id ); 1392 $text = $r['subscribe']; 1393 $q_args = array( 'action' => 'bbp_subscribe', 'object_id' => $object_id ); 1394 } 1395 1396 // Custom redirect 1397 if ( ! empty( $r['redirect_to'] ) ) { 1398 $q_args['redirect_to'] = urlencode( $r['redirect_to'] ); 1399 } 1400 1401 // URL 1402 $url = esc_url( wp_nonce_url( add_query_arg( $q_args ), 'toggle-subscription_' . $object_id ) ); 1403 $sub = $is_subscribed ? ' class="is-subscribed"' : ''; 1404 $html = sprintf( '%s<span id="subscribe-%d" %s><a href="%s" class="subscription-toggle" data-bbp-object-id="%d" data-bbp-nonce="%s">%s</a></span>%s', $r['before'], $object_id, $sub, $url, $object_id, wp_create_nonce( 'toggle-subscription_' . $object_id ), $text, $r['after'] ); 1405 1406 // Initial output is wrapped in a span, ajax output is hooked to this 1407 if ( ! empty( $wrap ) ) { 1408 $html = '<span id="subscription-toggle">' . $html . '</span>'; 1409 } 1410 1411 // Filter & return 1412 return apply_filters( 'bbp_get_user_subscribe_link', $html, $r, $user_id, $object_id ); 1461 1413 } 1462 1414
Note: See TracChangeset
for help on using the changeset viewer.