first commit
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\Woocommerce\Data;
|
||||
|
||||
use ElementorPro\Data\Base\Controller as Controller_Pro_Base;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
class Controller extends Controller_Pro_Base {
|
||||
|
||||
public function get_name() {
|
||||
return 'woocommerce-module';
|
||||
}
|
||||
|
||||
public function register_endpoints() {
|
||||
$this->register_endpoint( Endpoints\Set_Notice_Dismissed::class );
|
||||
$this->register_endpoint( Endpoints\Get_Notice_Dismissed::class );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\Woocommerce\Data\Endpoints;
|
||||
|
||||
use Elementor\Data\Base\Endpoint;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Base_Endpoint extends Endpoint {
|
||||
|
||||
const IS_CART_NOTICE_DISMISSED = 'is_custom_wc_cart_notice_dismissed';
|
||||
|
||||
public function get_name() : string {}
|
||||
|
||||
public function get_route() : string {
|
||||
return $this->get_name();
|
||||
}
|
||||
|
||||
protected function permission_callback(): bool {
|
||||
return current_user_can( 'edit_posts' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\Woocommerce\Data\Endpoints;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Get_Notice_Dismissed extends Base_Endpoint {
|
||||
|
||||
public function get_name() : string {
|
||||
return 'get-notice-dismissed';
|
||||
}
|
||||
|
||||
public function handle_post_meta_request( \WP_REST_Request $request ): array {
|
||||
$data = $request->get_params();
|
||||
$post_id = $data['post_id'];
|
||||
$is_dismissed_database_key = self::IS_CART_NOTICE_DISMISSED;
|
||||
|
||||
return [
|
||||
self::IS_CART_NOTICE_DISMISSED => get_post_meta( $post_id, $is_dismissed_database_key, true ),
|
||||
];
|
||||
}
|
||||
|
||||
protected function register() {
|
||||
register_rest_route( $this->controller->get_namespace(), $this->get_route() . '/(?P<post_id>\d+)', [
|
||||
[
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => [ $this, 'handle_post_meta_request' ],
|
||||
'permission_callback' => function () {
|
||||
return $this->permission_callback();
|
||||
},
|
||||
],
|
||||
] );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace ElementorPro\Modules\Woocommerce\Data\Endpoints;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Set_Notice_Dismissed extends Base_Endpoint {
|
||||
|
||||
public function get_name() : string {
|
||||
return 'set-notice-dismissed';
|
||||
}
|
||||
|
||||
public function handle_post_meta_request( \WP_REST_Request $request ): array {
|
||||
$data = $request->get_params();
|
||||
$post_id = $data['post_id'];
|
||||
$is_cart_dismissed = $data[ self::IS_CART_NOTICE_DISMISSED ];
|
||||
$is_cart_dismissed_database_value = true === $is_cart_dismissed ? 'true' : 'false';
|
||||
$is_dismissed_database_key = self::IS_CART_NOTICE_DISMISSED;
|
||||
|
||||
update_post_meta( $post_id, $is_dismissed_database_key, $is_cart_dismissed_database_value );
|
||||
|
||||
return [
|
||||
self::IS_CART_NOTICE_DISMISSED => $is_cart_dismissed,
|
||||
];
|
||||
}
|
||||
|
||||
protected function register() {
|
||||
register_rest_route( $this->controller->get_namespace(), $this->get_route(), [
|
||||
[
|
||||
'args' => [
|
||||
'post_id' => [
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
],
|
||||
self::IS_CART_NOTICE_DISMISSED => [
|
||||
'type' => 'boolean',
|
||||
'required' => true,
|
||||
],
|
||||
],
|
||||
'methods' => \WP_REST_Server::CREATABLE,
|
||||
'callback' => [ $this, 'handle_post_meta_request' ],
|
||||
'permission_callback' => function () {
|
||||
return $this->permission_callback();
|
||||
},
|
||||
],
|
||||
] );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user