Make WordPress Core

Changeset 57548


Ignore:
Timestamp:
02/07/2024 09:18:38 AM (12 months ago)
Author:
youknowriad
Message:

REST API: Introduce the necessary endpoints for the font library.

This commits add three endpoints to retrieve and manipulate fonts in WordPress.
This commit also means that we now have a fully functional Font Library in the site editor.

Props get_dave, youknowriad, mmaattiiaass, grantmkin, swissspidy, mcsf, jorbin, ocean90.
See #59166.

Location:
trunk
Files:
6 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/fonts/class-wp-font-library.php

    r57539 r57548  
    116116     *
    117117     * @param string $slug Font collection slug.
    118      * @return WP_Font_Collection|WP_Error Font collection object,
    119      *                                     or WP_Error object if the font collection doesn't exist.
     118     * @return WP_Font_Collection|null Font collection object, or null if the font collection doesn't exist.
    120119     */
    121120    public function get_font_collection( $slug ) {
     
    123122            return $this->collections[ $slug ];
    124123        }
    125         return new WP_Error( 'font_collection_not_found', __( 'Font collection not found.' ) );
     124        return null;
    126125    }
    127126
  • trunk/src/wp-includes/post.php

    r57541 r57548  
    568568        'wp_font_family',
    569569        array(
    570             'labels'       => array(
     570            'labels'                         => array(
    571571                'name'          => __( 'Font Families' ),
    572572                'singular_name' => __( 'Font Family' ),
    573573            ),
    574             'public'       => false,
    575             '_builtin'     => true, /* internal use only. don't use this when registering your own post type. */
    576             'hierarchical' => false,
    577             'capabilities' => array(
     574            'public'                         => false,
     575            '_builtin'                       => true, /* internal use only. don't use this when registering your own post type. */
     576            'hierarchical'                   => false,
     577            'capabilities'                   => array(
    578578                'read'                   => 'edit_theme_options',
    579579                'read_private_posts'     => 'edit_theme_options',
     
    587587                'delete_published_posts' => 'edit_theme_options',
    588588            ),
    589             'map_meta_cap' => true,
    590             'query_var'    => false,
    591             'show_in_rest' => false,
    592             'rewrite'      => false,
     589            'map_meta_cap'                   => true,
     590            'query_var'                      => false,
     591            'rewrite'                        => false,
     592            'show_in_rest'                   => true,
     593            'rest_base'                      => 'font-families',
     594            'rest_controller_class'          => 'WP_REST_Font_Families_Controller',
     595            // Disable autosave endpoints for font families.
     596            'autosave_rest_controller_class' => 'stdClass',
    593597        )
    594598    );
     
    597601        'wp_font_face',
    598602        array(
    599             'labels'       => array(
     603            'labels'                         => array(
    600604                'name'          => __( 'Font Faces' ),
    601605                'singular_name' => __( 'Font Face' ),
    602606            ),
    603             'public'       => false,
    604             '_builtin'     => true, /* internal use only. don't use this when registering your own post type. */
    605             'hierarchical' => false,
    606             'capabilities' => array(
     607            'public'                         => false,
     608            '_builtin'                       => true, /* internal use only. don't use this when registering your own post type. */
     609            'hierarchical'                   => false,
     610            'capabilities'                   => array(
    607611                'read'                   => 'edit_theme_options',
    608612                'read_private_posts'     => 'edit_theme_options',
     
    616620                'delete_published_posts' => 'edit_theme_options',
    617621            ),
    618             'map_meta_cap' => true,
    619             'query_var'    => false,
    620             'show_in_rest' => false,
    621             'rewrite'      => false,
     622            'map_meta_cap'                   => true,
     623            'query_var'                      => false,
     624            'rewrite'                        => false,
     625            'show_in_rest'                   => true,
     626            'rest_base'                      => 'font-families/(?P<font_family_id>[\d]+)/font-faces',
     627            'rest_controller_class'          => 'WP_REST_Font_Faces_Controller',
     628            // Disable autosave endpoints for font faces.
     629            'autosave_rest_controller_class' => 'stdClass',
    622630        )
    623631    );
  • trunk/src/wp-includes/rest-api.php

    r57312 r57548  
    392392    $controller = new WP_REST_Navigation_Fallback_Controller();
    393393    $controller->register_routes();
     394
     395    // Font Collections.
     396    $font_collections_controller = new WP_REST_Font_Collections_Controller();
     397    $font_collections_controller->register_routes();
    394398}
    395399
  • trunk/src/wp-settings.php

    r57545 r57548  
    311311require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-url-details-controller.php';
    312312require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-navigation-fallback-controller.php';
     313require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-font-families-controller.php';
     314require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-font-faces-controller.php';
     315require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-font-collections-controller.php';
    313316require ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-meta-fields.php';
    314317require ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-comment-meta-fields.php';
  • trunk/tests/phpunit/tests/fonts/font-library/wpFontLibrary/getFontCollection.php

    r57539 r57548  
    2626    public function test_should_get_no_font_collection_if_the_slug_is_not_registered() {
    2727        $font_collection = WP_Font_Library::get_instance()->get_font_collection( 'not-registered-font-collection' );
    28         $this->assertWPError( $font_collection );
     28        $this->assertNull( $font_collection );
    2929    }
    3030}
  • trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php

    r57494 r57548  
    190190            '/wp/v2/wp_pattern_category',
    191191            '/wp/v2/wp_pattern_category/(?P<id>[\d]+)',
     192            '/wp/v2/font-collections',
     193            '/wp/v2/font-collections/(?P<slug>[\/\w-]+)',
     194            '/wp/v2/font-families',
     195            '/wp/v2/font-families/(?P<font_family_id>[\d]+)/font-faces',
     196            '/wp/v2/font-families/(?P<font_family_id>[\d]+)/font-faces/(?P<id>[\d]+)',
     197            '/wp/v2/font-families/(?P<id>[\d]+)',
    192198        );
    193199
  • trunk/tests/qunit/fixtures/wp-api-generated.js

    r57494 r57548  
    66556655                            ],
    66566656                            "default": "view",
     6657                            "required": false
     6658                        }
     6659                    }
     6660                }
     6661            ]
     6662        },
     6663        "/wp/v2/font-families": {
     6664            "namespace": "wp/v2",
     6665            "methods": [
     6666                "GET",
     6667                "POST"
     6668            ],
     6669            "endpoints": [
     6670                {
     6671                    "methods": [
     6672                        "GET"
     6673                    ],
     6674                    "args": {
     6675                        "context": {
     6676                            "description": "Scope under which the request is made; determines fields present in response.",
     6677                            "type": "string",
     6678                            "enum": [
     6679                                "view",
     6680                                "embed",
     6681                                "edit"
     6682                            ],
     6683                            "default": "view",
     6684                            "required": false
     6685                        },
     6686                        "page": {
     6687                            "description": "Current page of the collection.",
     6688                            "type": "integer",
     6689                            "default": 1,
     6690                            "minimum": 1,
     6691                            "required": false
     6692                        },
     6693                        "per_page": {
     6694                            "description": "Maximum number of items to be returned in result set.",
     6695                            "type": "integer",
     6696                            "default": 10,
     6697                            "minimum": 1,
     6698                            "maximum": 100,
     6699                            "required": false
     6700                        },
     6701                        "exclude": {
     6702                            "description": "Ensure result set excludes specific IDs.",
     6703                            "type": "array",
     6704                            "items": {
     6705                                "type": "integer"
     6706                            },
     6707                            "default": [],
     6708                            "required": false
     6709                        },
     6710                        "include": {
     6711                            "description": "Limit result set to specific IDs.",
     6712                            "type": "array",
     6713                            "items": {
     6714                                "type": "integer"
     6715                            },
     6716                            "default": [],
     6717                            "required": false
     6718                        },
     6719                        "offset": {
     6720                            "description": "Offset the result set by a specific number of items.",
     6721                            "type": "integer",
     6722                            "required": false
     6723                        },
     6724                        "order": {
     6725                            "description": "Order sort attribute ascending or descending.",
     6726                            "type": "string",
     6727                            "default": "desc",
     6728                            "enum": [
     6729                                "asc",
     6730                                "desc"
     6731                            ],
     6732                            "required": false
     6733                        },
     6734                        "orderby": {
     6735                            "description": "Sort collection by post attribute.",
     6736                            "type": "string",
     6737                            "default": "id",
     6738                            "enum": [
     6739                                "id",
     6740                                "include"
     6741                            ],
     6742                            "required": false
     6743                        },
     6744                        "slug": {
     6745                            "description": "Limit result set to posts with one or more specific slugs.",
     6746                            "type": "array",
     6747                            "items": {
     6748                                "type": "string"
     6749                            },
     6750                            "required": false
     6751                        }
     6752                    }
     6753                },
     6754                {
     6755                    "methods": [
     6756                        "POST"
     6757                    ],
     6758                    "args": {
     6759                        "theme_json_version": {
     6760                            "description": "Version of the theme.json schema used for the typography settings.",
     6761                            "type": "integer",
     6762                            "default": 2,
     6763                            "minimum": 2,
     6764                            "maximum": 2,
     6765                            "required": false
     6766                        },
     6767                        "font_family_settings": {
     6768                            "description": "font-family declaration in theme.json format, encoded as a string.",
     6769                            "type": "string",
     6770                            "required": true
     6771                        }
     6772                    }
     6773                }
     6774            ],
     6775            "_links": {
     6776                "self": [
     6777                    {
     6778                        "href": "http://example.org/index.php?rest_route=/wp/v2/font-families"
     6779                    }
     6780                ]
     6781            }
     6782        },
     6783        "/wp/v2/font-families/(?P<id>[\\d]+)": {
     6784            "namespace": "wp/v2",
     6785            "methods": [
     6786                "GET",
     6787                "POST",
     6788                "PUT",
     6789                "PATCH",
     6790                "DELETE"
     6791            ],
     6792            "endpoints": [
     6793                {
     6794                    "methods": [
     6795                        "GET"
     6796                    ],
     6797                    "args": {
     6798                        "id": {
     6799                            "description": "Unique identifier for the post.",
     6800                            "type": "integer",
     6801                            "required": false
     6802                        },
     6803                        "context": {
     6804                            "description": "Scope under which the request is made; determines fields present in response.",
     6805                            "type": "string",
     6806                            "enum": [
     6807                                "view",
     6808                                "embed",
     6809                                "edit"
     6810                            ],
     6811                            "default": "view",
     6812                            "required": false
     6813                        }
     6814                    }
     6815                },
     6816                {
     6817                    "methods": [
     6818                        "POST",
     6819                        "PUT",
     6820                        "PATCH"
     6821                    ],
     6822                    "args": {
     6823                        "id": {
     6824                            "description": "Unique identifier for the post.",
     6825                            "type": "integer",
     6826                            "required": false
     6827                        },
     6828                        "theme_json_version": {
     6829                            "description": "Version of the theme.json schema used for the typography settings.",
     6830                            "type": "integer",
     6831                            "default": 2,
     6832                            "minimum": 2,
     6833                            "maximum": 2,
     6834                            "required": false
     6835                        },
     6836                        "font_family_settings": {
     6837                            "description": "font-family declaration in theme.json format, encoded as a string.",
     6838                            "type": "string",
     6839                            "required": true
     6840                        }
     6841                    }
     6842                },
     6843                {
     6844                    "methods": [
     6845                        "DELETE"
     6846                    ],
     6847                    "args": {
     6848                        "id": {
     6849                            "description": "Unique identifier for the post.",
     6850                            "type": "integer",
     6851                            "required": false
     6852                        },
     6853                        "force": {
     6854                            "type": "boolean",
     6855                            "default": false,
     6856                            "description": "Whether to bypass Trash and force deletion.",
     6857                            "required": false
     6858                        }
     6859                    }
     6860                }
     6861            ]
     6862        },
     6863        "/wp/v2/font-families/(?P<font_family_id>[\\d]+)/font-faces": {
     6864            "namespace": "wp/v2",
     6865            "methods": [
     6866                "GET",
     6867                "POST"
     6868            ],
     6869            "endpoints": [
     6870                {
     6871                    "methods": [
     6872                        "GET"
     6873                    ],
     6874                    "args": {
     6875                        "font_family_id": {
     6876                            "description": "The ID for the parent font family of the font face.",
     6877                            "type": "integer",
     6878                            "required": true
     6879                        },
     6880                        "context": {
     6881                            "description": "Scope under which the request is made; determines fields present in response.",
     6882                            "type": "string",
     6883                            "enum": [
     6884                                "view",
     6885                                "embed",
     6886                                "edit"
     6887                            ],
     6888                            "default": "view",
     6889                            "required": false
     6890                        },
     6891                        "page": {
     6892                            "description": "Current page of the collection.",
     6893                            "type": "integer",
     6894                            "default": 1,
     6895                            "minimum": 1,
     6896                            "required": false
     6897                        },
     6898                        "per_page": {
     6899                            "description": "Maximum number of items to be returned in result set.",
     6900                            "type": "integer",
     6901                            "default": 10,
     6902                            "minimum": 1,
     6903                            "maximum": 100,
     6904                            "required": false
     6905                        },
     6906                        "exclude": {
     6907                            "description": "Ensure result set excludes specific IDs.",
     6908                            "type": "array",
     6909                            "items": {
     6910                                "type": "integer"
     6911                            },
     6912                            "default": [],
     6913                            "required": false
     6914                        },
     6915                        "include": {
     6916                            "description": "Limit result set to specific IDs.",
     6917                            "type": "array",
     6918                            "items": {
     6919                                "type": "integer"
     6920                            },
     6921                            "default": [],
     6922                            "required": false
     6923                        },
     6924                        "offset": {
     6925                            "description": "Offset the result set by a specific number of items.",
     6926                            "type": "integer",
     6927                            "required": false
     6928                        },
     6929                        "order": {
     6930                            "description": "Order sort attribute ascending or descending.",
     6931                            "type": "string",
     6932                            "default": "desc",
     6933                            "enum": [
     6934                                "asc",
     6935                                "desc"
     6936                            ],
     6937                            "required": false
     6938                        },
     6939                        "orderby": {
     6940                            "description": "Sort collection by post attribute.",
     6941                            "type": "string",
     6942                            "default": "id",
     6943                            "enum": [
     6944                                "id",
     6945                                "include"
     6946                            ],
     6947                            "required": false
     6948                        }
     6949                    }
     6950                },
     6951                {
     6952                    "methods": [
     6953                        "POST"
     6954                    ],
     6955                    "args": {
     6956                        "font_family_id": {
     6957                            "description": "The ID for the parent font family of the font face.",
     6958                            "type": "integer",
     6959                            "required": true
     6960                        },
     6961                        "theme_json_version": {
     6962                            "description": "Version of the theme.json schema used for the typography settings.",
     6963                            "type": "integer",
     6964                            "default": 2,
     6965                            "minimum": 2,
     6966                            "maximum": 2,
     6967                            "required": false
     6968                        },
     6969                        "font_face_settings": {
     6970                            "description": "font-face declaration in theme.json format, encoded as a string.",
     6971                            "type": "string",
     6972                            "required": true
     6973                        }
     6974                    }
     6975                }
     6976            ]
     6977        },
     6978        "/wp/v2/font-families/(?P<font_family_id>[\\d]+)/font-faces/(?P<id>[\\d]+)": {
     6979            "namespace": "wp/v2",
     6980            "methods": [
     6981                "GET",
     6982                "DELETE"
     6983            ],
     6984            "endpoints": [
     6985                {
     6986                    "methods": [
     6987                        "GET"
     6988                    ],
     6989                    "args": {
     6990                        "font_family_id": {
     6991                            "description": "The ID for the parent font family of the font face.",
     6992                            "type": "integer",
     6993                            "required": true
     6994                        },
     6995                        "id": {
     6996                            "description": "Unique identifier for the font face.",
     6997                            "type": "integer",
     6998                            "required": true
     6999                        },
     7000                        "context": {
     7001                            "description": "Scope under which the request is made; determines fields present in response.",
     7002                            "type": "string",
     7003                            "enum": [
     7004                                "view",
     7005                                "embed",
     7006                                "edit"
     7007                            ],
     7008                            "default": "view",
     7009                            "required": false
     7010                        }
     7011                    }
     7012                },
     7013                {
     7014                    "methods": [
     7015                        "DELETE"
     7016                    ],
     7017                    "args": {
     7018                        "font_family_id": {
     7019                            "description": "The ID for the parent font family of the font face.",
     7020                            "type": "integer",
     7021                            "required": true
     7022                        },
     7023                        "id": {
     7024                            "description": "Unique identifier for the font face.",
     7025                            "type": "integer",
     7026                            "required": true
     7027                        },
     7028                        "force": {
     7029                            "type": "boolean",
     7030                            "default": false,
     7031                            "description": "Whether to bypass Trash and force deletion.",
    66577032                            "required": false
    66587033                        }
     
    87869161                                    "wp_template_part": "wp_template_part",
    87879162                                    "wp_navigation": "wp_navigation",
     9163                                    "wp_font_family": "wp_font_family",
     9164                                    "wp_font_face": "wp_font_face",
    87889165                                    "attachment": "attachment"
    87899166                                }
     
    1150511882                ]
    1150611883            }
     11884        },
     11885        "/wp/v2/font-collections": {
     11886            "namespace": "wp/v2",
     11887            "methods": [
     11888                "GET"
     11889            ],
     11890            "endpoints": [
     11891                {
     11892                    "methods": [
     11893                        "GET"
     11894                    ],
     11895                    "args": {
     11896                        "context": {
     11897                            "description": "Scope under which the request is made; determines fields present in response.",
     11898                            "type": "string",
     11899                            "enum": [
     11900                                "view",
     11901                                "embed",
     11902                                "edit"
     11903                            ],
     11904                            "default": "view",
     11905                            "required": false
     11906                        },
     11907                        "page": {
     11908                            "description": "Current page of the collection.",
     11909                            "type": "integer",
     11910                            "default": 1,
     11911                            "minimum": 1,
     11912                            "required": false
     11913                        },
     11914                        "per_page": {
     11915                            "description": "Maximum number of items to be returned in result set.",
     11916                            "type": "integer",
     11917                            "default": 10,
     11918                            "minimum": 1,
     11919                            "maximum": 100,
     11920                            "required": false
     11921                        }
     11922                    }
     11923                }
     11924            ],
     11925            "_links": {
     11926                "self": [
     11927                    {
     11928                        "href": "http://example.org/index.php?rest_route=/wp/v2/font-collections"
     11929                    }
     11930                ]
     11931            }
     11932        },
     11933        "/wp/v2/font-collections/(?P<slug>[\\/\\w-]+)": {
     11934            "namespace": "wp/v2",
     11935            "methods": [
     11936                "GET"
     11937            ],
     11938            "endpoints": [
     11939                {
     11940                    "methods": [
     11941                        "GET"
     11942                    ],
     11943                    "args": {
     11944                        "context": {
     11945                            "description": "Scope under which the request is made; determines fields present in response.",
     11946                            "type": "string",
     11947                            "enum": [
     11948                                "view",
     11949                                "embed",
     11950                                "edit"
     11951                            ],
     11952                            "default": "view",
     11953                            "required": false
     11954                        }
     11955                    }
     11956                }
     11957            ]
    1150711958        }
    1150811959    },
     
    1254212993        }
    1254312994    },
     12995    "wp_font_family": {
     12996        "description": "",
     12997        "hierarchical": false,
     12998        "has_archive": false,
     12999        "name": "Font Families",
     13000        "slug": "wp_font_family",
     13001        "icon": null,
     13002        "taxonomies": [],
     13003        "rest_base": "font-families",
     13004        "rest_namespace": "wp/v2",
     13005        "_links": {
     13006            "collection": [
     13007                {
     13008                    "href": "http://example.org/index.php?rest_route=/wp/v2/types"
     13009                }
     13010            ],
     13011            "wp:items": [
     13012                {
     13013                    "href": "http://example.org/index.php?rest_route=/wp/v2/font-families"
     13014                }
     13015            ],
     13016            "curies": [
     13017                {
     13018                    "name": "wp",
     13019                    "href": "https://api.w.org/{rel}",
     13020                    "templated": true
     13021                }
     13022            ]
     13023        }
     13024    },
     13025    "wp_font_face": {
     13026        "description": "",
     13027        "hierarchical": false,
     13028        "has_archive": false,
     13029        "name": "Font Faces",
     13030        "slug": "wp_font_face",
     13031        "icon": null,
     13032        "taxonomies": [],
     13033        "rest_base": "font-families/(?P<font_family_id>[\\d]+)/font-faces",
     13034        "rest_namespace": "wp/v2",
     13035        "_links": {
     13036            "collection": [
     13037                {
     13038                    "href": "http://example.org/index.php?rest_route=/wp/v2/types"
     13039                }
     13040            ],
     13041            "wp:items": [
     13042                {
     13043                    "href": "http://example.org/index.php?rest_route=/wp/v2/font-families/(?P<font_family_id>[\\d]+)/font-faces"
     13044                }
     13045            ],
     13046            "curies": [
     13047                {
     13048                    "name": "wp",
     13049                    "href": "https://api.w.org/{rel}",
     13050                    "templated": true
     13051                }
     13052            ]
     13053        }
     13054    },
    1254413055    "attachment": {
    1254513056        "description": "",
Note: See TracChangeset for help on using the changeset viewer.