[ Index ]

PHP Cross Reference of BackPress

title

Body

[close]

/includes/ -> functions.wp-scripts.php (source)

   1  <?php
   2  /**
   3   * BackPress script procedural API.
   4   *
   5   * @package BackPress
   6   * @since r16
   7   */
   8  
   9  /**
  10   * Prints script tags in document head.
  11   *
  12   * Called by admin-header.php and by wp_head hook. Since it is called by wp_head
  13   * on every page load, the function does not instantiate the WP_Scripts object
  14   * unless script names are explicitly passed. Does make use of already
  15   * instantiated $wp_scripts if present. Use provided wp_print_scripts hook to
  16   * register/enqueue new scripts.
  17   *
  18   * @since r16
  19   * @see WP_Dependencies::print_scripts()
  20   */
  21  function wp_print_scripts( $handles = false ) {
  22      do_action( 'wp_print_scripts' );
  23      if ( '' === $handles ) // for wp_head
  24          $handles = false;
  25  
  26      global $wp_scripts;
  27      if ( !is_a($wp_scripts, 'WP_Scripts') ) {
  28          if ( !$handles )
  29              return array(); // No need to instantiate if nothing's there.
  30          else
  31              $wp_scripts = new WP_Scripts();
  32      }
  33  
  34      return $wp_scripts->do_items( $handles );
  35  }
  36  
  37  /**
  38   * Register new JavaScript file.
  39   *
  40   * @since r16
  41   * @param string $handle Script name
  42   * @param string $src Script url
  43   * @param array $deps (optional) Array of script names on which this script depends
  44   * @param string|bool $ver (optional) Script version (used for cache busting), set to NULL to disable
  45   * @param bool (optional) Wether to enqueue the script before </head> or before </body>
  46   * @return null
  47   */
  48  function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
  49      global $wp_scripts;
  50      if ( !is_a($wp_scripts, 'WP_Scripts') )
  51          $wp_scripts = new WP_Scripts();
  52  
  53      $wp_scripts->add( $handle, $src, $deps, $ver );
  54      if ( $in_footer )
  55          $wp_scripts->add_data( $handle, 'group', 1 );
  56  }
  57  
  58  /**
  59   * Localizes a script.
  60   *
  61   * Localizes only if script has already been added.
  62   *
  63   * @since r16
  64   * @see WP_Scripts::localize()
  65   */
  66  function wp_localize_script( $handle, $object_name, $l10n ) {
  67      global $wp_scripts;
  68      if ( !is_a($wp_scripts, 'WP_Scripts') )
  69          return false;
  70  
  71      return $wp_scripts->localize( $handle, $object_name, $l10n );
  72  }
  73  
  74  /**
  75   * Remove a registered script.
  76   *
  77   * @since r16
  78   * @see WP_Scripts::remove() For parameter information.
  79   */
  80  function wp_deregister_script( $handle ) {
  81      global $wp_scripts;
  82      if ( !is_a($wp_scripts, 'WP_Scripts') )
  83          $wp_scripts = new WP_Scripts();
  84  
  85      $wp_scripts->remove( $handle );
  86  }
  87  
  88  /**
  89   * Enqueues script.
  90   *
  91   * Registers the script if src provided (does NOT overwrite) and enqueues.
  92   *
  93   * @since r16
  94   * @see wp_register_script() For parameter information.
  95   */
  96  function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) {
  97      global $wp_scripts;
  98      if ( !is_a($wp_scripts, 'WP_Scripts') )
  99          $wp_scripts = new WP_Scripts();
 100  
 101      if ( $src ) {
 102          $_handle = explode('?', $handle);
 103          $wp_scripts->add( $_handle[0], $src, $deps, $ver );
 104          if ( $in_footer )
 105              $wp_scripts->add_data( $_handle[0], 'group', 1 );
 106      }
 107      $wp_scripts->enqueue( $handle );
 108  }
 109  
 110  /**
 111   * Check whether script has been added to WordPress Scripts.
 112   *
 113   * The values for list defaults to 'queue', which is the same as enqueue for
 114   * scripts.
 115   *
 116   * @since WP unknown; BP unknown
 117   *
 118   * @param string $handle Handle used to add script.
 119   * @param string $list Optional, defaults to 'queue'. Others values are 'registered', 'queue', 'done', 'to_do'
 120   * @return bool
 121   */
 122  function wp_script_is( $handle, $list = 'queue' ) {
 123      global $wp_scripts;
 124      if ( !is_a($wp_scripts, 'WP_Scripts') )
 125          $wp_scripts = new WP_Scripts();
 126  
 127      $query = $wp_scripts->query( $handle, $list );
 128  
 129      if ( is_object( $query ) )
 130          return true;
 131  
 132      return $query;
 133  }


Generated: Thu Dec 26 01:01:01 2024 Cross-referenced by PHPXref 0.7.1