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

Implement Site Classification API (Backend Controller) #220

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions includes/RestApi/RestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ final class RestApi {
'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeInstallerController',
'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeFontsController',
'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeColorsController',
'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\SiteClassificationController',
);

/**
Expand Down
56 changes: 56 additions & 0 deletions includes/RestApi/SiteClassificationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace NewfoldLabs\WP\Module\Onboarding\RestApi;

use NewfoldLabs\WP\Module\Onboarding\Permissions;
use NewfoldLabs\WP\Module\Data\SiteClassification;

/**
* Class SiteClassificationController
*/
class SiteClassificationController {

/**
* The namespace of this controller's route.
*
* @var string
*/
protected $namespace = 'newfold-onboarding/v1';

/**
* The endpoint base
*
* @var string
*/
protected $rest_base = '/site-classification';

/**
* Registers rest routes for SiteClassificationController class.
*
* @return void
*/
public function register_routes() {
\register_rest_route(
$this->namespace,
$this->rest_base,
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( $this, 'get' ),
'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ),
)
);
}

/**
* Get site classification data.
*
* @return array
*/
public function get() {
if ( ! class_exists( 'NewfoldLabs\WP\Module\Data\SiteClassification' ) ) {
return array();
}
$classification = new SiteClassification();
return $classification->get();
}
}