WC_Install::delete_placeholder_imagepublic staticWC 11.0.0

Delete the placeholder image created by create_placeholder_image().

Removes the attachment post, its metadata and the underlying file, but only when the stored woocommerce_placeholder_image option still points at WooCommerce's own generated placeholder. A custom image set by the merchant through the "Placeholder image" setting is left untouched to avoid deleting merchant-owned media. The option itself is removed along with the rest of the woocommerce_ options during uninstall.

Method of the class: WC_Install{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = WC_Install::delete_placeholder_image();

Changelog

Since 11.0.0 Introduced.

WC_Install::delete_placeholder_image() code WC 11.0.1

public static function delete_placeholder_image() {
	$placeholder_image = absint( get_option( 'woocommerce_placeholder_image', 0 ) );

	if ( ! $placeholder_image ) {
		return;
	}

	// Only delete WooCommerce's own generated placeholder, never a custom image the merchant may have set.
	$attached_file = (string) get_post_meta( $placeholder_image, '_wp_attached_file', true );
	if ( 'woocommerce-placeholder.webp' !== wp_basename( $attached_file ) ) {
		return;
	}

	wp_delete_attachment( $placeholder_image, true );
}