Changeset 10816
- Timestamp:
- 05/27/2016 05:56:01 AM (8 years ago)
- Location:
- trunk/src/bp-notifications
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-notifications/bp-notifications-functions.php
r10806 r10816 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 } … … 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 } -
trunk/src/bp-notifications/bp-notifications-template.php
r10790 r10816 43 43 44 44 /** 45 * Output the notifications permalink. 46 * 47 * @since 1.9.0 48 */ 49 function bp_notifications_permalink() { 50 echo bp_get_notifications_permalink(); 45 * Output the notifications permalink for a user. 46 * 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. 51 */ 52 function bp_notifications_permalink( $user_id = 0 ) { 53 echo bp_get_notifications_permalink( $user_id ); 51 54 } 52 55 /** … … 54 57 * 55 58 * @since 1.9.0 56 * 59 * @since 2.6.0 Added $user_id as a parameter. 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 /** … … 64 76 * 65 77 * @since 1.9.0 66 * 67 * @param string $retval Permalink for the notifications. 68 */ 69 return apply_filters( 'bp_get_notifications_permalink', $retval ); 70 } 71 72 /** 73 * Output the unread notifications permalink. 74 * 75 * @since 1.9.0 76 */ 77 function bp_notifications_unread_permalink() { 78 echo bp_get_notifications_unread_permalink(); 78 * @since 2.6.0 Added $user_id as a parameter. 79 * 80 * @param string $retval Permalink for the notifications. 81 * @param int $user_id The user ID. 82 */ 83 return apply_filters( 'bp_get_notifications_permalink', $retval, $user_id ); 84 } 85 86 /** 87 * Output the unread notifications permalink for a user. 88 * 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. 93 */ 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.0 84 * 100 * @since 2.6.0 Added $user_id as a parameter. 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 /** … … 92 117 * 93 118 * @since 1.9.0 94 * 95 * @param string $retval Permalink for the unread notifications. 96 */ 97 return apply_filters( 'bp_get_notifications_unread_permalink', $retval ); 98 } 99 100 /** 101 * Output the read notifications permalink. 102 * 103 * @since 1.9.0 104 */ 105 function bp_notifications_read_permalink() { 106 echo bp_get_notifications_read_permalink(); 119 * @since 2.6.0 Added $user_id as a parameter. 120 * 121 * @param string $retval Permalink for the unread notifications. 122 * @param int $user_id The user ID. 123 */ 124 return apply_filters( 'bp_get_notifications_unread_permalink', $retval, $user_id ); 125 } 126 127 /** 128 * Output the read notifications permalink for a user. 129 * 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. 134 */ 135 function bp_notifications_read_permalink( $user_id = 0 ) { 136 echo bp_get_notifications_read_permalink( $user_id ); 107 137 } 108 138 /** … … 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 /** … … 120 157 * 121 158 * @since 1.9.0 122 * 123 * @param string $retval Permalink for the read notifications. 124 */ 125 return apply_filters( 'bp_get_notifications_unread_permalink', $retval ); 159 * @since 2.6.0 Added $user_id as a parameter. 160 * 161 * @param string $retval Permalink for the read notifications. 162 * @param int $user_id The user ID. 163 */ 164 return apply_filters( 'bp_get_notifications_unread_permalink', $retval, $user_id ); 126 165 } 127 166 … … 501 540 * 502 541 * @since 1.9.0 503 * 504 * @uses bp_get_the_notification_mark_read_link() 505 */ 506 function bp_the_notification_mark_read_link() { 507 echo bp_get_the_notification_mark_read_link(); 542 * @since 2.6.0 Added $user_id as a parameter. 543 * 544 * @param int $user_id The user ID. 545 */ 546 function bp_the_notification_mark_read_link( $user_id = 0 ) { 547 echo bp_get_the_notification_mark_read_link( $user_id ); 508 548 } 509 549 /** … … 511 551 * 512 552 * @since 1.9.0 513 * 553 * @since 2.6.0 Added $user_id as a parameter. 554 * 555 * @param int $user_id The user ID. 514 556 * @return string 515 557 */ 516 function bp_get_the_notification_mark_read_link() { 558 function bp_get_the_notification_mark_read_link( $user_id = 0 ) { 559 // Set default user ID to use. 560 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 517 561 518 562 // Start the output buffer. 519 563 ob_start(); ?> 520 564 521 <a href="<?php bp_the_notification_mark_read_url( ); ?>" class="mark-read primary"><?php _e( 'Read', 'buddypress' ); ?></a>565 <a href="<?php bp_the_notification_mark_read_url( $user_id ); ?>" class="mark-read primary"><?php _e( 'Read', 'buddypress' ); ?></a> 522 566 523 567 <?php $retval = ob_get_clean(); … … 527 571 * 528 572 * @since 1.9.0 529 * 530 * @param string $retval HTML for the mark read link for the current notification. 531 */ 532 return apply_filters( 'bp_get_the_notification_mark_read_link', $retval ); 573 * @since 2.6.0 Added $user_id as a parameter. 574 * 575 * @param string $retval HTML for the mark read link for the current notification. 576 * @param int $user_id The user ID. 577 */ 578 return apply_filters( 'bp_get_the_notification_mark_read_link', $retval, $user_id ); 533 579 } 534 580 … … 539 585 * 540 586 * @since 2.1.0 541 * 542 * @uses bp_get_the_notification_mark_read_url() 543 */ 544 function bp_the_notification_mark_read_url() { 545 echo esc_url( bp_get_the_notification_mark_read_url() ); 587 * @since 2.6.0 Added $user_id as a parameter. 588 * 589 * @param int $user_id The user ID. 590 */ 591 function bp_the_notification_mark_read_url( $user_id = 0 ) { 592 echo esc_url( bp_get_the_notification_mark_read_url( $user_id ) ); 546 593 } 547 594 /** … … 549 596 * 550 597 * @since 2.1.0 551 * 598 * @since 2.6.0 Added $user_id as a parameter. 599 * 600 * @param int $user_id The user ID. 552 601 * @return string 553 602 */ 554 function bp_get_the_notification_mark_read_url( ) {603 function bp_get_the_notification_mark_read_url( $user_id = 0 ) { 555 604 556 605 // Get the notification ID. … … 563 612 ); 564 613 614 // Set default user ID to use. 615 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 616 565 617 // Add the args to the URL. 566 $url = add_query_arg( $args, bp_get_notifications_unread_permalink( ) );618 $url = add_query_arg( $args, bp_get_notifications_unread_permalink( $user_id ) ); 567 619 568 620 // Add the nonce. … … 573 625 * 574 626 * @since 2.1.0 575 * 576 * @param string $url URL to use for marking the single notification as read. 577 */ 578 return apply_filters( 'bp_get_the_notification_mark_read_url', $url ); 627 * @since 2.6.0 Added $user_id as a parameter. 628 * 629 * @param string $url URL to use for marking the single notification as read. 630 * @param int $user_id The user ID. 631 */ 632 return apply_filters( 'bp_get_the_notification_mark_read_url', $url, $user_id ); 579 633 } 580 634 … … 583 637 * 584 638 * @since 1.9.0 585 * 586 * @uses bp_get_the_notification_mark_unread_link() 587 */ 588 function bp_the_notification_mark_unread_link() { 639 * @since 2.6.0 Added $user_id as a parameter. 640 * 641 * @param int $user_id The user ID. 642 */ 643 function bp_the_notification_mark_unread_link( $user_id = 0 ) { 589 644 echo bp_get_the_notification_mark_unread_link(); 590 645 } … … 593 648 * 594 649 * @since 1.9.0 595 * 650 * @since 2.6.0 Added $user_id as a parameter. 651 * 652 * @param int $user_id The user ID. 596 653 * @return string 597 654 */ 598 function bp_get_the_notification_mark_unread_link() { 655 function bp_get_the_notification_mark_unread_link( $user_id = 0 ) { 656 // Set default user ID to use. 657 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 599 658 600 659 // Start the output buffer. 601 660 ob_start(); ?> 602 661 603 <a href="<?php bp_the_notification_mark_unread_url( ); ?>" class="mark-unread primary"><?php _ex( 'Unread', 'Notification screen action', 'buddypress' ); ?></a>662 <a href="<?php bp_the_notification_mark_unread_url( $user_id ); ?>" class="mark-unread primary"><?php _ex( 'Unread', 'Notification screen action', 'buddypress' ); ?></a> 604 663 605 664 <?php $retval = ob_get_clean(); … … 609 668 * 610 669 * @since 1.9.0 611 * 612 * @param string $retval HTML for the mark unread link for the current notification. 613 */ 614 return apply_filters( 'bp_get_the_notification_mark_unread_link', $retval ); 670 * @since 2.6.0 Added $user_id as a parameter. 671 * 672 * @param string $retval HTML for the mark unread link for the current notification. 673 * @param int $user_id The user ID. 674 */ 675 return apply_filters( 'bp_get_the_notification_mark_unread_link', $retval, $user_id ); 615 676 } 616 677 … … 621 682 * 622 683 * @since 2.1.0 623 * 624 * @uses bp_get_the_notification_mark_unread_url() 625 */ 626 function bp_the_notification_mark_unread_url() { 627 echo esc_url( bp_get_the_notification_mark_unread_url() ); 684 * @since 2.6.0 Added $user_id as a parameter. 685 * 686 * @param int $user_id The user ID. 687 */ 688 function bp_the_notification_mark_unread_url( $user_id = 0 ) { 689 echo esc_url( bp_get_the_notification_mark_unread_url( $user_id ) ); 628 690 } 629 691 /** … … 631 693 * 632 694 * @since 2.1.0 633 * 695 * @since 2.6.0 Added $user_id as a parameter. 696 * 697 * @param int $user_id The user ID. 634 698 * @return string 635 699 */ 636 function bp_get_the_notification_mark_unread_url( ) {700 function bp_get_the_notification_mark_unread_url( $user_id = 0 ) { 637 701 638 702 // Get the notification ID. … … 645 709 ); 646 710 711 // Set default user ID to use. 712 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 713 647 714 // Add the args to the URL. 648 $url = add_query_arg( $args, bp_get_notifications_read_permalink( ) );715 $url = add_query_arg( $args, bp_get_notifications_read_permalink( $user_id ) ); 649 716 650 717 // Add the nonce. … … 655 722 * 656 723 * @since 2.1.0 657 * 658 * @param string $url URL to use for marking the single notification as unread. 659 */ 660 return apply_filters( 'bp_get_the_notification_mark_unread_url', $url ); 724 * @since 2.6.0 Added $user_id as a parameter. 725 * 726 * @param string $url URL to use for marking the single notification as unread. 727 * @param int $user_id The user ID. 728 */ 729 return apply_filters( 'bp_get_the_notification_mark_unread_url', $url, $user_id ); 661 730 } 662 731 … … 665 734 * 666 735 * @since 1.9.0 667 * 668 * @uses bp_get_the_notification_mark_unread_link() 669 */ 670 function bp_the_notification_mark_link() { 671 echo bp_get_the_notification_mark_link(); 736 * @since 2.6.0 Added $user_id as a parameter. 737 * 738 * @param int $user_id The user ID. 739 */ 740 function bp_the_notification_mark_link( $user_id = 0 ) { 741 echo bp_get_the_notification_mark_link( $user_id ); 672 742 } 673 743 /** … … 675 745 * 676 746 * @since 1.9.0 677 * 747 * @since 2.6.0 Added $user_id as a parameter. 748 * 749 * @param int $user_id The user ID. 678 750 * @return string 679 751 */ 680 function bp_get_the_notification_mark_link() { 752 function bp_get_the_notification_mark_link( $user_id = 0 ) { 753 // Set default user ID to use. 754 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 681 755 682 756 if ( bp_is_current_action( 'read' ) ) { 683 $retval = bp_get_the_notification_mark_unread_link( );757 $retval = bp_get_the_notification_mark_unread_link( $user_id ); 684 758 } else { 685 $retval = bp_get_the_notification_mark_read_link( );759 $retval = bp_get_the_notification_mark_read_link( $user_id ); 686 760 } 687 761 … … 690 764 * 691 765 * @since 1.9.0 692 * 693 * @param string $retval The mark link for the current notification. 694 */ 695 return apply_filters( 'bp_get_the_notification_mark_link', $retval ); 766 * @since 2.6.0 Added $user_id as a parameter. 767 * 768 * @param string $retval The mark link for the current notification. 769 * @param int $user_id The user ID. 770 */ 771 return apply_filters( 'bp_get_the_notification_mark_link', $retval, $user_id ); 696 772 } 697 773 … … 700 776 * 701 777 * @since 1.9.0 702 * 703 * @uses bp_get_the_notification_delete_link() 704 */ 705 function bp_the_notification_delete_link() { 706 echo bp_get_the_notification_delete_link(); 778 * @since 2.6.0 Added $user_id as a parameter. 779 * 780 * @param int $user_id The user ID. 781 */ 782 function bp_the_notification_delete_link( $user_id = 0 ) { 783 echo bp_get_the_notification_delete_link( $user_id ); 707 784 } 708 785 /** … … 710 787 * 711 788 * @since 1.9.0 712 * 789 * @since 2.6.0 Added $user_id as a parameter. 790 * 791 * @param int $user_id The user ID. 713 792 * @return string 714 793 */ 715 function bp_get_the_notification_delete_link() { 794 function bp_get_the_notification_delete_link( $user_id = 0 ) { 795 // Set default user ID to use. 796 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 716 797 717 798 // Start the output buffer. … … 726 807 * 727 808 * @since 1.9.0 728 * 729 * @param string $retval HTML for the delete link for the current notification. 730 */ 731 return apply_filters( 'bp_get_the_notification_delete_link', $retval ); 809 * @since 2.6.0 Added $user_id as a parameter. 810 * 811 * @param string $retval HTML for the delete link for the current notification. 812 * @param int $user_id The user ID. 813 */ 814 return apply_filters( 'bp_get_the_notification_delete_link', $retval, $user_id ); 732 815 } 733 816 … … 738 821 * 739 822 * @since 2.1.0 740 * 741 * @uses esc_url()742 * @ uses bp_get_the_notification_delete_url()743 */ 744 function bp_the_notification_delete_url( ) {745 echo esc_url( bp_get_the_notification_delete_url( ) );823 * @since 2.6.0 Added $user_id as a parameter. 824 * 825 * @param int $user_id The user ID. 826 */ 827 function bp_the_notification_delete_url( $user_id = 0 ) { 828 echo esc_url( bp_get_the_notification_delete_url( $user_id ) ); 746 829 } 747 830 /** … … 749 832 * 750 833 * @since 2.1.0 751 * 834 * @since 2.6.0 Added $user_id as a parameter. 835 * 836 * @param int $user_id The user ID. 752 837 * @return string 753 838 */ 754 function bp_get_the_notification_delete_url() { 839 function bp_get_the_notification_delete_url( $user_id = 0 ) { 840 // Set default user ID to use. 841 $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id; 755 842 756 843 // URL to add nonce to. 757 844 if ( bp_is_current_action( 'unread' ) ) { 758 $link = bp_get_notifications_unread_permalink( );845 $link = bp_get_notifications_unread_permalink( $user_id ); 759 846 } elseif ( bp_is_current_action( 'read' ) ) { 760 $link = bp_get_notifications_read_permalink( );847 $link = bp_get_notifications_read_permalink( $user_id ); 761 848 } 762 849 … … 780 867 * 781 868 * @since 2.1.0 782 * 783 * @param string $url URL used for deleting a single notification. 784 */ 785 return apply_filters( 'bp_get_the_notification_delete_url', $url ); 869 * @since 2.6.0 Added $user_id as a parameter. 870 * 871 * @param string $url URL used for deleting a single notification. 872 * @param int $user_id The user ID. 873 */ 874 return apply_filters( 'bp_get_the_notification_delete_url', $url, $user_id ); 786 875 } 787 876 … … 790 879 * 791 880 * @since 1.9.0 881 * @since 2.6.0 Added $user_id as a parameter to $args. 792 882 * 793 883 * @param array|string $args Array of arguments. … … 800 890 * 801 891 * @since 1.9.0 892 * @since 2.6.0 Added $user_id as a parameter to $args. 802 893 * 803 894 * @param array|string $args { 804 * @type string $before HTML before the links. 805 * @type string $after HTML after the links. 806 * @type string $sep HTML between the links. 807 * @type array $links Array of links to implode by 'sep'. 895 * @type string $before HTML before the links. 896 * @type string $after HTML after the links. 897 * @type string $sep HTML between the links. 898 * @type array $links Array of links to implode by 'sep'. 899 * @type int $user_id User ID to fetch action links for. Defaults to displayed user ID. 808 900 * } 809 901 * @return string HTML links for actions to take on single notifications. 810 902 */ 811 903 function bp_get_the_notification_action_links( $args = '' ) { 904 // Set default user ID to use. 905 $user_id = isset( $args['user_id'] ) ? $args['user_id'] : bp_displayed_user_id(); 812 906 813 907 // Parse. … … 817 911 'sep' => ' | ', 818 912 'links' => array( 819 bp_get_the_notification_mark_link( ),820 bp_get_the_notification_delete_link( )913 bp_get_the_notification_mark_link( $user_id ), 914 bp_get_the_notification_delete_link( $user_id ) 821 915 ) 822 916 ) );
Note: See TracChangeset
for help on using the changeset viewer.