2016-08-26 14:06:39 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Dependencies API: _WP_Dependency class
|
|
|
|
*
|
|
|
|
* @since 4.7.0
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class _WP_Dependency
|
|
|
|
*
|
|
|
|
* Helper class to register a handle and associated data.
|
|
|
|
*
|
|
|
|
* @access private
|
|
|
|
* @since 2.6.0
|
|
|
|
*/
|
|
|
|
class _WP_Dependency {
|
|
|
|
/**
|
|
|
|
* The handle name.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
* @var null
|
|
|
|
*/
|
|
|
|
public $handle;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The handle source.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
* @var null
|
|
|
|
*/
|
|
|
|
public $src;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An array of handle dependencies.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $deps = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The handle version.
|
|
|
|
*
|
|
|
|
* Used for cache-busting.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
* @var bool|string
|
|
|
|
*/
|
|
|
|
public $ver = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Additional arguments for the handle.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
* @var null
|
|
|
|
*/
|
|
|
|
public $args = null; // Custom property, such as $in_footer or $media.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extra data to supply to the handle.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $extra = array();
|
|
|
|
|
I18N: Add JavaScript translation support.
Adds the `wp_set_script_translations()` function which registers translations for a JavaScript file. This function takes a handle, domain and optionally a path and ensures JavaScript translation files are loaded if they exist.
Merges [43825,43828,43859,43898] from the 5.0 branch to trunk.
Props herregroen, atimmer, omarreiss, nerrad, swissspidy, ocean90, georgestephanis.
Fixes #45103, #45256.
Built from https://develop.svn.wordpress.org/trunk@44169
git-svn-id: http://core.svn.wordpress.org/trunk@43999 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-12-14 00:52:52 -05:00
|
|
|
/**
|
|
|
|
* Translation textdomain set for this dependency.
|
|
|
|
*
|
|
|
|
* @since 5.0.0
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $textdomain;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Translation path set for this dependency.
|
|
|
|
*
|
|
|
|
* @since 5.0.0
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public $translations_path;
|
|
|
|
|
2016-08-26 14:06:39 -04:00
|
|
|
/**
|
|
|
|
* Setup dependencies.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
2019-09-15 06:36:56 -04:00
|
|
|
*
|
|
|
|
* @param ...$args Dependency information.
|
2016-08-26 14:06:39 -04:00
|
|
|
*/
|
2019-09-15 06:36:56 -04:00
|
|
|
public function __construct( ...$args ) {
|
|
|
|
list( $this->handle, $this->src, $this->deps, $this->ver, $this->args ) = $args;
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! is_array( $this->deps ) ) {
|
2016-08-26 14:06:39 -04:00
|
|
|
$this->deps = array();
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2016-08-26 14:06:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add handle data.
|
|
|
|
*
|
|
|
|
* @since 2.6.0
|
|
|
|
*
|
|
|
|
* @param string $name The data key to add.
|
|
|
|
* @param mixed $data The data value to add.
|
|
|
|
* @return bool False if not scalar, true otherwise.
|
|
|
|
*/
|
|
|
|
public function add_data( $name, $data ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! is_scalar( $name ) ) {
|
2016-08-26 14:06:39 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
|
|
|
$this->extra[ $name ] = $data;
|
2016-08-26 14:06:39 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-15 17:48:51 -05:00
|
|
|
/**
|
|
|
|
* Sets the translation domain for this dependency.
|
|
|
|
*
|
|
|
|
* @since 5.0.0
|
|
|
|
*
|
|
|
|
* @param string $domain The translation textdomain.
|
|
|
|
* @param string $path Optional. The full file path to the directory containing translation files.
|
|
|
|
*
|
|
|
|
* @return bool False if $domain is not a string, true otherwise.
|
|
|
|
*/
|
I18N: Add JavaScript translation support.
Adds the `wp_set_script_translations()` function which registers translations for a JavaScript file. This function takes a handle, domain and optionally a path and ensures JavaScript translation files are loaded if they exist.
Merges [43825,43828,43859,43898] from the 5.0 branch to trunk.
Props herregroen, atimmer, omarreiss, nerrad, swissspidy, ocean90, georgestephanis.
Fixes #45103, #45256.
Built from https://develop.svn.wordpress.org/trunk@44169
git-svn-id: http://core.svn.wordpress.org/trunk@43999 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-12-14 00:52:52 -05:00
|
|
|
public function set_translations( $domain, $path = null ) {
|
|
|
|
if ( ! is_string( $domain ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$this->textdomain = $domain;
|
|
|
|
$this->translations_path = $path;
|
|
|
|
return true;
|
|
|
|
}
|
2016-08-26 14:06:39 -04:00
|
|
|
}
|