/** * Create a button. * * @since 1.0.0 * * @param int $muted_id The ID of the muted user. * @return string */ function bp_mute_get_button($muted_id) { global $bp, $members_template; if (!$muted_id) { return; } $obj = new Mute($muted_id, bp_loggedin_user_id()); $action = $obj->id ? '/stop/' : '/start/'; $url = bp_core_get_user_domain($muted_id) . $bp->mute->slug . $action; $button = array('id' => $obj->id ? 'muted' : 'unmuted', 'link_class' => $obj->id ? 'muted' : 'unmuted', 'link_id' => $obj->id ? 'mute-' . $muted_id : 'mute-' . $muted_id, 'link_title' => $obj->id ? _x('Unmute', 'Button', 'buddypress-mute') : _x('Mute', 'Button', 'buddypress-mute'), 'link_text' => $obj->id ? _x('Unmute', 'Button', 'buddypress-mute') : _x('Mute', 'Button', 'buddypress-mute'), 'link_href' => $obj->id ? wp_nonce_url($url, 'unmute') : wp_nonce_url($url, 'mute'), 'wrapper_class' => 'mute-button', 'component' => 'mute', 'wrapper_id' => 'mute-button-' . $muted_id, 'must_be_logged_in' => true, 'block_self' => true); return bp_get_button($button); }
/** * Return button for sending a public message * * @since 1.2.0 * * @param array $args Optional * * @uses bp_get_send_public_message_link() * @uses nxt_parse_args() * @uses bp_get_button() * @uses apply_filters() To call the 'bp_get_send_public_message_button' hook * * @return string The button for sending a public message */ function bp_get_send_public_message_button($args = '') { $defaults = array('id' => 'public_message', 'component' => 'activity', 'must_be_logged_in' => true, 'block_self' => true, 'wrapper_id' => 'post-mention', 'link_href' => bp_get_send_public_message_link(), 'link_title' => __('Send a public message on your activity stream.', 'buddypress'), 'link_text' => __('Public Message', 'buddypress'), 'link_class' => 'activity-button mention'); $button = nxt_parse_args($args, $defaults); // Filter and return the HTML button return bp_get_button(apply_filters('bp_get_send_public_message_button', $button)); }
/** * bp_get_blogs_visit_blog_button() * * Return button for visiting a blog in a loop * * @param array $args Custom button properties * @return string */ function bp_get_blogs_visit_blog_button( $args = '' ) { $defaults = array( 'id' => 'visit_blog', 'component' => 'blogs', 'must_be_logged_in' => false, 'block_self' => false, 'wrapper_class' => 'blog-button visit', 'link_href' => bp_get_blog_permalink(), 'link_class' => 'visit', 'link_text' => __( 'Visit Blog', 'buddypress' ), 'link_title' => __( 'Visit Blog', 'buddypress' ), ); $button = wp_parse_args( $args, $defaults ); // Filter and return the HTML button return bp_get_button( apply_filters( 'bp_get_blogs_visit_blog_button', $button ) ); }
/** * Returns a compliment button for a given user. * * @since 0.0.1 * @package BuddyPress_Compliments * * @global object $bp BuddyPress instance. * @global object $members_template Members template object. * @param array|string $args { * Attributes of the $args. * * @type int $receiver_id Compliment receiver ID. * @type int $sender_id Compliment sender ID. * @type string $link_text Link text. * @type string $link_title Link title. * @type string $wrapper_class Link wrapper class. * @type string $link_class Link class. Default "compliments-popup". * @type string $wrapper Link wrapper. Default "div". * * } * @return string Button HTML. */ function bp_compliments_get_add_compliment_button($args = '') { global $bp, $members_template; $r = wp_parse_args($args, array('receiver_id' => bp_displayed_user_id(), 'sender_id' => bp_loggedin_user_id(), 'link_text' => '', 'link_title' => '', 'wrapper_class' => '', 'link_class' => 'compliments-popup', 'wrapper' => 'div')); if (!$r['receiver_id'] || !$r['sender_id']) { return false; } // if the logged-in user is the receiver, use already-queried variables if (bp_loggedin_user_id() && $r['receiver_id'] == bp_loggedin_user_id()) { $receiver_domain = bp_loggedin_user_domain(); $receiver_fullname = bp_get_loggedin_user_fullname(); // else we do a lookup for the user domain and display name of the receiver } else { $receiver_domain = bp_core_get_user_domain($r['receiver_id']); $receiver_fullname = bp_core_get_user_displayname($r['receiver_id']); } // setup some variables $id = 'compliments'; $action = 'start'; $class = 'compliments'; /** * Filters the compliment receiver name. * * @since 0.0.1 * @package BuddyPress_Compliments * * @param string $receiver_fullname Receiver full name. * @param int $r['receiver_id'] Receiver ID. */ $link_text = sprintf(sprintf(__('Send %s', 'bp-compliments'), BP_COMP_SINGULAR_NAME), apply_filters('bp_compliments_receiver_name', bp_get_user_firstname($receiver_fullname), $r['receiver_id'])); if (empty($r['link_text'])) { $r['link_text'] = $link_text; } $wrapper_class = 'compliments-button ' . $id; if (!empty($r['wrapper_class'])) { $wrapper_class .= ' ' . esc_attr($r['wrapper_class']); } $link_class = $class; if (!empty($r['link_class'])) { $link_class .= ' ' . esc_attr($r['link_class']); } // make sure we can view the button if a user is on their own page $block_self = empty($members_template->member) ? true : false; // if we're using AJAX and a user is on their own profile, we need to set // block_self to false so the button shows up if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' && bp_is_my_profile()) { $block_self = false; } // setup the button arguments $button = array('id' => $id, 'component' => 'compliments', 'must_be_logged_in' => true, 'block_self' => $block_self, 'wrapper_class' => $wrapper_class, 'wrapper_id' => 'compliments-button-' . (int) $r['receiver_id'], 'link_href' => wp_nonce_url($receiver_domain . $bp->compliments->compliments->slug . '/' . $action . '/', $action . '_compliments'), 'link_text' => esc_attr($r['link_text']), 'link_title' => esc_attr($r['link_title']), 'link_id' => $class . '-' . (int) $r['receiver_id'], 'link_class' => $link_class, 'wrapper' => !empty($r['wrapper']) ? esc_attr($r['wrapper']) : false); // Filter and return the HTML button /** * Filters the compliment button. * * @since 0.0.1 * @package BuddyPress_Compliments * * @param string $button Button HTML. * @param int $r['receiver_id'] Receiver ID. * @param int $r['sender_id'] Sender ID. */ return bp_get_button(apply_filters('bp_compliments_get_add_compliment_button', $button, $r['receiver_id'], $r['sender_id'])); }
/** * Builds the reshare button * * @package BP Reshare * @since 1.0 * * @global BP_Activity_Template $activities_template * @uses buddyreshare_activity_can_reshare() to check if the activity can be reshared * @uses buddyreshare_activity_get_button_class() to get button's classe * @uses buddyreshare_activity_get_reshares_count() to get the number of reshares * @uses bp_get_activity_id() to get activity id * @uses buddyreshare_get_component_id() to get component's id * @uses buddyreshare_activity_get_action_url() to get action url * @uses buddyreshare_activity_get_id_to_reshare() to get the activity id to reshare * @uses buddyreshare_activity_get_button_title() to get the button title * @uses bp_get_button() to build the button * @return string reshare button */ function buddyreshare_activity_get_button() { global $activities_template; if (!buddyreshare_activity_can_reshare()) { return false; } $caption = apply_filters('buddyreshare_activity_get_button_caption', buddyreshare_activity_get_button_title()); $link_text = '<span class="' . buddyreshare_activity_get_button_class() . '">' . $caption . '</span><span class="rs-count">' . buddyreshare_activity_get_reshares_count() . '</span>'; $button = array('id' => 'reshare-container-' . bp_get_activity_id(), 'component' => buddyreshare_get_component_id(), 'must_be_logged_in' => true, 'wrapper' => false, 'block_self' => false, 'link_id' => 'bp-reshare-' . bp_get_activity_id(), 'link_href' => buddyreshare_activity_get_action_url(), 'link_rel' => buddyreshare_activity_get_id_to_reshare(), 'link_title' => buddyreshare_activity_get_button_title(), 'link_text' => $link_text, 'link_class' => 'button reshare-button bp-secondary-action'); // Filter and return the HTML button return bp_get_button(apply_filters('buddyreshare_activity_get_button', $button)); }
/** * Get the Create a Group button. * * @since 2.0.0 * * @return string */ function bp_get_group_create_button() { if (!is_user_logged_in()) { return false; } if (!bp_user_can_create_groups()) { return false; } $button_args = array('id' => 'create_group', 'component' => 'groups', 'link_text' => __('Create a Group', 'buddypress'), 'link_title' => __('Create a Group', 'buddypress'), 'link_class' => 'group-create no-ajax', 'link_href' => trailingslashit(bp_get_groups_directory_permalink() . 'create'), 'wrapper' => false, 'block_self' => false); /** * Filters the HTML button for creating a group. * * @since 2.0.0 * * @param string $button HTML button for creating a group. */ return bp_get_button(apply_filters('bp_get_group_create_button', $button_args)); }
/** * AJAX callback when clicking on the "Unfollow" button to unfollow a user. * * @uses check_admin_referer() Checks to make sure the WP security nonce matches. * @uses bp_follow_stop_following() Stops a user following another user. * @uses bp_follow_is_following() Checks to see if a user is following another user already. */ function bp_follow_ajax_action_stop() { check_admin_referer('stop_following'); $link_class = !empty($_POST['link_class']) ? str_replace('unfollow ', '', $_POST['link_class']) : false; // successful unfollow if (bp_follow_stop_following(array('leader_id' => $_POST['uid'], 'follower_id' => bp_loggedin_user_id()))) { // output follow button $output = bp_follow_get_add_follow_button(array('leader_id' => $_POST['uid'], 'follower_id' => bp_loggedin_user_id(), 'wrapper' => false, 'link_class' => $link_class)); // failed unfollow } else { // output fallback invalid button $args = array('id' => 'invalid', 'link_href' => 'javascript:;', 'component' => 'follow', 'wrapper' => false, 'link_class' => $link_class); if (!bp_follow_is_following(array('leader_id' => $_POST['uid'], 'follower_id' => bp_loggedin_user_id()))) { $output = bp_get_button(array_merge(array('link_text' => __('Not following', 'bp-follow')), $args)); } else { $output = bp_get_button(array_merge(array('link_text' => __('Error unfollowing user', 'bp-follow')), $args)); } } echo $output; exit; }
/** * Create and output a button. * * @since 1.2.6 * * @see bp_get_button() * * @param array|string $args See {@link BP_Button}. */ function bp_button($args = '') { echo bp_get_button($args); }
function bp_get_send_message_button() { return apply_filters( 'bp_get_send_message_button', bp_get_button( array( 'id' => 'private_message', 'component' => 'messages', 'must_be_logged_in' => true, 'block_self' => true, 'wrapper_id' => 'send-private-message', 'link_href' => bp_get_send_private_message_link(), 'link_class' => 'send-message', 'link_title' => __( 'Send a private message to this user.', 'buddypress' ), 'link_text' => __( 'Send Private Message', 'buddypress' ) ) ) ); }
function event_espresso_get_add_register_button($event_id = 0) { global $bp, $events_template, $org_options, $wpdb; if ($event_id == 0) { return false; } $is_active = event_espresso_get_is_active($event_id); switch ($is_active['status']) { case 'EXPIRED': //only show the event description. $html = _e('<p class="expired_event">This event has passed.</p>', 'event_espresso'); return $html; break; case 'REGISTRATION_CLOSED': //only show the event description. // if todays date is after $reg_end_date $html = _e('<p class="expired_event">We are sorry but registration for this event is now closed.</p>', 'event_espresso'); return $html; break; case 'REGISTRATION_NOT_OPEN': //only show the event description. // if todays date is after $reg_end_date // if todays date is prior to $reg_start_date $html = _e('<p class="expired_event">We are sorry but this event is not yet open for registration.</p>', 'event_espresso'); return $html; break; } $event = $wpdb->get_row("select * from " . EVENTS_DETAIL_TABLE . " WHERE id = {$event_id} "); $externalURL = $event->externalURL; $registration_url = $externalURL != '' ? $externalURL : home_url() . '/?page_id=' . $org_options['event_page_id'] . '®event_action=register&event_id=' . $event_id; $button = array('id' => 'register', 'component' => 'events', 'must_be_logged_in' => false, 'block_self' => false, 'wrapper_class' => 'register-button', 'wrapper_id' => 'register-button-' . $event_id, 'link_class' => 'requested', 'link_href' => $registration_url, 'link_text' => __('Register For Event', 'buddypress'), 'link_title' => __('Register For Event', 'buddypress')); // Filter and return the HTML button return bp_get_button(apply_filters('event_espresso_get_add_register_button', $button)); }
/** * Adds a 'Switch To' link to each member's profile page and profile listings in BuddyPress. * * @return null */ public function action_bp_button() { global $bp, $members_template; if (!empty($members_template) and empty($bp->displayed_user->id)) { $id = absint($members_template->member->id); } else { $id = absint($bp->displayed_user->id); } if (!($link = self::maybe_switch_url($id))) { return; } $link = add_query_arg(array('redirect_to' => urlencode(bp_core_get_user_domain($id))), $link); # Workaround for https://buddypress.trac.wordpress.org/ticket/4212 $components = array_keys($bp->active_components); if (!empty($components)) { $component = reset($components); } else { $component = 'core'; } echo bp_get_button(array('id' => 'user_switching', 'component' => $component, 'link_href' => $link, 'link_text' => __('Switch To', 'user-switching'))); }
/** * Returns a follow / unfollow button for a given user depending on the follower status. * * Checks to see if the follower is already following the leader. If is following, returns * "Stop following" button; if not following, returns "Follow" button. * * @param array $args { * Array of arguments. * @type int $leader_id The user ID of the person we want to follow. * @type int $follower_id The user ID initiating the follow request. * @type string $link_text The anchor text for the link. * @type string $link_title The title attribute for the link. * @type string $wrapper_class CSS class for the wrapper container. * @type string $link_class CSS class for the link. * @type string $wrapper The element for the wrapper container. Defaults to 'div'. * } * @return mixed String of the button on success. Boolean false on failure. * @uses bp_get_button() Renders a button using the BP Button API * @author r-a-y * @since 1.1 */ function bp_follow_get_add_follow_button($args = '') { global $bp, $members_template; $r = wp_parse_args($args, array('leader_id' => bp_displayed_user_id(), 'follower_id' => bp_loggedin_user_id(), 'link_text' => '', 'link_title' => '', 'wrapper_class' => '', 'link_class' => '', 'wrapper' => 'div')); if (!$r['leader_id'] || !$r['follower_id']) { return false; } // if we're checking during a members loop, then follow status is already // queried via bp_follow_inject_member_follow_status() if (!empty($members_template->in_the_loop) && $r['follower_id'] == bp_loggedin_user_id() && $r['leader_id'] == bp_get_member_user_id()) { $is_following = $members_template->member->is_following; // else we manually query the follow status } else { $is_following = bp_follow_is_following(array('leader_id' => $r['leader_id'], 'follower_id' => $r['follower_id'])); } // if the logged-in user is the leader, use already-queried variables if (bp_loggedin_user_id() && $r['leader_id'] == bp_loggedin_user_id()) { $leader_domain = bp_loggedin_user_domain(); $leader_fullname = bp_get_loggedin_user_fullname(); // else we do a lookup for the user domain and display name of the leader } else { $leader_domain = bp_core_get_user_domain($r['leader_id']); $leader_fullname = bp_core_get_user_displayname($r['leader_id']); } // setup some variables if ($is_following) { $id = 'following'; $action = 'stop'; $class = 'unfollow'; $link_text = sprintf(_x('Unfollow', 'Button', 'bp-follow'), apply_filters('bp_follow_leader_name', bp_get_user_firstname($leader_fullname), $r['leader_id'])); if (empty($r['link_text'])) { $r['link_text'] = $link_text; } } else { $id = 'not-following'; $action = 'start'; $class = 'follow'; $link_text = sprintf(_x('Follow', 'Button', 'bp-follow'), apply_filters('bp_follow_leader_name', bp_get_user_firstname($leader_fullname), $r['leader_id'])); if (empty($r['link_text'])) { $r['link_text'] = $link_text; } } $wrapper_class = 'follow-button ' . $id; if (!empty($r['wrapper_class'])) { $wrapper_class .= ' ' . esc_attr($r['wrapper_class']); } $link_class = $class; if (!empty($r['link_class'])) { $link_class .= ' ' . esc_attr($r['link_class']); } // make sure we can view the button if a user is on their own page $block_self = empty($members_template->member) ? true : false; // if we're using AJAX and a user is on their own profile, we need to set // block_self to false so the button shows up if (bp_follow_is_doing_ajax() && bp_is_my_profile()) { $block_self = false; } // setup the button arguments $button = array('id' => $id, 'component' => 'follow', 'must_be_logged_in' => true, 'block_self' => $block_self, 'wrapper_class' => $wrapper_class, 'wrapper_id' => 'follow-button-' . (int) $r['leader_id'], 'link_href' => wp_nonce_url($leader_domain . $bp->follow->followers->slug . '/' . $action . '/', $action . '_following'), 'link_text' => esc_attr($r['link_text']), 'link_title' => esc_attr($r['link_title']), 'link_id' => $class . '-' . (int) $r['leader_id'], 'link_class' => $link_class, 'wrapper' => !empty($r['wrapper']) ? esc_attr($r['wrapper']) : false); // Filter and return the HTML button return bp_get_button(apply_filters('bp_follow_get_add_follow_button', $button, $r['leader_id'], $r['follower_id'])); }
/** * bp_get_send_public_message_button( $args ) * * Return button for sending a public message * * @param array $args * @return string */ function bp_get_send_public_message_button( $args = '' ) { $defaults = array( 'id' => 'public_message', 'component' => 'activity', 'must_be_logged_in' => true, 'block_self' => true, 'wrapper_id' => 'post-mention', 'link_href' => bp_get_send_public_message_link(), 'link_title' => __( 'Mention this user in a new public message, this will send the user a notification to get their attention.', 'buddypress' ), 'link_text' => __( 'Mention this User', 'buddypress' ) ); $button = wp_parse_args( $args, $defaults ); // Filter and return the HTML button return bp_get_button( apply_filters( 'bp_get_send_public_message_button', $button ) ); }
/** * Adds a 'Switch To' link to each member's profile page and profile listings in BuddyPress. */ public function action_bp_button() { global $bp, $members_template; if (!empty($members_template) && empty($bp->displayed_user->id)) { $user = get_userdata($members_template->member->id); } else { $user = get_userdata($bp->displayed_user->id); } if (!$user) { return; } if (!($link = self::maybe_switch_url($user))) { return; } $link = add_query_arg(array('redirect_to' => urlencode(bp_core_get_user_domain($user->ID))), $link); # Workaround for https://buddypress.trac.wordpress.org/ticket/4212 $components = array_keys($bp->active_components); if (!empty($components)) { $component = reset($components); } else { $component = 'core'; } // @codingStandardsIgnoreStart echo bp_get_button(array('id' => 'user_switching', 'component' => $component, 'link_href' => esc_url($link), 'link_text' => esc_html__('Switch To', 'user-switching'), 'wrapper_id' => 'user_switching_switch_to')); // @codingStandardsIgnoreEnd }
function bp_get_add_friend_button($potential_friend_id = 0, $friend_status = false) { global $bp, $friends_template; if (empty($potential_friend_id)) { $potential_friend_id = bp_get_potential_friend_id($potential_friend_id); } $is_friend = bp_is_friend($potential_friend_id); if (empty($is_friend)) { return false; } switch ($is_friend) { case 'pending': $button = array('id' => 'pending', 'component' => 'friends', 'must_be_logged_in' => true, 'block_self' => true, 'wrapper_class' => 'friendship-button pending', 'wrapper_id' => 'friendship-button-' . $potential_friend_id, 'link_href' => trailingslashit($bp->loggedin_user->domain . bp_get_friends_slug() . '/requests'), 'link_text' => __('Friendship Requested', 'buddypress'), 'link_title' => __('Friendship Requested', 'buddypress'), 'link_class' => 'friendship-button pending requested'); break; case 'is_friend': $button = array('id' => 'is_friend', 'component' => 'friends', 'must_be_logged_in' => true, 'block_self' => false, 'wrapper_class' => 'friendship-button is_friend', 'wrapper_id' => 'friendship-button-' . $potential_friend_id, 'link_href' => nxt_nonce_url($bp->loggedin_user->domain . bp_get_friends_slug() . '/remove-friend/' . $potential_friend_id . '/', 'friends_remove_friend'), 'link_text' => __('Cancel Friendship', 'buddypress'), 'link_title' => __('Cancel Friendship', 'buddypress'), 'link_id' => 'friend-' . $potential_friend_id, 'link_rel' => 'remove', 'link_class' => 'friendship-button is_friend remove'); break; default: $button = array('id' => 'not_friends', 'component' => 'friends', 'must_be_logged_in' => true, 'block_self' => true, 'wrapper_class' => 'friendship-button not_friends', 'wrapper_id' => 'friendship-button-' . $potential_friend_id, 'link_href' => nxt_nonce_url($bp->loggedin_user->domain . bp_get_friends_slug() . '/add-friend/' . $potential_friend_id . '/', 'friends_add_friend'), 'link_text' => __('Add Friend', 'buddypress'), 'link_title' => __('Add Friend', 'buddypress'), 'link_id' => 'friend-' . $potential_friend_id, 'link_rel' => 'add', 'link_class' => 'friendship-button not_friends add'); break; } // Filter and return the HTML button return bp_get_button(apply_filters('bp_get_add_friend_button', $button)); }
/** * Return button for visiting a blog in a loop. * * @see BP_Button for a complete description of arguments and return * value. * * @param array|string $args { * Arguments are listed below, with their default values. For a * complete description of arguments, see {@link BP_Button}. * @type string $id Default: 'visit_blog'. * @type string $component Default: 'blogs'. * @type bool $must_be_logged_in Default: false. * @type bool $block_self Default: false. * @type string $wrapper_class Default: 'blog-button visit'. * @type string $link_href Permalink of the current blog in the loop. * @type string $link_class Default: 'blog-button visit'. * @type string $link_text Default: 'Visit Site'. * @type string $link_title Default: 'Visit Site'. * } * @return string The HTML for the Visit button. */ function bp_get_blogs_visit_blog_button($args = '') { $defaults = array('id' => 'visit_blog', 'component' => 'blogs', 'must_be_logged_in' => false, 'block_self' => false, 'wrapper_class' => 'blog-button visit', 'link_href' => bp_get_blog_permalink(), 'link_class' => 'blog-button visit', 'link_text' => __('Visit Site', 'buddypress'), 'link_title' => __('Visit Site', 'buddypress')); $button = wp_parse_args($args, $defaults); /** * Filters the button for visiting a blog in a loop. * * @since BuddyPress (1.2.10) * * @param array $button Array of arguments to be used for the button to visit a blog. */ return bp_get_button(apply_filters('bp_get_blogs_visit_blog_button', $button)); }
/** * Hook to insert the report user on user's profile * * @global type $bp */ function wangguard_bp_report_button_header() { global $bp; if (!$bp) { return; } $user_object = new WP_User($bp->displayed_user->id); if (empty($user_object->ID)) { return; } if (wangguard_is_admin($user_object)) { return; } echo bp_get_button(array('id' => 'wangguard_report_user', 'component' => 'members', 'must_be_logged_in' => true, 'block_self' => true, 'wrapper_id' => 'wangguard_report_user-button', 'link_href' => "javascript:void(0)", 'link_class' => 'wangguard-user-report wangguard-user-report-id-' . $user_object->ID, 'link_title' => __('Report user', 'wangguard'), 'link_text' => __('Report user', 'wangguard'))); }
/** * Generate the 'Private Message' button for member profile headers. * * @return string */ function bp_get_send_message_button() { // Note: 'bp_get_send_message_button' is a legacy filter. Use // 'bp_get_send_message_button_args' instead. See #4536. return apply_filters('bp_get_send_message_button', bp_get_button(apply_filters('bp_get_send_message_button_args', array('id' => 'private_message', 'component' => 'messages', 'must_be_logged_in' => true, 'block_self' => true, 'wrapper_id' => 'send-private-message', 'link_href' => bp_get_send_private_message_link(), 'link_title' => __('Send a private message to this user.', 'buddypress'), 'link_text' => __('Private Message', 'buddypress'), 'link_class' => 'send-message')))); }
/** * Adds a 'Switch To' link to each member's profile page and profile listings in BuddyPress. * * @return null */ function bp_button() { global $bp, $members_template; if (!empty($members_template)) { $id = absint($members_template->member->id); } else { $id = absint($bp->displayed_user->id); } if (current_user_can('switch_to_user', $id)) { # Workaround for https://buddypress.trac.wordpress.org/ticket/4212 $components = array_keys($bp->active_components); if (!empty($components)) { $component = reset($components); } else { $component = 'core'; } echo bp_get_button(array('id' => 'user_switching', 'component' => $component, 'link_href' => $this->switch_to_url($id), 'link_text' => __('Switch To', 'user_switching'))); } }
function bp_get_group_join_button($group = false) { global $bp, $groups_template; if (!$group) { $group =& $groups_template->group; } if (!is_user_logged_in() || bp_group_is_user_banned($group)) { return false; } // Group creation was not completed or status is unknown if (!$group->status) { return false; } // Already a member if ($group->is_member) { // Stop sole admins from abandoning their group $group_admins = groups_get_group_admins($group->id); if (1 == count($group_admins) && $group_admins[0]->user_id == bp_loggedin_user_id()) { return false; } $button = array('id' => 'leave_group', 'component' => 'groups', 'must_be_logged_in' => true, 'block_self' => false, 'wrapper_class' => 'group-button ' . $group->status, 'wrapper_id' => 'groupbutton-' . $group->id, 'link_href' => wp_nonce_url(bp_get_group_permalink($group) . 'leave-group', 'groups_leave_group'), 'link_text' => __('Leave Group', 'buddypress'), 'link_title' => __('Leave Group', 'buddypress'), 'link_class' => 'group-button leave-group'); // Not a member } else { // Show different buttons based on group status switch ($group->status) { case 'hidden': return false; break; case 'public': $button = array('id' => 'join_group', 'component' => 'groups', 'must_be_logged_in' => true, 'block_self' => false, 'wrapper_class' => 'group-button ' . $group->status, 'wrapper_id' => 'groupbutton-' . $group->id, 'link_href' => wp_nonce_url(bp_get_group_permalink($group) . 'join', 'groups_join_group'), 'link_text' => __('Join Group', 'buddypress'), 'link_title' => __('Join Group', 'buddypress'), 'link_class' => 'group-button join-group'); break; case 'private': // Member has not requested membership yet if (!bp_group_has_requested_membership($group)) { $button = array('id' => 'request_membership', 'component' => 'groups', 'must_be_logged_in' => true, 'block_self' => false, 'wrapper_class' => 'group-button ' . $group->status, 'wrapper_id' => 'groupbutton-' . $group->id, 'link_href' => wp_nonce_url(bp_get_group_permalink($group) . 'request-membership', 'groups_request_membership'), 'link_text' => __('Request Membership', 'buddypress'), 'link_title' => __('Request Membership', 'buddypress'), 'link_class' => 'group-button request-membership'); // Member has requested membership already } else { $button = array('id' => 'membership_requested', 'component' => 'groups', 'must_be_logged_in' => true, 'block_self' => false, 'wrapper_class' => 'group-button pending ' . $group->status, 'wrapper_id' => 'groupbutton-' . $group->id, 'link_href' => bp_get_group_permalink($group), 'link_text' => __('Request Sent', 'buddypress'), 'link_title' => __('Request Sent', 'buddypress'), 'link_class' => 'group-button pending membership-requested'); } break; } } // Filter and return the HTML button return bp_get_button(apply_filters('bp_get_group_join_button', $button)); }
/** * Return button for sending a public message (an @-mention). * * @since BuddyPress (1.2.0) * * @uses bp_get_send_public_message_link() * @uses wp_parse_args() * @uses bp_get_button() * @uses apply_filters() To call the 'bp_get_send_public_message_button' hook. * * @param array $args { * All arguments are optional. See {@link BP_Button} for complete * descriptions. * @type string $id Default: 'public_message'. * @type string $component Default: 'activity'. * @type bool $must_be_logged_in Default: true. * @type bool $block_self Default: true. * @type string $wrapper_id Default: 'post-mention'. * @type string $link_href Default: the public message link for * the current member in the loop. * @type string $link_title Default: 'Send a public message on your * activity stream.'. * @type string $link_text Default: 'Public Message'. * @type string $link_class Default: 'activity-button mention'. * } * @return string The button for sending a public message. */ function bp_get_send_public_message_button($args = '') { $r = bp_parse_args($args, array('id' => 'public_message', 'component' => 'activity', 'must_be_logged_in' => true, 'block_self' => true, 'wrapper_id' => 'post-mention', 'link_href' => bp_get_send_public_message_link(), 'link_title' => __('Send a public message on your activity stream.', 'buddypress'), 'link_text' => __('Public Message', 'buddypress'), 'link_class' => 'activity-button mention')); /** * Filters the public message button HTML. * * @since BuddyPress (1.2.10) * * @param array $r Array of arguments for the public message button HTML. */ return bp_get_button(apply_filters('bp_get_send_public_message_button', $r)); }
/** * Create the Add Friend button. * * @param int $potential_friend_id ID of the user to whom the button * applies. Default: value of {@link bp_get_potential_friend_id()}. * @param bool $friend_status Not currently used. * @return string HTML for the Add Friend button. */ function bp_get_add_friend_button($potential_friend_id = 0, $friend_status = false) { if (empty($potential_friend_id)) { $potential_friend_id = bp_get_potential_friend_id($potential_friend_id); } $is_friend = bp_is_friend($potential_friend_id); if (empty($is_friend)) { return false; } switch ($is_friend) { case 'pending': $button = array('id' => 'pending', 'component' => 'friends', 'must_be_logged_in' => true, 'block_self' => true, 'wrapper_class' => 'friendship-button pending_friend', 'wrapper_id' => 'friendship-button-' . $potential_friend_id, 'link_href' => wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $potential_friend_id . '/', 'friends_withdraw_friendship'), 'link_text' => __('Cancel Friendship Request', 'buddypress'), 'link_title' => __('Cancel Friendship Requested', 'buddypress'), 'link_id' => 'friend-' . $potential_friend_id, 'link_rel' => 'remove', 'link_class' => 'friendship-button pending_friend requested'); break; case 'awaiting_response': $button = array('id' => 'awaiting_response', 'component' => 'friends', 'must_be_logged_in' => true, 'block_self' => true, 'wrapper_class' => 'friendship-button awaiting_response_friend', 'wrapper_id' => 'friendship-button-' . $potential_friend_id, 'link_href' => bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/', 'link_text' => __('Friendship Requested', 'buddypress'), 'link_title' => __('Friendship Requested', 'buddypress'), 'link_id' => 'friend-' . $potential_friend_id, 'link_rel' => 'remove', 'link_class' => 'friendship-button awaiting_response_friend requested'); break; case 'is_friend': $button = array('id' => 'is_friend', 'component' => 'friends', 'must_be_logged_in' => true, 'block_self' => false, 'wrapper_class' => 'friendship-button is_friend', 'wrapper_id' => 'friendship-button-' . $potential_friend_id, 'link_href' => wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/remove-friend/' . $potential_friend_id . '/', 'friends_remove_friend'), 'link_text' => __('Cancel Friendship', 'buddypress'), 'link_title' => __('Cancel Friendship', 'buddypress'), 'link_id' => 'friend-' . $potential_friend_id, 'link_rel' => 'remove', 'link_class' => 'friendship-button is_friend remove'); break; default: $button = array('id' => 'not_friends', 'component' => 'friends', 'must_be_logged_in' => true, 'block_self' => true, 'wrapper_class' => 'friendship-button not_friends', 'wrapper_id' => 'friendship-button-' . $potential_friend_id, 'link_href' => wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $potential_friend_id . '/', 'friends_add_friend'), 'link_text' => __('Add Friend', 'buddypress'), 'link_title' => __('Add Friend', 'buddypress'), 'link_id' => 'friend-' . $potential_friend_id, 'link_rel' => 'add', 'link_class' => 'friendship-button not_friends add'); break; } /** * Filters the HTML for the add friend button. * * @since 1.1.0 * * @param string $button HTML markup for add friend button. */ return bp_get_button(apply_filters('bp_get_add_friend_button', $button)); }
/** * Get the Create a Group button. * * @since BuddyPress (2.0.0) * * @return string */ function bp_get_group_create_button() { if (!is_user_logged_in()) { return false; } if (!bp_user_can_create_groups()) { return false; } $button_args = array('id' => 'create_group', 'component' => 'groups', 'link_text' => __('Create a Group', 'buddypress'), 'link_title' => __('Create a Group', 'buddypress'), 'link_class' => 'button group-create bp-title-button', 'link_href' => trailingslashit(bp_get_root_domain()) . trailingslashit(bp_get_groups_root_slug()) . trailingslashit('create'), 'wrapper' => false); return bp_get_button(apply_filters('bp_get_group_create_button', $button_args)); }
/** * bp_button( $button ) * * Creates and outputs a button. * Args: div_id | div_class | a_href | a_title | a_id | a_class | a_rel | a_text * * @param array $button */ function bp_button( $button = '' ) { echo bp_get_button( $button ); }
/** * Static method to generate a follow blogs button. */ public static function get_button($args = '') { global $blogs_template; $r = wp_parse_args($args, array('leader_id' => !empty($blogs_template->in_the_loop) ? bp_get_blog_id() : get_current_blog_id(), 'follower_id' => bp_loggedin_user_id(), 'link_text' => '', 'link_title' => '', 'wrapper_class' => '', 'link_class' => '', 'wrapper' => 'div')); if (!$r['leader_id'] || !$r['follower_id']) { return false; } // if we're checking during a blog loop, then follow status is already // queried via bulk_inject_follow_blog_status() if (!empty($blogs_template->in_the_loop) && $r['follower_id'] == bp_loggedin_user_id() && $r['leader_id'] == bp_get_blog_id()) { $is_following = $blogs_template->blog->is_following; // else we manually query the follow status } else { $is_following = bp_follow_is_following(array('leader_id' => $r['leader_id'], 'follower_id' => $r['follower_id'], 'follow_type' => 'blogs')); } // setup some variables if ($is_following) { $id = 'following'; $action = 'unfollow'; $link_text = _x('Unfollow', 'Button', 'bp-follow'); if (empty($blogs_template->in_the_loop)) { $link_text = _x('Unfollow Site', 'Button', 'bp-follow'); } if (empty($r['link_text'])) { $r['link_text'] = $link_text; } } else { $id = 'not-following'; $action = 'follow'; $link_text = _x('Follow', 'Button', 'bp-follow'); if (empty($blogs_template->in_the_loop)) { $link_text = _x('Follow Site', 'Button', 'bp-follow'); } if (empty($r['link_text'])) { $r['link_text'] = $link_text; } } $wrapper_class = 'follow-button ' . $id; if (!empty($r['wrapper_class'])) { $wrapper_class .= ' ' . esc_attr($r['wrapper_class']); } $link_class = $action; if (!empty($r['link_class'])) { $link_class .= ' ' . esc_attr($r['link_class']); } // setup the button arguments $button = array('id' => $id, 'component' => 'follow', 'must_be_logged_in' => true, 'block_self' => false, 'wrapper_class' => $wrapper_class, 'wrapper_id' => 'follow-button-' . (int) $r['leader_id'], 'link_href' => wp_nonce_url(add_query_arg('blog_id', $r['leader_id'], home_url('/')), "bp_follow_blog_{$action}", "bpfb-{$action}"), 'link_text' => esc_attr($r['link_text']), 'link_title' => esc_attr($r['link_title']), 'link_id' => $action . '-' . (int) $r['leader_id'], 'link_class' => $link_class, 'wrapper' => !empty($r['wrapper']) ? esc_attr($r['wrapper']) : false); // Filter and return the HTML button return bp_get_button(apply_filters('bp_follow_blogs_get_follow_button', $button, $r, $is_following)); }