wp/wp-admin/includes/image-edit.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
--- a/wp/wp-admin/includes/image-edit.php	Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-admin/includes/image-edit.php	Tue Sep 27 16:37:53 2022 +0200
@@ -43,7 +43,15 @@
 			$note = "<div class='notice notice-success' tabindex='-1' role='alert'><p>$msg->msg</p></div>";
 		}
 	}
-
+	$edit_custom_sizes = false;
+	/**
+	 * Filters whether custom sizes are available options for image editing.
+	 *
+	 * @since 6.0.0
+	 *
+	 * @param bool|string[] $edit_custom_sizes True if custom sizes can be edited or array of custom size names.
+	 */
+	$edit_custom_sizes = apply_filters( 'edit_custom_thumbnail_sizes', $edit_custom_sizes );
 	?>
 	<div class="imgedit-wrap wp-clearfix">
 	<div id="imgedit-panel-<?php echo $post_id; ?>">
@@ -239,6 +247,26 @@
 			<input type="radio" id="imgedit-target-nothumb" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" />
 			<label for="imgedit-target-nothumb"><?php _e( 'All sizes except thumbnail' ); ?></label>
 		</span>
+		<?php
+		if ( $edit_custom_sizes ) {
+			if ( ! is_array( $edit_custom_sizes ) ) {
+				$edit_custom_sizes = get_intermediate_image_sizes();
+			}
+			foreach ( array_unique( $edit_custom_sizes ) as $key => $size ) {
+				if ( array_key_exists( $size, $meta['sizes'] ) ) {
+					if ( 'thumbnail' === $size ) {
+						continue;
+					}
+					?>
+					<span class="imgedit-label">
+						<input type="radio" id="imgedit-target-custom<?php echo esc_attr( $key ); ?>" name="imgedit-target-<?php echo $post_id; ?>" value="<?php echo esc_attr( $size ); ?>" />
+						<label for="imgedit-target-custom<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $size ); ?></label>
+					</span>
+					<?php
+				}
+			}
+		}
+		?>
 	</fieldset>
 	</div>
 	</div>
@@ -373,11 +401,11 @@
 		 * @since 2.9.0
 		 * @deprecated 3.5.0 Use {@see 'wp_save_image_editor_file'} instead.
 		 *
-		 * @param mixed           $override  Value to return instead of saving. Default null.
-		 * @param string          $filename  Name of the file to be saved.
-		 * @param WP_Image_Editor $image     The image editor instance.
-		 * @param string          $mime_type The mime type of the image.
-		 * @param int             $post_id   Attachment post ID.
+		 * @param bool|null        $override  Value to return instead of saving. Default null.
+		 * @param string           $filename  Name of the file to be saved.
+		 * @param resource|GdImage $image     Image resource or GdImage instance.
+		 * @param string           $mime_type The mime type of the image.
+		 * @param int              $post_id   Attachment post ID.
 		 */
 		$saved = apply_filters_deprecated(
 			'wp_save_image_file',
@@ -905,10 +933,14 @@
 		$meta['width']  = $size['width'];
 		$meta['height'] = $size['height'];
 
-		if ( $success && ( 'nothumb' === $target || 'all' === $target ) ) {
+		if ( $success ) {
 			$sizes = get_intermediate_image_sizes();
-			if ( 'nothumb' === $target ) {
-				$sizes = array_diff( $sizes, array( 'thumbnail' ) );
+			if ( 'nothumb' === $target || 'all' === $target ) {
+				if ( 'nothumb' === $target ) {
+					$sizes = array_diff( $sizes, array( 'thumbnail' ) );
+				}
+			} elseif ( 'thumbnail' !== $target ) {
+				$sizes = array_diff( $sizes, array( $target ) );
 			}
 		}
 
@@ -919,6 +951,11 @@
 		$success = true;
 		$delete  = true;
 		$nocrop  = true;
+	} else {
+		$sizes   = array( $target );
+		$success = true;
+		$delete  = true;
+		$nocrop  = $_wp_additional_image_sizes[ $size ]['crop'];
 	}
 
 	/*