107 lines
2.1 KiB
PHP
107 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* CartFlows Common Settings Data Query.
|
|
*
|
|
* @package CartFlows
|
|
*/
|
|
|
|
namespace CartflowsAdmin\AdminCore\Api;
|
|
|
|
// Exit if accessed directly.
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
use CartflowsAdmin\AdminCore\Api\ApiBase;
|
|
use CartflowsAdmin\AdminCore\Inc\AdminHelper;
|
|
|
|
/**
|
|
* Class Admin_Query.
|
|
*/
|
|
class HomePage extends ApiBase {
|
|
|
|
/**
|
|
* Route base.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $rest_base = '/admin/homepage/';
|
|
|
|
/**
|
|
* Instance
|
|
*
|
|
* @access private
|
|
* @var object Class object.
|
|
* @since 1.0.0
|
|
*/
|
|
private static $instance;
|
|
|
|
/**
|
|
* Initiator
|
|
*
|
|
* @since 1.0.0
|
|
* @return object initialized object of class.
|
|
*/
|
|
public static function get_instance() {
|
|
if ( ! isset( self::$instance ) ) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Init Hooks.
|
|
*
|
|
* @since 1.0.0
|
|
* @return void
|
|
*/
|
|
public function register_routes() {
|
|
|
|
$namespace = $this->get_api_namespace();
|
|
|
|
register_rest_route(
|
|
$namespace,
|
|
$this->rest_base,
|
|
array(
|
|
array(
|
|
'methods' => \WP_REST_Server::READABLE,
|
|
'callback' => array( $this, 'get_home_page_settings' ),
|
|
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
|
'args' => array(),
|
|
),
|
|
'schema' => array( $this, 'get_public_item_schema' ),
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get common settings.
|
|
*
|
|
* @param WP_REST_Request $request Full details about the request.
|
|
*/
|
|
public function get_home_page_settings( $request ) {
|
|
|
|
$boxes_settings = AdminHelper::get_admin_settings_option( $request['wcf_box_id'] );
|
|
|
|
$home_page_settings = array(
|
|
'is_hidden' => $boxes_settings,
|
|
);
|
|
|
|
return $home_page_settings;
|
|
}
|
|
|
|
/**
|
|
* Check whether a given request has permission to read notes.
|
|
*
|
|
* @param WP_REST_Request $request Full details about the request.
|
|
* @return WP_Error|boolean
|
|
*/
|
|
public function get_items_permissions_check( $request ) {
|
|
|
|
if ( ! current_user_can( 'cartflows_manage_flows_steps' ) ) {
|
|
return new \WP_Error( 'cartflows_rest_cannot_view', __( 'Sorry, you cannot list resources.', 'cartflows' ), array( 'status' => rest_authorization_required_code() ) );
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|