author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Image Editor |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
5 | 9 |
/** |
10 |
* Loads the WP image-editing interface. |
|
11 |
* |
|
9 | 12 |
* @since 2.9.0 |
13 |
* |
|
18 | 14 |
* @param int $post_id Attachment post ID. |
15 |
* @param false|object $msg Optional. Message to display for image editor updates or errors. |
|
16 |
* Default false. |
|
5 | 17 |
*/ |
9 | 18 |
function wp_image_editor( $post_id, $msg = false ) { |
19 |
$nonce = wp_create_nonce( "image_editor-$post_id" ); |
|
20 |
$meta = wp_get_attachment_metadata( $post_id ); |
|
21 |
$thumb = image_get_intermediate_size( $post_id, 'thumbnail' ); |
|
22 |
$sub_sizes = isset( $meta['sizes'] ) && is_array( $meta['sizes'] ); |
|
23 |
$note = ''; |
|
0 | 24 |
|
9 | 25 |
if ( isset( $meta['width'], $meta['height'] ) ) { |
0 | 26 |
$big = max( $meta['width'], $meta['height'] ); |
9 | 27 |
} else { |
28 |
die( __( 'Image data does not exist. Please re-upload the image.' ) ); |
|
29 |
} |
|
0 | 30 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
31 |
$sizer = $big > 600 ? 600 / $big : 1; |
0 | 32 |
|
33 |
$backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true ); |
|
9 | 34 |
$can_restore = false; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
35 |
|
9 | 36 |
if ( ! empty( $backup_sizes ) && isset( $backup_sizes['full-orig'], $meta['file'] ) ) { |
16 | 37 |
$can_restore = wp_basename( $meta['file'] ) !== $backup_sizes['full-orig']['file']; |
9 | 38 |
} |
0 | 39 |
|
40 |
if ( $msg ) { |
|
9 | 41 |
if ( isset( $msg->error ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
42 |
$note = "<div class='notice notice-error' role='alert'><p>$msg->error</p></div>"; |
9 | 43 |
} elseif ( isset( $msg->msg ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
44 |
$note = "<div class='notice notice-success' role='alert'><p>$msg->msg</p></div>"; |
9 | 45 |
} |
0 | 46 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
47 |
|
19 | 48 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
49 |
* Shows the settings in the Image Editor that allow selecting to edit only the thumbnail of an image. |
19 | 50 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
51 |
* @since 6.3.0 |
19 | 52 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
53 |
* @param bool $show Whether to show the settings in the Image Editor. Default false. |
19 | 54 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
55 |
$edit_thumbnails_separately = (bool) apply_filters( 'image_edit_thumbnails_separately', false ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
56 |
|
0 | 57 |
?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
<div class="imgedit-wrap wp-clearfix"> |
5 | 59 |
<div id="imgedit-panel-<?php echo $post_id; ?>"> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
60 |
<?php echo $note; ?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
61 |
<div class="imgedit-panel-content imgedit-panel-tools wp-clearfix"> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
<div class="imgedit-menu wp-clearfix"> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
63 |
<button type="button" onclick="imageEdit.toggleCropTool( <?php echo "$post_id, '$nonce'"; ?>, this );" aria-expanded="false" aria-controls="imgedit-crop" class="imgedit-crop button disabled" disabled><?php esc_html_e( 'Crop' ); ?></button> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
64 |
<button type="button" class="imgedit-scale button" onclick="imageEdit.toggleControls(this);" aria-expanded="false" aria-controls="imgedit-scale"><?php esc_html_e( 'Scale' ); ?></button> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
65 |
<div class="imgedit-rotate-menu-container"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
66 |
<button type="button" aria-controls="imgedit-rotate-menu" class="imgedit-rotate button" aria-expanded="false" onclick="imageEdit.togglePopup(this)" onblur="imageEdit.monitorPopup()"><?php esc_html_e( 'Image Rotation' ); ?></button> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
67 |
<div id="imgedit-rotate-menu" class="imgedit-popup-menu"> |
16 | 68 |
<?php |
69 |
// On some setups GD library does not provide imagerotate() - Ticket #11536. |
|
70 |
if ( wp_image_editor_supports( |
|
71 |
array( |
|
72 |
'mime_type' => get_post_mime_type( $post_id ), |
|
73 |
'methods' => array( 'rotate' ), |
|
74 |
) |
|
75 |
) ) { |
|
76 |
$note_no_rotate = ''; |
|
77 |
?> |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
78 |
<button type="button" class="imgedit-rleft button" onkeydown="imageEdit.browsePopup(event, this)" onclick="imageEdit.rotate( 90, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()"><?php esc_html_e( 'Rotate 90° left' ); ?></button> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
79 |
<button type="button" class="imgedit-rright button" onkeydown="imageEdit.browsePopup(event, this)" onclick="imageEdit.rotate(-90, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()"><?php esc_html_e( 'Rotate 90° right' ); ?></button> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
80 |
<button type="button" class="imgedit-rfull button" onkeydown="imageEdit.browsePopup(event, this)" onclick="imageEdit.rotate(180, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()"><?php esc_html_e( 'Rotate 180°' ); ?></button> |
16 | 81 |
<?php |
82 |
} else { |
|
83 |
$note_no_rotate = '<p class="note-no-rotate"><em>' . __( 'Image rotation is not supported by your web host.' ) . '</em></p>'; |
|
84 |
?> |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
85 |
<button type="button" class="imgedit-rleft button disabled" disabled></button> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
86 |
<button type="button" class="imgedit-rright button disabled" disabled></button> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
87 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
88 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
89 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
90 |
<hr /> |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
91 |
<button type="button" onkeydown="imageEdit.browsePopup(event, this)" onclick="imageEdit.flip(1, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()" class="imgedit-flipv button"><?php esc_html_e( 'Flip vertical' ); ?></button> |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
92 |
<button type="button" onkeydown="imageEdit.browsePopup(event, this)" onclick="imageEdit.flip(2, <?php echo "$post_id, '$nonce'"; ?>, this)" onblur="imageEdit.monitorPopup()" class="imgedit-fliph button"><?php esc_html_e( 'Flip horizontal' ); ?></button> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
93 |
<?php echo $note_no_rotate; ?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
94 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
95 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
96 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
97 |
<div class="imgedit-submit imgedit-menu"> |
16 | 98 |
<button type="button" id="image-undo-<?php echo $post_id; ?>" onclick="imageEdit.undo(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-undo button disabled" disabled><?php esc_html_e( 'Undo' ); ?></button> |
99 |
<button type="button" id="image-redo-<?php echo $post_id; ?>" onclick="imageEdit.redo(<?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-redo button disabled" disabled><?php esc_html_e( 'Redo' ); ?></button> |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
100 |
<button type="button" onclick="imageEdit.close(<?php echo $post_id; ?>, 1)" class="button imgedit-cancel-btn"><?php esc_html_e( 'Cancel Editing' ); ?></button> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
101 |
<button type="button" onclick="imageEdit.save(<?php echo "$post_id, '$nonce'"; ?>)" disabled="disabled" class="button button-primary imgedit-submit-btn"><?php esc_html_e( 'Save Edits' ); ?></button> |
5 | 102 |
</div> |
103 |
</div> |
|
104 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
105 |
<div class="imgedit-panel-content wp-clearfix"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
106 |
<div class="imgedit-tools"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
107 |
<input type="hidden" id="imgedit-nonce-<?php echo $post_id; ?>" value="<?php echo $nonce; ?>" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
108 |
<input type="hidden" id="imgedit-sizer-<?php echo $post_id; ?>" value="<?php echo $sizer; ?>" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
109 |
<input type="hidden" id="imgedit-history-<?php echo $post_id; ?>" value="" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
110 |
<input type="hidden" id="imgedit-undone-<?php echo $post_id; ?>" value="0" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
111 |
<input type="hidden" id="imgedit-selection-<?php echo $post_id; ?>" value="" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
112 |
<input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
113 |
<input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
114 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
115 |
<div id="imgedit-crop-<?php echo $post_id; ?>" class="imgedit-crop-wrap"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
116 |
<div class="imgedit-crop-grid"></div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
117 |
<img id="image-preview-<?php echo $post_id; ?>" onload="imageEdit.imgLoaded('<?php echo $post_id; ?>')" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
118 |
src="<?php echo esc_url( admin_url( 'admin-ajax.php', 'relative' ) ) . '?action=imgedit-preview&_ajax_nonce=' . $nonce . '&postid=' . $post_id . '&rand=' . rand( 1, 99999 ); ?>" alt="" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
119 |
</div> |
16 | 120 |
</div> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
121 |
<div class="imgedit-settings"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
122 |
<div class="imgedit-tool-active"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
123 |
<div class="imgedit-group"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
124 |
<div id="imgedit-scale" tabindex="-1" class="imgedit-group-controls"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
125 |
<div class="imgedit-group-top"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
126 |
<h2><?php _e( 'Scale Image' ); ?></h2> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
127 |
<button type="button" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);" aria-expanded="false"><span class="screen-reader-text"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
128 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
129 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
130 |
esc_html_e( 'Scale Image Help' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
131 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
132 |
</span></button> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
133 |
<div class="imgedit-help"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
134 |
<p><?php _e( 'You can proportionally scale the original image. For best results, scaling should be done before you crop, flip, or rotate. Images can only be scaled down, not up.' ); ?></p> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
135 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
136 |
<?php if ( isset( $meta['width'], $meta['height'] ) ) : ?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
137 |
<p> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
138 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
139 |
printf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
140 |
/* translators: %s: Image width and height in pixels. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
141 |
__( 'Original dimensions %s' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
142 |
'<span class="imgedit-original-dimensions">' . $meta['width'] . ' × ' . $meta['height'] . '</span>' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
143 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
144 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
145 |
</p> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
146 |
<?php endif; ?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
147 |
<div class="imgedit-submit"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
148 |
<fieldset class="imgedit-scale-controls"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
149 |
<legend><?php _e( 'New dimensions:' ); ?></legend> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
150 |
<div class="nowrap"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
151 |
<label for="imgedit-scale-width-<?php echo $post_id; ?>" class="screen-reader-text"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
152 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
153 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
154 |
_e( 'scale height' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
155 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
156 |
</label> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
157 |
<input type="number" step="1" min="0" max="<?php echo isset( $meta['width'] ) ? $meta['width'] : ''; ?>" aria-describedby="imgedit-scale-warn-<?php echo $post_id; ?>" id="imgedit-scale-width-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1, this)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 1, this)" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
158 |
<span class="imgedit-separator" aria-hidden="true">×</span> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
159 |
<label for="imgedit-scale-height-<?php echo $post_id; ?>" class="screen-reader-text"><?php _e( 'scale height' ); ?></label> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
160 |
<input type="number" step="1" min="0" max="<?php echo isset( $meta['height'] ) ? $meta['height'] : ''; ?>" aria-describedby="imgedit-scale-warn-<?php echo $post_id; ?>" id="imgedit-scale-height-<?php echo $post_id; ?>" onkeyup="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0, this)" onblur="imageEdit.scaleChanged(<?php echo $post_id; ?>, 0, this)" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
161 |
<button id="imgedit-scale-button" type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'scale')" class="button button-primary"><?php esc_html_e( 'Scale' ); ?></button> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
162 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
163 |
<span class="imgedit-scale-warn" id="imgedit-scale-warn-<?php echo $post_id; ?>"><span class="dashicons dashicons-warning" aria-hidden="true"></span><?php esc_html_e( 'Images cannot be scaled to a size larger than the original.' ); ?></span> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
164 |
</fieldset> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
165 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
166 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
167 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
168 |
</div> |
16 | 169 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
170 |
<?php if ( $can_restore ) { ?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
171 |
<div class="imgedit-group"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
172 |
<div class="imgedit-group-top"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
173 |
<h2><button type="button" onclick="imageEdit.toggleHelp(this);" class="button-link" aria-expanded="false"><?php _e( 'Restore original image' ); ?> <span class="dashicons dashicons-arrow-down imgedit-help-toggle"></span></button></h2> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
174 |
<div class="imgedit-help imgedit-restore"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
175 |
<p> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
176 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
177 |
_e( 'Discard any changes and restore the original image.' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
178 |
if ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
179 |
echo ' ' . __( 'Previously edited copies of the image will not be deleted.' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
180 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
181 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
182 |
</p> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
183 |
<div class="imgedit-submit"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
184 |
<input type="button" onclick="imageEdit.action(<?php echo "$post_id, '$nonce'"; ?>, 'restore')" class="button button-primary" value="<?php esc_attr_e( 'Restore image' ); ?>" <?php echo $can_restore; ?> /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
185 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
186 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
187 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
188 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
189 |
<?php } ?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
190 |
<div class="imgedit-group"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
191 |
<div id="imgedit-crop" tabindex="-1" class="imgedit-group-controls"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
192 |
<div class="imgedit-group-top"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
193 |
<h2><?php _e( 'Crop Image' ); ?></h2> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
194 |
<button type="button" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);" aria-expanded="false"><span class="screen-reader-text"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
195 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
196 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
197 |
_e( 'Image Crop Help' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
198 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
199 |
</span></button> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
200 |
<div class="imgedit-help"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
201 |
<p><?php _e( 'To crop the image, click on it and drag to make your selection.' ); ?></p> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
202 |
<p><strong><?php _e( 'Crop Aspect Ratio' ); ?></strong><br /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
203 |
<?php _e( 'The aspect ratio is the relationship between the width and height. You can preserve the aspect ratio by holding down the shift key while resizing your selection. Use the input box to specify the aspect ratio, e.g. 1:1 (square), 4:3, 16:9, etc.' ); ?></p> |
16 | 204 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
205 |
<p><strong><?php _e( 'Crop Selection' ); ?></strong><br /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
206 |
<?php _e( 'Once you have made your selection, you can adjust it by entering the size in pixels. The minimum selection size is the thumbnail size as set in the Media settings.' ); ?></p> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
207 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
208 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
209 |
<fieldset class="imgedit-crop-ratio"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
210 |
<legend><?php _e( 'Aspect ratio:' ); ?></legend> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
211 |
<div class="nowrap"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
212 |
<label for="imgedit-crop-width-<?php echo $post_id; ?>" class="screen-reader-text"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
213 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
214 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
215 |
_e( 'crop ratio width' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
216 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
217 |
</label> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
218 |
<input type="number" step="1" min="1" id="imgedit-crop-width-<?php echo $post_id; ?>" onkeyup="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 0, this)" onblur="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 0, this)" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
219 |
<span class="imgedit-separator" aria-hidden="true">:</span> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
220 |
<label for="imgedit-crop-height-<?php echo $post_id; ?>" class="screen-reader-text"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
221 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
222 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
223 |
_e( 'crop ratio height' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
224 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
225 |
</label> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
226 |
<input type="number" step="1" min="0" id="imgedit-crop-height-<?php echo $post_id; ?>" onkeyup="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 1, this)" onblur="imageEdit.setRatioSelection(<?php echo $post_id; ?>, 1, this)" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
227 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
228 |
</fieldset> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
229 |
<fieldset id="imgedit-crop-sel-<?php echo $post_id; ?>" class="imgedit-crop-sel"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
230 |
<legend><?php _e( 'Selection:' ); ?></legend> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
231 |
<div class="nowrap"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
232 |
<label for="imgedit-sel-width-<?php echo $post_id; ?>" class="screen-reader-text"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
233 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
234 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
235 |
_e( 'selection width' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
236 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
237 |
</label> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
238 |
<input type="number" step="1" min="0" id="imgedit-sel-width-<?php echo $post_id; ?>" onkeyup="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" onblur="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
239 |
<span class="imgedit-separator" aria-hidden="true">×</span> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
240 |
<label for="imgedit-sel-height-<?php echo $post_id; ?>" class="screen-reader-text"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
241 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
242 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
243 |
_e( 'selection height' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
244 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
245 |
</label> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
246 |
<input type="number" step="1" min="0" id="imgedit-sel-height-<?php echo $post_id; ?>" onkeyup="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" onblur="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
247 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
248 |
</fieldset> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
249 |
<fieldset id="imgedit-crop-sel-<?php echo $post_id; ?>" class="imgedit-crop-sel"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
250 |
<legend><?php _e( 'Starting Coordinates:' ); ?></legend> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
251 |
<div class="nowrap"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
252 |
<label for="imgedit-start-x-<?php echo $post_id; ?>" class="screen-reader-text"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
253 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
254 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
255 |
_e( 'horizontal start position' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
256 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
257 |
</label> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
258 |
<input type="number" step="1" min="0" id="imgedit-start-x-<?php echo $post_id; ?>" onkeyup="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" onblur="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" value="0" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
259 |
<span class="imgedit-separator" aria-hidden="true">×</span> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
260 |
<label for="imgedit-start-y-<?php echo $post_id; ?>" class="screen-reader-text"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
261 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
262 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
263 |
_e( 'vertical start position' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
264 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
265 |
</label> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
266 |
<input type="number" step="1" min="0" id="imgedit-start-y-<?php echo $post_id; ?>" onkeyup="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" onblur="imageEdit.setNumSelection(<?php echo $post_id; ?>, this)" value="0" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
267 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
268 |
</fieldset> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
269 |
<div class="imgedit-crop-apply imgedit-menu container"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
270 |
<button class="button-primary" type="button" onclick="imageEdit.handleCropToolClick( <?php echo "$post_id, '$nonce'"; ?>, this );" class="imgedit-crop-apply button"><?php esc_html_e( 'Apply Crop' ); ?></button> <button type="button" onclick="imageEdit.handleCropToolClick( <?php echo "$post_id, '$nonce'"; ?>, this );" class="imgedit-crop-clear button" disabled="disabled"><?php esc_html_e( 'Clear Crop' ); ?></button> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
271 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
272 |
</div> |
16 | 273 |
</div> |
274 |
</div> |
|
275 |
||
276 |
<?php |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
277 |
if ( $edit_thumbnails_separately && $thumb && $sub_sizes ) { |
16 | 278 |
$thumb_img = wp_constrain_dimensions( $thumb['width'], $thumb['height'], 160, 120 ); |
279 |
?> |
|
280 |
||
281 |
<div class="imgedit-group imgedit-applyto"> |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
282 |
<div class="imgedit-group-top"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
283 |
<h2><?php _e( 'Thumbnail Settings' ); ?></h2> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
284 |
<button type="button" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);" aria-expanded="false"><span class="screen-reader-text"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
285 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
286 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
287 |
esc_html_e( 'Thumbnail Settings Help' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
288 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
289 |
</span></button> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
290 |
<div class="imgedit-help"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
291 |
<p><?php _e( 'You can edit the image while preserving the thumbnail. For example, you may wish to have a square thumbnail that displays just a section of the image.' ); ?></p> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
292 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
293 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
294 |
<div class="imgedit-thumbnail-preview-group"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
295 |
<figure class="imgedit-thumbnail-preview"> |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
296 |
<img src="<?php echo esc_url( $thumb['url'] ); ?>" width="<?php echo esc_attr( $thumb_img[0] ); ?>" height="<?php echo esc_attr( $thumb_img[1] ); ?>" class="imgedit-size-preview" alt="" draggable="false" /> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
297 |
<figcaption class="imgedit-thumbnail-preview-caption"><?php _e( 'Current thumbnail' ); ?></figcaption> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
298 |
</figure> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
299 |
<div id="imgedit-save-target-<?php echo $post_id; ?>" class="imgedit-save-target"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
300 |
<fieldset> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
301 |
<legend><?php _e( 'Apply changes to:' ); ?></legend> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
302 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
303 |
<span class="imgedit-label"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
304 |
<input type="radio" id="imgedit-target-all" name="imgedit-target-<?php echo $post_id; ?>" value="all" checked="checked" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
305 |
<label for="imgedit-target-all"><?php _e( 'All image sizes' ); ?></label> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
306 |
</span> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
307 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
308 |
<span class="imgedit-label"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
309 |
<input type="radio" id="imgedit-target-thumbnail" name="imgedit-target-<?php echo $post_id; ?>" value="thumbnail" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
310 |
<label for="imgedit-target-thumbnail"><?php _e( 'Thumbnail' ); ?></label> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
311 |
</span> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
312 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
313 |
<span class="imgedit-label"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
314 |
<input type="radio" id="imgedit-target-nothumb" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
315 |
<label for="imgedit-target-nothumb"><?php _e( 'All sizes except thumbnail' ); ?></label> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
316 |
</span> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
317 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
318 |
</fieldset> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
319 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
320 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
321 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
322 |
<?php } ?> |
16 | 323 |
</div> |
324 |
</div> |
|
325 |
||
326 |
</div> |
|
327 |
||
0 | 328 |
<div class="imgedit-wait" id="imgedit-wait-<?php echo $post_id; ?>"></div> |
9 | 329 |
<div class="hidden" id="imgedit-leaving-<?php echo $post_id; ?>"><?php _e( "There are unsaved changes that will be lost. 'OK' to continue, 'Cancel' to return to the Image Editor." ); ?></div> |
0 | 330 |
</div> |
9 | 331 |
<?php |
0 | 332 |
} |
333 |
||
334 |
/** |
|
335 |
* Streams image in WP_Image_Editor to browser. |
|
336 |
* |
|
9 | 337 |
* @since 2.9.0 |
338 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
339 |
* @param WP_Image_Editor $image The image editor instance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
* @param string $mime_type The mime type of the image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
* @param int $attachment_id The image's attachment post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
* @return bool True on success, false on failure. |
0 | 343 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
344 |
function wp_stream_image( $image, $mime_type, $attachment_id ) { |
0 | 345 |
if ( $image instanceof WP_Image_Editor ) { |
5 | 346 |
|
347 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
* Filters the WP_Image_Editor instance for the image to be streamed to the browser. |
5 | 349 |
* |
350 |
* @since 3.5.0 |
|
351 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
352 |
* @param WP_Image_Editor $image The image editor instance. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
353 |
* @param int $attachment_id The attachment post ID. |
5 | 354 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
355 |
$image = apply_filters( 'image_editor_save_pre', $image, $attachment_id ); |
0 | 356 |
|
9 | 357 |
if ( is_wp_error( $image->stream( $mime_type ) ) ) { |
0 | 358 |
return false; |
9 | 359 |
} |
0 | 360 |
|
361 |
return true; |
|
362 |
} else { |
|
16 | 363 |
/* translators: 1: $image, 2: WP_Image_Editor */ |
364 |
_deprecated_argument( __FUNCTION__, '3.5.0', sprintf( __( '%1$s needs to be a %2$s object.' ), '$image', 'WP_Image_Editor' ) ); |
|
0 | 365 |
|
5 | 366 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
367 |
* Filters the GD image resource to be streamed to the browser. |
5 | 368 |
* |
369 |
* @since 2.9.0 |
|
16 | 370 |
* @deprecated 3.5.0 Use {@see 'image_editor_save_pre'} instead. |
5 | 371 |
* |
18 | 372 |
* @param resource|GdImage $image Image resource to be streamed. |
373 |
* @param int $attachment_id The attachment post ID. |
|
5 | 374 |
*/ |
16 | 375 |
$image = apply_filters_deprecated( 'image_save_pre', array( $image, $attachment_id ), '3.5.0', 'image_editor_save_pre' ); |
0 | 376 |
|
377 |
switch ( $mime_type ) { |
|
378 |
case 'image/jpeg': |
|
379 |
header( 'Content-Type: image/jpeg' ); |
|
380 |
return imagejpeg( $image, null, 90 ); |
|
381 |
case 'image/png': |
|
382 |
header( 'Content-Type: image/png' ); |
|
383 |
return imagepng( $image ); |
|
384 |
case 'image/gif': |
|
385 |
header( 'Content-Type: image/gif' ); |
|
386 |
return imagegif( $image ); |
|
18 | 387 |
case 'image/webp': |
388 |
if ( function_exists( 'imagewebp' ) ) { |
|
389 |
header( 'Content-Type: image/webp' ); |
|
390 |
return imagewebp( $image, null, 90 ); |
|
391 |
} |
|
392 |
return false; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
393 |
case 'image/avif': |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
394 |
if ( function_exists( 'imageavif' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
395 |
header( 'Content-Type: image/avif' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
396 |
return imageavif( $image, null, 90 ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
397 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
398 |
return false; |
0 | 399 |
default: |
400 |
return false; |
|
401 |
} |
|
402 |
} |
|
403 |
} |
|
404 |
||
405 |
/** |
|
9 | 406 |
* Saves image to file. |
407 |
* |
|
408 |
* @since 2.9.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
409 |
* @since 3.5.0 The `$image` parameter expects a `WP_Image_Editor` instance. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
410 |
* @since 6.0.0 The `$filesize` value was added to the returned array. |
0 | 411 |
* |
16 | 412 |
* @param string $filename Name of the file to be saved. |
413 |
* @param WP_Image_Editor $image The image editor instance. |
|
414 |
* @param string $mime_type The mime type of the image. |
|
415 |
* @param int $post_id Attachment post ID. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
416 |
* @return array|WP_Error|bool { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
417 |
* Array on success or WP_Error if the file failed to save. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
418 |
* When called with a deprecated value for the `$image` parameter, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
419 |
* i.e. a non-`WP_Image_Editor` image resource or `GdImage` instance, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
420 |
* the function will return true on success, false on failure. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
421 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
422 |
* @type string $path Path to the image file. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
423 |
* @type string $file Name of the image file. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
424 |
* @type int $width Image width. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
425 |
* @type int $height Image height. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
426 |
* @type string $mime-type The mime type of the image. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
427 |
* @type int $filesize File size of the image. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
428 |
* } |
0 | 429 |
*/ |
430 |
function wp_save_image_file( $filename, $image, $mime_type, $post_id ) { |
|
431 |
if ( $image instanceof WP_Image_Editor ) { |
|
5 | 432 |
|
433 |
/** This filter is documented in wp-admin/includes/image-edit.php */ |
|
434 |
$image = apply_filters( 'image_editor_save_pre', $image, $post_id ); |
|
435 |
||
436 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
437 |
* Filters whether to skip saving the image file. |
5 | 438 |
* |
439 |
* Returning a non-null value will short-circuit the save method, |
|
440 |
* returning that value instead. |
|
441 |
* |
|
442 |
* @since 3.5.0 |
|
443 |
* |
|
16 | 444 |
* @param bool|null $override Value to return instead of saving. Default null. |
5 | 445 |
* @param string $filename Name of the file to be saved. |
16 | 446 |
* @param WP_Image_Editor $image The image editor instance. |
447 |
* @param string $mime_type The mime type of the image. |
|
448 |
* @param int $post_id Attachment post ID. |
|
5 | 449 |
*/ |
450 |
$saved = apply_filters( 'wp_save_image_editor_file', null, $filename, $image, $mime_type, $post_id ); |
|
0 | 451 |
|
9 | 452 |
if ( null !== $saved ) { |
0 | 453 |
return $saved; |
9 | 454 |
} |
0 | 455 |
|
456 |
return $image->save( $filename, $mime_type ); |
|
457 |
} else { |
|
16 | 458 |
/* translators: 1: $image, 2: WP_Image_Editor */ |
459 |
_deprecated_argument( __FUNCTION__, '3.5.0', sprintf( __( '%1$s needs to be a %2$s object.' ), '$image', 'WP_Image_Editor' ) ); |
|
0 | 460 |
|
5 | 461 |
/** This filter is documented in wp-admin/includes/image-edit.php */ |
16 | 462 |
$image = apply_filters_deprecated( 'image_save_pre', array( $image, $post_id ), '3.5.0', 'image_editor_save_pre' ); |
5 | 463 |
|
464 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
465 |
* Filters whether to skip saving the image file. |
5 | 466 |
* |
467 |
* Returning a non-null value will short-circuit the save method, |
|
468 |
* returning that value instead. |
|
469 |
* |
|
470 |
* @since 2.9.0 |
|
16 | 471 |
* @deprecated 3.5.0 Use {@see 'wp_save_image_editor_file'} instead. |
5 | 472 |
* |
19 | 473 |
* @param bool|null $override Value to return instead of saving. Default null. |
474 |
* @param string $filename Name of the file to be saved. |
|
475 |
* @param resource|GdImage $image Image resource or GdImage instance. |
|
476 |
* @param string $mime_type The mime type of the image. |
|
477 |
* @param int $post_id Attachment post ID. |
|
5 | 478 |
*/ |
16 | 479 |
$saved = apply_filters_deprecated( |
480 |
'wp_save_image_file', |
|
481 |
array( null, $filename, $image, $mime_type, $post_id ), |
|
482 |
'3.5.0', |
|
483 |
'wp_save_image_editor_file' |
|
484 |
); |
|
0 | 485 |
|
9 | 486 |
if ( null !== $saved ) { |
0 | 487 |
return $saved; |
9 | 488 |
} |
0 | 489 |
|
490 |
switch ( $mime_type ) { |
|
491 |
case 'image/jpeg': |
|
5 | 492 |
/** This filter is documented in wp-includes/class-wp-image-editor.php */ |
0 | 493 |
return imagejpeg( $image, $filename, apply_filters( 'jpeg_quality', 90, 'edit_image' ) ); |
494 |
case 'image/png': |
|
495 |
return imagepng( $image, $filename ); |
|
496 |
case 'image/gif': |
|
497 |
return imagegif( $image, $filename ); |
|
18 | 498 |
case 'image/webp': |
499 |
if ( function_exists( 'imagewebp' ) ) { |
|
500 |
return imagewebp( $image, $filename ); |
|
501 |
} |
|
502 |
return false; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
503 |
case 'image/avif': |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
504 |
if ( function_exists( 'imageavif' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
505 |
return imageavif( $image, $filename ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
506 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
507 |
return false; |
0 | 508 |
default: |
509 |
return false; |
|
510 |
} |
|
511 |
} |
|
512 |
} |
|
513 |
||
5 | 514 |
/** |
515 |
* Image preview ratio. Internal use only. |
|
516 |
* |
|
517 |
* @since 2.9.0 |
|
518 |
* |
|
519 |
* @ignore |
|
520 |
* @param int $w Image width in pixels. |
|
521 |
* @param int $h Image height in pixels. |
|
522 |
* @return float|int Image preview ratio. |
|
523 |
*/ |
|
9 | 524 |
function _image_get_preview_ratio( $w, $h ) { |
525 |
$max = max( $w, $h ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
526 |
return $max > 600 ? ( 600 / $max ) : 1; |
0 | 527 |
} |
528 |
||
5 | 529 |
/** |
530 |
* Returns an image resource. Internal use only. |
|
531 |
* |
|
532 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
533 |
* @deprecated 3.5.0 Use WP_Image_Editor::rotate() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
534 |
* @see WP_Image_Editor::rotate() |
5 | 535 |
* |
536 |
* @ignore |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
537 |
* @param resource|GdImage $img Image resource. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
538 |
* @param float|int $angle Image rotation angle, in degrees. |
18 | 539 |
* @return resource|GdImage|false GD image resource or GdImage instance, false otherwise. |
5 | 540 |
*/ |
9 | 541 |
function _rotate_image_resource( $img, $angle ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
542 |
_deprecated_function( __FUNCTION__, '3.5.0', 'WP_Image_Editor::rotate()' ); |
18 | 543 |
|
9 | 544 |
if ( function_exists( 'imagerotate' ) ) { |
545 |
$rotated = imagerotate( $img, $angle, 0 ); |
|
18 | 546 |
|
547 |
if ( is_gd_image( $rotated ) ) { |
|
9 | 548 |
imagedestroy( $img ); |
0 | 549 |
$img = $rotated; |
550 |
} |
|
551 |
} |
|
18 | 552 |
|
0 | 553 |
return $img; |
554 |
} |
|
555 |
||
556 |
/** |
|
5 | 557 |
* Flips an image resource. Internal use only. |
558 |
* |
|
559 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
560 |
* @deprecated 3.5.0 Use WP_Image_Editor::flip() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
561 |
* @see WP_Image_Editor::flip() |
0 | 562 |
* |
5 | 563 |
* @ignore |
18 | 564 |
* @param resource|GdImage $img Image resource or GdImage instance. |
565 |
* @param bool $horz Whether to flip horizontally. |
|
566 |
* @param bool $vert Whether to flip vertically. |
|
567 |
* @return resource|GdImage (maybe) flipped image resource or GdImage instance. |
|
0 | 568 |
*/ |
9 | 569 |
function _flip_image_resource( $img, $horz, $vert ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
570 |
_deprecated_function( __FUNCTION__, '3.5.0', 'WP_Image_Editor::flip()' ); |
18 | 571 |
|
9 | 572 |
$w = imagesx( $img ); |
573 |
$h = imagesy( $img ); |
|
574 |
$dst = wp_imagecreatetruecolor( $w, $h ); |
|
18 | 575 |
|
576 |
if ( is_gd_image( $dst ) ) { |
|
9 | 577 |
$sx = $vert ? ( $w - 1 ) : 0; |
578 |
$sy = $horz ? ( $h - 1 ) : 0; |
|
0 | 579 |
$sw = $vert ? -$w : $w; |
580 |
$sh = $horz ? -$h : $h; |
|
581 |
||
9 | 582 |
if ( imagecopyresampled( $dst, $img, 0, 0, $sx, $sy, $w, $h, $sw, $sh ) ) { |
583 |
imagedestroy( $img ); |
|
0 | 584 |
$img = $dst; |
585 |
} |
|
586 |
} |
|
18 | 587 |
|
0 | 588 |
return $img; |
589 |
} |
|
590 |
||
591 |
/** |
|
5 | 592 |
* Crops an image resource. Internal use only. |
593 |
* |
|
594 |
* @since 2.9.0 |
|
0 | 595 |
* |
5 | 596 |
* @ignore |
18 | 597 |
* @param resource|GdImage $img Image resource or GdImage instance. |
598 |
* @param float $x Source point x-coordinate. |
|
599 |
* @param float $y Source point y-coordinate. |
|
600 |
* @param float $w Source width. |
|
601 |
* @param float $h Source height. |
|
602 |
* @return resource|GdImage (maybe) cropped image resource or GdImage instance. |
|
0 | 603 |
*/ |
9 | 604 |
function _crop_image_resource( $img, $x, $y, $w, $h ) { |
605 |
$dst = wp_imagecreatetruecolor( $w, $h ); |
|
18 | 606 |
|
607 |
if ( is_gd_image( $dst ) ) { |
|
9 | 608 |
if ( imagecopy( $dst, $img, 0, 0, $x, $y, $w, $h ) ) { |
609 |
imagedestroy( $img ); |
|
0 | 610 |
$img = $dst; |
611 |
} |
|
612 |
} |
|
18 | 613 |
|
0 | 614 |
return $img; |
615 |
} |
|
616 |
||
617 |
/** |
|
618 |
* Performs group of changes on Editor specified. |
|
619 |
* |
|
5 | 620 |
* @since 2.9.0 |
621 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
* @param WP_Image_Editor $image WP_Image_Editor instance. |
5 | 623 |
* @param array $changes Array of change operations. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
* @return WP_Image_Editor WP_Image_Editor instance with changes applied. |
0 | 625 |
*/ |
626 |
function image_edit_apply_changes( $image, $changes ) { |
|
18 | 627 |
if ( is_gd_image( $image ) ) { |
16 | 628 |
/* translators: 1: $image, 2: WP_Image_Editor */ |
629 |
_deprecated_argument( __FUNCTION__, '3.5.0', sprintf( __( '%1$s needs to be a %2$s object.' ), '$image', 'WP_Image_Editor' ) ); |
|
9 | 630 |
} |
0 | 631 |
|
9 | 632 |
if ( ! is_array( $changes ) ) { |
0 | 633 |
return $image; |
9 | 634 |
} |
0 | 635 |
|
5 | 636 |
// Expand change operations. |
0 | 637 |
foreach ( $changes as $key => $obj ) { |
9 | 638 |
if ( isset( $obj->r ) ) { |
639 |
$obj->type = 'rotate'; |
|
0 | 640 |
$obj->angle = $obj->r; |
9 | 641 |
unset( $obj->r ); |
642 |
} elseif ( isset( $obj->f ) ) { |
|
0 | 643 |
$obj->type = 'flip'; |
644 |
$obj->axis = $obj->f; |
|
9 | 645 |
unset( $obj->f ); |
646 |
} elseif ( isset( $obj->c ) ) { |
|
0 | 647 |
$obj->type = 'crop'; |
9 | 648 |
$obj->sel = $obj->c; |
649 |
unset( $obj->c ); |
|
0 | 650 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
651 |
|
9 | 652 |
$changes[ $key ] = $obj; |
0 | 653 |
} |
654 |
||
5 | 655 |
// Combine operations. |
9 | 656 |
if ( count( $changes ) > 1 ) { |
657 |
$filtered = array( $changes[0] ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
658 |
|
5 | 659 |
for ( $i = 0, $j = 1, $c = count( $changes ); $j < $c; $j++ ) { |
0 | 660 |
$combined = false; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
661 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
662 |
if ( $filtered[ $i ]->type === $changes[ $j ]->type ) { |
9 | 663 |
switch ( $filtered[ $i ]->type ) { |
0 | 664 |
case 'rotate': |
9 | 665 |
$filtered[ $i ]->angle += $changes[ $j ]->angle; |
666 |
$combined = true; |
|
0 | 667 |
break; |
668 |
case 'flip': |
|
9 | 669 |
$filtered[ $i ]->axis ^= $changes[ $j ]->axis; |
670 |
$combined = true; |
|
0 | 671 |
break; |
672 |
} |
|
673 |
} |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
674 |
|
9 | 675 |
if ( ! $combined ) { |
676 |
$filtered[ ++$i ] = $changes[ $j ]; |
|
677 |
} |
|
0 | 678 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
679 |
|
0 | 680 |
$changes = $filtered; |
9 | 681 |
unset( $filtered ); |
0 | 682 |
} |
683 |
||
5 | 684 |
// Image resource before applying the changes. |
685 |
if ( $image instanceof WP_Image_Editor ) { |
|
686 |
||
687 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
* Filters the WP_Image_Editor instance before applying changes to the image. |
5 | 689 |
* |
690 |
* @since 3.5.0 |
|
691 |
* |
|
692 |
* @param WP_Image_Editor $image WP_Image_Editor instance. |
|
9 | 693 |
* @param array $changes Array of change operations. |
5 | 694 |
*/ |
695 |
$image = apply_filters( 'wp_image_editor_before_change', $image, $changes ); |
|
18 | 696 |
} elseif ( is_gd_image( $image ) ) { |
5 | 697 |
|
698 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
699 |
* Filters the GD image resource before applying changes to the image. |
5 | 700 |
* |
701 |
* @since 2.9.0 |
|
16 | 702 |
* @deprecated 3.5.0 Use {@see 'wp_image_editor_before_change'} instead. |
5 | 703 |
* |
18 | 704 |
* @param resource|GdImage $image GD image resource or GdImage instance. |
705 |
* @param array $changes Array of change operations. |
|
5 | 706 |
*/ |
16 | 707 |
$image = apply_filters_deprecated( 'image_edit_before_change', array( $image, $changes ), '3.5.0', 'wp_image_editor_before_change' ); |
5 | 708 |
} |
0 | 709 |
|
710 |
foreach ( $changes as $operation ) { |
|
711 |
switch ( $operation->type ) { |
|
712 |
case 'rotate': |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
713 |
if ( 0 !== $operation->angle ) { |
9 | 714 |
if ( $image instanceof WP_Image_Editor ) { |
0 | 715 |
$image->rotate( $operation->angle ); |
9 | 716 |
} else { |
0 | 717 |
$image = _rotate_image_resource( $image, $operation->angle ); |
9 | 718 |
} |
0 | 719 |
} |
720 |
break; |
|
721 |
case 'flip': |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
722 |
if ( 0 !== $operation->axis ) { |
9 | 723 |
if ( $image instanceof WP_Image_Editor ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
724 |
$image->flip( ( $operation->axis & 1 ) !== 0, ( $operation->axis & 2 ) !== 0 ); |
9 | 725 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
726 |
$image = _flip_image_resource( $image, ( $operation->axis & 1 ) !== 0, ( $operation->axis & 2 ) !== 0 ); |
9 | 727 |
} |
728 |
} |
|
0 | 729 |
break; |
730 |
case 'crop': |
|
731 |
$sel = $operation->sel; |
|
732 |
||
733 |
if ( $image instanceof WP_Image_Editor ) { |
|
734 |
$size = $image->get_size(); |
|
9 | 735 |
$w = $size['width']; |
736 |
$h = $size['height']; |
|
0 | 737 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
738 |
$scale = isset( $sel->r ) ? $sel->r : 1 / _image_get_preview_ratio( $w, $h ); // Discard preview scaling. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
739 |
$image->crop( (int) ( $sel->x * $scale ), (int) ( $sel->y * $scale ), (int) ( $sel->w * $scale ), (int) ( $sel->h * $scale ) ); |
0 | 740 |
} else { |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
741 |
$scale = isset( $sel->r ) ? $sel->r : 1 / _image_get_preview_ratio( imagesx( $image ), imagesy( $image ) ); // Discard preview scaling. |
0 | 742 |
$image = _crop_image_resource( $image, $sel->x * $scale, $sel->y * $scale, $sel->w * $scale, $sel->h * $scale ); |
743 |
} |
|
744 |
break; |
|
745 |
} |
|
746 |
} |
|
747 |
||
748 |
return $image; |
|
749 |
} |
|
750 |
||
751 |
||
752 |
/** |
|
753 |
* Streams image in post to browser, along with enqueued changes |
|
16 | 754 |
* in `$_REQUEST['history']`. |
0 | 755 |
* |
9 | 756 |
* @since 2.9.0 |
757 |
* |
|
16 | 758 |
* @param int $post_id Attachment post ID. |
759 |
* @return bool True on success, false on failure. |
|
0 | 760 |
*/ |
761 |
function stream_preview_image( $post_id ) { |
|
762 |
$post = get_post( $post_id ); |
|
5 | 763 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
764 |
wp_raise_memory_limit( 'admin' ); |
0 | 765 |
|
766 |
$img = wp_get_image_editor( _load_image_to_edit_path( $post_id ) ); |
|
767 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
768 |
if ( is_wp_error( $img ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
769 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
770 |
} |
0 | 771 |
|
9 | 772 |
$changes = ! empty( $_REQUEST['history'] ) ? json_decode( wp_unslash( $_REQUEST['history'] ) ) : null; |
773 |
if ( $changes ) { |
|
0 | 774 |
$img = image_edit_apply_changes( $img, $changes ); |
9 | 775 |
} |
0 | 776 |
|
5 | 777 |
// Scale the image. |
0 | 778 |
$size = $img->get_size(); |
9 | 779 |
$w = $size['width']; |
780 |
$h = $size['height']; |
|
0 | 781 |
|
782 |
$ratio = _image_get_preview_ratio( $w, $h ); |
|
9 | 783 |
$w2 = max( 1, $w * $ratio ); |
784 |
$h2 = max( 1, $h * $ratio ); |
|
0 | 785 |
|
9 | 786 |
if ( is_wp_error( $img->resize( $w2, $h2 ) ) ) { |
0 | 787 |
return false; |
9 | 788 |
} |
0 | 789 |
|
790 |
return wp_stream_image( $img, $post->post_mime_type, $post_id ); |
|
791 |
} |
|
792 |
||
5 | 793 |
/** |
794 |
* Restores the metadata for a given attachment. |
|
795 |
* |
|
796 |
* @since 2.9.0 |
|
797 |
* |
|
798 |
* @param int $post_id Attachment post ID. |
|
799 |
* @return stdClass Image restoration message object. |
|
800 |
*/ |
|
9 | 801 |
function wp_restore_image( $post_id ) { |
16 | 802 |
$meta = wp_get_attachment_metadata( $post_id ); |
803 |
$file = get_attached_file( $post_id ); |
|
804 |
$backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true ); |
|
805 |
$old_backup_sizes = $backup_sizes; |
|
806 |
$restored = false; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
807 |
$msg = new stdClass(); |
0 | 808 |
|
9 | 809 |
if ( ! is_array( $backup_sizes ) ) { |
810 |
$msg->error = __( 'Cannot load image metadata.' ); |
|
0 | 811 |
return $msg; |
812 |
} |
|
813 |
||
9 | 814 |
$parts = pathinfo( $file ); |
815 |
$suffix = time() . rand( 100, 999 ); |
|
0 | 816 |
$default_sizes = get_intermediate_image_sizes(); |
817 |
||
9 | 818 |
if ( isset( $backup_sizes['full-orig'] ) && is_array( $backup_sizes['full-orig'] ) ) { |
0 | 819 |
$data = $backup_sizes['full-orig']; |
820 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
821 |
if ( $parts['basename'] !== $data['file'] ) { |
9 | 822 |
if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
823 |
// Delete only if it's an edited image. |
9 | 824 |
if ( preg_match( '/-e[0-9]{13}\./', $parts['basename'] ) ) { |
5 | 825 |
wp_delete_file( $file ); |
0 | 826 |
} |
827 |
} elseif ( isset( $meta['width'], $meta['height'] ) ) { |
|
9 | 828 |
$backup_sizes[ "full-$suffix" ] = array( |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
829 |
'width' => $meta['width'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
830 |
'height' => $meta['height'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
831 |
'filesize' => $meta['filesize'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
832 |
'file' => $parts['basename'], |
9 | 833 |
); |
0 | 834 |
} |
835 |
} |
|
836 |
||
9 | 837 |
$restored_file = path_join( $parts['dirname'], $data['file'] ); |
838 |
$restored = update_attached_file( $post_id, $restored_file ); |
|
0 | 839 |
|
9 | 840 |
$meta['file'] = _wp_relative_upload_path( $restored_file ); |
841 |
$meta['width'] = $data['width']; |
|
0 | 842 |
$meta['height'] = $data['height']; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
843 |
if ( isset( $data['filesize'] ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
844 |
/* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
845 |
* Restore the original filesize if it was backed up. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
846 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
847 |
* See https://core.trac.wordpress.org/ticket/59684. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
848 |
*/ |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
849 |
$meta['filesize'] = $data['filesize']; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
850 |
} |
0 | 851 |
} |
852 |
||
853 |
foreach ( $default_sizes as $default_size ) { |
|
9 | 854 |
if ( isset( $backup_sizes[ "$default_size-orig" ] ) ) { |
855 |
$data = $backup_sizes[ "$default_size-orig" ]; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
856 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
857 |
if ( isset( $meta['sizes'][ $default_size ] ) && $meta['sizes'][ $default_size ]['file'] !== $data['file'] ) { |
9 | 858 |
if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
859 |
// Delete only if it's an edited image. |
9 | 860 |
if ( preg_match( '/-e[0-9]{13}-/', $meta['sizes'][ $default_size ]['file'] ) ) { |
861 |
$delete_file = path_join( $parts['dirname'], $meta['sizes'][ $default_size ]['file'] ); |
|
5 | 862 |
wp_delete_file( $delete_file ); |
0 | 863 |
} |
864 |
} else { |
|
9 | 865 |
$backup_sizes[ "$default_size-{$suffix}" ] = $meta['sizes'][ $default_size ]; |
0 | 866 |
} |
867 |
} |
|
868 |
||
9 | 869 |
$meta['sizes'][ $default_size ] = $data; |
0 | 870 |
} else { |
9 | 871 |
unset( $meta['sizes'][ $default_size ] ); |
0 | 872 |
} |
873 |
} |
|
874 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
875 |
if ( ! wp_update_attachment_metadata( $post_id, $meta ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
876 |
|| ( $old_backup_sizes !== $backup_sizes && ! update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes ) ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
877 |
) { |
9 | 878 |
$msg->error = __( 'Cannot save image metadata.' ); |
0 | 879 |
return $msg; |
880 |
} |
|
881 |
||
9 | 882 |
if ( ! $restored ) { |
883 |
$msg->error = __( 'Image metadata is inconsistent.' ); |
|
884 |
} else { |
|
885 |
$msg->msg = __( 'Image restored successfully.' ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
886 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
887 |
if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
888 |
delete_post_meta( $post_id, '_wp_attachment_backup_sizes' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
889 |
} |
9 | 890 |
} |
0 | 891 |
|
892 |
return $msg; |
|
893 |
} |
|
894 |
||
895 |
/** |
|
16 | 896 |
* Saves image to post, along with enqueued changes |
897 |
* in `$_REQUEST['history']`. |
|
0 | 898 |
* |
9 | 899 |
* @since 2.9.0 |
900 |
* |
|
16 | 901 |
* @param int $post_id Attachment post ID. |
902 |
* @return stdClass |
|
0 | 903 |
*/ |
904 |
function wp_save_image( $post_id ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
905 |
$_wp_additional_image_sizes = wp_get_additional_image_sizes(); |
5 | 906 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
907 |
$return = new stdClass(); |
16 | 908 |
$success = false; |
909 |
$delete = false; |
|
910 |
$scaled = false; |
|
911 |
$nocrop = false; |
|
9 | 912 |
$post = get_post( $post_id ); |
0 | 913 |
|
914 |
$img = wp_get_image_editor( _load_image_to_edit_path( $post_id, 'full' ) ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
915 |
|
0 | 916 |
if ( is_wp_error( $img ) ) { |
9 | 917 |
$return->error = esc_js( __( 'Unable to create new image.' ) ); |
0 | 918 |
return $return; |
919 |
} |
|
920 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
921 |
$full_width = ! empty( $_REQUEST['fwidth'] ) ? (int) $_REQUEST['fwidth'] : 0; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
922 |
$full_height = ! empty( $_REQUEST['fheight'] ) ? (int) $_REQUEST['fheight'] : 0; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
923 |
$target = ! empty( $_REQUEST['target'] ) ? preg_replace( '/[^a-z0-9_-]+/i', '', $_REQUEST['target'] ) : ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
924 |
$scale = ! empty( $_REQUEST['do'] ) && 'scale' === $_REQUEST['do']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
925 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
926 |
/** This filter is documented in wp-admin/includes/image-edit.php */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
927 |
$edit_thumbnails_separately = (bool) apply_filters( 'image_edit_thumbnails_separately', false ); |
0 | 928 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
929 |
if ( $scale ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
930 |
$size = $img->get_size(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
931 |
$original_width = $size['width']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
932 |
$original_height = $size['height']; |
0 | 933 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
934 |
if ( $full_width > $original_width || $full_height > $original_height ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
935 |
$return->error = esc_js( __( 'Images cannot be scaled to a size larger than the original.' ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
936 |
return $return; |
0 | 937 |
} |
938 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
939 |
if ( $full_width > 0 && $full_height > 0 ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
940 |
// Check if it has roughly the same w / h ratio. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
941 |
$diff = round( $original_width / $original_height, 2 ) - round( $full_width / $full_height, 2 ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
942 |
if ( -0.1 < $diff && $diff < 0.1 ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
943 |
// Scale the full size image. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
944 |
if ( $img->resize( $full_width, $full_height ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
945 |
$scaled = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
946 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
947 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
948 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
949 |
if ( ! $scaled ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
950 |
$return->error = esc_js( __( 'Error while saving the scaled image. Please reload the page and try again.' ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
951 |
return $return; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
952 |
} |
0 | 953 |
} |
9 | 954 |
} elseif ( ! empty( $_REQUEST['history'] ) ) { |
955 |
$changes = json_decode( wp_unslash( $_REQUEST['history'] ) ); |
|
956 |
if ( $changes ) { |
|
957 |
$img = image_edit_apply_changes( $img, $changes ); |
|
958 |
} |
|
0 | 959 |
} else { |
9 | 960 |
$return->error = esc_js( __( 'Nothing to save, the image has not changed.' ) ); |
0 | 961 |
return $return; |
962 |
} |
|
963 |
||
9 | 964 |
$meta = wp_get_attachment_metadata( $post_id ); |
0 | 965 |
$backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true ); |
966 |
||
9 | 967 |
if ( ! is_array( $meta ) ) { |
968 |
$return->error = esc_js( __( 'Image data does not exist. Please re-upload the image.' ) ); |
|
0 | 969 |
return $return; |
970 |
} |
|
971 |
||
9 | 972 |
if ( ! is_array( $backup_sizes ) ) { |
0 | 973 |
$backup_sizes = array(); |
9 | 974 |
} |
0 | 975 |
|
5 | 976 |
// Generate new filename. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
977 |
$path = get_attached_file( $post_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
978 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
979 |
$basename = pathinfo( $path, PATHINFO_BASENAME ); |
9 | 980 |
$dirname = pathinfo( $path, PATHINFO_DIRNAME ); |
981 |
$ext = pathinfo( $path, PATHINFO_EXTENSION ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
982 |
$filename = pathinfo( $path, PATHINFO_FILENAME ); |
9 | 983 |
$suffix = time() . rand( 100, 999 ); |
0 | 984 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
985 |
if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
986 |
&& isset( $backup_sizes['full-orig'] ) && $backup_sizes['full-orig']['file'] !== $basename |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
987 |
) { |
0 | 988 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
989 |
if ( $edit_thumbnails_separately && 'thumbnail' === $target ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
990 |
$new_path = "{$dirname}/{$filename}-temp.{$ext}"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
} else { |
0 | 992 |
$new_path = $path; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
} |
0 | 994 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
995 |
while ( true ) { |
9 | 996 |
$filename = preg_replace( '/-e([0-9]+)$/', '', $filename ); |
997 |
$filename .= "-e{$suffix}"; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
998 |
$new_filename = "{$filename}.{$ext}"; |
9 | 999 |
$new_path = "{$dirname}/$new_filename"; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1000 |
|
9 | 1001 |
if ( file_exists( $new_path ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1002 |
++$suffix; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1003 |
} else { |
0 | 1004 |
break; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1005 |
} |
0 | 1006 |
} |
1007 |
} |
|
1008 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1009 |
$saved_image = wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id ); |
5 | 1010 |
// Save the full-size file, also needed to create sub-sizes. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1011 |
if ( ! $saved_image ) { |
9 | 1012 |
$return->error = esc_js( __( 'Unable to save the image.' ) ); |
0 | 1013 |
return $return; |
1014 |
} |
|
1015 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1016 |
if ( 'nothumb' === $target || 'all' === $target || 'full' === $target || $scaled ) { |
0 | 1017 |
$tag = false; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1018 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1019 |
if ( isset( $backup_sizes['full-orig'] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1020 |
if ( ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1021 |
&& $backup_sizes['full-orig']['file'] !== $basename |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1022 |
) { |
0 | 1023 |
$tag = "full-$suffix"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1024 |
} |
0 | 1025 |
} else { |
1026 |
$tag = 'full-orig'; |
|
1027 |
} |
|
1028 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1029 |
if ( $tag ) { |
9 | 1030 |
$backup_sizes[ $tag ] = array( |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1031 |
'width' => $meta['width'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1032 |
'height' => $meta['height'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1033 |
'filesize' => $meta['filesize'], |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1034 |
'file' => $basename, |
9 | 1035 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1036 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1037 |
|
5 | 1038 |
$success = ( $path === $new_path ) || update_attached_file( $post_id, $new_path ); |
0 | 1039 |
|
1040 |
$meta['file'] = _wp_relative_upload_path( $new_path ); |
|
1041 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1042 |
$size = $img->get_size(); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1043 |
$meta['width'] = $size['width']; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1044 |
$meta['height'] = $size['height']; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1045 |
$meta['filesize'] = $saved_image['filesize']; |
0 | 1046 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1047 |
if ( $success && ( 'nothumb' === $target || 'all' === $target ) ) { |
0 | 1048 |
$sizes = get_intermediate_image_sizes(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1049 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1050 |
if ( $edit_thumbnails_separately && 'nothumb' === $target ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1051 |
$sizes = array_diff( $sizes, array( 'thumbnail' ) ); |
9 | 1052 |
} |
0 | 1053 |
} |
1054 |
||
1055 |
$return->fw = $meta['width']; |
|
1056 |
$return->fh = $meta['height']; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1057 |
} elseif ( $edit_thumbnails_separately && 'thumbnail' === $target ) { |
9 | 1058 |
$sizes = array( 'thumbnail' ); |
16 | 1059 |
$success = true; |
1060 |
$delete = true; |
|
1061 |
$nocrop = true; |
|
0 | 1062 |
} |
1063 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1064 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1065 |
* We need to remove any existing resized image files because |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1066 |
* a new crop or rotate could generate different sizes (and hence, filenames), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1067 |
* keeping the new resized images from overwriting the existing image files. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1068 |
* https://core.trac.wordpress.org/ticket/32171 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1069 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1070 |
if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE && ! empty( $meta['sizes'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1071 |
foreach ( $meta['sizes'] as $size ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1072 |
if ( ! empty( $size['file'] ) && preg_match( '/-e[0-9]{13}-/', $size['file'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1073 |
$delete_file = path_join( $dirname, $size['file'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1074 |
wp_delete_file( $delete_file ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1075 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1076 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1077 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1078 |
|
0 | 1079 |
if ( isset( $sizes ) ) { |
1080 |
$_sizes = array(); |
|
1081 |
||
1082 |
foreach ( $sizes as $size ) { |
|
1083 |
$tag = false; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1084 |
|
9 | 1085 |
if ( isset( $meta['sizes'][ $size ] ) ) { |
1086 |
if ( isset( $backup_sizes[ "$size-orig" ] ) ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1087 |
if ( ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1088 |
&& $backup_sizes[ "$size-orig" ]['file'] !== $meta['sizes'][ $size ]['file'] |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1089 |
) { |
0 | 1090 |
$tag = "$size-$suffix"; |
9 | 1091 |
} |
0 | 1092 |
} else { |
1093 |
$tag = "$size-orig"; |
|
1094 |
} |
|
1095 |
||
9 | 1096 |
if ( $tag ) { |
1097 |
$backup_sizes[ $tag ] = $meta['sizes'][ $size ]; |
|
1098 |
} |
|
0 | 1099 |
} |
1100 |
||
5 | 1101 |
if ( isset( $_wp_additional_image_sizes[ $size ] ) ) { |
18 | 1102 |
$width = (int) $_wp_additional_image_sizes[ $size ]['width']; |
1103 |
$height = (int) $_wp_additional_image_sizes[ $size ]['height']; |
|
5 | 1104 |
$crop = ( $nocrop ) ? false : $_wp_additional_image_sizes[ $size ]['crop']; |
1105 |
} else { |
|
1106 |
$height = get_option( "{$size}_size_h" ); |
|
1107 |
$width = get_option( "{$size}_size_w" ); |
|
1108 |
$crop = ( $nocrop ) ? false : get_option( "{$size}_crop" ); |
|
1109 |
} |
|
1110 |
||
9 | 1111 |
$_sizes[ $size ] = array( |
1112 |
'width' => $width, |
|
1113 |
'height' => $height, |
|
1114 |
'crop' => $crop, |
|
1115 |
); |
|
0 | 1116 |
} |
1117 |
||
1118 |
$meta['sizes'] = array_merge( $meta['sizes'], $img->multi_resize( $_sizes ) ); |
|
1119 |
} |
|
1120 |
||
1121 |
unset( $img ); |
|
1122 |
||
1123 |
if ( $success ) { |
|
1124 |
wp_update_attachment_metadata( $post_id, $meta ); |
|
9 | 1125 |
update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes ); |
0 | 1126 |
|
16 | 1127 |
if ( 'thumbnail' === $target || 'all' === $target || 'full' === $target ) { |
1128 |
// Check if it's an image edit from attachment edit screen. |
|
1129 |
if ( ! empty( $_REQUEST['context'] ) && 'edit-attachment' === $_REQUEST['context'] ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1130 |
$thumb_url = wp_get_attachment_image_src( $post_id, array( 900, 600 ), true ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1131 |
|
0 | 1132 |
$return->thumbnail = $thumb_url[0]; |
1133 |
} else { |
|
9 | 1134 |
$file_url = wp_get_attachment_url( $post_id ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1135 |
|
16 | 1136 |
if ( ! empty( $meta['sizes']['thumbnail'] ) ) { |
1137 |
$thumb = $meta['sizes']['thumbnail']; |
|
9 | 1138 |
$return->thumbnail = path_join( dirname( $file_url ), $thumb['file'] ); |
5 | 1139 |
} else { |
0 | 1140 |
$return->thumbnail = "$file_url?w=128&h=128"; |
5 | 1141 |
} |
0 | 1142 |
} |
1143 |
} |
|
1144 |
} else { |
|
1145 |
$delete = true; |
|
1146 |
} |
|
1147 |
||
1148 |
if ( $delete ) { |
|
5 | 1149 |
wp_delete_file( $new_path ); |
0 | 1150 |
} |
1151 |
||
9 | 1152 |
$return->msg = esc_js( __( 'Image saved' ) ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1153 |
|
0 | 1154 |
return $return; |
1155 |
} |