@@ -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,9 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Bootstrap the plugin unit testing environment. |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Fields API |
|
3 | + * Bootstrap the plugin unit testing environment. |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Fields API |
|
7 | 7 | */ |
8 | 8 | define( 'WP_TESTS_FORCE_KNOWN_BUGS', true ); |
9 | 9 |
@@ -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 | /** |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * WordPress Fields API Screen classes |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Fields_API |
|
7 | - */ |
|
3 | + * WordPress Fields API Screen classes |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Fields_API |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Fields API Screen class. |
@@ -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> |
@@ -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; |
@@ -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 |
@@ -182,8 +182,6 @@ discard block |
||
182 | 182 | * Check user capabilities and theme supports, and then save |
183 | 183 | * the value of the field. |
184 | 184 | * |
185 | - * @param mixed $value The value to save. |
|
186 | - * @param int $item_id The Item ID. |
|
187 | 185 | * |
188 | 186 | * @return false|mixed False if cap check fails or value isn't set. |
189 | 187 | */ |
@@ -243,7 +241,6 @@ discard block |
||
243 | 241 | * Save the value of the field, using the related API. |
244 | 242 | * |
245 | 243 | * @param mixed $value The value to update. |
246 | - * @param int $item_id Item ID. |
|
247 | 244 | * |
248 | 245 | * @return mixed The result of saving the value. |
249 | 246 | */ |
@@ -383,7 +380,6 @@ discard block |
||
383 | 380 | /** |
384 | 381 | * Fetch the value of the field. |
385 | 382 | * |
386 | - * @param int $item_id (optional) The Item ID. |
|
387 | 383 | * |
388 | 384 | * @return mixed The value. |
389 | 385 | */ |
@@ -655,7 +651,7 @@ discard block |
||
655 | 651 | * |
656 | 652 | * @param $root |
657 | 653 | * @param $keys |
658 | - * @param mixed $default A default value which is used as a fallback. Default is null. |
|
654 | + * @param string $default A default value which is used as a fallback. Default is null. |
|
659 | 655 | * |
660 | 656 | * @return mixed The requested value or the default value. |
661 | 657 | */ |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | |
112 | 112 | $args = func_get_args(); |
113 | 113 | |
114 | - call_user_func_array( array( $this, 'init' ), $args ); |
|
114 | + call_user_func_array(array($this, 'init'), $args); |
|
115 | 115 | |
116 | 116 | } |
117 | 117 | |
@@ -125,11 +125,11 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @return WP_Fields_API_Field $field |
127 | 127 | */ |
128 | - public function init( $object_type, $id, $args = array() ) { |
|
128 | + public function init($object_type, $id, $args = array()) { |
|
129 | 129 | |
130 | 130 | $this->object_type = $object_type; |
131 | 131 | |
132 | - if ( is_array( $id ) ) { |
|
132 | + if (is_array($id)) { |
|
133 | 133 | $args = $id; |
134 | 134 | |
135 | 135 | $id = ''; |
@@ -137,31 +137,31 @@ discard block |
||
137 | 137 | $this->id = $id; |
138 | 138 | } |
139 | 139 | |
140 | - $keys = array_keys( get_object_vars( $this ) ); |
|
140 | + $keys = array_keys(get_object_vars($this)); |
|
141 | 141 | |
142 | - foreach ( $keys as $key ) { |
|
143 | - if ( isset( $args[ $key ] ) ) { |
|
144 | - $this->$key = $args[ $key ]; |
|
142 | + foreach ($keys as $key) { |
|
143 | + if (isset($args[$key])) { |
|
144 | + $this->$key = $args[$key]; |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
148 | 148 | // Parse the ID for array keys. |
149 | - $this->id_data['keys'] = preg_split( '/\[/', str_replace( ']', '', $this->id ) ); |
|
150 | - $this->id_data['base'] = array_shift( $this->id_data['keys'] ); |
|
149 | + $this->id_data['keys'] = preg_split('/\[/', str_replace(']', '', $this->id)); |
|
150 | + $this->id_data['base'] = array_shift($this->id_data['keys']); |
|
151 | 151 | |
152 | 152 | // Rebuild the ID. |
153 | 153 | $this->id = $this->id_data['base']; |
154 | 154 | |
155 | - if ( ! empty( $this->id_data['keys'] ) ) { |
|
156 | - $this->id .= '[' . implode( '][', $this->id_data['keys'] ) . ']'; |
|
155 | + if ( ! empty($this->id_data['keys'])) { |
|
156 | + $this->id .= '['.implode('][', $this->id_data['keys']).']'; |
|
157 | 157 | } |
158 | 158 | |
159 | - if ( $this->sanitize_callback ) { |
|
160 | - add_filter( "fields_sanitize_{$this->object_type}_{$this->object_name}_{$this->id}", $this->sanitize_callback, 10, 2 ); |
|
159 | + if ($this->sanitize_callback) { |
|
160 | + add_filter("fields_sanitize_{$this->object_type}_{$this->object_name}_{$this->id}", $this->sanitize_callback, 10, 2); |
|
161 | 161 | } |
162 | 162 | |
163 | - if ( $this->sanitize_js_callback ) { |
|
164 | - add_filter( "fields_sanitize_js_{$this->object_type}_{$this->object_name}_{$this->id}", $this->sanitize_js_callback, 10, 2 ); |
|
163 | + if ($this->sanitize_js_callback) { |
|
164 | + add_filter("fields_sanitize_js_{$this->object_type}_{$this->object_name}_{$this->id}", $this->sanitize_js_callback, 10, 2); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | } |
@@ -180,11 +180,11 @@ discard block |
||
180 | 180 | $value = func_get_arg(0); |
181 | 181 | $item_id = func_get_arg(1); |
182 | 182 | |
183 | - if ( ! $this->check_capabilities() || false === $value ) { |
|
183 | + if ( ! $this->check_capabilities() || false === $value) { |
|
184 | 184 | return false; |
185 | 185 | } |
186 | 186 | |
187 | - $value = $this->sanitize( $value ); |
|
187 | + $value = $this->sanitize($value); |
|
188 | 188 | |
189 | 189 | /** |
190 | 190 | * Fires when the WP_Fields_API_Field::save() method is called. |
@@ -198,9 +198,9 @@ discard block |
||
198 | 198 | * |
199 | 199 | * @return string The value to save |
200 | 200 | */ |
201 | - $value = apply_filters( 'field_save_' . $this->object_type . '_' . $this->id_data[ 'base' ], $value, $item_id, $this ); |
|
201 | + $value = apply_filters('field_save_'.$this->object_type.'_'.$this->id_data['base'], $value, $item_id, $this); |
|
202 | 202 | |
203 | - return $this->update( $value, $item_id ); |
|
203 | + return $this->update($value, $item_id); |
|
204 | 204 | |
205 | 205 | } |
206 | 206 | |
@@ -211,9 +211,9 @@ discard block |
||
211 | 211 | * |
212 | 212 | * @return mixed Null if an input isn't valid, otherwise the sanitized value. |
213 | 213 | */ |
214 | - public function sanitize( $value ) { |
|
214 | + public function sanitize($value) { |
|
215 | 215 | |
216 | - $value = wp_unslash( $value ); |
|
216 | + $value = wp_unslash($value); |
|
217 | 217 | |
218 | 218 | /** |
219 | 219 | * Filter a Customize field value in un-slashed form. |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * @param mixed $value Value of the field. |
222 | 222 | * @param WP_Fields_API_Field $this WP_Fields_API_Field instance. |
223 | 223 | */ |
224 | - return apply_filters( "fields_sanitize_{$this->object_type}_{$this->object_name}_{$this->id}", $value, $this ); |
|
224 | + return apply_filters("fields_sanitize_{$this->object_type}_{$this->object_name}_{$this->id}", $value, $this); |
|
225 | 225 | |
226 | 226 | } |
227 | 227 | |
@@ -233,27 +233,27 @@ discard block |
||
233 | 233 | * |
234 | 234 | * @return mixed The result of saving the value. |
235 | 235 | */ |
236 | - protected function update( $value ) { |
|
236 | + protected function update($value) { |
|
237 | 237 | |
238 | 238 | // @todo Support post / term / user / comment object field updates |
239 | 239 | |
240 | 240 | $item_id = func_get_arg(1); |
241 | 241 | |
242 | - switch ( $this->object_type ) { |
|
243 | - case is_callable( $this->update_value_callback ) : |
|
244 | - return call_user_func( $this->update_value_callback, $value, $item_id, $this ); |
|
242 | + switch ($this->object_type) { |
|
243 | + case is_callable($this->update_value_callback) : |
|
244 | + return call_user_func($this->update_value_callback, $value, $item_id, $this); |
|
245 | 245 | |
246 | 246 | case 'customizer' : |
247 | - return $this->_update_theme_mod( $value ); |
|
247 | + return $this->_update_theme_mod($value); |
|
248 | 248 | |
249 | 249 | case 'settings' : |
250 | - return $this->_update_option( $value ); |
|
250 | + return $this->_update_option($value); |
|
251 | 251 | |
252 | 252 | case 'post' : |
253 | 253 | case 'term' : |
254 | 254 | case 'user' : |
255 | 255 | case 'comment' : |
256 | - return $this->_update_meta( $this->object_type, $value, $item_id ); |
|
256 | + return $this->_update_meta($this->object_type, $value, $item_id); |
|
257 | 257 | |
258 | 258 | default : |
259 | 259 | |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * @param int $item_id Item ID. |
268 | 268 | * @param WP_Fields_API_Field $this WP_Fields_API_Field instance. |
269 | 269 | */ |
270 | - do_action( "fields_update_{$this->object_type}", $value, $item_id, $this ); |
|
270 | + do_action("fields_update_{$this->object_type}", $value, $item_id, $this); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | return null; |
@@ -281,22 +281,22 @@ discard block |
||
281 | 281 | * |
282 | 282 | * @return null |
283 | 283 | */ |
284 | - protected function _update_theme_mod( $value ) { |
|
284 | + protected function _update_theme_mod($value) { |
|
285 | 285 | |
286 | - if ( is_null( $value ) ) { |
|
287 | - remove_theme_mod( $this->id_data['base'] ); |
|
286 | + if (is_null($value)) { |
|
287 | + remove_theme_mod($this->id_data['base']); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | // Handle non-array theme mod. |
291 | - if ( empty( $this->id_data['keys'] ) ) { |
|
292 | - set_theme_mod( $this->id_data['base'], $value ); |
|
291 | + if (empty($this->id_data['keys'])) { |
|
292 | + set_theme_mod($this->id_data['base'], $value); |
|
293 | 293 | } else { |
294 | 294 | // Handle array-based theme mod. |
295 | - $mods = get_theme_mod( $this->id_data['base'] ); |
|
296 | - $mods = $this->multidimensional_replace( $mods, $this->id_data['keys'], $value ); |
|
295 | + $mods = get_theme_mod($this->id_data['base']); |
|
296 | + $mods = $this->multidimensional_replace($mods, $this->id_data['keys'], $value); |
|
297 | 297 | |
298 | - if ( isset( $mods ) ) { |
|
299 | - set_theme_mod( $this->id_data['base'], $mods ); |
|
298 | + if (isset($mods)) { |
|
299 | + set_theme_mod($this->id_data['base'], $mods); |
|
300 | 300 | } |
301 | 301 | } |
302 | 302 | |
@@ -311,23 +311,23 @@ discard block |
||
311 | 311 | * |
312 | 312 | * @return bool|null The result of saving the value. |
313 | 313 | */ |
314 | - protected function _update_option( $value ) { |
|
314 | + protected function _update_option($value) { |
|
315 | 315 | |
316 | - if ( is_null( $value ) ) { |
|
317 | - delete_option( $this->id_data['base'] ); |
|
316 | + if (is_null($value)) { |
|
317 | + delete_option($this->id_data['base']); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | // Handle non-array option. |
321 | - if ( empty( $this->id_data['keys'] ) ) { |
|
322 | - return update_option( $this->id_data['base'], $value ); |
|
321 | + if (empty($this->id_data['keys'])) { |
|
322 | + return update_option($this->id_data['base'], $value); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | // Handle array-based options. |
326 | - $options = get_option( $this->id_data['base'] ); |
|
327 | - $options = $this->multidimensional_replace( $options, $this->id_data['keys'], $value ); |
|
326 | + $options = get_option($this->id_data['base']); |
|
327 | + $options = $this->multidimensional_replace($options, $this->id_data['keys'], $value); |
|
328 | 328 | |
329 | - if ( isset( $options ) ) { |
|
330 | - return update_option( $this->id_data['base'], $options ); |
|
329 | + if (isset($options)) { |
|
330 | + return update_option($this->id_data['base'], $options); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | return null; |
@@ -343,23 +343,23 @@ discard block |
||
343 | 343 | * |
344 | 344 | * @return bool|null The result of saving the value. |
345 | 345 | */ |
346 | - protected function _update_meta( $meta_type, $value, $item_id = 0 ) { |
|
346 | + protected function _update_meta($meta_type, $value, $item_id = 0) { |
|
347 | 347 | |
348 | - if ( is_null( $value ) ) { |
|
349 | - delete_metadata( $meta_type, $item_id, $this->id_data['base'] ); |
|
348 | + if (is_null($value)) { |
|
349 | + delete_metadata($meta_type, $item_id, $this->id_data['base']); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | // Handle non-array option. |
353 | - if ( empty( $this->id_data['keys'] ) ) { |
|
354 | - return update_metadata( $meta_type, $item_id, $this->id_data['base'], $value ); |
|
353 | + if (empty($this->id_data['keys'])) { |
|
354 | + return update_metadata($meta_type, $item_id, $this->id_data['base'], $value); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | // Handle array-based keys. |
358 | - $keys = get_metadata( $meta_type, 0, $this->id_data['base'] ); |
|
359 | - $keys = $this->multidimensional_replace( $keys, $this->id_data['keys'], $value ); |
|
358 | + $keys = get_metadata($meta_type, 0, $this->id_data['base']); |
|
359 | + $keys = $this->multidimensional_replace($keys, $this->id_data['keys'], $value); |
|
360 | 360 | |
361 | - if ( isset( $keys ) ) { |
|
362 | - return update_metadata( $meta_type, $item_id, $this->id_data['base'], $keys ); |
|
361 | + if (isset($keys)) { |
|
362 | + return update_metadata($meta_type, $item_id, $this->id_data['base'], $keys); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | return null; |
@@ -377,24 +377,24 @@ discard block |
||
377 | 377 | |
378 | 378 | $item_id = func_get_arg(0); |
379 | 379 | |
380 | - switch ( $this->object_type ) { |
|
381 | - case is_callable( $this->value_callback ) : |
|
382 | - $value = call_user_func( $this->value_callback, $item_id, $this ); |
|
383 | - $value = $this->multidimensional_get( $value, $this->id_data['keys'], $this->default ); |
|
380 | + switch ($this->object_type) { |
|
381 | + case is_callable($this->value_callback) : |
|
382 | + $value = call_user_func($this->value_callback, $item_id, $this); |
|
383 | + $value = $this->multidimensional_get($value, $this->id_data['keys'], $this->default); |
|
384 | 384 | |
385 | 385 | break; |
386 | 386 | case 'post' : |
387 | 387 | case 'term' : |
388 | 388 | case 'user' : |
389 | 389 | case 'comment' : |
390 | - $value = $this->get_object_value( $item_id ); |
|
391 | - $value = $this->multidimensional_get( $value, $this->id_data['keys'], $this->default ); |
|
390 | + $value = $this->get_object_value($item_id); |
|
391 | + $value = $this->multidimensional_get($value, $this->id_data['keys'], $this->default); |
|
392 | 392 | break; |
393 | 393 | |
394 | 394 | case 'customizer' : |
395 | 395 | case 'settings' : |
396 | 396 | $value = $this->get_option_value(); |
397 | - $value = $this->multidimensional_get( $value, $this->id_data['keys'], $this->default ); |
|
397 | + $value = $this->multidimensional_get($value, $this->id_data['keys'], $this->default); |
|
398 | 398 | break; |
399 | 399 | |
400 | 400 | default : |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | * @param mixed $default The field default value. Default empty. |
411 | 411 | * @param int $item_id (optional) The Item ID. |
412 | 412 | */ |
413 | - $value = apply_filters( 'fields_value_' . $this->object_type . '_' . $this->object_name . '_' . $this->id_data['base'], $this->default, $item_id ); |
|
413 | + $value = apply_filters('fields_value_'.$this->object_type.'_'.$this->object_name.'_'.$this->id_data['base'], $this->default, $item_id); |
|
414 | 414 | break; |
415 | 415 | } |
416 | 416 | |
@@ -425,39 +425,39 @@ discard block |
||
425 | 425 | * |
426 | 426 | * @return mixed|null |
427 | 427 | */ |
428 | - public function get_object_value( $item_id ) { |
|
428 | + public function get_object_value($item_id) { |
|
429 | 429 | |
430 | 430 | $value = null; |
431 | 431 | $object = null; |
432 | 432 | |
433 | 433 | $field_key = $this->id_data['base']; |
434 | 434 | |
435 | - switch ( $this->object_type ) { |
|
435 | + switch ($this->object_type) { |
|
436 | 436 | case 'post' : |
437 | - $object = get_post( $item_id ); |
|
437 | + $object = get_post($item_id); |
|
438 | 438 | break; |
439 | 439 | |
440 | 440 | case 'term' : |
441 | - $object = get_term( $item_id ); |
|
441 | + $object = get_term($item_id); |
|
442 | 442 | break; |
443 | 443 | |
444 | 444 | case 'user' : |
445 | - $object = get_userdata( $item_id ); |
|
445 | + $object = get_userdata($item_id); |
|
446 | 446 | break; |
447 | 447 | |
448 | 448 | case 'comment' : |
449 | - $object = get_comment( $item_id ); |
|
449 | + $object = get_comment($item_id); |
|
450 | 450 | break; |
451 | 451 | } |
452 | 452 | |
453 | - if ( $object && ! is_wp_error( $object ) && isset( $object->{$field_key} ) ) { |
|
453 | + if ($object && ! is_wp_error($object) && isset($object->{$field_key} )) { |
|
454 | 454 | // Get value from object |
455 | 455 | $value = $object->{$field_key}; |
456 | 456 | } else { |
457 | 457 | // Get value from meta |
458 | - $value = get_metadata( $this->object_type, $item_id, $field_key ); |
|
458 | + $value = get_metadata($this->object_type, $item_id, $field_key); |
|
459 | 459 | |
460 | - if ( array() === $value ) { |
|
460 | + if (array() === $value) { |
|
461 | 461 | $value = $this->default; |
462 | 462 | } |
463 | 463 | } |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | $function = ''; |
477 | 477 | $value = null; |
478 | 478 | |
479 | - switch ( $this->object_type ) { |
|
479 | + switch ($this->object_type) { |
|
480 | 480 | case 'customizer' : |
481 | 481 | $function = 'get_theme_mod'; |
482 | 482 | break; |
@@ -486,14 +486,14 @@ discard block |
||
486 | 486 | break; |
487 | 487 | } |
488 | 488 | |
489 | - if ( is_callable( $function ) ) { |
|
489 | + if (is_callable($function)) { |
|
490 | 490 | // Handle non-array value |
491 | - if ( empty( $this->id_data['keys'] ) ) { |
|
492 | - return $function( $this->id_data['base'], $this->default ); |
|
491 | + if (empty($this->id_data['keys'])) { |
|
492 | + return $function($this->id_data['base'], $this->default); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | // Handle array-based value |
496 | - $value = $function( $this->id_data['base'] ); |
|
496 | + $value = $function($this->id_data['base']); |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | return $value; |
@@ -517,10 +517,10 @@ discard block |
||
517 | 517 | * @param mixed $value The field value. |
518 | 518 | * @param WP_Fields_API_Field $this {@see WP_Fields_API_Field} instance. |
519 | 519 | */ |
520 | - $value = apply_filters( "fields_sanitize_js_{$this->object_type}_{$this->object_name}_{$this->id}", $value, $this ); |
|
520 | + $value = apply_filters("fields_sanitize_js_{$this->object_type}_{$this->object_name}_{$this->id}", $value, $this); |
|
521 | 521 | |
522 | - if ( is_string( $value ) ) { |
|
523 | - return html_entity_decode( $value, ENT_QUOTES, 'UTF-8' ); |
|
522 | + if (is_string($value)) { |
|
523 | + return html_entity_decode($value, ENT_QUOTES, 'UTF-8'); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | return $value; |
@@ -534,18 +534,18 @@ discard block |
||
534 | 534 | */ |
535 | 535 | public function check_capabilities() { |
536 | 536 | |
537 | - if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) ) { |
|
537 | + if ($this->capability && ! call_user_func_array('current_user_can', (array) $this->capability)) { |
|
538 | 538 | return false; |
539 | 539 | } |
540 | 540 | |
541 | - if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) ) { |
|
541 | + if ($this->theme_supports && ! call_user_func_array('current_theme_supports', (array) $this->theme_supports)) { |
|
542 | 542 | return false; |
543 | 543 | } |
544 | 544 | |
545 | 545 | $access = true; |
546 | 546 | |
547 | - if ( is_callable( $this->capabilities_callback ) ) { |
|
548 | - $access = call_user_func( $this->capabilities_callback, $this ); |
|
547 | + if (is_callable($this->capabilities_callback)) { |
|
548 | + $access = call_user_func($this->capabilities_callback, $this); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | return $access; |
@@ -561,42 +561,42 @@ discard block |
||
561 | 561 | * |
562 | 562 | * @return null|array Keys are 'root', 'node', and 'key'. |
563 | 563 | */ |
564 | - final protected function multidimensional( &$root, $keys, $create = false ) { |
|
564 | + final protected function multidimensional(&$root, $keys, $create = false) { |
|
565 | 565 | |
566 | - if ( $create && empty( $root ) ) { |
|
566 | + if ($create && empty($root)) { |
|
567 | 567 | $root = array(); |
568 | 568 | } |
569 | 569 | |
570 | - if ( ! isset( $root ) || empty( $keys ) ) { |
|
570 | + if ( ! isset($root) || empty($keys)) { |
|
571 | 571 | return null; |
572 | 572 | } |
573 | 573 | |
574 | - $last = array_pop( $keys ); |
|
574 | + $last = array_pop($keys); |
|
575 | 575 | $node = &$root; |
576 | 576 | |
577 | - foreach ( $keys as $key ) { |
|
578 | - if ( $create && ! isset( $node[ $key ] ) ) { |
|
579 | - $node[ $key ] = array(); |
|
577 | + foreach ($keys as $key) { |
|
578 | + if ($create && ! isset($node[$key])) { |
|
579 | + $node[$key] = array(); |
|
580 | 580 | } |
581 | 581 | |
582 | - if ( ! is_array( $node ) || ! isset( $node[ $key ] ) ) { |
|
582 | + if ( ! is_array($node) || ! isset($node[$key])) { |
|
583 | 583 | return null; |
584 | 584 | } |
585 | 585 | |
586 | - $node = &$node[ $key ]; |
|
586 | + $node = &$node[$key]; |
|
587 | 587 | } |
588 | 588 | |
589 | - if ( $create ) { |
|
590 | - if ( ! is_array( $node ) ) { |
|
589 | + if ($create) { |
|
590 | + if ( ! is_array($node)) { |
|
591 | 591 | // account for an array overriding a string or object value |
592 | 592 | $node = array(); |
593 | 593 | } |
594 | - if ( ! isset( $node[ $last ] ) ) { |
|
595 | - $node[ $last ] = array(); |
|
594 | + if ( ! isset($node[$last])) { |
|
595 | + $node[$last] = array(); |
|
596 | 596 | } |
597 | 597 | } |
598 | 598 | |
599 | - if ( ! isset( $node[ $last ] ) ) { |
|
599 | + if ( ! isset($node[$last])) { |
|
600 | 600 | return null; |
601 | 601 | } |
602 | 602 | |
@@ -617,19 +617,19 @@ discard block |
||
617 | 617 | * |
618 | 618 | * @return |
619 | 619 | */ |
620 | - final protected function multidimensional_replace( $root, $keys, $value ) { |
|
620 | + final protected function multidimensional_replace($root, $keys, $value) { |
|
621 | 621 | |
622 | - if ( ! isset( $value ) ) { |
|
622 | + if ( ! isset($value)) { |
|
623 | 623 | return $root; |
624 | - } elseif ( empty( $keys ) ) { |
|
624 | + } elseif (empty($keys)) { |
|
625 | 625 | // If there are no keys, we're replacing the root. |
626 | 626 | return $value; |
627 | 627 | } |
628 | 628 | |
629 | - $result = $this->multidimensional( $root, $keys, true ); |
|
629 | + $result = $this->multidimensional($root, $keys, true); |
|
630 | 630 | |
631 | - if ( isset( $result ) ) { |
|
632 | - $result['node'][ $result['key'] ] = $value; |
|
631 | + if (isset($result)) { |
|
632 | + $result['node'][$result['key']] = $value; |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | return $root; |
@@ -645,18 +645,18 @@ discard block |
||
645 | 645 | * |
646 | 646 | * @return mixed The requested value or the default value. |
647 | 647 | */ |
648 | - final protected function multidimensional_get( $root, $keys, $default = null ) { |
|
648 | + final protected function multidimensional_get($root, $keys, $default = null) { |
|
649 | 649 | |
650 | 650 | // If there are no keys, test the root. |
651 | - if ( empty( $keys ) ) { |
|
652 | - if ( isset( $root ) ) { |
|
651 | + if (empty($keys)) { |
|
652 | + if (isset($root)) { |
|
653 | 653 | return $root; |
654 | 654 | } |
655 | 655 | } else { |
656 | - $result = $this->multidimensional( $root, $keys ); |
|
656 | + $result = $this->multidimensional($root, $keys); |
|
657 | 657 | |
658 | - if ( isset( $result ) ) { |
|
659 | - return $result['node'][ $result['key'] ]; |
|
658 | + if (isset($result)) { |
|
659 | + return $result['node'][$result['key']]; |
|
660 | 660 | } |
661 | 661 | } |
662 | 662 | |
@@ -672,11 +672,11 @@ discard block |
||
672 | 672 | * |
673 | 673 | * @return bool True if value is set, false if not. |
674 | 674 | */ |
675 | - final protected function multidimensional_isset( $root, $keys ) { |
|
675 | + final protected function multidimensional_isset($root, $keys) { |
|
676 | 676 | |
677 | - $result = $this->multidimensional_get( $root, $keys ); |
|
677 | + $result = $this->multidimensional_get($root, $keys); |
|
678 | 678 | |
679 | - return isset( $result ); |
|
679 | + return isset($result); |
|
680 | 680 | |
681 | 681 | } |
682 | 682 | } |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | * |
699 | 699 | * @return mixed The result of saving the value. |
700 | 700 | */ |
701 | - public function update( $value ) { |
|
701 | + public function update($value) { |
|
702 | 702 | |
703 | 703 | return null; |
704 | 704 |