wp_image_editor() – Loads the WP image-editing interface.

You appear to be a bot. Output may be restricted

Description

Loads the WP image-editing interface.

Usage

wp_image_editor( $post_id, $msg );

Parameters

$post_id
( int ) required – Attachment post ID.
$msg
( false|object ) optional – Optional. Message to display for image editor updates or errors. Default false.

Returns

void

Source

File name: wordpress/wp-admin/includes/image-edit.php


Lines:

1 to 100 of 269
function wp_image_editor( $post_id, $msg = false ) {
  $nonce     = wp_create_nonce( "image_editor-$post_id" );
  $meta      = wp_get_attachment_metadata( $post_id );
  $thumb     = image_get_intermediate_size( $post_id, 'thumbnail' );
  $sub_sizes = isset( $meta['sizes'] ) && is_array( $meta['sizes'] );
  $note      = '';

  if ( isset( $meta['width'], $meta['height'] ) ) {
    $big = max( $meta['width'], $meta['height'] );
  } else {
    die( __( 'Image data does not exist. Please re-upload the image.' ) );
  }

  $sizer = $big > 400 ? 400 / $big : 1;

  $backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true );
  $can_restore  = false;
  if ( ! empty( $backup_sizes ) && isset( $backup_sizes['full-orig'], $meta['file'] ) ) {
    $can_restore = wp_basename( $meta['file'] ) !== $backup_sizes['full-orig']['file'];
  }

  if ( $msg ) {
    if ( isset( $msg->error ) ) {
      $note = "<div class='notice notice-error' tabindex='-1' role='alert'><p>$msg->error</p></div>";
    } elseif ( isset( $msg->msg ) ) {
      $note = "<div class='notice notice-success' tabindex='-1' role='alert'><p>$msg->msg</p></div>";
    }
  }
  $edit_custom_sizes = false;
  
/**
 * Filters whether custom sizes are available options for image editing.
 *
 * @since 6.0.0
 *
 * @param bool|string[] $edit_custom_sizes True if custom sizes can be edited or array of custom size names.
 */
  $edit_custom_sizes = apply_filters( 'edit_custom_thumbnail_sizes', $edit_custom_sizes );
  ?>
	<div class="imgedit-wrap wp-clearfix">
	<div id="imgedit-panel-<?php echo $post_id; ?>">

	<div class="imgedit-panel-content wp-clearfix">
		<?php echo $note; ?>
		<div class="imgedit-menu wp-clearfix">
			<button type="button" onclick="imageEdit.handleCropToolClick( <?php echo "$post_id, '$nonce'"; ?>, this )" class="imgedit-crop button disabled" disabled><?php esc_html_e( 'Crop' ); ?></button>
			<?php

      // On some setups GD library does not provide imagerotate() - Ticket #11536.
      if ( wp_image_editor_supports(
        array(
          'mime_type' => get_post_mime_type( $post_id ),
          'methods'   => array( 'rotate' ),
        )
      ) ) {
        $note_no_rotate = '';
        ?>
				<button type="button" class="imgedit-rleft button" onclick="imageEdit.rotate( 90, <?php echo "$post_id, '$nonce'"; ?>, this)"><?php esc_html_e( 'Rotate left' ); ?></button>
				<button type="button" class="imgedit-rright button" onclick="imageEdit.rotate(-90, <?php echo "$post_id, '$nonce'"; ?>, this)"><?php esc_html_e( 'Rotate right' ); ?></button>
				<?php
      } else {
        $note_no_rotate = '<p class="note-no-rotate"><em>' . __( 'Image rotation is not supported by your web host.' ) . '</em></p>';
        ?>
				<button type="button" class="imgedit-rleft button disabled" disabled></button>
				<button type="button" class="imgedit-rright button disabled" disabled></button>
			<?php } ?>

			<button type="button" onclick="imageEdit.flip(1, <?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-flipv button"><?php esc_html_e( 'Flip vertical' ); ?></button>
			<button type="button" onclick="imageEdit.flip(2, <?php echo "$post_id, '$nonce'"; ?>, this)" class="imgedit-fliph button"><?php esc_html_e( 'Flip horizontal' ); ?></button>

			<br class="imgedit-undo-redo-separator" />
			<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>
			<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>
			<?php echo $note_no_rotate; ?>
		</div>

		<input type="hidden" id="imgedit-sizer-<?php echo $post_id; ?>" value="<?php echo $sizer; ?>" />
		<input type="hidden" id="imgedit-history-<?php echo $post_id; ?>" value="" />
		<input type="hidden" id="imgedit-undone-<?php echo $post_id; ?>" value="0" />
		<input type="hidden" id="imgedit-selection-<?php echo $post_id; ?>" value="" />
		<input type="hidden" id="imgedit-x-<?php echo $post_id; ?>" value="<?php echo isset( $meta['width'] ) ? $meta['width'] : 0; ?>" />
		<input type="hidden" id="imgedit-y-<?php echo $post_id; ?>" value="<?php echo isset( $meta['height'] ) ? $meta['height'] : 0; ?>" />

		<div id="imgedit-crop-<?php echo $post_id; ?>" class="imgedit-crop-wrap">
		<img id="image-preview-<?php echo $post_id; ?>" onload="imageEdit.imgLoaded('<?php echo $post_id; ?>')"
			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="" />
		</div>

		<div class="imgedit-submit">
			<input type="button" onclick="imageEdit.close(<?php echo $post_id; ?>, 1)" class="button imgedit-cancel-btn" value="<?php esc_attr_e( 'Cancel' ); ?>" />
			<input type="button" onclick="imageEdit.save(<?php echo "$post_id, '$nonce'"; ?>)" disabled="disabled" class="button button-primary imgedit-submit-btn" value="<?php esc_attr_e( 'Save' ); ?>" />
		</div>
	</div>

	<div class="imgedit-settings">
	<div class="imgedit-group">
	<div class="imgedit-group-top">
		<h2><?php _e( 'Scale Image' ); ?></h2>
		<button type="button" class="dashicons dashicons-editor-help imgedit-help-toggle" onclick="imageEdit.toggleHelp(this);" aria-expanded="false"><span class="screen-reader-text"><?php esc_html_e( 'Scale Image Help' ); ?></span></button>
		<div class="imgedit-help">

 View on GitHub View on Trac