Edit File by line
/home/barbar84/public_h.../wp-inclu...
File: class.wp-dependencies.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Dependencies API: WP_Dependencies base class
[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
* Core base class extended to register items.
[11] Fix | Delete
*
[12] Fix | Delete
* @since 2.6.0
[13] Fix | Delete
*
[14] Fix | Delete
* @see _WP_Dependency
[15] Fix | Delete
*/
[16] Fix | Delete
class WP_Dependencies {
[17] Fix | Delete
/**
[18] Fix | Delete
* An array of registered handle objects.
[19] Fix | Delete
*
[20] Fix | Delete
* @since 2.6.8
[21] Fix | Delete
* @var array
[22] Fix | Delete
*/
[23] Fix | Delete
public $registered = array();
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* An array of handles of queued objects.
[27] Fix | Delete
*
[28] Fix | Delete
* @since 2.6.8
[29] Fix | Delete
* @var string[]
[30] Fix | Delete
*/
[31] Fix | Delete
public $queue = array();
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* An array of handles of objects to queue.
[35] Fix | Delete
*
[36] Fix | Delete
* @since 2.6.0
[37] Fix | Delete
* @var string[]
[38] Fix | Delete
*/
[39] Fix | Delete
public $to_do = array();
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* An array of handles of objects already queued.
[43] Fix | Delete
*
[44] Fix | Delete
* @since 2.6.0
[45] Fix | Delete
* @var string[]
[46] Fix | Delete
*/
[47] Fix | Delete
public $done = array();
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* An array of additional arguments passed when a handle is registered.
[51] Fix | Delete
*
[52] Fix | Delete
* Arguments are appended to the item query string.
[53] Fix | Delete
*
[54] Fix | Delete
* @since 2.6.0
[55] Fix | Delete
* @var array
[56] Fix | Delete
*/
[57] Fix | Delete
public $args = array();
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* An array of handle groups to enqueue.
[61] Fix | Delete
*
[62] Fix | Delete
* @since 2.8.0
[63] Fix | Delete
* @var array
[64] Fix | Delete
*/
[65] Fix | Delete
public $groups = array();
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* A handle group to enqueue.
[69] Fix | Delete
*
[70] Fix | Delete
* @since 2.8.0
[71] Fix | Delete
* @deprecated 4.5.0
[72] Fix | Delete
* @var int
[73] Fix | Delete
*/
[74] Fix | Delete
public $group = 0;
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Cached lookup array of flattened queued items and dependencies.
[78] Fix | Delete
*
[79] Fix | Delete
* @since 5.4.0
[80] Fix | Delete
* @var array
[81] Fix | Delete
*/
[82] Fix | Delete
private $all_queued_deps;
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* Processes the items and dependencies.
[86] Fix | Delete
*
[87] Fix | Delete
* Processes the items passed to it or the queue, and their dependencies.
[88] Fix | Delete
*
[89] Fix | Delete
* @since 2.6.0
[90] Fix | Delete
* @since 2.8.0 Added the `$group` parameter.
[91] Fix | Delete
*
[92] Fix | Delete
* @param string|string[]|false $handles Optional. Items to be processed: queue (false),
[93] Fix | Delete
* single item (string), or multiple items (array of strings).
[94] Fix | Delete
* Default false.
[95] Fix | Delete
* @param int|false $group Optional. Group level: level (int), no groups (false).
[96] Fix | Delete
* @return string[] Array of handles of items that have been processed.
[97] Fix | Delete
*/
[98] Fix | Delete
public function do_items( $handles = false, $group = false ) {
[99] Fix | Delete
/*
[100] Fix | Delete
* If nothing is passed, print the queue. If a string is passed,
[101] Fix | Delete
* print that item. If an array is passed, print those items.
[102] Fix | Delete
*/
[103] Fix | Delete
$handles = false === $handles ? $this->queue : (array) $handles;
[104] Fix | Delete
$this->all_deps( $handles );
[105] Fix | Delete
[106] Fix | Delete
foreach ( $this->to_do as $key => $handle ) {
[107] Fix | Delete
if ( ! in_array( $handle, $this->done, true ) && isset( $this->registered[ $handle ] ) ) {
[108] Fix | Delete
/*
[109] Fix | Delete
* Attempt to process the item. If successful,
[110] Fix | Delete
* add the handle to the done array.
[111] Fix | Delete
*
[112] Fix | Delete
* Unset the item from the to_do array.
[113] Fix | Delete
*/
[114] Fix | Delete
if ( $this->do_item( $handle, $group ) ) {
[115] Fix | Delete
$this->done[] = $handle;
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
unset( $this->to_do[ $key ] );
[119] Fix | Delete
}
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
return $this->done;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
/**
[126] Fix | Delete
* Processes a dependency.
[127] Fix | Delete
*
[128] Fix | Delete
* @since 2.6.0
[129] Fix | Delete
* @since 5.5.0 Added the `$group` parameter.
[130] Fix | Delete
*
[131] Fix | Delete
* @param string $handle Name of the item. Should be unique.
[132] Fix | Delete
* @param int|false $group Optional. Group level: level (int), no groups (false).
[133] Fix | Delete
* Default false.
[134] Fix | Delete
* @return bool True on success, false if not set.
[135] Fix | Delete
*/
[136] Fix | Delete
public function do_item( $handle, $group = false ) {
[137] Fix | Delete
return isset( $this->registered[ $handle ] );
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
/**
[141] Fix | Delete
* Determines dependencies.
[142] Fix | Delete
*
[143] Fix | Delete
* Recursively builds an array of items to process taking
[144] Fix | Delete
* dependencies into account. Does NOT catch infinite loops.
[145] Fix | Delete
*
[146] Fix | Delete
* @since 2.1.0
[147] Fix | Delete
* @since 2.6.0 Moved from `WP_Scripts`.
[148] Fix | Delete
* @since 2.8.0 Added the `$group` parameter.
[149] Fix | Delete
*
[150] Fix | Delete
* @param string|string[] $handles Item handle (string) or item handles (array of strings).
[151] Fix | Delete
* @param bool $recursion Optional. Internal flag that function is calling itself.
[152] Fix | Delete
* Default false.
[153] Fix | Delete
* @param int|false $group Optional. Group level: level (int), no groups (false).
[154] Fix | Delete
* Default false.
[155] Fix | Delete
* @return bool True on success, false on failure.
[156] Fix | Delete
*/
[157] Fix | Delete
public function all_deps( $handles, $recursion = false, $group = false ) {
[158] Fix | Delete
$handles = (array) $handles;
[159] Fix | Delete
if ( ! $handles ) {
[160] Fix | Delete
return false;
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
foreach ( $handles as $handle ) {
[164] Fix | Delete
$handle_parts = explode( '?', $handle );
[165] Fix | Delete
$handle = $handle_parts[0];
[166] Fix | Delete
$queued = in_array( $handle, $this->to_do, true );
[167] Fix | Delete
[168] Fix | Delete
if ( in_array( $handle, $this->done, true ) ) { // Already done.
[169] Fix | Delete
continue;
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
$moved = $this->set_group( $handle, $recursion, $group );
[173] Fix | Delete
$new_group = $this->groups[ $handle ];
[174] Fix | Delete
[175] Fix | Delete
if ( $queued && ! $moved ) { // Already queued and in the right group.
[176] Fix | Delete
continue;
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
$keep_going = true;
[180] Fix | Delete
if ( ! isset( $this->registered[ $handle ] ) ) {
[181] Fix | Delete
$keep_going = false; // Item doesn't exist.
[182] Fix | Delete
} elseif ( $this->registered[ $handle ]->deps && array_diff( $this->registered[ $handle ]->deps, array_keys( $this->registered ) ) ) {
[183] Fix | Delete
$keep_going = false; // Item requires dependencies that don't exist.
[184] Fix | Delete
} elseif ( $this->registered[ $handle ]->deps && ! $this->all_deps( $this->registered[ $handle ]->deps, true, $new_group ) ) {
[185] Fix | Delete
$keep_going = false; // Item requires dependencies that don't exist.
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
if ( ! $keep_going ) { // Either item or its dependencies don't exist.
[189] Fix | Delete
if ( $recursion ) {
[190] Fix | Delete
return false; // Abort this branch.
[191] Fix | Delete
} else {
[192] Fix | Delete
continue; // We're at the top level. Move on to the next one.
[193] Fix | Delete
}
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
if ( $queued ) { // Already grabbed it and its dependencies.
[197] Fix | Delete
continue;
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
if ( isset( $handle_parts[1] ) ) {
[201] Fix | Delete
$this->args[ $handle ] = $handle_parts[1];
[202] Fix | Delete
}
[203] Fix | Delete
[204] Fix | Delete
$this->to_do[] = $handle;
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
return true;
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
/**
[211] Fix | Delete
* Register an item.
[212] Fix | Delete
*
[213] Fix | Delete
* Registers the item if no item of that name already exists.
[214] Fix | Delete
*
[215] Fix | Delete
* @since 2.1.0
[216] Fix | Delete
* @since 2.6.0 Moved from `WP_Scripts`.
[217] Fix | Delete
*
[218] Fix | Delete
* @param string $handle Name of the item. Should be unique.
[219] Fix | Delete
* @param string|bool $src Full URL of the item, or path of the item relative
[220] Fix | Delete
* to the WordPress root directory. If source is set to false,
[221] Fix | Delete
* item is an alias of other items it depends on.
[222] Fix | Delete
* @param string[] $deps Optional. An array of registered item handles this item depends on.
[223] Fix | Delete
* Default empty array.
[224] Fix | Delete
* @param string|bool|null $ver Optional. String specifying item version number, if it has one,
[225] Fix | Delete
* which is added to the URL as a query string for cache busting purposes.
[226] Fix | Delete
* If version is set to false, a version number is automatically added
[227] Fix | Delete
* equal to current installed WordPress version.
[228] Fix | Delete
* If set to null, no version is added.
[229] Fix | Delete
* @param mixed $args Optional. Custom property of the item. NOT the class property $args.
[230] Fix | Delete
* Examples: $media, $in_footer.
[231] Fix | Delete
* @return bool Whether the item has been registered. True on success, false on failure.
[232] Fix | Delete
*/
[233] Fix | Delete
public function add( $handle, $src, $deps = array(), $ver = false, $args = null ) {
[234] Fix | Delete
if ( isset( $this->registered[ $handle ] ) ) {
[235] Fix | Delete
return false;
[236] Fix | Delete
}
[237] Fix | Delete
$this->registered[ $handle ] = new _WP_Dependency( $handle, $src, $deps, $ver, $args );
[238] Fix | Delete
return true;
[239] Fix | Delete
}
[240] Fix | Delete
[241] Fix | Delete
/**
[242] Fix | Delete
* Add extra item data.
[243] Fix | Delete
*
[244] Fix | Delete
* Adds data to a registered item.
[245] Fix | Delete
*
[246] Fix | Delete
* @since 2.6.0
[247] Fix | Delete
*
[248] Fix | Delete
* @param string $handle Name of the item. Should be unique.
[249] Fix | Delete
* @param string $key The data key.
[250] Fix | Delete
* @param mixed $value The data value.
[251] Fix | Delete
* @return bool True on success, false on failure.
[252] Fix | Delete
*/
[253] Fix | Delete
public function add_data( $handle, $key, $value ) {
[254] Fix | Delete
if ( ! isset( $this->registered[ $handle ] ) ) {
[255] Fix | Delete
return false;
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
return $this->registered[ $handle ]->add_data( $key, $value );
[259] Fix | Delete
}
[260] Fix | Delete
[261] Fix | Delete
/**
[262] Fix | Delete
* Get extra item data.
[263] Fix | Delete
*
[264] Fix | Delete
* Gets data associated with a registered item.
[265] Fix | Delete
*
[266] Fix | Delete
* @since 3.3.0
[267] Fix | Delete
*
[268] Fix | Delete
* @param string $handle Name of the item. Should be unique.
[269] Fix | Delete
* @param string $key The data key.
[270] Fix | Delete
* @return mixed Extra item data (string), false otherwise.
[271] Fix | Delete
*/
[272] Fix | Delete
public function get_data( $handle, $key ) {
[273] Fix | Delete
if ( ! isset( $this->registered[ $handle ] ) ) {
[274] Fix | Delete
return false;
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
if ( ! isset( $this->registered[ $handle ]->extra[ $key ] ) ) {
[278] Fix | Delete
return false;
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
return $this->registered[ $handle ]->extra[ $key ];
[282] Fix | Delete
}
[283] Fix | Delete
[284] Fix | Delete
/**
[285] Fix | Delete
* Un-register an item or items.
[286] Fix | Delete
*
[287] Fix | Delete
* @since 2.1.0
[288] Fix | Delete
* @since 2.6.0 Moved from `WP_Scripts`.
[289] Fix | Delete
*
[290] Fix | Delete
* @param string|string[] $handles Item handle (string) or item handles (array of strings).
[291] Fix | Delete
*/
[292] Fix | Delete
public function remove( $handles ) {
[293] Fix | Delete
foreach ( (array) $handles as $handle ) {
[294] Fix | Delete
unset( $this->registered[ $handle ] );
[295] Fix | Delete
}
[296] Fix | Delete
}
[297] Fix | Delete
[298] Fix | Delete
/**
[299] Fix | Delete
* Queue an item or items.
[300] Fix | Delete
*
[301] Fix | Delete
* Decodes handles and arguments, then queues handles and stores
[302] Fix | Delete
* arguments in the class property $args. For example in extending
[303] Fix | Delete
* classes, $args is appended to the item url as a query string.
[304] Fix | Delete
* Note $args is NOT the $args property of items in the $registered array.
[305] Fix | Delete
*
[306] Fix | Delete
* @since 2.1.0
[307] Fix | Delete
* @since 2.6.0 Moved from `WP_Scripts`.
[308] Fix | Delete
*
[309] Fix | Delete
* @param string|string[] $handles Item handle (string) or item handles (array of strings).
[310] Fix | Delete
*/
[311] Fix | Delete
public function enqueue( $handles ) {
[312] Fix | Delete
foreach ( (array) $handles as $handle ) {
[313] Fix | Delete
$handle = explode( '?', $handle );
[314] Fix | Delete
[315] Fix | Delete
if ( ! in_array( $handle[0], $this->queue, true ) && isset( $this->registered[ $handle[0] ] ) ) {
[316] Fix | Delete
$this->queue[] = $handle[0];
[317] Fix | Delete
[318] Fix | Delete
// Reset all dependencies so they must be recalculated in recurse_deps().
[319] Fix | Delete
$this->all_queued_deps = null;
[320] Fix | Delete
[321] Fix | Delete
if ( isset( $handle[1] ) ) {
[322] Fix | Delete
$this->args[ $handle[0] ] = $handle[1];
[323] Fix | Delete
}
[324] Fix | Delete
}
[325] Fix | Delete
}
[326] Fix | Delete
}
[327] Fix | Delete
[328] Fix | Delete
/**
[329] Fix | Delete
* Dequeue an item or items.
[330] Fix | Delete
*
[331] Fix | Delete
* Decodes handles and arguments, then dequeues handles
[332] Fix | Delete
* and removes arguments from the class property $args.
[333] Fix | Delete
*
[334] Fix | Delete
* @since 2.1.0
[335] Fix | Delete
* @since 2.6.0 Moved from `WP_Scripts`.
[336] Fix | Delete
*
[337] Fix | Delete
* @param string|string[] $handles Item handle (string) or item handles (array of strings).
[338] Fix | Delete
*/
[339] Fix | Delete
public function dequeue( $handles ) {
[340] Fix | Delete
foreach ( (array) $handles as $handle ) {
[341] Fix | Delete
$handle = explode( '?', $handle );
[342] Fix | Delete
$key = array_search( $handle[0], $this->queue, true );
[343] Fix | Delete
[344] Fix | Delete
if ( false !== $key ) {
[345] Fix | Delete
// Reset all dependencies so they must be recalculated in recurse_deps().
[346] Fix | Delete
$this->all_queued_deps = null;
[347] Fix | Delete
[348] Fix | Delete
unset( $this->queue[ $key ] );
[349] Fix | Delete
unset( $this->args[ $handle[0] ] );
[350] Fix | Delete
}
[351] Fix | Delete
}
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
/**
[355] Fix | Delete
* Recursively search the passed dependency tree for $handle.
[356] Fix | Delete
*
[357] Fix | Delete
* @since 4.0.0
[358] Fix | Delete
*
[359] Fix | Delete
* @param string[] $queue An array of queued _WP_Dependency handles.
[360] Fix | Delete
* @param string $handle Name of the item. Should be unique.
[361] Fix | Delete
* @return bool Whether the handle is found after recursively searching the dependency tree.
[362] Fix | Delete
*/
[363] Fix | Delete
protected function recurse_deps( $queue, $handle ) {
[364] Fix | Delete
if ( isset( $this->all_queued_deps ) ) {
[365] Fix | Delete
return isset( $this->all_queued_deps[ $handle ] );
[366] Fix | Delete
}
[367] Fix | Delete
[368] Fix | Delete
$all_deps = array_fill_keys( $queue, true );
[369] Fix | Delete
$queues = array();
[370] Fix | Delete
$done = array();
[371] Fix | Delete
[372] Fix | Delete
while ( $queue ) {
[373] Fix | Delete
foreach ( $queue as $queued ) {
[374] Fix | Delete
if ( ! isset( $done[ $queued ] ) && isset( $this->registered[ $queued ] ) ) {
[375] Fix | Delete
$deps = $this->registered[ $queued ]->deps;
[376] Fix | Delete
if ( $deps ) {
[377] Fix | Delete
$all_deps += array_fill_keys( $deps, true );
[378] Fix | Delete
array_push( $queues, $deps );
[379] Fix | Delete
}
[380] Fix | Delete
$done[ $queued ] = true;
[381] Fix | Delete
}
[382] Fix | Delete
}
[383] Fix | Delete
$queue = array_pop( $queues );
[384] Fix | Delete
}
[385] Fix | Delete
[386] Fix | Delete
$this->all_queued_deps = $all_deps;
[387] Fix | Delete
[388] Fix | Delete
return isset( $this->all_queued_deps[ $handle ] );
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
/**
[392] Fix | Delete
* Query list for an item.
[393] Fix | Delete
*
[394] Fix | Delete
* @since 2.1.0
[395] Fix | Delete
* @since 2.6.0 Moved from `WP_Scripts`.
[396] Fix | Delete
*
[397] Fix | Delete
* @param string $handle Name of the item. Should be unique.
[398] Fix | Delete
* @param string $list Optional. Property name of list array. Default 'registered'.
[399] Fix | Delete
* @return bool|_WP_Dependency Found, or object Item data.
[400] Fix | Delete
*/
[401] Fix | Delete
public function query( $handle, $list = 'registered' ) {
[402] Fix | Delete
switch ( $list ) {
[403] Fix | Delete
case 'registered':
[404] Fix | Delete
case 'scripts': // Back compat.
[405] Fix | Delete
if ( isset( $this->registered[ $handle ] ) ) {
[406] Fix | Delete
return $this->registered[ $handle ];
[407] Fix | Delete
}
[408] Fix | Delete
return false;
[409] Fix | Delete
[410] Fix | Delete
case 'enqueued':
[411] Fix | Delete
case 'queue':
[412] Fix | Delete
if ( in_array( $handle, $this->queue, true ) ) {
[413] Fix | Delete
return true;
[414] Fix | Delete
}
[415] Fix | Delete
return $this->recurse_deps( $this->queue, $handle );
[416] Fix | Delete
[417] Fix | Delete
case 'to_do':
[418] Fix | Delete
case 'to_print': // Back compat.
[419] Fix | Delete
return in_array( $handle, $this->to_do, true );
[420] Fix | Delete
[421] Fix | Delete
case 'done':
[422] Fix | Delete
case 'printed': // Back compat.
[423] Fix | Delete
return in_array( $handle, $this->done, true );
[424] Fix | Delete
}
[425] Fix | Delete
return false;
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
/**
[429] Fix | Delete
* Set item group, unless already in a lower group.
[430] Fix | Delete
*
[431] Fix | Delete
* @since 2.8.0
[432] Fix | Delete
*
[433] Fix | Delete
* @param string $handle Name of the item. Should be unique.
[434] Fix | Delete
* @param bool $recursion Internal flag that calling function was called recursively.
[435] Fix | Delete
* @param int|false $group Group level: level (int), no groups (false).
[436] Fix | Delete
* @return bool Not already in the group or a lower group.
[437] Fix | Delete
*/
[438] Fix | Delete
public function set_group( $handle, $recursion, $group ) {
[439] Fix | Delete
$group = (int) $group;
[440] Fix | Delete
[441] Fix | Delete
if ( isset( $this->groups[ $handle ] ) && $this->groups[ $handle ] <= $group ) {
[442] Fix | Delete
return false;
[443] Fix | Delete
}
[444] Fix | Delete
[445] Fix | Delete
$this->groups[ $handle ] = $group;
[446] Fix | Delete
[447] Fix | Delete
return true;
[448] Fix | Delete
}
[449] Fix | Delete
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function