Ticket #6749: 6749-2.diff
| File 6749-2.diff, 55.1 KB (added by , 4 years ago) |
|---|
-
src/bp-groups/bp-groups-functions.php
diff --git src/bp-groups/bp-groups-functions.php src/bp-groups/bp-groups-functions.php index 9ecddaad7..3a4062df8 100644
function groups_get_group( $group_id ) { 69 69 return apply_filters( 'groups_get_group', $group ); 70 70 } 71 71 72 /** 73 * Retrieve group by a given field. 74 * 75 * @since 10.0.0 76 * 77 * @param string|int $field (Required) The field to retrieve the group. id | ID | slug. 78 * @param string|int $value (Required) A value for $field. A group ID or slug. 79 * @return BP_Groups_Group|false BP_Groups_Group object on success, false on failure. 80 */ 81 function bp_get_group_by( $field, $value ) { 82 $group_id = $value; 83 84 if ( 'slug' === $field && is_string( $value ) ) { 85 $group_id = groups_get_id( $value ); 86 } 87 88 $group = groups_get_group( array( 'group_id' => (int) $group_id ) ); 89 90 if ( empty( $group->id ) ) { 91 return false; 92 } 93 94 return $group; 95 } 96 97 /** 98 * Retrieve a group, defaults to the current group in loop at BP_Groups_Template. 99 * 100 * @since 10.0.0 101 * 102 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 103 * Default: current group in loop. 104 * @return BP_Groups_Group|false BP_Groups_Group object on success, false on failure. 105 */ 106 function bp_get_group( $group = false ) { 107 global $groups_template; 108 109 $group_obj = false; 110 111 if ( $group instanceof BP_Groups_Group ) { 112 $group_obj = $group; 113 } elseif ( is_string( $group ) ) { 114 $group_obj = bp_get_group_by( 'slug', $group ); 115 } elseif ( is_numeric( $group ) ) { 116 $group_obj = bp_get_group_by( 'id', $group ); 117 } elseif ( isset( $groups_template->group ) && is_object( $groups_template->group ) ) { 118 $group_obj = $groups_template->group; 119 } 120 121 return $group_obj; 122 } 123 72 124 /** Group Creation, Editing & Deletion ****************************************/ 73 125 74 126 /** -
src/bp-groups/bp-groups-template.php
diff --git src/bp-groups/bp-groups-template.php src/bp-groups/bp-groups-template.php index 91df7d46e..0ca2afbcb 100644
function bp_groups_group_type_base() { 89 89 * 90 90 * @since 2.7.0 91 91 * 92 * @param string $base 92 * @param string $base Base slug of the group type. 93 93 */ 94 94 return apply_filters( 'bp_groups_group_type_base', _x( 'type', 'group type URL base', 'buddypress' ) ); 95 95 } … … function bp_groups() { 541 541 * 542 542 * @since 1.0.0 543 543 * 544 * @return object544 * @return BP_Groups_Group 545 545 */ 546 546 function bp_the_group() { 547 547 global $groups_template; … … function bp_the_group() { 549 549 } 550 550 551 551 /** 552 * Is the group accessible to the currently logged-inuser?552 * Is the group accessible to a user? 553 553 * Despite the name of the function, it has historically checked 554 554 * whether a user has access to a group. 555 555 * In BP 2.9, a property was added to the BP_Groups_Group class, … … function bp_the_group() { 558 558 * bp_current_user_can( 'groups_see_group' ). 559 559 * 560 560 * @since 1.0.0 561 * @since 10.0.0 Updated to use `bp_get_group` and added the `$user_id` parameter. 561 562 * 562 * @param BP_Groups_Group|null $group Optional. Group object. Default: current group in loop. 563 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 564 * Default: current group in loop. 565 * @param int $user_id ID of the User. 566 * Default: current logged in user. 563 567 * @return bool 564 568 */ 565 function bp_group_is_visible( $group = null) {566 global $groups_template;569 function bp_group_is_visible( $group = false, $user_id = 0 ) { 570 $group = bp_get_group( $group ); 567 571 568 if ( bp_current_user_can( 'bp_moderate') ) {569 return true;572 if ( empty( $group->id ) ) { 573 return false; 570 574 } 571 575 572 if ( empty( $ group) ) {573 $ group =& $groups_template->group;576 if ( empty( $user_id ) ) { 577 $user_id = bp_loggedin_user_id(); 574 578 } 575 579 576 return bp_current_user_can( 'groups_access_group', array( 'group_id' => $group->id) );580 return (bool) ( bp_current_user_can( 'bp_moderate' ) || bp_user_can( $user_id, 'groups_access_group', array( 'group_id' => $group->id ) ) ); 577 581 } 578 582 579 583 /** 580 * Output the ID of the current group in the loop.584 * Output the ID of the group. 581 585 * 582 586 * @since 1.0.0 583 587 * 584 * @param object|bool $group Optional. Group object. Default: current group in loop. 588 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 589 * Default: current group in loop. 585 590 */ 586 591 function bp_group_id( $group = false ) { 587 592 echo bp_get_group_id( $group ); 588 593 } 589 594 /** 590 * Get the ID of the current group in the loop.595 * Get the ID of the group. 591 596 * 592 597 * @since 1.0.0 598 * @since 10.0.0 Updated to use `bp_get_group` 593 599 * 594 * @param object|bool $group Optional. Group object.595 * Default: current group in loop.600 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 601 * Default: current group in loop. 596 602 * @return int 597 603 */ 598 604 function bp_get_group_id( $group = false ) { 599 global $groups_template;605 $group = bp_get_group( $group ); 600 606 601 if ( empty( $group ) ) {602 $group =& $groups_template->group;607 if ( empty( $group->id ) ) { 608 return 0; 603 609 } 604 610 605 611 /** 606 * Filters the ID of the current group in the loop.612 * Filters the ID of the group. 607 613 * 608 614 * @since 1.0.0 609 615 * @since 2.5.0 Added the `$group` parameter. 610 616 * 611 * @param int $id ID of the current group in the loop.612 * @param object $group Group object.617 * @param int $id ID of the group. 618 * @param BP_Groups_Group $group The group object. 613 619 */ 614 620 return apply_filters( 'bp_get_group_id', $group->id, $group ); 615 621 } … … function bp_group_class( $classes = array() ) { 696 702 } 697 703 698 704 /** 699 * Output the name of the current group in the loop.705 * Output the name of the group. 700 706 * 701 707 * @since 1.0.0 702 708 * 703 * @param object|bool $group Optional. Group object.704 * Default: current group in loop.709 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 710 * Default: current group in loop. 705 711 */ 706 712 function bp_group_name( $group = false ) { 707 713 echo bp_get_group_name( $group ); 708 714 } 709 715 /** 710 * Get the name of the current group in the loop.716 * Get the name of the group. 711 717 * 712 718 * @since 1.0.0 719 * @since 10.0.0 Updated to use `bp_get_group` 713 720 * 714 * @param object|bool $group Optional. Group object.715 * Default: current group in loop.721 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 722 * Default: current group in loop. 716 723 * @return string 717 */724 */ 718 725 function bp_get_group_name( $group = false ) { 719 global $groups_template;726 $group = bp_get_group( $group ); 720 727 721 if ( empty( $group ) ) {722 $group =& $groups_template->group;728 if ( empty( $group->id ) ) { 729 return ''; 723 730 } 724 731 725 732 /** 726 * Filters the name of the current group in the loop.733 * Filters the name of the group. 727 734 * 728 735 * @since 1.0.0 729 736 * @since 2.5.0 Added the `$group` parameter. 730 737 * 731 * @param string $name Name of the current group in the loop.732 * @param object $group Group object.738 * @param string $name Name of the group. 739 * @param BP_Groups_Group $group The group object. 733 740 */ 734 741 return apply_filters( 'bp_get_group_name', $group->name, $group ); 735 742 } 736 743 737 744 /** 738 * Output the type of the current group in the loop.745 * Output the type of the group. 739 746 * 740 747 * @since 1.0.0 741 748 * 742 * @param object|bool $group Optional. Group object.743 * Default: current group in loop.749 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 750 * Default: current group in loop. 744 751 */ 745 752 function bp_group_type( $group = false ) { 746 753 echo bp_get_group_type( $group ); 747 754 } 748 749 /**750 * Get the type of the current group in the loop.751 *752 * @since 1.0.0753 *754 * @param object|bool $group Optional. Group object.755 * Default: current group in loop.756 * @return string757 */758 function bp_get_group_type( $group = false ) {759 global $groups_template;760 761 if ( empty( $group ) ) {762 $group =& $groups_template->group;763 }764 765 if ( 'public' == $group->status ) {766 $type = __( "Public Group", 'buddypress' );767 } elseif ( 'hidden' == $group->status ) {768 $type = __( "Hidden Group", 'buddypress' );769 } elseif ( 'private' == $group->status ) {770 $type = __( "Private Group", 'buddypress' );771 } else {772 $type = ucwords( $group->status ) . ' ' . __( 'Group', 'buddypress' );773 }774 775 755 /** 776 * Filters the type for the current group in the loop.756 * Get the type of the group. 777 757 * 778 758 * @since 1.0.0 779 * @since 2.5.0 Added the `$group` parameter.759 * @since 10.0.0 Updated to use `bp_get_group` 780 760 * 781 * @param string $type Type for the current group in the loop. 782 * @param object $group Group object. 761 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 762 * Default: current group in loop. 763 * @return string 783 764 */ 784 return apply_filters( 'bp_get_group_type', $type, $group ); 785 } 765 function bp_get_group_type( $group = false ) { 766 $group = bp_get_group( $group ); 767 768 if ( empty( $group->id ) ) { 769 return ''; 770 } 771 772 if ( 'public' === $group->status ) { 773 $type = __( "Public Group", 'buddypress' ); 774 } elseif ( 'hidden' === $group->status ) { 775 $type = __( "Hidden Group", 'buddypress' ); 776 } elseif ( 'private' === $group->status ) { 777 $type = __( "Private Group", 'buddypress' ); 778 } else { 779 $type = ucwords( $group->status ) . ' ' . __( 'Group', 'buddypress' ); 780 } 781 782 /** 783 * Filters the type for the group. 784 * 785 * @since 1.0.0 786 * @since 2.5.0 Added the `$group` parameter. 787 * 788 * @param string $type Type for the group. 789 * @param BP_Groups_Group $group The group object. 790 */ 791 return apply_filters( 'bp_get_group_type', $type, $group ); 792 } 793 786 794 /** 787 * Output the status of the current group in the loop.795 * Output the status of the group. 788 796 * 789 797 * @since 1.1.0 790 798 * 791 * @param object|bool $group Optional. Group object.792 * Default: current group in loop.799 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 800 * Default: current group in loop. 793 801 */ 794 802 function bp_group_status( $group = false ) { 795 803 echo bp_get_group_status( $group ); 796 804 } 797 805 /** 798 * Get the status of the current group in the loop.806 * Get the status of the group. 799 807 * 800 808 * @since 1.1.0 809 * @since 10.0.0 Updated to use `bp_get_group` 801 810 * 802 * @param object|bool $group Optional. Group object.803 *Default: current group in loop.811 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 812 * Default: current group in loop. 804 813 * @return string 805 814 */ 806 815 function bp_get_group_status( $group = false ) { 807 global $groups_template;816 $group = bp_get_group( $group ); 808 817 809 if ( empty( $group ) ) {810 $group =& $groups_template->group;818 if ( empty( $group->id ) ) { 819 return ''; 811 820 } 812 821 813 822 /** 814 * Filters the status of the current group in the loop.823 * Filters the status of the group. 815 824 * 816 825 * @since 1.0.0 817 826 * @since 2.5.0 Added the `$group` parameter. 818 827 * 819 * @param string $status Status of the current group in the loop.820 * @param object $group Group object.828 * @param string $status Status of the group. 829 * @param BP_Groups_Group $group The group object. 821 830 */ 822 831 return apply_filters( 'bp_get_group_status', $group->status, $group ); 823 832 } 824 833 825 834 /** 826 * Output the group avatar while in the groups loop.835 * Output the group avatar. 827 836 * 828 837 * @since 1.0.0 838 * @since 10.0.0 Added the `$group` parameter. 829 839 * 830 840 * @param array|string $args { 831 841 * See {@link bp_get_group_avatar()} for description of arguments. 832 842 * } 843 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 844 * Default: current group in loop. 833 845 */ 834 function bp_group_avatar( $args = '' ) {835 echo bp_get_group_avatar( $args );846 function bp_group_avatar( $args = '', $group = false ) { 847 echo bp_get_group_avatar( $args, $group ); 836 848 } 837 849 /** 838 850 * Get a group's avatar. 839 851 * 840 852 * @since 1.0.0 853 * @since 10.0.0 Added the `$group` parameter. 841 854 * 842 855 * @see bp_core_fetch_avatar() For a description of arguments and return values. 843 856 * … … function bp_group_avatar( $args = '' ) { 845 858 * Arguments are listed here with an explanation of their defaults. 846 859 * For more information about the arguments, see {@link bp_core_fetch_avatar()}. 847 860 * 848 * @type string $alt Default: 'Group logo of [group name]'. 849 * @type string $class Default: 'avatar'. 850 * @type string $type Default: 'full'. 851 * @type int|bool $width Default: false. 852 * @type int|bool $height Default: false. 853 * @type bool $id Passed to `$css_id` parameter. 861 * @type string $type Default: 'full'. 862 * @type int|bool $width Default: false. 863 * @type int|bool $height Default: false. 864 * @type string $class Default: 'avatar'. 865 * @type bool $no_grav Default: false. 866 * @type bool $html Default: false. 867 * @type string|bool $id Passed to `$css_id` parameter. Default: false. 868 * @type string $alt Default: 'Group logo of [group name]'. 854 869 * } 855 * @return string Group avatar string. 870 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 871 * Default: current group in loop. 872 * @return string|bool Group avatar string or false if avatar uploads is disabled. 856 873 */ 857 function bp_get_group_avatar( $args = '' ) { 858 global $groups_template; 874 function bp_get_group_avatar( $args = '', $group = false ) { 875 $group = bp_get_group( $group ); 876 877 if ( empty( $group->id ) ) { 878 return ''; 879 } 859 880 860 881 // Bail if avatars are turned off. 861 882 if ( bp_disable_group_avatar_uploads() || ! buddypress()->avatar->show_avatars ) { … … function bp_group_avatar( $args = '' ) { 863 884 } 864 885 865 886 // Parse the arguments. 866 $r = bp_parse_args( $args, array( 867 'type' => 'full', 868 'width' => false, 869 'height' => false, 870 'class' => 'avatar', 871 'id' => false, 872 'alt' => sprintf( __( 'Group logo of %s', 'buddypress' ), $groups_template->group->name ) 873 ) ); 887 $r = bp_parse_args( 888 $args, 889 array( 890 'type' => 'full', 891 'width' => false, 892 'height' => false, 893 'class' => 'avatar', 894 'no_grav' => false, 895 'html' => false, 896 'id' => false, 897 // translators: %1$s is the name of the group. 898 'alt' => sprintf( __( 'Group logo of %1$s', 'buddypress' ), $group->name ), 899 ) 900 ); 874 901 875 902 // Fetch the avatar from the folder. 876 $avatar = bp_core_fetch_avatar( array( 877 'item_id' => $groups_template->group->id, 878 'avatar_dir' => 'group-avatars', 879 'object' => 'group', 880 'type' => $r['type'], 881 'alt' => $r['alt'], 882 'css_id' => $r['id'], 883 'class' => $r['class'], 884 'width' => $r['width'], 885 'height' => $r['height'], 886 ) ); 903 $avatar = bp_core_fetch_avatar( 904 array( 905 'item_id' => $group->id, 906 'avatar_dir' => 'group-avatars', 907 'object' => 'group', 908 'type' => $r['type'], 909 'html' => $r['html'], 910 'alt' => $r['alt'], 911 'no_grav' => $r['no_grav'], 912 'css_id' => $r['id'], 913 'class' => $r['class'], 914 'width' => $r['width'], 915 'height' => $r['height'], 916 ) 917 ); 887 918 888 // If No avatarfound, provide some backwards compatibility.919 // If no avatar is found, provide some backwards compatibility. 889 920 if ( empty( $avatar ) ) { 890 $avatar = '<img src="' . esc_url( $groups_template->group->avatar_thumb ) . '" class="avatar" alt="' . esc_attr( $groups_template->group->name ) . '" />'; 921 $avatar = sprintf( 922 '<img src"%1$s" class="avatar" alt="%2$s" />', 923 esc_url( bp_get_group_avatar_thumb( $group ) ), 924 esc_attr( $group->name ) 925 ); 891 926 } 892 927 893 928 /** 894 * Filters the group avatar while in the groups loop.929 * Filters the group avatar. 895 930 * 896 931 * @since 1.0.0 932 * @since 10.0.0 Added the `$group` paremeter. 897 933 * 898 * @param string $avatar HTML image element holding the group avatar. 899 * @param array $r Array of parsed arguments for the group avatar. 934 * @param string $avatar HTML image element holding the group avatar. 935 * @param array $r Array of parsed arguments for the group avatar. 936 * @param BP_Groups_Group $group The group object. 900 937 */ 901 return apply_filters( 'bp_get_group_avatar', $avatar, $r );938 return apply_filters( 'bp_get_group_avatar', $avatar, $r, $group ); 902 939 } 903 940 904 941 /** 905 * Output the group avatar thumbnail while in the groups loop.942 * Output the group avatar thumbnail. 906 943 * 907 944 * @since 1.0.0 908 945 * 909 * @param object|bool $group Optional. Group object.910 * Default: current group in loop.946 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 947 * Default: current group in loop. 911 948 */ 912 949 function bp_group_avatar_thumb( $group = false ) { 913 950 echo bp_get_group_avatar_thumb( $group ); 914 951 } 915 952 /** 916 * Return the group avatar thumbnail while in the groups loop.953 * Return the group avatar thumbnail. 917 954 * 918 955 * @since 1.0.0 919 956 * 920 * @param object|bool $group Optional. Group object.921 * Default: current group in loop.957 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 958 * Default: current group in loop. 922 959 * @return string 923 960 */ 924 961 function bp_get_group_avatar_thumb( $group = false ) { 925 return bp_get_group_avatar( array( 926 'type' => 'thumb', 927 'id' => ! empty( $group->id ) ? $group->id : false 928 ) ); 962 return bp_get_group_avatar( 963 array( 964 'type' => 'thumb', 965 'id' => ! empty( $group->id ) ? $group->id : false, 966 ), 967 $group 968 ); 929 969 } 930 970 931 971 /** 932 * Output the miniature group avatar thumbnail while in the groups loop.972 * Output the miniature group avatar thumbnail. 933 973 * 934 974 * @since 1.0.0 935 975 * 936 * @param object|bool $group Optional. Group object.937 * Default: current group in loop.976 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 977 * Default: current group in loop. 938 978 */ 939 979 function bp_group_avatar_mini( $group = false ) { 940 980 echo bp_get_group_avatar_mini( $group ); 941 981 } 942 982 /** 943 * Return the miniature group avatar thumbnail while in the groups loop.983 * Return the miniature group avatar thumbnail. 944 984 * 945 985 * @since 1.0.0 946 986 * 947 * @param object|bool $group Optional. Group object.948 * Default: current group in loop.987 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 988 * Default: current group in loop. 949 989 * @return string 950 990 */ 951 991 function bp_get_group_avatar_mini( $group = false ) { 952 return bp_get_group_avatar( array( 953 'type' => 'thumb', 954 'width' => 30, 955 'height' => 30, 956 'id' => ! empty( $group->id ) ? $group->id : false 957 ) ); 992 return bp_get_group_avatar( 993 array( 994 'type' => 'thumb', 995 'width' => 30, 996 'height' => 30, 997 'id' => ! empty( $group->id ) ? $group->id : false, 998 ), 999 $group 1000 ); 958 1001 } 959 1002 960 1003 /** 961 * Returnsthe group avatar URL.1004 * Output the group avatar URL. 962 1005 * 963 * @since 5.0.01006 * @since 10.0.0 964 1007 * 965 * @param object|bool $group Optional. Group object. Default current group in loop. 966 * @param string $type Optional. The type of the avatar ('full' or 'thumb'). Default 'full'. 967 * @return string The avatar URL. 1008 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1009 * Default: current group in loop. 1010 * @param string $type Optional. The type of the avatar ('full' or 'thumb'). 1011 * Default 'full'. 968 1012 */ 969 function bp_get_group_avatar_url( $group = false, $type = 'full' ) { 970 $group_id = bp_get_group_id( $group ); 971 972 if ( ! $group_id ) { 973 return ''; 974 } 975 976 return bp_core_fetch_avatar( 977 array( 978 'type' => $type, 979 'object' => 'group', 980 'item_id' => $group_id, 981 'html' => false, 982 ) 983 ); 1013 function bp_group_avatar_url( $group = false, $type = 'full' ) { 1014 echo bp_get_group_avatar_url( $group, $type ); 984 1015 } 1016 /** 1017 * Returns the group avatar URL. 1018 * 1019 * @since 5.0.0 1020 * @since 10.0.0 Updated to use `bp_get_group_avatar` 1021 * 1022 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1023 * Default: current group in loop. 1024 * @param string $type Optional. The type of the avatar ('full' or 'thumb'). 1025 * Default 'full'. 1026 * @return string 1027 */ 1028 function bp_get_group_avatar_url( $group = false, $type = 'full' ) { 1029 return bp_get_group_avatar( array( 'type' => $type ), $group ); 1030 } 985 1031 986 1032 /** Group cover image *********************************************************/ 987 1033 988 1034 /** 989 * Should we use the group's cover image header.1035 * Check if the group's cover image header enabled/active. 990 1036 * 991 1037 * @since 2.4.0 992 1038 * 993 * @return bool True if the displayed user has a cover image, 994 * False otherwise 1039 * @return bool True if the cover image header is enabled, false otherwise. 995 1040 */ 996 1041 function bp_group_use_cover_image_header() { 997 1042 return (bool) bp_is_active( 'groups', 'cover_image' ) && ! bp_disable_group_cover_image_uploads(); … … function bp_group_use_cover_image_header() { 1001 1046 * Returns the group cover image URL. 1002 1047 * 1003 1048 * @since 5.0.0 1049 * @since 10.0.0 Updated to use `bp_get_group` 1004 1050 * 1005 * @param object|bool $group Optional. Group object. Default current group in loop. 1051 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1052 * Default: current group in loop. 1006 1053 * @return string The cover image URL or empty string if not found. 1007 1054 */ 1008 1055 function bp_get_group_cover_url( $group = false ) { 1009 $group _id = bp_get_group_id( $group );1056 $group = bp_get_group( $group ); 1010 1057 1011 if ( ! $group_id) {1058 if ( empty( $group->id ) ) { 1012 1059 return ''; 1013 1060 } 1014 1061 … … function bp_get_group_cover_url( $group = false ) { 1016 1063 'url', 1017 1064 array( 1018 1065 'object_dir' => 'groups', 1019 'item_id' => $group _id,1066 'item_id' => $group->id, 1020 1067 ) 1021 1068 ); 1022 1069 … … function bp_get_group_cover_url( $group = false ) { 1028 1075 } 1029 1076 1030 1077 /** 1031 * Output the 'last active' string for the current group in the loop.1078 * Output the 'last active' string for the group. 1032 1079 * 1033 1080 * @since 1.0.0 1034 * @since 2.7.0 Added $argsas a parameter.1081 * @since 2.7.0 Added `$args` as a parameter. 1035 1082 * 1036 * @param object|bool $group Optional. Group object. Default: current group in loop. 1037 * @param array|string $args Optional. {@see bp_get_group_last_active()}. 1083 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1084 * Default: current group in loop. 1085 * @param array|string $args Optional. {@see bp_get_group_last_active()}. 1038 1086 */ 1039 1087 function bp_group_last_active( $group = false, $args = array() ) { 1040 1088 echo bp_get_group_last_active( $group, $args ); 1041 1089 } 1042 1090 /** 1043 * Return the 'last active' string for the current group in the loop.1091 * Return the 'last active' string for the group. 1044 1092 * 1045 1093 * @since 1.0.0 1046 * @since 2.7.0 Added $args as a parameter. 1094 * @since 2.7.0 Added `$args` as a parameter. 1095 * @since 10.0.0 Updated to use `bp_get_group` 1047 1096 * 1048 * @param object|bool $group Optional. Group object. Default: current group in loop. 1097 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1098 * Default: current group in loop. 1049 1099 * @param array|string $args { 1050 1100 * Array of optional parameters. 1051 1101 * … … function bp_group_last_active( $group = false, $args = array() ) { 1055 1105 * @return string 1056 1106 */ 1057 1107 function bp_get_group_last_active( $group = false, $args = array() ) { 1058 global $groups_template;1108 $group = bp_get_group( $group ); 1059 1109 1060 if ( empty( $group ) ) {1061 $group =& $groups_template->group;1110 if ( empty( $group->id ) ) { 1111 return ''; 1062 1112 } 1063 1113 1064 1114 $r = bp_parse_args( $args, array( … … function bp_group_last_active( $group = false, $args = array() ) { 1086 1136 * @since 1.0.0 1087 1137 * @since 2.5.0 Added the `$group` parameter. 1088 1138 * 1089 * @param string $value Determined last active value for the current group.1090 * @param object $group Group object.1139 * @param string $value Determined last active value for the current group. 1140 * @param BP_Groups_Group|null $group The group object. 1091 1141 */ 1092 1142 return apply_filters( 'bp_get_group_last_active', bp_core_time_since( $last_active ), $group ); 1093 1143 } 1094 1144 } 1095 1145 1096 1146 /** 1097 * Output the permalink for the current group in the loop.1147 * Output the permalink for the group. 1098 1148 * 1099 1149 * @since 1.0.0 1100 1150 * 1101 * @param BP_Groups_Group|null $group Optional. Group object. Default: current group in loop. 1151 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1152 * Default: current group in loop. 1102 1153 */ 1103 function bp_group_permalink( $group = null) {1154 function bp_group_permalink( $group = false ) { 1104 1155 echo bp_get_group_permalink( $group ); 1105 1156 } 1106 1157 /** 1107 * Return the permalink for the current group in the loop.1158 * Return the permalink for the group. 1108 1159 * 1109 1160 * @since 1.0.0 1161 * @since 10.0.0 Updated to use `bp_get_group` 1110 1162 * 1111 * @param BP_Groups_Group|null $group Optional. Group object. Default: current group in loop. 1163 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1164 * Default: current group in loop. 1112 1165 * @return string 1113 1166 */ 1114 function bp_get_group_permalink( $group = null) {1115 global $groups_template;1167 function bp_get_group_permalink( $group = false ) { 1168 $group = bp_get_group( $group ); 1116 1169 1117 if ( empty( $group ) ) {1118 $group =& $groups_template->group;1170 if ( empty( $group->id ) ) { 1171 return ''; 1119 1172 } 1120 1173 1121 1174 /** 1122 * Filters the permalink for the current group in the loop.1175 * Filters the permalink for the group. 1123 1176 * 1124 1177 * @since 1.0.0 1125 1178 * @since 2.5.0 Added the `$group` parameter. 1126 1179 * 1127 * @param string $value Permalink for the current group in the loop.1128 * @param object $group Group object.1180 * @param string $permalink Permalink for the group. 1181 * @param BP_Groups_Group $group The group object. 1129 1182 */ 1130 1183 return apply_filters( 'bp_get_group_permalink', trailingslashit( bp_get_groups_directory_permalink() . bp_get_group_slug( $group ) . '/' ), $group ); 1131 1184 } 1132 1185 1133 1186 /** 1134 * Output an HTML-formatted link for the current group in the loop.1187 * Output an HTML-formatted link for the group. 1135 1188 * 1136 1189 * @since 2.9.0 1137 1190 * 1138 * @param BP_Groups_Group|null $group Optional. Group object.1139 * Default: current group in loop.1191 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1192 * Default: current group in loop. 1140 1193 */ 1141 function bp_group_link( $group = null) {1194 function bp_group_link( $group = false ) { 1142 1195 echo bp_get_group_link( $group ); 1143 1196 } 1144 1197 /** 1145 * Return an HTML-formatted link for the current group in the loop.1198 * Return an HTML-formatted link for the group. 1146 1199 * 1147 1200 * @since 2.9.0 1201 * @since 10.0.0 Updated to use `bp_get_group` 1148 1202 * 1149 * @param BP_Groups_Group|null $group Optional. Group object.1150 *Default: current group in loop.1203 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1204 * Default: current group in loop. 1151 1205 * @return string 1152 1206 */ 1153 function bp_get_group_link( $group = null) {1154 global $groups_template;1207 function bp_get_group_link( $group = false ) { 1208 $group = bp_get_group( $group ); 1155 1209 1156 if ( empty( $group ) ) {1157 $group =& $groups_template->group;1210 if ( empty( $group->id ) ) { 1211 return ''; 1158 1212 } 1159 1213 1160 1214 $link = sprintf( … … function bp_group_link( $group = null ) { 1165 1219 ); 1166 1220 1167 1221 /** 1168 * Filters the HTML-formatted link for the current group in the loop.1222 * Filters the HTML-formatted link for the group. 1169 1223 * 1170 1224 * @since 2.9.0 1171 1225 * 1172 * @param string $value HTML-formatted link for the 1173 * current group in the loop. 1174 * @param BP_Groups_Group $group The current group object. 1226 * @param string $link HTML-formatted link for the group. 1227 * @param BP_Groups_Group $group The group object. 1175 1228 */ 1176 1229 return apply_filters( 'bp_get_group_link', $link, $group ); 1177 1230 } 1178 1231 1179 1232 /** 1180 * Output the permalink for the admin section of the current group in the loop.1233 * Output the permalink for the admin section of the group. 1181 1234 * 1182 1235 * @since 1.0.0 1183 1236 * 1184 * @param object|bool $group Optional. Group object.1185 * Default: current group in loop.1237 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1238 * Default: current group in loop. 1186 1239 */ 1187 1240 function bp_group_admin_permalink( $group = false ) { 1188 1241 echo bp_get_group_admin_permalink( $group ); 1189 1242 } 1190 1243 /** 1191 * Return the permalink for the admin section of the current group in the loop.1244 * Return the permalink for the admin section of the group. 1192 1245 * 1193 1246 * @since 1.0.0 1247 * @since 10.0.0 Updated to use `bp_get_group` 1194 1248 * 1195 * @param object|bool $group Optional. Group object.1196 *Default: current group in loop.1249 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1250 * Default: current group in loop. 1197 1251 * @return string 1198 1252 */ 1199 1253 function bp_get_group_admin_permalink( $group = false ) { 1200 global $groups_template;1254 $group = bp_get_group( $group ); 1201 1255 1202 if ( empty( $group ) ) {1203 $group =& $groups_template->group;1256 if ( empty( $group->id ) ) { 1257 return ''; 1204 1258 } 1205 1259 1206 1260 /** 1207 * Filters the permalink for the admin section of the current group in the loop.1261 * Filters the permalink for the admin section of the group. 1208 1262 * 1209 1263 * @since 1.0.0 1210 1264 * @since 2.5.0 Added the `$group` parameter. 1211 1265 * 1212 * @param string $value Permalink for the admin section of the current group in the loop.1213 * @param object $group Group object.1266 * @param string $permalink Permalink for the admin section of the group. 1267 * @param BP_Groups_Group $group The group object. 1214 1268 */ 1215 1269 return apply_filters( 'bp_get_group_admin_permalink', trailingslashit( bp_get_group_permalink( $group ) . 'admin' ), $group ); 1216 1270 } 1217 1271 1218 1272 /** 1219 * Return the slug for the current group in the loop.1273 * Output the slug for the group. 1220 1274 * 1221 1275 * @since 1.0.0 1222 1276 * 1223 * @param object|bool $group Optional. Group object.1224 * Default: current group in loop.1277 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1278 * Default: current group in loop. 1225 1279 */ 1226 1280 function bp_group_slug( $group = false ) { 1227 1281 echo bp_get_group_slug( $group ); 1228 1282 } 1229 1283 /** 1230 * Return the slug for the current group in the loop.1284 * Return the slug for the group. 1231 1285 * 1232 1286 * @since 1.0.0 1287 * @since 10.0.0 Updated to use `bp_get_group` 1233 1288 * 1234 * @param object|bool $group Optional. Group object.1235 *Default: current group in loop.1289 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1290 * Default: current group in loop. 1236 1291 * @return string 1237 1292 */ 1238 1293 function bp_get_group_slug( $group = false ) { 1239 global $groups_template;1294 $group = bp_get_group( $group ); 1240 1295 1241 if ( empty( $group ) ) {1242 $group =& $groups_template->group;1296 if ( empty( $group->id ) ) { 1297 return ''; 1243 1298 } 1244 1299 1245 1300 /** 1246 * Filters the slug for the current group in the loop.1301 * Filters the slug for the group. 1247 1302 * 1248 1303 * @since 1.0.0 1249 1304 * @since 2.5.0 Added the `$group` parameter. 1250 1305 * 1251 * @param string $slug Slug for the current group in the loop.1252 * @param object $group Group object.1306 * @param string $slug Slug for the group. 1307 * @param BP_Groups_Group $group The group object. 1253 1308 */ 1254 1309 return apply_filters( 'bp_get_group_slug', $group->slug, $group ); 1255 1310 } 1256 1311 1257 1312 /** 1258 * Output the description for the current group in the loop.1313 * Output the description for the group. 1259 1314 * 1260 1315 * @since 1.0.0 1261 1316 * 1262 * @param object|bool $group Optional. Group object.1263 * Default: current group in loop.1317 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1318 * Default: current group in loop. 1264 1319 */ 1265 1320 function bp_group_description( $group = false ) { 1266 1321 echo bp_get_group_description( $group ); 1267 1322 } 1268 1323 /** 1269 * Return the description for the current group in the loop.1324 * Return the description for the group. 1270 1325 * 1271 1326 * @since 1.0.0 1327 * @since 10.0.0 Updated to use `bp_get_group` 1272 1328 * 1273 * @param object|bool $group Optional. Group object.1274 *Default: current group in loop.1329 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1330 * Default: current group in loop. 1275 1331 * @return string 1276 1332 */ 1277 1333 function bp_get_group_description( $group = false ) { 1278 global $groups_template;1334 $group = bp_get_group( $group ); 1279 1335 1280 if ( empty( $group ) ) {1281 $group =& $groups_template->group;1336 if ( empty( $group->id ) ) { 1337 return ''; 1282 1338 } 1283 1339 1284 1340 /** 1285 * Filters the description for the current group in the loop.1341 * Filters the description for the group. 1286 1342 * 1287 1343 * @since 1.0.0 1288 1344 * @since 2.5.0 Added the `$group` parameter. 1289 1345 * 1290 * @param string $value Description for the currentgroup.1291 * @param object $group Group object.1346 * @param string $description Description for the group. 1347 * @param BP_Groups_Group $group The group object. 1292 1348 */ 1293 1349 return apply_filters( 'bp_get_group_description', stripslashes( $group->description ), $group ); 1294 1350 } 1295 1351 1296 1352 /** 1297 * Output the description for the current group in the loop, for use in a textarea.1353 * Output the description for the group, for use in a textarea. 1298 1354 * 1299 1355 * @since 1.0.0 1300 1356 * 1301 * @param object|bool $group Optional. Group object.1302 * Default: current group in loop.1357 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1358 * Default: current group in loop. 1303 1359 */ 1304 1360 function bp_group_description_editable( $group = false ) { 1305 1361 echo bp_get_group_description_editable( $group ); 1306 1362 } 1307 1363 /** 1308 * Return the permalink for the current group in the loop, for use in a textarea.1364 * Return the permalink for the group, for use in a textarea. 1309 1365 * 1310 1366 * 'bp_get_group_description_editable' does not have the formatting 1311 1367 * filters that 'bp_get_group_description' has, which makes it 1312 1368 * appropriate for "raw" editing. 1313 1369 * 1314 1370 * @since 1.0.0 1371 * @since 10.0.0 Updated to use `bp_get_group` 1315 1372 * 1316 * @param object|bool $group Optional. Group object.1317 *Default: current group in loop.1373 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1374 * Default: current group in loop. 1318 1375 * @return string 1319 1376 */ 1320 1377 function bp_get_group_description_editable( $group = false ) { 1321 global $groups_template;1378 $group = bp_get_group( $group ); 1322 1379 1323 if ( empty( $group ) ) {1324 $group =& $groups_template->group;1380 if ( empty( $group->id ) ) { 1381 return ''; 1325 1382 } 1326 1383 1327 1384 /** 1328 * Filters the permalink for the current group in the loop, for use in a textarea.1385 * Filters the permalink for the group, for use in a textarea. 1329 1386 * 1330 1387 * 'bp_get_group_description_editable' does not have the formatting filters that 1331 1388 * 'bp_get_group_description' has, which makes it appropriate for "raw" editing. … … function bp_group_description_editable( $group = false ) { 1333 1390 * @since 1.0.0 1334 1391 * @since 2.5.0 Added the `$group` parameter. 1335 1392 * 1336 * @param string $description Description for the current group in the loop.1337 * @param object $group Group object.1393 * @param string $description Description for the group. 1394 * @param BP_Groups_Group $group The group object. 1338 1395 */ 1339 1396 return apply_filters( 'bp_get_group_description_editable', $group->description, $group ); 1340 1397 } … … function bp_group_description_editable( $group = false ) { 1344 1401 * 1345 1402 * @since 1.0.0 1346 1403 * 1347 * @param object|bool $group Optional. The group being referenced. 1348 * Defaults to the group currently being 1349 * iterated on in the groups loop. 1350 * @param int $length Optional. Length of returned string, including ellipsis. 1351 * Default: 225. 1404 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1405 * Default: current group in loop. 1406 * @param int $length Optional. Length of returned string, including ellipsis. 1407 * Default: 225. 1352 1408 */ 1353 1409 function bp_group_description_excerpt( $group = false, $length = 225 ) { 1354 1410 echo bp_get_group_description_excerpt( $group, $length ); … … function bp_group_description_excerpt( $group = false, $length = 225 ) { 1357 1413 * Get an excerpt of a group description. 1358 1414 * 1359 1415 * @since 1.0.0 1416 * @since 10.0.0 Updated to use `bp_get_group` 1360 1417 * 1361 * @param object|bool $group Optional. The group being referenced. 1362 * Defaults to the group currently being 1363 * iterated on in the groups loop. 1364 * @param int $length Optional. Length of returned string, including ellipsis. 1365 * Default: 225. 1366 * @return string Excerpt. 1418 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1419 * Default: current group in loop. 1420 * @param int $length Optional. Length of returned string, including ellipsis. 1421 * Default: 225. 1422 * @return string 1367 1423 */ 1368 1424 function bp_get_group_description_excerpt( $group = false, $length = 225 ) { 1369 global $groups_template;1425 $group = bp_get_group( $group ); 1370 1426 1371 if ( empty( $group ) ) {1372 $group =& $groups_template->group;1427 if ( empty( $group->id ) ) { 1428 return ''; 1373 1429 } 1374 1430 1375 1431 /** … … function bp_group_description_excerpt( $group = false, $length = 225 ) { 1377 1433 * 1378 1434 * @since 1.0.0 1379 1435 * 1380 * @param string $valueExcerpt of a group description.1381 * @param object $group Object for group whose description is made into an excerpt.1436 * @param string $description Excerpt of a group description. 1437 * @param BP_Groups_Group $group The group object. 1382 1438 */ 1383 1439 return apply_filters( 'bp_get_group_description_excerpt', bp_create_excerpt( $group->description, $length ), $group ); 1384 1440 } 1385 1441 1386 1442 /** 1387 * Output the created date of the current group in the loop.1443 * Output the created date of the group. 1388 1444 * 1389 1445 * @since 1.0.0 1390 * @since 2.7.0 Added $argsas a parameter.1446 * @since 2.7.0 Added `$args` as a parameter. 1391 1447 * 1392 * @param object|bool $group Optional. Group object. Default: current group in loop. 1393 * @param array|string $args {@see bp_get_group_date_created()}. 1448 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1449 * Default: current group in loop. 1450 * @param array|string $args {@see bp_get_group_date_created()}. 1394 1451 */ 1395 1452 function bp_group_date_created( $group = false, $args = array() ) { 1396 1453 echo bp_get_group_date_created( $group, $args ); 1397 1454 } 1398 1455 /** 1399 * Return the created date of the current group in the loop.1456 * Return the created date of the group. 1400 1457 * 1401 1458 * @since 1.0.0 1402 * @since 2.7.0 Added $args as a parameter. 1459 * @since 2.7.0 Added `$args` as a parameter. 1460 * @since 10.0.0 Updated to use `bp_get_group` 1403 1461 * 1404 * @param object|bool $group Optional. Group object. Default: current group in loop. 1405 * @param array|string $args { 1462 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1463 * Default: current group in loop. 1464 * @param array|string $args { 1406 1465 * Array of optional parameters. 1407 1466 * 1408 1467 * @type bool $relative Optional. If true, returns relative created date. eg. active 5 months ago. … … function bp_group_date_created( $group = false, $args = array() ) { 1411 1470 * @return string 1412 1471 */ 1413 1472 function bp_get_group_date_created( $group = false, $args = array() ) { 1414 global $groups_template; 1415 1416 $r = bp_parse_args( $args, array( 1417 'relative' => true, 1418 ), 'group_date_created' ); 1473 $group = bp_get_group( $group ); 1419 1474 1420 if ( empty( $group ) ) {1421 $group =& $groups_template->group;1475 if ( empty( $group->id ) ) { 1476 return ''; 1422 1477 } 1423 1478 1479 $r = bp_parse_args( 1480 $args, 1481 array( 'relative' => true ), 1482 'group_date_created' 1483 ); 1484 1424 1485 // We do not want relative time, so return now. 1425 1486 // @todo Should the 'bp_get_group_date_created' filter be applied here? 1426 1487 if ( ! $r['relative'] ) { … … function bp_group_date_created( $group = false, $args = array() ) { 1428 1489 } 1429 1490 1430 1491 /** 1431 * Filters the created date of the current group in the loop.1492 * Filters the created date of the group. 1432 1493 * 1433 1494 * @since 1.0.0 1434 1495 * @since 2.5.0 Added the `$group` parameter. 1435 1496 * 1436 * @param string $value Created date for the currentgroup.1437 * @param object $group Group object.1497 * @param string $date Created date for the group. 1498 * @param BP_Groups_Group $group The group object. 1438 1499 */ 1439 1500 return apply_filters( 'bp_get_group_date_created', bp_core_time_since( $group->date_created ), $group ); 1440 1501 } 1441 1502 1442 1503 /** 1443 * Output the username of the creator of the current group in the loop.1504 * Output the username of the creator of the group. 1444 1505 * 1445 1506 * @since 1.7.0 1446 1507 * 1447 * @param object|bool $group Optional. Group object.1448 * Default: current group in loop.1508 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1509 * Default: current group in loop. 1449 1510 */ 1450 1511 function bp_group_creator_username( $group = false ) { 1451 1512 echo bp_get_group_creator_username( $group ); 1452 1513 } 1453 1514 /** 1454 * Return the username of the creator of the current group in the loop.1515 * Return the username of the creator of the group. 1455 1516 * 1456 1517 * @since 1.7.0 1518 * @since 10.0.0 Updated to use `bp_get_group` 1457 1519 * 1458 * @param object|bool $group Optional. Group object.1459 *Default: current group in loop.1520 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1521 * Default: current group in loop. 1460 1522 * @return string 1461 1523 */ 1462 1524 function bp_get_group_creator_username( $group = false ) { 1463 global $groups_template;1525 $group = bp_get_group( $group ); 1464 1526 1465 if ( empty( $group ) ) {1466 $group =& $groups_template->group;1527 if ( empty( $group->id ) ) { 1528 return ''; 1467 1529 } 1468 1530 1469 1531 /** 1470 * Filters the username of the creator of the current group in the loop.1532 * Filters the username of the creator of the group. 1471 1533 * 1472 1534 * @since 1.7.0 1473 1535 * @since 2.5.0 Added the `$group` parameter. 1474 1536 * 1475 * @param string $valueUsername of the group creator.1476 * @param object $group Group object.1537 * @param string $creator_id Username of the group creator. 1538 * @param BP_Groups_Group $group The group object. 1477 1539 */ 1478 1540 return apply_filters( 'bp_get_group_creator_username', bp_core_get_user_displayname( $group->creator_id ), $group ); 1479 1541 } 1480 1542 1481 1543 /** 1482 * Output the user ID of the creator of the current group in the loop.1544 * Output the user ID of the creator of the group. 1483 1545 * 1484 1546 * @since 1.7.0 1485 1547 * 1486 * @param object|bool $group Optional. Group object.1487 * Default: current group in loop.1548 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1549 * Default: current group in loop. 1488 1550 */ 1489 1551 function bp_group_creator_id( $group = false ) { 1490 1552 echo bp_get_group_creator_id( $group ); 1491 1553 } 1492 1554 /** 1493 * Return the user ID of the creator of the current group in the loop.1555 * Return the user ID of the creator of the group. 1494 1556 * 1495 1557 * @since 1.7.0 1558 * @since 10.0.0 Updated to use `bp_get_group` 1496 1559 * 1497 * @param object|bool $group Optional. Group object.1498 *Default: current group in loop.1560 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1561 * Default: current group in loop. 1499 1562 * @return int 1500 1563 */ 1501 1564 function bp_get_group_creator_id( $group = false ) { 1502 global $groups_template;1565 $group = bp_get_group( $group ); 1503 1566 1504 if ( empty( $group ) ) {1505 $group =& $groups_template->group;1567 if ( empty( $group->id ) ) { 1568 return 0; 1506 1569 } 1507 1570 1508 1571 /** 1509 * Filters the user ID of the creator of the current group in the loop.1572 * Filters the user ID of the creator of the group. 1510 1573 * 1511 1574 * @since 1.7.0 1512 1575 * @since 2.5.0 Added the `$group` parameter. 1513 1576 * 1514 * @param int $creator_id User ID of the group creator.1515 * @param object $group Group object.1577 * @param int $creator_id User ID of the group creator. 1578 * @param BP_Groups_Group $group The group object. 1516 1579 */ 1517 1580 return apply_filters( 'bp_get_group_creator_id', $group->creator_id, $group ); 1518 1581 } 1519 1582 1520 1583 /** 1521 * Output the permalink of the creator of the current group in the loop.1584 * Output the permalink of the creator of the group. 1522 1585 * 1523 1586 * @since 1.7.0 1524 1587 * 1525 * @param object|bool $group Optional. Group object.1526 * Default: current group in loop.1588 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1589 * Default: current group in loop. 1527 1590 */ 1528 1591 function bp_group_creator_permalink( $group = false ) { 1529 1592 echo bp_get_group_creator_permalink( $group ); 1530 1593 } 1531 1594 /** 1532 * Return the permalink of the creator of the current group in the loop.1595 * Return the permalink of the creator of the group. 1533 1596 * 1534 1597 * @since 1.7.0 1598 * @since 10.0.0 Updated to use `bp_get_group` 1535 1599 * 1536 * @param object|bool $group Optional. Group object.1537 *Default: current group in loop.1600 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1601 * Default: current group in loop. 1538 1602 * @return string 1539 1603 */ 1540 1604 function bp_get_group_creator_permalink( $group = false ) { 1541 global $groups_template;1605 $group = bp_get_group( $group ); 1542 1606 1543 if ( empty( $group ) ) {1544 $group =& $groups_template->group;1607 if ( empty( $group->id ) ) { 1608 return ''; 1545 1609 } 1546 1610 1547 1611 /** 1548 * Filters the permalink of the creator of the current group in the loop.1612 * Filters the permalink of the creator of the group. 1549 1613 * 1550 1614 * @since 1.7.0 1551 1615 * @since 2.5.0 Added the `$group` parameter. 1552 1616 * 1553 * @param string $valuePermalink of the group creator.1554 * @param object $group Group object.1617 * @param string $permalink Permalink of the group creator. 1618 * @param BP_Groups_Group $group The group object. 1555 1619 */ 1556 1620 return apply_filters( 'bp_get_group_creator_permalink', bp_core_get_user_domain( $group->creator_id ), $group ); 1557 1621 } 1558 1622 1559 1623 /** 1560 * Determine whether a user is the creator of the current group in the loop.1624 * Determine whether a user is the creator of the group. 1561 1625 * 1562 1626 * @since 1.7.0 1627 * @since 10.0.0 Updated to use `bp_get_group` 1563 1628 * 1564 * @param BP_Groups_Group|null $group Optional. Group object. Default: current group in loop. 1565 * @param int $user_id ID of the user. 1629 * @param int|string|BP_Groups_Group $group (Optional) Group identifier. 1630 * Default: current group in loop. 1631 * @param int $user_id ID of the user. 1632 * Default: current logged in user. 1566 1633 * @return bool 1567 1634 */ 1568 function bp_is_group_creator( $group = null, $user_id = 0 ) {1569 global $groups_template;1635 function bp_is_group_creator( $group = false, $user_id = 0 ) { 1636 $group = bp_get_group( $group ); 1570 1637 1571 if ( empty( $group ) ) {1572 $group =& $groups_template->group;1638 if ( empty( $group->id ) ) { 1639 return false; 1573 1640 } 1574 1641 1575 1642 if ( empty( $user_id ) ) { 1576 1643 $user_id = bp_loggedin_user_id(); 1577 1644 } 1578 1645 1579 return (bool) ( $group->creator_id == $user_id );1646 return (bool) ( $group->creator_id === $user_id ); 1580 1647 } 1581 1648 1582 1649 /** … … function bp_group_current_avatar( $type = 'thumb' ) { 5431 5498 * Return whether a group has an avatar. 5432 5499 * 5433 5500 * @since 1.1.0 5501 * @since 10.0.0 Updated to use `bp_get_group_avatar` 5434 5502 * 5435 5503 * @param int|bool $group_id Group ID to check. 5436 * @return bool ean5504 * @return bool 5437 5505 */ 5438 5506 function bp_get_group_has_avatar( $group_id = false ) { 5439 5507 5440 if ( false === $group_id) {5508 if ( empty( $group_id ) ) { 5441 5509 $group_id = bp_get_current_group_id(); 5442 5510 } 5443 5511 5444 5512 $avatar_args = array( 5445 'item_id' => $group_id,5446 'object' => 'group',5447 5513 'no_grav' => true, 5448 5514 'html' => false, 5449 5515 'type' => 'thumb', 5450 5516 ); 5451 5517 5452 $group_avatar = bp_core_fetch_avatar( $avatar_args ); 5453 5454 if ( bp_core_avatar_default( 'local', $avatar_args ) === $group_avatar ) { 5455 return false; 5456 } 5518 $group_avatar = bp_get_group_avatar( $avatar_args, $group_id ); 5519 $avatar_args = array_merge( 5520 $avatar_args, 5521 array( 5522 'item_id' => $group_id, 5523 'object' => 'group', 5524 ) 5525 ); 5457 5526 5458 return true;5527 return ( bp_core_avatar_default( 'local', $avatar_args ) !== $group_avatar ); 5459 5528 } 5460 5529 5461 5530 /** -
new file tests/phpunit/testcases/groups/functions/get-group.php
diff --git tests/phpunit/testcases/groups/functions/get-group.php tests/phpunit/testcases/groups/functions/get-group.php new file mode 100644 index 000000000..c86240832
- + 1 <?php 2 3 /** 4 * @group groups 5 * @group functions 6 */ 7 class BP_Tests_Get_Groups_Param extends BP_UnitTestCase { 8 9 public function setUp() { 10 parent::setUp(); 11 12 if ( isset( $GLOBALS['groups_template'] ) ) { 13 $this->groups_template = $GLOBALS['groups_template']; 14 } 15 } 16 17 public function tearDown() { 18 if ( $this->groups_template ) { 19 $GLOBALS['groups_template'] = $this->groups_template; 20 } 21 22 parent::tearDown(); 23 } 24 25 public function test_bp_get_group_with_no_group() { 26 $this->assertFalse( bp_get_group() ); 27 $this->assertFalse( bp_get_group_by( 'id', 0 ) ); 28 } 29 30 public function test_bp_get_group_with_id() { 31 $g = $this->factory->group->create(); 32 33 $this->assertSame( $g, bp_get_group( $g )->id ); 34 $this->assertSame( $g, bp_get_group_by( 'id', $g )->id ); 35 $this->assertSame( $g, bp_get_group_by( 'ID', $g )->id ); 36 } 37 38 public function test_bp_get_group_with_slug() { 39 $slug = 'test-group'; 40 $g = $this->factory->group->create( array( 'slug' => $slug ) ); 41 $g1 = bp_get_group( $slug ); 42 43 $this->assertSame( $g, $g1->id ); 44 $this->assertSame( $slug, $g1->slug ); 45 46 $g2 = bp_get_group_by( 'slug', $slug ); 47 48 $this->assertSame( $g, $g2->id ); 49 $this->assertSame( $slug, $g2->slug ); 50 } 51 52 public function test_bp_get_group_with_object() { 53 $g = $this->factory->group->create_and_get(); 54 55 $this->assertSame( $g->id, bp_get_group( $g )->id ); 56 } 57 58 public function test_bp_get_group_from_groups_template() { 59 $g = $this->factory->group->create( array( 'status' => 'private' ) ); 60 61 // Fake the current group. 62 $GLOBALS['groups_template'] = new stdClass; 63 $GLOBALS['groups_template']->group = groups_get_group( $g ); 64 65 $this->assertSame( $g, bp_get_group()->id ); 66 } 67 } -
new file tests/phpunit/testcases/groups/template/group-is-visible.php
diff --git tests/phpunit/testcases/groups/template/group-is-visible.php tests/phpunit/testcases/groups/template/group-is-visible.php new file mode 100644 index 000000000..c1f78148b
- + 1 <?php 2 3 /** 4 * @group groups 5 * @group template 6 */ 7 class BP_Tests_Groups_Template_Is_Visible extends BP_UnitTestCase { 8 9 public function setUp() { 10 parent::setUp(); 11 12 if ( isset( $GLOBALS['groups_template'] ) ) { 13 $this->groups_template = $GLOBALS['groups_template']; 14 } 15 } 16 17 public function tearDown() { 18 if ( $this->groups_template ) { 19 $GLOBALS['groups_template'] = $this->groups_template; 20 } 21 22 parent::tearDown(); 23 } 24 25 public function test_bp_group_is_visible_no_member() { 26 $g = $this->factory->group->create( array( 'status' => 'private' ) ); 27 28 $this->assertFalse( bp_group_is_visible( $g ) ); 29 } 30 31 public function test_bp_group_is_visible_regular_member() { 32 $g = $this->factory->group->create( array( 'status' => 'private' ) ); 33 $u = $this->factory->user->create(); 34 35 $this->set_current_user( $u ); 36 37 $this->assertFalse( bp_group_is_visible( $g ) ); 38 } 39 40 public function test_bp_group_is_visible_regular_member_from_group() { 41 $g = $this->factory->group->create( array( 'status' => 'private' ) ); 42 $u = $this->factory->user->create(); 43 44 $this->set_current_user( $u ); 45 46 $this->add_user_to_group( $u, $g ); 47 48 $this->assertTrue( bp_group_is_visible( $g ) ); 49 } 50 51 public function test_bp_group_is_visible_invalid_group() { 52 $u = $this->factory->user->create(); 53 54 // Empty the current group. 55 $GLOBALS['groups_template'] = new stdClass; 56 $GLOBALS['groups_template']->group = null; 57 58 $this->set_current_user( $u ); 59 60 $this->assertFalse( bp_group_is_visible() ); 61 } 62 63 public function test_bp_group_is_visible_admin() { 64 $g = $this->factory->group->create( array( 'status' => 'private' ) ); 65 $u = $this->factory->user->create( array( 'role' => 'administrator' ) ); 66 67 $this->set_current_user( $u ); 68 69 $this->assertTrue( bp_group_is_visible( $g ) ); 70 } 71 72 public function test_bp_group_is_visible_using_user_id() { 73 $g = $this->factory->group->create( array( 'status' => 'hidden' ) ); 74 $u = $this->factory->user->create(); 75 76 $this->add_user_to_group( $u, $g ); 77 78 $this->assertTrue( bp_group_is_visible( $g, $u ) ); 79 } 80 81 public function test_bp_group_is_not_visible_using_user_id() { 82 $g = $this->factory->group->create( array( 'status' => 'private' ) ); 83 $u = $this->factory->user->create(); 84 85 $this->assertFalse( bp_group_is_visible( $g, $u ) ); 86 } 87 88 public function test_bp_group_is_visible_with_group_slug() { 89 $slug = 'test-group'; 90 91 $this->factory->group->create( 92 array( 93 'status' => 'private', 94 'slug' => $slug, 95 ) 96 ); 97 98 $u = $this->factory->user->create( array( 'role' => 'administrator' ) ); 99 100 $this->set_current_user( $u ); 101 102 $this->assertTrue( bp_group_is_visible( $slug ) ); 103 } 104 105 public function test_bp_group_is_visible_from_current_group() { 106 $g = $this->factory->group->create( array( 'status' => 'private' ) ); 107 $u = $this->factory->user->create( array( 'role' => 'administrator' ) ); 108 109 // Fake the current group. 110 $GLOBALS['groups_template'] = new stdClass; 111 $GLOBALS['groups_template']->group = groups_get_group( $g ); 112 113 $this->set_current_user( $u ); 114 115 $this->assertTrue( bp_group_is_visible() ); 116 } 117 } -
tests/phpunit/testcases/groups/template/
diff --git tests/phpunit/testcases/groups/template/bpGroupStatusMessage.php tests/phpunit/testcases/groups/template/status-message.php similarity index 97% rename from tests/phpunit/testcases/groups/template/bpGroupStatusMessage.php rename to tests/phpunit/testcases/groups/template/status-message.php index bcc1ff3eb..c4fd836f7 100644
old new 2 2 3 3 /** 4 4 * @group groups 5 * @group template 5 6 */ 6 class BP_Tests_Groups_Template_ BpGroupStatusMessage extends BP_UnitTestCase {7 class BP_Tests_Groups_Template_Status_Message extends BP_UnitTestCase { 7 8 private $current_user; 8 9 private $groups_template = null; 9 10