bp_core_register_common_scripts

Register scripts commonly used by BuddyPress.

Description

bp_core_register_common_scripts(); 

Usage

  1. if ( !function_exists( 'bp_core_register_common_scripts' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-cssjs.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_core_register_common_scripts(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-cssjs.php  
  1. function bp_core_register_common_scripts() { 
  2. $url =buddypress)->plugin_url . 'bp-core/js/'; 
  3.  
  4. /** 
  5. * Moment.js locale. 
  6. * Try to map current WordPress locale to a moment.js locale file for loading. 
  7. * eg. French (France) locale for WP is fr_FR. Here, we try to find fr-fr.js 
  8. * (this file doesn't exist). 
  9. */ 
  10. $locale = sanitize_file_name( strtolower( get_locale() ) ); 
  11. $locale = str_replace( '_', '-', $locale ); 
  12. if ( file_exists(buddypress)->core->path . "bp-core/js/vendor/moment-js/locale/{$locale}{$min}.js" ) ) { 
  13. $moment_locale_url = $url . "vendor/moment-js/locale/{$locale}{$min}.js"; 
  14.  
  15. /** 
  16. * Try to find the short-form locale. 
  17. * eg. French (France) locale for WP is fr_FR. Here, we try to find fr.js 
  18. * (this exists). 
  19. */ 
  20. } else { 
  21. $locale = substr( $locale, 0, strpos( $locale, '-' ) ); 
  22. if ( file_exists(buddypress)->core->path . "bp-core/js/vendor/moment-js/locale/{$locale}{$min}.js" ) ) { 
  23. $moment_locale_url = $url . "vendor/moment-js/locale/{$locale}{$min}.js"; 
  24.  
  25. // Set up default scripts to register. 
  26. $scripts = array( 
  27. // Legacy. 
  28. 'bp-confirm' => array( 'file' => "{$url}confirm{$min}.js", 'dependencies' => array( 'jquery' ), 'footer' => false ),  
  29. 'bp-widget-members' => array( 'file' => "{$url}widget-members{$min}.js", 'dependencies' => array( 'jquery' ), 'footer' => false ),  
  30. 'bp-jquery-query' => array( 'file' => "{$url}jquery-query{$min}.js", 'dependencies' => array( 'jquery' ), 'footer' => false ),  
  31. 'bp-jquery-cookie' => array( 'file' => "{$url}vendor/jquery-cookie{$min}.js", 'dependencies' => array( 'jquery' ), 'footer' => false ),  
  32. 'bp-jquery-scroll-to' => array( 'file' => "{$url}vendor/jquery-scroll-to{$min}.js", 'dependencies' => array( 'jquery' ), 'footer' => false ),  
  33.  
  34. // Version 2.1. 
  35. 'jquery-caret' => array( 'file' => "{$url}vendor/jquery.caret{$min}.js", 'dependencies' => array( 'jquery' ), 'footer' => true ),  
  36. 'jquery-atwho' => array( 'file' => "{$url}vendor/jquery.atwho{$min}.js", 'dependencies' => array( 'jquery', 'jquery-caret' ), 'footer' => true ),  
  37.  
  38. // Version 2.3. 
  39. 'bp-plupload' => array( 'file' => "{$url}bp-plupload{$min}.js", 'dependencies' => array( 'plupload', 'jquery', 'json2', 'wp-backbone' ), 'footer' => true ),  
  40. 'bp-avatar' => array( 'file' => "{$url}avatar{$min}.js", 'dependencies' => array( 'jcrop' ), 'footer' => true ),  
  41. 'bp-webcam' => array( 'file' => "{$url}webcam{$min}.js", 'dependencies' => array( 'bp-avatar' ), 'footer' => true ),  
  42.  
  43. // Version 2.4. 
  44. 'bp-cover-image' => array( 'file' => "{$url}cover-image{$min}.js", 'dependencies' => array(), 'footer' => true ),  
  45.  
  46. // Version 2.7. 
  47. 'bp-moment' => array( 'file' => "{$url}vendor/moment-js/moment{$min}.js", 'dependencies' => array(), 'footer' => true ),  
  48. 'bp-livestamp' => array( 'file' => "{$url}vendor/livestamp{$min}.js", 'dependencies' => array( 'jquery', 'bp-moment' ), 'footer' => true ),  
  49. ); 
  50.  
  51. // Version 2.7 - Add Moment.js locale to our $scripts array if we found one. 
  52. if ( isset( $moment_locale_url ) ) { 
  53. $scripts['bp-moment-locale'] = array( 'file' => esc_url( $moment_locale_url ), 'dependencies' => array( 'bp-moment' ), 'footer' => true ); 
  54.  
  55. /** 
  56. * Filters the BuddyPress Core javascript files to register. 
  57. * Default handles include 'bp-confirm', 'bp-widget-members',  
  58. * 'bp-jquery-query', 'bp-jquery-cookie', and 'bp-jquery-scroll-to'. 
  59. * @since 2.1.0 'jquery-caret', 'jquery-atwho' added. 
  60. * @since 2.3.0 'bp-plupload', 'bp-avatar', 'bp-webcam' added. 
  61. * @since 2.4.0 'bp-cover-image' added. 
  62. * @since 2.7.0 'bp-moment', 'bp-livestamp' added. 
  63. * 'bp-moment-locale' is added conditionally if a moment.js locale file is found. 
  64. * @param array $value Array of javascript file information to register. 
  65. */ 
  66.  
  67.  
  68. $version = bp_get_version(); 
  69. foreach ( $scripts as $id => $script ) { 
  70. wp_register_script( $id, $script['file'], $script['dependencies'], $version, $script['footer'] );