1 | <?php |
||
11 | class Theme_Options_Container extends Container { |
||
12 | |||
13 | /** |
||
14 | * Array of registered page slugs to verify uniqueness with |
||
15 | * |
||
16 | * @var array |
||
17 | */ |
||
18 | protected static $registered_pages = array(); |
||
19 | |||
20 | /** |
||
21 | * Array of container settings |
||
22 | * |
||
23 | * @var array |
||
24 | */ |
||
25 | public $settings = array( |
||
26 | 'parent' => '', |
||
27 | 'file' => '', |
||
28 | 'icon' => '', |
||
29 | 'position' => null, |
||
30 | ); |
||
31 | |||
32 | /** |
||
33 | * Create a new container |
||
34 | * |
||
35 | * @param string $unique_id Unique id of the container |
||
36 | * @param string $title title of the container |
||
37 | * @param string $type Type of the container |
||
38 | */ |
||
39 | public function __construct( $unique_id, $title, $type ) { |
||
46 | |||
47 | /** |
||
48 | * Sanitize the container title for use in |
||
49 | * the theme options file name. |
||
50 | * |
||
51 | * @param string $string |
||
52 | * @return string |
||
53 | */ |
||
54 | protected function clear_string( $string ) { |
||
57 | |||
58 | /** |
||
59 | * Attach container as a theme options page/subpage. |
||
60 | */ |
||
61 | public function init() { |
||
77 | |||
78 | /** |
||
79 | * Checks whether the current save request is valid |
||
80 | * |
||
81 | * @return bool |
||
82 | */ |
||
83 | public function is_valid_save() { |
||
90 | |||
91 | /** |
||
92 | * Perform save operation after successful is_valid_save() check. |
||
93 | * The call is propagated to all fields in the container. |
||
94 | * |
||
95 | * @param mixed $user_data |
||
96 | */ |
||
97 | public function save( $user_data = null ) { |
||
110 | |||
111 | /** |
||
112 | * Get environment array for page request (in admin) |
||
113 | * |
||
114 | * @return array |
||
115 | */ |
||
116 | protected function get_environment_for_request() { |
||
119 | |||
120 | /** |
||
121 | * Perform checks whether the container should be attached during the current request |
||
122 | * |
||
123 | * @return bool True if the container is allowed to be attached |
||
124 | */ |
||
125 | public function is_valid_attach_for_request() { |
||
128 | |||
129 | /** |
||
130 | * Get environment array for object id |
||
131 | * |
||
132 | * @return array |
||
133 | */ |
||
134 | protected function get_environment_for_object( $object_id ) { |
||
137 | |||
138 | /** |
||
139 | * Check container attachment rules against object id |
||
140 | * |
||
141 | * @param int $object_id |
||
142 | * @return bool |
||
143 | */ |
||
144 | public function is_valid_attach_for_object( $object_id = null ) { |
||
147 | |||
148 | /** |
||
149 | * Add theme options container pages. |
||
150 | * Hook the container saving action. |
||
151 | */ |
||
152 | public function attach() { |
||
181 | |||
182 | /** |
||
183 | * Whether this container is currently viewed. |
||
184 | * |
||
185 | * @return boolean |
||
186 | */ |
||
187 | public function should_activate() { |
||
196 | |||
197 | /** |
||
198 | * Output the container markup |
||
199 | */ |
||
200 | public function render() { |
||
209 | |||
210 | /** |
||
211 | * Register the page while making sure it is unique. |
||
212 | * |
||
213 | * @return boolean |
||
214 | */ |
||
215 | public function register_page() { |
||
243 | |||
244 | /** |
||
245 | * Change the parent theme options page of this container |
||
246 | * |
||
247 | * @return Container $this |
||
248 | */ |
||
249 | public function set_page_parent( $parent ) { |
||
257 | |||
258 | /** |
||
259 | * Set the icon of this theme options page. |
||
260 | * Applicable only for parent theme option pages. |
||
261 | * |
||
262 | * @return Container $this |
||
263 | */ |
||
264 | public function set_icon( $icon ) { |
||
268 | |||
269 | /** |
||
270 | * Set the theme options file name of this container. |
||
271 | * |
||
272 | * @return Container $this |
||
273 | */ |
||
274 | public function set_page_file( $file ) { |
||
278 | |||
279 | /** |
||
280 | * Set the page position of this container in the administration menu. |
||
281 | * |
||
282 | * @return Container $this |
||
283 | */ |
||
284 | public function set_page_position( $position ) { |
||
288 | } |
||
289 | |||
290 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: