@@ 25-38 (lines=14) @@ | ||
22 | * |
|
23 | * @param array|callable $options |
|
24 | */ |
|
25 | public function set_options( $options ) { |
|
26 | $this->options = array(); |
|
27 | ||
28 | if ( is_callable( $options ) ) { |
|
29 | $this->options = $options; |
|
30 | } elseif ( is_array( $options ) ) { |
|
31 | $this->add_options( $options ); |
|
32 | } else { |
|
33 | $this->options = array(); |
|
34 | Incorrect_Syntax_Exception::raise( 'Only arrays and callbacks are allowed in the <code>set_options()</code> method.' ); |
|
35 | } |
|
36 | ||
37 | return $this; |
|
38 | } |
|
39 | ||
40 | /** |
|
41 | * Add new options to this field. |
|
@@ 46-56 (lines=11) @@ | ||
43 | * |
|
44 | * @param array|callable $options |
|
45 | */ |
|
46 | public function add_options( $options ) { |
|
47 | if ( is_array( $options ) ) { |
|
48 | $old_options = is_callable( $this->options ) ? array() : $this->options; |
|
49 | $this->options = array_merge( $old_options, $options ); |
|
50 | } else { |
|
51 | $this->options = array(); |
|
52 | Incorrect_Syntax_Exception::raise( 'Only arrays are allowed in the <code>add_options()</code> method.' ); |
|
53 | } |
|
54 | ||
55 | return $this; |
|
56 | } |
|
57 | ||
58 | /** |
|
59 | * Check if there are callbacks and populate the options |