-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Font Library #5285
Conversation
src/wp-includes/fonts/font-library/class-wp-rest-font-library-controller.php
Outdated
Show resolved
Hide resolved
This reverts commit d4bce59.
'callback' => array( $this, 'get_font_collections' ), | ||
'permission_callback' => array( $this, 'update_font_library_permissions_check' ), | ||
), | ||
'schema' => array( $this, 'get_items_schema' ), |
There was a problem hiding this comment.
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.
wordpress-develop/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php
Lines 133 to 157 in 23c811e
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 ); | |
} |
$collections[] = $this->prepare_item_for_response( $collection->get_config(), null ); | ||
} | ||
|
||
return new WP_REST_Response( $collections, 200 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$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 ); |
There was a problem hiding this comment.
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.' ), |
There was a problem hiding this comment.
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/
@matiasbenedetto My review was requested. Please ensure before requesting my reviewing the following things are complete, before I review.
|
* | ||
* @since 6.4.0 | ||
*/ | ||
class WP_REST_Font_Families_Controller extends WP_REST_Controller { |
There was a problem hiding this comment.
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 ); | ||
} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Sharing @spacedmonkey observations from Make/Core slack in the
Some links to help:
See WordPress/gutenberg#54697 to add
|
…est_prepare_item.
Closing this PR due to the inclusion of this feature was punted to 6.5: |
Tracking the required changes to make Font Library ready for 6.5 in this Gutenberg issue: WordPress/gutenberg#54169 |
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.