1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
<?php
class Papi_Core_Box {
/**
* Capabilities list.
*
* @var array
*/
public $capabilities = [];
/**
* Context.
*
* @var string
*/
public $context = 'normal';
/**
* Display box.
*
* @var boolean
*/
public $display = true;
/**
* The core type identifier.
*
* @var string
*/
public $id = '';
/**
* Box layout that all properties will inherit.
*
* Possible values are:
* - horizontal
* - vertical
*
* @var string
*/
public $layout = 'horizontal';
/**
* Custom box options.
*
* @var array
*/
private $options = [];
/**
* Priority.
*
* @var string
*/
public $priority = 'default';
/**
* Box properties.
*
* @var array
*/
public $properties = [];
/**
* The sort order of the core box.
*
* @var int
*/
public $sort_order = 1000;
/**
* The title of the box.
*
* @var string
*/
public $title = '';
/**
* The constructor.
*
* @param array $args
* @param array $properties
*/
public function __construct( array $args = [], array $properties = [] ) {
$this->setup_args( $args );
$this->setup_properties( $properties );
}
/**
* Get box option.
*
* @param string $key
*
* @return mixed
*/
public function get_option( $key ) {
return isset( $this->options[$key] ) ? $this->options[$key] : null;
}
/**
* Set box option.
*
* @param string $key
* @param mixed $value
*/
public function set_option( $key, $value ) {
$this->options[$key] = $value;
}
/**
* Setup arguments.
*
* @param array $args
*/
private function setup_args( array $args ) {
$excluded_keys = ['options', 'properties'];
foreach ( $args as $key => $value ) {
if ( isset( $this->$key ) && ! in_array( $key, $excluded_keys ) ) {
$this->$key = papi_esc_html( $value );
}
}
if ( empty( $this->id ) ) {
$this->id = strtolower( papi_f( papi_underscorify( papify( $this->title ) ) ) );
$this->id = sanitize_text_field( $this->id );
}
}
/**
* Setup properties.
*
* @param array $properties
*/
private function setup_properties( array $properties ) {
$this->properties = papi_populate_properties( $properties );
}
/**
* Get a string representation of the object.
*
* @return string
*/
public function __toString() {
return $this->id;
}
}