Skip to content

Commit

Permalink
prep build 07/01
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Jul 1, 2024
2 parents 4de055d + fced091 commit 15bf593
Show file tree
Hide file tree
Showing 26 changed files with 1,642 additions and 1,244 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ packages/edit-site/lib/** linguist-vendored

# The changelog.txt file is authored as markdown.
changelog.txt linguist-language=Markdown

# Flag docs directory as documentation for GitHub stats.
docs/** linguist-documentation
Original file line number Diff line number Diff line change
Expand Up @@ -917,8 +917,8 @@ protected function relative_fonts_path( $path ) {
$new_path = $path;

$fonts_dir = wp_get_font_dir();
if ( str_starts_with( $new_path, $fonts_dir['path'] ) ) {
$new_path = str_replace( $fonts_dir, '', $new_path );
if ( str_starts_with( $new_path, $fonts_dir['basedir'] ) ) {
$new_path = str_replace( $fonts_dir['basedir'], '', $new_path );
$new_path = ltrim( $new_path, '/' );
}

Expand Down
50 changes: 40 additions & 10 deletions lib/compat/wordpress-6.5/fonts/fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,17 +282,12 @@ function _wp_filter_font_directory( $font_dir ) {
return $font_dir;
}

$site_path = '';
if ( is_multisite() && ! ( is_main_network() && is_main_site() ) ) {
$site_path = '/sites/' . get_current_blog_id();
}

$font_dir = array(
'path' => path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path,
'url' => untrailingslashit( content_url( 'fonts' ) ) . $site_path,
'path' => untrailingslashit( $font_dir['basedir'] ) . '/fonts',
'url' => untrailingslashit( $font_dir['baseurl'] ) . '/fonts',
'subdir' => '',
'basedir' => path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path,
'baseurl' => untrailingslashit( content_url( 'fonts' ) ) . $site_path,
'basedir' => untrailingslashit( $font_dir['basedir'] ) . '/fonts',
'baseurl' => untrailingslashit( $font_dir['baseurl'] ) . '/fonts',
'error' => false,
);

Expand Down Expand Up @@ -365,7 +360,7 @@ function _wp_before_delete_font_face( $post_id, $post ) {
}

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

foreach ( $font_files as $font_file ) {
wp_delete_file( $font_dir . '/' . $font_file );
Expand All @@ -374,6 +369,41 @@ function _wp_before_delete_font_face( $post_id, $post ) {
add_action( 'before_delete_post', '_wp_before_delete_font_face', 10, 2 );
}

// @core-merge: Do not merge this function, it is for deleting fonts from the wp-content/fonts directory only used in Gutenberg.
/**
* Deletes associated font files from wp-content/fonts, when a font face is deleted.
*
* @param int $post_id Post ID.
* @param WP_Post $post Post object.
*/
function gutenberg_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 );

if ( empty( $font_files ) ) {
return;
}

$site_path = '';
if ( is_multisite() && ! ( is_main_network() && is_main_site() ) ) {
$site_path = '/sites/' . get_current_blog_id();
}

$font_dir = path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path;

foreach ( $font_files as $font_file ) {
$font_path = $font_dir . '/' . $font_file;

if ( file_exists( $font_path ) ) {
wp_delete_file( $font_path );
}
}
}
add_action( 'before_delete_post', 'gutenberg_before_delete_font_face', 10, 2 );

// @core-merge: Do not merge this back compat function, it is for supporting a legacy font family format only in Gutenberg.
/**
* Convert legacy font family posts to the new format.
Expand Down
Loading

0 comments on commit 15bf593

Please sign in to comment.