/bp-activity/bp-activity-cssjs.php

  1. <?php 
  2. /** 
  3. * Activity component CSS/JS 
  4. * 
  5. * @package BuddyPress 
  6. * @subpackage ActivityScripts 
  7. * @since 1.0.0 
  8. */ 
  9.  
  10. // Exit if accessed directly. 
  11. defined( 'ABSPATH' ) || exit; 
  12.  
  13. /** 
  14. * Enqueue @mentions JS. 
  15. * 
  16. * @since 2.1.0 
  17. */ 
  18. function bp_activity_mentions_script() { 
  19. if ( ! bp_activity_maybe_load_mentions_scripts() ) { 
  20. return; 
  21.  
  22. // Special handling for New/Edit screens in wp-admin. 
  23. if ( is_admin() ) { 
  24. if ( 
  25. ! get_current_screen() || 
  26. ! in_array( get_current_screen()->base, array( 'page', 'post' ) ) || 
  27. ! post_type_supports( get_current_screen()->post_type, 'editor' ) ) { 
  28. return; 
  29.  
  30.  
  31. $min = bp_core_get_minified_asset_suffix(); 
  32.  
  33. wp_enqueue_script( 'bp-mentions', buddypress()->plugin_url . "bp-activity/js/mentions{$min}.js", array( 'jquery', 'jquery-atwho' ), bp_get_version(), true ); 
  34. wp_enqueue_style( 'bp-mentions-css', buddypress()->plugin_url . "bp-activity/css/mentions{$min}.css", array(), bp_get_version() ); 
  35.  
  36. wp_style_add_data( 'bp-mentions-css', 'rtl', true ); 
  37. if ( $min ) { 
  38. wp_style_add_data( 'bp-mentions-css', 'suffix', $min ); 
  39.  
  40. // If the script has been enqueued, let's attach our mentions TinyMCE init callback. 
  41. add_filter( 'tiny_mce_before_init', 'bp_add_mentions_on_tinymce_init', 10, 2 ); 
  42.  
  43. /** 
  44. * Fires at the end of the Activity Mentions script. 
  45. * 
  46. * This is the hook where BP components can add their own prefetched results 
  47. * friends to the page for quicker @mentions lookups. 
  48. * 
  49. * @since 2.1.0 
  50. */ 
  51. do_action( 'bp_activity_mentions_prime_results' ); 
  52. add_action( 'bp_enqueue_scripts', 'bp_activity_mentions_script' ); 
  53. add_action( 'bp_admin_enqueue_scripts', 'bp_activity_mentions_script' ); 
  54.  
  55. /** 
  56. * Bind the mentions listener to a wp_editor instance when TinyMCE initializes. 
  57. * 
  58. * @since 2.3.3 
  59. * 
  60. * @param array $settings An array with TinyMCE config. 
  61. * @param string $editor_id Unique editor identifier, e.g. 'content'. 
  62. * @return array $mceInit An array with TinyMCE config. 
  63. */ 
  64. function bp_add_mentions_on_tinymce_init( $settings, $editor_id ) { 
  65. // We only apply the mentions init to the visual post editor in the WP dashboard. 
  66. if ( 'content' === $editor_id ) { 
  67. $settings['init_instance_callback'] = 'window.bp.mentions.tinyMCEinit'; 
  68.  
  69. return $settings; 
.