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