Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ThemeFontsController | |
0.00% |
0 / 19 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| register_routes | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| get_theme_fonts | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace NewfoldLabs\WP\Module\Onboarding\RestApi\Themes; |
| 4 | |
| 5 | use NewfoldLabs\WP\Module\Onboarding\Data\Themes\Fonts; |
| 6 | use NewfoldLabs\WP\Module\Onboarding\Permissions; |
| 7 | |
| 8 | /** |
| 9 | * Class ThemeFontsController |
| 10 | */ |
| 11 | class ThemeFontsController extends \WP_REST_Controller { |
| 12 | |
| 13 | |
| 14 | /** |
| 15 | * The namespace of this controller's route. |
| 16 | * |
| 17 | * @var string |
| 18 | */ |
| 19 | protected $namespace = 'newfold-onboarding/v1'; |
| 20 | |
| 21 | /** |
| 22 | * The base of this controller's route. |
| 23 | * |
| 24 | * @var string |
| 25 | */ |
| 26 | protected $rest_base = '/themes'; |
| 27 | |
| 28 | |
| 29 | /** |
| 30 | * The extended base of this controller's route. |
| 31 | * |
| 32 | * @var string |
| 33 | */ |
| 34 | protected $rest_extended_base = '/fonts'; |
| 35 | |
| 36 | /** |
| 37 | * Registers routes for ThemeColorsController |
| 38 | */ |
| 39 | public function register_routes() { |
| 40 | \register_rest_route( |
| 41 | $this->namespace, |
| 42 | $this->rest_base . $this->rest_extended_base, |
| 43 | array( |
| 44 | array( |
| 45 | 'methods' => \WP_REST_Server::READABLE, |
| 46 | 'callback' => array( $this, 'get_theme_fonts' ), |
| 47 | 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), |
| 48 | ), |
| 49 | ) |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Retrieves the active theme font variations. |
| 55 | * |
| 56 | * @return array|\WP_Error |
| 57 | */ |
| 58 | public function get_theme_fonts() { |
| 59 | $theme_font_palettes = Fonts::get_fonts_from_theme(); |
| 60 | |
| 61 | if ( ! $theme_font_palettes ) { |
| 62 | return new \WP_Error( |
| 63 | 'Theme Fonts not found', |
| 64 | 'No WordPress Fonts are available for this theme.', |
| 65 | array( 'status' => 404 ) |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | return $theme_font_palettes; |
| 70 | } |
| 71 | } |