Make WordPress Core

Changeset 57548

Timestamp:
02/07/2024 09:18:38 AM (6 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 n;
    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
     396
     397
    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';
     313
     314
     315
    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->assert( $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
     193
     194
     195
     196
     197
    192198        );
    193199
  • trunk/tests/qunit/fixtures/wp-api-generated.js

    r57494 r57548  
    66556655                            ],
    66566656                            "default": "view",
     6657
     6658
     6659
     6660
     6661
     6662
     6663
     6664
     6665
     6666
     6667
     6668
     6669
     6670
     6671
     6672
     6673
     6674
     6675
     6676
     6677
     6678
     6679
     6680
     6681
     6682
     6683
     6684
     6685
     6686
     6687
     6688
     6689
     6690
     6691
     6692
     6693
     6694
     6695
     6696
     6697
     6698
     6699
     6700
     6701
     6702
     6703
     6704
     6705
     6706
     6707
     6708
     6709
     6710
     6711
     6712
     6713
     6714
     6715
     6716
     6717
     6718
     6719
     6720
     6721
     6722
     6723
     6724
     6725
     6726
     6727
     6728
     6729
     6730
     6731
     6732
     6733
     6734
     6735
     6736
     6737
     6738
     6739
     6740
     6741
     6742
     6743
     6744
     6745
     6746
     6747
     6748
     6749
     6750
     6751
     6752
     6753
     6754
     6755
     6756
     6757
     6758
     6759
     6760
     6761
     6762
     6763
     6764
     6765
     6766
     6767
     6768
     6769
     6770
     6771
     6772
     6773
     6774
     6775
     6776
     6777
     6778
     6779
     6780
     6781
     6782
     6783
     6784
     6785
     6786
     6787
     6788
     6789
     6790
     6791
     6792
     6793
     6794
     6795
     6796
     6797
     6798
     6799
     6800
     6801
     6802
     6803
     6804
     6805
     6806
     6807
     6808
     6809
     6810
     6811
     6812
     6813
     6814
     6815
     6816
     6817
     6818
     6819
     6820
     6821
     6822
     6823
     6824
     6825
     6826
     6827
     6828
     6829
     6830
     6831
     6832
     6833
     6834
     6835
     6836
     6837
     6838
     6839
     6840
     6841
     6842
     6843
     6844
     6845
     6846
     6847
     6848
     6849
     6850
     6851
     6852
     6853
     6854
     6855
     6856
     6857
     6858
     6859
     6860
     6861
     6862
     6863
     6864
     6865
     6866
     6867
     6868
     6869
     6870
     6871
     6872
     6873
     6874
     6875
     6876
     6877
     6878
     6879
     6880
     6881
     6882
     6883
     6884
     6885
     6886
     6887
     6888
     6889
     6890
     6891
     6892
     6893
     6894
     6895
     6896
     6897
     6898
     6899
     6900
     6901
     6902
     6903
     6904
     6905
     6906
     6907
     6908
     6909
     6910
     6911
     6912
     6913
     6914
     6915
     6916
     6917
     6918
     6919
     6920
     6921
     6922
     6923
     6924
     6925
     6926
     6927
     6928
     6929
     6930
     6931
     6932
     6933
     6934
     6935
     6936
     6937
     6938
     6939
     6940
     6941
     6942
     6943
     6944
     6945
     6946
     6947
     6948
     6949
     6950
     6951
     6952
     6953
     6954
     6955
     6956
     6957
     6958
     6959
     6960
     6961
     6962
     6963
     6964
     6965
     6966
     6967
     6968
     6969
     6970
     6971
     6972
     6973
     6974
     6975
     6976
     6977
     6978
     6979
     6980
     6981
     6982
     6983
     6984
     6985
     6986
     6987
     6988
     6989
     6990
     6991
     6992
     6993
     6994
     6995
     6996
     6997
     6998
     6999
     7000
     7001
     7002
     7003
     7004
     7005
     7006
     7007
     7008
     7009
     7010
     7011
     7012
     7013
     7014
     7015
     7016
     7017
     7018
     7019
     7020
     7021
     7022
     7023
     7024
     7025
     7026
     7027
     7028
     7029
     7030
     7031
    66577032                            "required": false
    66587033                        }
     
    87869161                                    "wp_template_part": "wp_template_part",
    87879162                                    "wp_navigation": "wp_navigation",
     9163
     9164
    87889165                                    "attachment": "attachment"
    87899166                                }
     
    1150511882                ]
    1150611883            }
     11884
     11885
     11886
     11887
     11888
     11889
     11890
     11891
     11892
     11893
     11894
     11895
     11896
     11897
     11898
     11899
     11900
     11901
     11902
     11903
     11904
     11905
     11906
     11907
     11908
     11909
     11910
     11911
     11912
     11913
     11914
     11915
     11916
     11917
     11918
     11919
     11920
     11921
     11922
     11923
     11924
     11925
     11926
     11927
     11928
     11929
     11930
     11931
     11932
     11933
     11934
     11935
     11936
     11937
     11938
     11939
     11940
     11941
     11942
     11943
     11944
     11945
     11946
     11947
     11948
     11949
     11950
     11951
     11952
     11953
     11954
     11955
     11956
     11957
    1150711958        }
    1150811959    },
     
    1254212993        }
    1254312994    },
     12995
     12996
     12997
     12998
     12999
     13000
     13001
     13002
     13003
     13004
     13005
     13006
     13007
     13008
     13009
     13010
     13011
     13012
     13013
     13014
     13015
     13016
     13017
     13018
     13019
     13020
     13021
     13022
     13023
     13024
     13025
     13026
     13027
     13028
     13029
     13030
     13031
     13032
     13033
     13034
     13035
     13036
     13037
     13038
     13039
     13040
     13041
     13042
     13043
     13044
     13045
     13046
     13047
     13048
     13049
     13050
     13051
     13052
     13053
     13054
    1254413055    "attachment": {
    1254513056        "description": "",
Note: See TracChangeset for help on using the changeset viewer.