[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-activity/ -> bp-activity-cssjs.php (source)

   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  
  23      // Special handling for New/Edit screens in wp-admin.
  24      if ( is_admin() ) {
  25          if (
  26              ! get_current_screen() ||
  27              ! in_array( get_current_screen()->base, array( 'page', 'post' ) ) ||
  28              ! post_type_supports( get_current_screen()->post_type, 'editor' ) ) {
  29              return;
  30          }
  31      }
  32  
  33  
  34      $min = bp_core_get_minified_asset_suffix();
  35  
  36      wp_enqueue_script( 'bp-mentions', buddypress()->plugin_url . "bp-activity/js/mentions{$min}.js", array( 'jquery', 'jquery-atwho' ), bp_get_version(), true );
  37      wp_enqueue_style( 'bp-mentions-css', buddypress()->plugin_url . "bp-activity/css/mentions{$min}.css", array(), bp_get_version() );
  38  
  39      wp_style_add_data( 'bp-mentions-css', 'rtl', 'replace' );
  40      if ( $min ) {
  41          wp_style_add_data( 'bp-mentions-css', 'suffix', $min );
  42      }
  43  
  44      // If the script has been enqueued, let's attach our mentions TinyMCE init callback.
  45      add_filter( 'tiny_mce_before_init', 'bp_add_mentions_on_tinymce_init', 10, 2 );
  46  
  47      /**
  48       * Fires at the end of the Activity Mentions script.
  49       *
  50       * This is the hook where BP components can add their own prefetched results
  51       * friends to the page for quicker @mentions lookups.
  52       *
  53       * @since 2.1.0
  54       */
  55      do_action( 'bp_activity_mentions_prime_results' );
  56  }
  57  add_action( 'bp_enqueue_scripts', 'bp_activity_mentions_script' );
  58  add_action( 'bp_admin_enqueue_scripts', 'bp_activity_mentions_script' );
  59  
  60  /**
  61   * Bind the mentions listener to a wp_editor instance when TinyMCE initializes.
  62   *
  63   * @since 2.3.3
  64   *
  65   * @param array  $settings   An array with TinyMCE config.
  66   * @param string $editor_id Unique editor identifier, e.g. 'content'.
  67   * @return array  $mceInit   An array with TinyMCE config.
  68   */
  69  function bp_add_mentions_on_tinymce_init( $settings, $editor_id ) {
  70      // We only apply the mentions init to the visual post editor in the WP dashboard.
  71      if ( 'content' === $editor_id ) {
  72          $settings['init_instance_callback'] = 'window.bp.mentions.tinyMCEinit';
  73      }
  74  
  75      return $settings;
  76  }


Generated: Wed Nov 13 01:01:39 2019 Cross-referenced by PHPXref 0.7.1