AudioPreset.php
4 years ago
Block.php
4 years ago
CurrentUser.php
5 years ago
EmailCollection.php
5 years ago
LicensedProduct.php
5 years ago
Model.php
4 years ago
ModelInterface.php
5 years ago
Player.php
5 years ago
Post.php
5 years ago
Preset.php
4 years ago
ReusableVideo.php
4 years ago
Setting.php
5 years ago
Video.php
4 years ago
Webhook.php
3 years ago
Webhook.php
88 lines
| 1 | <?php |
| 2 | |
| 3 | namespace PrestoPlayer\Models; |
| 4 | |
| 5 | class Webhook extends Model |
| 6 | { |
| 7 | /** |
| 8 | * Table used to access db |
| 9 | * |
| 10 | * @var string |
| 11 | */ |
| 12 | protected $table = 'presto_player_webhooks'; |
| 13 | |
| 14 | /** |
| 15 | * Model Schema |
| 16 | * |
| 17 | * @var array |
| 18 | */ |
| 19 | public function schema() |
| 20 | { |
| 21 | return [ |
| 22 | 'id' => [ |
| 23 | 'type' => 'integer' |
| 24 | ], |
| 25 | 'name' => [ |
| 26 | 'type' => 'string', |
| 27 | 'sanitize_callback' => 'wp_kses_post' |
| 28 | ], |
| 29 | 'url' => [ |
| 30 | 'type' => 'string', |
| 31 | 'sanitize_callback' => 'sanitize_url' |
| 32 | ], |
| 33 | 'method' => [ |
| 34 | 'type' => 'string', |
| 35 | 'sanitize_callback' => 'sanitize_text_field' |
| 36 | ], |
| 37 | 'email_name' => [ |
| 38 | 'type' => 'string', |
| 39 | 'sanitize_callback' => 'sanitize_text_field' |
| 40 | ], |
| 41 | 'headers' => [ |
| 42 | 'type' => 'array' |
| 43 | ], |
| 44 | 'created_by' => [ |
| 45 | 'type' => 'integer', |
| 46 | 'default' => get_current_user_id() |
| 47 | ], |
| 48 | 'created_at' => [ |
| 49 | 'type' => 'string' |
| 50 | ], |
| 51 | 'updated_at' => [ |
| 52 | 'type' => 'string', |
| 53 | 'default' => current_time('mysql') |
| 54 | ], |
| 55 | 'deleted_at' => [ |
| 56 | 'type' => 'string' |
| 57 | ] |
| 58 | ]; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * These attributes are queryable |
| 63 | * |
| 64 | * @var array |
| 65 | */ |
| 66 | protected $queryable = ['name']; |
| 67 | |
| 68 | /** |
| 69 | * Create a preset in the db |
| 70 | * |
| 71 | * @param array $args |
| 72 | * @return integer |
| 73 | */ |
| 74 | public function create($args = []) |
| 75 | { |
| 76 | // name is required |
| 77 | if (empty($args['name'])) { |
| 78 | return new \WP_Error('missing_parameter', __('You must enter a name for the webhook.', 'presto-player')); |
| 79 | } |
| 80 | |
| 81 | // generate slug on the fly |
| 82 | $args['name'] = !empty($args['name']) ? $args['name'] : sanitize_title($args['name']); |
| 83 | |
| 84 | // create |
| 85 | return parent::create($args); |
| 86 | } |
| 87 | } |
| 88 |