base
api.php
1.3 KB
2 years ago
csv-reader.php
1.2 KB
2 years ago
custom-endpoint.php
954 B
2 years ago
exporter.php
4.4 KB
2 years ago
file-reader-interface.php
302 B
2 years ago
forward-calls.php
1.1 KB
2 years ago
importer.php
2.0 KB
2 years ago
json-reader.php
823 B
2 years ago
post-model.php
3.6 KB
2 years ago
post.php
3.0 KB
2 years ago
role.php
4.1 KB
2 years ago
taxonomy.php
1.1 KB
2 years ago
api.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.23, at base/api.php
| 1 | <?php |
| 2 | /** |
| 3 | * Abstract api class |
| 4 | * |
| 5 | * @package Timetics |
| 6 | */ |
| 7 | namespace Timetics\Base; |
| 8 | |
| 9 | use WP_Error; |
| 10 | |
| 11 | /** |
| 12 | * Abstract class Api. |
| 13 | * |
| 14 | * @since 1.0.0 |
| 15 | */ |
| 16 | abstract class Api extends \WP_REST_Controller { |
| 17 | |
| 18 | /** |
| 19 | * Api Constructor function. |
| 20 | * |
| 21 | * @since 1.0.0 |
| 22 | * |
| 23 | * @return void |
| 24 | */ |
| 25 | public function __construct() { |
| 26 | add_action( 'rest_api_init', [ $this, 'register_routes' ] ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Register routes |
| 31 | * |
| 32 | * @since 1.0.0 |
| 33 | * |
| 34 | * @return void |
| 35 | */ |
| 36 | public function register_routes() { |
| 37 | // Need to override the function on child class. |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Validate input fields. |
| 42 | * |
| 43 | * @since 1.0.0 |
| 44 | * |
| 45 | * @param array $data Accepts data in array format. |
| 46 | * @param array $fields Optional. Default empty array. |
| 47 | * |
| 48 | * @return bool | WP_error |
| 49 | */ |
| 50 | public function validate( $data, $fields = [] ) { |
| 51 | $error = new WP_Error(); |
| 52 | |
| 53 | foreach ( $fields as $field ) { |
| 54 | if ( empty( $data[ $field ] ) ) { |
| 55 | /* translators: Error Message */ |
| 56 | $error->add( $field . '_error', sprintf( esc_html__( '%s can\'t be empty', 'timetics' ), $field ) ); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if ( ! empty( $error->errors ) ) { |
| 61 | return $error; |
| 62 | } |
| 63 | |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | } |
| 68 |