Skip to content
This repository was archived by the owner on Dec 2, 2022. It is now read-only.

Commit f293957

Browse files
committed
Ensure all defaults are set per field to prevent PHP index errors, PHPCS
Signed-off-by: Kevin Provance <kevin.provance@gmail.com>
1 parent 3586e60 commit f293957

35 files changed

+427
-370
lines changed

redux-core/inc/classes/class-redux-field.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function output( $style = '' ) {
276276
/**
277277
* Unused for now.
278278
*
279-
* @param string $data CSS data.
279+
* @param mixed $data CSS data.
280280
*/
281281
public function css_style( $data ) {
282282

redux-core/inc/fields/ace_editor/class-redux-ace-editor.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ public function enqueue() {
8585
'redux-field-ace-editor-css',
8686
Redux_Core::$url . 'inc/fields/ace_editor/redux-ace-editor.css',
8787
array(),
88-
$this->timestamp,
89-
'all'
88+
$this->timestamp
9089
);
9190
}
9291

redux-core/inc/fields/background/class-redux-background.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function render() {
9292
$this->value['background-color'] = $this->value['color'];
9393
}
9494

95-
$def_bg_color = isset( $this->field['default']['background-color'] ) ? $this->field['default']['background-color'] : '';
95+
$def_bg_color = $this->field['default']['background-color'] ?? '';
9696

9797
echo '<input ';
9898
echo 'data-id="' . esc_attr( $this->field['id'] ) . '"';
@@ -287,7 +287,7 @@ public function render() {
287287
$hide = '';
288288
}
289289

290-
$placeholder = isset( $this->field['placeholder'] ) ? $this->field['placeholder'] : esc_html__( 'No media selected', 'redux-framework' );
290+
$placeholder = $this->field['placeholder'] ?? esc_html__( 'No media selected', 'redux-framework' );
291291

292292
echo '<input placeholder="' . esc_html( $placeholder ) . '" type="text" class="redux-background-input ' . esc_attr( $hide ) . 'upload ' . esc_attr( $this->field['class'] ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[background-image]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][background-image]" value="' . esc_url( $this->value['background-image'] ) . '" />';
293293
echo '<input type="hidden" class="upload-id ' . esc_attr( $this->field['class'] ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[media][id]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][media][id]" value="' . esc_attr( $this->value['media']['id'] ) . '" />';
@@ -322,7 +322,7 @@ public function render() {
322322
echo '<a class="of-uploaded-image" href="' . esc_url( $this->value['background-image'] ) . '" target="_blank">';
323323

324324
$alt = wp_prepare_attachment_for_js( $this->value['media']['id'] );
325-
$alt = isset( $alt['alt'] ) ? $alt['alt'] : '';
325+
$alt = $alt['alt'] ?? '';
326326

327327
echo '<img class="redux-option-image" id="image_' . esc_attr( $this->value['media']['id'] ) . '" src="' . esc_url( $this->value['media']['thumbnail'] ) . '" alt="' . esc_attr( $alt ) . '" target="_blank" rel="external" />';
328328
echo '</a>';
@@ -401,8 +401,7 @@ public function enqueue() {
401401
'redux-field-background-css',
402402
Redux_Core::$url . 'inc/fields/background/redux-background.css',
403403
array(),
404-
$this->timestamp,
405-
'all'
404+
$this->timestamp
406405
);
407406

408407
wp_enqueue_style( 'redux-color-picker-css' );
@@ -412,15 +411,15 @@ public function enqueue() {
412411
/**
413412
* Output CSS styling.
414413
*
415-
* @param array $value Value array.
414+
* @param array $data Value array.
416415
*
417-
* @return string|void
416+
* @return string
418417
*/
419-
public function css_style( $value = array() ) {
418+
public function css_style( $data = array() ): string {
420419
$css = '';
421420

422-
if ( ! empty( $value ) && is_array( $value ) ) {
423-
foreach ( $value as $key => $val ) {
421+
if ( ! empty( $data ) && is_array( $data ) ) {
422+
foreach ( $data as $key => $val ) {
424423
if ( ! empty( $val ) && 'media' !== $key ) {
425424
if ( 'background-image' === $key ) {
426425
$css .= $key . ":url('" . esc_url( $val ) . "');";

redux-core/inc/fields/border/class-redux-border.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ public function enqueue() {
260260
'redux-field-border-css',
261261
Redux_Core::$url . 'inc/fields/border/redux-border.css',
262262
array(),
263-
$this->timestamp,
264-
'all'
263+
$this->timestamp
265264
);
266265
}
267266
}

redux-core/inc/fields/button_set/class-redux-button-set.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919
*/
2020
class Redux_Button_Set extends Redux_Field {
2121

22+
/**
23+
* Set field defaults.
24+
*/
25+
public function set_defaults() {
26+
$defaults = array(
27+
'options' => array(),
28+
'multi' => false,
29+
);
30+
31+
$this->field = wp_parse_args( $this->field, $defaults );
32+
}
33+
2234
/**
2335
* Field Render Function.
2436
* Takes the vars and outputs the HTML for the field in the settings
@@ -40,7 +52,7 @@ public function render() {
4052
}
4153
}
4254

43-
$is_multi = ( isset( $this->field['multi'] ) && true === $this->field['multi'] ) ? true : false;
55+
$is_multi = isset( $this->field['multi'] ) && true === (bool) $this->field['multi'];
4456

4557
$name = $this->field['name'] . $this->field['name_suffix'];
4658

redux-core/inc/fields/checkbox/class-redux-checkbox.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ public function enqueue() {
128128
'redux-field-checkbox-css',
129129
Redux_Core::$url . 'inc/fields/checkbox/redux-checkbox.css',
130130
array(),
131-
$this->timestamp,
132-
'all'
131+
$this->timestamp
133132
);
134133
}
135134

redux-core/inc/fields/color/class-redux-color.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@
1919
*/
2020
class Redux_Color extends Redux_Field {
2121

22+
/**
23+
* Set field defaults.
24+
*/
25+
public function set_defaults() {
26+
$defaults = array(
27+
'transparent' => true,
28+
'alpha' => false,
29+
);
30+
31+
$this->field = wp_parse_args( $this->field, $defaults );
32+
}
33+
2234
/**
2335
* Field Render Function.
2436
* Takes the vars and outputs the HTML for the field in the settings
@@ -103,12 +115,10 @@ public function enqueue() {
103115
*
104116
* @param string $data Field data.
105117
*
106-
* @return array|void
118+
* @return string
107119
*/
108-
public function css_style( $data ) {
109-
$style = array();
110-
111-
return $style;
120+
public function css_style( $data ): string {
121+
return '';
112122
}
113123

114124
/**

redux-core/inc/fields/color_gradient/class-redux-color-gradient.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public function set_defaults() {
4545
$defaults = array(
4646
'preview' => false,
4747
'preview_height' => '150px',
48+
'transparent' => true,
49+
'alpha' => false,
4850
);
4951

5052
$this->field = wp_parse_args( $this->field, $defaults );
@@ -160,8 +162,7 @@ public function enqueue() {
160162
'redux-field-color_gradient-css',
161163
Redux_Core::$url . 'inc/fields/color_gradient/redux-color-gradient.css',
162164
array(),
163-
$this->timestamp,
164-
'all'
165+
$this->timestamp
165166
);
166167
}
167168
}
@@ -177,9 +178,7 @@ public function css_style( $data ) {
177178
if ( Redux_Core::$pro_loaded ) {
178179

179180
// phpcs:ignore WordPress.NamingConventions.ValidHookName
180-
$pro_data = apply_filters( 'redux/pro/color_gradient/output', $data );
181-
182-
return $pro_data;
181+
return apply_filters( 'redux/pro/color_gradient/output', $data );
183182
}
184183
}
185184

redux-core/inc/fields/color_rgba/class-redux-color-rgba.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function set_defaults() {
5757
// Convert empty array to null, if there.
5858
$this->field['options']['palette'] = empty( $this->field['options']['palette'] ) ? null : $this->field['options']['palette'];
5959

60-
$this->field['output_transparent'] = isset( $this->field['output_transparent'] ) ? $this->field['output_transparent'] : false;
60+
$this->field['output_transparent'] = $this->field['output_transparent'] ?? false;
6161
}
6262

6363
/**
@@ -72,8 +72,8 @@ public function render() {
7272
$field_id = $this->field['id'];
7373

7474
// Color picker container.
75-
echo '<div
76-
class="redux-color-rgba-container ' . esc_attr( $this->field['class'] ) . '"
75+
echo '<div
76+
class="redux-color-rgba-container ' . esc_attr( $this->field['class'] ) . '"
7777
data-id="' . esc_attr( $field_id ) . '"
7878
data-show-input="' . esc_attr( $this->field['options']['show_input'] ) . '"
7979
data-show-initial="' . esc_attr( $this->field['options']['show_initial'] ) . '"
@@ -178,8 +178,7 @@ public function enqueue() {
178178
'redux-field-color-rgba-css',
179179
Redux_Core::$url . 'inc/fields/color_rgba/redux-color-rgba.css',
180180
array(),
181-
$this->timestamp,
182-
'all'
181+
$this->timestamp
183182
);
184183
}
185184
}
@@ -192,7 +191,7 @@ public function enqueue() {
192191
* @access private
193192
* @return string
194193
*/
195-
private function get_color_val() {
194+
private function get_color_val(): string {
196195

197196
// No notices.
198197
$color = '';
@@ -230,12 +229,10 @@ private function get_color_val() {
230229
*
231230
* @param string $data Field data.
232231
*
233-
* @return array|void
232+
* @return string
234233
*/
235-
public function css_style( $data ) {
236-
$style = array();
237-
238-
return $style;
234+
public function css_style( $data ): string {
235+
return '';
239236
}
240237

241238
/**

redux-core/inc/fields/date/class-redux-date.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ class Redux_Date extends Redux_Field {
3030
public function render() {
3131
$placeholder = ( isset( $this->field['placeholder'] ) ) ? ' placeholder="' . $this->field['placeholder'] . '" ' : '';
3232

33-
echo '<input
34-
data-id="' . esc_attr( $this->field['id'] ) . '"
35-
type="text"
36-
id="' . esc_attr( $this->field['id'] ) . '-date"
33+
echo '<input
34+
data-id="' . esc_attr( $this->field['id'] ) . '"
35+
type="text"
36+
id="' . esc_attr( $this->field['id'] ) . '-date"
3737
name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '"' . esc_attr( $placeholder ) . '
38-
value="' . esc_attr( $this->value ) . '"
38+
value="' . esc_attr( $this->value ) . '"
3939
class="redux-datepicker regular-text ' . esc_attr( $this->field['class'] ) . '" />';
4040
}
4141

@@ -53,8 +53,7 @@ public function enqueue() {
5353
'redux-field-date-css',
5454
Redux_Core::$url . 'inc/fields/date/redux-date.css',
5555
array(),
56-
$this->timestamp,
57-
'all'
56+
$this->timestamp
5857
);
5958
}
6059

0 commit comments

Comments
 (0)