PluginProbe
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More / 2.2.0
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More v2.2.0
2.3.0 2.2.0 2.1.1 2.1.0 2.0.0 1.10.0 1.9.1 1.9.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 All 59 releases
storeengine / addons / webhooks / database.php

database.php in StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More 2.2.0, at addons/webhooks/database.php

104 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace StoreEngine\Addons\Webhooks;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 class Database {
10
11 public static function init() {
12 $self = new self();
13 add_action( 'init', [ $self, 'create_storeengine_webhook_post_type' ] );
14 add_action( 'rest_api_init', [ $self, 'register_storeengine_webhook_meta' ] );
15 }
16
17 public function create_storeengine_webhook_post_type() {
18 register_post_type(
19 'storeengine_webhook',
20 [
21 'labels' => [
22 'name' => esc_html__( 'Webhooks', 'storeengine' ),
23 'singular_name' => esc_html__( 'Webhook', 'storeengine' ),
24 'search_items' => esc_html__( 'Search webhooks', 'storeengine' ),
25 'parent_item_colon' => esc_html__( 'Parent webhooks:', 'storeengine' ),
26 'not_found' => esc_html__( 'No webhooks found.', 'storeengine' ),
27 'not_found_in_trash' => esc_html__( 'No webhooks found in Trash.', 'storeengine' ),
28 'archives' => esc_html__( 'webhook archives', 'storeengine' ),
29 ],
30 'public' => false,
31 'publicly_queryable' => false,
32 'show_ui' => false,
33 'show_in_menu' => false,
34 'hierarchical' => false,
35 'rewrite' => false,
36 'query_var' => false,
37 'has_archive' => false,
38 'delete_with_user' => false,
39 'supports' => [ 'title', 'author', 'custom-fields' ],
40 'show_in_rest' => true,
41 'rest_base' => 'webhook',
42 'rest_namespace' => STOREENGINE_PLUGIN_SLUG . '/v1',
43 'rest_controller_class' => 'WP_REST_Posts_Controller',
44 'capability_type' => 'post',
45 'capabilities' => [
46 'edit_post' => 'manage_options',
47 'read_post' => 'manage_options',
48 'delete_post' => 'manage_options',
49 'delete_posts' => 'manage_options',
50 'edit_posts' => 'manage_options',
51 'edit_others_posts' => 'manage_options',
52 'publish_posts' => 'manage_options',
53 'read_private_posts' => 'manage_options',
54 'create_posts' => 'manage_options',
55 ],
56 ]
57 );
58 }
59
60 public function register_storeengine_webhook_meta() {
61 register_meta(
62 'post',
63 '_storeengine_webhook_delivery_url',
64 [
65 'object_subtype' => 'storeengine_webhook',
66 'type' => 'string',
67 'single' => true,
68 'show_in_rest' => true,
69 'sanitize_callback' => 'sanitize_url',
70 ]
71 );
72
73 register_meta(
74 'post',
75 '_storeengine_webhook_secret',
76 [
77 'object_subtype' => 'storeengine_webhook',
78 'type' => 'string',
79 'single' => true,
80 'show_in_rest' => true,
81 'sanitize_callback' => 'sanitize_text_field',
82 ]
83 );
84
85 register_meta(
86 'post',
87 '_storeengine_webhook_events',
88 [
89 'object_subtype' => 'storeengine_webhook',
90 'type' => 'array',
91 'single' => true,
92 'show_in_rest' => [
93 'schema' => [
94 'items' => [
95 'type' => 'string',
96 'enum' => Webhooks::get_events(),
97 ],
98 ],
99 ],
100 ]
101 );
102 }
103 }
104