@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @param CMB2 $cmb The CMB2 object to hookup. |
42 | 42 | */ |
43 | - public static function maybe_init_and_hookup( CMB2 $cmb ) { |
|
44 | - throw new Exception( sprintf( esc_html__( '%1$s should be implemented by the extended class.', 'cmb2' ), __FUNCTION__ ) ); |
|
43 | + public static function maybe_init_and_hookup(CMB2 $cmb) { |
|
44 | + throw new Exception(sprintf(esc_html__('%1$s should be implemented by the extended class.', 'cmb2'), __FUNCTION__)); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @since 2.0.0 |
51 | 51 | * @param CMB2 $cmb The CMB2 object to hookup. |
52 | 52 | */ |
53 | - public function __construct( CMB2 $cmb ) { |
|
53 | + public function __construct(CMB2 $cmb) { |
|
54 | 54 | $this->cmb = $cmb; |
55 | 55 | $this->object_type = $this->cmb->mb_object_type(); |
56 | 56 | } |
@@ -66,23 +66,23 @@ discard block |
||
66 | 66 | * @param integer $priority Order the functions are executed. |
67 | 67 | * @param int $accepted_args The number of arguments the function accepts. |
68 | 68 | */ |
69 | - public function once( $action, $hook, $priority = 10, $accepted_args = 1 ) { |
|
69 | + public function once($action, $hook, $priority = 10, $accepted_args = 1) { |
|
70 | 70 | static $hooks_completed = array(); |
71 | 71 | |
72 | 72 | $args = func_get_args(); |
73 | 73 | |
74 | 74 | // Get object hash.. This bypasses issues with serializing closures. |
75 | - if ( is_object( $hook ) ) { |
|
76 | - $args[1] = spl_object_hash( $args[1] ); |
|
77 | - } elseif ( is_array( $hook ) && is_object( $hook[0] ) ) { |
|
78 | - $args[1][0] = spl_object_hash( $hook[0] ); |
|
75 | + if (is_object($hook)) { |
|
76 | + $args[1] = spl_object_hash($args[1]); |
|
77 | + } elseif (is_array($hook) && is_object($hook[0])) { |
|
78 | + $args[1][0] = spl_object_hash($hook[0]); |
|
79 | 79 | } |
80 | 80 | |
81 | - $key = md5( serialize( $args ) ); |
|
81 | + $key = md5(serialize($args)); |
|
82 | 82 | |
83 | - if ( ! isset( $hooks_completed[ $key ] ) ) { |
|
84 | - $hooks_completed[ $key ] = 1; |
|
85 | - add_filter( $action, $hook, $priority, $accepted_args ); |
|
83 | + if ( ! isset($hooks_completed[$key])) { |
|
84 | + $hooks_completed[$key] = 1; |
|
85 | + add_filter($action, $hook, $priority, $accepted_args); |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
@@ -93,13 +93,13 @@ discard block |
||
93 | 93 | * @throws Exception Throws an exception if the field is invalid. |
94 | 94 | * @return mixed |
95 | 95 | */ |
96 | - public function __get( $field ) { |
|
97 | - switch ( $field ) { |
|
96 | + public function __get($field) { |
|
97 | + switch ($field) { |
|
98 | 98 | case 'object_type': |
99 | 99 | case 'cmb': |
100 | 100 | return $this->{$field}; |
101 | 101 | default: |
102 | - throw new Exception( sprintf( esc_html__( 'Invalid %1$s property: %2$s', 'cmb2' ), __CLASS__, $field ) ); |
|
102 | + throw new Exception(sprintf(esc_html__('Invalid %1$s property: %2$s', 'cmb2'), __CLASS__, $field)); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | } |
@@ -24,13 +24,13 @@ discard block |
||
24 | 24 | */ |
25 | 25 | protected static $option_sets = array(); |
26 | 26 | |
27 | - public static function get( $option_key ) { |
|
27 | + public static function get($option_key) { |
|
28 | 28 | |
29 | - if ( empty( self::$option_sets ) || empty( self::$option_sets[ $option_key ] ) ) { |
|
30 | - self::$option_sets[ $option_key ] = new CMB2_Option( $option_key ); |
|
29 | + if (empty(self::$option_sets) || empty(self::$option_sets[$option_key])) { |
|
30 | + self::$option_sets[$option_key] = new CMB2_Option($option_key); |
|
31 | 31 | } |
32 | 32 | |
33 | - return self::$option_sets[ $option_key ]; |
|
33 | + return self::$option_sets[$option_key]; |
|
34 | 34 | } |
35 | 35 | } |
36 | 36 | |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | * Leave empty for temporary data store. |
65 | 65 | * @since 2.0.0 |
66 | 66 | */ |
67 | - public function __construct( $option_key = '' ) { |
|
68 | - $this->key = ! empty( $option_key ) ? $option_key : ''; |
|
67 | + public function __construct($option_key = '') { |
|
68 | + $this->key = ! empty($option_key) ? $option_key : ''; |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * @return mixed Delete success or failure |
76 | 76 | */ |
77 | 77 | public function delete_option() { |
78 | - $deleted = $this->key ? delete_option( $this->key ) : true; |
|
78 | + $deleted = $this->key ? delete_option($this->key) : true; |
|
79 | 79 | $this->options = $deleted ? array() : $this->options; |
80 | 80 | return $this->options; |
81 | 81 | } |
@@ -88,15 +88,15 @@ discard block |
||
88 | 88 | * @param bool $resave Whether or not to resave. |
89 | 89 | * @return array Modified options |
90 | 90 | */ |
91 | - public function remove( $field_id, $resave = false ) { |
|
91 | + public function remove($field_id, $resave = false) { |
|
92 | 92 | |
93 | 93 | $this->get_options(); |
94 | 94 | |
95 | - if ( isset( $this->options[ $field_id ] ) ) { |
|
96 | - unset( $this->options[ $field_id ] ); |
|
95 | + if (isset($this->options[$field_id])) { |
|
96 | + unset($this->options[$field_id]); |
|
97 | 97 | } |
98 | 98 | |
99 | - if ( $resave ) { |
|
99 | + if ($resave) { |
|
100 | 100 | $this->set(); |
101 | 101 | } |
102 | 102 | |
@@ -111,13 +111,13 @@ discard block |
||
111 | 111 | * @param mixed $default Fallback value for the option. |
112 | 112 | * @return array Requested field or default |
113 | 113 | */ |
114 | - public function get( $field_id, $default = false ) { |
|
114 | + public function get($field_id, $default = false) { |
|
115 | 115 | $opts = $this->get_options(); |
116 | 116 | |
117 | - if ( 'all' == $field_id ) { |
|
117 | + if ('all' == $field_id) { |
|
118 | 118 | return $opts; |
119 | - } elseif ( array_key_exists( $field_id, $opts ) ) { |
|
120 | - return false !== $opts[ $field_id ] ? $opts[ $field_id ] : $default; |
|
119 | + } elseif (array_key_exists($field_id, $opts)) { |
|
120 | + return false !== $opts[$field_id] ? $opts[$field_id] : $default; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | return $default; |
@@ -133,20 +133,20 @@ discard block |
||
133 | 133 | * @param bool $single Whether data should not be an array. |
134 | 134 | * @return boolean Return status of update. |
135 | 135 | */ |
136 | - public function update( $field_id, $value = '', $resave = false, $single = true ) { |
|
136 | + public function update($field_id, $value = '', $resave = false, $single = true) { |
|
137 | 137 | $this->get_options(); |
138 | 138 | |
139 | - if ( true !== $field_id ) { |
|
139 | + if (true !== $field_id) { |
|
140 | 140 | |
141 | - if ( ! $single ) { |
|
141 | + if ( ! $single) { |
|
142 | 142 | // If multiple, add to array. |
143 | - $this->options[ $field_id ][] = $value; |
|
143 | + $this->options[$field_id][] = $value; |
|
144 | 144 | } else { |
145 | - $this->options[ $field_id ] = $value; |
|
145 | + $this->options[$field_id] = $value; |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | - if ( $resave || true === $field_id ) { |
|
149 | + if ($resave || true === $field_id) { |
|
150 | 150 | return $this->set(); |
151 | 151 | } |
152 | 152 | |
@@ -164,20 +164,20 @@ discard block |
||
164 | 164 | * @param array $options Optional options to override. |
165 | 165 | * @return bool Success/Failure |
166 | 166 | */ |
167 | - public function set( $options = array() ) { |
|
168 | - if ( ! empty( $options ) || empty( $options ) && empty( $this->key ) ) { |
|
167 | + public function set($options = array()) { |
|
168 | + if ( ! empty($options) || empty($options) && empty($this->key)) { |
|
169 | 169 | $this->options = $options; |
170 | 170 | } |
171 | 171 | |
172 | - $this->options = wp_unslash( $this->options ); // get rid of those evil magic quotes. |
|
172 | + $this->options = wp_unslash($this->options); // get rid of those evil magic quotes. |
|
173 | 173 | |
174 | - if ( empty( $this->key ) ) { |
|
174 | + if (empty($this->key)) { |
|
175 | 175 | return false; |
176 | 176 | } |
177 | 177 | |
178 | - $test_save = apply_filters( "cmb2_override_option_save_{$this->key}", 'cmb2_no_override_option_save', $this->options, $this ); |
|
178 | + $test_save = apply_filters("cmb2_override_option_save_{$this->key}", 'cmb2_no_override_option_save', $this->options, $this); |
|
179 | 179 | |
180 | - if ( 'cmb2_no_override_option_save' !== $test_save ) { |
|
180 | + if ('cmb2_no_override_option_save' !== $test_save) { |
|
181 | 181 | // If override, do not proceed to update the option, just return result. |
182 | 182 | return $test_save; |
183 | 183 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @param bool $autoload Whether to load the option when WordPress starts up. |
193 | 193 | * @param CMB2_Option $cmb_option This object. |
194 | 194 | */ |
195 | - $autoload = apply_filters( "cmb2_should_autoload_{$this->key}", true, $this ); |
|
195 | + $autoload = apply_filters("cmb2_should_autoload_{$this->key}", true, $this); |
|
196 | 196 | |
197 | 197 | return update_option( |
198 | 198 | $this->key, |
@@ -211,16 +211,16 @@ discard block |
||
211 | 211 | * @param mixed $default Optional. Default value to return if the option does not exist. |
212 | 212 | * @return mixed Value set for the option. |
213 | 213 | */ |
214 | - public function get_options( $default = null ) { |
|
215 | - if ( empty( $this->options ) && ! empty( $this->key ) ) { |
|
214 | + public function get_options($default = null) { |
|
215 | + if (empty($this->options) && ! empty($this->key)) { |
|
216 | 216 | |
217 | - $test_get = apply_filters( "cmb2_override_option_get_{$this->key}", 'cmb2_no_override_option_get', $default, $this ); |
|
217 | + $test_get = apply_filters("cmb2_override_option_get_{$this->key}", 'cmb2_no_override_option_get', $default, $this); |
|
218 | 218 | |
219 | - if ( 'cmb2_no_override_option_get' !== $test_get ) { |
|
219 | + if ('cmb2_no_override_option_get' !== $test_get) { |
|
220 | 220 | $this->options = $test_get; |
221 | 221 | } else { |
222 | 222 | // If no override, get the option. |
223 | - $this->options = get_option( $this->key, $default ); |
|
223 | + $this->options = get_option($this->key, $default); |
|
224 | 224 | } |
225 | 225 | } |
226 | 226 | |
@@ -238,13 +238,13 @@ discard block |
||
238 | 238 | * @throws Exception Throws an exception if the field is invalid. |
239 | 239 | * @return mixed |
240 | 240 | */ |
241 | - public function __get( $field ) { |
|
242 | - switch ( $field ) { |
|
241 | + public function __get($field) { |
|
242 | + switch ($field) { |
|
243 | 243 | case 'options': |
244 | 244 | case 'key': |
245 | 245 | return $this->{$field}; |
246 | 246 | default: |
247 | - throw new Exception( sprintf( esc_html__( 'Invalid %1$s property: %2$s', 'cmb2' ), __CLASS__, $field ) ); |
|
247 | + throw new Exception(sprintf(esc_html__('Invalid %1$s property: %2$s', 'cmb2'), __CLASS__, $field)); |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | } |
@@ -17,13 +17,13 @@ discard block |
||
17 | 17 | */ |
18 | 18 | function cmb2_bootstrap() { |
19 | 19 | |
20 | - if ( is_admin() ) { |
|
20 | + if (is_admin()) { |
|
21 | 21 | /** |
22 | 22 | * Fires on the admin side when CMB2 is included/loaded. |
23 | 23 | * |
24 | 24 | * In most cases, this should be used to add metaboxes. See example-functions.php |
25 | 25 | */ |
26 | - do_action( 'cmb2_admin_init' ); |
|
26 | + do_action('cmb2_admin_init'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * |
32 | 32 | * Can be used to add metaboxes if needed on the front-end or WP-API (or the front and backend). |
33 | 33 | */ |
34 | - do_action( 'cmb2_init' ); |
|
34 | + do_action('cmb2_init'); |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * For back-compat. Does the dirty-work of instantiating all the |
@@ -39,15 +39,15 @@ discard block |
||
39 | 39 | * |
40 | 40 | * @since 2.0.2 |
41 | 41 | */ |
42 | - $cmb_config_arrays = apply_filters( 'cmb2_meta_boxes', array() ); |
|
43 | - foreach ( (array) $cmb_config_arrays as $cmb_config ) { |
|
44 | - new CMB2( $cmb_config ); |
|
42 | + $cmb_config_arrays = apply_filters('cmb2_meta_boxes', array()); |
|
43 | + foreach ((array) $cmb_config_arrays as $cmb_config) { |
|
44 | + new CMB2($cmb_config); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Fires after all CMB2 instances are created |
49 | 49 | */ |
50 | - do_action( 'cmb2_init_before_hookup' ); |
|
50 | + do_action('cmb2_init_before_hookup'); |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Get all created metaboxes, and instantiate CMB2_Hookup |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @since 2.0.2 |
57 | 57 | */ |
58 | - foreach ( CMB2_Boxes::get_all() as $cmb ) { |
|
58 | + foreach (CMB2_Boxes::get_all() as $cmb) { |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Initiates the box "hookup" into WordPress. |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @param array $cmb The CMB2 object to hookup. |
74 | 74 | */ |
75 | - do_action( "cmb2_init_hookup_{$cmb->cmb_id}", $cmb ); |
|
75 | + do_action("cmb2_init_hookup_{$cmb->cmb_id}", $cmb); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | 79 | * Fires after CMB2 initiation process has been completed |
80 | 80 | */ |
81 | - do_action( 'cmb2_after_init' ); |
|
81 | + do_action('cmb2_after_init'); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /* End. That's it, folks! */ |