mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-01 03:04:34 +00:00
Code is Poetry.
WordPress' code just... wasn't. This is now dealt with. Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS. Fixes #41057. git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -145,7 +145,7 @@ class WP_Scripts extends WP_Dependencies {
|
||||
*
|
||||
* @param WP_Scripts $this WP_Scripts instance (passed by reference).
|
||||
*/
|
||||
do_action_ref_array( 'wp_default_scripts', array(&$this) );
|
||||
do_action_ref_array( 'wp_default_scripts', array( &$this ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,11 +196,13 @@ class WP_Scripts extends WP_Dependencies {
|
||||
* @return bool|string|void Void if no data exists, extra scripts if `$echo` is true, true otherwise.
|
||||
*/
|
||||
public function print_extra_script( $handle, $echo = true ) {
|
||||
if ( !$output = $this->get_data( $handle, 'data' ) )
|
||||
if ( ! $output = $this->get_data( $handle, 'data' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !$echo )
|
||||
if ( ! $echo ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
echo "<script type='text/javascript'>\n"; // CDATA and type='text/javascript' is not needed for HTML 5
|
||||
echo "/* <![CDATA[ */\n";
|
||||
@@ -224,18 +226,20 @@ class WP_Scripts extends WP_Dependencies {
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
public function do_item( $handle, $group = false ) {
|
||||
if ( !parent::do_item($handle) )
|
||||
if ( ! parent::do_item( $handle ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( 0 === $group && $this->groups[$handle] > 0 ) {
|
||||
if ( 0 === $group && $this->groups[ $handle ] > 0 ) {
|
||||
$this->in_footer[] = $handle;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( false === $group && in_array($handle, $this->in_footer, true) )
|
||||
if ( false === $group && in_array( $handle, $this->in_footer, true ) ) {
|
||||
$this->in_footer = array_diff( $this->in_footer, (array) $handle );
|
||||
}
|
||||
|
||||
$obj = $this->registered[$handle];
|
||||
$obj = $this->registered[ $handle ];
|
||||
|
||||
if ( null === $obj->ver ) {
|
||||
$ver = '';
|
||||
@@ -243,20 +247,21 @@ class WP_Scripts extends WP_Dependencies {
|
||||
$ver = $obj->ver ? $obj->ver : $this->default_version;
|
||||
}
|
||||
|
||||
if ( isset($this->args[$handle]) )
|
||||
$ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle];
|
||||
if ( isset( $this->args[ $handle ] ) ) {
|
||||
$ver = $ver ? $ver . '&' . $this->args[ $handle ] : $this->args[ $handle ];
|
||||
}
|
||||
|
||||
$src = $obj->src;
|
||||
$src = $obj->src;
|
||||
$cond_before = $cond_after = '';
|
||||
$conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
|
||||
|
||||
if ( $conditional ) {
|
||||
$cond_before = "<!--[if {$conditional}]>\n";
|
||||
$cond_after = "<![endif]-->\n";
|
||||
$cond_after = "<![endif]-->\n";
|
||||
}
|
||||
|
||||
$before_handle = $this->print_inline_script( $handle, 'before', false );
|
||||
$after_handle = $this->print_inline_script( $handle, 'after', false );
|
||||
$after_handle = $this->print_inline_script( $handle, 'after', false );
|
||||
|
||||
if ( $before_handle ) {
|
||||
$before_handle = sprintf( "<script type='text/javascript'>\n%s\n</script>\n", $before_handle );
|
||||
@@ -284,8 +289,8 @@ class WP_Scripts extends WP_Dependencies {
|
||||
_print_scripts();
|
||||
$this->reset();
|
||||
} elseif ( $this->in_default_dir( $srce ) && ! $conditional ) {
|
||||
$this->print_code .= $this->print_extra_script( $handle, false );
|
||||
$this->concat .= "$handle,";
|
||||
$this->print_code .= $this->print_extra_script( $handle, false );
|
||||
$this->concat .= "$handle,";
|
||||
$this->concat_version .= "$handle$ver";
|
||||
return true;
|
||||
} else {
|
||||
@@ -315,14 +320,16 @@ class WP_Scripts extends WP_Dependencies {
|
||||
$src = $this->base_url . $src;
|
||||
}
|
||||
|
||||
if ( ! empty( $ver ) )
|
||||
if ( ! empty( $ver ) ) {
|
||||
$src = add_query_arg( 'ver', $ver, $src );
|
||||
}
|
||||
|
||||
/** This filter is documented in wp-includes/class.wp-scripts.php */
|
||||
$src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
|
||||
|
||||
if ( ! $src )
|
||||
if ( ! $src ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$tag = "{$cond_before}{$before_handle}<script type='text/javascript' src='$src'></script>\n{$after_handle}{$cond_after}";
|
||||
|
||||
@@ -411,30 +418,34 @@ class WP_Scripts extends WP_Dependencies {
|
||||
* @return bool
|
||||
*/
|
||||
public function localize( $handle, $object_name, $l10n ) {
|
||||
if ( $handle === 'jquery' )
|
||||
if ( $handle === 'jquery' ) {
|
||||
$handle = 'jquery-core';
|
||||
}
|
||||
|
||||
if ( is_array($l10n) && isset($l10n['l10n_print_after']) ) { // back compat, preserve the code in 'l10n_print_after' if present
|
||||
if ( is_array( $l10n ) && isset( $l10n['l10n_print_after'] ) ) { // back compat, preserve the code in 'l10n_print_after' if present
|
||||
$after = $l10n['l10n_print_after'];
|
||||
unset($l10n['l10n_print_after']);
|
||||
unset( $l10n['l10n_print_after'] );
|
||||
}
|
||||
|
||||
foreach ( (array) $l10n as $key => $value ) {
|
||||
if ( !is_scalar($value) )
|
||||
if ( ! is_scalar( $value ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8');
|
||||
$l10n[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
|
||||
}
|
||||
|
||||
$script = "var $object_name = " . wp_json_encode( $l10n ) . ';';
|
||||
|
||||
if ( !empty($after) )
|
||||
if ( ! empty( $after ) ) {
|
||||
$script .= "\n$after;";
|
||||
}
|
||||
|
||||
$data = $this->get_data( $handle, 'data' );
|
||||
|
||||
if ( !empty( $data ) )
|
||||
if ( ! empty( $data ) ) {
|
||||
$script = "$data\n$script";
|
||||
}
|
||||
|
||||
return $this->add_data( $handle, 'data', $script );
|
||||
}
|
||||
@@ -452,20 +463,22 @@ class WP_Scripts extends WP_Dependencies {
|
||||
* @return bool Not already in the group or a lower group
|
||||
*/
|
||||
public function set_group( $handle, $recursion, $group = false ) {
|
||||
if ( isset( $this->registered[$handle]->args ) && $this->registered[$handle]->args === 1 )
|
||||
if ( isset( $this->registered[ $handle ]->args ) && $this->registered[ $handle ]->args === 1 ) {
|
||||
$grp = 1;
|
||||
else
|
||||
} else {
|
||||
$grp = (int) $this->get_data( $handle, 'group' );
|
||||
}
|
||||
|
||||
if ( false !== $group && $grp > $group )
|
||||
if ( false !== $group && $grp > $group ) {
|
||||
$grp = $group;
|
||||
}
|
||||
|
||||
return parent::set_group( $handle, $recursion, $grp );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines script dependencies.
|
||||
*
|
||||
*
|
||||
* @since 2.1.0
|
||||
*
|
||||
* @see WP_Dependencies::all_deps()
|
||||
@@ -500,7 +513,7 @@ class WP_Scripts extends WP_Dependencies {
|
||||
* @return array Handles of items that have been processed.
|
||||
*/
|
||||
public function do_head_items() {
|
||||
$this->do_items(false, 0);
|
||||
$this->do_items( false, 0 );
|
||||
return $this->done;
|
||||
}
|
||||
|
||||
@@ -514,7 +527,7 @@ class WP_Scripts extends WP_Dependencies {
|
||||
* @return array Handles of items that have been processed.
|
||||
*/
|
||||
public function do_footer_items() {
|
||||
$this->do_items(false, 1);
|
||||
$this->do_items( false, 1 );
|
||||
return $this->done;
|
||||
}
|
||||
|
||||
@@ -549,12 +562,12 @@ class WP_Scripts extends WP_Dependencies {
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function reset() {
|
||||
$this->do_concat = false;
|
||||
$this->print_code = '';
|
||||
$this->concat = '';
|
||||
$this->do_concat = false;
|
||||
$this->print_code = '';
|
||||
$this->concat = '';
|
||||
$this->concat_version = '';
|
||||
$this->print_html = '';
|
||||
$this->ext_version = '';
|
||||
$this->ext_handles = '';
|
||||
$this->print_html = '';
|
||||
$this->ext_version = '';
|
||||
$this->ext_handles = '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user