@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | */ |
22 | 22 | function setUp() { |
23 | 23 | parent::setUp(); |
24 | - require_once( WP_FIELDS_API_DIR . 'implementation/wp-includes/class-wp-customize-manager.php' ); |
|
24 | + require_once(WP_FIELDS_API_DIR.'implementation/wp-includes/class-wp-customize-manager.php'); |
|
25 | 25 | //require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; |
26 | - wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); |
|
26 | + wp_set_current_user($this->factory->user->create(array('role' => 'administrator'))); |
|
27 | 27 | |
28 | 28 | global $wp_customize; |
29 | 29 | $this->wp_customize = new WP_Customize_Manager(); |
@@ -45,15 +45,15 @@ discard block |
||
45 | 45 | * @return array |
46 | 46 | */ |
47 | 47 | function get_nav_menu_items_option() { |
48 | - return get_option( 'nav_menu_options', array( 'auto_add' => array() ) ); |
|
48 | + return get_option('nav_menu_options', array('auto_add' => array())); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Test constants and statics. |
53 | 53 | */ |
54 | 54 | function test_constants() { |
55 | - do_action( 'customize_register', $this->wp_customize ); |
|
56 | - $this->assertTrue( taxonomy_exists( WP_Customize_Nav_Menu_Setting::TAXONOMY ) ); |
|
55 | + do_action('customize_register', $this->wp_customize); |
|
56 | + $this->assertTrue(taxonomy_exists(WP_Customize_Nav_Menu_Setting::TAXONOMY)); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -62,49 +62,49 @@ discard block |
||
62 | 62 | * @see WP_Customize_Nav_Menu_Setting::__construct() |
63 | 63 | */ |
64 | 64 | function test_construct() { |
65 | - do_action( 'customize_register', $this->wp_customize ); |
|
66 | - |
|
67 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, 'nav_menu[123]' ); |
|
68 | - $this->assertEquals( 'nav_menu', $setting->type ); |
|
69 | - $this->assertEquals( 'postMessage', $setting->transport ); |
|
70 | - $this->assertEquals( 123, $setting->term_id ); |
|
71 | - $this->assertNull( $setting->previous_term_id ); |
|
72 | - $this->assertNull( $setting->update_status ); |
|
73 | - $this->assertNull( $setting->update_error ); |
|
74 | - $this->assertInternalType( 'array', $setting->default ); |
|
75 | - foreach ( array( 'name', 'description', 'parent' ) as $key ) { |
|
76 | - $this->assertArrayHasKey( $key, $setting->default ); |
|
65 | + do_action('customize_register', $this->wp_customize); |
|
66 | + |
|
67 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, 'nav_menu[123]'); |
|
68 | + $this->assertEquals('nav_menu', $setting->type); |
|
69 | + $this->assertEquals('postMessage', $setting->transport); |
|
70 | + $this->assertEquals(123, $setting->term_id); |
|
71 | + $this->assertNull($setting->previous_term_id); |
|
72 | + $this->assertNull($setting->update_status); |
|
73 | + $this->assertNull($setting->update_error); |
|
74 | + $this->assertInternalType('array', $setting->default); |
|
75 | + foreach (array('name', 'description', 'parent') as $key) { |
|
76 | + $this->assertArrayHasKey($key, $setting->default); |
|
77 | 77 | } |
78 | - $this->assertEquals( '', $setting->default['name'] ); |
|
79 | - $this->assertEquals( '', $setting->default['description'] ); |
|
80 | - $this->assertEquals( 0, $setting->default['parent'] ); |
|
78 | + $this->assertEquals('', $setting->default['name']); |
|
79 | + $this->assertEquals('', $setting->default['description']); |
|
80 | + $this->assertEquals(0, $setting->default['parent']); |
|
81 | 81 | |
82 | 82 | $exception = null; |
83 | 83 | try { |
84 | - $bad_setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, 'foo_bar_baz' ); |
|
85 | - unset( $bad_setting ); |
|
86 | - } catch ( Exception $e ) { |
|
84 | + $bad_setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, 'foo_bar_baz'); |
|
85 | + unset($bad_setting); |
|
86 | + } catch (Exception $e) { |
|
87 | 87 | $exception = $e; |
88 | 88 | } |
89 | - $this->assertInstanceOf( 'Exception', $exception ); |
|
89 | + $this->assertInstanceOf('Exception', $exception); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
93 | 93 | * Test empty constructor. |
94 | 94 | */ |
95 | 95 | function test_construct_empty_menus() { |
96 | - do_action( 'customize_register', $this->wp_customize ); |
|
96 | + do_action('customize_register', $this->wp_customize); |
|
97 | 97 | $_wp_customize = $this->wp_customize; |
98 | - unset( $_wp_customize->nav_menus ); |
|
98 | + unset($_wp_customize->nav_menus); |
|
99 | 99 | |
100 | 100 | $exception = null; |
101 | 101 | try { |
102 | - $bad_setting = new WP_Customize_Nav_Menu_Setting( $_wp_customize, 'nav_menu_item[123]' ); |
|
103 | - unset( $bad_setting ); |
|
104 | - } catch ( Exception $e ) { |
|
102 | + $bad_setting = new WP_Customize_Nav_Menu_Setting($_wp_customize, 'nav_menu_item[123]'); |
|
103 | + unset($bad_setting); |
|
104 | + } catch (Exception $e) { |
|
105 | 105 | $exception = $e; |
106 | 106 | } |
107 | - $this->assertInstanceOf( 'Exception', $exception ); |
|
107 | + $this->assertInstanceOf('Exception', $exception); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -113,15 +113,15 @@ discard block |
||
113 | 113 | * @see WP_Customize_Nav_Menu_Setting::__construct() |
114 | 114 | */ |
115 | 115 | function test_construct_placeholder() { |
116 | - do_action( 'customize_register', $this->wp_customize ); |
|
116 | + do_action('customize_register', $this->wp_customize); |
|
117 | 117 | $default = array( |
118 | 118 | 'name' => 'Lorem', |
119 | 119 | 'description' => 'ipsum', |
120 | 120 | 'parent' => 123, |
121 | 121 | ); |
122 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, 'nav_menu[-5]', compact( 'default' ) ); |
|
122 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, 'nav_menu[-5]', compact('default')); |
|
123 | 123 | $this->assertEquals( -5, $setting->term_id ); |
124 | - $this->assertEquals( $default, $setting->default ); |
|
124 | + $this->assertEquals($default, $setting->default); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -130,33 +130,33 @@ discard block |
||
130 | 130 | * @see WP_Customize_Nav_Menu_Setting::value() |
131 | 131 | */ |
132 | 132 | function test_value() { |
133 | - do_action( 'customize_register', $this->wp_customize ); |
|
133 | + do_action('customize_register', $this->wp_customize); |
|
134 | 134 | |
135 | 135 | $menu_name = 'Test 123'; |
136 | - $parent_menu_id = wp_create_nav_menu( "Parent $menu_name" ); |
|
136 | + $parent_menu_id = wp_create_nav_menu("Parent $menu_name"); |
|
137 | 137 | $description = 'Hello my world.'; |
138 | - $menu_id = wp_update_nav_menu_object( 0, array( |
|
138 | + $menu_id = wp_update_nav_menu_object(0, array( |
|
139 | 139 | 'menu-name' => $menu_name, |
140 | 140 | 'parent' => $parent_menu_id, |
141 | 141 | 'description' => $description, |
142 | - ) ); |
|
142 | + )); |
|
143 | 143 | |
144 | 144 | $setting_id = "nav_menu[$menu_id]"; |
145 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
145 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
146 | 146 | |
147 | 147 | $value = $setting->value(); |
148 | - $this->assertInternalType( 'array', $value ); |
|
149 | - foreach ( array( 'name', 'description', 'parent' ) as $key ) { |
|
150 | - $this->assertArrayHasKey( $key, $value ); |
|
148 | + $this->assertInternalType('array', $value); |
|
149 | + foreach (array('name', 'description', 'parent') as $key) { |
|
150 | + $this->assertArrayHasKey($key, $value); |
|
151 | 151 | } |
152 | - $this->assertEquals( $menu_name, $value['name'] ); |
|
153 | - $this->assertEquals( $description, $value['description'] ); |
|
154 | - $this->assertEquals( $parent_menu_id, $value['parent'] ); |
|
152 | + $this->assertEquals($menu_name, $value['name']); |
|
153 | + $this->assertEquals($description, $value['description']); |
|
154 | + $this->assertEquals($parent_menu_id, $value['parent']); |
|
155 | 155 | |
156 | 156 | $new_menu_name = 'Foo'; |
157 | - wp_update_nav_menu_object( $menu_id, array( 'menu-name' => $new_menu_name ) ); |
|
157 | + wp_update_nav_menu_object($menu_id, array('menu-name' => $new_menu_name)); |
|
158 | 158 | $updated_value = $setting->value(); |
159 | - $this->assertEquals( $new_menu_name, $updated_value['name'] ); |
|
159 | + $this->assertEquals($new_menu_name, $updated_value['name']); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
@@ -165,18 +165,18 @@ discard block |
||
165 | 165 | * @see WP_Customize_Nav_Menu_Setting::preview() |
166 | 166 | */ |
167 | 167 | function test_preview_updated() { |
168 | - do_action( 'customize_register', $this->wp_customize ); |
|
168 | + do_action('customize_register', $this->wp_customize); |
|
169 | 169 | |
170 | - $menu_id = wp_update_nav_menu_object( 0, array( |
|
170 | + $menu_id = wp_update_nav_menu_object(0, array( |
|
171 | 171 | 'menu-name' => 'Name 1', |
172 | 172 | 'description' => 'Description 1', |
173 | 173 | 'parent' => 0, |
174 | - ) ); |
|
174 | + )); |
|
175 | 175 | $setting_id = "nav_menu[$menu_id]"; |
176 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
176 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
177 | 177 | |
178 | 178 | $nav_menu_options = $this->get_nav_menu_items_option(); |
179 | - $this->assertNotContains( $menu_id, $nav_menu_options['auto_add'] ); |
|
179 | + $this->assertNotContains($menu_id, $nav_menu_options['auto_add']); |
|
180 | 180 | |
181 | 181 | $post_value = array( |
182 | 182 | 'name' => 'Name 2', |
@@ -184,41 +184,41 @@ discard block |
||
184 | 184 | 'parent' => 1, |
185 | 185 | 'auto_add' => true, |
186 | 186 | ); |
187 | - $this->wp_customize->set_post_value( $setting_id, $post_value ); |
|
187 | + $this->wp_customize->set_post_value($setting_id, $post_value); |
|
188 | 188 | |
189 | 189 | $value = $setting->value(); |
190 | - $this->assertEquals( 'Name 1', $value['name'] ); |
|
191 | - $this->assertEquals( 'Description 1', $value['description'] ); |
|
192 | - $this->assertEquals( 0, $value['parent'] ); |
|
190 | + $this->assertEquals('Name 1', $value['name']); |
|
191 | + $this->assertEquals('Description 1', $value['description']); |
|
192 | + $this->assertEquals(0, $value['parent']); |
|
193 | 193 | |
194 | - $term = (array) wp_get_nav_menu_object( $menu_id ); |
|
194 | + $term = (array) wp_get_nav_menu_object($menu_id); |
|
195 | 195 | |
196 | 196 | $this->assertEqualSets( |
197 | - wp_array_slice_assoc( $value, array( 'name', 'description', 'parent' ) ), |
|
198 | - wp_array_slice_assoc( $term, array( 'name', 'description', 'parent' ) ) |
|
197 | + wp_array_slice_assoc($value, array('name', 'description', 'parent')), |
|
198 | + wp_array_slice_assoc($term, array('name', 'description', 'parent')) |
|
199 | 199 | ); |
200 | 200 | |
201 | 201 | $setting->preview(); |
202 | 202 | $value = $setting->value(); |
203 | - $this->assertEquals( 'Name 2', $value['name'] ); |
|
204 | - $this->assertEquals( 'Description 2', $value['description'] ); |
|
205 | - $this->assertEquals( 1, $value['parent'] ); |
|
206 | - $term = (array) wp_get_nav_menu_object( $menu_id ); |
|
207 | - $this->assertEqualSets( $value, wp_array_slice_assoc( $term, array_keys( $value ) ) ); |
|
203 | + $this->assertEquals('Name 2', $value['name']); |
|
204 | + $this->assertEquals('Description 2', $value['description']); |
|
205 | + $this->assertEquals(1, $value['parent']); |
|
206 | + $term = (array) wp_get_nav_menu_object($menu_id); |
|
207 | + $this->assertEqualSets($value, wp_array_slice_assoc($term, array_keys($value))); |
|
208 | 208 | |
209 | - $menu_object = wp_get_nav_menu_object( $menu_id ); |
|
210 | - $this->assertEquals( (object) $term, $menu_object ); |
|
211 | - $this->assertEquals( $post_value['name'], $menu_object->name ); |
|
209 | + $menu_object = wp_get_nav_menu_object($menu_id); |
|
210 | + $this->assertEquals((object) $term, $menu_object); |
|
211 | + $this->assertEquals($post_value['name'], $menu_object->name); |
|
212 | 212 | |
213 | - $nav_menu_options = get_option( 'nav_menu_options', array( 'auto_add' => array() ) ); |
|
214 | - $this->assertContains( $menu_id, $nav_menu_options['auto_add'] ); |
|
213 | + $nav_menu_options = get_option('nav_menu_options', array('auto_add' => array())); |
|
214 | + $this->assertContains($menu_id, $nav_menu_options['auto_add']); |
|
215 | 215 | |
216 | 216 | $menus = wp_get_nav_menus(); |
217 | - $menus_ids = wp_list_pluck( $menus, 'term_id' ); |
|
218 | - $i = array_search( $menu_id, $menus_ids ); |
|
219 | - $this->assertInternalType( 'int', $i, 'Update-previewed menu does not appear in wp_get_nav_menus()' ); |
|
220 | - $filtered_menu = $menus[ $i ]; |
|
221 | - $this->assertEquals( 'Name 2', $filtered_menu->name ); |
|
217 | + $menus_ids = wp_list_pluck($menus, 'term_id'); |
|
218 | + $i = array_search($menu_id, $menus_ids); |
|
219 | + $this->assertInternalType('int', $i, 'Update-previewed menu does not appear in wp_get_nav_menus()'); |
|
220 | + $filtered_menu = $menus[$i]; |
|
221 | + $this->assertEquals('Name 2', $filtered_menu->name); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | * @see WP_Customize_Nav_Menu_Setting::preview() |
228 | 228 | */ |
229 | 229 | function test_preview_inserted() { |
230 | - do_action( 'customize_register', $this->wp_customize ); |
|
230 | + do_action('customize_register', $this->wp_customize); |
|
231 | 231 | |
232 | 232 | $menu_id = -123; |
233 | 233 | $post_value = array( |
@@ -237,33 +237,33 @@ discard block |
||
237 | 237 | 'auto_add' => false, |
238 | 238 | ); |
239 | 239 | $setting_id = "nav_menu[$menu_id]"; |
240 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
240 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
241 | 241 | |
242 | - $this->wp_customize->set_post_value( $setting->id, $post_value ); |
|
242 | + $this->wp_customize->set_post_value($setting->id, $post_value); |
|
243 | 243 | $setting->preview(); |
244 | 244 | $value = $setting->value(); |
245 | - $this->assertEquals( $post_value, $value ); |
|
245 | + $this->assertEquals($post_value, $value); |
|
246 | 246 | |
247 | - $term = (array) wp_get_nav_menu_object( $menu_id ); |
|
248 | - $this->assertNotEmpty( $term ); |
|
249 | - $this->assertNotInstanceOf( 'WP_Error', $term ); |
|
250 | - $this->assertEqualSets( $post_value, wp_array_slice_assoc( $term, array_keys( $value ) ) ); |
|
251 | - $this->assertEquals( $menu_id, $term['term_id'] ); |
|
252 | - $this->assertEquals( $menu_id, $term['term_taxonomy_id'] ); |
|
247 | + $term = (array) wp_get_nav_menu_object($menu_id); |
|
248 | + $this->assertNotEmpty($term); |
|
249 | + $this->assertNotInstanceOf('WP_Error', $term); |
|
250 | + $this->assertEqualSets($post_value, wp_array_slice_assoc($term, array_keys($value))); |
|
251 | + $this->assertEquals($menu_id, $term['term_id']); |
|
252 | + $this->assertEquals($menu_id, $term['term_taxonomy_id']); |
|
253 | 253 | |
254 | - $menu_object = wp_get_nav_menu_object( $menu_id ); |
|
255 | - $this->assertEquals( (object) $term, $menu_object ); |
|
256 | - $this->assertEquals( $post_value['name'], $menu_object->name ); |
|
254 | + $menu_object = wp_get_nav_menu_object($menu_id); |
|
255 | + $this->assertEquals((object) $term, $menu_object); |
|
256 | + $this->assertEquals($post_value['name'], $menu_object->name); |
|
257 | 257 | |
258 | 258 | $nav_menu_options = $this->get_nav_menu_items_option(); |
259 | - $this->assertNotContains( $menu_id, $nav_menu_options['auto_add'] ); |
|
259 | + $this->assertNotContains($menu_id, $nav_menu_options['auto_add']); |
|
260 | 260 | |
261 | 261 | $menus = wp_get_nav_menus(); |
262 | - $menus_ids = wp_list_pluck( $menus, 'term_id' ); |
|
263 | - $i = array_search( $menu_id, $menus_ids ); |
|
264 | - $this->assertInternalType( 'int', $i, 'Insert-previewed menu was not injected into wp_get_nav_menus()' ); |
|
265 | - $filtered_menu = $menus[ $i ]; |
|
266 | - $this->assertEquals( 'New Menu Name 1', $filtered_menu->name ); |
|
262 | + $menus_ids = wp_list_pluck($menus, 'term_id'); |
|
263 | + $i = array_search($menu_id, $menus_ids); |
|
264 | + $this->assertInternalType('int', $i, 'Insert-previewed menu was not injected into wp_get_nav_menus()'); |
|
265 | + $filtered_menu = $menus[$i]; |
|
266 | + $this->assertEquals('New Menu Name 1', $filtered_menu->name); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -272,32 +272,32 @@ discard block |
||
272 | 272 | * @see WP_Customize_Nav_Menu_Setting::preview() |
273 | 273 | */ |
274 | 274 | function test_preview_deleted() { |
275 | - do_action( 'customize_register', $this->wp_customize ); |
|
275 | + do_action('customize_register', $this->wp_customize); |
|
276 | 276 | |
277 | - $menu_id = wp_update_nav_menu_object( 0, array( |
|
277 | + $menu_id = wp_update_nav_menu_object(0, array( |
|
278 | 278 | 'menu-name' => 'Name 1', |
279 | 279 | 'description' => 'Description 1', |
280 | 280 | 'parent' => 0, |
281 | - ) ); |
|
281 | + )); |
|
282 | 282 | $setting_id = "nav_menu[$menu_id]"; |
283 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
283 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
284 | 284 | $nav_menu_options = $this->get_nav_menu_items_option(); |
285 | 285 | $nav_menu_options['auto_add'][] = $menu_id; |
286 | - update_option( 'nav_menu_options', $nav_menu_options ); |
|
286 | + update_option('nav_menu_options', $nav_menu_options); |
|
287 | 287 | |
288 | 288 | $nav_menu_options = $this->get_nav_menu_items_option(); |
289 | - $this->assertContains( $menu_id, $nav_menu_options['auto_add'] ); |
|
289 | + $this->assertContains($menu_id, $nav_menu_options['auto_add']); |
|
290 | 290 | |
291 | - $this->wp_customize->set_post_value( $setting_id, false ); |
|
291 | + $this->wp_customize->set_post_value($setting_id, false); |
|
292 | 292 | |
293 | - $this->assertInternalType( 'array', $setting->value() ); |
|
294 | - $this->assertInternalType( 'object', wp_get_nav_menu_object( $menu_id ) ); |
|
293 | + $this->assertInternalType('array', $setting->value()); |
|
294 | + $this->assertInternalType('object', wp_get_nav_menu_object($menu_id)); |
|
295 | 295 | $setting->preview(); |
296 | - $this->assertFalse( $setting->value() ); |
|
297 | - $this->assertFalse( wp_get_nav_menu_object( $menu_id ) ); |
|
296 | + $this->assertFalse($setting->value()); |
|
297 | + $this->assertFalse(wp_get_nav_menu_object($menu_id)); |
|
298 | 298 | |
299 | 299 | $nav_menu_options = $this->get_nav_menu_items_option(); |
300 | - $this->assertNotContains( $menu_id, $nav_menu_options['auto_add'] ); |
|
300 | + $this->assertNotContains($menu_id, $nav_menu_options['auto_add']); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | /** |
@@ -306,11 +306,11 @@ discard block |
||
306 | 306 | * @see WP_Customize_Nav_Menu_Setting::sanitize() |
307 | 307 | */ |
308 | 308 | function test_sanitize() { |
309 | - do_action( 'customize_register', $this->wp_customize ); |
|
310 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, 'nav_menu[123]' ); |
|
309 | + do_action('customize_register', $this->wp_customize); |
|
310 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, 'nav_menu[123]'); |
|
311 | 311 | |
312 | - $this->assertNull( $setting->sanitize( 'not an array' ) ); |
|
313 | - $this->assertNull( $setting->sanitize( 123 ) ); |
|
312 | + $this->assertNull($setting->sanitize('not an array')); |
|
313 | + $this->assertNull($setting->sanitize(123)); |
|
314 | 314 | |
315 | 315 | $value = array( |
316 | 316 | 'name' => ' Hello <b>world</b> ', |
@@ -319,16 +319,16 @@ discard block |
||
319 | 319 | 'auto_add' => true, |
320 | 320 | 'extra' => 'ignored', |
321 | 321 | ); |
322 | - $sanitized = $setting->sanitize( $value ); |
|
323 | - $this->assertEquals( 'Hello <b>world</b>', $sanitized['name'] ); |
|
324 | - $this->assertEquals( 'New line', $sanitized['description'] ); |
|
325 | - $this->assertEquals( 0, $sanitized['parent'] ); |
|
326 | - $this->assertEquals( true, $sanitized['auto_add'] ); |
|
327 | - $this->assertEqualSets( array( 'name', 'description', 'parent', 'auto_add' ), array_keys( $sanitized ) ); |
|
322 | + $sanitized = $setting->sanitize($value); |
|
323 | + $this->assertEquals('Hello <b>world</b>', $sanitized['name']); |
|
324 | + $this->assertEquals('New line', $sanitized['description']); |
|
325 | + $this->assertEquals(0, $sanitized['parent']); |
|
326 | + $this->assertEquals(true, $sanitized['auto_add']); |
|
327 | + $this->assertEqualSets(array('name', 'description', 'parent', 'auto_add'), array_keys($sanitized)); |
|
328 | 328 | |
329 | 329 | $value['name'] = ' '; // Blank spaces. |
330 | - $sanitized = $setting->sanitize( $value ); |
|
331 | - $this->assertEquals( '(unnamed)', $sanitized['name'] ); |
|
330 | + $sanitized = $setting->sanitize($value); |
|
331 | + $this->assertEquals('(unnamed)', $sanitized['name']); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
@@ -337,19 +337,19 @@ discard block |
||
337 | 337 | * @see WP_Customize_Nav_Menu_Setting::update() |
338 | 338 | */ |
339 | 339 | function test_save_updated() { |
340 | - do_action( 'customize_register', $this->wp_customize ); |
|
340 | + do_action('customize_register', $this->wp_customize); |
|
341 | 341 | |
342 | - $menu_id = wp_update_nav_menu_object( 0, array( |
|
342 | + $menu_id = wp_update_nav_menu_object(0, array( |
|
343 | 343 | 'menu-name' => 'Name 1', |
344 | 344 | 'description' => 'Description 1', |
345 | 345 | 'parent' => 0, |
346 | - ) ); |
|
346 | + )); |
|
347 | 347 | $nav_menu_options = $this->get_nav_menu_items_option(); |
348 | 348 | $nav_menu_options['auto_add'][] = $menu_id; |
349 | - update_option( 'nav_menu_options', $nav_menu_options ); |
|
349 | + update_option('nav_menu_options', $nav_menu_options); |
|
350 | 350 | |
351 | 351 | $setting_id = "nav_menu[$menu_id]"; |
352 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
352 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
353 | 353 | |
354 | 354 | $auto_add = false; |
355 | 355 | $new_value = array( |
@@ -359,36 +359,36 @@ discard block |
||
359 | 359 | 'auto_add' => $auto_add, |
360 | 360 | ); |
361 | 361 | |
362 | - $this->wp_customize->set_post_value( $setting_id, $new_value ); |
|
362 | + $this->wp_customize->set_post_value($setting_id, $new_value); |
|
363 | 363 | $setting->save(); |
364 | 364 | |
365 | - $menu_object = wp_get_nav_menu_object( $menu_id ); |
|
366 | - foreach ( array( 'name', 'description', 'parent' ) as $key ) { |
|
367 | - $this->assertEquals( $new_value[ $key ], $menu_object->$key ); |
|
365 | + $menu_object = wp_get_nav_menu_object($menu_id); |
|
366 | + foreach (array('name', 'description', 'parent') as $key) { |
|
367 | + $this->assertEquals($new_value[$key], $menu_object->$key); |
|
368 | 368 | } |
369 | 369 | $this->assertEqualSets( |
370 | - wp_array_slice_assoc( $new_value, array( 'name', 'description', 'parent' ) ), |
|
371 | - wp_array_slice_assoc( (array) $menu_object, array( 'name', 'description', 'parent' ) ) |
|
370 | + wp_array_slice_assoc($new_value, array('name', 'description', 'parent')), |
|
371 | + wp_array_slice_assoc((array) $menu_object, array('name', 'description', 'parent')) |
|
372 | 372 | ); |
373 | - $this->assertEquals( $new_value, $setting->value() ); |
|
374 | - |
|
375 | - $save_response = apply_filters( 'customize_save_response', array() ); |
|
376 | - $this->assertArrayHasKey( 'nav_menu_updates', $save_response ); |
|
377 | - $update_result = array_shift( $save_response['nav_menu_updates'] ); |
|
378 | - $this->assertArrayHasKey( 'term_id', $update_result ); |
|
379 | - $this->assertArrayHasKey( 'previous_term_id', $update_result ); |
|
380 | - $this->assertArrayHasKey( 'error', $update_result ); |
|
381 | - $this->assertArrayHasKey( 'status', $update_result ); |
|
382 | - $this->assertArrayHasKey( 'saved_value', $update_result ); |
|
383 | - $this->assertEquals( $new_value, $update_result['saved_value'] ); |
|
384 | - |
|
385 | - $this->assertEquals( $menu_id, $update_result['term_id'] ); |
|
386 | - $this->assertNull( $update_result['previous_term_id'] ); |
|
387 | - $this->assertNull( $update_result['error'] ); |
|
388 | - $this->assertEquals( 'updated', $update_result['status'] ); |
|
373 | + $this->assertEquals($new_value, $setting->value()); |
|
374 | + |
|
375 | + $save_response = apply_filters('customize_save_response', array()); |
|
376 | + $this->assertArrayHasKey('nav_menu_updates', $save_response); |
|
377 | + $update_result = array_shift($save_response['nav_menu_updates']); |
|
378 | + $this->assertArrayHasKey('term_id', $update_result); |
|
379 | + $this->assertArrayHasKey('previous_term_id', $update_result); |
|
380 | + $this->assertArrayHasKey('error', $update_result); |
|
381 | + $this->assertArrayHasKey('status', $update_result); |
|
382 | + $this->assertArrayHasKey('saved_value', $update_result); |
|
383 | + $this->assertEquals($new_value, $update_result['saved_value']); |
|
384 | + |
|
385 | + $this->assertEquals($menu_id, $update_result['term_id']); |
|
386 | + $this->assertNull($update_result['previous_term_id']); |
|
387 | + $this->assertNull($update_result['error']); |
|
388 | + $this->assertEquals('updated', $update_result['status']); |
|
389 | 389 | |
390 | 390 | $nav_menu_options = $this->get_nav_menu_items_option(); |
391 | - $this->assertNotContains( $menu_id, $nav_menu_options['auto_add'] ); |
|
391 | + $this->assertNotContains($menu_id, $nav_menu_options['auto_add']); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | * @see WP_Customize_Nav_Menu_Setting::update() |
398 | 398 | */ |
399 | 399 | function test_save_inserted() { |
400 | - do_action( 'customize_register', $this->wp_customize ); |
|
400 | + do_action('customize_register', $this->wp_customize); |
|
401 | 401 | |
402 | 402 | $menu_id = -123; |
403 | 403 | $post_value = array( |
@@ -407,37 +407,37 @@ discard block |
||
407 | 407 | 'auto_add' => true, |
408 | 408 | ); |
409 | 409 | $setting_id = "nav_menu[$menu_id]"; |
410 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
410 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
411 | 411 | |
412 | - $this->wp_customize->set_post_value( $setting->id, $post_value ); |
|
412 | + $this->wp_customize->set_post_value($setting->id, $post_value); |
|
413 | 413 | |
414 | - $this->assertNull( $setting->previous_term_id ); |
|
415 | - $this->assertLessThan( 0, $setting->term_id ); |
|
414 | + $this->assertNull($setting->previous_term_id); |
|
415 | + $this->assertLessThan(0, $setting->term_id); |
|
416 | 416 | $setting->save(); |
417 | - $this->assertEquals( $menu_id, $setting->previous_term_id ); |
|
418 | - $this->assertGreaterThan( 0, $setting->term_id ); |
|
417 | + $this->assertEquals($menu_id, $setting->previous_term_id); |
|
418 | + $this->assertGreaterThan(0, $setting->term_id); |
|
419 | 419 | |
420 | 420 | $nav_menu_options = $this->get_nav_menu_items_option(); |
421 | - $this->assertContains( $setting->term_id, $nav_menu_options['auto_add'] ); |
|
422 | - |
|
423 | - $menu = wp_get_nav_menu_object( $setting->term_id ); |
|
424 | - unset( $post_value['auto_add'] ); |
|
425 | - $this->assertEqualSets( $post_value, wp_array_slice_assoc( (array) $menu, array_keys( $post_value ) ) ); |
|
426 | - |
|
427 | - $save_response = apply_filters( 'customize_save_response', array() ); |
|
428 | - $this->assertArrayHasKey( 'nav_menu_updates', $save_response ); |
|
429 | - $update_result = array_shift( $save_response['nav_menu_updates'] ); |
|
430 | - $this->assertArrayHasKey( 'term_id', $update_result ); |
|
431 | - $this->assertArrayHasKey( 'previous_term_id', $update_result ); |
|
432 | - $this->assertArrayHasKey( 'error', $update_result ); |
|
433 | - $this->assertArrayHasKey( 'status', $update_result ); |
|
434 | - $this->assertArrayHasKey( 'saved_value', $update_result ); |
|
435 | - $this->assertEquals( $setting->value(), $update_result['saved_value'] ); |
|
436 | - |
|
437 | - $this->assertEquals( $menu->term_id, $update_result['term_id'] ); |
|
438 | - $this->assertEquals( $menu_id, $update_result['previous_term_id'] ); |
|
439 | - $this->assertNull( $update_result['error'] ); |
|
440 | - $this->assertEquals( 'inserted', $update_result['status'] ); |
|
421 | + $this->assertContains($setting->term_id, $nav_menu_options['auto_add']); |
|
422 | + |
|
423 | + $menu = wp_get_nav_menu_object($setting->term_id); |
|
424 | + unset($post_value['auto_add']); |
|
425 | + $this->assertEqualSets($post_value, wp_array_slice_assoc((array) $menu, array_keys($post_value))); |
|
426 | + |
|
427 | + $save_response = apply_filters('customize_save_response', array()); |
|
428 | + $this->assertArrayHasKey('nav_menu_updates', $save_response); |
|
429 | + $update_result = array_shift($save_response['nav_menu_updates']); |
|
430 | + $this->assertArrayHasKey('term_id', $update_result); |
|
431 | + $this->assertArrayHasKey('previous_term_id', $update_result); |
|
432 | + $this->assertArrayHasKey('error', $update_result); |
|
433 | + $this->assertArrayHasKey('status', $update_result); |
|
434 | + $this->assertArrayHasKey('saved_value', $update_result); |
|
435 | + $this->assertEquals($setting->value(), $update_result['saved_value']); |
|
436 | + |
|
437 | + $this->assertEquals($menu->term_id, $update_result['term_id']); |
|
438 | + $this->assertEquals($menu_id, $update_result['previous_term_id']); |
|
439 | + $this->assertNull($update_result['error']); |
|
440 | + $this->assertEquals('inserted', $update_result['status']); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
@@ -446,23 +446,23 @@ discard block |
||
446 | 446 | * @see WP_Customize_Nav_Menu_Setting::update() |
447 | 447 | */ |
448 | 448 | function test_save_inserted_conflicted_name() { |
449 | - do_action( 'customize_register', $this->wp_customize ); |
|
449 | + do_action('customize_register', $this->wp_customize); |
|
450 | 450 | |
451 | 451 | $menu_name = 'Foo'; |
452 | - wp_update_nav_menu_object( 0, array( 'menu-name' => $menu_name ) ); |
|
452 | + wp_update_nav_menu_object(0, array('menu-name' => $menu_name)); |
|
453 | 453 | |
454 | 454 | $menu_id = -123; |
455 | 455 | $setting_id = "nav_menu[$menu_id]"; |
456 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
457 | - $this->wp_customize->set_post_value( $setting->id, array( 'name' => $menu_name ) ); |
|
456 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
457 | + $this->wp_customize->set_post_value($setting->id, array('name' => $menu_name)); |
|
458 | 458 | $setting->save(); |
459 | 459 | |
460 | 460 | $expected_resolved_menu_name = "$menu_name (2)"; |
461 | - $new_menu = wp_get_nav_menu_object( $setting->term_id ); |
|
462 | - $this->assertEquals( $expected_resolved_menu_name, $new_menu->name ); |
|
461 | + $new_menu = wp_get_nav_menu_object($setting->term_id); |
|
462 | + $this->assertEquals($expected_resolved_menu_name, $new_menu->name); |
|
463 | 463 | |
464 | - $save_response = apply_filters( 'customize_save_response', array() ); |
|
465 | - $this->assertEquals( $expected_resolved_menu_name, $save_response['nav_menu_updates'][0]['saved_value']['name'] ); |
|
464 | + $save_response = apply_filters('customize_save_response', array()); |
|
465 | + $this->assertEquals($expected_resolved_menu_name, $save_response['nav_menu_updates'][0]['saved_value']['name']); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
@@ -471,41 +471,41 @@ discard block |
||
471 | 471 | * @see WP_Customize_Nav_Menu_Setting::update() |
472 | 472 | */ |
473 | 473 | function test_save_deleted() { |
474 | - do_action( 'customize_register', $this->wp_customize ); |
|
474 | + do_action('customize_register', $this->wp_customize); |
|
475 | 475 | |
476 | 476 | $menu_name = 'Lorem Ipsum'; |
477 | - $menu_id = wp_create_nav_menu( $menu_name ); |
|
477 | + $menu_id = wp_create_nav_menu($menu_name); |
|
478 | 478 | $setting_id = "nav_menu[$menu_id]"; |
479 | - $setting = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); |
|
479 | + $setting = new WP_Customize_Nav_Menu_Setting($this->wp_customize, $setting_id); |
|
480 | 480 | $nav_menu_options = $this->get_nav_menu_items_option(); |
481 | 481 | $nav_menu_options['auto_add'][] = $menu_id; |
482 | - update_option( 'nav_menu_options', $nav_menu_options ); |
|
482 | + update_option('nav_menu_options', $nav_menu_options); |
|
483 | 483 | |
484 | - $menu = wp_get_nav_menu_object( $menu_id ); |
|
485 | - $this->assertEquals( $menu_name, $menu->name ); |
|
484 | + $menu = wp_get_nav_menu_object($menu_id); |
|
485 | + $this->assertEquals($menu_name, $menu->name); |
|
486 | 486 | |
487 | - $this->wp_customize->set_post_value( $setting_id, false ); |
|
487 | + $this->wp_customize->set_post_value($setting_id, false); |
|
488 | 488 | $setting->save(); |
489 | 489 | |
490 | - $this->assertFalse( wp_get_nav_menu_object( $menu_id ) ); |
|
490 | + $this->assertFalse(wp_get_nav_menu_object($menu_id)); |
|
491 | 491 | |
492 | - $save_response = apply_filters( 'customize_save_response', array() ); |
|
493 | - $this->assertArrayHasKey( 'nav_menu_updates', $save_response ); |
|
494 | - $update_result = array_shift( $save_response['nav_menu_updates'] ); |
|
495 | - $this->assertArrayHasKey( 'term_id', $update_result ); |
|
496 | - $this->assertArrayHasKey( 'previous_term_id', $update_result ); |
|
497 | - $this->assertArrayHasKey( 'error', $update_result ); |
|
498 | - $this->assertArrayHasKey( 'status', $update_result ); |
|
499 | - $this->assertArrayHasKey( 'saved_value', $update_result ); |
|
500 | - $this->assertNull( $update_result['saved_value'] ); |
|
492 | + $save_response = apply_filters('customize_save_response', array()); |
|
493 | + $this->assertArrayHasKey('nav_menu_updates', $save_response); |
|
494 | + $update_result = array_shift($save_response['nav_menu_updates']); |
|
495 | + $this->assertArrayHasKey('term_id', $update_result); |
|
496 | + $this->assertArrayHasKey('previous_term_id', $update_result); |
|
497 | + $this->assertArrayHasKey('error', $update_result); |
|
498 | + $this->assertArrayHasKey('status', $update_result); |
|
499 | + $this->assertArrayHasKey('saved_value', $update_result); |
|
500 | + $this->assertNull($update_result['saved_value']); |
|
501 | 501 | |
502 | - $this->assertEquals( $menu_id, $update_result['term_id'] ); |
|
503 | - $this->assertNull( $update_result['previous_term_id'] ); |
|
504 | - $this->assertNull( $update_result['error'] ); |
|
505 | - $this->assertEquals( 'deleted', $update_result['status'] ); |
|
502 | + $this->assertEquals($menu_id, $update_result['term_id']); |
|
503 | + $this->assertNull($update_result['previous_term_id']); |
|
504 | + $this->assertNull($update_result['error']); |
|
505 | + $this->assertEquals('deleted', $update_result['status']); |
|
506 | 506 | |
507 | 507 | $nav_menu_options = $this->get_nav_menu_items_option(); |
508 | - $this->assertNotContains( $menu_id, $nav_menu_options['auto_add'] ); |
|
508 | + $this->assertNotContains($menu_id, $nav_menu_options['auto_add']); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | } |
@@ -14,54 +14,54 @@ discard block |
||
14 | 14 | |
15 | 15 | function setUp() { |
16 | 16 | parent::setUp(); |
17 | - require_once( WP_FIELDS_API_DIR . 'implementation/wp-includes/class-wp-customize-manager.php' ); |
|
17 | + require_once(WP_FIELDS_API_DIR.'implementation/wp-includes/class-wp-customize-manager.php'); |
|
18 | 18 | //require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' ); |
19 | 19 | $GLOBALS['wp_customize'] = new WP_Customize_Manager(); |
20 | 20 | $this->manager = $GLOBALS['wp_customize']; |
21 | 21 | |
22 | - unset( $GLOBALS['_wp_sidebars_widgets'] ); // clear out cache set by wp_get_sidebars_widgets() |
|
22 | + unset($GLOBALS['_wp_sidebars_widgets']); // clear out cache set by wp_get_sidebars_widgets() |
|
23 | 23 | $sidebars_widgets = wp_get_sidebars_widgets(); |
24 | - $this->assertEqualSets( array( 'wp_inactive_widgets', 'sidebar-1' ), array_keys( wp_get_sidebars_widgets() ) ); |
|
25 | - $this->assertContains( 'search-2', $sidebars_widgets['sidebar-1'] ); |
|
26 | - $this->assertContains( 'categories-2', $sidebars_widgets['sidebar-1'] ); |
|
27 | - $this->assertArrayHasKey( 2, get_option( 'widget_search' ) ); |
|
28 | - $widget_categories = get_option( 'widget_categories' ); |
|
29 | - $this->assertArrayHasKey( 2, $widget_categories ); |
|
30 | - $this->assertEquals( '', $widget_categories[2]['title'] ); |
|
31 | - |
|
32 | - remove_action( 'after_setup_theme', 'twentyfifteen_setup' ); // @todo We should not be including a theme anyway |
|
33 | - |
|
34 | - $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); |
|
35 | - wp_set_current_user( $user_id ); |
|
24 | + $this->assertEqualSets(array('wp_inactive_widgets', 'sidebar-1'), array_keys(wp_get_sidebars_widgets())); |
|
25 | + $this->assertContains('search-2', $sidebars_widgets['sidebar-1']); |
|
26 | + $this->assertContains('categories-2', $sidebars_widgets['sidebar-1']); |
|
27 | + $this->assertArrayHasKey(2, get_option('widget_search')); |
|
28 | + $widget_categories = get_option('widget_categories'); |
|
29 | + $this->assertArrayHasKey(2, $widget_categories); |
|
30 | + $this->assertEquals('', $widget_categories[2]['title']); |
|
31 | + |
|
32 | + remove_action('after_setup_theme', 'twentyfifteen_setup'); // @todo We should not be including a theme anyway |
|
33 | + |
|
34 | + $user_id = $this->factory->user->create(array('role' => 'administrator')); |
|
35 | + wp_set_current_user($user_id); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | function tearDown() { |
39 | 39 | $this->manager = null; |
40 | - unset( $GLOBALS['wp_customize'] ); |
|
41 | - unset( $GLOBALS['wp_scripts'] ); |
|
40 | + unset($GLOBALS['wp_customize']); |
|
41 | + unset($GLOBALS['wp_scripts']); |
|
42 | 42 | parent::tearDown(); |
43 | 43 | } |
44 | 44 | |
45 | - function set_customized_post_data( $customized ) { |
|
46 | - $_POST['customized'] = wp_slash( wp_json_encode( $customized ) ); |
|
45 | + function set_customized_post_data($customized) { |
|
46 | + $_POST['customized'] = wp_slash(wp_json_encode($customized)); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | function do_customize_boot_actions() { |
50 | 50 | $_SERVER['REQUEST_METHOD'] = 'POST'; |
51 | - do_action( 'setup_theme' ); |
|
52 | - $_REQUEST['nonce'] = wp_create_nonce( 'preview-customize_' . $this->manager->theme()->get_stylesheet() ); |
|
53 | - do_action( 'after_setup_theme' ); |
|
54 | - do_action( 'init' ); |
|
55 | - do_action( 'wp_loaded' ); |
|
56 | - do_action( 'wp', $GLOBALS['wp'] ); |
|
51 | + do_action('setup_theme'); |
|
52 | + $_REQUEST['nonce'] = wp_create_nonce('preview-customize_'.$this->manager->theme()->get_stylesheet()); |
|
53 | + do_action('after_setup_theme'); |
|
54 | + do_action('init'); |
|
55 | + do_action('wp_loaded'); |
|
56 | + do_action('wp', $GLOBALS['wp']); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
60 | 60 | * Test WP_Customize_Widgets::__construct() |
61 | 61 | */ |
62 | 62 | function test_construct() { |
63 | - $this->assertInstanceOf( 'WP_Customize_Widgets', $this->manager->widgets ); |
|
64 | - $this->assertEquals( $this->manager, $this->manager->widgets->manager ); |
|
63 | + $this->assertInstanceOf('WP_Customize_Widgets', $this->manager->widgets); |
|
64 | + $this->assertEquals($this->manager, $this->manager->widgets->manager); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -83,20 +83,20 @@ discard block |
||
83 | 83 | ), |
84 | 84 | ); |
85 | 85 | $customized = array(); |
86 | - foreach ( $raw_widget_customized as $setting_id => $instance ) { |
|
87 | - $customized[ $setting_id ] = $this->manager->widgets->sanitize_widget_js_instance( $instance ); |
|
86 | + foreach ($raw_widget_customized as $setting_id => $instance) { |
|
87 | + $customized[$setting_id] = $this->manager->widgets->sanitize_widget_js_instance($instance); |
|
88 | 88 | } |
89 | 89 | |
90 | - $this->set_customized_post_data( $customized ); |
|
90 | + $this->set_customized_post_data($customized); |
|
91 | 91 | $this->do_customize_boot_actions(); |
92 | - $this->assertTrue( is_customize_preview() ); |
|
92 | + $this->assertTrue(is_customize_preview()); |
|
93 | 93 | |
94 | - $this->assertNotEmpty( $this->manager->get_setting( 'widget_categories[2]' ), 'Expected setting for pre-existing widget category-2, being customized.' ); |
|
95 | - $this->assertNotEmpty( $this->manager->get_setting( 'widget_search[2]' ), 'Expected setting for pre-existing widget search-2, not being customized.' ); |
|
96 | - $this->assertNotEmpty( $this->manager->get_setting( 'widget_search[3]' ), 'Expected dynamic setting for non-existing widget search-3, being customized.' ); |
|
94 | + $this->assertNotEmpty($this->manager->get_setting('widget_categories[2]'), 'Expected setting for pre-existing widget category-2, being customized.'); |
|
95 | + $this->assertNotEmpty($this->manager->get_setting('widget_search[2]'), 'Expected setting for pre-existing widget search-2, not being customized.'); |
|
96 | + $this->assertNotEmpty($this->manager->get_setting('widget_search[3]'), 'Expected dynamic setting for non-existing widget search-3, being customized.'); |
|
97 | 97 | |
98 | - $widget_categories = get_option( 'widget_categories' ); |
|
99 | - $this->assertEquals( $raw_widget_customized['widget_categories[2]'], $widget_categories[2], 'Expected $wp_customize->get_setting(widget_categories[2])->preview() to have been called.' ); |
|
98 | + $widget_categories = get_option('widget_categories'); |
|
99 | + $this->assertEquals($raw_widget_customized['widget_categories[2]'], $widget_categories[2], 'Expected $wp_customize->get_setting(widget_categories[2])->preview() to have been called.'); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -104,68 +104,68 @@ discard block |
||
104 | 104 | */ |
105 | 105 | function test_get_setting_args() { |
106 | 106 | |
107 | - add_filter( 'widget_customizer_setting_args', array( $this, 'filter_widget_customizer_setting_args' ), 10, 2 ); |
|
107 | + add_filter('widget_customizer_setting_args', array($this, 'filter_widget_customizer_setting_args'), 10, 2); |
|
108 | 108 | |
109 | 109 | $default_args = array( |
110 | 110 | 'type' => 'option', |
111 | 111 | 'capability' => 'edit_theme_options', |
112 | 112 | 'transport' => 'refresh', |
113 | 113 | 'default' => array(), |
114 | - 'sanitize_callback' => array( $this->manager->widgets, 'sanitize_widget_instance' ), |
|
115 | - 'sanitize_js_callback' => array( $this->manager->widgets, 'sanitize_widget_js_instance' ), |
|
114 | + 'sanitize_callback' => array($this->manager->widgets, 'sanitize_widget_instance'), |
|
115 | + 'sanitize_js_callback' => array($this->manager->widgets, 'sanitize_widget_js_instance'), |
|
116 | 116 | ); |
117 | 117 | |
118 | - $args = $this->manager->widgets->get_setting_args( 'widget_foo[2]' ); |
|
119 | - foreach ( $default_args as $key => $default_value ) { |
|
120 | - $this->assertEquals( $default_value, $args[ $key ] ); |
|
118 | + $args = $this->manager->widgets->get_setting_args('widget_foo[2]'); |
|
119 | + foreach ($default_args as $key => $default_value) { |
|
120 | + $this->assertEquals($default_value, $args[$key]); |
|
121 | 121 | } |
122 | - $this->assertEquals( 'WIDGET_FOO[2]', $args['uppercase_id_set_by_filter'] ); |
|
122 | + $this->assertEquals('WIDGET_FOO[2]', $args['uppercase_id_set_by_filter']); |
|
123 | 123 | |
124 | 124 | $override_args = array( |
125 | 125 | 'type' => 'theme_mod', |
126 | 126 | 'capability' => 'edit_posts', |
127 | 127 | 'transport' => 'postMessage', |
128 | - 'default' => array( 'title' => 'asd' ), |
|
128 | + 'default' => array('title' => 'asd'), |
|
129 | 129 | 'sanitize_callback' => '__return_empty_array', |
130 | 130 | 'sanitize_js_callback' => '__return_empty_array', |
131 | 131 | ); |
132 | - $args = $this->manager->widgets->get_setting_args( 'widget_bar[3]', $override_args ); |
|
133 | - foreach ( $override_args as $key => $override_value ) { |
|
134 | - $this->assertEquals( $override_value, $args[ $key ] ); |
|
132 | + $args = $this->manager->widgets->get_setting_args('widget_bar[3]', $override_args); |
|
133 | + foreach ($override_args as $key => $override_value) { |
|
134 | + $this->assertEquals($override_value, $args[$key]); |
|
135 | 135 | } |
136 | - $this->assertEquals( 'WIDGET_BAR[3]', $args['uppercase_id_set_by_filter'] ); |
|
136 | + $this->assertEquals('WIDGET_BAR[3]', $args['uppercase_id_set_by_filter']); |
|
137 | 137 | |
138 | 138 | $default_args = array( |
139 | 139 | 'type' => 'option', |
140 | 140 | 'capability' => 'edit_theme_options', |
141 | 141 | 'transport' => 'refresh', |
142 | 142 | 'default' => array(), |
143 | - 'sanitize_callback' => array( $this->manager->widgets, 'sanitize_sidebar_widgets' ), |
|
144 | - 'sanitize_js_callback' => array( $this->manager->widgets, 'sanitize_sidebar_widgets_js_instance' ), |
|
143 | + 'sanitize_callback' => array($this->manager->widgets, 'sanitize_sidebar_widgets'), |
|
144 | + 'sanitize_js_callback' => array($this->manager->widgets, 'sanitize_sidebar_widgets_js_instance'), |
|
145 | 145 | ); |
146 | - $args = $this->manager->widgets->get_setting_args( 'sidebars_widgets[sidebar-1]' ); |
|
147 | - foreach ( $default_args as $key => $default_value ) { |
|
148 | - $this->assertEquals( $default_value, $args[ $key ] ); |
|
146 | + $args = $this->manager->widgets->get_setting_args('sidebars_widgets[sidebar-1]'); |
|
147 | + foreach ($default_args as $key => $default_value) { |
|
148 | + $this->assertEquals($default_value, $args[$key]); |
|
149 | 149 | } |
150 | - $this->assertEquals( 'SIDEBARS_WIDGETS[SIDEBAR-1]', $args['uppercase_id_set_by_filter'] ); |
|
150 | + $this->assertEquals('SIDEBARS_WIDGETS[SIDEBAR-1]', $args['uppercase_id_set_by_filter']); |
|
151 | 151 | |
152 | 152 | $override_args = array( |
153 | 153 | 'type' => 'theme_mod', |
154 | 154 | 'capability' => 'edit_posts', |
155 | 155 | 'transport' => 'postMessage', |
156 | - 'default' => array( 'title' => 'asd' ), |
|
156 | + 'default' => array('title' => 'asd'), |
|
157 | 157 | 'sanitize_callback' => '__return_empty_array', |
158 | 158 | 'sanitize_js_callback' => '__return_empty_array', |
159 | 159 | ); |
160 | - $args = $this->manager->widgets->get_setting_args( 'sidebars_widgets[sidebar-2]', $override_args ); |
|
161 | - foreach ( $override_args as $key => $override_value ) { |
|
162 | - $this->assertEquals( $override_value, $args[ $key ] ); |
|
160 | + $args = $this->manager->widgets->get_setting_args('sidebars_widgets[sidebar-2]', $override_args); |
|
161 | + foreach ($override_args as $key => $override_value) { |
|
162 | + $this->assertEquals($override_value, $args[$key]); |
|
163 | 163 | } |
164 | - $this->assertEquals( 'SIDEBARS_WIDGETS[SIDEBAR-2]', $args['uppercase_id_set_by_filter'] ); |
|
164 | + $this->assertEquals('SIDEBARS_WIDGETS[SIDEBAR-2]', $args['uppercase_id_set_by_filter']); |
|
165 | 165 | } |
166 | 166 | |
167 | - function filter_widget_customizer_setting_args( $args, $id ) { |
|
168 | - $args['uppercase_id_set_by_filter'] = strtoupper( $id ); |
|
167 | + function filter_widget_customizer_setting_args($args, $id) { |
|
168 | + $args['uppercase_id_set_by_filter'] = strtoupper($id); |
|
169 | 169 | return $args; |
170 | 170 | } |
171 | 171 | |
@@ -182,18 +182,18 @@ discard block |
||
182 | 182 | 'dropdown' => '1', |
183 | 183 | ); |
184 | 184 | |
185 | - $sanitized_for_js = $this->manager->widgets->sanitize_widget_js_instance( $new_categories_instance ); |
|
186 | - $this->assertArrayHasKey( 'encoded_serialized_instance', $sanitized_for_js ); |
|
187 | - $this->assertTrue( is_serialized( base64_decode( $sanitized_for_js['encoded_serialized_instance'] ), true ) ); |
|
188 | - $this->assertEquals( $new_categories_instance['title'], $sanitized_for_js['title'] ); |
|
189 | - $this->assertTrue( $sanitized_for_js['is_widget_customizer_js_value'] ); |
|
190 | - $this->assertArrayHasKey( 'instance_hash_key', $sanitized_for_js ); |
|
185 | + $sanitized_for_js = $this->manager->widgets->sanitize_widget_js_instance($new_categories_instance); |
|
186 | + $this->assertArrayHasKey('encoded_serialized_instance', $sanitized_for_js); |
|
187 | + $this->assertTrue(is_serialized(base64_decode($sanitized_for_js['encoded_serialized_instance']), true)); |
|
188 | + $this->assertEquals($new_categories_instance['title'], $sanitized_for_js['title']); |
|
189 | + $this->assertTrue($sanitized_for_js['is_widget_customizer_js_value']); |
|
190 | + $this->assertArrayHasKey('instance_hash_key', $sanitized_for_js); |
|
191 | 191 | |
192 | 192 | $corrupted_sanitized_for_js = $sanitized_for_js; |
193 | - $corrupted_sanitized_for_js['encoded_serialized_instance'] = base64_encode( serialize( array( 'title' => 'EVIL' ) ) ); |
|
194 | - $this->assertNull( $this->manager->widgets->sanitize_widget_instance( $corrupted_sanitized_for_js ), 'Expected sanitize_widget_instance to reject corrupted data.' ); |
|
193 | + $corrupted_sanitized_for_js['encoded_serialized_instance'] = base64_encode(serialize(array('title' => 'EVIL'))); |
|
194 | + $this->assertNull($this->manager->widgets->sanitize_widget_instance($corrupted_sanitized_for_js), 'Expected sanitize_widget_instance to reject corrupted data.'); |
|
195 | 195 | |
196 | - $unsanitized_from_js = $this->manager->widgets->sanitize_widget_instance( $sanitized_for_js ); |
|
197 | - $this->assertEquals( $unsanitized_from_js, $new_categories_instance ); |
|
196 | + $unsanitized_from_js = $this->manager->widgets->sanitize_widget_instance($sanitized_for_js); |
|
197 | + $this->assertEquals($unsanitized_from_js, $new_categories_instance); |
|
198 | 198 | } |
199 | 199 | } |
@@ -5,28 +5,28 @@ |
||
5 | 5 | * @package WordPress |
6 | 6 | * @subpackage Fields API |
7 | 7 | */ |
8 | -define( 'WP_TESTS_FORCE_KNOWN_BUGS', true ); |
|
8 | +define('WP_TESTS_FORCE_KNOWN_BUGS', true); |
|
9 | 9 | |
10 | 10 | // Support for: |
11 | 11 | // 1. `WP_DEVELOP_DIR` environment variable |
12 | 12 | // 2. Plugin installed inside of WordPress.org developer checkout |
13 | 13 | // 3. Tests checked out to /tmp |
14 | 14 | // 4. VVV tests |
15 | -if ( false !== getenv( 'WP_DEVELOP_DIR' ) ) { |
|
16 | - $test_root = getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit'; |
|
17 | -} else if ( file_exists( '../../../../tests/phpunit/includes/bootstrap.php' ) ) { |
|
15 | +if (false !== getenv('WP_DEVELOP_DIR')) { |
|
16 | + $test_root = getenv('WP_DEVELOP_DIR').'/tests/phpunit'; |
|
17 | +} else if (file_exists('../../../../tests/phpunit/includes/bootstrap.php')) { |
|
18 | 18 | $test_root = '../../../../tests/phpunit'; |
19 | -} else if ( file_exists( '/tmp/wordpress-tests-lib/includes/bootstrap.php' ) ) { |
|
19 | +} else if (file_exists('/tmp/wordpress-tests-lib/includes/bootstrap.php')) { |
|
20 | 20 | $test_root = '/tmp/wordpress-tests-lib'; |
21 | -} else if ( file_exists( '/srv/www/wordpress-develop/tests/phpunit/includes/bootstrap.php' ) ) { |
|
21 | +} else if (file_exists('/srv/www/wordpress-develop/tests/phpunit/includes/bootstrap.php')) { |
|
22 | 22 | $test_root = '/srv/www/wordpress-develop/tests/phpunit'; |
23 | 23 | } |
24 | 24 | |
25 | -require $test_root . '/includes/functions.php'; |
|
25 | +require $test_root.'/includes/functions.php'; |
|
26 | 26 | |
27 | 27 | function _manually_load_plugin() { |
28 | - require dirname( __FILE__ ) . '/../wordpress-fields-api.php'; |
|
28 | + require dirname(__FILE__).'/../wordpress-fields-api.php'; |
|
29 | 29 | } |
30 | -tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); |
|
30 | +tests_add_filter('muplugins_loaded', '_manually_load_plugin'); |
|
31 | 31 | |
32 | -require $test_root . '/includes/bootstrap.php'; |
|
32 | +require $test_root.'/includes/bootstrap.php'; |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * WordPress Fields API Section classes |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Customize |
|
7 | - * @since 3.4.0 |
|
8 | - */ |
|
3 | + * WordPress Fields API Section classes |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Customize |
|
7 | + * @since 3.4.0 |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Fields API Section class. |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | |
157 | 157 | $args = func_get_args(); |
158 | 158 | |
159 | - call_user_func_array( array( $this, 'init' ), $args ); |
|
159 | + call_user_func_array(array($this, 'init'), $args); |
|
160 | 160 | |
161 | 161 | } |
162 | 162 | |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | * @param string $id A specific ID of the section. |
168 | 168 | * @param array $args Section arguments. |
169 | 169 | */ |
170 | - public function init( $object_type, $id, $args = array() ) { |
|
170 | + public function init($object_type, $id, $args = array()) { |
|
171 | 171 | |
172 | 172 | /** |
173 | 173 | * @var $wp_fields WP_Fields_API |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | |
177 | 177 | $this->object_type = $object_type; |
178 | 178 | |
179 | - if ( is_array( $id ) ) { |
|
179 | + if (is_array($id)) { |
|
180 | 180 | $args = $id; |
181 | 181 | |
182 | 182 | $id = ''; |
@@ -184,19 +184,19 @@ discard block |
||
184 | 184 | $this->id = $id; |
185 | 185 | } |
186 | 186 | |
187 | - $keys = array_keys( get_object_vars( $this ) ); |
|
187 | + $keys = array_keys(get_object_vars($this)); |
|
188 | 188 | |
189 | - foreach ( $keys as $key ) { |
|
190 | - if ( isset( $args[ $key ] ) ) { |
|
191 | - $this->$key = $args[ $key ]; |
|
189 | + foreach ($keys as $key) { |
|
190 | + if (isset($args[$key])) { |
|
191 | + $this->$key = $args[$key]; |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | 195 | self::$instance_count += 1; |
196 | 196 | $this->instance_number = self::$instance_count; |
197 | 197 | |
198 | - if ( empty( $this->active_callback ) ) { |
|
199 | - $this->active_callback = array( $this, 'active_callback' ); |
|
198 | + if (empty($this->active_callback)) { |
|
199 | + $this->active_callback = array($this, 'active_callback'); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /*if ( $this->screen ) { |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | $section = $this; |
225 | 225 | $active = true; |
226 | 226 | |
227 | - if ( is_callable( $this->active_callback ) ) { |
|
228 | - $active = call_user_func( $this->active_callback, $this ); |
|
227 | + if (is_callable($this->active_callback)) { |
|
228 | + $active = call_user_func($this->active_callback, $this); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * @param bool $active Whether the Fields API section is active. |
235 | 235 | * @param WP_Fields_API_Section $section {@see WP_Fields_API_Section} instance. |
236 | 236 | */ |
237 | - $active = apply_filters( 'fields_api_section_active_' . $this->object_type, $active, $section ); |
|
237 | + $active = apply_filters('fields_api_section_active_'.$this->object_type, $active, $section); |
|
238 | 238 | |
239 | 239 | return $active; |
240 | 240 | |
@@ -264,8 +264,8 @@ discard block |
||
264 | 264 | */ |
265 | 265 | public function json() { |
266 | 266 | |
267 | - $array = wp_array_slice_assoc( (array) $this, array( 'id', 'description', 'priority', 'screen', 'type' ) ); |
|
268 | - $array['title'] = html_entity_decode( $this->title, ENT_QUOTES, get_bloginfo( 'charset' ) ); |
|
267 | + $array = wp_array_slice_assoc((array) $this, array('id', 'description', 'priority', 'screen', 'type')); |
|
268 | + $array['title'] = html_entity_decode($this->title, ENT_QUOTES, get_bloginfo('charset')); |
|
269 | 269 | $array['content'] = $this->get_content(); |
270 | 270 | $array['active'] = $this->active(); |
271 | 271 | $array['instanceNumber'] = $this->instance_number; |
@@ -282,18 +282,18 @@ discard block |
||
282 | 282 | */ |
283 | 283 | public function check_capabilities() { |
284 | 284 | |
285 | - if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) { |
|
285 | + if ($this->capability && ! call_user_func_array('current_user_can', (array) $this->capability)) { |
|
286 | 286 | return false; |
287 | 287 | } |
288 | 288 | |
289 | - if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) { |
|
289 | + if ($this->theme_supports && ! call_user_func_array('current_theme_supports', (array) $this->theme_supports)) { |
|
290 | 290 | return false; |
291 | 291 | } |
292 | 292 | |
293 | 293 | $access = true; |
294 | 294 | |
295 | - if ( is_callable( $this->capabilities_callback ) ) { |
|
296 | - $access = call_user_func( $this->capabilities_callback, $this ); |
|
295 | + if (is_callable($this->capabilities_callback)) { |
|
296 | + $access = call_user_func($this->capabilities_callback, $this); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | return $access; |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | |
312 | 312 | $this->maybe_render(); |
313 | 313 | |
314 | - $template = trim( ob_get_contents() ); |
|
314 | + $template = trim(ob_get_contents()); |
|
315 | 315 | |
316 | 316 | ob_end_clean(); |
317 | 317 | |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | */ |
325 | 325 | final public function maybe_render() { |
326 | 326 | |
327 | - if ( ! $this->check_capabilities() ) { |
|
327 | + if ( ! $this->check_capabilities()) { |
|
328 | 328 | return; |
329 | 329 | } |
330 | 330 | |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | * |
337 | 337 | * @param WP_Fields_API_Section $this WP_Fields API_Section instance. |
338 | 338 | */ |
339 | - do_action( "fields_api_render_section_{$this->object_type}", $this ); |
|
339 | + do_action("fields_api_render_section_{$this->object_type}", $this); |
|
340 | 340 | |
341 | 341 | /** |
342 | 342 | * Fires before rendering a specific Fields API section. |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | * of the specific Fields API section to be rendered. |
349 | 349 | * |
350 | 350 | */ |
351 | - do_action( "fields_api_render_section_{$this->object_type}_{$this->object_name}_{$this->id}" ); |
|
351 | + do_action("fields_api_render_section_{$this->object_type}_{$this->object_name}_{$this->id}"); |
|
352 | 352 | |
353 | 353 | $this->render(); |
354 | 354 | |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | * // @todo Merge render_template / print_template() from Customizer |
361 | 361 | */ |
362 | 362 | protected function render() { |
363 | - echo esc_html( $this->title ); |
|
363 | + echo esc_html($this->title); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | /** |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | |
158 | 158 | $args = func_get_args(); |
159 | 159 | |
160 | - call_user_func_array( array( $this, 'init' ), $args ); |
|
160 | + call_user_func_array(array($this, 'init'), $args); |
|
161 | 161 | |
162 | 162 | } |
163 | 163 | |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @param string $id A specific ID of the control. |
169 | 169 | * @param array $args Control arguments. |
170 | 170 | */ |
171 | - public function init( $object_type, $id, $args = array() ) { |
|
171 | + public function init($object_type, $id, $args = array()) { |
|
172 | 172 | |
173 | 173 | /** |
174 | 174 | * @var $wp_fields WP_Fields_API |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | |
178 | 178 | $this->object_type = $object_type; |
179 | 179 | |
180 | - if ( is_array( $id ) ) { |
|
180 | + if (is_array($id)) { |
|
181 | 181 | $args = $id; |
182 | 182 | |
183 | 183 | $id = ''; |
@@ -185,40 +185,40 @@ discard block |
||
185 | 185 | $this->id = $id; |
186 | 186 | } |
187 | 187 | |
188 | - $keys = array_keys( get_object_vars( $this ) ); |
|
188 | + $keys = array_keys(get_object_vars($this)); |
|
189 | 189 | |
190 | - foreach ( $keys as $key ) { |
|
191 | - if ( isset( $args[ $key ] ) ) { |
|
192 | - $this->$key = $args[ $key ]; |
|
190 | + foreach ($keys as $key) { |
|
191 | + if (isset($args[$key])) { |
|
192 | + $this->$key = $args[$key]; |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
196 | - if ( empty( $this->active_callback ) ) { |
|
197 | - $this->active_callback = array( $this, 'active_callback' ); |
|
196 | + if (empty($this->active_callback)) { |
|
197 | + $this->active_callback = array($this, 'active_callback'); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | self::$instance_count += 1; |
201 | 201 | $this->instance_number = self::$instance_count; |
202 | 202 | |
203 | 203 | // Process fields. |
204 | - if ( empty( $this->fields ) ) { |
|
204 | + if (empty($this->fields)) { |
|
205 | 205 | $this->fields = $id; |
206 | 206 | } |
207 | 207 | |
208 | 208 | $fields = array(); |
209 | 209 | |
210 | - if ( is_array( $this->fields ) ) { |
|
211 | - foreach ( $this->fields as $key => $field ) { |
|
212 | - $field_obj = $wp_fields->get_field( $this->object_type, $field, $this->object_name ); |
|
210 | + if (is_array($this->fields)) { |
|
211 | + foreach ($this->fields as $key => $field) { |
|
212 | + $field_obj = $wp_fields->get_field($this->object_type, $field, $this->object_name); |
|
213 | 213 | |
214 | - if ( $field_obj ) { |
|
215 | - $fields[ $key ] = $field_obj; |
|
214 | + if ($field_obj) { |
|
215 | + $fields[$key] = $field_obj; |
|
216 | 216 | } |
217 | 217 | } |
218 | 218 | } else { |
219 | - $field_obj = $wp_fields->get_field( $this->object_type, $this->fields, $this->object_name ); |
|
219 | + $field_obj = $wp_fields->get_field($this->object_type, $this->fields, $this->object_name); |
|
220 | 220 | |
221 | - if ( $field_obj ) { |
|
221 | + if ($field_obj) { |
|
222 | 222 | $this->field = $field_obj; |
223 | 223 | $fields['default'] = $field_obj; |
224 | 224 | } |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | */ |
234 | 234 | public function setup_choices() { |
235 | 235 | |
236 | - if ( ! isset( $this->choices ) ) { |
|
236 | + if ( ! isset($this->choices)) { |
|
237 | 237 | $choices = $this->choices(); |
238 | 238 | |
239 | 239 | $this->choices = $choices; |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | $control = $this; |
268 | 268 | $active = true; |
269 | 269 | |
270 | - if ( is_callable( $this->active_callback ) ) { |
|
271 | - $active = call_user_func( $this->active_callback, $this ); |
|
270 | + if (is_callable($this->active_callback)) { |
|
271 | + $active = call_user_func($this->active_callback, $this); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * @param bool $active Whether the Field control is active. |
278 | 278 | * @param WP_Fields_API_Control $control WP_Fields_API_Control instance. |
279 | 279 | */ |
280 | - $active = apply_filters( 'fields_control_active_' . $this->object_type, $active, $control ); |
|
280 | + $active = apply_filters('fields_control_active_'.$this->object_type, $active, $control); |
|
281 | 281 | |
282 | 282 | return $active; |
283 | 283 | |
@@ -306,15 +306,15 @@ discard block |
||
306 | 306 | * @param string $field_key |
307 | 307 | * @return mixed The requested field's value, if the field exists. |
308 | 308 | */ |
309 | - final public function value( $field_key = 'default' ) { |
|
309 | + final public function value($field_key = 'default') { |
|
310 | 310 | |
311 | - if ( isset( $this->fields[ $field_key ] ) ) { |
|
311 | + if (isset($this->fields[$field_key])) { |
|
312 | 312 | /** |
313 | 313 | * @var $field WP_Fields_API_Field |
314 | 314 | */ |
315 | - $field = $this->fields[ $field_key ]; |
|
315 | + $field = $this->fields[$field_key]; |
|
316 | 316 | |
317 | - return $field->value( $this->item_id ); |
|
317 | + return $field->value($this->item_id); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | return null; |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | |
331 | 331 | $array = array(); |
332 | 332 | |
333 | - $array['fields'] = wp_list_pluck( $this->fields, 'id' ); |
|
333 | + $array['fields'] = wp_list_pluck($this->fields, 'id'); |
|
334 | 334 | $array['type'] = $this->type; |
335 | 335 | $array['priority'] = $this->priority; |
336 | 336 | $array['active'] = $this->active(); |
@@ -359,22 +359,22 @@ discard block |
||
359 | 359 | /** |
360 | 360 | * @var $field WP_Fields_API_Field |
361 | 361 | */ |
362 | - foreach ( $this->fields as $field ) { |
|
363 | - if ( ! $field || ! $field->check_capabilities() ) { |
|
362 | + foreach ($this->fields as $field) { |
|
363 | + if ( ! $field || ! $field->check_capabilities()) { |
|
364 | 364 | return false; |
365 | 365 | } |
366 | 366 | } |
367 | 367 | |
368 | - $section = $wp_fields->get_section( $this->object_type, $this->section, $this->object_name ); |
|
368 | + $section = $wp_fields->get_section($this->object_type, $this->section, $this->object_name); |
|
369 | 369 | |
370 | - if ( $section && ! $section->check_capabilities() ) { |
|
370 | + if ($section && ! $section->check_capabilities()) { |
|
371 | 371 | return false; |
372 | 372 | } |
373 | 373 | |
374 | 374 | $access = true; |
375 | 375 | |
376 | - if ( is_callable( $this->capabilities_callback ) ) { |
|
377 | - $access = call_user_func( $this->capabilities_callback, $this ); |
|
376 | + if (is_callable($this->capabilities_callback)) { |
|
377 | + $access = call_user_func($this->capabilities_callback, $this); |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | return $access; |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | |
393 | 393 | $this->maybe_render(); |
394 | 394 | |
395 | - $template = trim( ob_get_clean() ); |
|
395 | + $template = trim(ob_get_clean()); |
|
396 | 396 | |
397 | 397 | return $template; |
398 | 398 | |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | */ |
406 | 406 | final public function maybe_render() { |
407 | 407 | |
408 | - if ( ! $this->check_capabilities() ) { |
|
408 | + if ( ! $this->check_capabilities()) { |
|
409 | 409 | return; |
410 | 410 | } |
411 | 411 | |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | * |
415 | 415 | * @param WP_Fields_API_Control $this WP_Fields_API_Control instance. |
416 | 416 | */ |
417 | - do_action( 'fields_render_control_' . $this->object_type, $this ); |
|
417 | + do_action('fields_render_control_'.$this->object_type, $this); |
|
418 | 418 | |
419 | 419 | /** |
420 | 420 | * Fires just before a specific control is rendered. |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | * |
425 | 425 | * @param WP_Fields_API_Control $this {@see WP_Fields_API_Control} instance. |
426 | 426 | */ |
427 | - do_action( 'fields_render_control_' . $this->object_type . '_' . $this->object_name . '_' . $this->id, $this ); |
|
427 | + do_action('fields_render_control_'.$this->object_type.'_'.$this->object_name.'_'.$this->id, $this); |
|
428 | 428 | |
429 | 429 | $this->render(); |
430 | 430 | |
@@ -436,10 +436,10 @@ discard block |
||
436 | 436 | */ |
437 | 437 | protected function render() { |
438 | 438 | |
439 | - $id = 'fields-control-' . str_replace( '[', '-', str_replace( ']', '', $this->id ) ); |
|
440 | - $class = 'fields-control fields-control-' . $this->type; |
|
439 | + $id = 'fields-control-'.str_replace('[', '-', str_replace(']', '', $this->id)); |
|
440 | + $class = 'fields-control fields-control-'.$this->type; |
|
441 | 441 | |
442 | - ?><li id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( $class ); ?>"> |
|
442 | + ?><li id="<?php echo esc_attr($id); ?>" class="<?php echo esc_attr($class); ?>"> |
|
443 | 443 | <?php $this->render_content(); ?> |
444 | 444 | </li><?php |
445 | 445 | |
@@ -452,13 +452,13 @@ discard block |
||
452 | 452 | * @param string $field_key |
453 | 453 | * @return string Data link parameter, if $field_key is a valid field, empty string otherwise. |
454 | 454 | */ |
455 | - public function get_link( $field_key = 'default' ) { |
|
455 | + public function get_link($field_key = 'default') { |
|
456 | 456 | |
457 | - if ( ! isset( $this->fields[ $field_key ] ) ) { |
|
457 | + if ( ! isset($this->fields[$field_key])) { |
|
458 | 458 | return ''; |
459 | 459 | } |
460 | 460 | |
461 | - return 'data-fields-field-link="' . esc_attr( $this->fields[ $field_key ]->id ) . '"'; |
|
461 | + return 'data-fields-field-link="'.esc_attr($this->fields[$field_key]->id).'"'; |
|
462 | 462 | |
463 | 463 | } |
464 | 464 | |
@@ -469,9 +469,9 @@ discard block |
||
469 | 469 | * |
470 | 470 | * @param string $field_key |
471 | 471 | */ |
472 | - public function link( $field_key = 'default' ) { |
|
472 | + public function link($field_key = 'default') { |
|
473 | 473 | |
474 | - echo $this->get_link( $field_key ); |
|
474 | + echo $this->get_link($field_key); |
|
475 | 475 | |
476 | 476 | } |
477 | 477 | |
@@ -482,8 +482,8 @@ discard block |
||
482 | 482 | */ |
483 | 483 | public function input_attrs() { |
484 | 484 | |
485 | - foreach ( $this->input_attrs as $attr => $value ) { |
|
486 | - echo $attr . '="' . esc_attr( $value ) . '" '; |
|
485 | + foreach ($this->input_attrs as $attr => $value) { |
|
486 | + echo $attr.'="'.esc_attr($value).'" '; |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | } |
@@ -502,13 +502,13 @@ discard block |
||
502 | 502 | |
503 | 503 | ?> |
504 | 504 | <label> |
505 | - <?php if ( ! empty( $this->label ) ) : ?> |
|
506 | - <span class="fields-control-title"><?php echo esc_html( $this->label ); ?></span> |
|
505 | + <?php if ( ! empty($this->label)) : ?> |
|
506 | + <span class="fields-control-title"><?php echo esc_html($this->label); ?></span> |
|
507 | 507 | <?php endif; |
508 | - if ( ! empty( $this->description ) ) : ?> |
|
508 | + if ( ! empty($this->description)) : ?> |
|
509 | 509 | <span class="description fields-control-description"><?php echo $this->description; ?></span> |
510 | 510 | <?php endif; ?> |
511 | - <input type="<?php echo esc_attr( $this->type ); ?>" <?php $this->input_attrs(); ?> value="<?php echo esc_attr( $this->value( $this->item_id ) ); ?>" <?php $this->link(); ?> /> |
|
511 | + <input type="<?php echo esc_attr($this->type); ?>" <?php $this->input_attrs(); ?> value="<?php echo esc_attr($this->value($this->item_id)); ?>" <?php $this->link(); ?> /> |
|
512 | 512 | </label> |
513 | 513 | <?php |
514 | 514 | |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | public function print_template() { |
527 | 527 | |
528 | 528 | ?> |
529 | - <script type="text/html" id="tmpl-fields-<?php echo esc_attr( $this->object_type ); ?>-control-<?php echo esc_attr( $this->type ); ?>-content"> |
|
529 | + <script type="text/html" id="tmpl-fields-<?php echo esc_attr($this->object_type); ?>-control-<?php echo esc_attr($this->type); ?>-content"> |
|
530 | 530 | <?php $this->content_template(); ?> |
531 | 531 | </script> |
532 | 532 | <?php |
@@ -554,10 +554,10 @@ discard block |
||
554 | 554 | * |
555 | 555 | * @return mixed|null |
556 | 556 | */ |
557 | - public function &__get( $name ) { |
|
557 | + public function &__get($name) { |
|
558 | 558 | |
559 | 559 | // Map $this->choices to $this->choices() for dynamic choice handling |
560 | - if ( 'choices' == $name ) { |
|
560 | + if ('choices' == $name) { |
|
561 | 561 | $this->setup_choices(); |
562 | 562 | |
563 | 563 | return $this->choices; |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | |
150 | 150 | $args = func_get_args(); |
151 | 151 | |
152 | - call_user_func_array( array( $this, 'init' ), $args ); |
|
152 | + call_user_func_array(array($this, 'init'), $args); |
|
153 | 153 | |
154 | 154 | } |
155 | 155 | |
@@ -160,11 +160,11 @@ discard block |
||
160 | 160 | * @param string $id A specific ID of the screen. |
161 | 161 | * @param array $args Screen arguments. |
162 | 162 | */ |
163 | - public function init( $object_type, $id, $args = array() ) { |
|
163 | + public function init($object_type, $id, $args = array()) { |
|
164 | 164 | |
165 | 165 | $this->object_type = $object_type; |
166 | 166 | |
167 | - if ( is_array( $id ) ) { |
|
167 | + if (is_array($id)) { |
|
168 | 168 | $args = $id; |
169 | 169 | |
170 | 170 | $id = ''; |
@@ -172,19 +172,19 @@ discard block |
||
172 | 172 | $this->id = $id; |
173 | 173 | } |
174 | 174 | |
175 | - $keys = array_keys( get_object_vars( $this ) ); |
|
175 | + $keys = array_keys(get_object_vars($this)); |
|
176 | 176 | |
177 | - foreach ( $keys as $key ) { |
|
178 | - if ( isset( $args[ $key ] ) ) { |
|
179 | - $this->$key = $args[ $key ]; |
|
177 | + foreach ($keys as $key) { |
|
178 | + if (isset($args[$key])) { |
|
179 | + $this->$key = $args[$key]; |
|
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
183 | 183 | self::$instance_count += 1; |
184 | 184 | $this->instance_number = self::$instance_count; |
185 | 185 | |
186 | - if ( empty( $this->active_callback ) ) { |
|
187 | - $this->active_callback = array( $this, 'active_callback' ); |
|
186 | + if (empty($this->active_callback)) { |
|
187 | + $this->active_callback = array($this, 'active_callback'); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | $this->sections = array(); // Users cannot customize the $sections array. |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | $screen = $this; |
204 | 204 | $active = true; |
205 | 205 | |
206 | - if ( is_callable( $this->active_callback ) ) { |
|
207 | - $active = call_user_func( $this->active_callback, $this ); |
|
206 | + if (is_callable($this->active_callback)) { |
|
207 | + $active = call_user_func($this->active_callback, $this); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @param bool $active Whether the Fields API screen is active. |
215 | 215 | * @param WP_Fields_API_Screen $screen {@see WP_Fields_API_Screen} instance. |
216 | 216 | */ |
217 | - $active = apply_filters( 'fields_api_screen_active_' . $this->object_type, $active, $screen ); |
|
217 | + $active = apply_filters('fields_api_screen_active_'.$this->object_type, $active, $screen); |
|
218 | 218 | |
219 | 219 | return $active; |
220 | 220 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | */ |
244 | 244 | public function json() { |
245 | 245 | |
246 | - $array = wp_array_slice_assoc( (array) $this, array( 'id', 'title', 'description', 'priority', 'type' ) ); |
|
246 | + $array = wp_array_slice_assoc((array) $this, array('id', 'title', 'description', 'priority', 'type')); |
|
247 | 247 | |
248 | 248 | $array['content'] = $this->get_content(); |
249 | 249 | $array['active'] = $this->active(); |
@@ -261,18 +261,18 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function check_capabilities() { |
263 | 263 | |
264 | - if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) { |
|
264 | + if ($this->capability && ! call_user_func_array('current_user_can', (array) $this->capability)) { |
|
265 | 265 | return false; |
266 | 266 | } |
267 | 267 | |
268 | - if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) { |
|
268 | + if ($this->theme_supports && ! call_user_func_array('current_theme_supports', (array) $this->theme_supports)) { |
|
269 | 269 | return false; |
270 | 270 | } |
271 | 271 | |
272 | 272 | $access = true; |
273 | 273 | |
274 | - if ( is_callable( $this->capabilities_callback ) ) { |
|
275 | - $access = call_user_func( $this->capabilities_callback, $this ); |
|
274 | + if (is_callable($this->capabilities_callback)) { |
|
275 | + $access = call_user_func($this->capabilities_callback, $this); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | return $access; |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | |
291 | 291 | $this->maybe_render(); |
292 | 292 | |
293 | - $template = trim( ob_get_contents() ); |
|
293 | + $template = trim(ob_get_contents()); |
|
294 | 294 | |
295 | 295 | ob_end_clean(); |
296 | 296 | |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | */ |
305 | 305 | final public function maybe_render() { |
306 | 306 | |
307 | - if ( ! $this->check_capabilities() ) { |
|
307 | + if ( ! $this->check_capabilities()) { |
|
308 | 308 | return; |
309 | 309 | } |
310 | 310 | |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | * |
314 | 314 | * @param WP_Fields_API_Screen $this WP_Fields_API_Screen instance. |
315 | 315 | */ |
316 | - do_action( "fields_api_render_screen_{$this->object_type}", $this ); |
|
316 | + do_action("fields_api_render_screen_{$this->object_type}", $this); |
|
317 | 317 | |
318 | 318 | /** |
319 | 319 | * Fires before rendering a specific Fields API screen. |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | * The dynamic portion of the hook name, `$this->id`, refers to |
322 | 322 | * the ID of the specific Fields API screen to be rendered. |
323 | 323 | */ |
324 | - do_action( "fields_api_render_screen_{$this->object_type}_{$this->object_name}_{$this->id}" ); |
|
324 | + do_action("fields_api_render_screen_{$this->object_type}_{$this->object_name}_{$this->id}"); |
|
325 | 325 | |
326 | 326 | $this->render(); |
327 | 327 | |
@@ -333,12 +333,12 @@ discard block |
||
333 | 333 | * @access protected |
334 | 334 | */ |
335 | 335 | protected function render() { |
336 | - $classes = 'accordion-section control-section control-screen control-screen-' . $this->type; |
|
336 | + $classes = 'accordion-section control-section control-screen control-screen-'.$this->type; |
|
337 | 337 | ?> |
338 | - <li id="accordion-screen-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>"> |
|
338 | + <li id="accordion-screen-<?php echo esc_attr($this->id); ?>" class="<?php echo esc_attr($classes); ?>"> |
|
339 | 339 | <h3 class="accordion-section-title" tabindex="0"> |
340 | - <?php echo esc_html( $this->title ); ?> |
|
341 | - <span class="screen-reader-text"><?php _e( 'Press return or enter to open this screen' ); ?></span> |
|
340 | + <?php echo esc_html($this->title); ?> |
|
341 | + <span class="screen-reader-text"><?php _e('Press return or enter to open this screen'); ?></span> |
|
342 | 342 | </h3> |
343 | 343 | <ul class="accordion-sub-container control-screen-content"> |
344 | 344 | <?php $this->render_content(); ?> |
@@ -401,14 +401,14 @@ discard block |
||
401 | 401 | */ |
402 | 402 | protected function render_content() { |
403 | 403 | ?> |
404 | - <li class="screen-meta accordion-section control-section<?php if ( empty( $this->description ) ) { echo ' cannot-expand'; } ?>"> |
|
404 | + <li class="screen-meta accordion-section control-section<?php if (empty($this->description)) { echo ' cannot-expand'; } ?>"> |
|
405 | 405 | <div class="accordion-section-title" tabindex="0"> |
406 | 406 | <span class="preview-notice"><?php |
407 | 407 | /* translators: %s is the site/screen title in the Fields API */ |
408 | - printf( __( 'You are editing %s' ), '<strong class="screen-title">' . esc_html( $this->title ) . '</strong>' ); |
|
408 | + printf(__('You are editing %s'), '<strong class="screen-title">'.esc_html($this->title).'</strong>'); |
|
409 | 409 | ?></span> |
410 | 410 | </div> |
411 | - <?php if ( ! empty( $this->description ) ) : ?> |
|
411 | + <?php if ( ! empty($this->description)) : ?> |
|
412 | 412 | <div class="accordion-section-content description"> |
413 | 413 | <?php echo $this->description; ?> |
414 | 414 | </div> |
@@ -22,32 +22,32 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * The absolute server path to the fields API directory. |
24 | 24 | */ |
25 | -define( 'WP_FIELDS_API_DIR', plugin_dir_path( __FILE__ ) ); |
|
25 | +define('WP_FIELDS_API_DIR', plugin_dir_path(__FILE__)); |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * On `plugins_loaded`, create an instance of the Fields API manager class. |
29 | 29 | */ |
30 | 30 | function _wp_fields_api_include() { |
31 | 31 | |
32 | - require_once( WP_FIELDS_API_DIR . 'includes/class-wp-fields-api.php' ); |
|
32 | + require_once(WP_FIELDS_API_DIR.'includes/class-wp-fields-api.php'); |
|
33 | 33 | |
34 | 34 | // Init Customize class |
35 | 35 | $GLOBALS['wp_fields'] = new WP_Fields_API; |
36 | 36 | |
37 | 37 | } |
38 | 38 | |
39 | -add_action( 'plugins_loaded', '_wp_fields_api_include', 8 ); |
|
39 | +add_action('plugins_loaded', '_wp_fields_api_include', 8); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Implement Fields API Customizer instead of WP Core Customizer. |
43 | 43 | */ |
44 | 44 | function _wp_fields_api_customize_include() { |
45 | 45 | |
46 | - if ( ! ( ( isset( $_REQUEST['wp_customize'] ) && 'on' == $_REQUEST['wp_customize'] ) || ( is_admin() && 'customize.php' == basename( $_SERVER['PHP_SELF'] ) ) ) ) { |
|
46 | + if ( ! ((isset($_REQUEST['wp_customize']) && 'on' == $_REQUEST['wp_customize']) || (is_admin() && 'customize.php' == basename($_SERVER['PHP_SELF'])))) { |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | - require_once( WP_FIELDS_API_DIR . 'implementation/wp-includes/class-wp-customize-manager.php' ); |
|
50 | + require_once(WP_FIELDS_API_DIR.'implementation/wp-includes/class-wp-customize-manager.php'); |
|
51 | 51 | |
52 | 52 | // Init Customize class |
53 | 53 | $GLOBALS['wp_customize'] = new WP_Customize_Manager; |
@@ -62,16 +62,16 @@ discard block |
||
62 | 62 | */ |
63 | 63 | function _wp_fields_api_user_edit_include() { |
64 | 64 | |
65 | - require_once( WP_FIELDS_API_DIR . 'implementation/user-profile.php' ); |
|
65 | + require_once(WP_FIELDS_API_DIR.'implementation/user-profile.php'); |
|
66 | 66 | |
67 | 67 | return; |
68 | 68 | |
69 | 69 | // Load our overrides |
70 | - require_once( WP_FIELDS_API_DIR . 'implementation/wp-admin/includes/user.php' ); |
|
71 | - require_once( WP_FIELDS_API_DIR . 'implementation/wp-admin/user-edit.php' ); |
|
70 | + require_once(WP_FIELDS_API_DIR.'implementation/wp-admin/includes/user.php'); |
|
71 | + require_once(WP_FIELDS_API_DIR.'implementation/wp-admin/user-edit.php'); |
|
72 | 72 | |
73 | 73 | // Bail on original core file, don't run the rest |
74 | 74 | exit; |
75 | 75 | |
76 | 76 | } |
77 | -add_action( 'load-user-edit.php', '_wp_fields_api_user_edit_include' ); |
|
78 | 77 | \ No newline at end of file |
78 | +add_action('load-user-edit.php', '_wp_fields_api_user_edit_include'); |
|
79 | 79 | \ No newline at end of file |