Ticket #7023: 7023.01.patch
File 7023.01.patch, 19.5 KB (added by , 8 years ago) |
---|
-
src/bp-notifications/bp-notifications-functions.php
98 98 * @return bool True on success, false on failure. 99 99 */ 100 100 function bp_notifications_delete_notification( $id ) { 101 if ( ! bp_notifications_check_notification_access( bp_ loggedin_user_id(), $id ) ) {101 if ( ! bp_notifications_check_notification_access( bp_displayed_user_id(), $id ) ) { 102 102 return false; 103 103 } 104 104 … … 117 117 * @return bool True on success, false on failure. 118 118 */ 119 119 function bp_notifications_mark_notification( $id, $is_new = false ) { 120 if ( ! bp_notifications_check_notification_access( bp_ loggedin_user_id(), $id ) ) {120 if ( ! bp_notifications_check_notification_access( bp_displayed_user_id(), $id ) ) { 121 121 return false; 122 122 } 123 123 -
src/bp-notifications/bp-notifications-template.php
42 42 } 43 43 44 44 /** 45 * Output the notifications permalink .45 * Output the notifications permalink for a user. 46 46 * 47 47 * @since 1.9.0 48 * @since 2.6.0 Added $user_id as a parameter. 49 * 50 * @param int $user_id The user ID. 48 51 */ 49 function bp_notifications_permalink( ) {50 echo bp_get_notifications_permalink( );52 function bp_notifications_permalink( $user_id = 0 ) { 53 echo bp_get_notifications_permalink( $user_id ); 51 54 } 52 55 /** 53 56 * Return the notifications permalink. 54 57 * 55 58 * @since 1.9.0 59 * @since 2.6.0 Added $user_id as a parameter. 56 60 * 61 * @param int $user_id The user ID. 57 62 * @return string Notifications permalink. 58 63 */ 59 function bp_get_notifications_permalink() { 60 $retval = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() ); 64 function bp_get_notifications_permalink( $user_id = 0 ) { 65 if ( 0 === $user_id ) { 66 $user_id = bp_loggedin_user_id(); 67 $domain = bp_loggedin_user_domain(); 68 } else { 69 $domain = bp_core_get_user_domain( (int) $user_id ); 70 } 71 72 $retval = trailingslashit( $domain . bp_get_notifications_slug() ); 61 73 62 74 /** 63 75 * Filters the notifications permalink. 64 76 * 65 77 * @since 1.9.0 78 * @since 2.6.0 Added $user_id as a parameter. 66 79 * 67 * @param string $retval Permalink for the notifications. 80 * @param string $retval Permalink for the notifications. 81 * @param int $user_id The user ID. 68 82 */ 69 return apply_filters( 'bp_get_notifications_permalink', $retval );83 return apply_filters( 'bp_get_notifications_permalink', $retval, $user_id ); 70 84 } 71 85 72 86 /** 73 * Output the unread notifications permalink .87 * Output the unread notifications permalink for a user. 74 88 * 75 89 * @since 1.9.0 90 * @since 2.6.0 Added $user_id as a parameter. 91 * 92 * @param int $user_id The user ID. 76 93 */ 77 function bp_notifications_unread_permalink( ) {78 echo bp_get_notifications_unread_permalink( );94 function bp_notifications_unread_permalink( $user_id = 0 ) { 95 echo bp_get_notifications_unread_permalink( $user_id ); 79 96 } 80 97 /** 81 98 * Return the unread notifications permalink. 82 99 * 83 * @since 1.9.0100 * @since 2.6.0 Added $user_id as a parameter. 84 101 * 102 * @param int $user_id The user ID. 85 103 * @return string Unread notifications permalink. 86 104 */ 87 function bp_get_notifications_unread_permalink() { 88 $retval = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() . '/unread' ); 105 function bp_get_notifications_unread_permalink( $user_id = 0 ) { 106 if ( 0 === $user_id ) { 107 $user_id = bp_loggedin_user_id(); 108 $domain = bp_loggedin_user_domain(); 109 } else { 110 $domain = bp_core_get_user_domain( (int) $user_id ); 111 } 112 113 $retval = trailingslashit( $domain . bp_get_notifications_slug() . '/unread' ); 89 114 90 115 /** 91 116 * Filters the unread notifications permalink. 92 117 * 93 118 * @since 1.9.0 119 * @since 2.6.0 Added $user_id as a parameter. 94 120 * 95 * @param string $retval Permalink for the unread notifications. 121 * @param string $retval Permalink for the unread notifications. 122 * @param int $user_id The user ID. 96 123 */ 97 return apply_filters( 'bp_get_notifications_unread_permalink', $retval );124 return apply_filters( 'bp_get_notifications_unread_permalink', $retval, $user_id ); 98 125 } 99 126 100 127 /** 101 * Output the read notifications permalink .128 * Output the read notifications permalink for a user. 102 129 * 103 130 * @since 1.9.0 131 * @since 2.6.0 Added $user_id as a parameter. 132 * 133 * @param int $user_id The user ID. 104 134 */ 105 function bp_notifications_read_permalink( ) {106 echo bp_get_notifications_read_permalink( );135 function bp_notifications_read_permalink( $user_id = 0 ) { 136 echo bp_get_notifications_read_permalink( $user_id ); 107 137 } 108 138 /** 109 139 * Return the read notifications permalink. … … 112 142 * 113 143 * @return string Read notifications permalink. 114 144 */ 115 function bp_get_notifications_read_permalink() { 116 $retval = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() . '/read' ); 145 function bp_get_notifications_read_permalink( $user_id = 0 ) { 146 if ( 0 === $user_id ) { 147 $user_id = bp_loggedin_user_id(); 148 $domain = bp_loggedin_user_domain(); 149 } else { 150 $domain = bp_core_get_user_domain( (int) $user_id ); 151 } 152 153 $retval = trailingslashit( $domain . bp_get_notifications_slug() . '/read' ); 117 154 118 155 /** 119 156 * Filters the read notifications permalink. 120 157 * 121 158 * @since 1.9.0 159 * @since 2.6.0 Added $user_id as a parameter. 122 160 * 123 * @param string $retval Permalink for the read notifications. 161 * @param string $retval Permalink for the read notifications. 162 * @param int $user_id The user ID. 124 163 */ 125 return apply_filters( 'bp_get_notifications_unread_permalink', $retval );164 return apply_filters( 'bp_get_notifications_unread_permalink', $retval, $user_id ); 126 165 } 127 166 128 167 /** The Loop ******************************************************************/ … … 498 537 * Output the mark read link for the current notification. 499 538 * 500 539 * @since 1.9.0 540 * @since 2.6.0 Added $user_id as a parameter. 501 541 * 502 * @ uses bp_get_the_notification_mark_read_link()542 * @param int $user_id The user ID. 503 543 */ 504 function bp_the_notification_mark_read_link( ) {505 echo bp_get_the_notification_mark_read_link( );544 function bp_the_notification_mark_read_link( $user_id = 0 ) { 545 echo bp_get_the_notification_mark_read_link( $user_id ); 506 546 } 507 547 /** 508 548 * Return the mark read link for the current notification. 509 549 * 510 550 * @since 1.9.0 551 * @since 2.6.0 Added $user_id as a parameter. 511 552 * 553 * @param int $user_id The user ID. 512 554 * @return string 513 555 */ 514 function bp_get_the_notification_mark_read_link() { 556 function bp_get_the_notification_mark_read_link( $user_id = 0 ) { 557 // Set default user ID to use. 558 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 515 559 516 560 // Start the output buffer. 517 561 ob_start(); ?> 518 562 519 <a href="<?php bp_the_notification_mark_read_url( ); ?>" class="mark-read primary"><?php _e( 'Read', 'buddypress' ); ?></a>563 <a href="<?php bp_the_notification_mark_read_url( $user_id ); ?>" class="mark-read primary"><?php _e( 'Read', 'buddypress' ); ?></a> 520 564 521 565 <?php $retval = ob_get_clean(); 522 566 … … 524 568 * Filters the mark read link for the current notification. 525 569 * 526 570 * @since 1.9.0 571 * @since 2.6.0 Added $user_id as a parameter. 527 572 * 528 * @param string $retval HTML for the mark read link for the current notification. 573 * @param string $retval HTML for the mark read link for the current notification. 574 * @param int $user_id The user ID. 529 575 */ 530 return apply_filters( 'bp_get_the_notification_mark_read_link', $retval );576 return apply_filters( 'bp_get_the_notification_mark_read_link', $retval, $user_id ); 531 577 } 532 578 533 579 /** … … 536 582 * Since this function directly outputs a URL, it is escaped. 537 583 * 538 584 * @since 2.1.0 585 * @since 2.6.0 Added $user_id as a parameter. 539 586 * 540 * @ uses bp_get_the_notification_mark_read_url()587 * @param int $user_id The user ID. 541 588 */ 542 function bp_the_notification_mark_read_url( ) {543 echo esc_url( bp_get_the_notification_mark_read_url( ) );589 function bp_the_notification_mark_read_url( $user_id = 0 ) { 590 echo esc_url( bp_get_the_notification_mark_read_url( $user_id ) ); 544 591 } 545 592 /** 546 593 * Return the URL used for marking a single notification as read. 547 594 * 548 595 * @since 2.1.0 596 * @since 2.6.0 Added $user_id as a parameter. 549 597 * 598 * @param int $user_id The user ID. 550 599 * @return string 551 600 */ 552 function bp_get_the_notification_mark_read_url( ) {601 function bp_get_the_notification_mark_read_url( $user_id = 0 ) { 553 602 554 603 // Get the notification ID. 555 604 $id = bp_get_the_notification_id(); … … 560 609 'notification_id' => $id 561 610 ); 562 611 612 // Set default user ID to use. 613 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 614 563 615 // Add the args to the URL. 564 $url = add_query_arg( $args, bp_get_notifications_unread_permalink( ) );616 $url = add_query_arg( $args, bp_get_notifications_unread_permalink( $user_id ) ); 565 617 566 618 // Add the nonce. 567 619 $url = wp_nonce_url( $url, 'bp_notification_mark_read_' . $id ); … … 570 622 * Filters the URL used for marking a single notification as read. 571 623 * 572 624 * @since 2.1.0 573 * 574 * @param string $url URL to use for marking the single notification as read. 625 * @since 2.6.0 Added $user_id as a parameter. 626 \ * 627 * @param string $url URL to use for marking the single notification as read. 628 * @param int $user_id The user ID. 575 629 */ 576 return apply_filters( 'bp_get_the_notification_mark_read_url', $url );630 return apply_filters( 'bp_get_the_notification_mark_read_url', $url, $user_id ); 577 631 } 578 632 579 633 /** 580 634 * Output the mark unread link for the current notification. 581 635 * 582 636 * @since 1.9.0 637 * @since 2.6.0 Added $user_id as a parameter. 583 638 * 584 * @ uses bp_get_the_notification_mark_unread_link()639 * @param int $user_id The user ID. 585 640 */ 586 function bp_the_notification_mark_unread_link( ) {641 function bp_the_notification_mark_unread_link( $user_id = 0 ) { 587 642 echo bp_get_the_notification_mark_unread_link(); 588 643 } 589 644 /** 590 645 * Return the mark unread link for the current notification. 591 646 * 592 647 * @since 1.9.0 648 * @since 2.6.0 Added $user_id as a parameter. 593 649 * 650 * @param int $user_id The user ID. 594 651 * @return string 595 652 */ 596 function bp_get_the_notification_mark_unread_link() { 653 function bp_get_the_notification_mark_unread_link( $user_id = 0 ) { 654 // Set default user ID to use. 655 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 597 656 598 657 // Start the output buffer. 599 658 ob_start(); ?> 600 659 601 <a href="<?php bp_the_notification_mark_unread_url( ); ?>" class="mark-unread primary"><?php _ex( 'Unread', 'Notification screen action', 'buddypress' ); ?></a>660 <a href="<?php bp_the_notification_mark_unread_url( $user_id ); ?>" class="mark-unread primary"><?php _ex( 'Unread', 'Notification screen action', 'buddypress' ); ?></a> 602 661 603 662 <?php $retval = ob_get_clean(); 604 663 … … 606 665 * Filters the link used for marking a single notification as unread. 607 666 * 608 667 * @since 1.9.0 668 * @since 2.6.0 Added $user_id as a parameter. 609 669 * 610 * @param string $retval HTML for the mark unread link for the current notification. 670 * @param string $retval HTML for the mark unread link for the current notification. 671 * @param int $user_id The user ID. 611 672 */ 612 return apply_filters( 'bp_get_the_notification_mark_unread_link', $retval );673 return apply_filters( 'bp_get_the_notification_mark_unread_link', $retval, $user_id ); 613 674 } 614 675 615 676 /** … … 618 679 * Since this function directly outputs a URL, it is escaped. 619 680 * 620 681 * @since 2.1.0 682 * @since 2.6.0 Added $user_id as a parameter. 621 683 * 622 * @ uses bp_get_the_notification_mark_unread_url()684 * @param int $user_id The user ID. 623 685 */ 624 function bp_the_notification_mark_unread_url( ) {625 echo esc_url( bp_get_the_notification_mark_unread_url( ) );686 function bp_the_notification_mark_unread_url( $user_id = 0 ) { 687 echo esc_url( bp_get_the_notification_mark_unread_url( $user_id ) ); 626 688 } 627 689 /** 628 690 * Return the URL used for marking a single notification as unread. 629 691 * 630 692 * @since 2.1.0 693 * @since 2.6.0 Added $user_id as a parameter. 631 694 * 695 * @param int $user_id The user ID. 632 696 * @return string 633 697 */ 634 function bp_get_the_notification_mark_unread_url( ) {698 function bp_get_the_notification_mark_unread_url( $user_id = 0 ) { 635 699 636 700 // Get the notification ID. 637 701 $id = bp_get_the_notification_id(); … … 642 706 'notification_id' => $id 643 707 ); 644 708 709 // Set default user ID to use. 710 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 711 645 712 // Add the args to the URL. 646 $url = add_query_arg( $args, bp_get_notifications_read_permalink( ) );713 $url = add_query_arg( $args, bp_get_notifications_read_permalink( $user_id ) ); 647 714 648 715 // Add the nonce. 649 716 $url = wp_nonce_url( $url, 'bp_notification_mark_unread_' . $id ); … … 652 719 * Filters the URL used for marking a single notification as unread. 653 720 * 654 721 * @since 2.1.0 722 * @since 2.6.0 Added $user_id as a parameter. 655 723 * 656 * @param string $url URL to use for marking the single notification as unread. 724 * @param string $url URL to use for marking the single notification as unread. 725 * @param int $user_id The user ID. 657 726 */ 658 return apply_filters( 'bp_get_the_notification_mark_unread_url', $url );727 return apply_filters( 'bp_get_the_notification_mark_unread_url', $url, $user_id ); 659 728 } 660 729 661 730 /** 662 731 * Output the mark link for the current notification. 663 732 * 664 733 * @since 1.9.0 734 * @since 2.6.0 Added $user_id as a parameter. 665 735 * 666 * @ uses bp_get_the_notification_mark_unread_link()736 * @param int $user_id The user ID. 667 737 */ 668 function bp_the_notification_mark_link( ) {669 echo bp_get_the_notification_mark_link( );738 function bp_the_notification_mark_link( $user_id = 0 ) { 739 echo bp_get_the_notification_mark_link( $user_id ); 670 740 } 671 741 /** 672 742 * Return the mark link for the current notification. 673 743 * 674 744 * @since 1.9.0 745 * @since 2.6.0 Added $user_id as a parameter. 675 746 * 747 * @param int $user_id The user ID. 676 748 * @return string 677 749 */ 678 function bp_get_the_notification_mark_link() { 750 function bp_get_the_notification_mark_link( $user_id = 0 ) { 751 // Set default user ID to use. 752 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 679 753 680 754 if ( bp_is_current_action( 'read' ) ) { 681 $retval = bp_get_the_notification_mark_unread_link( );755 $retval = bp_get_the_notification_mark_unread_link( $user_id ); 682 756 } else { 683 $retval = bp_get_the_notification_mark_read_link( );757 $retval = bp_get_the_notification_mark_read_link( $user_id ); 684 758 } 685 759 686 760 /** 687 761 * Filters the mark link for the current notification. 688 762 * 689 763 * @since 1.9.0 764 * @since 2.6.0 Added $user_id as a parameter. 690 765 * 691 * @param string $retval The mark link for the current notification. 766 * @param string $retval The mark link for the current notification. 767 * @param int $user_id The user ID. 692 768 */ 693 return apply_filters( 'bp_get_the_notification_mark_link', $retval );769 return apply_filters( 'bp_get_the_notification_mark_link', $retval, $user_id ); 694 770 } 695 771 696 772 /** 697 773 * Output the delete link for the current notification. 698 774 * 699 775 * @since 1.9.0 776 * @since 2.6.0 Added $user_id as a parameter. 700 777 * 701 * @ uses bp_get_the_notification_delete_link()778 * @param int $user_id The user ID. 702 779 */ 703 function bp_the_notification_delete_link( ) {704 echo bp_get_the_notification_delete_link( );780 function bp_the_notification_delete_link( $user_id = 0 ) { 781 echo bp_get_the_notification_delete_link( $user_id ); 705 782 } 706 783 /** 707 784 * Return the delete link for the current notification. 708 785 * 709 786 * @since 1.9.0 787 * @since 2.6.0 Added $user_id as a parameter. 710 788 * 789 * @param int $user_id The user ID. 711 790 * @return string 712 791 */ 713 function bp_get_the_notification_delete_link() { 792 function bp_get_the_notification_delete_link( $user_id = 0 ) { 793 // Set default user ID to use. 794 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 714 795 715 796 // Start the output buffer. 716 797 ob_start(); ?> … … 723 804 * Filters the delete link for the current notification. 724 805 * 725 806 * @since 1.9.0 807 * @since 2.6.0 Added $user_id as a parameter. 726 808 * 727 * @param string $retval HTML for the delete link for the current notification. 809 * @param string $retval HTML for the delete link for the current notification. 810 * @param int $user_id The user ID. 728 811 */ 729 return apply_filters( 'bp_get_the_notification_delete_link', $retval );812 return apply_filters( 'bp_get_the_notification_delete_link', $retval, $user_id ); 730 813 } 731 814 732 815 /** … … 735 818 * Since this function directly outputs a URL, it is escaped. 736 819 * 737 820 * @since 2.1.0 821 * @since 2.6.0 Added $user_id as a parameter. 738 822 * 739 * @uses esc_url() 740 * @uses bp_get_the_notification_delete_url() 823 * @param int $user_id The user ID. 741 824 */ 742 function bp_the_notification_delete_url( ) {743 echo esc_url( bp_get_the_notification_delete_url( ) );825 function bp_the_notification_delete_url( $user_id = 0 ) { 826 echo esc_url( bp_get_the_notification_delete_url( $user_id ) ); 744 827 } 745 828 /** 746 829 * Return the URL used for deleting a single notification. 747 830 * 748 831 * @since 2.1.0 832 * @since 2.6.0 Added $user_id as a parameter. 749 833 * 834 * @param int $user_id The user ID. 750 835 * @return string 751 836 */ 752 function bp_get_the_notification_delete_url() { 837 function bp_get_the_notification_delete_url( $user_id = 0 ) { 838 // Set default user ID to use. 839 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 753 840 754 841 // URL to add nonce to. 755 842 if ( bp_is_current_action( 'unread' ) ) { 756 $link = bp_get_notifications_unread_permalink( );843 $link = bp_get_notifications_unread_permalink( $user_id ); 757 844 } elseif ( bp_is_current_action( 'read' ) ) { 758 $link = bp_get_notifications_read_permalink( );845 $link = bp_get_notifications_read_permalink( $user_id ); 759 846 } 760 847 761 848 // Get the ID. … … 777 864 * Filters the URL used for deleting a single notification. 778 865 * 779 866 * @since 2.1.0 867 * @since 2.6.0 Added $user_id as a parameter. 780 868 * 781 * @param string $url URL used for deleting a single notification. 869 * @param string $url URL used for deleting a single notification. 870 * @param int $user_id The user ID. 782 871 */ 783 return apply_filters( 'bp_get_the_notification_delete_url', $url );872 return apply_filters( 'bp_get_the_notification_delete_url', $url, $user_id ); 784 873 } 785 874 786 875 /** 787 876 * Output the action links for the current notification. 788 877 * 789 878 * @since 1.9.0 879 * @since 2.6.0 Added $user_id as a parameter to $args. 790 880 * 791 881 * @param array|string $args Array of arguments. 792 882 */ … … 797 887 * Return the action links for the current notification. 798 888 * 799 889 * @since 1.9.0 890 * @since 2.6.0 Added $user_id as a parameter to $args. 800 891 * 801 892 * @param array|string $args { 802 * @type string $before HTML before the links. 803 * @type string $after HTML after the links. 804 * @type string $sep HTML between the links. 805 * @type array $links Array of links to implode by 'sep'. 893 * @type string $before HTML before the links. 894 * @type string $after HTML after the links. 895 * @type string $sep HTML between the links. 896 * @type array $links Array of links to implode by 'sep'. 897 * @type int $user_id User ID to fetch action links for. Defaults to displayed user ID. 806 898 * } 807 899 * @return string HTML links for actions to take on single notifications. 808 900 */ 809 901 function bp_get_the_notification_action_links( $args = '' ) { 902 // Set default user ID to use. 903 $user_id = isset( $args['user_id'] ) ? $args['user_id'] : bp_displayed_user_id(); 810 904 811 905 // Parse. 812 906 $r = wp_parse_args( $args, array( … … 814 908 'after' => '', 815 909 'sep' => ' | ', 816 910 'links' => array( 817 bp_get_the_notification_mark_link( ),818 bp_get_the_notification_delete_link( )911 bp_get_the_notification_mark_link( $user_id ), 912 bp_get_the_notification_delete_link( $user_id ) 819 913 ) 820 914 ) ); 821 915