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