Ticket #2299: forum-subscriptions.patch
File forum-subscriptions.patch, 24.6 KB (added by , 10 years ago) |
---|
-
includes/users/template-tags.php
866 866 'unsubscribe' => __( 'Unsubscribe', 'bbpress' ), 867 867 'user_id' => 0, 868 868 'topic_id' => 0, 869 'forum_id' => 0, 869 870 'before' => ' | ', 870 871 'after' => '' 871 872 ), 'get_user_subscribe_link' ); … … 873 874 // Validate user and topic ID's 874 875 $user_id = bbp_get_user_id( $r['user_id'], true, true ); 875 876 $topic_id = bbp_get_topic_id( $r['topic_id'] ); 876 if ( empty( $user_id ) || empty( $topic_id ) ) { 877 $forum_id = bbp_get_forum_id( $r['forum_id'] ); 878 879 if ( empty( $user_id ) || ( empty( $topic_id ) && empty( $forum_id ) ) ) { 877 880 return false; 878 881 } 879 882 … … 882 885 return false; 883 886 } 884 887 888 $id = bbp_is_single_forum() ? $forum_id : $topic_id; 889 $type = bbp_is_single_forum() ? 'forum' : 'topic'; 890 885 891 // Decide which link to show 886 $is_subscribed = bbp_is_user_subscribed( $user_id, $topic_id );892 $is_subscribed = bbp_is_user_subscribed( $user_id, $topic_id, $forum_id ); 887 893 if ( !empty( $is_subscribed ) ) { 888 894 $text = $r['unsubscribe']; 889 $query_args = array( 'action' => 'bbp_unsubscribe', 'topic_id' => $topic_id );895 $query_args = array( 'action' => 'bbp_unsubscribe', $type . '_id' => $id ); 890 896 } else { 891 897 $text = $r['subscribe']; 892 $query_args = array( 'action' => 'bbp_subscribe', 'topic_id' => $topic_id );898 $query_args = array( 'action' => 'bbp_subscribe', $type . '_id' => $id ); 893 899 } 894 900 895 901 // Create the link based where the user is and if the user is 896 902 // subscribed already 897 903 if ( bbp_is_subscriptions() ) { 898 904 $permalink = bbp_get_subscriptions_permalink( $user_id ); 905 } elseif ( bbp_is_single_forum() ) { 906 $permalink = bbp_get_forum_permalink( $forum_id ); 899 907 } elseif ( bbp_is_single_topic() || bbp_is_single_reply() ) { 900 908 $permalink = bbp_get_topic_permalink( $topic_id ); 901 909 } else { 902 910 $permalink = get_permalink(); 903 911 } 904 912 905 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $ topic_id ) );913 $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $id ) ); 906 914 $sub = $is_subscribed ? ' class="is-subscribed"' : ''; 907 $html = sprintf( '%s<span id="subscribe-%d" %s><a href="%s" class="subscription-toggle" data- topic="%d">%s</a></span>%s', $r['before'], $topic_id, $sub, $url, $topic_id, $text, $r['after'] );915 $html = sprintf( '%s<span id="subscribe-%d" %s><a href="%s" class="subscription-toggle" data-%s="%d">%s</a></span>%s', $r['before'], $topic_id, $sub, $url, $type, $id, $text, $r['after'] ); 908 916 909 917 // Initial output is wrapped in a span, ajax output is hooked to this 910 918 if ( !empty( $wrap ) ) { … … 912 920 } 913 921 914 922 // Return the link 915 return apply_filters( 'bbp_get_user_subscribe_link', $html, $r, $user_id, $topic_id );923 return apply_filters( 'bbp_get_user_subscribe_link', $html, $r, $user_id, $topic_id, $forum_id ); 916 924 } 917 925 918 926 -
includes/users/functions.php
316 316 $favorites = bbp_get_user_favorites_topic_ids( $user_id ); 317 317 318 318 if ( !empty( $favorites ) ) { 319 319 320 320 // Checking a specific topic id 321 321 if ( !empty( $topic_id ) ) { 322 322 $topic = bbp_get_topic( $topic_id ); … … 516 516 /** Subscriptions *************************************************************/ 517 517 518 518 /** 519 * Get the users who have subscribed to the forum 520 * 521 * @param int $forum_id Optional. Topic id 522 * @uses wpdb::get_col() To execute our query and get the column back 523 * @uses apply_filters() Calls 'bbp_get_forum_subscribers' with the subscribers 524 * @return array|bool Results if the forum has any subscribers, otherwise false 525 */ 526 function bbp_get_forum_subscribers( $forum_id = 0 ) { 527 if ( empty( $forum_id ) ) return; 528 529 global $wpdb; 530 531 $key = $wpdb->prefix . '_bbp_subscriptions'; 532 $users = wp_cache_get( 'bbp_get_forum_subscribers_' . $forum_id, 'bbpress_users' ); 533 if ( empty( $users ) ) { 534 $users = $wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '{$key}' and FIND_IN_SET('{$forum_id}', meta_value) > 0" ); 535 wp_cache_set( 'bbp_get_forum_subscribers_' . $forum_id, $users, 'bbpress_users' ); 536 } 537 538 if ( !empty( $users ) ) { 539 $users = apply_filters( 'bbp_get_forum_subscribers', $users ); 540 return $users; 541 } 542 543 return false; 544 } 545 546 /** 519 547 * Get the users who have subscribed to the topic 520 548 * 521 549 * @since bbPress (r2668) … … 551 579 * @since bbPress (r2668) 552 580 * 553 581 * @param int $user_id Optional. User id 554 * @uses bbp_get_user_subscribed_ topic_ids() To get the user's subscriptions582 * @uses bbp_get_user_subscribed_ids() To get the user's subscriptions 555 583 * @uses bbp_has_topics() To get the topics 556 584 * @uses apply_filters() Calls 'bbp_get_user_subscriptions' with the topic query 557 585 * and user id … … 565 593 return false; 566 594 567 595 // If user has subscriptions, load them 568 $subscriptions = bbp_get_user_subscribed_ topic_ids( $user_id );596 $subscriptions = bbp_get_user_subscribed_ids( $user_id ); 569 597 if ( !empty( $subscriptions ) ) { 570 598 $query = bbp_has_topics( array( 'post__in' => $subscriptions ) ); 571 599 return apply_filters( 'bbp_get_user_subscriptions', $query, $user_id ); … … 574 602 return false; 575 603 } 576 604 605 577 606 /** 578 * Get a user's subscribed topic s'ids607 * Get a user's subscribed topic/forum ids 579 608 * 580 609 * @since bbPress (r2668) 581 610 * 582 611 * @param int $user_id Optional. User id 583 612 * @uses bbp_get_user_id() To get the user id 584 613 * @uses get_user_option() To get the user's subscriptions 585 * @uses apply_filters() Calls 'bbp_get_user_subscribed_ topic_ids' with614 * @uses apply_filters() Calls 'bbp_get_user_subscribed_ids' with 586 615 * the subscriptions and user id 587 616 * @return array|bool Results if user has subscriptions, otherwise false 588 617 */ 589 function bbp_get_user_subscribed_ topic_ids( $user_id = 0 ) {618 function bbp_get_user_subscribed_ids( $user_id = 0 ) { 590 619 $user_id = bbp_get_user_id( $user_id ); 591 620 if ( empty( $user_id ) ) 592 621 return false; … … 595 624 $subscriptions = (array) explode( ',', $subscriptions ); 596 625 $subscriptions = array_filter( $subscriptions ); 597 626 598 return apply_filters( 'bbp_get_user_subscribed_ topic_ids', $subscriptions, $user_id );627 return apply_filters( 'bbp_get_user_subscribed_ids', $subscriptions, $user_id ); 599 628 } 600 629 601 630 /** … … 605 634 * 606 635 * @param int $user_id Optional. User id 607 636 * @param int $topic_id Optional. Topic id 637 * @param int $forum_id Optional. Topic id 608 638 * @uses bbp_get_user_id() To get the user id 609 * @uses bbp_get_user_subscribed_ topic_ids() To get the user's subscriptions639 * @uses bbp_get_user_subscribed_ids() To get the user's subscriptions 610 640 * @uses bbp_get_topic() To get the topic 611 641 * @uses bbp_get_topic_id() To get the topic id 612 642 * @uses apply_filters() Calls 'bbp_is_user_subscribed' with the bool, user id, 613 643 * topic id and subsriptions 614 * @return bool True if the topic is in user's subscriptions, otherwise false644 * @return bool True if the topic or forum is in user's subscriptions, otherwise false 615 645 */ 616 function bbp_is_user_subscribed( $user_id = 0, $topic_id = 0 ) {646 function bbp_is_user_subscribed( $user_id = 0, $topic_id = 0, $forum_id = 0 ) { 617 647 618 648 // Validate user 619 649 $user_id = bbp_get_user_id( $user_id, true, true ); … … 621 651 return false; 622 652 623 653 $retval = false; 624 $subscriptions = bbp_get_user_subscribed_topic_ids( $user_id );654 $subscriptions = (array) bbp_get_user_subscribed_ids( $user_id ); 625 655 626 656 if ( !empty( $subscriptions ) ) { 627 657 628 // Checking a specific topic id 629 if ( !empty( $topic_id ) ) { 630 $topic = bbp_get_topic( $topic_id ); 631 $topic_id = !empty( $topic ) ? $topic->ID : 0; 658 if( ! empty( $topic_id ) ) { 632 659 633 // Using the global topic id 634 } elseif ( bbp_get_topic_id() ) { 635 $topic_id = bbp_get_topic_id(); 660 // Checking a specific topic id 661 if ( !empty( $topic_id ) ) { 662 $topic = bbp_get_topic( $topic_id ); 663 $topic_id = !empty( $topic ) ? $topic->ID : 0; 636 664 637 // Use the current post id 638 } elseif ( !bbp_get_topic_id() ) { 639 $topic_id = get_the_ID(); 640 } 665 // Using the global topic id 666 } elseif ( bbp_get_topic_id() ) { 667 $topic_id = bbp_get_topic_id(); 641 668 642 // Is topic_id in the user's favorites 643 if ( !empty( $topic_id ) ) { 644 $retval = in_array( $topic_id, $subscriptions ); 669 // Use the current post id 670 } elseif ( !bbp_get_topic_id() ) { 671 $topic_id = get_the_ID(); 672 } 673 674 // Is topic_id in the user's favorites 675 if ( !empty( $topic_id ) ) { 676 $retval = in_array( $topic_id, $subscriptions ); 677 } 678 679 } else { 680 681 // Checking a specific forum id 682 if ( !empty( $forum_id ) ) { 683 $forum = bbp_get_forum( $forum_id ); 684 $forum_id = !empty( $forum ) ? $forum->ID : 0; 685 686 // Using the global forum id 687 } elseif ( bbp_get_forum_id() ) { 688 $forum_id = bbp_get_forum_id(); 689 690 // Use the current post id 691 } elseif ( !bbp_get_forum_id() ) { 692 $forum_id = get_the_ID(); 693 } 694 695 // Is forum_id in the user's favorites 696 if ( !empty( $forum_id ) ) { 697 $retval = in_array( $forum_id, $subscriptions ); 698 } 699 645 700 } 646 701 } 647 702 648 return (bool) apply_filters( 'bbp_is_user_subscribed', (bool) $retval, $user_id, $topic_id, $ subscriptions );703 return (bool) apply_filters( 'bbp_is_user_subscribed', (bool) $retval, $user_id, $topic_id, $forum_id, $subscriptions ); 649 704 } 650 705 651 706 /** … … 655 710 * 656 711 * @param int $user_id Optional. User id 657 712 * @param int $topic_id Optional. Topic id 658 * @uses bbp_get_user_subscribed_ topic_ids() To get the user's subscriptions713 * @uses bbp_get_user_subscribed_ids() To get the user's subscriptions 659 714 * @uses bbp_get_topic() To get the topic 660 715 * @uses update_user_option() To update the user's subscriptions 661 716 * @uses do_action() Calls 'bbp_add_user_subscription' with the user & topic id 662 717 * @return bool Always true 663 718 */ 664 function bbp_add_user_subscription( $user_id = 0, $topic_id = 0 ) {665 if ( empty( $user_id ) || empty( $topic_id) )719 function bbp_add_user_subscription( $user_id = 0, $topic_id = 0, $forum_id = 0 ) { 720 if ( empty( $user_id ) || ( empty( $topic_id ) && empty( $forum_id ) ) ) 666 721 return false; 667 722 668 $subscriptions = (array) bbp_get_user_subscribed_topic_ids( $user_id ); 723 $retval = false; 724 $subscriptions = (array) bbp_get_user_subscribed_ids( $user_id ); 669 725 726 $forum = bbp_get_forum( $forum_id ); 670 727 $topic = bbp_get_topic( $topic_id ); 671 if ( empty( $topic ) ) 728 729 if ( empty( $topic ) && empty( $forum ) ) 672 730 return false; 673 731 674 if ( !in_array( $topic_id, $subscriptions ) ) { 675 $subscriptions[] = $topic_id; 732 $id = ! empty( $topic ) ? $topic_id : $forum_id; 733 734 if ( !in_array( $id, $subscriptions ) ) { 735 $subscriptions[] = $id; 676 736 $subscriptions = array_filter( $subscriptions ); 677 737 $subscriptions = (string) implode( ',', $subscriptions ); 678 738 update_user_option( $user_id, '_bbp_subscriptions', $subscriptions ); 679 739 680 wp_cache_delete( 'bbp_get_topic_subscribers_' . $ topic_id, 'bbpress' );740 wp_cache_delete( 'bbp_get_topic_subscribers_' . $id, 'bbpress' ); 681 741 } 682 742 683 do_action( 'bbp_add_user_subscription', $user_id, $ topic_id );743 do_action( 'bbp_add_user_subscription', $user_id, $id ); 684 744 685 745 return true; 686 746 } … … 692 752 * 693 753 * @param int $user_id Optional. User id 694 754 * @param int $topic_id Optional. Topic id 695 * @uses bbp_get_user_subscribed_ topic_ids() To get the user's subscriptions755 * @uses bbp_get_user_subscribed_ids() To get the user's subscriptions 696 756 * @uses update_user_option() To update the user's subscriptions 697 757 * @uses delete_user_option() To delete the user's subscriptions meta 698 758 * @uses do_action() Calls 'bbp_remove_user_subscription' with the user id and … … 700 760 * @return bool True if the topic was removed from user's subscriptions, 701 761 * otherwise false 702 762 */ 703 function bbp_remove_user_subscription( $user_id , $topic_id) {704 if ( empty( $user_id ) || empty( $topic_id) )763 function bbp_remove_user_subscription( $user_id = 0, $topic_id = 0, $forum_id = 0 ) { 764 if ( empty( $user_id ) || ( empty( $topic_id ) && empty( $forum_id ) ) ) 705 765 return false; 706 766 707 $subscriptions = (array) bbp_get_user_subscribed_ topic_ids( $user_id );767 $subscriptions = (array) bbp_get_user_subscribed_ids( $user_id ); 708 768 709 if ( empty( $subscriptions ) ) 769 $forum = bbp_get_forum( $forum_id ); 770 $topic = bbp_get_topic( $topic_id ); 771 772 if ( empty( $topic ) && empty( $forum ) ) 710 773 return false; 711 774 712 $pos = array_search( $topic_id, $subscriptions ); 775 $id = ! empty( $topic ) ? $topic_id : $forum_id; 776 $type = ! empty( $forum ) ? 'topic' : 'forum'; 777 $pos = array_search( $id, $subscriptions ); 778 713 779 if ( is_numeric( $pos ) ) { 780 714 781 array_splice( $subscriptions, $pos, 1 ); 715 782 $subscriptions = array_filter( $subscriptions ); 716 717 783 if ( !empty( $subscriptions ) ) { 718 784 $subscriptions = implode( ',', $subscriptions ); 719 785 update_user_option( $user_id, '_bbp_subscriptions', $subscriptions ); … … 721 787 delete_user_option( $user_id, '_bbp_subscriptions' ); 722 788 } 723 789 724 wp_cache_delete( 'bbp_get_ topic_subscribers_' . $topic_id, 'bbpress' );790 wp_cache_delete( 'bbp_get_' . $type . '_subscribers_' . $id, 'bbpress' ); 725 791 } 726 792 727 do_action( 'bbp_remove_user_subscription', $user_id, $topic_id );793 do_action( 'bbp_remove_user_subscription', $user_id, $topic_id, $forum_id ); 728 794 729 795 return true; 730 796 } … … 755 821 return false; 756 822 757 823 // Bail if no topic ID is passed 758 if ( empty( $_GET['topic_id'] ) )824 if ( empty( $_GET['topic_id'] ) && empty( $_GET['forum_id'] ) ) 759 825 return; 760 826 761 827 // Setup possible get actions … … 770 836 771 837 // Get required data 772 838 $user_id = bbp_get_user_id( 0, true, true ); 773 $topic_id = intval( $_GET['topic_id'] ); 839 $topic_id = ! empty( $_GET['topic_id'] ) ? intval( $_GET['topic_id'] ) : 0 ; 840 $forum_id = ! empty( $_GET['forum_id'] ) ? intval( $_GET['forum_id'] ) : 0 ; 774 841 775 842 // Check for empty topic 776 if ( empty( $topic_id ) ) {843 if ( empty( $topic_id ) && empty( $forum_id ) ) { 777 844 bbp_add_error( 'bbp_subscription_topic_id', __( '<strong>ERROR</strong>: No topic was found! Which topic are you subscribing/unsubscribing to?', 'bbpress' ) ); 778 845 779 // Check nonce 780 } elseif ( ! bbp_verify_nonce_request( 'toggle-subscription_' . $topic_id ) ) { 846 // Check forum nonce 847 } elseif ( ! empty( $forum_id ) && ! bbp_verify_nonce_request( 'toggle-subscription_' . $forum_id ) ) { 848 bbp_add_error( 'bbp_subscription_forum_id', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress' ) ); 849 850 // Check topic nonce 851 } elseif ( ! empty( $topic_id ) && ! bbp_verify_nonce_request( 'toggle-subscription_' . $topic_id ) ) { 781 852 bbp_add_error( 'bbp_subscription_topic_id', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress' ) ); 782 853 783 854 // Check current user's ability to edit the user … … 791 862 792 863 /** No errors *************************************************************/ 793 864 794 $is_subscription = bbp_is_user_subscribed( $user_id, $topic_id );865 $is_subscription = bbp_is_user_subscribed( $user_id, $topic_id, $forum_id ); 795 866 $success = false; 796 867 797 868 if ( true == $is_subscription && 'bbp_unsubscribe' == $action ) 798 $success = bbp_remove_user_subscription( $user_id, $topic_id );869 $success = bbp_remove_user_subscription( $user_id, $topic_id, $forum_id ); 799 870 elseif ( false == $is_subscription && 'bbp_subscribe' == $action ) 800 $success = bbp_add_user_subscription( $user_id, $topic_id );871 $success = bbp_add_user_subscription( $user_id, $topic_id, $forum_id ); 801 872 802 873 // Do additional subscriptions actions 803 do_action( 'bbp_subscriptions_handler', $success, $user_id, $topic_id, $ action );874 do_action( 'bbp_subscriptions_handler', $success, $user_id, $topic_id, $forum_id, $action ); 804 875 805 876 // Success! 806 877 if ( true == $success ) { … … 810 881 $redirect = bbp_get_subscriptions_permalink( $user_id ); 811 882 } elseif ( bbp_is_single_user() ) { 812 883 $redirect = bbp_get_user_profile_url(); 884 } elseif ( is_singular( bbp_get_forum_post_type() ) ) { 885 $redirect = bbp_get_forum_permalink( $topic_id ); 813 886 } elseif ( is_singular( bbp_get_topic_post_type() ) ) { 814 887 $redirect = bbp_get_topic_permalink( $topic_id ); 815 888 } elseif ( is_single() || is_page() ) { … … 972 1045 * @return array|bool Results if the user has created topics, otherwise false 973 1046 */ 974 1047 function bbp_get_user_topics_started( $user_id = 0 ) { 975 1048 976 1049 // Validate user 977 1050 $user_id = bbp_get_user_id( $user_id ); 978 1051 if ( empty( $user_id ) ) … … 1004 1077 * @return array|bool Results if the user has created topics, otherwise false 1005 1078 */ 1006 1079 function bbp_get_user_replies_created( $user_id = 0 ) { 1007 1080 1008 1081 // Validate user 1009 1082 $user_id = bbp_get_user_id( $user_id ); 1010 1083 if ( empty( $user_id ) ) … … 1047 1120 * which a user can edit another user (or themselves.) If these conditions are 1048 1121 * met. We assume a user cannot perform this task, and look for ways they can 1049 1122 * earn the ability to access this template. 1050 * 1123 * 1051 1124 * @since bbPress (r3605) 1052 1125 * 1053 1126 * @uses bbp_is_topic_edit() -
includes/replies/functions.php
731 731 732 732 // Handle Subscription Checkbox 733 733 if ( bbp_is_subscriptions_active() && !empty( $author_id ) && !empty( $topic_id ) ) { 734 $subscribed = bbp_is_user_subscribed( $author_id, $topic_id );734 $subscribed = bbp_is_user_subscribed( $author_id, $topic_id, $forum_id ); 735 735 $subscheck = ( !empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' == $_POST['bbp_topic_subscription'] ) ) ? true : false; 736 736 737 737 // Subscribed and unsubscribing -
includes/common/functions.php
980 980 /** Subscriptions *************************************************************/ 981 981 982 982 /** 983 * Sends notification emails for new topics 984 * 985 * Gets new post's ID and check if there are subscribed users to that forum, and 986 * if there are, send notifications 987 * 988 * @param int $topic_id ID of the newly made reply 989 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 990 * @uses bbp_get_topic_id() To validate the topic ID 991 * @uses get_the_author_meta() To get the author's display name 992 * @uses do_action() Calls 'bbp_pre_notify_subscribers' with the reply id and 993 * topic id 994 * @uses bbp_get_topic_subscribers() To get the topic subscribers 995 * @uses apply_filters() Calls 'bbp_subscription_mail_message' with the 996 * message, reply id, topic id and user id 997 * @uses get_userdata() To get the user data 998 * @uses wp_mail() To send the mail 999 * @uses do_action() Calls 'bbp_post_notify_subscribers' with the reply id 1000 * and topic id 1001 * @return bool True on success, false on failure 1002 */ 1003 function bbp_notify_forum_subscribers( $topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0 ) { 1004 1005 // Bail if subscriptions are turned off 1006 if ( !bbp_is_subscriptions_active() ) 1007 return false; 1008 1009 /** Validation ************************************************************/ 1010 1011 $topic_id = bbp_get_topic_id( $topic_id ); 1012 $forum_id = bbp_get_forum_id( $forum_id ); 1013 1014 /** User ******************************************************************/ 1015 1016 // Get subscribers and bail if empty 1017 $user_ids = bbp_get_forum_subscribers( $forum_id, true ); 1018 if ( empty( $user_ids ) ) 1019 return false; 1020 1021 // Poster name 1022 $topic_author_name = bbp_get_topic_author_display_name( $topic_id ); 1023 1024 /** Mail ******************************************************************/ 1025 1026 do_action( 'bbp_pre_notify_subscribers', $topic_id, $forum_id, $user_ids ); 1027 1028 // Remove filters from reply content and topic title to prevent content 1029 // from being encoded with HTML entities, wrapped in paragraph tags, etc... 1030 remove_all_filters( 'bbp_get_topic_content' ); 1031 remove_all_filters( 'bbp_get_forum_title' ); 1032 1033 // Strip tags from text 1034 $forum_title = strip_tags( bbp_get_forum_title( $forum_id ) ); 1035 $topic_content = strip_tags( bbp_get_topic_content( $topic_id ) ); 1036 $topic_url = bbp_remove_view_all( bbp_get_topic_permalink( $topic_id ) ); 1037 $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ); 1038 1039 // Loop through users 1040 foreach ( (array) $user_ids as $user_id ) { 1041 1042 // Don't send notifications to the person who made the post 1043 if ( !empty( $topic_author ) && (int) $user_id == (int) $topic_author ) 1044 continue; 1045 1046 // For plugins to filter messages per reply/topic/user 1047 $message = sprintf( __( '%1$s wrote: 1048 1049 %2$s 1050 1051 Post Link: %3$s 1052 1053 ----------- 1054 1055 You are receiving this email because you subscribed to a forum. 1056 1057 Login and visit the topic to unsubscribe from these emails.', 'bbpress' ), 1058 1059 $topic_author_name, 1060 $topic_content, 1061 $topic_url 1062 ); 1063 1064 $message = apply_filters( 'bbp_subscription_mail_message', $message, $topic_id, $forum_id, $user_id ); 1065 if ( empty( $message ) ) 1066 continue; 1067 1068 // For plugins to filter titles per reply/topic/user 1069 $subject = apply_filters( 'bbp_subscription_mail_title', '[' . $blog_name . '] ' . $forum_title, $topic_id, $forum_id, $user_id ); 1070 if ( empty( $subject ) ) 1071 continue; 1072 1073 // Custom headers 1074 $headers = apply_filters( 'bbp_subscription_mail_headers', array() ); 1075 1076 // Get user data of this user 1077 $user = get_userdata( $user_id ); 1078 1079 // Send notification email 1080 wp_mail( $user->user_email, $subject, $message, $headers ); 1081 } 1082 1083 do_action( 'bbp_post_notify_subscribers', $topic_id, $forum_id, $user_ids ); 1084 1085 return true; 1086 } 1087 1088 /** 983 1089 * Sends notification emails for new posts 984 1090 * 985 1091 * Gets new post's ID and check if there are subscribed users to that topic, and … … 1494 1600 1495 1601 // Forum/Topic/Reply Feed 1496 1602 if ( isset( $query_vars['post_type'] ) ) { 1497 1603 1498 1604 // Supported select query vars 1499 1605 $select_query_vars = array( 1500 1606 'p' => false, -
includes/core/actions.php
220 220 add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_favorites' ); 221 221 222 222 // Subscriptions 223 add_action( 'bbp_trash_forum', 'bbp_remove_forum_from_all_subscriptions' ); 223 224 add_action( 'bbp_trash_topic', 'bbp_remove_topic_from_all_subscriptions' ); 225 add_action( 'bbp_delete_forum', 'bbp_remove_forum_from_all_subscriptions' ); 224 226 add_action( 'bbp_delete_topic', 'bbp_remove_topic_from_all_subscriptions' ); 227 add_action( 'bbp_new_topic', 'bbp_notify_forum_subscribers', 11, 4 ); 225 228 add_action( 'bbp_new_reply', 'bbp_notify_subscribers', 11, 5 ); 226 229 227 230 // Sticky -
includes/forums/functions.php
2212 2212 2213 2213 do_action( 'bbp_untrashed_forum', $forum_id ); 2214 2214 } 2215 2216 2217 /** 2218 * Remove a deleted forum from all users' subscriptions 2219 * 2220 * @param int $forum_id Topic ID to remove 2221 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active 2222 * @uses bbp_get_forum_subscribers() To get the topic subscribers 2223 * @uses bbp_remove_user_subscription() To remove the user subscription 2224 */ 2225 function bbp_remove_forum_from_all_subscriptions( $forum_id = 0 ) { 2226 2227 // Subscriptions are not active 2228 if ( !bbp_is_subscriptions_active() ) 2229 return; 2230 2231 $forum_id = bbp_get_forum_id( $forum_id ); 2232 2233 // Bail if no topic 2234 if ( empty( $forum_id ) ) 2235 return; 2236 2237 // Get users 2238 $users = (array) bbp_get_forum_subscribers( $forum_id ); 2239 2240 // Users exist 2241 if ( !empty( $users ) ) { 2242 2243 // Loop through users 2244 foreach ( $users as $user ) { 2245 2246 // Remove each user 2247 bbp_remove_user_subscription( $user, 0, $forum_id ); 2248 } 2249 } 2250 } -
templates/default/bbpress/loop-topics.php
16 16 <li class="bbp-header"> 17 17 18 18 <ul class="forum-titles"> 19 <li class="bbp-topic-title"><?php _e( 'Topic', 'bbpress' ); ?>< /li>19 <li class="bbp-topic-title"><?php _e( 'Topic', 'bbpress' ); ?><?php bbp_user_subscribe_link(); ?></li> 20 20 <li class="bbp-topic-voice-count"><?php _e( 'Voices', 'bbpress' ); ?></li> 21 21 <li class="bbp-topic-reply-count"><?php bbp_show_lead_topic() ? _e( 'Replies', 'bbpress' ) : _e( 'Posts', 'bbpress' ); ?></li> 22 22 <li class="bbp-topic-freshness"><?php _e( 'Freshness', 'bbpress' ); ?></li>