File "WPDA_API.php"
Full Path: /home/vantageo/public_html/cache/cache/cache/cache/.wp-cli/wp-content/plugins/wp-data-access/WPDataAccess/API/WPDA_API.php
File size: 1.53 KB
MIME-type: text/x-php
Charset: utf-8
<?php // phpcs:ignore Standard.Category.SniffName.ErrorCode
/**
* JSON REST API.
*/
namespace WPDataAccess\API {
use WPDataAccess\WPDA;
/**
* JSON REST API main class.
*/
class WPDA_API {
const WPDA_NAMESPACE = 'wpda';
const WPDA_REST_API_TABLE_ACCESS = 'wpda_rest_api_table_access';
public function hide() {
add_filter(
'rest_authentication_errors',
function ( $access ) {
$rest_route = isset( $GLOBALS['wp']->query_vars['rest_route'] )
? untrailingslashit( $GLOBALS['wp']->query_vars['rest_route'] )
: '';
if ( '/' . self::WPDA_NAMESPACE === $rest_route && ! current_user_can( 'manage_options' ) ) {
return new \WP_Error(
'rest_cannot_access',
__( 'Only authenticated admin users can access the REST API.', 'wp-data-access' ),
array(
'status' => rest_authorization_required_code(),
)
);
}
return $access;
}
);
}
/**
* Register routes.
*
* @return void
*/
public function init() {
// Plugin
$plugin = new WPDA_Plugin();
$plugin->register_rest_routes();
// Apps
$apps = new WPDA_Apps();
$apps->register_rest_routes();
// Data Explorer
$tree = new WPDA_Tree();
$tree->register_rest_routes();
// Data Tables and Data Forms
$tables = new WPDA_Table();
$tables->register_rest_routes();
// Admin actions
$actions = new WPDA_Actions();
$actions->register_rest_routes();
// Settings
$settings = new WPDA_Settings();
$settings->register_rest_routes();
}
}
}