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

Font Library #5285

Closed
Closed

Conversation

matiasbenedetto
Copy link

@matiasbenedetto matiasbenedetto commented Sep 22, 2023

Trac ticket: https://core.trac.wordpress.org/ticket/59166


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

'callback' => array( $this, 'get_font_collections' ),
'permission_callback' => array( $this, 'update_font_library_permissions_check' ),
),
'schema' => array( $this, 'get_items_schema' ),
Copy link
Member

Choose a reason for hiding this comment

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

There idea of schema, is the desciptions an item in the response in the request. The shape of the repsonse should match between items and item endpoints. Items should just be a array of item. That way you can reuse the same prepare_items_for_response. See this example.

public function get_items( $request ) {
$data = array();
$block_types = $this->block_registry->get_all_registered();
// Retrieve the list of registered collection query parameters.
$registered = $this->get_collection_params();
$namespace = '';
if ( isset( $registered['namespace'] ) && ! empty( $request['namespace'] ) ) {
$namespace = $request['namespace'];
}
foreach ( $block_types as $slug => $obj ) {
if ( $namespace ) {
list ( $block_namespace ) = explode( '/', $obj->name );
if ( $namespace !== $block_namespace ) {
continue;
}
}
$block_type = $this->prepare_item_for_response( $obj, $request );
$data[] = $this->prepare_response_for_collection( $block_type );
}
return rest_ensure_response( $data );
}

Comment on lines +106 to +109
$collections[] = $this->prepare_item_for_response( $collection->get_config(), null );
}

return new WP_REST_Response( $collections, 200 );
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$collections[] = $this->prepare_item_for_response( $collection->get_config(), null );
}
return new WP_REST_Response( $collections, 200 );
$font_collection = $this->prepare_item_for_response( $collection->get_config(), null );
$collections[] = $this->prepare_response_for_collection( $font_collection );
}
return rest_ensure_response( $collections );

Copy link
Contributor

Choose a reason for hiding this comment

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

'context' => array( 'view', 'edit', 'embed' ),
),
'data' => array(
'description' => __( 'Data of the font collection.' ),
Copy link
Member

Choose a reason for hiding this comment

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

This seems like it is embedded font family object no? This should use links to link to font object.
https://developer.wordpress.org/rest-api/using-the-rest-api/linking-and-embedding/

@spacedmonkey
Copy link
Member

@matiasbenedetto My review was requested. Please ensure before requesting my reviewing the following things are complete, before I review.

  • All unit tests are pass.
  • PHPCS coding standards pass.
  • All feedback has been actioned.

*
* @since 6.4.0
*/
class WP_REST_Font_Families_Controller extends WP_REST_Controller {
Copy link
Member

Choose a reason for hiding this comment

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

@matiasbenedetto Sorry if I am missing this, but why is this a custom controller? Doesn't this map to the post contoller for font CPT?

function wp_register_font_collection( $config ) {
return WP_Font_Library::register_font_collection( $config );
}

Copy link
Member

Choose a reason for hiding this comment

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

how do a unregister a font collection.

Copy link
Author

Choose a reason for hiding this comment

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

That's not currently possible but that work is already started: WordPress/gutenberg#54701

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines +272 to +283
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.' ),
array(
'status' => rest_authorization_required_code(),
)
);
}
return true;
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we not use a meta capabilities for the font post type instead of just using edit_theme_options? Example
https://core.trac.wordpress.org/ticket/54516

Copy link
Contributor

Choose a reason for hiding this comment

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

This received detailed discussion over on WordPress/gutenberg#55280.

@hellofromtonya
Copy link
Contributor

hellofromtonya commented Oct 5, 2023

Sharing @spacedmonkey observations from Make/Core slack in the #core channel:

I am currently reviewing the font apis PR . I must say, I am very worried about the PR in it's current state. The code simply doesn't follow the WP core code style and doesn't feel WordPress. I have a number of problems with it, including.

  • Limited developer API. We need function like wp_insert_font / wp_create_font etc.
  • Lack of filter or actions.
  • No way to unregister font collections.
  • Capabilities. Creating new fonts should have capabilies and not simply map to edit_theme_options
  • Confusing API structure. Collection should have embedded font objects
  • What happens to fonts when collections are unregistered.
  • If fonts are stored as post object, can I query to get all fonts from a collection.
  • Are fonts deleted when the user is deleted.
  • No way to filter where a font is stored. ( #hosting channel for detail ).

With time very limited in this release, it feels like actioning the above, feel like it is going too hard to achieve in this release.

I think this feature needs some more time to bake.

Some links to help:

No way to filter where a font is stored.

See WordPress/gutenberg#54697 to add WP_FONTS_DIR constant to unblock web hosts.

No way to unregister font collections.

WordPress/gutenberg#54697

@matiasbenedetto
Copy link
Author

Closing this PR due to the inclusion of this feature was punted to 6.5:
https://wordpress.slack.com/archives/C02RQBWTW/p1696525101347939

@matiasbenedetto
Copy link
Author

Tracking the required changes to make Font Library ready for 6.5 in this Gutenberg issue: WordPress/gutenberg#54169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.