Skip to content

Commit

Permalink
Merge branch 'trunk' into dependencies/npm-set-prefer-dedupe
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Oct 10, 2024
2 parents 5929b93 + 292769d commit 5e67967
Show file tree
Hide file tree
Showing 17 changed files with 253 additions and 25,893 deletions.
3 changes: 2 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
save-exact = true
engine-strict = true
legacy-peer-deps = true
lockfile-version = 3
prefer-dedupe = true
save-exact = true
25,804 changes: 1 addition & 25,803 deletions package-lock.json

Large diffs are not rendered by default.

62 changes: 42 additions & 20 deletions src/js/_enqueues/wp/customize/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -4602,26 +4602,29 @@
* @return {Object} Options
*/
calculateImageSelectOptions: function( attachment, controller ) {
var control = controller.get( 'control' ),
flexWidth = !! parseInt( control.params.flex_width, 10 ),
flexHeight = !! parseInt( control.params.flex_height, 10 ),
realWidth = attachment.get( 'width' ),
realHeight = attachment.get( 'height' ),
xInit = parseInt( control.params.width, 10 ),
yInit = parseInt( control.params.height, 10 ),
ratio = xInit / yInit,
xImg = xInit,
yImg = yInit,
var control = controller.get( 'control' ),
flexWidth = !! parseInt( control.params.flex_width, 10 ),
flexHeight = !! parseInt( control.params.flex_height, 10 ),
realWidth = attachment.get( 'width' ),
realHeight = attachment.get( 'height' ),
xInit = parseInt( control.params.width, 10 ),
yInit = parseInt( control.params.height, 10 ),
requiredRatio = xInit / yInit,
realRatio = realWidth / realHeight,
xImg = xInit,
yImg = yInit,
x1, y1, imgSelectOptions;

controller.set( 'hasRequiredAspectRatio', control.hasRequiredAspectRatio( requiredRatio, realRatio ) );
controller.set( 'suggestedCropSize', { width: realWidth, height: realHeight, x1: 0, y1: 0, x2: xInit, y2: yInit } );
controller.set( 'canSkipCrop', ! control.mustBeCropped( flexWidth, flexHeight, xInit, yInit, realWidth, realHeight ) );

if ( realWidth / realHeight > ratio ) {
if ( realRatio > requiredRatio ) {
yInit = realHeight;
xInit = yInit * ratio;
xInit = yInit * requiredRatio;
} else {
xInit = realWidth;
yInit = xInit / ratio;
yInit = xInit / requiredRatio;
}

x1 = ( realWidth - xInit ) / 2;
Expand Down Expand Up @@ -4662,13 +4665,13 @@
/**
* Return whether the image must be cropped, based on required dimensions.
*
* @param {boolean} flexW
* @param {boolean} flexH
* @param {number} dstW
* @param {number} dstH
* @param {number} imgW
* @param {number} imgH
* @return {boolean}
* @param {boolean} flexW Width is flexible.
* @param {boolean} flexH Height is flexible.
* @param {number} dstW Required width.
* @param {number} dstH Required height.
* @param {number} imgW Provided image's width.
* @param {number} imgH Provided image's height.
* @return {boolean} Whether cropping is required.
*/
mustBeCropped: function( flexW, flexH, dstW, dstH, imgW, imgH ) {
if ( true === flexW && true === flexH ) {
Expand All @@ -4694,6 +4697,25 @@
return true;
},

/**
* Check if the image's aspect ratio essentially matches the required aspect ratio.
*
* Floating point precision is low, so this allows a small tolerance. This
* tolerance allows for images over 100,000 px on either side to still trigger
* the cropping flow.
*
* @param {number} requiredRatio Required image ratio.
* @param {number} realRatio Provided image ratio.
* @return {boolean} Whether the image has the required aspect ratio.
*/
hasRequiredAspectRatio: function ( requiredRatio, realRatio ) {
if ( Math.abs( requiredRatio - realRatio ) < 0.000001 ) {
return true;
}

return false;
},

/**
* If cropping was skipped, apply the image data directly to the setting.
*/
Expand Down
32 changes: 25 additions & 7 deletions src/js/media/controllers/cropper.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ Cropper = wp.media.controller.State.extend(/** @lends wp.media.controller.Croppe
* @return {void}
*/
createCropToolbar: function() {
var canSkipCrop, toolbarOptions;
var canSkipCrop, hasRequiredAspectRatio, suggestedCropSize, toolbarOptions;

canSkipCrop = this.get('canSkipCrop') || false;
suggestedCropSize = this.get( 'suggestedCropSize' );
hasRequiredAspectRatio = this.get( 'hasRequiredAspectRatio' );
canSkipCrop = this.get( 'canSkipCrop' ) || false;

toolbarOptions = {
controller: this.frame,
Expand Down Expand Up @@ -127,18 +129,34 @@ Cropper = wp.media.controller.State.extend(/** @lends wp.media.controller.Croppe
}
};

if ( canSkipCrop ) {
if ( canSkipCrop || hasRequiredAspectRatio ) {
_.extend( toolbarOptions.items, {
skip: {
style: 'secondary',
text: l10n.skipCropping,
priority: 70,
requires: { library: false, selection: false },
click: function() {
var selection = this.controller.state().get('selection').first();
this.controller.state().cropperView.remove();
this.controller.trigger('skippedcrop', selection);
this.controller.close();
var controller = this.controller,
selection = controller.state().get( 'selection' ).first();

controller.state().cropperView.remove();

// Apply the suggested crop size.
if ( hasRequiredAspectRatio && !canSkipCrop ) {
selection.set({cropDetails: suggestedCropSize});
controller.state().doCrop( selection ).done( function( croppedImage ) {
controller.trigger( 'cropped', croppedImage );
controller.close();
}).fail( function() {
controller.trigger( 'content:error:crop' );
});
return;
}

// Skip the cropping process.
controller.trigger( 'skippedcrop', selection );
controller.close();
}
}
});
Expand Down
32 changes: 22 additions & 10 deletions src/wp-admin/includes/image-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -826,9 +826,10 @@ function wp_restore_image( $post_id ) {
}
} elseif ( isset( $meta['width'], $meta['height'] ) ) {
$backup_sizes[ "full-$suffix" ] = array(
'width' => $meta['width'],
'height' => $meta['height'],
'file' => $parts['basename'],
'width' => $meta['width'],
'height' => $meta['height'],
'filesize' => $meta['filesize'],
'file' => $parts['basename'],
);
}
}
Expand All @@ -839,6 +840,14 @@ function wp_restore_image( $post_id ) {
$meta['file'] = _wp_relative_upload_path( $restored_file );
$meta['width'] = $data['width'];
$meta['height'] = $data['height'];
if ( isset( $data['filesize'] ) ) {
/*
* Restore the original filesize if it was backed up.
*
* See https://core.trac.wordpress.org/ticket/59684.
*/
$meta['filesize'] = $data['filesize'];
}
}

foreach ( $default_sizes as $default_size ) {
Expand Down Expand Up @@ -997,8 +1006,9 @@ function wp_save_image( $post_id ) {
}
}

$saved_image = wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id );
// Save the full-size file, also needed to create sub-sizes.
if ( ! wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id ) ) {
if ( ! $saved_image ) {
$return->error = esc_js( __( 'Unable to save the image.' ) );
return $return;
}
Expand All @@ -1018,19 +1028,21 @@ function wp_save_image( $post_id ) {

if ( $tag ) {
$backup_sizes[ $tag ] = array(
'width' => $meta['width'],
'height' => $meta['height'],
'file' => $basename,
'width' => $meta['width'],
'height' => $meta['height'],
'filesize' => $meta['filesize'],
'file' => $basename,
);
}

$success = ( $path === $new_path ) || update_attached_file( $post_id, $new_path );

$meta['file'] = _wp_relative_upload_path( $new_path );

$size = $img->get_size();
$meta['width'] = $size['width'];
$meta['height'] = $size['height'];
$size = $img->get_size();
$meta['width'] = $size['width'];
$meta['height'] = $size['height'];
$meta['filesize'] = $saved_image['filesize'];

if ( $success && ( 'nothumb' === $target || 'all' === $target ) ) {
$sizes = get_intermediate_image_sizes();
Expand Down
2 changes: 2 additions & 0 deletions src/wp-content/themes/twentyeleven/inc/widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ public function flush_widget_cache() {
* Displays the form for this widget on the Widgets page of the WP Admin area.
*
* @since Twenty Eleven 1.0
*
* @param array $instance The settings for the particular instance of the widget.
*/
public function form( $instance ) {
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/block-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ function _resolve_template_for_new_post( $wp_query ) {
* }
* @return WP_Block_Template|WP_Error The registered template object on success, WP_Error object on failure.
*/
function wp_register_block_template( $template_name, $args = array() ) {
function register_block_template( $template_name, $args = array() ) {
return WP_Block_Templates_Registry::get_instance()->register( $template_name, $args );
}

Expand All @@ -390,6 +390,6 @@ function wp_register_block_template( $template_name, $args = array() ) {
* @return WP_Block_Template|WP_Error The unregistered template object on success, WP_Error object on failure or if the
* template doesn't exist.
*/
function wp_unregister_block_template( $template_name ) {
function unregister_block_template( $template_name ) {
return WP_Block_Templates_Registry::get_instance()->unregister( $template_name );
}
33 changes: 16 additions & 17 deletions src/wp-includes/capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -913,24 +913,23 @@ function current_user_can( $capability, ...$args ) {
* capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
* map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
*
* This function replaces the current_user_can_for_blog() function.
*
* Example usage:
*
* current_user_can_for_blog( $blog_id, 'edit_posts' );
* current_user_can_for_blog( $blog_id, 'edit_post', $post->ID );
* current_user_can_for_blog( $blog_id, 'edit_post_meta', $post->ID, $meta_key );
* current_user_can_for_site( $site_id, 'edit_posts' );
* current_user_can_for_site( $site_id, 'edit_post', $post->ID );
* current_user_can_for_site( $site_id, 'edit_post_meta', $post->ID, $meta_key );
*
* @since 3.0.0
* @since 5.3.0 Formalized the existing and already documented `...$args` parameter
* by adding it to the function signature.
* @since 5.8.0 Wraps current_user_can() after switching to blog.
* @since 6.7.0
*
* @param int $blog_id Site ID.
* @param int $site_id Site ID.
* @param string $capability Capability name.
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
* @return bool Whether the user has the given capability.
*/
function current_user_can_for_blog( $blog_id, $capability, ...$args ) {
$switched = is_multisite() ? switch_to_blog( $blog_id ) : false;
function current_user_can_for_site( $site_id, $capability, ...$args ) {
$switched = is_multisite() ? switch_to_blog( $site_id ) : false;

$can = current_user_can( $capability, ...$args );

Expand Down Expand Up @@ -1023,19 +1022,19 @@ function user_can( $user, $capability, ...$args ) {
*
* Example usage:
*
* user_can_for_blog( $user->ID, $blog_id, 'edit_posts' );
* user_can_for_blog( $user->ID, $blog_id, 'edit_post', $post->ID );
* user_can_for_blog( $user->ID, $blog_id, 'edit_post_meta', $post->ID, $meta_key );
* user_can_for_site( $user->ID, $site_id, 'edit_posts' );
* user_can_for_site( $user->ID, $site_id, 'edit_post', $post->ID );
* user_can_for_site( $user->ID, $site_id, 'edit_post_meta', $post->ID, $meta_key );
*
* @since 6.7.0
*
* @param int|WP_User $user User ID or object.
* @param int $blog_id Site ID.
* @param int $site_id Site ID.
* @param string $capability Capability name.
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
* @return bool Whether the user has the given capability.
*/
function user_can_for_blog( $user, $blog_id, $capability, ...$args ) {
function user_can_for_site( $user, $site_id, $capability, ...$args ) {
if ( ! is_object( $user ) ) {
$user = get_userdata( $user );
}
Expand All @@ -1047,11 +1046,11 @@ function user_can_for_blog( $user, $blog_id, $capability, ...$args ) {
}

// Check if the blog ID is valid.
if ( ! is_numeric( $blog_id ) || $blog_id <= 0 ) {
if ( ! is_numeric( $site_id ) || $site_id <= 0 ) {
return false;
}

$switched = is_multisite() ? switch_to_blog( $blog_id ) : false;
$switched = is_multisite() ? switch_to_blog( $site_id ) : false;

$can = user_can( $user->ID, $capability, ...$args );

Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function update( $new_instance, $old_instance ) {
*
* @since 2.8.0
*
* @param array $instance Current settings.
* @param array $instance The settings for the particular instance of the widget.
* @return string Default return is 'noform'.
*/
public function form( $instance ) {
Expand Down
18 changes: 18 additions & 0 deletions src/wp-includes/deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -6406,3 +6406,21 @@ function wp_create_block_style_variation_instance_name( $block, $variation ) {
_deprecated_function( __FUNCTION__, '6.7.0', 'wp_unique_id' );
return $variation . '--' . md5( serialize( $block ) );
}

/**
* Returns whether the current user has the specified capability for a given site.
*
* @since 3.0.0
* @since 5.3.0 Formalized the existing and already documented `...$args` parameter
* by adding it to the function signature.
* @since 5.8.0 Wraps current_user_can() after switching to blog.
* @deprecated 6.7.0 Use current_user_can_for_site() instead.
*
* @param int $blog_id Site ID.
* @param string $capability Capability name.
* @param mixed ...$args Optional further parameters, typically starting with an object ID.
* @return bool Whether the user has the given capability.
*/
function current_user_can_for_blog( $blog_id, $capability, ...$args ) {
return current_user_can_for_site( $blog_id, $capability, ...$args );
}
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public function get_collection_params() {
return apply_filters( 'rest_pattern_directory_collection_params', $query_params );
}

/*
/**
* Include a hash of the query args, so that different requests are stored in
* separate caches.
*
Expand Down
7 changes: 7 additions & 0 deletions src/wp-includes/style-engine/class-wp-style-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @since 6.4.0 Added support for background.backgroundImage.
* @since 6.5.0 Added support for background.backgroundPosition,
* background.backgroundRepeat and dimensions.aspectRatio.
* @since 6.7.0 Added support for typography.writingMode.
*/
#[AllowDynamicProperties]
final class WP_Style_Engine {
Expand Down Expand Up @@ -305,6 +306,12 @@ final class WP_Style_Engine {
),
'path' => array( 'typography', 'letterSpacing' ),
),
'writingMode' => array(
'property_keys' => array(
'default' => 'writing-mode',
),
'path' => array( 'typography', 'writingMode' ),
),
),
);

Expand Down
Loading

0 comments on commit 5e67967

Please sign in to comment.