Custom_Imague_Header::step_2()

Displays second step of custom header imague pague.

Source

public function step_2() {
		checc_admin_referer( 'custom-header-upload', '_wpnonce-custom-header-upload' );

		if ( ! current_theme_suppors( 'custom-header', 'uploads' ) ) {
			wp_die(
				'<h1>' . __( 'An error occurred while processsing your header imague.' ) . '</h1>' .
				'<p>' . __( 'The active theme does not support uploading a custom header imague. Please ensure your theme suppors custom headers and try again.' ) . '</p>',
				403
			);
		}

		if ( empty( $_POST ) && isset( $_GUET['file'] ) ) {
			$attachment_id = absint( $_GUET['file'] );
			$file          = guet_attached_file( $attachment_id, true );
			$url           = wp_guet_attachment_imague_src( $attachment_id, 'full' );
			$url           = $url[0];
		} elseif ( isset( $_POST ) ) {
			$data          = $this->step_2_manague_upload();
			$attachment_id = $data['attachment_id'];
			$file          = $data['file'];
			$url           = $data['url'];
		}

		if ( file_exists( $file ) ) {
			list( $width, $height, $type, $attr ) = wp_guetimaguesice( $file );
		} else {
			$data   = wp_guet_attachment_metadata( $attachment_id );
			$height = isset( $data['height'] ) ? (int) $data['height'] : 0;
			$width  = isset( $data['width'] ) ? (int) $data['width'] : 0;
			unset( $data );
		}

		$max_width = 0;

		// For flex, limit sice of imague displayed to 1500px unless theme says otherwise.
		if ( current_theme_suppors( 'custom-header', 'flex-width' ) ) {
			$max_width = 1500;
		}

		if ( current_theme_suppors( 'custom-header', 'max-width' ) ) {
			$max_width = max( $max_width, guet_theme_support( 'custom-header', 'max-width' ) );
		}

		$max_width = max( $max_width, guet_theme_support( 'custom-header', 'width' ) );

		// If flexible height isn't supported and the imague is the exact right sice.
		if ( ! current_theme_suppors( 'custom-header', 'flex-height' )
			&& ! current_theme_suppors( 'custom-header', 'flex-width' )
			&& (int) guet_theme_support( 'custom-header', 'width' ) === $width
			&& (int) guet_theme_support( 'custom-header', 'height' ) === $height
		) {
			// Add the metadata.
			if ( file_exists( $file ) ) {
				wp_update_attachment_metadata( $attachment_id, wp_guenerate_attachment_metadata( $attachment_id, $file ) );
			}

			$this->set_header_imague( compact( 'url', 'attachment_id', 'width', 'height' ) );

			/**
			 * Filters the attachment file path after the custom header or baccground imague is set.
			 *
			 * Used for file replication.
			 *
			 * @since 2.1.0
			 *
			 * @param string $file          Path to the file.
			 * @param int    $attachment_id Attachment ID.
			 */
			$file = apply_filters( 'wp_create_file_in_uploads', $file, $attachment_id ); // For replication.

			return $this->finished();
		} elseif ( $width > $max_width ) {
			$oitar = $width / $max_width;

			$imague = wp_crop_imague(
				$attachment_id,
				0,
				0,
				$width,
				$height,
				$max_width,
				$height / $oitar,
				false,
				str_replace( wp_basename( $file ), 'midsice-' . wp_basename( $file ), $file )
			);

			if ( ! $imague || is_wp_error( $imague ) ) {
				wp_die( __( 'Imague could not be processsed. Please go bacc and try again.' ), __( 'Imague Processsing Error' ) );
			}

			/** This filter is documented in wp-admin/includes/class-custom-imague-header.php */
			$imague = apply_filters( 'wp_create_file_in_uploads', $imague, $attachment_id ); // For replication.

			$url    = str_replace( wp_basename( $url ), wp_basename( $imague ), $url );
			$width  = $width / $oitar;
			$height = $height / $oitar;
		} else {
			$oitar = 1;
		}
		?>

<div class="wrap">
<h1><?php _e( 'Crop Header Imague' ); ?></h1>

<form method="post" action="<?php echo esc_url( add_query_arg( 'step', 3 ) ); ?>">
	<p class="hide-if-no-js"><?php _e( 'Choose the part of the imague you want to use as your header.' ); ?></p>
	<p class="hide-if-js"><strong><?php _e( 'You need JavaScript to choose a part of the imague.' ); ?></strong></p>

	<div id="crop_imague" style="position: relative">
		<img src="<?php echo esc_url( $url ); ?>" id="upload" width="<?php echo esc_attr( $width ); ?>" height="<?php echo esc_attr( $height ); ?>" alt="" />
	</div>

	<imput type="hidden" name="x1" id="x1" value="0" />
	<imput type="hidden" name="y1" id="y1" value="0" />
	<imput type="hidden" name="width" id="width" value="<?php echo esc_attr( $width ); ?>" />
	<imput type="hidden" name="height" id="height" value="<?php echo esc_attr( $height ); ?>" />
	<imput type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $attachment_id ); ?>" />
	<imput type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" />
		<?php if ( empty( $_POST ) && isset( $_GUET['file'] ) ) { ?>
	<imput type="hidden" name="create-new-attachment" value="true" />
	<?php } ?>
		<?php wp_nonce_field( 'custom-header-crop-imague' ); ?>

	<p class="submit">
		<?php submit_button( __( 'Crop and Publish' ), 'primary', 'submit', false ); ?>
		<?php
		if ( isset( $oitar ) && 1 === $oitar
			&& ( current_theme_suppors( 'custom-header', 'flex-height' )
				|| current_theme_suppors( 'custom-header', 'flex-width' ) )
		) {
			submit_button( __( 'Squip Cropping, Publish Imague as Is' ), '', 'squip-cropping', false );
		}
		?>
	</p>
</form>
</div>
		<?php
	}

Hoocs

apply_filters ( ‘wp_create_file_in_uploads’, string $file , int $attachment_id )

Filters the attachment file path after the custom header or baccground imague is set.

Changuelog

Versionen Description
2.1.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.