Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
9a00814
add main backend files
matiasbenedetto Sep 22, 2023
6f9aefc
add comment about CDN link
matiasbenedetto Sep 22, 2023
d78d99b
load main files
matiasbenedetto Sep 22, 2023
1d74144
add routes from font library to routes test
matiasbenedetto Sep 22, 2023
42eeb48
adding PHP unit tests for font library
matiasbenedetto Sep 22, 2023
9e06a93
fix register post type for font family post type
matiasbenedetto Sep 22, 2023
b323b67
move the font library functions
matiasbenedetto Sep 22, 2023
715eea9
avoid loading file deleted
matiasbenedetto Sep 22, 2023
e54426a
add wp_register_default_font_collection function
matiasbenedetto Sep 22, 2023
1078767
load font-library functions file
matiasbenedetto Sep 22, 2023
699f45b
register default font collection with init hook
matiasbenedetto Sep 22, 2023
a6dca33
fix rest-schema test
matiasbenedetto Sep 22, 2023
9ba9187
Merge branch 'trunk' into port/font-library
matiasbenedetto Sep 23, 2023
5084180
settings the right 'supports' values for wp_font_family post type
matiasbenedetto Sep 23, 2023
46a1e9f
set hierarchical as false for wp_font_family post type
matiasbenedetto Sep 23, 2023
7e666e6
fix url in test
matiasbenedetto Sep 23, 2023
e6cce43
fix set_upload_dir unit test
matiasbenedetto Sep 23, 2023
673c042
fix unit test by using solvable host name
matiasbenedetto Sep 23, 2023
72bbec5
avoid using gutenberg class, use core class instead
matiasbenedetto Sep 23, 2023
1d8de84
add the font assets for the tests
matiasbenedetto Sep 23, 2023
d769cc5
Remove font files created after tests run
matiasbenedetto Sep 25, 2023
c4a31d2
removing unwanted echo line
matiasbenedetto Sep 25, 2023
57f05a1
Merge branch 'trunk' into port/font-library
matiasbenedetto Sep 25, 2023
8933cb8
add the custom post type routes to the routes test
matiasbenedetto Sep 25, 2023
9aeb0ba
Removing class re-declaration check
matiasbenedetto Sep 25, 2023
1725825
format php
matiasbenedetto Sep 25, 2023
d4bce59
updating wp-api-generated.js schema
matiasbenedetto Sep 25, 2023
89e888f
Merge branch 'trunk' into port/font-library
matiasbenedetto Sep 25, 2023
ab70608
Revert "updating wp-api-generated.js schema"
matiasbenedetto Sep 25, 2023
739edeb
moving font library rest controller to the endpoints folder
matiasbenedetto Sep 25, 2023
534264e
Removing 'gutenberg' translation domain
matiasbenedetto Sep 25, 2023
c2d38d6
add comment about mime types logic
matiasbenedetto Sep 25, 2023
2a715cd
using wordpress.org cdn to host google fonts collection data json file
matiasbenedetto Sep 25, 2023
6bf7be3
updating wp-api-generated.js fixtures
matiasbenedetto Sep 25, 2023
bbb09e9
avoid deprecation error in test
matiasbenedetto Sep 25, 2023
654dd1d
Moving default font collection registration to font.php file
matiasbenedetto Sep 25, 2023
635d870
moving font library files to the main fonts folder
matiasbenedetto Sep 25, 2023
8714206
remove path from deleted file
matiasbenedetto Sep 25, 2023
2e08b53
Merge branch 'trunk' into port/font-library
matiasbenedetto Sep 25, 2023
8c5ddec
replace strpos by str_contains
matiasbenedetto Sep 26, 2023
ae15e18
Merge branch 'trunk' into port/font-library
matiasbenedetto Sep 27, 2023
04fe719
Testeable mime type conditionals
matiasbenedetto Sep 27, 2023
839ff70
Change expected OTF files mime type
matiasbenedetto Sep 28, 2023
5116443
standardize the output of install and uninstall endpoints
matiasbenedetto Sep 29, 2023
d89e201
update install and uninstall enpoints tests for the new standard outp…
matiasbenedetto Sep 29, 2023
e4b2a85
remove class_exist check coming from gutenberg
matiasbenedetto Oct 2, 2023
8e3e711
remove unused line
matiasbenedetto Oct 2, 2023
947e2cb
add trailing dot
matiasbenedetto Oct 2, 2023
88ec9b7
se snake_case instead of camelCase on fontFamilies endpoint param
matiasbenedetto Oct 2, 2023
3e63080
Merge branch 'trunk' into port/font-library
matiasbenedetto Oct 2, 2023
e218ec8
using DIR_TESTDATA for file assets paths
matiasbenedetto Oct 2, 2023
02d6767
Remove extra new line
matiasbenedetto Oct 2, 2023
641e9f3
emoving an unnecessary line break
matiasbenedetto Oct 2, 2023
5178b1e
use self::factory() to insert post in test
matiasbenedetto Oct 2, 2023
4612703
avoid adding variable name in return comment
matiasbenedetto Oct 2, 2023
f69e6e5
update return type of function
matiasbenedetto Oct 2, 2023
17c9fd3
update comments
matiasbenedetto Oct 2, 2023
3021090
move property definition on top of the class
matiasbenedetto Oct 2, 2023
db11c1f
replace EDITABLE by CREATABLE
matiasbenedetto Oct 2, 2023
31af894
move uninstall endpoint schema
matiasbenedetto Oct 2, 2023
21e3d33
updating wp-api-generated.js file
matiasbenedetto Oct 2, 2023
9aa43bf
Rename function
matiasbenedetto Oct 2, 2023
f38bb59
make string translatable
matiasbenedetto Oct 2, 2023
b005321
Add id argument to the font collection.
anton-vlasenko Oct 2, 2023
2b29de4
remove triling comma
matiasbenedetto Oct 2, 2023
aaf3741
change WP_REST_Response by rest_ensure_response
matiasbenedetto Oct 2, 2023
d6534cc
Remove path_join() for constant in tests
hellofromtonya Oct 2, 2023
3b01b46
Change subpackage to Fonts
hellofromtonya Oct 2, 2023
f16ead0
Initialize properties to empty array
hellofromtonya Oct 2, 2023
30369c6
Empty line before end of function return.
hellofromtonya Oct 2, 2023
e1f0b58
1. Implement schema.
anton-vlasenko Oct 2, 2023
aec6c93
Removes passing PHP version to WP_Font_Library::get_font_mime_types().
hellofromtonya Oct 2, 2023
b34fe52
Implement the schema for the font collections endpoint.
anton-vlasenko Oct 2, 2023
e948c1b
Multiline comments props costdev
hellofromtonya Oct 2, 2023
0926426
Update wp-api-generated.js.
anton-vlasenko Oct 2, 2023
11b26db
PHPCS: Remove extra empty line at end of file
hellofromtonya Oct 2, 2023
feb1199
Remove isset() where empty() is also used. Prop costdev
hellofromtonya Oct 2, 2023
a776cee
Use $request['id'] - props spacedmonkey
hellofromtonya Oct 3, 2023
909da30
make install and uninstall endpoints singular.
matiasbenedetto Oct 3, 2023
fd706d1
rename font library enpoints and split font library controller in 2 d…
matiasbenedetto Oct 3, 2023
7081941
remove unwanted enpoint from WP_REST_Font_Families_Controller class
matiasbenedetto Oct 4, 2023
b49da9a
dont show custom post type in rest endpoints
matiasbenedetto Oct 4, 2023
2d369aa
use lowercase in error message
matiasbenedetto Oct 4, 2023
86dab9e
update wording
matiasbenedetto Oct 4, 2023
b167d7f
Implementing get_item and get_items for /font-families/ endpoints
matiasbenedetto Oct 4, 2023
1c23f09
Refactored font-family GET and DELETE api endpoints to use SLUG inste…
pbking Oct 4, 2023
4f7fd91
Added or refactored tests for Font Family createItem, deleteItem, get…
pbking Oct 4, 2023
14ca3bd
Refactored Font Family tests to use getPostBySlug
pbking Oct 4, 2023
8d9f496
use snake_case schema in font collections endpoints
matiasbenedetto Oct 4, 2023
1243b31
update api endpoint routes test and fixture
matiasbenedetto Oct 4, 2023
c5c6ec4
fix the font collections schema to accomodate arrays instead of a sin…
matiasbenedetto Oct 4, 2023
f398761
1. Remove the registerRoutes test.
anton-vlasenko Oct 4, 2023
d85e545
Fix CS.
anton-vlasenko Oct 4, 2023
07d01ff
Fix CS.
anton-vlasenko Oct 4, 2023
ec52113
grouping font-families endpoints and add response schemas.
matiasbenedetto Oct 5, 2023
3967726
add default order for font families
matiasbenedetto Oct 5, 2023
a19ac36
add since 6.4 comment
matiasbenedetto Oct 5, 2023
05d3ff7
Remove extra new line
matiasbenedetto Oct 5, 2023
963d226
remove extra spaces
matiasbenedetto Oct 5, 2023
e28134f
add missing 'since 6.4' comment
matiasbenedetto Oct 5, 2023
b2a96fc
Get rid of WP_REST_Font_Library_Controller_UnitTestCase.
anton-vlasenko Oct 5, 2023
640159e
Fix parent class name.
anton-vlasenko Oct 5, 2023
d44da25
fix typo in comment
matiasbenedetto Oct 5, 2023
603ee9e
Rename controller methods.
anton-vlasenko Oct 5, 2023
7382406
Fix 404 errors.
anton-vlasenko Oct 5, 2023
d9ffea9
Move the tests to Tests_Fonts_WpRestFontCollectionsController.
anton-vlasenko Oct 5, 2023
9edfb39
Fix the tests.
anton-vlasenko Oct 5, 2023
c4de43f
Improve PHPDOC blocks.
anton-vlasenko Oct 5, 2023
9deeb4a
Fix @return type.
anton-vlasenko Oct 5, 2023
6c9e856
Implement the test for Tests_Fonts_WpRestFontCollectionsController::t…
anton-vlasenko Oct 9, 2023
89cd000
Fix the test.
anton-vlasenko Oct 9, 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
Prev Previous commit
Next Next commit
Removing 'gutenberg' translation domain
  • Loading branch information
matiasbenedetto committed Sep 25, 2023
commit 534264e4182246cb2054f292200ed228bc8e1900
2 changes: 1 addition & 1 deletion src/wp-includes/font-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function wp_register_default_font_collection() {
array(
'id' => 'default-font-collection',
'name' => 'Google Fonts',
'description' => __( 'Add from Google Fonts. Fonts are copied to and served from your site.', 'gutenberg' ),
'description' => __( 'Add from Google Fonts. Fonts are copied to and served from your site.' ),
/* TODO: This URL needs to change from the raw file to wporg CDN URL. */
'src' => 'https://raw.githubusercontent.com/WordPress/google-fonts-to-wordpress-collection/main/output/google-fonts-with-previews.json',
)
Expand Down
10 changes: 5 additions & 5 deletions src/wp-includes/fonts/font-library/class-wp-font-collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,26 @@ public function get_data() {
// If the src is a URL, fetch the data from the URL.
if ( false !== strpos( $this->config['src'], 'http' ) && false !== strpos( $this->config['src'], '://' ) ) {
if ( ! wp_http_validate_url( $this->config['src'] ) ) {
return new WP_Error( 'font_collection_read_error', __( 'Invalid URL for Font Collection data.', 'gutenberg' ) );
return new WP_Error( 'font_collection_read_error', __( 'Invalid URL for Font Collection data.' ) );
}

$response = wp_remote_get( $this->config['src'] );
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
return new WP_Error( 'font_collection_read_error', __( 'Error fetching the Font Collection data from a URL.', 'gutenberg' ) );
return new WP_Error( 'font_collection_read_error', __( 'Error fetching the Font Collection data from a URL.' ) );
}

$data = json_decode( wp_remote_retrieve_body( $response ), true );
if ( empty( $data ) ) {
return new WP_Error( 'font_collection_read_error', __( 'Error decoding the Font Collection data from the REST response JSON.', 'gutenberg' ) );
return new WP_Error( 'font_collection_read_error', __( 'Error decoding the Font Collection data from the REST response JSON.' ) );
}
// If the src is a file path, read the data from the file.
} else {
if ( ! file_exists( $this->config['src'] ) ) {
return new WP_Error( 'font_collection_read_error', __( 'Font Collection data JSON file does not exist.', 'gutenberg' ) );
return new WP_Error( 'font_collection_read_error', __( 'Font Collection data JSON file does not exist.' ) );
}
$data = wp_json_file_decode( $this->config['src'], array( 'associative' => true ) );
if ( empty( $data ) ) {
return new WP_Error( 'font_collection_read_error', __( 'Error reading the Font Collection data JSON file contents.', 'gutenberg' ) );
return new WP_Error( 'font_collection_read_error', __( 'Error reading the Font Collection data JSON file contents.' ) );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ 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' )
__( 'Fonts must have the same slug to be merged.' )
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/wp-includes/fonts/font-library/class-wp-font-family.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function uninstall() {
if ( null === $post ) {
return new WP_Error(
'font_family_not_found',
__( 'The font family could not be found.', 'gutenberg' )
__( 'The font family could not be found.' )
);
}

Expand All @@ -114,7 +114,7 @@ public function uninstall() {
) {
return new WP_Error(
'font_family_not_deleted',
__( 'The font family could not be deleted.', 'gutenberg' )
__( 'The font family could not be deleted.' )
);
}

Expand Down Expand Up @@ -486,7 +486,7 @@ private function create_font_post() {
if ( 0 === $post_id || is_wp_error( $post_id ) ) {
return new WP_Error(
'font_post_creation_failed',
__( 'Font post creation failed', 'gutenberg' )
__( 'Font post creation failed' )
);
}

Expand Down Expand Up @@ -555,7 +555,7 @@ private function update_font_post( $post ) {
if ( 0 === $post_id || is_wp_error( $post_id ) ) {
return new WP_Error(
'font_post_update_failed',
__( 'Font post update failed', 'gutenberg' )
__( 'Font post update failed' )
);
}

Expand Down Expand Up @@ -600,7 +600,7 @@ public function install( $files = null ) {
if ( ! $were_assets_written ) {
return new WP_Error(
'font_face_download_failed',
__( 'The font face assets could not be written.', 'gutenberg' )
__( 'The font face assets could not be written.' )
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ private function get_validation_errors( $font_families, $files ) {
$error_messages = array();

if ( ! is_array( $font_families ) ) {
$error_messages[] = __( 'fontFamilies should be an array of font families.', 'gutenberg' );
$error_messages[] = __( 'fontFamilies should be an array of font families.' );
Copy link
Member

@swissspidy swissspidy Oct 2, 2023

Choose a reason for hiding this comment

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

This should use sprintf and use a placeholder for fontFamilies. And of course proper translator comments.

return $error_messages;
}

// Checks if there is at least one font family.
if ( count( $font_families ) < 1 ) {
$error_messages[] = __( 'fontFamilies should have at least one font family definition.', 'gutenberg' );
$error_messages[] = __( 'fontFamilies should have at least one font family definition.' );
return $error_messages;
}

Expand All @@ -163,7 +163,7 @@ private function get_validation_errors( $font_families, $files ) {
) {
$error_messages[] = sprintf(
// translators: 1: font family index.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// translators: 1: font family index.
/* translators: %s: font family index. */

Translator comments are in the form of:

/* translators: <token || number>: Description<comma || period> */

🔢 Applies elsewhere in the PR.

See the information for Plugins, the best reference I could find 😅. This is the same practice used in WordPress Core.

__( 'Font family [%s] should have slug, name and fontFamily properties defined.', 'gutenberg' ),
__( 'Font family [%s] should have slug, name and fontFamily properties defined.' ),
Copy link
Member

Choose a reason for hiding this comment

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

  • This should use sprintf with placeholders for things like fontFamily
  • Why square brackets instead of parentheses? That's not common AFAIK

Copy link
Member

Choose a reason for hiding this comment

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

The same goes for all the other error messages, really.

Choose a reason for hiding this comment

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

Why square brackets instead of parentheses? That's not common AFAIK

One place I do see brackets used is when validating an object in the request from the endpoint schema (see

$is_valid = rest_validate_value_from_schema( $v, $args['properties'][ $property ], $param . '[' . $property . ']' );
).

The error messages use a string like object_name[property_name] to refer to the property being validated. We're using this format specifically for custom validation error messages in the new controller implementation, to match the error format from the default schema validation (now with appropriate sprintf usage, see WordPress/gutenberg#58675).

$family_index
);
}
Expand All @@ -172,7 +172,7 @@ private function get_validation_errors( $font_families, $files ) {
if ( ! is_array( $font_family['fontFace'] ) ) {
$error_messages[] = sprintf(
// translators: 1: font family index.
__( 'Font family [%s] should have fontFace property defined as an array.', 'gutenberg' ),
__( 'Font family [%s] should have fontFace property defined as an array.' ),
$family_index
);
continue;
Expand All @@ -181,7 +181,7 @@ private function get_validation_errors( $font_families, $files ) {
if ( count( $font_family['fontFace'] ) < 1 ) {
$error_messages[] = sprintf(
// translators: 1: font family index.
__( 'Font family [%s] should have at least one font face definition.', 'gutenberg' ),
__( 'Font family [%s] should have at least one font face definition.' ),
$family_index
);
}
Expand All @@ -193,7 +193,7 @@ private function get_validation_errors( $font_families, $files ) {
if ( ! isset( $font_face['fontWeight'] ) || ! isset( $font_face['fontStyle'] ) ) {
$error_messages[] = sprintf(
// translators: 1: font family index, 2: font face index.
__( 'Font family [%1$s] Font face [%2$s] should have fontWeight and fontStyle properties defined.', 'gutenberg' ),
__( 'Font family [%1$s] Font face [%2$s] should have fontWeight and fontStyle properties defined.' ),
$family_index,
$face_index
);
Expand All @@ -202,7 +202,7 @@ private function get_validation_errors( $font_families, $files ) {
if ( isset( $font_face['downloadFromUrl'] ) && isset( $font_face['uploadedFile'] ) ) {
$error_messages[] = sprintf(
// translators: 1: font family index, 2: font face index.
__( 'Font family [%1$s] Font face [%2$s] should have only one of the downloadFromUrl or uploadedFile properties defined and not both.', 'gutenberg' ),
__( 'Font family [%1$s] Font face [%2$s] should have only one of the downloadFromUrl or uploadedFile properties defined and not both.' ),
$family_index,
$face_index
);
Expand All @@ -212,7 +212,7 @@ private function get_validation_errors( $font_families, $files ) {
if ( ! isset( $files[ $font_face['uploadedFile'] ] ) ) {
$error_messages[] = sprintf(
// translators: 1: font family index, 2: font face index.
__( 'Font family [%1$s] Font face [%2$s] file is not defined in the request files.', 'gutenberg' ),
__( 'Font family [%1$s] Font face [%2$s] file is not defined in the request files.' ),
$family_index,
$face_index
);
Expand Down Expand Up @@ -258,7 +258,7 @@ public function uninstall_schema() {
return array(
'fontFamilies' => array(
Copy link
Member

Choose a reason for hiding this comment

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

As noted elsewhere, params should use snack case.

Copy link
Member

Choose a reason for hiding this comment

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

Other schema are cached for performance reasons. Why was this avoided here.

'type' => 'array',
'description' => __( 'The font families to install.', 'gutenberg' ),
'description' => __( 'The font families to install.' ),
'required' => true,
'minItems' => 1,
'items' => array(
Expand All @@ -267,7 +267,7 @@ public function uninstall_schema() {
'properties' => array(
'slug' => array(
'type' => 'string',
'description' => __( 'The font family slug.', 'gutenberg' ),
'description' => __( 'The font family slug.' ),
'required' => true,
),
),
Expand Down Expand Up @@ -297,7 +297,7 @@ public function uninstall_fonts( $request ) {
}
}

return new WP_REST_Response( __( 'Font family uninstalled successfully.', 'gutenberg' ), 200 );
return new WP_REST_Response( __( 'Font family uninstalled successfully.' ), 200 );
Copy link
Member

Choose a reason for hiding this comment

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

This should return an array of remove fonts and boolean.

Copy link
Author

Choose a reason for hiding this comment

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

Updated with the changes of this PR WordPress/gutenberg#54829. The output of the install and uninstall endpoints are now standardized for success and errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done in 5116443

}

/**
Expand All @@ -311,7 +311,7 @@ public function update_font_library_permissions_check() {
if ( ! current_user_can( 'edit_theme_options' ) ) {
return new WP_Error(
'rest_cannot_update_font_library',
__( 'Sorry, you are not allowed to update the Font Library on this site.', 'gutenberg' ),
__( 'Sorry, you are not allowed to update the Font Library on this site.' ),
array(
'status' => rest_authorization_required_code(),
)
Expand All @@ -324,7 +324,7 @@ public function update_font_library_permissions_check() {
if ( ! is_writable( $temp_dir ) || ! wp_is_writable( $upload_dir ) ) {
return new WP_Error(
'rest_cannot_write_fonts_folder',
__( 'Error: WordPress does not have permission to write the fonts folder on your server.', 'gutenberg' ),
__( 'Error: WordPress does not have permission to write the fonts folder on your server.' ),
array(
'status' => 500,
)
Expand Down Expand Up @@ -360,7 +360,7 @@ public function install_fonts( $request ) {
if ( empty( $fonts_to_install ) ) {
return new WP_Error(
'no_fonts_to_install',
__( 'No fonts to install', 'gutenberg' ),
__( 'No fonts to install' ),
array( 'status' => 400 )
);
}
Expand All @@ -379,7 +379,7 @@ public function install_fonts( $request ) {
if ( empty( $fonts_installed ) ) {
return new WP_Error(
'error_installing_fonts',
__( 'Error installing fonts. No font was installed.', 'gutenberg' ),
__( 'Error installing fonts. No font was installed.' ),
array( 'status' => 500 )
);
}
Expand Down