wp/wp-includes/functions.wp-scripts.php
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 18:28:13 +0200
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
permissions -rw-r--r--
upgrade wordpress to 5.2.3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     3
 * Dependencies API: Scripts functions
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @package WordPress
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     8
 * @subpackage Dependencies
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    12
 * Initialize $wp_scripts if it has not been set.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    13
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    14
 * @global WP_Scripts $wp_scripts
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    15
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    16
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    17
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    18
 * @return WP_Scripts WP_Scripts instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    20
function wp_scripts() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
	global $wp_scripts;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    22
	if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    23
		$wp_scripts = new WP_Scripts();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    25
	return $wp_scripts;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    26
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    29
 * Helper function to output a _doing_it_wrong message when applicable.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
 * @ignore
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
 * @param string $function Function name.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    35
 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    36
function _wp_scripts_maybe_doing_it_wrong( $function ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    37
	if ( did_action( 'init' ) || did_action( 'admin_enqueue_scripts' ) || did_action( 'wp_enqueue_scripts' ) || did_action( 'login_enqueue_scripts' ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    38
		return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    40
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    41
	_doing_it_wrong(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    42
		$function,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    43
		sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    44
			/* translators: 1: wp_enqueue_scripts, 2: admin_enqueue_scripts, 3: login_enqueue_scripts */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    45
			__( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    46
			'<code>wp_enqueue_scripts</code>',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    47
			'<code>admin_enqueue_scripts</code>',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    48
			'<code>login_enqueue_scripts</code>'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    49
		),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    50
		'3.3.0'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    51
	);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    54
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    55
 * Prints scripts in document head that are in the $handles queue.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    57
 * Called by admin-header.php and {@see 'wp_head'} hook. Since it is called by wp_head on every page load,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
 * the function does not instantiate the WP_Scripts object unless script names are explicitly passed.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    59
 * Makes use of already-instantiated $wp_scripts global if present. Use provided {@see 'wp_print_scripts'}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
 * hook to register/enqueue new scripts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
 * @see WP_Scripts::do_items()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    65
 * @since 2.1.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
 * @param string|bool|array $handles Optional. Scripts to be printed. Default 'false'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
 * @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
function wp_print_scripts( $handles = false ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
	 * Fires before scripts in the $handles queue are printed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    73
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
	 * @since 2.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    75
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	do_action( 'wp_print_scripts' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    77
	if ( '' === $handles ) { // for wp_head
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
		$handles = false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
	global $wp_scripts;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
	if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
		if ( ! $handles ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
			return array(); // No need to instantiate if nothing is there.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    87
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    90
	return wp_scripts()->do_items( $handles );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    94
 * Adds extra code to a registered script.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    95
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    96
 * Code will only be added if the script is already in the queue.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    97
 * Accepts a string $data containing the Code. If two or more code blocks
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    98
 * are added to the same script $handle, they will be printed in the order
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    99
 * they were added, i.e. the latter added code can redeclare the previous.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   100
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   101
 * @since 4.5.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   102
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   103
 * @see WP_Scripts::add_inline_script()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   104
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   105
 * @param string $handle   Name of the script to add the inline script to.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   106
 * @param string $data     String containing the javascript to be added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   107
 * @param string $position Optional. Whether to add the inline script before the handle
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   108
 *                         or after. Default 'after'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   109
 * @return bool True on success, false on failure.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   110
 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   111
function wp_add_inline_script( $handle, $data, $position = 'after' ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   112
	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   113
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   114
	if ( false !== stripos( $data, '</script>' ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   115
		_doing_it_wrong(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   116
			__FUNCTION__,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   117
			sprintf(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   118
				/* translators: 1: <script>, 2: wp_add_inline_script() */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   119
				__( 'Do not pass %1$s tags to %2$s.' ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   120
				'<code>&lt;script&gt;</code>',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   121
				'<code>wp_add_inline_script()</code>'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   122
			),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   123
			'4.5.0'
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   124
		);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   125
		$data = trim( preg_replace( '#<script[^>]*>(.*)</script>#is', '$1', $data ) );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   126
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   127
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   128
	return wp_scripts()->add_inline_script( $handle, $data, $position );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   129
}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   130
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   131
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
 * Register a new script.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   134
 * Registers a script to be enqueued later using the wp_enqueue_script() function.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   136
 * @see WP_Dependencies::add()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   137
 * @see WP_Dependencies::add_data()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   139
 * @since 2.1.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   140
 * @since 4.3.0 A return value was added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   142
 * @param string           $handle    Name of the script. Should be unique.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   143
 * @param string|bool      $src       Full URL of the script, or path of the script relative to the WordPress root directory.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   144
 *                                    If source is set to false, script is an alias of other scripts it depends on.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   145
 * @param array            $deps      Optional. An array of registered script handles this script depends on. Default empty array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   146
 * @param string|bool|null $ver       Optional. String specifying script version number, if it has one, which is added to the URL
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   147
 *                                    as a query string for cache busting purposes. If version is set to false, a version
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   148
 *                                    number is automatically added equal to current installed WordPress version.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   149
 *                                    If set to null, no version is added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   150
 * @param bool             $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   151
 *                                    Default 'false'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   152
 * @return bool Whether the script has been registered. True on success, false on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
	$wp_scripts = wp_scripts();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   158
	$registered = $wp_scripts->add( $handle, $src, $deps, $ver );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
	if ( $in_footer ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
		$wp_scripts->add_data( $handle, 'group', 1 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   161
	}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   162
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   163
	return $registered;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
 * Localize a script.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
 * Works only if the script has already been added.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
 * Accepts an associative array $l10n and creates a JavaScript object:
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
 *     "$object_name" = {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
 *         key: value,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
 *         key: value,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
 *         ...
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   177
 *     }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   178
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
 * @see WP_Dependencies::localize()
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   180
 * @link https://core.trac.wordpress.org/ticket/11520
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   183
 * @since 2.2.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   185
 * @todo Documentation cleanup
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   186
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
 * @param string $handle      Script handle the data will be attached to.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
 * @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
 *                            Example: '/[a-zA-Z0-9_]+/'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
 * @param array $l10n         The data itself. The data can be either a single or multi-dimensional array.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
 * @return bool True if the script was successfully localized, false otherwise.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
function wp_localize_script( $handle, $object_name, $l10n ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
	global $wp_scripts;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   195
	if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   196
		_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   200
	return $wp_scripts->localize( $handle, $object_name, $l10n );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   204
 * Sets translated strings for a script.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   205
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   206
 * Works only if the script has already been added.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   207
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   208
 * @see WP_Scripts::set_translations()
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   209
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   210
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   211
 * @since 5.0.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   212
 * @since 5.1.0 The `$domain` parameter was made optional.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   213
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   214
 * @param string $handle Script handle the textdomain will be attached to.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   215
 * @param string $domain Optional. Text domain. Default 'default'.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   216
 * @param string $path   Optional. The full file path to the directory containing translation files.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   217
 * @return bool True if the text domain was successfully localized, false otherwise.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   218
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   219
function wp_set_script_translations( $handle, $domain = 'default', $path = null ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   220
	global $wp_scripts;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   221
	if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   222
		_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   223
		return false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   224
	}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   225
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   226
	return $wp_scripts->set_translations( $handle, $domain, $path );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   227
}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   228
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   229
/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
 * Remove a registered script.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
 * Note: there are intentional safeguards in place to prevent critical admin scripts,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
 * such as jQuery core, from being unregistered.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
 * @see WP_Dependencies::remove()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   237
 * @since 2.1.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
 * @param string $handle Name of the script to be removed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
function wp_deregister_script( $handle ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   242
	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
	 * Do not allow accidental or negligent de-registering of critical scripts in the admin.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
	 * Show minimal remorse if the correct hook is used.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
	$current_filter = current_filter();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
	if ( ( is_admin() && 'admin_enqueue_scripts' !== $current_filter ) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
		( 'wp-login.php' === $GLOBALS['pagenow'] && 'login_enqueue_scripts' !== $current_filter )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
	) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
		$no = array(
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   253
			'jquery',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   254
			'jquery-core',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   255
			'jquery-migrate',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   256
			'jquery-ui-core',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   257
			'jquery-ui-accordion',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   258
			'jquery-ui-autocomplete',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   259
			'jquery-ui-button',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   260
			'jquery-ui-datepicker',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   261
			'jquery-ui-dialog',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   262
			'jquery-ui-draggable',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   263
			'jquery-ui-droppable',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   264
			'jquery-ui-menu',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   265
			'jquery-ui-mouse',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   266
			'jquery-ui-position',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   267
			'jquery-ui-progressbar',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   268
			'jquery-ui-resizable',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   269
			'jquery-ui-selectable',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   270
			'jquery-ui-slider',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   271
			'jquery-ui-sortable',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   272
			'jquery-ui-spinner',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   273
			'jquery-ui-tabs',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   274
			'jquery-ui-tooltip',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   275
			'jquery-ui-widget',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   276
			'underscore',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   277
			'backbone',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
		if ( in_array( $handle, $no ) ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   281
			$message = sprintf(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   282
				/* translators: 1: script name, 2: wp_enqueue_scripts */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   283
				__( 'Do not deregister the %1$s script in the administration area. To target the front-end theme, use the %2$s hook.' ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   284
				"<code>$handle</code>",
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   285
				'<code>wp_enqueue_scripts</code>'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   286
			);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   287
			_doing_it_wrong( __FUNCTION__, $message, '3.6.0' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
	wp_scripts()->remove( $handle );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
 * Enqueue a script.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
 * Registers the script if $src provided (does NOT overwrite), and enqueues it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   300
 * @see WP_Dependencies::add()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   301
 * @see WP_Dependencies::add_data()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   302
 * @see WP_Dependencies::enqueue()
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   304
 * @since 2.1.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   305
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   306
 * @param string           $handle    Name of the script. Should be unique.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   307
 * @param string           $src       Full URL of the script, or path of the script relative to the WordPress root directory.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   308
 *                                    Default empty.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   309
 * @param array            $deps      Optional. An array of registered script handles this script depends on. Default empty array.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   310
 * @param string|bool|null $ver       Optional. String specifying script version number, if it has one, which is added to the URL
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   311
 *                                    as a query string for cache busting purposes. If version is set to false, a version
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   312
 *                                    number is automatically added equal to current installed WordPress version.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   313
 *                                    If set to null, no version is added.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   314
 * @param bool             $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   315
 *                                    Default 'false'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   317
function wp_enqueue_script( $handle, $src = '', $deps = array(), $ver = false, $in_footer = false ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   318
	$wp_scripts = wp_scripts();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   319
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   320
	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   321
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   322
	if ( $src || $in_footer ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   323
		$_handle = explode( '?', $handle );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   325
		if ( $src ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
			$wp_scripts->add( $_handle[0], $src, $deps, $ver );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
		if ( $in_footer ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
			$wp_scripts->add_data( $_handle[0], 'group', 1 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   331
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
	$wp_scripts->enqueue( $handle );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
 * Remove a previously enqueued script.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
 * @see WP_Dependencies::dequeue()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
 * @param string $handle Name of the script to be removed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
function wp_dequeue_script( $handle ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   347
	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   349
	wp_scripts()->dequeue( $handle );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   353
 * Determines whether a script has been added to the queue.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   354
 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   355
 * For more information on this and similar theme functions, check out
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   356
 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   357
 * Conditional Tags} article in the Theme Developer Handbook.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
 * @since 3.5.0 'enqueued' added as an alias of the 'queue' list.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
 * @param string $handle Name of the script.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
 * @param string $list   Optional. Status of the script to check. Default 'enqueued'.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
 *                       Accepts 'enqueued', 'registered', 'queue', 'to_do', and 'done'.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   365
 * @return bool Whether the script is queued.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
function wp_script_is( $handle, $list = 'enqueued' ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   369
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   370
	return (bool) wp_scripts()->query( $handle, $list );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   371
}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   372
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   373
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
 * Add metadata to a script.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   376
 * Works only if the script has already been added.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   377
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   378
 * Possible values for $key and $value:
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   379
 * 'conditional' string Comments for IE 6, lte IE 7, etc.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   380
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   381
 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   382
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   383
 * @see WP_Dependencies::add_data()
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   384
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   385
 * @param string $handle Name of the script.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   386
 * @param string $key    Name of data point for which we're storing a value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   387
 * @param mixed  $value  String containing the data to be added.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   388
 * @return bool True on success, false on failure.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   389
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   390
function wp_script_add_data( $handle, $key, $value ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   391
	return wp_scripts()->add_data( $handle, $key, $value );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
}