/** * Enqueue @mentions JS. * * @since 2.1.0 */ function bp_activity_mentions_script() { if (!bp_activity_maybe_load_mentions_scripts()) { return; } // Special handling for New/Edit screens in wp-admin. if (is_admin()) { if (!get_current_screen() || !in_array(get_current_screen()->base, array('page', 'post')) || !post_type_supports(get_current_screen()->post_type, 'editor')) { return; } } $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script('bp-mentions', buddypress()->plugin_url . "bp-activity/js/mentions{$min}.js", array('jquery', 'jquery-atwho'), bp_get_version(), true); wp_enqueue_style('bp-mentions-css', buddypress()->plugin_url . "bp-activity/css/mentions{$min}.css", array(), bp_get_version()); wp_style_add_data('bp-mentions-css', 'rtl', true); if ($min) { wp_style_add_data('bp-mentions-css', 'suffix', $min); } // If the script has been enqueued, let's attach our mentions TinyMCE init callback. add_filter('tiny_mce_before_init', 'bp_add_mentions_on_tinymce_init', 10, 2); /** * Fires at the end of the Activity Mentions script. * * This is the hook where BP components can add their own prefetched results * friends to the page for quicker @mentions lookups. * * @since 2.1.0 */ do_action('bp_activity_mentions_prime_results'); }
/** * Enqueue @mentions JS. * * @since BuddyPress (2.1) */ function bp_activity_mentions_script() { if (!bp_activity_maybe_load_mentions_scripts()) { return; } // Special handling for New/Edit screens in wp-admin if (is_admin()) { if (!get_current_screen() || !in_array(get_current_screen()->base, array('page', 'post')) || !post_type_supports(get_current_screen()->post_type, 'editor')) { return; } } $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script('bp-mentions', buddypress()->plugin_url . "bp-activity/js/mentions{$min}.js", array('jquery', 'jquery-atwho'), bp_get_version(), true); wp_enqueue_style('bp-mentions-css', buddypress()->plugin_url . "bp-activity/css/mentions{$min}.css", array(), bp_get_version()); wp_style_add_data('bp-mentions-css', 'rtl', true); if ($min) { wp_style_add_data('bp-mentions-css', 'suffix', $min); } // Print a list of the current user's friends to the page for quicker @mentions lookups. do_action('bp_activity_mentions_prime_results'); }
/** * Used by the Activity component's @mentions to print a JSON list of the current user's friends. * * This is intended to speed up @mentions lookups for a majority of use cases. * * @see bp_activity_mentions_script() */ function bp_friends_prime_mentions_results() { if (!bp_activity_maybe_load_mentions_scripts()) { return; } $friends_query = array('count_total' => '', 'populate_extras' => false, 'type' => 'alphabetical', 'user_id' => get_current_user_id()); $friends_query = new BP_User_Query($friends_query); $results = array(); foreach ($friends_query->results as $user) { $result = new stdClass(); $result->ID = $user->user_nicename; $result->image = bp_core_fetch_avatar(array('html' => false, 'item_id' => $user->ID)); $result->name = bp_core_get_user_displayname($user->ID); $results[] = $result; } wp_localize_script('bp-mentions', 'BP_Suggestions', array('friends' => $results)); }
/** * Set up a list of members the current user is following for at-mention use. * * This is intended to speed up at-mention lookups for a majority of use cases. * * @since 1.3.0 * * @see bp_activity_mentions_script() */ function bp_follow_prime_mentions_results() { if (!bp_activity_maybe_load_mentions_scripts()) { return; } // Bail out if the site has a ton of users. if (is_multisite() && wp_is_large_network('users')) { return; } $following = bp_follow_get_following(array('user_id' => bp_loggedin_user_id())); if (empty($following)) { return; } $followers_query = new BP_User_Query(array('count_total' => '', 'populate_extras' => false, 'type' => 'alphabetical', 'include' => $following)); $results = array(); foreach ($followers_query->results as $user) { $result = new stdClass(); $result->ID = $user->user_nicename; $result->image = bp_core_fetch_avatar(array('html' => false, 'item_id' => $user->ID)); $result->name = bp_core_get_user_displayname($user->ID); $results[] = $result; } wp_localize_script('bp-mentions', 'BP_Suggestions', array('friends' => $results)); }
/** * Used by the Activity component's @mentions to print a JSON list of the current user's friends. * * This is intended to speed up @mentions lookups for a majority of use cases. * * @since 2.1.0 * * @see bp_activity_mentions_script() */ function bp_friends_prime_mentions_results() { if (!bp_activity_maybe_load_mentions_scripts()) { return; } // Bail out if the site has a ton of users. if (is_multisite() && wp_is_large_network('users')) { return; } if (friends_get_total_friend_count(get_current_user_id()) > 150) { return; } $friends_query = array('count_total' => '', 'populate_extras' => false, 'type' => 'alphabetical', 'user_id' => get_current_user_id()); $friends_query = new BP_User_Query($friends_query); $results = array(); foreach ($friends_query->results as $user) { $result = new stdClass(); $result->ID = $user->user_nicename; $result->image = bp_core_fetch_avatar(array('html' => false, 'item_id' => $user->ID)); if (!empty($user->display_name) && !bp_disable_profile_sync()) { $result->name = $user->display_name; } else { $result->name = bp_core_get_user_displayname($user->ID); } $results[] = $result; } wp_localize_script('bp-mentions', 'BP_Suggestions', array('friends' => $results)); }