Make WordPress Core

Ticket #25326: 25326.1-scripts.diff

File 25326.1-scripts.diff, 8.9 KB (added by kpdesign, 12 years ago)

Functional docs changes for functions.wp-scripts.php

  • src/wp-includes/functions.wp-scripts.php

     
    11<?php
    22/**
    3  * BackPress script procedural API.
     3 * BackPress Scripts Procedural API
    44 *
    5  * @package BackPress
    6  * @since r16
     5 * @since 2.6.0
     6 *
     7 * @package WordPress
     8 * @subpackage BackPress
    79 */
    810
    911/**
    10  * Prints script tags in document head.
     12 * Print scripts in document head that are in the $handles queue.
    1113 *
    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.
    1718 *
    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.
    2027 */
    2128function wp_print_scripts( $handles = false ) {
    2229        do_action( 'wp_print_scripts' );
     
    3946}
    4047
    4148/**
    42  * Register new Javascript file.
     49 * Register a new JavaScript file.
    4350 *
    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'.
    5168 */
    5269function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
    5370        global $wp_scripts;
     
    6683/**
    6784 * Wrapper for $wp_scripts->localize().
    6885 *
    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>
    7289 * "$object_name" = {
    73  *   key: value,
    74  *   key: value,
    75  *   ...
     90 *       key: value,
     91 *       key: value,
     92 *       ...
    7693 * }
    77  * See http://core.trac.wordpress.org/ticket/11520 for more information.
     94 * </code>
    7895 *
    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.
    8098 *
    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.
    84104 * @return bool Whether the localization was added successfully.
    85105 */
    86106function wp_localize_script( $handle, $object_name, $l10n ) {
     
    99119/**
    100120 * Remove a registered script.
    101121 *
    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.
    104128 */
    105129function wp_deregister_script( $handle ) {
    106130        global $wp_scripts;
     
    111135                $wp_scripts = new WP_Scripts();
    112136        }
    113137
    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         */
    116143        $current_filter = current_filter();
    117144        if ( ( is_admin() && 'admin_enqueue_scripts' !== $current_filter ) ||
    118145                ( 'wp-login.php' === $GLOBALS['pagenow'] && 'login_enqueue_scripts' !== $current_filter )
     
    139166}
    140167
    141168/**
    142  * Enqueues script.
     169 * Enqueue a script.
    143170 *
    144171 * Registers the script if src provided (does NOT overwrite) and enqueues.
    145172 *
    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'.
    148187 */
    149188function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) {
    150189        global $wp_scripts;
     
    167206/**
    168207 * Remove an enqueued script.
    169208 *
     209 * @see WP_Dependencies::dequeue()
     210 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
     211 *
    170212 * @since 3.1.0
    171  * @see WP_Scripts::dequeue() For parameter information.
     213 *
     214 * @param string $handle Name of the script to be removed.
    172215 */
    173216function wp_dequeue_script( $handle ) {
    174217        global $wp_scripts;
     
    183226}
    184227
    185228/**
    186  * Check whether script has been added to WordPress Scripts.
     229 * Check whether a script has been added to the queue.
    187230 *
    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.
    191232 *
    192233 * @since 2.8.0
     234 * @since 3.5.0 'enqueued' added as an alias of the 'queue' list.
    193235 *
    194236 * @param string $handle Name of the script.
    195  * @param string $list Optional. Defaults to 'enqueued'. Values are
    196  *      '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'.
    197239 * @return bool Whether script is in the list.
    198240 */
    199241function wp_script_is( $handle, $list = 'enqueued' ) {