| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentSupport\App\Models; |
| 4 |
|
| 5 |
use FluentSupport\Framework\Database\Orm\Model as BaseModel; |
| 6 |
|
| 7 |
class Model extends BaseModel |
| 8 |
{ |
| 9 |
protected $guarded = ['id', 'ID']; |
| 10 |
|
| 11 |
public function __construct($attributes = []) |
| 12 |
{ |
| 13 |
parent::__construct($attributes); |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Dates go out as stored: site time, "Y-m-d H:i:s", like every other date |
| 18 |
* column. The framework default is an ISO UTC moment, which made |
| 19 |
* created_at/updated_at the only dates in another format. |
| 20 |
* |
| 21 |
* @param \DateTimeInterface $date |
| 22 |
* @return string |
| 23 |
*/ |
| 24 |
protected function serializeDate(\DateTimeInterface $date) |
| 25 |
{ |
| 26 |
if ($date instanceof \DateTime || $date instanceof \DateTimeImmutable) { |
| 27 |
$date = (clone $date)->setTimezone(wp_timezone()); |
| 28 |
} |
| 29 |
|
| 30 |
return $date->format('Y-m-d H:i:s'); |
| 31 |
} |
| 32 |
|
| 33 |
public function getPerPage() |
| 34 |
{ |
| 35 |
if (!isset($_REQUEST['per_page'])) { |
| 36 |
return 15; |
| 37 |
} |
| 38 |
|
| 39 |
if (isset($_REQUEST['nonce'])) { |
| 40 |
$nonceAction = (defined('REST_REQUEST') && REST_REQUEST) ? 'wp_rest' : 'fluent-support'; |
| 41 |
|
| 42 |
if (!wp_verify_nonce(sanitize_text_field(wp_unslash($_REQUEST['nonce'])), $nonceAction)) { |
| 43 |
return 15; |
| 44 |
} |
| 45 |
} elseif (is_admin() || wp_doing_ajax() || (defined('REST_REQUEST') && REST_REQUEST)) { |
| 46 |
return intval(sanitize_text_field(wp_unslash($_REQUEST['per_page']))) ?? 15; |
| 47 |
} |
| 48 |
|
| 49 |
return intval(sanitize_text_field(wp_unslash($_REQUEST['per_page']))); |
| 50 |
} |
| 51 |
} |
| 52 |
|