| 1 | Index: wp-includes/functions.wp-scripts.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-includes/functions.wp-scripts.php (revision 18560) |
|---|
| 4 | +++ wp-includes/functions.wp-scripts.php (working copy) |
|---|
| 5 | @@ -24,7 +24,11 @@ |
|---|
| 6 | $handles = false; |
|---|
| 7 | |
|---|
| 8 | global $wp_scripts; |
|---|
| 9 | - if ( !is_a($wp_scripts, 'WP_Scripts') ) { |
|---|
| 10 | + if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
|---|
| 11 | + if ( ! did_action( 'init' ) ) |
|---|
| 12 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|---|
| 13 | + '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
|---|
| 14 | + |
|---|
| 15 | if ( !$handles ) |
|---|
| 16 | return array(); // No need to instantiate if nothing is there. |
|---|
| 17 | else |
|---|
| 18 | @@ -47,9 +51,13 @@ |
|---|
| 19 | */ |
|---|
| 20 | function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { |
|---|
| 21 | global $wp_scripts; |
|---|
| 22 | + if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
|---|
| 23 | + if ( ! did_action( 'init' ) ) |
|---|
| 24 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|---|
| 25 | + '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
|---|
| 26 | + $wp_scripts = new WP_Scripts(); |
|---|
| 27 | + } |
|---|
| 28 | |
|---|
| 29 | - wp_scripts_init(); |
|---|
| 30 | - |
|---|
| 31 | $wp_scripts->add( $handle, $src, $deps, $ver ); |
|---|
| 32 | if ( $in_footer ) |
|---|
| 33 | $wp_scripts->add_data( $handle, 'group', 1 ); |
|---|
| 34 | @@ -75,9 +83,13 @@ |
|---|
| 35 | */ |
|---|
| 36 | function wp_localize_script( $handle, $name, $data ) { |
|---|
| 37 | global $wp_scripts; |
|---|
| 38 | + if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
|---|
| 39 | + if ( ! did_action( 'init' ) ) |
|---|
| 40 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|---|
| 41 | + '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
|---|
| 42 | + return false; |
|---|
| 43 | + } |
|---|
| 44 | |
|---|
| 45 | - wp_scripts_init(); |
|---|
| 46 | - |
|---|
| 47 | return $wp_scripts->add_script_data( $handle, $name, $data ); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | @@ -89,9 +101,13 @@ |
|---|
| 51 | */ |
|---|
| 52 | function wp_deregister_script( $handle ) { |
|---|
| 53 | 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 | |
|---|
| 61 | - wp_scripts_init(); |
|---|
| 62 | - |
|---|
| 63 | $wp_scripts->remove( $handle ); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | @@ -105,9 +121,13 @@ |
|---|
| 67 | */ |
|---|
| 68 | function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) { |
|---|
| 69 | global $wp_scripts; |
|---|
| 70 | + if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
|---|
| 71 | + if ( ! did_action( 'init' ) ) |
|---|
| 72 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|---|
| 73 | + '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
|---|
| 74 | + $wp_scripts = new WP_Scripts(); |
|---|
| 75 | + } |
|---|
| 76 | |
|---|
| 77 | - wp_scripts_init(); |
|---|
| 78 | - |
|---|
| 79 | if ( $src ) { |
|---|
| 80 | $_handle = explode('?', $handle); |
|---|
| 81 | $wp_scripts->add( $_handle[0], $src, $deps, $ver ); |
|---|
| 82 | @@ -125,9 +145,13 @@ |
|---|
| 83 | */ |
|---|
| 84 | function wp_dequeue_script( $handle ) { |
|---|
| 85 | global $wp_scripts; |
|---|
| 86 | + if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
|---|
| 87 | + if ( ! did_action( 'init' ) ) |
|---|
| 88 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|---|
| 89 | + '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
|---|
| 90 | + $wp_scripts = new WP_Scripts(); |
|---|
| 91 | + } |
|---|
| 92 | |
|---|
| 93 | - wp_scripts_init(); |
|---|
| 94 | - |
|---|
| 95 | $wp_scripts->dequeue( $handle ); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | @@ -145,9 +169,13 @@ |
|---|
| 99 | */ |
|---|
| 100 | function wp_script_is( $handle, $list = 'queue' ) { |
|---|
| 101 | global $wp_scripts; |
|---|
| 102 | + if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) { |
|---|
| 103 | + if ( ! did_action( 'init' ) ) |
|---|
| 104 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|---|
| 105 | + '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
|---|
| 106 | + $wp_scripts = new WP_Scripts(); |
|---|
| 107 | + } |
|---|
| 108 | |
|---|
| 109 | - wp_scripts_init(); |
|---|
| 110 | - |
|---|
| 111 | $query = $wp_scripts->query( $handle, $list ); |
|---|
| 112 | |
|---|
| 113 | if ( is_object( $query ) ) |
|---|
| 114 | @@ -155,22 +183,3 @@ |
|---|
| 115 | |
|---|
| 116 | return $query; |
|---|
| 117 | } |
|---|
| 118 | - |
|---|
| 119 | -/** |
|---|
| 120 | - * Initializes $wp_scripts global (if it hasn't already been initialized by a faulty plugin or theme). |
|---|
| 121 | - * |
|---|
| 122 | - * @since 3.3 |
|---|
| 123 | - */ |
|---|
| 124 | -function wp_scripts_init() { |
|---|
| 125 | - global $wp_scripts; |
|---|
| 126 | - static $done = false; |
|---|
| 127 | - |
|---|
| 128 | - if ( !$done && !is_a($wp_scripts, 'WP_Scripts') ) { |
|---|
| 129 | - if ( !did_action('after_setup_theme') ) // last action before init |
|---|
| 130 | - _doing_it_wrong( __FUNCTION__, __( '$wp_scripts should not be accessed before the "init" hook.' ), '3.3' ); |
|---|
| 131 | - |
|---|
| 132 | - $wp_scripts = new WP_Scripts(); |
|---|
| 133 | - $done = true; |
|---|
| 134 | - } |
|---|
| 135 | -} |
|---|
| 136 | - |
|---|
| 137 | Index: wp-includes/functions.wp-styles.php |
|---|
| 138 | =================================================================== |
|---|
| 139 | --- wp-includes/functions.wp-styles.php (revision 18560) |
|---|
| 140 | +++ wp-includes/functions.wp-styles.php (working copy) |
|---|
| 141 | @@ -23,7 +23,11 @@ |
|---|
| 142 | $handles = false; |
|---|
| 143 | |
|---|
| 144 | global $wp_styles; |
|---|
| 145 | - if ( !is_a($wp_styles, 'WP_Styles') ) { |
|---|
| 146 | + if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { |
|---|
| 147 | + if ( ! did_action( 'init' ) ) |
|---|
| 148 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|---|
| 149 | + '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
|---|
| 150 | + |
|---|
| 151 | if ( !$handles ) |
|---|
| 152 | return array(); // No need to instantiate if nothing is there. |
|---|
| 153 | else |
|---|
| 154 | @@ -46,8 +50,12 @@ |
|---|
| 155 | */ |
|---|
| 156 | function wp_add_inline_style( $handle, $data ) { |
|---|
| 157 | global $wp_styles; |
|---|
| 158 | - if ( !is_a($wp_styles, 'WP_Styles') ) |
|---|
| 159 | - return false; |
|---|
| 160 | + if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { |
|---|
| 161 | + if ( ! did_action( 'init' ) ) |
|---|
| 162 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|---|
| 163 | + '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
|---|
| 164 | + $wp_styles = new WP_Styles(); |
|---|
| 165 | + } |
|---|
| 166 | |
|---|
| 167 | return $wp_styles->add_inline_style( $handle, $data ); |
|---|
| 168 | } |
|---|
| 169 | @@ -70,9 +78,13 @@ |
|---|
| 170 | */ |
|---|
| 171 | function wp_register_style( $handle, $src, $deps = array(), $ver = false, $media = 'all' ) { |
|---|
| 172 | global $wp_styles; |
|---|
| 173 | + if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { |
|---|
| 174 | + if ( ! did_action( 'init' ) ) |
|---|
| 175 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|---|
| 176 | + '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
|---|
| 177 | + $wp_styles = new WP_Styles(); |
|---|
| 178 | + } |
|---|
| 179 | |
|---|
| 180 | - wp_styles_init(); |
|---|
| 181 | - |
|---|
| 182 | $wp_styles->add( $handle, $src, $deps, $ver, $media ); |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | @@ -87,9 +99,13 @@ |
|---|
| 186 | */ |
|---|
| 187 | function wp_deregister_style( $handle ) { |
|---|
| 188 | global $wp_styles; |
|---|
| 189 | + if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { |
|---|
| 190 | + if ( ! did_action( 'init' ) ) |
|---|
| 191 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|---|
| 192 | + '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
|---|
| 193 | + $wp_styles = new WP_Styles(); |
|---|
| 194 | + } |
|---|
| 195 | |
|---|
| 196 | - wp_styles_init(); |
|---|
| 197 | - |
|---|
| 198 | $wp_styles->remove( $handle ); |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | @@ -114,9 +130,13 @@ |
|---|
| 202 | */ |
|---|
| 203 | function wp_enqueue_style( $handle, $src = false, $deps = array(), $ver = false, $media = 'all' ) { |
|---|
| 204 | global $wp_styles; |
|---|
| 205 | + if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { |
|---|
| 206 | + if ( ! did_action( 'init' ) ) |
|---|
| 207 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|---|
| 208 | + '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
|---|
| 209 | + $wp_styles = new WP_Styles(); |
|---|
| 210 | + } |
|---|
| 211 | |
|---|
| 212 | - wp_styles_init(); |
|---|
| 213 | - |
|---|
| 214 | if ( $src ) { |
|---|
| 215 | $_handle = explode('?', $handle); |
|---|
| 216 | $wp_styles->add( $_handle[0], $src, $deps, $ver, $media ); |
|---|
| 217 | @@ -132,9 +152,13 @@ |
|---|
| 218 | */ |
|---|
| 219 | function wp_dequeue_style( $handle ) { |
|---|
| 220 | global $wp_styles; |
|---|
| 221 | + if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { |
|---|
| 222 | + if ( ! did_action( 'init' ) ) |
|---|
| 223 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|---|
| 224 | + '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
|---|
| 225 | + $wp_styles = new WP_Styles(); |
|---|
| 226 | + } |
|---|
| 227 | |
|---|
| 228 | - wp_styles_init(); |
|---|
| 229 | - |
|---|
| 230 | $wp_styles->dequeue( $handle ); |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | @@ -152,9 +176,13 @@ |
|---|
| 234 | */ |
|---|
| 235 | function wp_style_is( $handle, $list = 'queue' ) { |
|---|
| 236 | global $wp_styles; |
|---|
| 237 | + if ( ! is_a( $wp_styles, 'WP_Styles' ) ) { |
|---|
| 238 | + if ( ! did_action( 'init' ) ) |
|---|
| 239 | + _doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ), |
|---|
| 240 | + '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>init</code>' ), '3.3' ); |
|---|
| 241 | + $wp_styles = new WP_Styles(); |
|---|
| 242 | + } |
|---|
| 243 | |
|---|
| 244 | - wp_styles_init(); |
|---|
| 245 | - |
|---|
| 246 | $query = $wp_styles->query( $handle, $list ); |
|---|
| 247 | |
|---|
| 248 | if ( is_object( $query ) ) |
|---|
| 249 | @@ -162,22 +190,3 @@ |
|---|
| 250 | |
|---|
| 251 | return $query; |
|---|
| 252 | } |
|---|
| 253 | - |
|---|
| 254 | -/** |
|---|
| 255 | - * Initializes $wp_styles global (if it hasn't already been initialized by a faulty plugin or theme). |
|---|
| 256 | - * |
|---|
| 257 | - * @since 3.3 |
|---|
| 258 | - */ |
|---|
| 259 | -function wp_styles_init() { |
|---|
| 260 | - global $wp_styles; |
|---|
| 261 | - static $done = false; |
|---|
| 262 | - |
|---|
| 263 | - if ( !$done && !is_a($wp_styles, 'WP_Styles') ) { |
|---|
| 264 | - if ( !did_action('after_setup_theme') ) |
|---|
| 265 | - _doing_it_wrong( __FUNCTION__, __( '$wp_styles should not be accessed before the "init" hook.' ), '3.3' ); |
|---|
| 266 | - |
|---|
| 267 | - $wp_styles = new WP_Styles(); |
|---|
| 268 | - $done = true; |
|---|
| 269 | - } |
|---|
| 270 | -} |
|---|
| 271 | - |
|---|