diff --git wp-includes/functions.wp-scripts.php wp-includes/functions.wp-scripts.php
index a8dac35..30667d2 100644
|
|
|
function wp_print_scripts( $handles = false ) { |
| 23 | 23 | if ( '' === $handles ) // for wp_head |
| 24 | 24 | $handles = false; |
| 25 | 25 | |
| | 26 | if ( !$handles ) |
| | 27 | return array(); // No need to instantiate if nothing is there. |
| | 28 | |
| 26 | 29 | global $wp_scripts; |
| 27 | | if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
| 28 | | if ( ! did_action( 'init' ) ) |
| 29 | | _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
| 30 | | '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
| 31 | | |
| 32 | | if ( !$handles ) |
| 33 | | return array(); // No need to instantiate if nothing is there. |
| 34 | | else |
| 35 | | $wp_scripts = new WP_Scripts(); |
| 36 | | } |
| | 30 | wp_scripts_maybe_initialize( $wp_scripts, __FUNCTION__ ); |
| 37 | 31 | |
| 38 | 32 | return $wp_scripts->do_items( $handles ); |
| 39 | 33 | } |
| … |
… |
function wp_print_scripts( $handles = false ) { |
| 51 | 45 | */ |
| 52 | 46 | function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { |
| 53 | 47 | global $wp_scripts; |
| 54 | | if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
| 55 | | if ( ! did_action( 'init' ) ) |
| 56 | | _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
| 57 | | '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
| 58 | | $wp_scripts = new WP_Scripts(); |
| 59 | | } |
| 60 | | |
| | 48 | wp_scripts_maybe_initialize( $wp_scripts, __FUNCTION__ ); |
| 61 | 49 | $wp_scripts->add( $handle, $src, $deps, $ver ); |
| 62 | 50 | if ( $in_footer ) |
| 63 | 51 | $wp_scripts->add_data( $handle, 'group', 1 ); |
| … |
… |
function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_f |
| 85 | 73 | */ |
| 86 | 74 | function wp_localize_script( $handle, $object_name, $l10n ) { |
| 87 | 75 | global $wp_scripts; |
| 88 | | if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
| 89 | | if ( ! did_action( 'init' ) ) |
| 90 | | _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
| 91 | | '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
| 92 | | |
| | 76 | if ( !is_a( $wp_scripts, 'WP_Scripts' ) ) |
| 93 | 77 | return false; |
| 94 | | } |
| | 78 | |
| | 79 | wp_scripts_maybe_initialize( $wp_scripts, __FUNCTION__ ); |
| 95 | 80 | |
| 96 | 81 | return $wp_scripts->localize( $handle, $object_name, $l10n ); |
| 97 | 82 | } |
| … |
… |
function wp_localize_script( $handle, $object_name, $l10n ) { |
| 104 | 89 | */ |
| 105 | 90 | function wp_deregister_script( $handle ) { |
| 106 | 91 | global $wp_scripts; |
| 107 | | if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
| 108 | | if ( ! did_action( 'init' ) ) |
| 109 | | _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
| 110 | | '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
| 111 | | $wp_scripts = new WP_Scripts(); |
| 112 | | } |
| 113 | | |
| | 92 | wp_scripts_maybe_initialize( $wp_scripts, __FUNCTION__ ); |
| 114 | 93 | $wp_scripts->remove( $handle ); |
| 115 | 94 | } |
| 116 | 95 | |
| … |
… |
function wp_deregister_script( $handle ) { |
| 124 | 103 | */ |
| 125 | 104 | function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) { |
| 126 | 105 | global $wp_scripts; |
| 127 | | if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
| 128 | | if ( ! did_action( 'init' ) ) |
| 129 | | _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
| 130 | | '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
| 131 | | $wp_scripts = new WP_Scripts(); |
| 132 | | } |
| | 106 | wp_scripts_maybe_initialize( $wp_scripts, __FUNCTION__ ); |
| 133 | 107 | |
| 134 | 108 | if ( $src ) { |
| 135 | 109 | $_handle = explode('?', $handle); |
| … |
… |
function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false |
| 148 | 122 | */ |
| 149 | 123 | function wp_dequeue_script( $handle ) { |
| 150 | 124 | global $wp_scripts; |
| 151 | | if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
| 152 | | if ( ! did_action( 'init' ) ) |
| 153 | | _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
| 154 | | '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
| 155 | | $wp_scripts = new WP_Scripts(); |
| 156 | | } |
| 157 | | |
| | 125 | wp_scripts_maybe_initialize( $wp_scripts, __FUNCTION__ ); |
| 158 | 126 | $wp_scripts->dequeue( $handle ); |
| 159 | 127 | } |
| 160 | 128 | |
| … |
… |
function wp_dequeue_script( $handle ) { |
| 172 | 140 | */ |
| 173 | 141 | function wp_script_is( $handle, $list = 'queue' ) { |
| 174 | 142 | global $wp_scripts; |
| 175 | | if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
| 176 | | if ( ! did_action( 'init' ) ) |
| 177 | | _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
| 178 | | '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
| 179 | | $wp_scripts = new WP_Scripts(); |
| 180 | | } |
| | 143 | wp_scripts_maybe_initialize( $wp_scripts, __FUNCTION__ ); |
| 181 | 144 | |
| 182 | 145 | $query = $wp_scripts->query( $handle, $list ); |
| 183 | 146 | |
| … |
… |
function wp_script_is( $handle, $list = 'queue' ) { |
| 186 | 149 | |
| 187 | 150 | return $query; |
| 188 | 151 | } |
| | 152 | |
| | 153 | /** |
| | 154 | * Checks if first argument is an instance of WP_Scripts and optionally creates |
| | 155 | * and returns it, or returns a fallback. |
| | 156 | * |
| | 157 | * @since 3.5.0 |
| | 158 | * |
| | 159 | * @param string &$wp_scripts Variable to test. |
| | 160 | * @param string $function The function from which it was called. |
| | 161 | */ |
| | 162 | function wp_scripts_maybe_initialize( &$wp_scripts, $function ) { |
| | 163 | if ( is_a( $wp_scripts, 'WP_Scripts' ) ) |
| | 164 | return; |
| | 165 | |
| | 166 | if ( ! did_action( 'init' ) ) |
| | 167 | _doing_it_wrong( $function, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
| | 168 | '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
| | 169 | |
| | 170 | $wp_scripts = new WP_Scripts; |
| | 171 | } |
| | 172 | |