From 410ad6c7b926fd3192fd3ddcb3bfafb46e13680a Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 25 Mar 2026 21:45:22 +0100 Subject: [PATCH] inital of rest api --- src/backend/backend.php | 15 +++++++++ src/backend/endpoints/crop.php | 60 ++++++++++++++++++++++++++++++++++ theatergf-gallery.php | 2 ++ 3 files changed, 77 insertions(+) create mode 100644 src/backend/backend.php create mode 100644 src/backend/endpoints/crop.php diff --git a/src/backend/backend.php b/src/backend/backend.php new file mode 100644 index 0000000..df67658 --- /dev/null +++ b/src/backend/backend.php @@ -0,0 +1,15 @@ +register_routes(); +}); + diff --git a/src/backend/endpoints/crop.php b/src/backend/endpoints/crop.php new file mode 100644 index 0000000..f253d0c --- /dev/null +++ b/src/backend/endpoints/crop.php @@ -0,0 +1,60 @@ +namespace = $namespace; + $this->rest_base = $base_path; + } + + public function register_routes() { + + register_rest_route($this->namespace, '/' . $this->rest_base . '/new', [ + 'methods' => \WP_REST_Server::CREATABLE, + 'callback' => [ $this, 'create_item' ], + 'permission_callback' => [ $this, 'create_item_permissions_check' ], + 'args' => [ + 'img_id' => [ + 'required' => true, + 'validate_callback' => function ( $param, $request, $key) { return wp_attachment_is_image($param); } + ], + 'x' => [ + 'required' => true, + 'validate_callback' => function ( $param, $request, $key) { return is_numeric($param) && $param > 0; } + ], + 'y' => [ + 'required' => true, + 'validate_callback' => function ( $param, $request, $key) { return is_numeric($param) && $param > 0; } + ], + 'width' => [ + 'required' => true, + 'validate_callback' => function ( $param, $request, $key) { return is_numeric($param) && $param > 0; } + ], + 'height' => [ + 'required' => true, + 'validate_callback' => function ( $param, $request, $key) { return is_numeric($param) && $param > 0; } + ] + ] + ]); + } + + public function create_item_permissions_check( $request ) { + + if ( ! is_user_logged_in()) { + return new \WP_Error( 'unauthenticated', 'Log in to interact with this endpoint.', array( 'status' => 401 )); + } + + if ( ! (is_user_logged_in() && current_user_can( 'edit_pages' )) ) { + return new \WP_Error( 'forbidden', 'No Permission for this endpoint.', array( 'status' => 403 )); + } + + return true; + } + + public function create_item( $request ) { + return true; + } + +} diff --git a/theatergf-gallery.php b/theatergf-gallery.php index e3bae25..c9936bb 100644 --- a/theatergf-gallery.php +++ b/theatergf-gallery.php @@ -34,3 +34,5 @@ add_action( 'init', 'TheaterGF\Gallery\block_init' ); if ( is_admin() ) { require_once __DIR__ . '/src/admin/admin.php'; } + +require_once __DIR__ . '/src/backend/backend.php';