PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.3.75
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.3.75
11.3.75 11.3.73 11.3.71 11.3.70 11.3.69 11.3.64 11.3.65 11.3.62 11.3.61 11.3.56 11.3.58 11.0.31 11.0.52 11.0.54 11.0.56 11.0.58 11.0.7 11.1.10 11.1.11 11.1.13 11.1.14 11.1.15 11.1.2 11.1.20 11.1.21 All 73 releases
leadin / public / modules / api / class-base-api-controller.php

class-base-api-controller.php in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.3.75, at public/modules/api/class-base-api-controller.php

72 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Leadin\api;
4
5 use Leadin\data\Filters;
6
7 /**
8 * Base class to set a rest endpoint
9 */
10 class Base_Api_Controller {
11
12 /**
13 * Register a route with given parameters
14 *
15 * @param string $path The path for the route to register the service on. Route gets namespaced with leadin/v1.
16 * @param string $methods Comma seperated list of methods allowed for this route.
17 * @param array $callback Method to execute when this endpoint is requested.
18 */
19 public function register_leadin_route( $path, $methods, $callback ) {
20 register_rest_route(
21 'leadin/v1',
22 $path,
23 array(
24 'methods' => $methods,
25 'callback' => $callback,
26 'permission_callback' => array( $this, 'verify_permissions' ),
27 )
28 );
29 }
30
31 /**
32 * Register an admin route with given parameters
33 *
34 * @param string $path The path for the route to register the service on. Route gets namespaced with leadin/v1.
35 * @param string $methods Comma seperated list of methods allowed for this route.
36 * @param array $callback Method to execute when this endpoint is requested.
37 */
38 public function register_leadin_admin_route( $path, $methods, $callback ) {
39 register_rest_route(
40 'leadin/v1',
41 $path,
42 array(
43 'methods' => $methods,
44 'callback' => $callback,
45 'permission_callback' => array( $this, 'verify_admin_permissions' ),
46 )
47 );
48 }
49
50
51 /**
52 * Permissions required by user to execute the request. User permissions are already
53 * verified by nonce 'wp_rest' automatically.
54 *
55 * @return bool true if the user has adequate permissions for this endpoint.
56 */
57 public function verify_permissions() {
58 return current_user_can( Filters::apply_view_plugin_menu_capability_filters() );
59 }
60
61 /**
62 * Permissions required by user to execute the request. User permissions are already
63 * verified by nonce 'wp_rest' automatically.
64 *
65 * @return bool true if the user has adequate admin permissions for this endpoint.
66 */
67 public function verify_admin_permissions() {
68 return current_user_can( Filters::apply_connect_plugin_capability_filters() );
69 }
70
71 }
72