displayed_user->ID ) ) $bbp_user_id = $bbp->displayed_user->ID; // Maybe fallback on the current_user ID elseif ( ( true == $current_user_fallback ) && !empty( $bbp->current_user->ID ) ) $bbp_user_id = $bbp->current_user->ID; // Failsafe else $bbp_user_id = get_query_var( 'bbp_user_id' ); return apply_filters( 'bbp_get_user_id', (int) $bbp_user_id ); } /** * Output ID of current user * * @since bbPress (r2574) * * @uses bbp_get_current_user_id() To get the current user id */ function bbp_current_user_id() { echo bbp_get_current_user_id(); } /** * Return ID of current user * * @since bbPress (r2574) * * @uses bbp_get_user_id() To get the current user id * @uses apply_filters() Calls 'bbp_get_current_user_id' with the id * @return int Current user id */ function bbp_get_current_user_id() { return apply_filters( 'bbp_get_current_user_id', bbp_get_user_id( 0, false, true ) ); } /** * Output ID of displayed user * * @since bbPress (r2688) * * @uses bbp_get_displayed_user_id() To get the displayed user id */ function bbp_displayed_user_id() { echo bbp_get_displayed_user_id(); } /** * Return ID of displayed user * * @since bbPress (r2688) * * @uses bbp_get_user_id() To get the displayed user id * @uses apply_filters() Calls 'bbp_get_displayed_user_id' with the id * @return int Displayed user id */ function bbp_get_displayed_user_id() { return apply_filters( 'bbp_get_displayed_user_id', bbp_get_user_id( 0, true, false ) ); } /** * Return a sanitized user field value * * @since bbPress (r2688) * * @param string $field Field to get * @uses sanitize_text_field() To sanitize the field * @uses esc_attr() To sanitize the field * @return string|bool Value of the field if it exists, else false */ function bbp_get_displayed_user_field( $field = '' ) { global $bbp; // Return field if exists if ( isset( $bbp->displayed_user->$field ) ) return esc_attr( sanitize_text_field( $bbp->displayed_user->$field ) ); // Return empty return false; } /** * Output name of current user * * @since bbPress (r2574) * * @uses bbp_get_current_user_name() To get the current user name */ function bbp_current_user_name() { echo bbp_get_current_user_name(); } /** * Return name of current user * * @since bbPress (r2574) * * @uses apply_filters() Calls 'bbp_get_current_user_name' with the * current user name * @return string */ function bbp_get_current_user_name() { global $user_identity; $current_user_name = is_user_logged_in() ? $user_identity : __( 'Anonymous', 'bbpress' ); return apply_filters( 'bbp_get_current_user_name', $current_user_name ); } /** * Output avatar of current user * * @since bbPress (r2574) * * @param int $size Size of the avatar. Defaults to 40 * @uses bbp_get_current_user_avatar() To get the current user avatar */ function bbp_current_user_avatar( $size = 40 ) { echo bbp_get_current_user_avatar( $size ); } /** * Return avatar of current user * * @since bbPress (r2574) * * @param int $size Size of the avatar. Defaults to 40 * @uses bbp_get_current_user_id() To get the current user id * @uses bbp_get_current_anonymous_user_data() To get the current * anonymous user's email * @uses get_avatar() To get the avatar * @uses apply_filters() Calls 'bbp_get_current_user_avatar' with the * avatar and size * @return string Current user avatar */ function bbp_get_current_user_avatar( $size = 40 ) { if ( !$user = bbp_get_current_user_id() ) $user = bbp_get_current_anonymous_user_data( 'email' ); return apply_filters( 'bbp_get_current_user_avatar', get_avatar( $user, $size ), $size ); } /** * Output link to the profile page of a user * * @since bbPress (r2688) * * @param int $user_id Optional. User id * @uses bbp_get_user_profile_link() To get user profile link */ function bbp_user_profile_link( $user_id = 0 ) { echo bbp_get_user_profile_link( $user_id ); } /** * Return link to the profile page of a user * * @since bbPress (r2688) * * @param int $user_id Optional. User id * @uses bbp_get_user_id() To get user id * @uses get_userdata() To get user data * @uses bbp_get_user_profile_url() To get user profile url * @uses apply_filters() Calls 'bbp_get_user_profile_link' with the user * profile link and user id * @return string User profile link */ function bbp_get_user_profile_link( $user_id = 0 ) { if ( !$user_id = bbp_get_user_id( $user_id ) ) return false; $user = get_userdata( $user_id ); $name = esc_attr( $user->display_name ); $user_link = '' . $name . ''; return apply_filters( 'bbp_get_user_profile_link', $user_link, $user_id ); } /** * Output URL to the profile page of a user * * @since bbPress (r2688) * * @param int $user_id Optional. User id * @param string $user_nicename Optional. User nicename * @uses bbp_get_user_profile_url() To get user profile url */ function bbp_user_profile_url( $user_id = 0, $user_nicename = '' ) { echo bbp_get_user_profile_url( $user_id ); } /** * Return URL to the profile page of a user * * @since bbPress (r2688) * * @param int $user_id Optional. User id * @param string $user_nicename Optional. User nicename * @uses bbp_get_user_id() To get user id * @uses WP_Rewrite::using_permalinks() To check if the blog is using * permalinks * @uses add_query_arg() To add custom args to the url * @uses home_url() To get blog home url * @uses apply_filters() Calls 'bbp_get_user_profile_url' with the user * profile url, user id and user nicename * @return string User profile url */ function bbp_get_user_profile_url( $user_id = 0, $user_nicename = '' ) { global $wp_rewrite, $bbp; // Use displayed user ID if there is one, and one isn't requested if ( !$user_id = bbp_get_user_id( $user_id ) ) return false; // Allow early overriding of the profile URL to cut down on processing $early_profile_url = apply_filters( 'bbp_pre_get_user_profile_url', (int) $user_id ); if ( is_string( $early_profile_url ) ) return $early_profile_url; // Pretty permalinks if ( $wp_rewrite->using_permalinks() ) { $url = $wp_rewrite->root . $bbp->user_slug . '/%' . $bbp->user_id . '%'; // Get username if not passed if ( empty( $user_nicename ) ) { $user = get_userdata( $user_id ); if ( !empty( $user->user_nicename ) ) { $user_nicename = $user->user_nicename; } } $url = str_replace( '%' . $bbp->user_id . '%', $user_nicename, $url ); $url = home_url( user_trailingslashit( $url ) ); // Unpretty permalinks } else { $url = add_query_arg( array( $bbp->user_id => $user_id ), home_url( '/' ) ); } return apply_filters( 'bbp_get_user_profile_url', $url, $user_id, $user_nicename ); } /** * Output link to the profile edit page of a user * * @since bbPress (r2688) * * @param int $user_id Optional. User id * @uses bbp_get_user_profile_edit_link() To get user profile edit link */ function bbp_user_profile_edit_link( $user_id = 0 ) { echo bbp_get_user_profile_edit_link( $user_id ); } /** * Return link to the profile edit page of a user * * @since bbPress (r2688) * * @param int $user_id Optional. User id * @uses bbp_get_user_id() To get user id * @uses get_userdata() To get user data * @uses bbp_get_user_profile_edit_url() To get user profile edit url * @uses apply_filters() Calls 'bbp_get_user_profile_link' with the edit * link and user id * @return string User profile edit link */ function bbp_get_user_profile_edit_link( $user_id = 0 ) { if ( !$user_id = bbp_get_user_id( $user_id ) ) return false; $user = get_userdata( $user_id ); $name = $user->display_name; $edit_link = '' . $name . ''; return apply_filters( 'bbp_get_user_profile_link', $edit_link, $user_id ); } /** * Output URL to the profile edit page of a user * * @since bbPress (r2688) * * @param int $user_id Optional. User id * @param string $user_nicename Optional. User nicename * @uses bbp_get_user_profile_edit_url() To get user profile edit url */ function bbp_user_profile_edit_url( $user_id = 0, $user_nicename = '' ) { echo bbp_get_user_profile_edit_url( $user_id ); } /** * Return URL to the profile edit page of a user * * @since bbPress (r2688) * * @param int $user_id Optional. User id * @param string $user_nicename Optional. User nicename * @uses bbp_get_user_id() To get user id * @uses WP_Rewrite::using_permalinks() To check if the blog is using * permalinks * @uses add_query_arg() To add custom args to the url * @uses home_url() To get blog home url * @uses apply_filters() Calls 'bbp_get_user_edit_profile_url' with the * edit profile url, user id and user nicename * @return string */ function bbp_get_user_profile_edit_url( $user_id = 0, $user_nicename = '' ) { global $wp_rewrite, $bbp; if ( !$user_id = bbp_get_user_id( $user_id ) ) return; // Pretty permalinks if ( $wp_rewrite->using_permalinks() ) { $url = $wp_rewrite->root . $bbp->user_slug . '/%' . $bbp->user_id . '%/' . $bbp->edit_id; // Get username if not passed if ( empty( $user_nicename ) ) { $user = get_userdata( $user_id ); if ( !empty( $user->user_nicename ) ) { $user_nicename = $user->user_nicename; } } $url = str_replace( '%' . $bbp->user_id . '%', $user_nicename, $url ); $url = home_url( user_trailingslashit( $url ) ); // Unpretty permalinks } else { $url = add_query_arg( array( $bbp->user_id => $user_id, $bbp->edit_id => '1' ), home_url( '/' ) ); } return apply_filters( 'bbp_get_user_edit_profile_url', $url, $user_id, $user_nicename ); } /** * Output the link to the admin section * * @since bbPress (r2827) * * @param mixed $args Optional. See {@link bbp_get_admin_link()} * @uses bbp_get_admin_link() To get the admin link */ function bbp_admin_link( $args = '' ) { echo bbp_get_admin_link( $args ); } /** * Return the link to the admin section * * @since bbPress (r2827) * * @param mixed $args Optional. This function supports these arguments: * - text: The text * - before: Before the lnk * - after: After the link * @uses current_user_can() To check if the current user can moderate * @uses admin_url() To get the admin url * @uses apply_filters() Calls 'bbp_get_admin_link' with the link & args * @return The link */ function bbp_get_admin_link( $args = '' ) { if ( !current_user_can( 'moderate' ) ) return; if ( $args && is_string( $args ) && false === strpos( $args, '=' ) ) $args = array( 'text' => $args ); $defaults = array( 'text' => __( 'Admin', 'bbpress' ), 'before' => '', 'after' => '' ); $args = wp_parse_args( $args, $defaults ); extract( $args, EXTR_SKIP ); $uri = admin_url(); return apply_filters( 'bbp_get_admin_link', $before . '' . $text . '' . $after, $args ); } /** User IP *******************************************************************/ /** * Output the author IP address of a post * * @since bbPress (r3120) * * @param mixed $args Optional. If it is an integer, it is used as post id. * @uses bbp_get_author_ip() To get the post author link */ function bbp_author_ip( $args = '' ) { echo bbp_get_author_ip( $args ); } /** * Return the author IP address of a post * * @since bbPress (r3120) * * @param mixed $args Optional. If an integer, it is used as reply id. * @uses get_post_meta() To check if it's a topic page * @return string Author link of reply */ function bbp_get_author_ip( $args = '' ) { // Default arguments $defaults = array( 'post_id' => 0, 'before' => ' ' ); $r = wp_parse_args( $args, $defaults ); extract( $r ); // Used as post id if ( is_numeric( $args ) ) $post_id = $args; // Get the author IP meta value if ( $author_ip = get_post_meta( $post_id, '_bbp_author_ip', true ) ) $author_ip = $before . $author_ip . $after; // No IP address else $author_ip = ''; return apply_filters( 'bbp_get_author_ip', $author_ip, $args ); } /** Favorites *****************************************************************/ /** * Output the link to the user's favorites page (profile page) * * @since bbPress (r2652) * * @param int $user_id Optional. User id * @uses bbp_get_favorites_permalink() To get the favorites permalink */ function bbp_favorites_permalink( $user_id = 0 ) { echo bbp_get_favorites_permalink( $user_id ); } /** * Return the link to the user's favorites page (profile page) * * @since bbPress (r2652) * * @param int $user_id Optional. User id * @uses bbp_get_user_profile_url() To get the user profile url * @uses apply_filters() Calls 'bbp_get_favorites_permalink' with the * user profile url and user id * @return string Permanent link to user profile page */ function bbp_get_favorites_permalink( $user_id = 0 ) { return apply_filters( 'bbp_get_favorites_permalink', bbp_get_user_profile_url( $user_id ), $user_id ); } /** * Output the link to make a topic favorite/remove a topic from favorites * * @since bbPress (r2652) * * @param array $add Optional. Add to favorites args * @param array $rem Optional. Remove from favorites args * @param int $user_id Optional. User id * @uses bbp_get_user_favorites_link() To get the user favorites link */ function bbp_user_favorites_link( $add = array(), $rem = array(), $user_id = 0 ) { echo bbp_get_user_favorites_link( $add, $rem, $user_id ); } /** * User favorites link * * Return the link to make a topic favorite/remove a topic from * favorites * * @since bbPress (r2652) * * @param array $add Optional. Add to favorites args * @param array $rem Optional. Remove from favorites args * @param int $user_id Optional. User id * @uses bbp_get_user_id() To get the user id * @uses current_user_can() If the current user can edit the user * @uses bbp_get_topic_id() To get the topic id * @uses bbp_is_user_favorite() To check if the topic is user's favorite * @uses bbp_get_favorites_permalink() To get the favorites permalink * @uses bbp_get_topic_permalink() To get the topic permalink * @uses bbp_is_favorites() Is it the favorites page? * @uses apply_filters() Calls 'bbp_get_user_favorites_link' with the * html, add args, remove args, user & topic id * @return string User favorites link */ function bbp_get_user_favorites_link( $add = array(), $rem = array(), $user_id = 0 ) { if ( !bbp_is_favorites_active() ) return false; if ( !$user_id = bbp_get_user_id( $user_id, true, true ) ) return false; if ( !current_user_can( 'edit_user', (int) $user_id ) ) return false; if ( !$topic_id = bbp_get_topic_id() ) return false; if ( empty( $add ) || !is_array( $add ) ) { $add = array( 'mid' => __( 'Add this topic to your favorites', 'bbpress' ), 'post' => __( ' (%?%)', 'bbpress' ) ); } if ( empty( $rem ) || !is_array( $rem ) ) { $rem = array( 'pre' => __( 'This topic is one of your %favorites% [', 'bbpress' ), 'mid' => __( '×', 'bbpress' ), 'post' => __( ']', 'bbpress' ) ); } if ( $is_fav = bbp_is_user_favorite( $user_id, $topic_id ) ) { $url = esc_url( bbp_get_favorites_permalink( $user_id ) ); $rem = preg_replace( '|%(.+)%|', "$1", $rem ); $favs = array( 'action' => 'bbp_favorite_remove', 'topic_id' => $topic_id ); $pre = ( is_array( $rem ) && isset( $rem['pre'] ) ) ? $rem['pre'] : ''; $mid = ( is_array( $rem ) && isset( $rem['mid'] ) ) ? $rem['mid'] : ( is_string( $rem ) ? $rem : '' ); $post = ( is_array( $rem ) && isset( $rem['post'] ) ) ? $rem['post'] : ''; } else { $url = esc_url( bbp_get_topic_permalink( $topic_id ) ); $add = preg_replace( '|%(.+)%|', "$1", $add ); $favs = array( 'action' => 'bbp_favorite_add', 'topic_id' => $topic_id ); $pre = ( is_array( $add ) && isset( $add['pre'] ) ) ? $add['pre'] : ''; $mid = ( is_array( $add ) && isset( $add['mid'] ) ) ? $add['mid'] : ( is_string( $add ) ? $add : '' ); $post = ( is_array( $add ) && isset( $add['post'] ) ) ? $add['post'] : ''; } // Create the link based where the user is and if the topic is already the user's favorite if ( bbp_is_favorites() ) $permalink = bbp_get_favorites_permalink( $user_id ); elseif ( is_singular( bbp_get_topic_post_type() ) ) $permalink = bbp_get_topic_permalink( $topic_id ); elseif ( bbp_is_query_name( 'bbp_single_topic' ) ) $permalink = get_permalink(); $url = esc_url( wp_nonce_url( add_query_arg( $favs, $permalink ), 'toggle-favorite_' . $topic_id ) ); $is_fav = $is_fav ? 'is-favorite' : ''; $html = '' . $pre . '' . $mid . '' . $post . ''; // Return the link return apply_filters( 'bbp_get_user_favorites_link', $html, $add, $rem, $user_id, $topic_id ); } /** Subscriptions *************************************************************/ /** * Output the link to the user's subscriptions page (profile page) * * @since bbPress (r2688) * * @param int $user_id Optional. User id * @uses bbp_get_subscriptions_permalink() To get the subscriptions link */ function bbp_subscriptions_permalink( $user_id = 0 ) { echo bbp_get_subscriptions_permalink( $user_id ); } /** * Return the link to the user's subscriptions page (profile page) * * @since bbPress (r2688) * * @param int $user_id Optional. User id * @uses bbp_get_user_profile_url() To get the user profile url * @uses apply_filters() Calls 'bbp_get_subscriptions_permalink' with * the user profile url and user id * @return string Permanent link to user subscriptions page */ function bbp_get_subscriptions_permalink( $user_id = 0 ) { return apply_filters( 'bbp_get_subscriptions_permalink', bbp_get_user_profile_url( $user_id ), $user_id ); } /** * Output the link to subscribe/unsubscribe from a topic * * @since bbPress (r2668) * * @param mixed $args See {@link bbp_get_user_subscribe_link()} * @uses bbp_get_user_subscribe_link() To get the subscribe link */ function bbp_user_subscribe_link( $args = '' ) { echo bbp_get_user_subscribe_link( $args ); } /** * Return the link to subscribe/unsubscribe from a topic * * @since bbPress (r2668) * * @param mixed $args This function supports these arguments: * - subscribe: Subscribe text * - unsubscribe: Unsubscribe text * - user_id: User id * - topic_id: Topic id * - before: Before the link * - after: After the link * @param int $user_id Optional. User id * @uses bbp_get_user_id() To get the user id * @uses current_user_can() To check if the current user can edit user * @uses bbp_get_topic_id() To get the topic id * @uses bbp_is_user_subscribed() To check if the user is subscribed * @uses bbp_is_subscriptions() To check if it's the subscriptions page * @uses bbp_get_subscriptions_permalink() To get subscriptions link * @uses bbp_get_topic_permalink() To get topic link * @uses apply_filters() Calls 'bbp_get_user_subscribe_link' with the * link, args, user id & topic id * @return string Permanent link to topic */ function bbp_get_user_subscribe_link( $args = '', $user_id = 0 ) { if ( !bbp_is_subscriptions_active() ) return; $defaults = array ( 'subscribe' => __( 'Subscribe', 'bbpress' ), 'unsubscribe' => __( 'Unsubscribe', 'bbpress' ), 'user_id' => 0, 'topic_id' => 0, 'before' => ' | ', 'after' => '' ); $args = wp_parse_args( $args, $defaults ); extract( $args ); // Try to get a user_id if ( !$user_id = bbp_get_user_id( $user_id, true, true ) ) return false; // No link if you can't edit yourself if ( !current_user_can( 'edit_user', (int) $user_id ) ) return false; // No link if not viewing a topic if ( !$topic_id = bbp_get_topic_id( $topic_id ) ) return false; // Decine which link to show if ( $is_subscribed = bbp_is_user_subscribed( $user_id, $topic_id ) ) { $text = $unsubscribe; $query_args = array( 'action' => 'bbp_unsubscribe', 'topic_id' => $topic_id ); } else { $text = $subscribe; $query_args = array( 'action' => 'bbp_subscribe', 'topic_id' => $topic_id ); } // Create the link based where the user is and if the user is subscribed already if ( bbp_is_subscriptions() ) $permalink = bbp_get_subscriptions_permalink( $user_id ); elseif ( is_singular( bbp_get_topic_post_type() ) ) $permalink = bbp_get_topic_permalink( $topic_id ); elseif ( bbp_is_query_name( 'bbp_single_topic' ) ) $permalink = get_permalink(); $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-subscription_' . $topic_id ) ); $is_subscribed = $is_subscribed ? 'is-subscribed' : ''; $html = '' . $before . '' . $text . '' . $after . ''; // Return the link return apply_filters( 'bbp_get_user_subscribe_link', $html, $args, $user_id, $topic_id ); } /** Edit User *****************************************************************/ /** * Edit profile success message * * @since bbPress (r2688) * * @uses bbp_is_single_user() To check if it's the profile page * @uses bbp_is_single_user_edit() To check if it's the profile edit page */ function bbp_notice_edit_user_success() { if ( isset( $_GET['updated'] ) && ( bbp_is_single_user() || bbp_is_single_user_edit() ) ) : ?>