@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if( !function_exists( 'pollux_app' )) { |
|
3 | +if( !function_exists( 'pollux_app' ) ) { |
|
4 | 4 | function pollux_app() { |
5 | 5 | return GeminiLabs\Pollux\Application::getInstance(); |
6 | 6 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | * Compatibility with Give WP plugin |
5 | 5 | */ |
6 | 6 | add_filter( 'give_load_admin_scripts', function( $is_admin_page, $hook ) { |
7 | - $needle = sprintf( '_page_%s', filter_input( INPUT_GET, 'page' )); |
|
8 | - return substr( $hook, - strlen( $needle )) !== $needle |
|
7 | + $needle = sprintf( '_page_%s', filter_input( INPUT_GET, 'page' ) ); |
|
8 | + return substr( $hook, - strlen( $needle ) ) !== $needle |
|
9 | 9 | ? $is_admin_page |
10 | 10 | : true; |
11 | 11 | }, 10, 2 ); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | $this->versions = wp_parse_args( $versions, array( |
31 | 31 | 'php' => static::MIN_PHP_VERSION, |
32 | 32 | 'wordpress' => static::MIN_WORDPRESS_VERSION, |
33 | - )); |
|
33 | + ) ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | if( $this->isValid() ) { |
42 | 42 | return true; |
43 | 43 | } |
44 | - add_action( 'activated_plugin', array( $this, 'deactivate' )); |
|
45 | - add_action( 'admin_notices', array( $this, 'deactivate' )); |
|
44 | + add_action( 'activated_plugin', array( $this, 'deactivate' ) ); |
|
45 | + add_action( 'admin_notices', array( $this, 'deactivate' ) ); |
|
46 | 46 | return false; |
47 | 47 | } |
48 | 48 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | filter_input( INPUT_GET, 'plugin_status' ), |
138 | 138 | filter_input( INPUT_GET, 'paged' ), |
139 | 139 | filter_input( INPUT_GET, 's' ) |
140 | - ))); |
|
140 | + ) ) ); |
|
141 | 141 | exit; |
142 | 142 | } |
143 | 143 | } |
@@ -38,8 +38,8 @@ |
||
38 | 38 | { |
39 | 39 | $data = wp_parse_args( $data, $defaults ); |
40 | 40 | foreach( $defaults as $key => $value ) { |
41 | - $method = ( new Helper )->buildMethodName( $key, 'normalize' ); |
|
42 | - if( method_exists( $this, $method )) { |
|
41 | + $method = (new Helper)->buildMethodName( $key, 'normalize' ); |
|
42 | + if( method_exists( $this, $method ) ) { |
|
43 | 43 | $data[$key] = $this->$method( $data[$key], $data, $id ); |
44 | 44 | } |
45 | 45 | } |
@@ -18,16 +18,16 @@ discard block |
||
18 | 18 | */ |
19 | 19 | public function get( $metaKey, array $args = [] ) |
20 | 20 | { |
21 | - if( empty( $metaKey ))return; |
|
21 | + if( empty($metaKey) )return; |
|
22 | 22 | |
23 | 23 | $args = $this->normalize( $args ); |
24 | 24 | $metaKey = $this->buildMetaKey( $metaKey, $args['prefix'] ); |
25 | 25 | $metaValue = get_post_meta( $args['id'], $metaKey, $args['single'] ); |
26 | 26 | |
27 | - if( is_string( $metaValue )) { |
|
27 | + if( is_string( $metaValue ) ) { |
|
28 | 28 | $metaValue = trim( $metaValue ); |
29 | 29 | } |
30 | - return empty( $metaValue ) |
|
30 | + return empty($metaValue) |
|
31 | 31 | ? $args['fallback'] |
32 | 32 | : $metaValue; |
33 | 33 | } |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | */ |
40 | 40 | protected function buildMetaKey( $metaKey, $prefix ) |
41 | 41 | { |
42 | - return ( substr( $metaKey, 0, 1 ) == '_' && !empty( $prefix )) |
|
42 | + return (substr( $metaKey, 0, 1 ) == '_' && !empty($prefix)) |
|
43 | 43 | ? sprintf( '_%s%s', rtrim( $prefix, '_' ), $metaKey ) |
44 | - : $prefix . $metaKey; |
|
44 | + : $prefix.$metaKey; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -55,6 +55,6 @@ discard block |
||
55 | 55 | 'single' => true, |
56 | 56 | 'prefix' => Application::prefix(), |
57 | 57 | ]; |
58 | - return shortcode_atts( $defaults, array_change_key_case( $args )); |
|
58 | + return shortcode_atts( $defaults, array_change_key_case( $args ) ); |
|
59 | 59 | } |
60 | 60 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | public function validate( array $conditions ) |
30 | 30 | { |
31 | 31 | array_walk( $conditions, function( &$value, $key ) { |
32 | - $method = ( new Helper )->buildMethodName( $key, 'validate' ); |
|
32 | + $method = (new Helper)->buildMethodName( $key, 'validate' ); |
|
33 | 33 | $value = method_exists( $this, $method ) |
34 | 34 | ? $this->$method( $value ) |
35 | 35 | : $this->validateUnknown( $key, $value ); |
@@ -43,10 +43,10 @@ discard block |
||
43 | 43 | */ |
44 | 44 | protected function normalizeCondition( $conditions ) |
45 | 45 | { |
46 | - if( !is_array( $conditions )) { |
|
46 | + if( !is_array( $conditions ) ) { |
|
47 | 47 | $conditions = []; |
48 | 48 | } |
49 | - if( count( array_filter( array_keys( $conditions ), 'is_string' )) == 0 ) { |
|
49 | + if( count( array_filter( array_keys( $conditions ), 'is_string' ) ) == 0 ) { |
|
50 | 50 | foreach( $conditions as $key ) { |
51 | 51 | $conditions[str_replace( '!', '', $key )] = substr( $key, 0, 1 ) == '!' ? 0 : 1; |
52 | 52 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | } |
57 | 57 | return array_intersect_key( |
58 | 58 | $conditions, |
59 | - array_flip( $this->filter( 'conditions', static::conditions() )) |
|
59 | + array_flip( $this->filter( 'conditions', static::conditions() ) ) |
|
60 | 60 | ); |
61 | 61 | } |
62 | 62 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | protected function validateIsFrontPage( $value ) |
104 | 104 | { |
105 | - return $value == ( $this->getPostId() == get_option( 'page_on_front' )); |
|
105 | + return $value == ($this->getPostId() == get_option( 'page_on_front' )); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | protected function validateIsHome( $value ) |
113 | 113 | { |
114 | - return $value == ( $this->getPostId() == get_option( 'page_for_posts' )); |
|
114 | + return $value == ($this->getPostId() == get_option( 'page_for_posts' )); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | */ |
121 | 121 | protected function validateIsPageTemplate( $value ) |
122 | 122 | { |
123 | - return ( new Helper )->endsWith( |
|
123 | + return (new Helper)->endsWith( |
|
124 | 124 | $value, |
125 | - basename( get_page_template_slug( $this->getPostId() )) |
|
125 | + basename( get_page_template_slug( $this->getPostId() ) ) |
|
126 | 126 | ); |
127 | 127 | } |
128 | 128 |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | { |
31 | 31 | $args = array_pad( $args, 2, null ); |
32 | 32 | $group = $this->$group; |
33 | - if( is_object( $group )) { |
|
33 | + if( is_object( $group ) ) { |
|
34 | 34 | return $group; |
35 | 35 | } |
36 | 36 | return $this->get( $group, $args[0], $args[1] ); |
@@ -43,15 +43,15 @@ discard block |
||
43 | 43 | public function __get( $group ) |
44 | 44 | { |
45 | 45 | if( $group == 'all' ) { |
46 | - return (object) $this->options; |
|
46 | + return (object)$this->options; |
|
47 | 47 | } |
48 | - if( empty( $group )) { |
|
48 | + if( empty($group) ) { |
|
49 | 49 | $group = $this->getDefaultGroup(); |
50 | 50 | } |
51 | - if( is_array( $group )) { |
|
51 | + if( is_array( $group ) ) { |
|
52 | 52 | $group = reset( $group ); |
53 | 53 | } |
54 | - return isset( $this->options[$group] ) |
|
54 | + return isset($this->options[$group]) |
|
55 | 55 | ? $this->options[$group] |
56 | 56 | : null; |
57 | 57 | } |
@@ -67,13 +67,13 @@ discard block |
||
67 | 67 | if( func_num_args() < 1 ) { |
68 | 68 | return $this->all; |
69 | 69 | } |
70 | - if( is_string( $group )) { |
|
70 | + if( is_string( $group ) ) { |
|
71 | 71 | $group = $this->$group; |
72 | 72 | } |
73 | - if( !is_array( $group )) { |
|
73 | + if( !is_array( $group ) ) { |
|
74 | 74 | return $fallback; |
75 | 75 | } |
76 | - if( is_null( $key )) { |
|
76 | + if( is_null( $key ) ) { |
|
77 | 77 | return $group; |
78 | 78 | } |
79 | 79 | return $this->getValue( $group, $key, $fallback ); |
@@ -94,10 +94,10 @@ discard block |
||
94 | 94 | */ |
95 | 95 | protected function getValue( array $group, $key, $fallback ) |
96 | 96 | { |
97 | - if( !array_key_exists( $key, $group )) { |
|
97 | + if( !array_key_exists( $key, $group ) ) { |
|
98 | 98 | return $fallback; |
99 | 99 | } |
100 | - return empty( $group[$key] ) && !is_null( $fallback ) |
|
100 | + return empty($group[$key]) && !is_null( $fallback ) |
|
101 | 101 | ? $fallback |
102 | 102 | : $group[$key]; |
103 | 103 | } |
@@ -22,15 +22,15 @@ discard block |
||
22 | 22 | { |
23 | 23 | $instructions = array_reduce( $this->getInstructionGroups(), function( $html, $metabox ) { |
24 | 24 | $fields = $this->getInstructionFields( $metabox ); |
25 | - if( empty( $fields )) { |
|
25 | + if( empty($fields) ) { |
|
26 | 26 | return $html; |
27 | 27 | } |
28 | - return $html . sprintf( '<p><strong>%s</strong></p><pre class="my-sites nav-tab-active misc-pub-section">%s</pre>', |
|
28 | + return $html.sprintf( '<p><strong>%s</strong></p><pre class="my-sites nav-tab-active misc-pub-section">%s</pre>', |
|
29 | 29 | $metabox['title'], |
30 | 30 | $fields |
31 | 31 | ); |
32 | 32 | }); |
33 | - return $this->filter( 'before/instructions', '' ) . $instructions . $this->filter( 'after/instructions', '' ); |
|
33 | + return $this->filter( 'before/instructions', '' ).$instructions.$this->filter( 'after/instructions', '' ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | protected function getInstructionFields( $metabox ) |
40 | 40 | { |
41 | 41 | $skipFields = ['custom_html', 'divider', 'heading', 'taxonomy']; |
42 | - return array_reduce( $metabox['fields'], function( $html, $field ) use( $metabox, $skipFields ) { |
|
42 | + return array_reduce( $metabox['fields'], function( $html, $field ) use($metabox, $skipFields) { |
|
43 | 43 | return $this->validate( $field['condition'] ) && !in_array( $field['type'], $skipFields ) |
44 | - ? $html . $this->filter( 'instruction', "PostMeta::get('{$field['slug']}');", $field, $metabox ) . PHP_EOL |
|
44 | + ? $html.$this->filter( 'instruction', "PostMeta::get('{$field['slug']}');", $field, $metabox ).PHP_EOL |
|
45 | 45 | : $html; |
46 | 46 | }); |
47 | 47 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | { |
86 | 86 | return $this->filter( 'show/instructions', count( array_filter( $this->metaboxes, function( $metabox ) { |
87 | 87 | return $this->show( false, $metabox ); |
88 | - })) > 0 ); |
|
88 | + }) ) > 0 ); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -32,16 +32,16 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function init() |
34 | 34 | { |
35 | - if( empty( $this->app->config->{static::ID} ))return; |
|
35 | + if( empty($this->app->config->{static::ID} ) )return; |
|
36 | 36 | |
37 | 37 | $this->normalize( $this->app->config->{static::ID}, [ |
38 | 38 | 'post_types' => [], |
39 | - ]); |
|
39 | + ] ); |
|
40 | 40 | |
41 | 41 | add_filter( 'rwmb_normalize_map_field', [$this, 'normalizeMapField'] ); |
42 | - add_filter( 'rwmb_show', [$this, 'show'], 10, 2 ); |
|
43 | - add_filter( 'rwmb_meta_boxes', [$this, 'register'] ); |
|
44 | - add_filter( 'rwmb_outer_html', [$this, 'renderField'], 10, 2 ); |
|
42 | + add_filter( 'rwmb_show', [$this, 'show'], 10, 2 ); |
|
43 | + add_filter( 'rwmb_meta_boxes', [$this, 'register'] ); |
|
44 | + add_filter( 'rwmb_outer_html', [$this, 'renderField'], 10, 2 ); |
|
45 | 45 | |
46 | 46 | } |
47 | 47 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | { |
76 | 76 | return PostMeta::get( $key, [ |
77 | 77 | 'id' => $this->getPostId(), |
78 | - ]); |
|
78 | + ] ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -84,14 +84,14 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function normalizeMapField( $field ) |
86 | 86 | { |
87 | - if( empty( $field['address_field'] )) { |
|
87 | + if( empty($field['address_field']) ) { |
|
88 | 88 | return $field; |
89 | 89 | } |
90 | - if( !$this->app->make( Helper::class )->startsWith( Application::PREFIX, $field['address_field'] )) { |
|
91 | - $field['address_field'] = Application::PREFIX . $field['address_field']; |
|
90 | + if( !$this->app->make( Helper::class )->startsWith( Application::PREFIX, $field['address_field'] ) ) { |
|
91 | + $field['address_field'] = Application::PREFIX.$field['address_field']; |
|
92 | 92 | } |
93 | 93 | $apiKey = SiteMeta::services( $field['api_key'] ); |
94 | - if( !empty( $apiKey ) && is_string( $apiKey )) { |
|
94 | + if( !empty($apiKey) && is_string( $apiKey ) ) { |
|
95 | 95 | $field['api_key'] = $apiKey; |
96 | 96 | } |
97 | 97 | return $field; |
@@ -103,14 +103,14 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function register() |
105 | 105 | { |
106 | - if( current_user_can( 'switch_themes' )) { |
|
106 | + if( current_user_can( 'switch_themes' ) ) { |
|
107 | 107 | $instructions = $this->initInstructions(); |
108 | - if( is_array( $instructions )) { |
|
108 | + if( is_array( $instructions ) ) { |
|
109 | 109 | $this->normalize( $instructions ); |
110 | 110 | } |
111 | 111 | } |
112 | 112 | $metaboxes = func_num_args() |
113 | - ? ( new Helper )->toArray( func_get_arg(0) ) |
|
113 | + ? (new Helper)->toArray( func_get_arg( 0 ) ) |
|
114 | 114 | : []; |
115 | 115 | return array_merge( $metaboxes, $this->metaboxes ); |
116 | 116 | } |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | public function show( $bool, array $metabox ) |
134 | 134 | { |
135 | 135 | if( defined( 'DOING_AJAX' ) |
136 | - || !isset( $metabox['condition'] ) |
|
137 | - || !$this->hasPostType( $metabox )) { |
|
136 | + || !isset($metabox['condition']) |
|
137 | + || !$this->hasPostType( $metabox ) ) { |
|
138 | 138 | return $bool; |
139 | 139 | } |
140 | 140 | return $this->validate( $metabox['condition'] ); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | */ |
146 | 146 | protected function getPostId() |
147 | 147 | { |
148 | - if( !( $postId = filter_input( INPUT_GET, 'post' ))) { |
|
148 | + if( !($postId = filter_input( INPUT_GET, 'post' )) ) { |
|
149 | 149 | $postId = filter_input( INPUT_POST, 'post_ID' ); |
150 | 150 | } |
151 | 151 | return intval( $postId ); |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | { |
159 | 159 | return array_unique( iterator_to_array( |
160 | 160 | new RecursiveIteratorIterator( |
161 | - new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' )) |
|
161 | + new RecursiveArrayIterator( array_column( $this->metaboxes, 'post_types' ) ) |
|
162 | 162 | ), |
163 | 163 | false |
164 | - )); |
|
164 | + ) ); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | */ |
170 | 170 | protected function hasPostType( array $metabox ) |
171 | 171 | { |
172 | - if( !isset( $metabox['post_types'] )) { |
|
172 | + if( !isset($metabox['post_types']) ) { |
|
173 | 173 | return true; |
174 | 174 | } |
175 | - if( !( $type = filter_input( INPUT_GET, 'post_type' ))) { |
|
175 | + if( !($type = filter_input( INPUT_GET, 'post_type' )) ) { |
|
176 | 176 | $type = get_post_type( $this->getPostId() ); |
177 | 177 | } |
178 | 178 | return in_array( $type, $metabox['post_types'] ); |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | 'id' => $id, |
191 | 191 | 'slug' => $id, |
192 | 192 | 'validation' => [], |
193 | - ]); |
|
193 | + ] ); |
|
194 | 194 | $this->metaboxes[] = $this->setDependencies( |
195 | 195 | $this->normalizeThis( $metabox, $data, $id ) |
196 | 196 | ); |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | protected function normalizeDepends( $depends, array $data, $parentId ) |
206 | 206 | { |
207 | - return is_string( $depends ) && !empty( $depends ) |
|
207 | + return is_string( $depends ) && !empty($depends) |
|
208 | 208 | ? $this->normalizeId( $depends, $data, $parentId ) |
209 | 209 | : ''; |
210 | 210 | } |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | */ |
225 | 225 | protected function normalizeFields( array $fields, array $data, $parentId ) |
226 | 226 | { |
227 | - return array_map( function( $id, $field ) use( $parentId ) { |
|
228 | - $defaults = [ |
|
227 | + return array_map( function( $id, $field ) use($parentId) { |
|
228 | + $defaults = [ |
|
229 | 229 | 'attributes' => [], |
230 | 230 | 'class' => '', |
231 | 231 | 'condition' => [], |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | */ |
246 | 246 | protected function normalizeId( $id, array $data, $parentId ) |
247 | 247 | { |
248 | - return Application::prefix() . $id; |
|
248 | + return Application::prefix().$id; |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | */ |
255 | 255 | protected function normalizePostTypes( $types ) |
256 | 256 | { |
257 | - return ( new Helper )->toArray( $types ); |
|
257 | + return (new Helper)->toArray( $types ); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
@@ -263,10 +263,10 @@ discard block |
||
263 | 263 | protected function normalizeValidation( array $validation, array $data, $parentId ) |
264 | 264 | { |
265 | 265 | foreach( ['messages', 'rules'] as $key ) { |
266 | - if( empty( $validation[$key] ))continue; |
|
266 | + if( empty($validation[$key]) )continue; |
|
267 | 267 | foreach( $validation[$key] as $id => $value ) { |
268 | 268 | $validation[$key][$this->normalizeFieldName( $id, ['slug' => $id], $parentId )] = $value; |
269 | - unset( $validation[$key][$id] ); |
|
269 | + unset($validation[$key][$id]); |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | return $validation; |
@@ -279,12 +279,12 @@ discard block |
||
279 | 279 | { |
280 | 280 | $fields = &$metabox['fields']; |
281 | 281 | $depends = array_column( $fields, 'depends' ); |
282 | - array_walk( $depends, function( $value, $index ) use( &$fields, $metabox ) { |
|
283 | - if( empty( $value ))return; |
|
284 | - $dependency = array_search( $value, array_column( $fields, 'id' )); |
|
282 | + array_walk( $depends, function( $value, $index ) use(&$fields, $metabox) { |
|
283 | + if( empty($value) )return; |
|
284 | + $dependency = array_search( $value, array_column( $fields, 'id' ) ); |
|
285 | 285 | $fields[$index]['attributes']['data-depends'] = $value; |
286 | - if( !$this->getMetaValue( $fields[$dependency]['slug'], '', $metabox['slug'] )) { |
|
287 | - $fields[$index]['class'] = trim( 'hidden ' . $fields[$index]['class'] ); |
|
286 | + if( !$this->getMetaValue( $fields[$dependency]['slug'], '', $metabox['slug'] ) ) { |
|
287 | + $fields[$index]['class'] = trim( 'hidden '.$fields[$index]['class'] ); |
|
288 | 288 | } |
289 | 289 | }); |
290 | 290 | return $metabox; |