Skip to content

Commit e3a6d78

Browse files
committed
Merge branch 'trunk' into 64418/improve-custom-css-handling
2 parents 81679af + fcf6a84 commit e3a6d78

File tree

13 files changed

+356
-85
lines changed

13 files changed

+356
-85
lines changed

src/wp-admin/includes/class-wp-filesystem-direct.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,18 @@ public function owner( $file ) {
249249
/**
250250
* Gets the permissions of the specified file or filepath in their octal format.
251251
*
252-
* FIXME does not handle errors in fileperms()
253-
*
254252
* @since 2.5.0
255253
*
256254
* @param string $file Path to the file.
257-
* @return string Mode of the file (the last 3 digits).
255+
* @return string Mode of the file (the last 3 digits), or the string "0" on failure.
258256
*/
259257
public function getchmod( $file ) {
260-
return substr( decoct( @fileperms( $file ) ), -3 );
258+
$perms = @fileperms( $file );
259+
if ( false === $perms ) {
260+
return '0';
261+
}
262+
263+
return substr( decoct( $perms ), -3 );
261264
}
262265

263266
/**

src/wp-admin/widgets-form.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@
187187

188188
// Remove old position.
189189
if ( ! isset( $_POST['delete_widget'] ) ) {
190-
foreach ( $sidebars_widgets as $sidebar_id => $sidebar ) {
191-
if ( is_array( $sidebar ) ) {
192-
$sidebars_widgets[ $sidebar_id ] = array_diff( $sidebar, array( $widget_id ) );
190+
foreach ( $sidebars_widgets as $sidebar_widget_id => $sidebar_widget ) {
191+
if ( is_array( $sidebar_widget ) ) {
192+
$sidebars_widgets[ $sidebar_widget_id ] = array_diff( $sidebar_widget, array( $widget_id ) );
193193
}
194194
}
195195

src/wp-includes/class-wp-scripts.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,26 @@ class WP_Scripts extends WP_Dependencies {
2222
* Full URL with trailing slash.
2323
*
2424
* @since 2.6.0
25-
* @var string
25+
* @see wp_default_scripts()
26+
* @var string|null
2627
*/
2728
public $base_url;
2829

2930
/**
3031
* URL of the content directory.
3132
*
3233
* @since 2.8.0
33-
* @var string
34+
* @see wp_default_scripts()
35+
* @var string|null
3436
*/
3537
public $content_url;
3638

3739
/**
3840
* Default version string for scripts.
3941
*
4042
* @since 2.6.0
41-
* @var string
43+
* @see wp_default_scripts()
44+
* @var string|null
4245
*/
4346
public $default_version;
4447

@@ -118,6 +121,7 @@ class WP_Scripts extends WP_Dependencies {
118121
* List of default directories.
119122
*
120123
* @since 2.8.0
124+
* @see wp_default_scripts()
121125
* @var string[]|null
122126
*/
123127
public $default_dirs;
@@ -413,9 +417,19 @@ public function do_item( $handle, $group = false ) {
413417
$src = $this->base_url . $src;
414418
}
415419

416-
if ( ! empty( $ver ) ) {
417-
$src = add_query_arg( 'ver', $ver, $src );
420+
$query_args = array();
421+
if ( empty( $obj->ver ) && null !== $obj->ver && is_string( $this->default_version ) ) {
422+
$query_args['ver'] = $this->default_version;
423+
} elseif ( is_scalar( $obj->ver ) ) {
424+
$query_args['ver'] = (string) $obj->ver;
425+
}
426+
if ( isset( $this->args[ $handle ] ) ) {
427+
parse_str( $this->args[ $handle ], $parsed_args );
428+
if ( $parsed_args ) {
429+
$query_args = array_merge( $query_args, $parsed_args );
430+
}
418431
}
432+
$src = add_query_arg( rawurlencode_deep( $query_args ), $src );
419433

420434
/** This filter is documented in wp-includes/class-wp-scripts.php */
421435
$src = esc_url_raw( apply_filters( 'script_loader_src', $src, $handle ) );

src/wp-includes/class-wp-styles.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,34 @@ class WP_Styles extends WP_Dependencies {
2222
* Full URL with trailing slash.
2323
*
2424
* @since 2.6.0
25-
* @var string
25+
* @see wp_default_styles()
26+
* @var string|null
2627
*/
2728
public $base_url;
2829

2930
/**
3031
* URL of the content directory.
3132
*
3233
* @since 2.8.0
33-
* @var string
34+
* @see wp_default_styles()
35+
* @var string|null
3436
*/
3537
public $content_url;
3638

3739
/**
3840
* Default version string for stylesheets.
3941
*
4042
* @since 2.6.0
41-
* @var string
43+
* @see wp_default_styles()
44+
* @var string|null
4245
*/
4346
public $default_version;
4447

4548
/**
4649
* The current text direction.
4750
*
4851
* @since 2.6.0
52+
* @see wp_default_styles()
4953
* @var string
5054
*/
5155
public $text_direction = 'ltr';
@@ -96,6 +100,7 @@ class WP_Styles extends WP_Dependencies {
96100
* List of default directories.
97101
*
98102
* @since 2.8.0
103+
* @see wp_default_styles()
99104
* @var string[]|null
100105
*/
101106
public $default_dirs;
@@ -217,7 +222,7 @@ public function do_item( $handle, $group = false ) {
217222
return true;
218223
}
219224

220-
$href = $this->_css_href( $src, $ver, $handle );
225+
$href = $this->_css_href( $src, $obj->ver, $handle );
221226
if ( ! $href ) {
222227
return true;
223228
}
@@ -423,19 +428,29 @@ public function all_deps( $handles, $recursion = false, $group = false ) {
423428
*
424429
* @since 2.6.0
425430
*
426-
* @param string $src The source of the enqueued style.
427-
* @param string $ver The version of the enqueued style.
428-
* @param string $handle The style's registered handle.
431+
* @param string $src The source of the enqueued style.
432+
* @param string|false|null $ver The version of the enqueued style.
433+
* @param string $handle The style's registered handle.
429434
* @return string Style's fully-qualified URL.
430435
*/
431436
public function _css_href( $src, $ver, $handle ) {
432437
if ( ! is_bool( $src ) && ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && str_starts_with( $src, $this->content_url ) ) ) {
433438
$src = $this->base_url . $src;
434439
}
435440

436-
if ( ! empty( $ver ) ) {
437-
$src = add_query_arg( 'ver', $ver, $src );
441+
$query_args = array();
442+
if ( empty( $ver ) && null !== $ver && is_string( $this->default_version ) ) {
443+
$query_args['ver'] = $this->default_version;
444+
} elseif ( is_scalar( $ver ) ) {
445+
$query_args['ver'] = (string) $ver;
446+
}
447+
if ( isset( $this->args[ $handle ] ) ) {
448+
parse_str( $this->args[ $handle ], $parsed_args );
449+
if ( $parsed_args ) {
450+
$query_args = array_merge( $query_args, $parsed_args );
451+
}
438452
}
453+
$src = add_query_arg( rawurlencode_deep( $query_args ), $src );
439454

440455
/**
441456
* Filters an enqueued style's fully-qualified URL.

src/wp-includes/class-wp-theme-json-resolver.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ public static function get_user_data_from_wp_global_styles( $theme, $create_post
515515

516516
$global_style_query = new WP_Query();
517517
$recent_posts = $global_style_query->query( $args );
518-
if ( count( $recent_posts ) === 1 ) {
518+
if ( count( $recent_posts ) === 1 && $recent_posts[0] instanceof WP_Post ) {
519519
$user_cpt = get_object_vars( $recent_posts[0] );
520520
} elseif ( $create_post ) {
521521
$cpt_post_id = wp_insert_post(
@@ -532,7 +532,10 @@ public static function get_user_data_from_wp_global_styles( $theme, $create_post
532532
true
533533
);
534534
if ( ! is_wp_error( $cpt_post_id ) ) {
535-
$user_cpt = get_object_vars( get_post( $cpt_post_id ) );
535+
$post = get_post( $cpt_post_id );
536+
if ( $post instanceof WP_Post ) {
537+
$user_cpt = get_object_vars( $post );
538+
}
536539
}
537540
}
538541

0 commit comments

Comments
 (0)