mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * BackPress script procedural API.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package BackPress
mp-wp_genesis 6 * @since r16
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /**
mp-wp_genesis 10 * Prints script tags in document head.
mp-wp_genesis 11 *
mp-wp_genesis 12 * Called by admin-header.php and by wp_head hook. Since it is called by wp_head
mp-wp_genesis 13 * on every page load, the function does not instantiate the WP_Scripts object
mp-wp_genesis 14 * unless script names are explicitly passed. Does make use of already
mp-wp_genesis 15 * instantiated $wp_scripts if present. Use provided wp_print_scripts hook to
mp-wp_genesis 16 * register/enqueue new scripts.
mp-wp_genesis 17 *
mp-wp_genesis 18 * @since r16
mp-wp_genesis 19 * @see WP_Scripts::print_scripts()
mp-wp_genesis 20 */
mp-wp_genesis 21 function wp_print_scripts( $handles = false ) {
mp-wp_genesis 22 do_action( 'wp_print_scripts' );
mp-wp_genesis 23 if ( '' === $handles ) // for wp_head
mp-wp_genesis 24 $handles = false;
mp-wp_genesis 25
mp-wp_genesis 26 global $wp_scripts;
mp-wp_genesis 27 if ( !is_a($wp_scripts, 'WP_Scripts') ) {
mp-wp_genesis 28 if ( !$handles )
mp-wp_genesis 29 return array(); // No need to instantiate if nothing's there.
mp-wp_genesis 30 else
mp-wp_genesis 31 $wp_scripts = new WP_Scripts();
mp-wp_genesis 32 }
mp-wp_genesis 33
mp-wp_genesis 34 return $wp_scripts->do_items( $handles );
mp-wp_genesis 35 }
mp-wp_genesis 36
mp-wp_genesis 37 /**
mp-wp_genesis 38 * Register new JavaScript file.
mp-wp_genesis 39 *
mp-wp_genesis 40 * @since r16
mp-wp_genesis 41 * @see WP_Scripts::add() For parameter information.
mp-wp_genesis 42 */
mp-wp_genesis 43 function wp_register_script( $handle, $src, $deps = array(), $ver = false ) {
mp-wp_genesis 44 global $wp_scripts;
mp-wp_genesis 45 if ( !is_a($wp_scripts, 'WP_Scripts') )
mp-wp_genesis 46 $wp_scripts = new WP_Scripts();
mp-wp_genesis 47
mp-wp_genesis 48 $wp_scripts->add( $handle, $src, $deps, $ver );
mp-wp_genesis 49 }
mp-wp_genesis 50
mp-wp_genesis 51 /**
mp-wp_genesis 52 * Localizes a script.
mp-wp_genesis 53 *
mp-wp_genesis 54 * Localizes only if script has already been added.
mp-wp_genesis 55 *
mp-wp_genesis 56 * @since r16
mp-wp_genesis 57 * @see WP_Script::localize()
mp-wp_genesis 58 */
mp-wp_genesis 59 function wp_localize_script( $handle, $object_name, $l10n ) {
mp-wp_genesis 60 global $wp_scripts;
mp-wp_genesis 61 if ( !is_a($wp_scripts, 'WP_Scripts') )
mp-wp_genesis 62 return false;
mp-wp_genesis 63
mp-wp_genesis 64 return $wp_scripts->localize( $handle, $object_name, $l10n );
mp-wp_genesis 65 }
mp-wp_genesis 66
mp-wp_genesis 67 /**
mp-wp_genesis 68 * Remove a registered script.
mp-wp_genesis 69 *
mp-wp_genesis 70 * @since r16
mp-wp_genesis 71 * @see WP_Scripts::remove() For parameter information.
mp-wp_genesis 72 */
mp-wp_genesis 73 function wp_deregister_script( $handle ) {
mp-wp_genesis 74 global $wp_scripts;
mp-wp_genesis 75 if ( !is_a($wp_scripts, 'WP_Scripts') )
mp-wp_genesis 76 $wp_scripts = new WP_Scripts();
mp-wp_genesis 77
mp-wp_genesis 78 $wp_scripts->remove( $handle );
mp-wp_genesis 79 }
mp-wp_genesis 80
mp-wp_genesis 81 /**
mp-wp_genesis 82 * Enqueues script.
mp-wp_genesis 83 *
mp-wp_genesis 84 * Registers the script if src provided (does NOT overwrite) and enqueues.
mp-wp_genesis 85 *
mp-wp_genesis 86 * @since r16
mp-wp_genesis 87 * @see WP_Script::add(), WP_Script::enqueue()
mp-wp_genesis 88 */
mp-wp_genesis 89 function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false ) {
mp-wp_genesis 90 global $wp_scripts;
mp-wp_genesis 91 if ( !is_a($wp_scripts, 'WP_Scripts') )
mp-wp_genesis 92 $wp_scripts = new WP_Scripts();
mp-wp_genesis 93
mp-wp_genesis 94 if ( $src ) {
mp-wp_genesis 95 $_handle = explode('?', $handle);
mp-wp_genesis 96 $wp_scripts->add( $_handle[0], $src, $deps, $ver );
mp-wp_genesis 97 }
mp-wp_genesis 98 $wp_scripts->enqueue( $handle );
mp-wp_genesis 99 }