PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.59
Timetics – Appointment Booking Calendar & Scheduling v1.0.59
1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 All 62 releases
timetics / base / api.php

api.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.59, at base/api.php

70 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Abstract api class
4 *
5 * @package Timetics
6 */
7 namespace Timetics\Base;
8
9 defined( 'ABSPATH' ) || exit;
10
11 use WP_Error;
12
13 /**
14 * Abstract class Api.
15 *
16 * @since 1.0.0
17 */
18 abstract class Api extends \WP_REST_Controller {
19
20 /**
21 * Api Constructor function.
22 *
23 * @since 1.0.0
24 *
25 * @return void
26 */
27 public function __construct() {
28 add_action( 'rest_api_init', [ $this, 'register_routes' ] );
29 }
30
31 /**
32 * Register routes
33 *
34 * @since 1.0.0
35 *
36 * @return void
37 */
38 public function register_routes() {
39 // Need to override the function on child class.
40 }
41
42 /**
43 * Validate input fields.
44 *
45 * @since 1.0.0
46 *
47 * @param array $data Accepts data in array format.
48 * @param array $fields Optional. Default empty array.
49 *
50 * @return bool | WP_error
51 */
52 public function validate( $data, $fields = [] ) {
53 $error = new WP_Error();
54
55 foreach ( $fields as $field ) {
56 if ( empty( $data[ $field ] ) ) {
57 /* translators: Error Message */
58 $error->add( $field . '_error', sprintf( esc_html__( '%s can\'t be empty', 'timetics' ), $field ) );
59 }
60 }
61
62 if ( ! empty( $error->errors ) ) {
63 return $error;
64 }
65
66 return true;
67 }
68
69 }
70