Ticket #25326: 25326.1-scripts.diff
| File 25326.1-scripts.diff, 8.9 KB (added by , 12 years ago) |
|---|
-
src/wp-includes/functions.wp-scripts.php
1 1 <?php 2 2 /** 3 * BackPress script procedural API.3 * BackPress Scripts Procedural API 4 4 * 5 * @package BackPress 6 * @since r16 5 * @since 2.6.0 6 * 7 * @package WordPress 8 * @subpackage BackPress 7 9 */ 8 10 9 11 /** 10 * Print s script tags in document head.12 * Print scripts in document head that are in the $handles queue. 11 13 * 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. 14 * Called by admin-header.php and wp_head hook. Since it is called by wp_head on every page load, 15 * the function does not instantiate the WP_Scripts object unless script names are explicitly passed. 16 * Makes use of already-instantiated $wp_scripts global if present. Use provided wp_print_scripts to 17 * hook to register/enqueue new scripts. 17 18 * 18 * @since r16 19 * @see WP_Dependencies::print_scripts() 19 * @see WP_Scripts::print_scripts() 20 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 21 * 22 * @since 2.6.0 23 * 24 * @param array|bool $handles Scripts to be printed. 25 * Default 'false'. 26 * @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array. 20 27 */ 21 28 function wp_print_scripts( $handles = false ) { 22 29 do_action( 'wp_print_scripts' ); … … 39 46 } 40 47 41 48 /** 42 * Register new Javascript file.49 * Register a new JavaScript file. 43 50 * 44 * @since r16 45 * @param string $handle Script name 46 * @param string $src Script url 47 * @param array $deps (optional) Array of script names on which this script depends 48 * @param string|bool $ver (optional) Script version (used for cache busting), set to null to disable 49 * @param bool $in_footer (optional) Whether to enqueue the script before </head> or before </body> 50 * @return null 51 * Register a JavaScript file to be linked later using the wp_enqueue_script() function. 52 * 53 * @see WP_Dependencies::add() 54 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 55 * 56 * @since 2.6.0 57 * 58 * @param string $handle Name of the script. Should be unique. 59 * @param string $src Path to the script from the WordPress root directory. Example: '/js/myscript.js'. 60 * @param array $deps Optional. An array of registered script handles this script depends on. Set false if there are no dependencies. 61 * Default empty array. 62 * @param string|bool $ver Optional. String specifying script version number, if it has one, which is concatenated to end of path as a query string. 63 * If no version is specified or set to false, a version number is automatically added equal to current installed WordPress version. 64 * If set to null, no version is added. 65 * Default 'false'. Accepts 'false', 'null', or 'string'. 66 * @param bool $in_footer Optional. Whether to enqueue the script before </head> or before </body>. 67 * Default 'false'. Accepts 'false' or 'true'. 51 68 */ 52 69 function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { 53 70 global $wp_scripts; … … 66 83 /** 67 84 * Wrapper for $wp_scripts->localize(). 68 85 * 69 * Used to localize a script. 70 * Works only if the script has already been added.71 * Accepts an associative array $l10n and creates JS object:86 * Used to localize a script. Works only if the script has already been added. 87 * Accepts an associative array $l10n and creates a JavaScript object: 88 * <code> 72 89 * "$object_name" = { 73 * key: value,74 * key: value,75 * ...90 * key: value, 91 * key: value, 92 * ... 76 93 * } 77 * See http://core.trac.wordpress.org/ticket/11520 for more information.94 * </code> 78 95 * 79 * @since r16 96 * @link http://core.trac.wordpress.org/ticket/11520 97 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 80 98 * 81 * @param string $handle The script handle that was registered or used in script-loader 82 * @param string $object_name Name for the created JS object. This is passed directly so it should be qualified JS variable /[a-zA-Z0-9_]+/ 83 * @param array $l10n Associative PHP array containing the translated strings. HTML entities will be converted and the array will be JSON encoded. 99 * @since 2.6.0 100 * 101 * @param string $handle Script handle you are attaching the data for. 102 * @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable. Example: '/[a-zA-Z0-9_]+/'. 103 * @param array $l10n The data itself. The data can be either a single or multi-dimensional array. 84 104 * @return bool Whether the localization was added successfully. 85 105 */ 86 106 function wp_localize_script( $handle, $object_name, $l10n ) { … … 99 119 /** 100 120 * Remove a registered script. 101 121 * 102 * @since r16 103 * @see WP_Scripts::remove() For parameter information. 122 * @see WP_Dependencies::remove() 123 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 124 * 125 * @since 2.6.0 126 * 127 * @param string $handle Name of the script to be removed. 104 128 */ 105 129 function wp_deregister_script( $handle ) { 106 130 global $wp_scripts; … … 111 135 $wp_scripts = new WP_Scripts(); 112 136 } 113 137 114 // Do not allow accidental or negligent deregistering of critical scripts in the admin. 115 // Show minimal remorse if the correct hook is used. 138 /** 139 * Do not allow accidental or negligent deregistering of 140 * critical scripts in the admin. Show minimal remorse 141 * if the correct hook is used. 142 */ 116 143 $current_filter = current_filter(); 117 144 if ( ( is_admin() && 'admin_enqueue_scripts' !== $current_filter ) || 118 145 ( 'wp-login.php' === $GLOBALS['pagenow'] && 'login_enqueue_scripts' !== $current_filter ) … … 139 166 } 140 167 141 168 /** 142 * Enqueue sscript.169 * Enqueue a script. 143 170 * 144 171 * Registers the script if src provided (does NOT overwrite) and enqueues. 145 172 * 146 * @since r16 147 * @see wp_register_script() For parameter information. 173 * @see WP_Dependencies::add(), WP_Dependencies::enqueue() 174 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 175 * 176 * @since 2.6.0 177 178 * @param string $handle Name of the script. 179 * @param string|bool $src Path to the script from the root directory of WordPress. Example: '/js/myscript.js'. 180 * @param array $deps An array of registered handles this script depends on. 181 * Default empty array. 182 * @param string|bool $ver Optional. String specifying the script version number, if it has one. This parameter is used to ensure 183 * that the correct version is sent to the client regardless of caching, and so should be included if 184 * a version number is available and makes sense for the script. 185 * @param bool $in_footer Optional. Whether to enqueue the script before </head> or before </body>. 186 * Default 'false'. Accepts 'false' or 'true'. 148 187 */ 149 188 function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) { 150 189 global $wp_scripts; … … 167 206 /** 168 207 * Remove an enqueued script. 169 208 * 209 * @see WP_Dependencies::dequeue() 210 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 211 * 170 212 * @since 3.1.0 171 * @see WP_Scripts::dequeue() For parameter information. 213 * 214 * @param string $handle Name of the script to be removed. 172 215 */ 173 216 function wp_dequeue_script( $handle ) { 174 217 global $wp_scripts; … … 183 226 } 184 227 185 228 /** 186 * Check whether script has been added to WordPress Scripts.229 * Check whether a script has been added to the queue. 187 230 * 188 * By default, checks if the script has been enqueued. You can also 189 * pass 'registered' to $list, to see if the script is registered, 190 * and you can check processing statuses with 'to_do' and 'done'. 231 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 191 232 * 192 233 * @since 2.8.0 234 * @since 3.5.0 'enqueued' added as an alias of the 'queue' list. 193 235 * 194 236 * @param string $handle Name of the script. 195 * @param string $list Optional. Defaults to 'enqueued'. Values are196 * 'registered', 'enqueued' (or 'queue'), 'to_do', and 'done'.237 * @param string $list Optional. Status of the script to check. 238 * Default 'enqueued'. Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'. 197 239 * @return bool Whether script is in the list. 198 240 */ 199 241 function wp_script_is( $handle, $list = 'enqueued' ) {