Ticket #25402: 25402.2.diff
File 25402.2.diff, 9.6 KB (added by , 11 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 17 * hook to register/enqueue new scripts. 17 18 * 18 * @since r16 19 * @see WP_Dependencies::print_scripts() 19 * @see WP_Scripts::do_items() 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. Default 'false'. 25 * @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array. 20 26 */ 21 27 function wp_print_scripts( $handles = false ) { 22 28 do_action( 'wp_print_scripts' ); … … 39 45 } 40 46 41 47 /** 42 * Register new Javascript file.48 * Register a new script. 43 49 * 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 50 * Registers a script to be linked later using the wp_enqueue_script() function. 51 * 52 * @see WP_Dependencies::add(), WP_Dependencies::add_data() 53 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 54 * 55 * @since 2.6.0 56 * 57 * @param string $handle Name of the script. Should be unique. 58 * @param string $src Path to the script from the WordPress root directory. Example: '/js/myscript.js'. 59 * @param array $deps Optional. An array of registered script handles this script depends on. Set false if there 60 * are no dependencies. Default empty array. 61 * @param string|bool $ver Optional. String specifying script version number, if it has one, which is concatenated 62 * to end of path as a query string. If no version is specified or set to false, a version 63 * number is automatically added equal to current installed WordPress version. 64 * If set to null, no version is added. Default 'false'. Accepts 'false', 'null', or 'string'. 65 * @param bool $in_footer Optional. Whether to enqueue the script before </head> or before </body>. 66 * Default 'false'. Accepts 'false' or 'true'. 51 67 */ 52 68 function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) { 53 69 global $wp_scripts; … … 64 80 } 65 81 66 82 /** 67 * Wrapper for $wp_scripts->localize().83 * Localize a script. 68 84 * 69 * Used to localize a script.70 85 * Works only if the script has already been added. 71 * Accepts an associative array $l10n and creates JS object: 86 * 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 * @see WP_Dependencies::localize() 97 * @link http://core.trac.wordpress.org/ticket/11520 98 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 80 99 * 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. 84 * @return bool Whether the localization was added successfully. 100 * @since 2.6.0 101 * 102 * @param string $handle Script handle the data will be attached to. 103 * @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable. 104 * Example: '/[a-zA-Z0-9_]+/'. 105 * @param array $l10n The data itself. The data can be either a single or multi-dimensional array. 106 * @return bool True if the script was successfully localized, false otherwise. 85 107 */ 86 108 function wp_localize_script( $handle, $object_name, $l10n ) { 87 109 global $wp_scripts; … … 99 121 /** 100 122 * Remove a registered script. 101 123 * 102 * @since r16 103 * @see WP_Scripts::remove() For parameter information. 124 * There are intentional safeguards in place to prevent critical admin scripts, such as jQuery core, from being unregistered. 125 * 126 * @see WP_Dependencies::remove() 127 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 128 * 129 * @since 2.6.0 130 * 131 * @param string $handle Name of the script to be removed. 104 132 */ 105 133 function wp_deregister_script( $handle ) { 106 134 global $wp_scripts; … … 111 139 $wp_scripts = new WP_Scripts(); 112 140 } 113 141 114 // Do not allow accidental or negligent deregistering of critical scripts in the admin. 115 // Show minimal remorse if the correct hook is used. 142 /** 143 * Do not allow accidental or negligent deregistering of 144 * critical scripts in the admin. Show minimal remorse 145 * if the correct hook is used. 146 */ 116 147 $current_filter = current_filter(); 117 148 if ( ( is_admin() && 'admin_enqueue_scripts' !== $current_filter ) || 118 149 ( 'wp-login.php' === $GLOBALS['pagenow'] && 'login_enqueue_scripts' !== $current_filter ) … … 123 154 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-menu', 'jquery-ui-mouse', 124 155 'jquery-ui-position', 'jquery-ui-progressbar', 'jquery-ui-resizable', 'jquery-ui-selectable', 125 156 'jquery-ui-slider', 'jquery-ui-sortable', 'jquery-ui-spinner', 'jquery-ui-tabs', 126 'jquery-ui-tooltip', 'jquery-ui-widget', 127 'underscore', 'backbone', 157 'jquery-ui-tooltip', 'jquery-ui-widget', 'underscore', 'backbone', 128 158 ); 129 159 130 160 if ( in_array( $handle, $no ) ) { … … 139 169 } 140 170 141 171 /** 142 * Enqueue sscript.172 * Enqueue a script. 143 173 * 144 174 * Registers the script if src provided (does NOT overwrite) and enqueues. 145 175 * 146 * @since r16 147 * @see wp_register_script() For parameter information. 176 * @see WP_Dependencies::add(), WP_Dependencies::add_data(), WP_Dependencies::enqueue() 177 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 178 * 179 * @since 2.6.0 180 181 * @param string $handle Name of the script. 182 * @param string|bool $src Path to the script from the root directory of WordPress. Example: '/js/myscript.js'. 183 * @param array $deps An array of registered handles this script depends on. Default empty array. 184 * @param string|bool $ver Optional. String specifying the script version number, if it has one. This parameter 185 * is used to ensure that the correct version is sent to the client regardless of caching, 186 * and so should be included if a version number is available and makes sense for the script. 187 * @param bool $in_footer Optional. Whether to enqueue the script before </head> or before </body>. 188 * Default 'false'. Accepts 'false' or 'true'. 148 189 */ 149 190 function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) { 150 191 global $wp_scripts; … … 165 206 } 166 207 167 208 /** 168 * Remove a nenqueued script.209 * Remove a previously enqueued script. 169 210 * 211 * @see WP_Dependencies::dequeue() 212 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 213 * 170 214 * @since 3.1.0 171 * @see WP_Scripts::dequeue() For parameter information. 215 * 216 * @param string $handle Name of the script to be removed. 172 217 */ 173 218 function wp_dequeue_script( $handle ) { 174 219 global $wp_scripts; … … 183 228 } 184 229 185 230 /** 186 * Check whether script has been added to WordPress Scripts.231 * Check whether a script has been added to the queue. 187 232 * 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'. 233 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 191 234 * 192 235 * @since 2.8.0 236 * @since 3.5.0 'enqueued' added as an alias of the 'queue' list. 193 237 * 194 238 * @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'.197 * @return bool Whether script is in the list.239 * @param string $list Optional. Status of the script to check. Default 'enqueued'. Accepts 'enqueued', 240 * 'registered', 'queue', 'to_do', and 'done'. 241 * @return bool Whether script is queued. 198 242 */ 199 243 function wp_script_is( $handle, $list = 'enqueued' ) { 200 244 global $wp_scripts;