Edit File by line
/home/zeestwma/redstone.../wp-admin/includes
File: image-edit.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WordPress Image Editor
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Administration
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/**
[8] Fix | Delete
* Loads the WP image-editing interface.
[9] Fix | Delete
*
[10] Fix | Delete
* @since 2.9.0
[11] Fix | Delete
*
[12] Fix | Delete
* @param int $post_id Attachment post ID.
[13] Fix | Delete
* @param false|object $msg Optional. Message to display for image editor updates or errors.
[14] Fix | Delete
* Default false.
[15] Fix | Delete
*/
[16] Fix | Delete
function wp_image_editor( $post_id, $msg = false ) {
[17] Fix | Delete
$nonce = wp_create_nonce( "image_editor-$post_id" );
[18] Fix | Delete
$meta = wp_get_attachment_metadata( $post_id );
[19] Fix | Delete
$thumb = image_get_intermediate_size( $post_id, 'thumbnail' );
[20] Fix | Delete
$sub_sizes = isset( $meta['sizes'] ) && is_array( $meta['sizes'] );
[21] Fix | Delete
$note = '';
[22] Fix | Delete
[23] Fix | Delete
if ( isset( $meta['width'], $meta['height'] ) ) {
[24] Fix | Delete
$big = max( $meta['width'], $meta['height'] );
[25] Fix | Delete
} else {
[26] Fix | Delete
die( __( 'Image data does not exist. Please re-upload the image.' ) );
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
$sizer = $big > 600 ? 600 / $big : 1;
[30] Fix | Delete
[31] Fix | Delete
$backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
[32] Fix | Delete
$can_restore = false;
[33] Fix | Delete
[34] Fix | Delete
if ( ! empty( $backup_sizes ) && isset( $backup_sizes['full-orig'], $meta['file'] ) ) {
[35] Fix | Delete
$can_restore = wp_basename( $meta['file'] ) !== $backup_sizes['full-orig']['file'];
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
if ( $msg ) {
[39] Fix | Delete
if ( isset( $msg->error ) ) {
[40] Fix | Delete
$note = "<div class='notice notice-error' role='alert'><p>$msg->error</p></div>";
[41] Fix | Delete
} elseif ( isset( $msg->msg ) ) {
[42] Fix | Delete
$note = "<div class='notice notice-success' role='alert'><p>$msg->msg</p></div>";
[43] Fix | Delete
}
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* Shows the settings in the Image Editor that allow selecting to edit only the thumbnail of an image.
[48] Fix | Delete
*
[49] Fix | Delete
* @since 6.3.0
[50] Fix | Delete
*
[51] Fix | Delete
* @param bool $show Whether to show the settings in the Image Editor. Default false.
[52] Fix | Delete
*/
[53] Fix | Delete
$edit_thumbnails_separately = (bool) apply_filters( 'image_edit_thumbnails_separately', false );
[54] Fix | Delete
[55] Fix | Delete
?>
[56] Fix | Delete
<div class="imgedit-wrap wp-clearfix">
[57] Fix | Delete
<div id="imgedit-panel-<?php echo $post_id; ?>">
[58] Fix | Delete
<?php echo $note; ?>
[59] Fix | Delete
<div class="imgedit-panel-content imgedit-panel-tools wp-clearfix">
[60] Fix | Delete
<div class="imgedit-menu wp-clearfix">
[61] Fix | Delete
<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>
[62] Fix | Delete
<button type="button" class="imgedit-scale button" onclick="imageEdit.toggleControls(this);" aria-expanded="false" aria-controls="imgedit-scale"><?php esc_html_e( 'Scale' ); ?></button>
[63] Fix | Delete
<div class="imgedit-rotate-menu-container">
[64] Fix | Delete
<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>
[65] Fix | Delete
<div id="imgedit-rotate-menu" class="imgedit-popup-menu">
[66] Fix | Delete
<?php
[67] Fix | Delete
// On some setups GD library does not provide imagerotate() - Ticket #11536.
[68] Fix | Delete
if ( wp_image_editor_supports(
[69] Fix | Delete
array(
[70] Fix | Delete
'mime_type' => get_post_mime_type( $post_id ),
[71] Fix | Delete
'methods' => array( 'rotate' ),
[72] Fix | Delete
)
[73] Fix | Delete
) ) {
[74] Fix | Delete
$note_no_rotate = '';
[75] Fix | Delete
?>
[76] Fix | Delete
<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&deg; left' ); ?></button>
[77] Fix | Delete
<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&deg; right' ); ?></button>
[78] Fix | Delete
<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&deg;' ); ?></button>
[79] Fix | Delete
<?php
[80] Fix | Delete
} else {
[81] Fix | Delete
$note_no_rotate = '<p class="note-no-rotate"><em>' . __( 'Image rotation is not supported by your web host.' ) . '</em></p>';
[82] Fix | Delete
?>
[83] Fix | Delete
<button type="button" class="imgedit-rleft button disabled" disabled></button>
[84] Fix | Delete
<button type="button" class="imgedit-rright button disabled" disabled></button>
[85] Fix | Delete
<?php
[86] Fix | Delete
}
[87] Fix | Delete
?>
[88] Fix | Delete
<hr />
[89] Fix | Delete
<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>
[90] Fix | Delete
<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>
[91] Fix | Delete
<?php echo $note_no_rotate; ?>
[92] Fix | Delete
</div>
[93] Fix | Delete
</div>
[94] Fix | Delete
</div>
[95] Fix | Delete
<div class="imgedit-submit imgedit-menu">
[96] Fix | Delete
<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>
[97] Fix | Delete
<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>
[98] Fix | Delete
<button type="button" onclick="imageEdit.close(<?php echo $post_id; ?>, 1)" class="button imgedit-cancel-btn"><?php esc_html_e( 'Cancel Editing' ); ?></button>
[99] Fix | Delete
<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>
[100] Fix | Delete
</div>
[101] Fix | Delete
</div>
[102] Fix | Delete
[103] Fix | Delete
<div class="imgedit-panel-content wp-clearfix">
[104] Fix | Delete
<div class="imgedit-tools">
[105] Fix | Delete
<input type="hidden" id="imgedit-nonce-<?php echo $post_id; ?>" value="<?php echo $nonce; ?>" />
[106] Fix | Delete
<input type="hidden" id="imgedit-sizer-<?php echo $post_id; ?>" value="<?php echo $sizer; ?>" />
[107] Fix | Delete
<input type="hidden" id="imgedit-history-<?php echo $post_id; ?>" value="" />
[108] Fix | Delete
<input type="hidden" id="imgedit-undone-<?php echo $post_id; ?>" value="0" />
[109] Fix | Delete
<input type="hidden" id="imgedit-selection-<?php echo $post_id; ?>" value="" />
[110] Fix | Delete
<input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />
[111] Fix | Delete
<input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />
[112] Fix | Delete
[113] Fix | Delete
<div id="imgedit-crop-<?php echo $post_id; ?>" class="imgedit-crop-wrap">
[114] Fix | Delete
<div class="imgedit-crop-grid"></div>
[115] Fix | Delete
<img id="image-preview-<?php echo $post_id; ?>" onload="imageEdit.imgLoaded('<?php echo $post_id; ?>')"
[116] Fix | Delete
src="<?php echo esc_url( admin_url( 'admin-ajax.php', 'relative' ) ) . '?action=imgedit-preview&amp;_ajax_nonce=' . $nonce . '&amp;postid=' . $post_id . '&amp;rand=' . rand( 1, 99999 ); ?>" alt="" />
[117] Fix | Delete
</div>
[118] Fix | Delete
</div>
[119] Fix | Delete
<div class="imgedit-settings">
[120] Fix | Delete
<div class="imgedit-tool-active">
[121] Fix | Delete
<div class="imgedit-group">
[122] Fix | Delete
<div id="imgedit-scale" tabindex="-1" class="imgedit-group-controls">
[123] Fix | Delete
<div class="imgedit-group-top">
[124] Fix | Delete
<h2><?php _e( 'Scale Image' ); ?></h2>
[125] Fix | Delete
<button type="button" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);" aria-expanded="false"><span class="screen-reader-text">
[126] Fix | Delete
<?php
[127] Fix | Delete
/* translators: Hidden accessibility text. */
[128] Fix | Delete
esc_html_e( 'Scale Image Help' );
[129] Fix | Delete
?>
[130] Fix | Delete
</span></button>
[131] Fix | Delete
<div class="imgedit-help">
[132] Fix | Delete
<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>
[133] Fix | Delete
</div>
[134] Fix | Delete
<?php if ( isset( $meta['width'], $meta['height'] ) ) : ?>
[135] Fix | Delete
<p>
[136] Fix | Delete
<?php
[137] Fix | Delete
printf(
[138] Fix | Delete
/* translators: %s: Image width and height in pixels. */
[139] Fix | Delete
__( 'Original dimensions %s' ),
[140] Fix | Delete
'<span class="imgedit-original-dimensions">' . $meta['width'] . ' &times; ' . $meta['height'] . '</span>'
[141] Fix | Delete
);
[142] Fix | Delete
?>
[143] Fix | Delete
</p>
[144] Fix | Delete
<?php endif; ?>
[145] Fix | Delete
<div class="imgedit-submit">
[146] Fix | Delete
<fieldset class="imgedit-scale-controls">
[147] Fix | Delete
<legend><?php _e( 'New dimensions:' ); ?></legend>
[148] Fix | Delete
<div class="nowrap">
[149] Fix | Delete
<label for="imgedit-scale-width-<?php echo $post_id; ?>" class="screen-reader-text">
[150] Fix | Delete
<?php
[151] Fix | Delete
/* translators: Hidden accessibility text. */
[152] Fix | Delete
_e( 'scale height' );
[153] Fix | Delete
?>
[154] Fix | Delete
</label>
[155] Fix | Delete
<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; ?>" />
[156] Fix | Delete
<span class="imgedit-separator" aria-hidden="true">&times;</span>
[157] Fix | Delete
<label for="imgedit-scale-height-<?php echo $post_id; ?>" class="screen-reader-text"><?php _e( 'scale height' ); ?></label>
[158] Fix | Delete
<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; ?>" />
[159] Fix | Delete
<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>
[160] Fix | Delete
</div>
[161] Fix | Delete
<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>
[162] Fix | Delete
</fieldset>
[163] Fix | Delete
</div>
[164] Fix | Delete
</div>
[165] Fix | Delete
</div>
[166] Fix | Delete
</div>
[167] Fix | Delete
[168] Fix | Delete
<?php if ( $can_restore ) { ?>
[169] Fix | Delete
<div class="imgedit-group">
[170] Fix | Delete
<div class="imgedit-group-top">
[171] Fix | Delete
<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>
[172] Fix | Delete
<div class="imgedit-help imgedit-restore">
[173] Fix | Delete
<p>
[174] Fix | Delete
<?php
[175] Fix | Delete
_e( 'Discard any changes and restore the original image.' );
[176] Fix | Delete
if ( ! defined( 'IMAGE_EDIT_OVERWRITE' ) || ! IMAGE_EDIT_OVERWRITE ) {
[177] Fix | Delete
echo ' ' . __( 'Previously edited copies of the image will not be deleted.' );
[178] Fix | Delete
}
[179] Fix | Delete
?>
[180] Fix | Delete
</p>
[181] Fix | Delete
<div class="imgedit-submit">
[182] Fix | Delete
<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; ?> />
[183] Fix | Delete
</div>
[184] Fix | Delete
</div>
[185] Fix | Delete
</div>
[186] Fix | Delete
</div>
[187] Fix | Delete
<?php } ?>
[188] Fix | Delete
<div class="imgedit-group">
[189] Fix | Delete
<div id="imgedit-crop" tabindex="-1" class="imgedit-group-controls">
[190] Fix | Delete
<div class="imgedit-group-top">
[191] Fix | Delete
<h2><?php _e( 'Crop Image' ); ?></h2>
[192] Fix | Delete
<button type="button" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);" aria-expanded="false"><span class="screen-reader-text">
[193] Fix | Delete
<?php
[194] Fix | Delete
/* translators: Hidden accessibility text. */
[195] Fix | Delete
_e( 'Image Crop Help' );
[196] Fix | Delete
?>
[197] Fix | Delete
</span></button>
[198] Fix | Delete
<div class="imgedit-help">
[199] Fix | Delete
<p><?php _e( 'To crop the image, click on it and drag to make your selection.' ); ?></p>
[200] Fix | Delete
<p><strong><?php _e( 'Crop Aspect Ratio' ); ?></strong><br />
[201] Fix | Delete
<?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>
[202] Fix | Delete
[203] Fix | Delete
<p><strong><?php _e( 'Crop Selection' ); ?></strong><br />
[204] Fix | Delete
<?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>
[205] Fix | Delete
</div>
[206] Fix | Delete
</div>
[207] Fix | Delete
<fieldset class="imgedit-crop-ratio">
[208] Fix | Delete
<legend><?php _e( 'Aspect ratio:' ); ?></legend>
[209] Fix | Delete
<div class="nowrap">
[210] Fix | Delete
<label for="imgedit-crop-width-<?php echo $post_id; ?>" class="screen-reader-text">
[211] Fix | Delete
<?php
[212] Fix | Delete
/* translators: Hidden accessibility text. */
[213] Fix | Delete
_e( 'crop ratio width' );
[214] Fix | Delete
?>
[215] Fix | Delete
</label>
[216] Fix | Delete
<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)" />
[217] Fix | Delete
<span class="imgedit-separator" aria-hidden="true">:</span>
[218] Fix | Delete
<label for="imgedit-crop-height-<?php echo $post_id; ?>" class="screen-reader-text">
[219] Fix | Delete
<?php
[220] Fix | Delete
/* translators: Hidden accessibility text. */
[221] Fix | Delete
_e( 'crop ratio height' );
[222] Fix | Delete
?>
[223] Fix | Delete
</label>
[224] Fix | Delete
<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)" />
[225] Fix | Delete
</div>
[226] Fix | Delete
</fieldset>
[227] Fix | Delete
<fieldset id="imgedit-crop-sel-<?php echo $post_id; ?>" class="imgedit-crop-sel">
[228] Fix | Delete
<legend><?php _e( 'Selection:' ); ?></legend>
[229] Fix | Delete
<div class="nowrap">
[230] Fix | Delete
<label for="imgedit-sel-width-<?php echo $post_id; ?>" class="screen-reader-text">
[231] Fix | Delete
<?php
[232] Fix | Delete
/* translators: Hidden accessibility text. */
[233] Fix | Delete
_e( 'selection width' );
[234] Fix | Delete
?>
[235] Fix | Delete
</label>
[236] Fix | Delete
<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)" />
[237] Fix | Delete
<span class="imgedit-separator" aria-hidden="true">&times;</span>
[238] Fix | Delete
<label for="imgedit-sel-height-<?php echo $post_id; ?>" class="screen-reader-text">
[239] Fix | Delete
<?php
[240] Fix | Delete
/* translators: Hidden accessibility text. */
[241] Fix | Delete
_e( 'selection height' );
[242] Fix | Delete
?>
[243] Fix | Delete
</label>
[244] Fix | Delete
<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)" />
[245] Fix | Delete
</div>
[246] Fix | Delete
</fieldset>
[247] Fix | Delete
<fieldset id="imgedit-crop-sel-<?php echo $post_id; ?>" class="imgedit-crop-sel">
[248] Fix | Delete
<legend><?php _e( 'Starting Coordinates:' ); ?></legend>
[249] Fix | Delete
<div class="nowrap">
[250] Fix | Delete
<label for="imgedit-start-x-<?php echo $post_id; ?>" class="screen-reader-text">
[251] Fix | Delete
<?php
[252] Fix | Delete
/* translators: Hidden accessibility text. */
[253] Fix | Delete
_e( 'horizontal start position' );
[254] Fix | Delete
?>
[255] Fix | Delete
</label>
[256] Fix | Delete
<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" />
[257] Fix | Delete
<span class="imgedit-separator" aria-hidden="true">&times;</span>
[258] Fix | Delete
<label for="imgedit-start-y-<?php echo $post_id; ?>" class="screen-reader-text">
[259] Fix | Delete
<?php
[260] Fix | Delete
/* translators: Hidden accessibility text. */
[261] Fix | Delete
_e( 'vertical start position' );
[262] Fix | Delete
?>
[263] Fix | Delete
</label>
[264] Fix | Delete
<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" />
[265] Fix | Delete
</div>
[266] Fix | Delete
</fieldset>
[267] Fix | Delete
<div class="imgedit-crop-apply imgedit-menu container">
[268] Fix | Delete
<button class="button 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>
[269] Fix | Delete
</div>
[270] Fix | Delete
</div>
[271] Fix | Delete
</div>
[272] Fix | Delete
</div>
[273] Fix | Delete
[274] Fix | Delete
<?php
[275] Fix | Delete
if ( $edit_thumbnails_separately && $thumb && $sub_sizes ) {
[276] Fix | Delete
$thumb_img = wp_constrain_dimensions( $thumb['width'], $thumb['height'], 160, 120 );
[277] Fix | Delete
?>
[278] Fix | Delete
[279] Fix | Delete
<div class="imgedit-group imgedit-applyto">
[280] Fix | Delete
<div class="imgedit-group-top">
[281] Fix | Delete
<h2><?php _e( 'Thumbnail Settings' ); ?></h2>
[282] Fix | Delete
<button type="button" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);" aria-expanded="false"><span class="screen-reader-text">
[283] Fix | Delete
<?php
[284] Fix | Delete
/* translators: Hidden accessibility text. */
[285] Fix | Delete
esc_html_e( 'Thumbnail Settings Help' );
[286] Fix | Delete
?>
[287] Fix | Delete
</span></button>
[288] Fix | Delete
<div class="imgedit-help">
[289] Fix | Delete
<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>
[290] Fix | Delete
</div>
[291] Fix | Delete
</div>
[292] Fix | Delete
<div class="imgedit-thumbnail-preview-group">
[293] Fix | Delete
<figure class="imgedit-thumbnail-preview">
[294] Fix | Delete
<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" />
[295] Fix | Delete
<figcaption class="imgedit-thumbnail-preview-caption"><?php _e( 'Current thumbnail' ); ?></figcaption>
[296] Fix | Delete
</figure>
[297] Fix | Delete
<div id="imgedit-save-target-<?php echo $post_id; ?>" class="imgedit-save-target">
[298] Fix | Delete
<fieldset>
[299] Fix | Delete
<legend><?php _e( 'Apply changes to:' ); ?></legend>
[300] Fix | Delete
[301] Fix | Delete
<span class="imgedit-label">
[302] Fix | Delete
<input type="radio" id="imgedit-target-all" name="imgedit-target-<?php echo $post_id; ?>" value="all" checked="checked" />
[303] Fix | Delete
<label for="imgedit-target-all"><?php _e( 'All image sizes' ); ?></label>
[304] Fix | Delete
</span>
[305] Fix | Delete
[306] Fix | Delete
<span class="imgedit-label">
[307] Fix | Delete
<input type="radio" id="imgedit-target-thumbnail" name="imgedit-target-<?php echo $post_id; ?>" value="thumbnail" />
[308] Fix | Delete
<label for="imgedit-target-thumbnail"><?php _e( 'Thumbnail' ); ?></label>
[309] Fix | Delete
</span>
[310] Fix | Delete
[311] Fix | Delete
<span class="imgedit-label">
[312] Fix | Delete
<input type="radio" id="imgedit-target-nothumb" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" />
[313] Fix | Delete
<label for="imgedit-target-nothumb"><?php _e( 'All sizes except thumbnail' ); ?></label>
[314] Fix | Delete
</span>
[315] Fix | Delete
[316] Fix | Delete
</fieldset>
[317] Fix | Delete
</div>
[318] Fix | Delete
</div>
[319] Fix | Delete
</div>
[320] Fix | Delete
<?php } ?>
[321] Fix | Delete
</div>
[322] Fix | Delete
</div>
[323] Fix | Delete
[324] Fix | Delete
</div>
[325] Fix | Delete
[326] Fix | Delete
<div class="imgedit-wait" id="imgedit-wait-<?php echo $post_id; ?>"></div>
[327] Fix | Delete
<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>
[328] Fix | Delete
</div>
[329] Fix | Delete
<?php
[330] Fix | Delete
}
[331] Fix | Delete
[332] Fix | Delete
/**
[333] Fix | Delete
* Streams image in WP_Image_Editor to browser.
[334] Fix | Delete
*
[335] Fix | Delete
* @since 2.9.0
[336] Fix | Delete
*
[337] Fix | Delete
* @param WP_Image_Editor $image The image editor instance.
[338] Fix | Delete
* @param string $mime_type The mime type of the image.
[339] Fix | Delete
* @param int $attachment_id The image's attachment post ID.
[340] Fix | Delete
* @return bool True on success, false on failure.
[341] Fix | Delete
*/
[342] Fix | Delete
function wp_stream_image( $image, $mime_type, $attachment_id ) {
[343] Fix | Delete
if ( $image instanceof WP_Image_Editor ) {
[344] Fix | Delete
[345] Fix | Delete
/**
[346] Fix | Delete
* Filters the WP_Image_Editor instance for the image to be streamed to the browser.
[347] Fix | Delete
*
[348] Fix | Delete
* @since 3.5.0
[349] Fix | Delete
*
[350] Fix | Delete
* @param WP_Image_Editor $image The image editor instance.
[351] Fix | Delete
* @param int $attachment_id The attachment post ID.
[352] Fix | Delete
*/
[353] Fix | Delete
$image = apply_filters( 'image_editor_save_pre', $image, $attachment_id );
[354] Fix | Delete
[355] Fix | Delete
if ( is_wp_error( $image->stream( $mime_type ) ) ) {
[356] Fix | Delete
return false;
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
return true;
[360] Fix | Delete
} else {
[361] Fix | Delete
/* translators: 1: $image, 2: WP_Image_Editor */
[362] Fix | Delete
_deprecated_argument( __FUNCTION__, '3.5.0', sprintf( __( '%1$s needs to be a %2$s object.' ), '$image', 'WP_Image_Editor' ) );
[363] Fix | Delete
[364] Fix | Delete
/**
[365] Fix | Delete
* Filters the GD image resource to be streamed to the browser.
[366] Fix | Delete
*
[367] Fix | Delete
* @since 2.9.0
[368] Fix | Delete
* @deprecated 3.5.0 Use {@see 'image_editor_save_pre'} instead.
[369] Fix | Delete
*
[370] Fix | Delete
* @param resource|GdImage $image Image resource to be streamed.
[371] Fix | Delete
* @param int $attachment_id The attachment post ID.
[372] Fix | Delete
*/
[373] Fix | Delete
$image = apply_filters_deprecated( 'image_save_pre', array( $image, $attachment_id ), '3.5.0', 'image_editor_save_pre' );
[374] Fix | Delete
[375] Fix | Delete
switch ( $mime_type ) {
[376] Fix | Delete
case 'image/jpeg':
[377] Fix | Delete
header( 'Content-Type: image/jpeg' );
[378] Fix | Delete
return imagejpeg( $image, null, 90 );
[379] Fix | Delete
case 'image/png':
[380] Fix | Delete
header( 'Content-Type: image/png' );
[381] Fix | Delete
return imagepng( $image );
[382] Fix | Delete
case 'image/gif':
[383] Fix | Delete
header( 'Content-Type: image/gif' );
[384] Fix | Delete
return imagegif( $image );
[385] Fix | Delete
case 'image/webp':
[386] Fix | Delete
if ( function_exists( 'imagewebp' ) ) {
[387] Fix | Delete
header( 'Content-Type: image/webp' );
[388] Fix | Delete
return imagewebp( $image, null, 90 );
[389] Fix | Delete
}
[390] Fix | Delete
return false;
[391] Fix | Delete
case 'image/avif':
[392] Fix | Delete
if ( function_exists( 'imageavif' ) ) {
[393] Fix | Delete
header( 'Content-Type: image/avif' );
[394] Fix | Delete
return imageavif( $image, null, 90 );
[395] Fix | Delete
}
[396] Fix | Delete
return false;
[397] Fix | Delete
default:
[398] Fix | Delete
return false;
[399] Fix | Delete
}
[400] Fix | Delete
}
[401] Fix | Delete
}
[402] Fix | Delete
[403] Fix | Delete
/**
[404] Fix | Delete
* Saves image to file.
[405] Fix | Delete
*
[406] Fix | Delete
* @since 2.9.0
[407] Fix | Delete
* @since 3.5.0 The `$image` parameter expects a `WP_Image_Editor` instance.
[408] Fix | Delete
* @since 6.0.0 The `$filesize` value was added to the returned array.
[409] Fix | Delete
*
[410] Fix | Delete
* @param string $filename Name of the file to be saved.
[411] Fix | Delete
* @param WP_Image_Editor $image The image editor instance.
[412] Fix | Delete
* @param string $mime_type The mime type of the image.
[413] Fix | Delete
* @param int $post_id Attachment post ID.
[414] Fix | Delete
* @return array|WP_Error|bool {
[415] Fix | Delete
* Array on success or WP_Error if the file failed to save.
[416] Fix | Delete
* When called with a deprecated value for the `$image` parameter,
[417] Fix | Delete
* i.e. a non-`WP_Image_Editor` image resource or `GdImage` instance,
[418] Fix | Delete
* the function will return true on success, false on failure.
[419] Fix | Delete
*
[420] Fix | Delete
* @type string $path Path to the image file.
[421] Fix | Delete
* @type string $file Name of the image file.
[422] Fix | Delete
* @type int $width Image width.
[423] Fix | Delete
* @type int $height Image height.
[424] Fix | Delete
* @type string $mime-type The mime type of the image.
[425] Fix | Delete
* @type int $filesize File size of the image.
[426] Fix | Delete
* }
[427] Fix | Delete
*/
[428] Fix | Delete
function wp_save_image_file( $filename, $image, $mime_type, $post_id ) {
[429] Fix | Delete
if ( $image instanceof WP_Image_Editor ) {
[430] Fix | Delete
[431] Fix | Delete
/** This filter is documented in wp-admin/includes/image-edit.php */
[432] Fix | Delete
$image = apply_filters( 'image_editor_save_pre', $image, $post_id );
[433] Fix | Delete
[434] Fix | Delete
/**
[435] Fix | Delete
* Filters whether to skip saving the image file.
[436] Fix | Delete
*
[437] Fix | Delete
* Returning a non-null value will short-circuit the save method,
[438] Fix | Delete
* returning that value instead.
[439] Fix | Delete
*
[440] Fix | Delete
* @since 3.5.0
[441] Fix | Delete
*
[442] Fix | Delete
* @param bool|null $override Value to return instead of saving. Default null.
[443] Fix | Delete
* @param string $filename Name of the file to be saved.
[444] Fix | Delete
* @param WP_Image_Editor $image The image editor instance.
[445] Fix | Delete
* @param string $mime_type The mime type of the image.
[446] Fix | Delete
* @param int $post_id Attachment post ID.
[447] Fix | Delete
*/
[448] Fix | Delete
$saved = apply_filters( 'wp_save_image_editor_file', null, $filename, $image, $mime_type, $post_id );
[449] Fix | Delete
[450] Fix | Delete
if ( null !== $saved ) {
[451] Fix | Delete
return $saved;
[452] Fix | Delete
}
[453] Fix | Delete
[454] Fix | Delete
return $image->save( $filename, $mime_type );
[455] Fix | Delete
} else {
[456] Fix | Delete
/* translators: 1: $image, 2: WP_Image_Editor */
[457] Fix | Delete
_deprecated_argument( __FUNCTION__, '3.5.0', sprintf( __( '%1$s needs to be a %2$s object.' ), '$image', 'WP_Image_Editor' ) );
[458] Fix | Delete
[459] Fix | Delete
/** This filter is documented in wp-admin/includes/image-edit.php */
[460] Fix | Delete
$image = apply_filters_deprecated( 'image_save_pre', array( $image, $post_id ), '3.5.0', 'image_editor_save_pre' );
[461] Fix | Delete
[462] Fix | Delete
/**
[463] Fix | Delete
* Filters whether to skip saving the image file.
[464] Fix | Delete
*
[465] Fix | Delete
* Returning a non-null value will short-circuit the save method,
[466] Fix | Delete
* returning that value instead.
[467] Fix | Delete
*
[468] Fix | Delete
* @since 2.9.0
[469] Fix | Delete
* @deprecated 3.5.0 Use {@see 'wp_save_image_editor_file'} instead.
[470] Fix | Delete
*
[471] Fix | Delete
* @param bool|null $override Value to return instead of saving. Default null.
[472] Fix | Delete
* @param string $filename Name of the file to be saved.
[473] Fix | Delete
* @param resource|GdImage $image Image resource or GdImage instance.
[474] Fix | Delete
* @param string $mime_type The mime type of the image.
[475] Fix | Delete
* @param int $post_id Attachment post ID.
[476] Fix | Delete
*/
[477] Fix | Delete
$saved = apply_filters_deprecated(
[478] Fix | Delete
'wp_save_image_file',
[479] Fix | Delete
array( null, $filename, $image, $mime_type, $post_id ),
[480] Fix | Delete
'3.5.0',
[481] Fix | Delete
'wp_save_image_editor_file'
[482] Fix | Delete
);
[483] Fix | Delete
[484] Fix | Delete
if ( null !== $saved ) {
[485] Fix | Delete
return $saved;
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
switch ( $mime_type ) {
[489] Fix | Delete
case 'image/jpeg':
[490] Fix | Delete
/** This filter is documented in wp-includes/class-wp-image-editor.php */
[491] Fix | Delete
return imagejpeg( $image, $filename, apply_filters( 'jpeg_quality', 90, 'edit_image' ) );
[492] Fix | Delete
case 'image/png':
[493] Fix | Delete
return imagepng( $image, $filename );
[494] Fix | Delete
case 'image/gif':
[495] Fix | Delete
return imagegif( $image, $filename );
[496] Fix | Delete
case 'image/webp':
[497] Fix | Delete
if ( function_exists( 'imagewebp' ) ) {
[498] Fix | Delete
return imagewebp( $image, $filename );
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function