| 1 |
<?php // phpcs:ignore Standard.Category.SniffName.ErrorCode |
| 2 |
|
| 3 |
/** |
| 4 |
* JSON REST API. |
| 5 |
*/ |
| 6 |
|
| 7 |
namespace WPDataAccess\API { |
| 8 |
|
| 9 |
use WPDataAccess\WPDA; |
| 10 |
|
| 11 |
/** |
| 12 |
* JSON REST API main class. |
| 13 |
*/ |
| 14 |
class WPDA_API { |
| 15 |
|
| 16 |
const WPDA_NAMESPACE = 'wpda'; |
| 17 |
const WPDA_REST_API_TABLE_ACCESS = 'wpda_rest_api_table_access'; |
| 18 |
|
| 19 |
public function hide() { |
| 20 |
|
| 21 |
add_filter( |
| 22 |
'rest_authentication_errors', |
| 23 |
function ( $access ) { |
| 24 |
$rest_route = isset( $GLOBALS['wp']->query_vars['rest_route'] ) |
| 25 |
? untrailingslashit( $GLOBALS['wp']->query_vars['rest_route'] ) |
| 26 |
: ''; |
| 27 |
|
| 28 |
if ( '/' . self::WPDA_NAMESPACE === $rest_route && ! current_user_can( 'manage_options' ) ) { |
| 29 |
return new \WP_Error( |
| 30 |
'rest_cannot_access', |
| 31 |
__( 'Only authenticated admin users can access the REST API.', 'wp-data-access' ), |
| 32 |
array( |
| 33 |
'status' => rest_authorization_required_code(), |
| 34 |
) |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
return $access; |
| 39 |
} |
| 40 |
); |
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Register routes. |
| 46 |
* |
| 47 |
* @return void |
| 48 |
*/ |
| 49 |
public function init() { |
| 50 |
|
| 51 |
// Plugin |
| 52 |
$plugin = new WPDA_Plugin(); |
| 53 |
$plugin->register_rest_routes(); |
| 54 |
|
| 55 |
// Apps |
| 56 |
$apps = new WPDA_Apps(); |
| 57 |
$apps->register_rest_routes(); |
| 58 |
|
| 59 |
// Data Explorer |
| 60 |
$tree = new WPDA_Tree(); |
| 61 |
$tree->register_rest_routes(); |
| 62 |
|
| 63 |
// Data Tables and Data Forms |
| 64 |
$tables = new WPDA_Table(); |
| 65 |
$tables->register_rest_routes(); |
| 66 |
|
| 67 |
// Admin actions |
| 68 |
$actions = new WPDA_Actions(); |
| 69 |
$actions->register_rest_routes(); |
| 70 |
|
| 71 |
// Settings |
| 72 |
$settings = new WPDA_Settings(); |
| 73 |
$settings->register_rest_routes(); |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
} |
| 78 |
|
| 79 |
} |
| 80 |
|