Creating models
<?php
namespace HivePress\Models;
use HivePress\Helpers as hp;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
class Foo_Bar extends Post {
public function __construct( $args = [] ) {
$args = hp\merge_arrays(
[
// Define the model fields.
'fields' => [
'description' => [
'type' => 'textarea',
'max_length' => 1234,
'required' => true,
'_alias' => 'post_content',
],
],
],
$args
);
parent::__construct( $args );
}
// Implement custom methods.
public function get_short_description() {
return substr( $this->get_description(), 0, 123 );
}
}Last updated