Skip to content

Commit

Permalink
Font Library: Fix font installation failure (#55893)
Browse files Browse the repository at this point in the history
* Font Library: Fix font installation failure

* Made 'has_upload_director' private

---------

Co-authored-by: Jason Crist <[email protected]>
  • Loading branch information
t-hamano and pbking authored Nov 7, 2023
1 parent 659c960 commit eba64ca
Showing 1 changed file with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,18 @@ public function update_font_library_permissions_check() {
return true;
}

/**
* Checks whether the font directory exists or not.
*
* @since 6.5.0
*
* @return bool Whether the font directory exists.
*/
private function has_upload_directory() {
$upload_dir = WP_Font_Library::get_fonts_dir();
return is_dir( $upload_dir );
}

/**
* Checks whether the user has write permissions to the temp and fonts directories.
*
Expand Down Expand Up @@ -418,12 +430,29 @@ public function install_fonts( $request ) {
$response_status = 400;
}

if ( $this->needs_write_permission( $fonts_to_install ) && ! $this->has_write_permission() ) {
$errors[] = new WP_Error(
'cannot_write_fonts_folder',
__( 'Error: WordPress does not have permission to write the fonts folder on your server.', 'gutenberg' )
);
$response_status = 500;
if ( $this->needs_write_permission( $fonts_to_install ) ) {
$upload_dir = WP_Font_Library::get_fonts_dir();
if ( ! $this->has_upload_directory() ) {
if ( ! wp_mkdir_p( $upload_dir ) ) {
$errors[] = new WP_Error(
'cannot_create_fonts_folder',
sprintf(
/* translators: %s: Directory path. */
__( 'Error: Unable to create directory %s.', 'gutenberg' ),
esc_html( $upload_dir )
)
);
$response_status = 500;
}
}

if ( $this->has_upload_directory() && ! $this->has_write_permission() ) {
$errors[] = new WP_Error(
'cannot_write_fonts_folder',
__( 'Error: WordPress does not have permission to write the fonts folder on your server.', 'gutenberg' )
);
$response_status = 500;
}
}

if ( ! empty( $errors ) ) {
Expand Down

1 comment on commit eba64ca

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in eba64ca.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6787063792
📝 Reported issues:

Please sign in to comment.