Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fonts Library: Backend #52704

Merged
merged 174 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
3d82594
Adding fonts library backend
matiasbenedetto Jul 17, 2023
d470388
load font library
matiasbenedetto Jul 17, 2023
df4708c
Format php.
jffng Jul 17, 2023
ccc5636
Update comment.
jffng Jul 17, 2023
da9d7ea
Fix array key merge.
jffng Jul 17, 2023
b318ab8
Format php.
jffng Jul 17, 2023
9c4f88e
linting: lint and add comments where needed
Jul 17, 2023
5ef49fd
linting: add comments on rest fonts library file
Jul 17, 2023
1661b6d
lint: fix filedocs
Jul 17, 2023
5c81374
lint: fix lib loader errors
Jul 17, 2023
74f83f2
Misc updates to comments for consistency
mikachan Jul 18, 2023
9853219
Update controller name in load.php
mikachan Jul 18, 2023
b929bf0
Add an install method to the font family class to simplify the code
matiasbenedetto Jul 18, 2023
0c8978e
Renaming the Fonts Library class to Fonts Library Family to emphasize…
matiasbenedetto Jul 18, 2023
a51b59b
Renaming WP_Fonts_Library_Family to WP_Font_Family
matiasbenedetto Jul 18, 2023
999775e
lint: make sure coding standards test passes
Jul 18, 2023
b1be3fe
Replace include for admin.php with file.php
mikachan Jul 18, 2023
76c5074
Fix linter errors
mikachan Jul 18, 2023
31591a5
adding 1 php test
matiasbenedetto Jul 18, 2023
bd6b697
Merge branch 'try/fonts-library-backend' of github.com:WordPress/gute…
matiasbenedetto Jul 18, 2023
d7dcaaf
fix test
matiasbenedetto Jul 18, 2023
24ce14e
Move a few methods from Font Family class to Fonts Library
matiasbenedetto Jul 18, 2023
4b166d8
move more methods to Fonts Library class
matiasbenedetto Jul 18, 2023
9cd7cee
Breaking the classes in to smaller ones and adding tests
matiasbenedetto Jul 19, 2023
6163367
add tests font Font Family class
matiasbenedetto Jul 19, 2023
ced015c
Create fonts dir at init of wordpress
matiasbenedetto Jul 19, 2023
58dba25
Testing and refactoring WP_Font_Family class
matiasbenedetto Jul 19, 2023
228f3d0
PHP formatting
matiasbenedetto Jul 19, 2023
462b80a
fix syntax
matiasbenedetto Jul 19, 2023
849a2d5
move comment
matiasbenedetto Jul 19, 2023
2c81cad
update wording
matiasbenedetto Jul 19, 2023
b610d80
update comment
matiasbenedetto Jul 19, 2023
d9179f3
update comment
matiasbenedetto Jul 19, 2023
005f21a
update comment
matiasbenedetto Jul 19, 2023
52b447f
update comment
matiasbenedetto Jul 19, 2023
82275a7
call to sanitize before creating the post
matiasbenedetto Jul 20, 2023
c9de5e9
fix return of method
matiasbenedetto Jul 20, 2023
1cf6cc7
Addding a failing test for local fonts upload
matiasbenedetto Jul 20, 2023
6bf1d8c
micro-optimization
matiasbenedetto Jul 20, 2023
98faaff
interting the order of static and access control keywords in method d…
matiasbenedetto Jul 20, 2023
cba9f85
To avoid fatal error when the class is introduced into Core, add a gu…
matiasbenedetto Jul 20, 2023
ea8f23b
updating comments
matiasbenedetto Jul 20, 2023
771c829
adding missing access keywords for methods
matiasbenedetto Jul 20, 2023
253ec1f
WP_Theme_JSON_Gutenberg instead of WP_Theme_JSON
matiasbenedetto Jul 20, 2023
e6879d0
Moving init calls to a new file.
matiasbenedetto Jul 20, 2023
83199e6
adding comment to file
matiasbenedetto Jul 20, 2023
afc6a48
format PHP
matiasbenedetto Jul 20, 2023
c3c7169
update comment
matiasbenedetto Jul 21, 2023
0aa582a
syntax change
matiasbenedetto Jul 21, 2023
2803603
syntax change
matiasbenedetto Jul 21, 2023
82aefd9
update comment
matiasbenedetto Jul 21, 2023
c73ee9c
add missing 'new' while returning a WP_Error
matiasbenedetto Jul 21, 2023
392adf0
fix return comment
matiasbenedetto Jul 21, 2023
5b20914
renaming variable
matiasbenedetto Jul 21, 2023
11ad658
stylistic change to early return
matiasbenedetto Jul 21, 2023
9489974
shortening the syntax and variable renaming
matiasbenedetto Jul 21, 2023
6f2c113
Stylistic change: switching the order of parameters of assertEquals call
matiasbenedetto Jul 21, 2023
3acc356
simplify delete_asset method code
matiasbenedetto Jul 21, 2023
4aa9660
refactor uninstall endpoint response
matiasbenedetto Jul 21, 2023
92ae857
fixing return type comment
matiasbenedetto Jul 21, 2023
80cd47b
fixing return type and refactor to early return
matiasbenedetto Jul 21, 2023
b689232
check is post_id is an error
matiasbenedetto Jul 21, 2023
f28a81d
using assertStringEndsWith assertion
matiasbenedetto Jul 24, 2023
37cae56
update comment
matiasbenedetto Jul 24, 2023
7b13187
update comment
matiasbenedetto Jul 24, 2023
1a5ce29
update comment
matiasbenedetto Jul 24, 2023
45ddcf1
update comment
matiasbenedetto Jul 24, 2023
1c518d6
replace assertEquals by assertSame
matiasbenedetto Jul 24, 2023
af28cd3
assertSame and assertCount
matiasbenedetto Jul 24, 2023
503f449
assertFileExists
matiasbenedetto Jul 24, 2023
f923cb1
assertFileDoesNotExist
matiasbenedetto Jul 24, 2023
b90e72f
simplify has_font_faces_method
matiasbenedetto Jul 24, 2023
3a4e189
return early if there are no fonts to be installed
matiasbenedetto Jul 25, 2023
1e009d0
fix assertWPError calls
matiasbenedetto Jul 25, 2023
1d7c68b
adding public keyword to test cases
matiasbenedetto Jul 25, 2023
6c06a37
improving the suffix and sanitiztion for get_filename_from_font_face …
matiasbenedetto Jul 25, 2023
23de632
simplify uninstall method
matiasbenedetto Jul 25, 2023
7562ff3
updating comments
matiasbenedetto Jul 25, 2023
fbaea86
adding covers in php tests
matiasbenedetto Jul 25, 2023
76dce91
require font slug in the get_filename_from_font_face method
matiasbenedetto Jul 25, 2023
66c8034
improve get_datamethod test
matiasbenedetto Jul 25, 2023
fe594aa
add fixture for WP_Font_Family_Test
matiasbenedetto Jul 27, 2023
b86907b
deleting unused data
matiasbenedetto Jul 27, 2023
6acb5a0
renaminng test case
matiasbenedetto Jul 27, 2023
72d08d6
fixing WP_Font_Family_Utils_Test tests
matiasbenedetto Jul 27, 2023
4e5b583
format php
matiasbenedetto Jul 27, 2023
c51a611
adding dataProviders in WP_Font_Family_Utils_Test
matiasbenedetto Jul 27, 2023
1cae91c
adding params comments in test cases
matiasbenedetto Jul 27, 2023
06ee7a8
adding messages on tests with multiple assertions
matiasbenedetto Jul 27, 2023
fa9556c
test refactor
matiasbenedetto Jul 27, 2023
9149731
refactor test
matiasbenedetto Jul 27, 2023
e2d1a34
php format
matiasbenedetto Jul 27, 2023
4bf2846
add comments to data_provider
matiasbenedetto Jul 27, 2023
192e865
change test case name
matiasbenedetto Jul 27, 2023
06d950e
raname custom post type
matiasbenedetto Jul 27, 2023
7c741c4
Merge branch 'trunk' into try/fonts-library-backend
matiasbenedetto Jul 27, 2023
b0a9e2d
add missing parameter in docbloc
matiasbenedetto Jul 27, 2023
3cb3f49
adding comment
matiasbenedetto Jul 27, 2023
f17f49f
adding full stops at the end of param comments
matiasbenedetto Jul 27, 2023
b71213e
change test assert type
matiasbenedetto Jul 28, 2023
042fb21
change test assert type
matiasbenedetto Jul 28, 2023
c029041
change test assert type
matiasbenedetto Jul 28, 2023
fd81086
use wp_handle_upload to write thee files and use wp-content/uploads/f…
matiasbenedetto Aug 1, 2023
06e6996
Merge branch 'trunk' into try/fonts-library-backend
matiasbenedetto Aug 1, 2023
c1ac4a4
strict suffix check
matiasbenedetto Aug 1, 2023
53b128c
update comment
matiasbenedetto Aug 1, 2023
943904f
update comment
matiasbenedetto Aug 1, 2023
02fce52
moving fonts library loading before checking if its available
matiasbenedetto Aug 1, 2023
7675a9f
Merge branch 'try/fonts-library-backend' of github.com:WordPress/gute…
matiasbenedetto Aug 1, 2023
1c13db8
Fixes local font upload tests
matiasbenedetto Aug 2, 2023
8f306e0
allowing the installation of fonts with remote urls that won't be don…
matiasbenedetto Aug 2, 2023
c89af7c
delete google fonts data and endpoint
matiasbenedetto Aug 2, 2023
357ad1c
PHP code formatting
matiasbenedetto Aug 2, 2023
9d4d514
lint
matiasbenedetto Aug 3, 2023
e698420
php lint
matiasbenedetto Aug 3, 2023
7e5e711
moving post_type registration to the WP_Fonts_Library class
matiasbenedetto Aug 3, 2023
a7f9ab4
change endpoint url
matiasbenedetto Aug 3, 2023
7b911d3
adding test file for WP_REST_Fonts_Library_Controller class
matiasbenedetto Aug 4, 2023
914158a
adding tests for innstall endpoint
matiasbenedetto Aug 7, 2023
90a4f07
add test for font family constructor failure
matiasbenedetto Aug 7, 2023
10a317a
Font Family constructo raise an exception if the slug was not provided
matiasbenedetto Aug 7, 2023
cc22568
add tests for uninstall endpoint
matiasbenedetto Aug 7, 2023
ba8b567
format php
matiasbenedetto Aug 7, 2023
433aa54
add validation for install endpoint
matiasbenedetto Aug 7, 2023
bf7f3d0
fix comment
matiasbenedetto Aug 8, 2023
72ac9f4
improve comment text
matiasbenedetto Aug 8, 2023
05a6863
fix comment
matiasbenedetto Aug 8, 2023
a36cb63
fix comment
matiasbenedetto Aug 8, 2023
c4f1665
code format fix
matiasbenedetto Aug 8, 2023
62b6b8d
fix test assertion and comment
matiasbenedetto Aug 8, 2023
d25993d
fix comment
matiasbenedetto Aug 8, 2023
5f61437
fix comment
matiasbenedetto Aug 8, 2023
3f4fffa
fix comment
matiasbenedetto Aug 8, 2023
12cf920
update comment
matiasbenedetto Aug 8, 2023
16b3133
code formatting
matiasbenedetto Aug 8, 2023
94e4f69
fix comment
matiasbenedetto Aug 8, 2023
7439610
update test name
matiasbenedetto Aug 8, 2023
55ebc62
update assertion type
matiasbenedetto Aug 8, 2023
2efd15b
Improves test descripcion
matiasbenedetto Aug 8, 2023
f4e32c0
code formatting
matiasbenedetto Aug 8, 2023
9f11804
update test assertion type
matiasbenedetto Aug 8, 2023
1a64fb8
comment update
matiasbenedetto Aug 8, 2023
2b98fc7
update comment
matiasbenedetto Aug 8, 2023
be73689
update comment
matiasbenedetto Aug 8, 2023
e235ff2
update comment
matiasbenedetto Aug 8, 2023
8de2259
update comment
matiasbenedetto Aug 8, 2023
2a0b34b
update comment
matiasbenedetto Aug 8, 2023
80ec701
update comment
matiasbenedetto Aug 8, 2023
7b6e2a7
code and comments style
matiasbenedetto Aug 8, 2023
a9e29e1
comment style
matiasbenedetto Aug 8, 2023
671f382
comment update
matiasbenedetto Aug 8, 2023
217940a
update comment
matiasbenedetto Aug 8, 2023
1a70f11
update comment
matiasbenedetto Aug 8, 2023
8f74fc8
update assertion type
matiasbenedetto Aug 8, 2023
b98e2da
fix get_validation_error function
matiasbenedetto Aug 8, 2023
99680a9
improving comment
matiasbenedetto Aug 8, 2023
4c3e2fd
improve comment
matiasbenedetto Aug 8, 2023
f974f6e
adding test method description
matiasbenedetto Aug 8, 2023
443659b
code format
matiasbenedetto Aug 8, 2023
b19d8ed
lint fixes
matiasbenedetto Aug 8, 2023
14d4d13
Merge branch 'trunk' into try/fonts-library-backend
matiasbenedetto Aug 8, 2023
e67472f
fix test
matiasbenedetto Aug 8, 2023
1d36d12
removing unwated parameter comment
matiasbenedetto Aug 8, 2023
e381f30
format
matiasbenedetto Aug 8, 2023
26cdcb2
lint
matiasbenedetto Aug 8, 2023
4ec9659
Exclude fontsapi tests.
hellofromtonya Aug 9, 2023
274a8be
Exclude Fonts API in multisite tests
hellofromtonya Aug 9, 2023
e80c497
Core parity: since, formatting, package.
hellofromtonya Aug 10, 2023
b2a2ba6
init global function: renames & adds Core merge notes.
hellofromtonya Aug 10, 2023
5453579
Moves post_type registration to init function.
hellofromtonya Aug 10, 2023
82968c9
Remove function_exist wrap from Gutenberg init function.
hellofromtonya Aug 10, 2023
6072214
adding constant check to load Fonts Library files
matiasbenedetto Aug 10, 2023
7586418
Add constant to turn on Fonts Library in tests.
hellofromtonya Aug 10, 2023
e7660cc
Add constant to turn on Fonts Library in mu tests.
hellofromtonya Aug 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions lib/experimental/fonts-library/class-wp-font-family-utils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* Fonts Family Utils class.
*
* This file contains utils fot Font Family class.
*
* @package Gutenberg
* @subpackage Fonts Library
* @since X.X.X
*/

matiasbenedetto marked this conversation as resolved.
Show resolved Hide resolved
if ( class_exists( 'WP_Font_Family_Utils' ) ) {
return;
}

/**
* A class of utilities for working with the Font Library.
*/
class WP_Font_Family_Utils {
matiasbenedetto marked this conversation as resolved.
Show resolved Hide resolved

/**
* Generates a filename for a font face asset.
*
* Creates a filename for a font face asset using font family, style, weight and extension information.
*
* @param array $font_face The font face array containing 'fontFamily', 'fontStyle', and 'fontWeight' attributes.
* @param string $url The URL of the font face asset, used to derive the file extension.
* @param int $i Optional counter for appending to the filename, default is 1.
* @return string The generated filename for the font face asset.
*/
public static function get_filename_from_font_face( $font_face, $url, $i = 1 ) {
$extension = pathinfo( $url, PATHINFO_EXTENSION );
$filename = sanitize_title( "{$font_face['fontFamily']}_{$font_face['fontStyle']}_{$font_face['fontWeight']}" );
if ( $i > 1 ) {
$filename .= "_{$i}";
}
matiasbenedetto marked this conversation as resolved.
Show resolved Hide resolved
return "{$filename}.{$extension}";
}

/**
* Merges two fonts and their font faces.
*
* @param array $font1 The first font to merge.
* @param array $font2 The second font to merge.
*
matiasbenedetto marked this conversation as resolved.
Show resolved Hide resolved
* @return array|WP_Error The merged font or WP_Error if the fonts have different slugs.
*/
public static function merge_fonts_data( $font1, $font2 ) {
if ( $font1['slug'] !== $font2['slug'] ) {
return new WP_Error( 'fonts_must_have_same_slug', __( 'Fonts must have the same slug to be merged.', 'gutenberg' ) );
}
$font_faces_1 = isset( $font1['fontFace'] ) ? $font1['fontFace'] : array();
$font_faces_2 = isset( $font2['fontFace'] ) ? $font2['fontFace'] : array();
Comment on lines +65 to +66
Copy link
Contributor

Choose a reason for hiding this comment

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

@matiasbenedetto @hellofromtonya Is Gutenberg planning to bump its minimum version to PHP 7? If so, can we use the null coalescing operator here?

Copy link
Contributor

@hellofromtonya hellofromtonya Jul 24, 2023

Choose a reason for hiding this comment

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

The timing of when to bump the PHP minimum version is being discussed here #52344

Copy link
Contributor

Choose a reason for hiding this comment

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

If so, can we use the null coalescing operator here?

Hey @costdev Gutenberg did bump to 7.0. But need to wait on adopting 7.0 changes. Waiting on the PHP 7.0 Code Standards Make/Core proposal.

$merged_font_faces = array_merge( $font_faces_1, $font_faces_2 );

$serialized_faces = array_map( 'serialize', $merged_font_faces );
$unique_serialized_faces = array_unique( $serialized_faces );
$unique_faces = array_map( 'unserialize', $unique_serialized_faces );

$merged_font = array_merge( $font1, $font2 );
$merged_font['fontFace'] = $unique_faces;

return $merged_font;
}

/**
* Returns whether the given file has a font MIME type.
*
* @param string $filepath The file to check.
* @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 );
return in_array( $filetype['type'], WP_Fonts_Library::ALLOWED_FONT_MIME_TYPES, true );
}

}
Loading