Changeset 5834 for trunk/src/includes/users/functions.php
- Timestamp:
- 07/15/2015 03:59:23 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/users/functions.php
r5827 r5834 1906 1906 } 1907 1907 1908 /** User Nicename Taxonomies **************************************************/ 1909 1910 /** 1911 * Return the term id for a given user id and taxonomy 1912 * 1913 * @since bbPress (r5834) 1914 * 1915 * @param int $user_id User id. 1916 * @param string $taxonomy Taxonomy. 1917 * @uses get_userdata() To get the user data 1918 * @uses taxonomy_exists() To make sure the taxonomy exists 1919 * @uses get_term_by() To get the term by name 1920 * 1921 * @return boolean|int Return false early, or if not found, or int term id 1922 */ 1923 function bbp_get_user_taxonomy_term_id( $user_id = 0, $taxonomy = '' ) { 1924 1925 // Bail if no user ID. 1926 if ( empty( $user_id ) ) { 1927 return false; 1928 } 1929 1930 // Bail if user does not exist. 1931 $user = get_userdata( $user_id ); 1932 if ( empty( $user ) ) { 1933 return false; 1934 } 1935 1936 // Bail if no taxonomy. 1937 if ( empty( $taxonomy ) || ! taxonomy_exists( $taxonomy ) ) { 1938 return false; 1939 } 1940 1941 // Get the term id. 1942 $term = get_term_by( 'name', $user->user_nicename, $taxonomy ); 1943 if ( ! empty( $term ) ) { 1944 return $term->term_id; 1945 } 1946 1947 return false; 1948 } 1949 1950 /** 1951 * Return the user id for a given term id and taxonomy 1952 * 1953 * @since bbPress (r5834) 1954 * 1955 * @param int $term_id Term id. 1956 * @param string $taxonomy Taxonomy. 1957 * @uses taxonomy_exists() To make sure the taxonomy exists 1958 * @uses get_term() To get the term by term id 1959 * @uses get_user_by() To get the user by nicename 1960 * 1961 * @return boolean|int Return false early, or if not found, or int user id 1962 */ 1963 function bbp_get_term_taxonomy_user_id( $term_id = 0, $taxonomy = '' ) { 1964 1965 // Bail if no user ID. 1966 if ( empty( $term_id ) ) { 1967 return false; 1968 } 1969 1970 // Bail if no taxonomy. 1971 if ( empty( $taxonomy ) || ! taxonomy_exists( $taxonomy ) ) { 1972 return false; 1973 } 1974 1975 // Bail if no term exists. 1976 $term = get_term( $term_id, $taxonomy ); 1977 if ( empty( $term ) ) { 1978 return false; 1979 } 1980 1981 // Get the user by nicename. 1982 $nicename = $term->name; 1983 $user = get_user_by( 'slug', $nicename ); 1984 if ( ! empty( $user ) ) { 1985 return $user->ID; 1986 } 1987 1988 return false; 1989 } 1990 1991 function bbp_filter_forum_mod_term_link( $termlink = '', $term = '', $taxonomy = '' ) { 1992 1993 // Bail if taxonomy is not forum mod 1994 if ( bbp_get_forum_mod_tax_id() !== $taxonomy ) { 1995 return $termlink; 1996 } 1997 1998 // Bail if forum mods is not allowed 1999 if ( ! bbp_allow_forum_mods() ) { 2000 return $termlink; 2001 } 2002 2003 // Get user ID from taxonomy term 2004 $user_id = bbp_get_term_taxonomy_user_id( $term->term_id, bbp_get_forum_mod_tax_id() ); 2005 2006 if ( is_admin() ) { 2007 2008 // Get the moderator's display name 2009 $display_name = get_userdata( $user_id )->display_name; 2010 $user_link = get_edit_user_link( $user_id ); 2011 2012 // Link or name only 2013 if ( ! empty( $user_link ) ) { 2014 $retval = '<a href="' . esc_url( $user_link ) . '">' . esc_html( $display_name ) . '</a>'; 2015 2016 // Can't edit 2017 } else { 2018 $retval = $display_name; 2019 } 2020 2021 // Theme side term link 2022 } else { 2023 $retval = bbp_get_user_profile_link( $user_id ); 2024 } 2025 2026 return $retval; 2027 } 2028 1908 2029 /** Permissions ***************************************************************/ 1909 2030
Note: See TracChangeset
for help on using the changeset viewer.