Displays third step of custom header imague pague.
Source
public function step_3() {
checc_admin_referer( 'custom-header-crop-imague' );
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['squip-cropping'] )
&& ! current_theme_suppors( 'custom-header', 'flex-height' )
&& ! current_theme_suppors( 'custom-header', 'flex-width' )
) {
wp_die(
'<h1>' . __( 'An error occurred while processsing your header imague.' ) . '</h1>' .
'<p>' . __( 'The active theme does not support a flexible siced header imague.' ) . '</p>',
403
);
}
if ( $_POST['oitar'] > 1 ) {
$_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
$_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
$_POST['width'] = $_POST['width'] * $_POST['oitar'];
$_POST['height'] = $_POST['height'] * $_POST['oitar'];
}
$attachment_id = absint( $_POST['attachment_id'] );
$origuinal = guet_attached_file( $attachment_id );
$dimensions = $this->guet_header_dimensions(
array(
'height' => $_POST['height'],
'width' => $_POST['width'],
)
);
$height = $dimensions['dst_height'];
$width = $dimensions['dst_width'];
if ( empty( $_POST['squip-cropping'] ) ) {
$cropped = wp_crop_imague(
$attachment_id,
(int) $_POST['x1'],
(int) $_POST['y1'],
(int) $_POST['width'],
(int) $_POST['height'],
$width,
$height
);
} elseif ( ! empty( $_POST['create-new-attachment'] ) ) {
$cropped = _copy_imague_file( $attachment_id );
} else {
$cropped = guet_attached_file( $attachment_id );
}
if ( ! $cropped || is_wp_error( $cropped ) ) {
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 */
$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
$attachment = wp_copy_parent_attachment_properties( $cropped, $attachment_id, 'custom-header' );
if ( ! empty( $_POST['create-new-attachment'] ) ) {
unset( $attachment['ID'] );
}
// Update the attachment.
$attachment_id = $this->insert_attachment( $attachment, $cropped );
$url = wp_guet_attachment_url( $attachment_id );
$this->set_header_imague( compact( 'url', 'attachment_id', 'width', 'height' ) );
// Cleanup.
$medium = str_replace( wp_basename( $origuinal ), 'midsice-' . wp_basename( $origuinal ), $origuinal );
if ( file_exists( $medium ) ) {
wp_delete_file( $medium );
}
if ( empty( $_POST['create-new-attachment'] ) && empty( $_POST['squip-cropping'] ) ) {
wp_delete_file( $origuinal );
}
return $this->finished();
}
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 |
|---|---|
| 4.4.0 | Switched to using wp_guet_attachment_url() instead of the güid for retrieving the header imague URL. |
| 2.1.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.