Skip to content

Commit 97d7e52

Browse files
committed
Fix: password field backward compatibility for single input, without the User/Password combination
1 parent 86b0912 commit 97d7e52

File tree

1 file changed

+91
-49
lines changed

1 file changed

+91
-49
lines changed
Lines changed: 91 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,95 @@
11
<?php
2+
/**
3+
* Class ReduxFramework_password
4+
*/
25
class ReduxFramework_password {
36

4-
/**
5-
* Field Constructor.
6-
*
7-
* Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function
8-
*
9-
* @since ReduxFramework 1.0.1
10-
*/
11-
function __construct( $field = array(), $value ='', $parent ) {
12-
$this->field = $field;
13-
$this->value = $value;
14-
$this->args = $parent->args;
15-
}
16-
17-
/**
18-
* Field Render Function.
19-
*
20-
* Takes the vars and outputs the HTML for the field in the settings
21-
*
22-
* @since ReduxFramework 1.0.1
23-
*/
24-
function render() {
25-
if (!empty($this->field['username']) && $this->field['username'] === true ) {
26-
$defaults = array(
27-
'username'=>'',
28-
'password'=>'',
29-
'placeholder' => array('password'=>__( 'Password', 'redux-framework' ), 'username'=>__( 'Username', 'redux-framework' ))
30-
);
31-
$this->value = wp_parse_args( $this->value, $defaults );
32-
}
33-
34-
if ( !empty($this->field['placeholder'] ) ) {
35-
if ( is_array( $this->field['placeholder'] ) && !empty( $this->field['placeholder']['password'] ) ) {
36-
$this->value['placeholder']['password'] = $this->field['placeholder']['password'];
37-
}
38-
if ( is_array( $this->field['placeholder'] ) && !empty( $this->field['placeholder']['username'] ) ) {
39-
$this->value['placeholder']['username'] = $this->field['placeholder']['username'];
40-
}
41-
} else {
42-
$this->value['placeholder']['password'] = $this->field['placeholder'];
43-
}
44-
45-
if (!empty($this->field['username']) && $this->field['username'] === true ) {
46-
echo '<input type="input" autocomplete="off" placeholder="'.$this->value['placeholder']['username'].'" id="' . $this->field['id'] . '[username]" name="' . $this->args['opt_name'] . '[' . $this->field['id'] . '][username]" value="' . esc_attr($this->value['username']) . '" class="regular-text ' . $this->field['class'] . '" style="margin-right: 5px;" />';
47-
echo '<input type="password" autocomplete="off" placeholder="'.$this->value['placeholder']['password'].'" id="' . $this->field['id'] . '[password]" name="' . $this->args['opt_name'] . '[' . $this->field['id'] . '][password]" value="' . esc_attr($this->value['password']) . '" class="regular-text ' . $this->field['class'] . '" />';
48-
} else {
49-
echo '<input type="password" autocomplete="off" placeholder="'.$this->value['placeholder']['password'].'" id="' . $this->field['id'] . '" name="' . $this->args['opt_name'] . '[' . $this->field['id'] . ']" value="' . esc_attr($this->value) . '" class="' . $this->field['class'] . '" />';
50-
}
51-
52-
}
7+
/**
8+
* Field Constructor.
9+
* Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function
10+
* @since ReduxFramework 1.0.1
11+
*/
12+
function __construct( $field = array(), $value = '', $parent ) {
13+
$this->field = $field;
14+
$this->value = $value;
15+
$this->args = $parent->args;
16+
}
17+
18+
/**
19+
* Field Render Function.
20+
* Takes the vars and outputs the HTML for the field in the settings
21+
* @since ReduxFramework 1.0.1
22+
*/
23+
function render() {
24+
if ( ! empty( $this->field['username'] ) && $this->field['username'] === true ) {
25+
$this->_render_combined_field();
26+
}
27+
else {
28+
$this->_render_single_field();
29+
}
30+
}
31+
32+
/**
33+
* This will render a combined User/Password field
34+
* @since ReduxFramework 3.0.9
35+
* @example
36+
* <code>
37+
* array(
38+
* 'id' => 'smtp_account',
39+
* 'type' => 'password',
40+
* 'username' => true,
41+
* 'title' => 'SMTP Account',
42+
* 'placeholder' => array('username' => 'Username')
43+
* )
44+
* </code>
45+
*/
46+
private function _render_combined_field() {
47+
48+
$defaults = array(
49+
'username' => '',
50+
'password' => '',
51+
'placeholder' => array(
52+
'password' => __( 'Password', 'redux-framework' ),
53+
'username' => __( 'Username', 'redux-framework' )
54+
)
55+
);
56+
$this->value = wp_parse_args( $this->value, $defaults );
57+
58+
59+
if ( ! empty( $this->field['placeholder'] ) ) {
60+
if ( is_array( $this->field['placeholder'] ) && ! empty( $this->field['placeholder']['password'] ) ) {
61+
$this->value['placeholder']['password'] = $this->field['placeholder']['password'];
62+
}
63+
if ( is_array( $this->field['placeholder'] ) && ! empty( $this->field['placeholder']['username'] ) ) {
64+
$this->value['placeholder']['username'] = $this->field['placeholder']['username'];
65+
}
66+
}
67+
else {
68+
$this->value['placeholder']['password'] = $this->field['placeholder'];
69+
}
70+
71+
// Username field
72+
echo '<input type="input" autocomplete="off" placeholder="' . $this->value['placeholder']['username'] . '" id="' . $this->field['id'] . '[username]" name="' . $this->args['opt_name'] . '[' . $this->field['id'] . '][username]" value="' . esc_attr( $this->value['username'] ) . '" class="regular-text ' . $this->field['class'] . '" style="margin-right: 5px;" />';
73+
74+
// Password field
75+
echo '<input type="password" autocomplete="off" placeholder="' . $this->value['placeholder']['password'] . '" id="' . $this->field['id'] . '[password]" name="' . $this->args['opt_name'] . '[' . $this->field['id'] . '][password]" value="' . esc_attr( $this->value['password'] ) . '" class="regular-text ' . $this->field['class'] . '" />';
76+
77+
}
78+
79+
/**
80+
* This will render a single Password field
81+
* @since ReduxFramework 3.0.9
82+
* @example
83+
* <code>
84+
* array(
85+
* 'id' => 'smtp_password',
86+
* 'type' => 'password',
87+
* 'title' => 'SMTP Password'
88+
* )
89+
* </code>
90+
*/
91+
private function _render_single_field() {
92+
echo '<input type="password" id="' . $this->field['id'] . '" name="' . $this->args['opt_name'] . '[' . $this->field['id'] . ']" value="' . esc_attr( $this->value ) . '" class="regular-text ' . $this->field['class'] . '" />';
93+
}
94+
5395
}

0 commit comments

Comments
 (0)