wp_image_editor

函数


wp_image_editor ( $post_id, $msg = false )
参数
  • (int)
    $post_id
    Attachment post ID.
    Required:
  • (false|object)
    $msg
    Optional. Message to display for image editor updates or errors. Default false.
    Required:
    Default: false
定义位置
  • wp-admin/includes/image-edit.php
    , line 18
引入
2.9.0
弃用

加载WP图像编辑界面。

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 = "";
		} elseif ( isset( $msg->msg ) ) {
			$note = "";
		}
	}
	$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 );
	?>
	
get_post_mime_type( $post_id ), 'methods' => array( 'rotate' ), ) ) ) { $note_no_rotate = ''; ?> <?php } else { $note_no_rotate = '

' . __( 'Image rotation is not supported by your web host.' ) . ''; ?>

wp_image_editor插图
)" disabled="disabled" class="button button-primary imgedit-submit-btn" value="" />

<?php printf( /* translators: %s: Image width and height in pixels. */ __( 'Original dimensions %s' ), '' . $meta['width'] . ' × ' . $meta['height'] . '' ); ?>

!
, 'scale')" class="button button-primary" value="" />

, 'restore')" class="button button-primary" value="" />



wp_image_editor插图1
$size ) { if ( array_key_exists( $size, $meta['sizes'] ) ) { if ( 'thumbnail' === $size ) { continue; } ?>
<?php }