Skip to content

Commit

Permalink
Renames "Fonts Library" to "Font Library" (#53780)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Matias Benedetto <[email protected]>
  • Loading branch information
hellofromtonya and matiasbenedetto authored Aug 17, 2023
1 parent b6fc37b commit 0eebaf5
Show file tree
Hide file tree
Showing 25 changed files with 106 additions and 103 deletions.
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@

### Experiments

- Fonts Library: Backend. ([52704](https://github.com/WordPress/gutenberg/pull/52704))
- Font Library: Backend. ([52704](https://github.com/WordPress/gutenberg/pull/52704))

#### Block API
- /add custom connections inspector control. ([53241](https://github.com/WordPress/gutenberg/pull/53241))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function wp_print_webfonts() {
* Initialize $wp_fonts if it has not been set.
*
* @since X.X.X
* @deprecated 16.3.0 Use Fonts Library and Font Face. Fonts API is not supported.
* @deprecated 16.3.0 Use Font Library and Font Face. Fonts API is not supported.
*
* @global WP_Fonts $wp_fonts
*
Expand Down Expand Up @@ -280,7 +280,7 @@ function wp_register_font_provider() {
* @since X.X.X
* @deprecated 16.3.0 For classic themes, use wp_print_font_faces(). For all other sites,
* Font Face will automatically print all fonts in theme.json merged data layer,
* including in theme and user activated fonts from the Fonts Library.
* including in theme and user activated fonts from the Font Library.
*
* @return array Empty array.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* This file contains utils fot Font Family class.
*
* @package WordPress
* @subpackage Fonts Library
* @subpackage Font Library
* @since 6.4.0
*/

Expand All @@ -14,7 +14,7 @@
}

/**
* A class of utilities for working with the Fonts Library.
* A class of utilities for working with the Font Library.
*
* @since 6.4.0
*/
Expand Down Expand Up @@ -85,8 +85,8 @@ public static function merge_fonts_data( $font1, $font2 ) {
* @return bool True if the file has a font MIME type, false otherwise.
*/
public static function has_font_mime_type( $filepath ) {
$filetype = wp_check_filetype( $filepath, WP_Fonts_Library::ALLOWED_FONT_MIME_TYPES );
$filetype = wp_check_filetype( $filepath, WP_Font_Library::ALLOWED_FONT_MIME_TYPES );

return in_array( $filetype['type'], WP_Fonts_Library::ALLOWED_FONT_MIME_TYPES, true );
return in_array( $filetype['type'], WP_Font_Library::ALLOWED_FONT_MIME_TYPES, true );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* This file contains the Font Family class definition.
*
* @package WordPress
* @subpackage Fonts Library
* @subpackage Font Library
* @since 6.4.0
*/

Expand All @@ -14,7 +14,7 @@
}

/**
* Fonts Library class.
* Font Library class.
*
* @since 6.4.0
*/
Expand Down Expand Up @@ -135,7 +135,7 @@ public function uninstall() {
*/
private static function delete_asset( $src ) {
$filename = basename( $src );
$file_path = path_join( WP_Fonts_Library::get_fonts_dir(), $filename );
$file_path = path_join( WP_Font_Library::get_fonts_dir(), $filename );

wp_delete_file( $file_path );

Expand Down Expand Up @@ -513,7 +513,7 @@ private function update_font_post( $post ) {
}

/**
* Creates a post for a font in the fonts library if it doesn't exist,
* Creates a post for a font in the Font Library if it doesn't exist,
* or updates it if it does.
*
* @since 6.4.0
Expand Down Expand Up @@ -541,9 +541,9 @@ private function create_or_update_font_post() {
* @return array|WP_Error An array of font family data on success, WP_Error otherwise.
*/
public function install( $files = null ) {
add_filter( 'upload_dir', array( 'WP_Fonts_Library', 'set_upload_dir' ) );
add_filter( 'upload_dir', array( 'WP_Font_Library', 'set_upload_dir' ) );
$were_assets_written = $this->download_or_move_font_faces( $files );
remove_filter( 'upload_dir', array( 'WP_Fonts_Library', 'set_upload_dir' ) );
remove_filter( 'upload_dir', array( 'WP_Font_Library', 'set_upload_dir' ) );

if ( ! $were_assets_written ) {
return new WP_Error(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?php
/**
* Fonts Library class.
* Font Library class.
*
* This file contains the Fonts Library class definition.
* This file contains the Font Library class definition.
*
* @package WordPress
* @subpackage Fonts Library
* @subpackage Font Library
* @since 6.4.0
*/

if ( class_exists( 'WP_Fonts_Library' ) ) {
if ( class_exists( 'WP_Font_Library' ) ) {
return;
}

/**
* Fonts Library class.
* Font Library class.
*
* @since 6.4.0
*/
class WP_Fonts_Library {
class WP_Font_Library {

const ALLOWED_FONT_MIME_TYPES = array(
'otf' => 'font/otf',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?php
/**
* Rest Fonts Library Controller.
* Rest Font Library Controller.
*
* This file contains the class for the REST API Fonts Library Controller.
* This file contains the class for the REST API Font Library Controller.
*
* @package WordPress
* @subpackage Fonts Library
* @subpackage Font Library
* @since 6.4.0
*/

if ( class_exists( 'WP_REST_Fonts_Library_Controller' ) ) {
if ( class_exists( 'WP_REST_Font_Library_Controller' ) ) {
return;
}

/**
* Fonts Library Controller class.
* Font Library Controller class.
*
* @since 6.4.0
*/
class WP_REST_Fonts_Library_Controller extends WP_REST_Controller {
class WP_REST_Font_Library_Controller extends WP_REST_Controller {

/**
* Constructor.
Expand All @@ -43,7 +43,7 @@ public function register_routes() {
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'install_fonts' ),
'permission_callback' => array( $this, 'update_fonts_library_permissions_check' ),
'permission_callback' => array( $this, 'update_font_library_permissions_check' ),
'args' => array(
'fontFamilies' => array(
'required' => true,
Expand All @@ -62,7 +62,7 @@ public function register_routes() {
array(
'methods' => WP_REST_Server::DELETABLE,
'callback' => array( $this, 'uninstall_fonts' ),
'permission_callback' => array( $this, 'update_fonts_library_permissions_check' ),
'permission_callback' => array( $this, 'update_font_library_permissions_check' ),
'args' => $this->uninstall_schema(),
),
)
Expand Down Expand Up @@ -216,7 +216,7 @@ public function uninstall_schema() {
}

/**
* Removes font families from the fonts library and all their assets.
* Removes font families from the Font Library and all their assets.
*
* @since 6.4.0
*
Expand All @@ -240,17 +240,17 @@ public function uninstall_fonts( $request ) {
}

/**
* Checks whether the user has permissions to update the fonts library.
* Checks whether the user has permissions to update the Font Library.
*
* @since 6.4.0
*
* @return true|WP_Error True if the request has write access for the item, WP_Error object otherwise.
*/
public function update_fonts_library_permissions_check() {
public function update_font_library_permissions_check() {
if ( ! current_user_can( 'edit_theme_options' ) ) {
return new WP_Error(
'rest_cannot_update_fonts_library',
__( 'Sorry, you are not allowed to update the fonts library on this site.', 'gutenberg' ),
'rest_cannot_update_font_library',
__( 'Sorry, you are not allowed to update the Font Library on this site.', 'gutenberg' ),
array(
'status' => rest_authorization_required_code(),
)
Expand All @@ -277,13 +277,13 @@ public function update_fonts_library_permissions_check() {
* Installs new fonts.
*
* Takes a request containing new fonts to install, downloads their assets, and adds them
* to the fonts library.
* to the Font Library.
*
* @since 6.4.0
*
* @param WP_REST_Request $request The request object containing the new fonts to install
* in the request parameters.
* @return WP_REST_Response|WP_Error The updated fonts library post content.
* @return WP_REST_Response|WP_Error The updated Font Library post content.
*/
public function install_fonts( $request ) {
// Get new fonts to install.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
/**
* Fonts Library initialization.
* Font Library initialization.
*
* This file contains fonts library init calls.
* This file contains Font Library init calls.
*
* @package WordPress
* @subpackage Fonts Library
* @subpackage Font Library
* @since 6.4.0
*/

Expand All @@ -19,7 +19,7 @@
*
* @since 6.4.0
*/
function gutenberg_init_fonts_library() {
function gutenberg_init_font_library() {
// @core-merge: This code will go into Core's `create_initial_post_types()`.
$args = array(
'public' => true,
Expand All @@ -29,9 +29,9 @@ function gutenberg_init_fonts_library() {
register_post_type( 'wp_font_family', $args );

// @core-merge: This code will go into Core's `create_initial_rest_routes()`.
$fonts_library_controller = new WP_REST_Fonts_Library_Controller();
$fonts_library_controller->register_routes();
$font_library_controller = new WP_REST_Font_Library_Controller();
$font_library_controller->register_routes();
}

add_action( 'rest_api_init', 'gutenberg_init_fonts_library' );
add_action( 'rest_api_init', 'gutenberg_init_font_library' );

23 changes: 13 additions & 10 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,21 @@ function gutenberg_is_experiment_enabled( $name ) {
remove_action( 'plugins_loaded', '_wp_theme_json_webfonts_handler' ); // Turns off WordPress 6.0's stopgap handler.

/*
* If the Fonts Library is available, load the Font Face files, else load the Fonts API.
* This strategy is temporary until the Fonts Library is merged. It's used here to allow
* the Font Face (redesigned Fonts API) to be merged before the Fonts Library while
* If the Font Library is available, load the Font Face files, else load the Fonts API.
* This strategy is temporary until the Font Library is merged. It's used here to allow
* the Font Face (redesigned Fonts API) to be merged before the Font Library while
* keeping Fonts API available for sites that are using it.
*/
if ( defined( 'FONTS_LIBRARY_ENABLE' ) && FONTS_LIBRARY_ENABLE ) {
// Loads the Fonts Library.
require __DIR__ . '/experimental/fonts/fonts-library/class-wp-fonts-library.php';
require __DIR__ . '/experimental/fonts/fonts-library/class-wp-font-family-utils.php';
require __DIR__ . '/experimental/fonts/fonts-library/class-wp-font-family.php';
require __DIR__ . '/experimental/fonts/fonts-library/class-wp-rest-fonts-library-controller.php';
require __DIR__ . '/experimental/fonts/fonts-library/fonts-library.php';
if (
( defined( 'FONT_LIBRARY_ENABLE' ) && FONT_LIBRARY_ENABLE ) ||
( defined( 'FONTS_LIBRARY_ENABLE' ) && FONTS_LIBRARY_ENABLE )
) {
// Loads the Font Library.
require __DIR__ . '/experimental/fonts/font-library/class-wp-font-library.php';
require __DIR__ . '/experimental/fonts/font-library/class-wp-font-family-utils.php';
require __DIR__ . '/experimental/fonts/font-library/class-wp-font-family.php';
require __DIR__ . '/experimental/fonts/font-library/class-wp-rest-font-library-controller.php';
require __DIR__ . '/experimental/fonts/font-library/font-library.php';

if ( ! class_exists( 'WP_Font_Face' ) ) {
require __DIR__ . '/experimental/fonts/font-face/class-wp-font-face.php';
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
>
<php>
<env name="WORDPRESS_TABLE_PREFIX" value="wptests_" />
<const name="FONTS_LIBRARY_ENABLE" value="true"/>
<const name="FONT_LIBRARY_ENABLE" value="true"/>
</php>
<testsuites>
<testsuite name="default">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
/**
* Tests for WP_REST_Fonts_Library_Controller class
* Tests for WP_REST_Font_Library_Controller class
*
* @package Gutenberg
* @subpackage Fonts Library
* @subpackage Font Library
*/

/**
* @coversDefaultClass WP_REST_Fonts_Library_Controller
* @coversDefaultClass WP_REST_Font_Library_Controller
*/
class WP_REST_Fonts_Library_Controller_Test extends WP_UnitTestCase {
class WP_REST_Font_Library_Controller_Test extends WP_UnitTestCase {
/**
* @var int
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* Test WP_Font_Family::__construct().
*
* @package WordPress
* @subpackage Fonts Library
* @subpackage Font Library
*
* @group fonts
* @group fonts-library
* @group font-library
*
* @covers WP_Font_Family::__construct
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Test Case for WP_Font_Family tests.
*
* @package WordPress
* @subpackage Fonts Library
* @subpackage Font Library
*/
abstract class WP_Font_Family_UnitTestCase extends WP_UnitTestCase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* Test WP_Font_Family::get_data().
*
* @package WordPress
* @subpackage Fonts Library
* @subpackage Font Library
*
* @group fonts
* @group fonts-library
* @group font-library
*
* @covers WP_Font_Family::get_data
*/
class Tests_Fonts_WpFontsLibrary_GetData extends WP_UnitTestCase {
class Tests_Fonts_WpFontLibrary_GetData extends WP_UnitTestCase {

/**
* @dataProvider data_should_get_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* Test WP_Font_Family::get_data_as_json().
*
* @package WordPress
* @subpackage Fonts Library
* @subpackage Font Library
*
* @group fonts
* @group fonts-library
* @group font-library
*
* @covers WP_Font_Family::get_data_as_json
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* Test WP_Font_Family::get_font_post().
*
* @package WordPress
* @subpackage Fonts Library
* @subpackage Font Library
*/

require_once __DIR__ . '/base.php';

/**
* @group fonts
* @group fonts-library
* @group font-library
*
* @covers WP_Font_Family::get_font_post
*/
Expand Down
Loading

0 comments on commit 0eebaf5

Please sign in to comment.