W3cubDocs

/WordPress

_wp_before_delete_font_face( int $post_id, WP_Post $post )

Deletes associated font files when a font face is deleted.

Parameters

$post_idintrequired
Post ID.
$postWP_Postrequired
Post object.

Source

function _wp_before_delete_font_face( $post_id, $post ) {
	if ( 'wp_font_face' !== $post->post_type ) {
		return;
	}

	$font_files = get_post_meta( $post_id, '_wp_font_face_file', false );
	$font_dir   = untrailingslashit( wp_get_font_dir()['basedir'] );

	foreach ( $font_files as $font_file ) {
		wp_delete_file( $font_dir . '/' . $font_file );
	}
}

Changelog

Version Description
6.5.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/_wp_before_delete_font_face