From 78b277abde0e53c9ab9107309ca8bea76685e9a0 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Fri, 28 Apr 2023 10:29:24 +0530 Subject: [PATCH 1/3] add site classification controller --- includes/RestApi/RestApi.php | 1 + .../RestApi/SiteClassificationController.php | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 includes/RestApi/SiteClassificationController.php diff --git a/includes/RestApi/RestApi.php b/includes/RestApi/RestApi.php index 2b1c620e7..c9f5eeae8 100644 --- a/includes/RestApi/RestApi.php +++ b/includes/RestApi/RestApi.php @@ -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' ); /** diff --git a/includes/RestApi/SiteClassificationController.php b/includes/RestApi/SiteClassificationController.php new file mode 100644 index 000000000..60f8724b9 --- /dev/null +++ b/includes/RestApi/SiteClassificationController.php @@ -0,0 +1,51 @@ +namespace, + $this->rest_base, + array( + 'methods' => \WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_site_classification' ), + 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), + ) + ); + } + + public function get_site_classification() { + if ( ! class_exists( 'NewfoldLabs\WP\Module\Data\SiteClassification' ) ) { + return array(); + } + $classification = new SiteClassification(); + return $classification->get(); + } +} From 7b46fe90c28296f3f51471dc81a6d95e24c9ac2d Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Fri, 28 Apr 2023 10:49:50 +0530 Subject: [PATCH 2/3] fix lint --- includes/RestApi/RestApi.php | 2 +- includes/RestApi/SiteClassificationController.php | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/includes/RestApi/RestApi.php b/includes/RestApi/RestApi.php index c9f5eeae8..8c2fba99b 100644 --- a/includes/RestApi/RestApi.php +++ b/includes/RestApi/RestApi.php @@ -28,7 +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' + 'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\SiteClassificationController', ); /** diff --git a/includes/RestApi/SiteClassificationController.php b/includes/RestApi/SiteClassificationController.php index 60f8724b9..77820fb49 100644 --- a/includes/RestApi/SiteClassificationController.php +++ b/includes/RestApi/SiteClassificationController.php @@ -41,11 +41,16 @@ public function register_routes() { ); } - public function get_site_classification() { - if ( ! class_exists( 'NewfoldLabs\WP\Module\Data\SiteClassification' ) ) { + /** + * Fetch the Site Classification data using the data module helper. + * + * @return array + */ + public function get_site_classification() { + if ( ! class_exists( 'NewfoldLabs\WP\Module\Data\SiteClassification' ) ) { return array(); } - $classification = new SiteClassification(); - return $classification->get(); - } + $classification = new SiteClassification(); + return $classification->get(); + } } From 7b1e224becc2aed39056c69c16d1630b0fa15deb Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Fri, 28 Apr 2023 20:55:11 +0530 Subject: [PATCH 3/3] rename the function to reduce redundant naming --- includes/RestApi/SiteClassificationController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/RestApi/SiteClassificationController.php b/includes/RestApi/SiteClassificationController.php index 77820fb49..863e764b3 100644 --- a/includes/RestApi/SiteClassificationController.php +++ b/includes/RestApi/SiteClassificationController.php @@ -35,18 +35,18 @@ public function register_routes() { $this->rest_base, array( 'methods' => \WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_site_classification' ), + 'callback' => array( $this, 'get' ), 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), ) ); } /** - * Fetch the Site Classification data using the data module helper. + * Get site classification data. * * @return array */ - public function get_site_classification() { + public function get() { if ( ! class_exists( 'NewfoldLabs\WP\Module\Data\SiteClassification' ) ) { return array(); }