Test Failed
Push — master ( c2c5e3...6c3fa5 )
by Brandon
02:30
created

class-user-fields.php ➔ repro_user_save_profile_fields()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 62.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
4
5
/**
6
 * repro_user_profile_fields function.
7
 *
8
 * @access public
9
 * @param mixed $user User.
10
 * @return void
11
 */
12
function repro_user_profile_fields( $user ) {
13
14
	?>
15
16
	<h3>Real Estate Portal Profiles</h3>
17
18
	<table class="form-table">
19
20
		<tr>
21
			<th><label for="zillow-username">Zillow Username:</label></th>
22
23
			<td>
24
				<input type="text" name="zillow_username" id="zillow-username" value="<?php echo esc_attr( get_the_author_meta( 'zillow_username', $user->ID ) ); ?>" class="regular-text" /><br />
25
				<span class="description">Please provide your Zillow Username.</span>
26
			</td>
27
		</tr>
28
29
		<tr>
30
			<th><label for="trulia-username">Trulia Username:</label></th>
31
32
			<td>
33
				<input type="text" name="trulia_username" id="trulia-username" value="<?php echo esc_attr( get_the_author_meta( 'trulia_username', $user->ID ) ); ?>" class="regular-text" /><br />
34
				<span class="description">Please provide your Trulia Username.</span>
35
			</td>
36
		</tr>
37
38
		<tr>
39
			<th><label for="homescom-user-id">Homes.com User ID:</label></th>
40
41
			<td>
42
				<input type="text" name="homescom_user_id" id="homescom-user-id" value="<?php echo esc_attr( get_the_author_meta( 'homescom_user_id', $user->ID ) ); ?>" class="regular-text" /><br />
43
				<span class="description">Please provide your Homes.com User ID.</span>
44
			</td>
45
		</tr>
46
47
48
		<tr>
49
			<th><label for="realtorcom-url">Realtor.com Profile Url:</label></th>
50
51
			<td>
52
				<input type="text" name="realtorcom_url" id="realtorcom-url" value="<?php echo esc_attr( get_the_author_meta( 'realtorcom_url', $user->ID ) ); ?>" class="regular-text" /><br />
53
				<span class="description">Please provide your Realtor.com URL.</span>
54
			</td>
55
		</tr>
56
57
	</table>
58
59
	<?php
60
61
} // End repro_user_profile_fields.
62
add_action( 'show_user_profile', 'repro_user_profile_fields' );
63
add_action( 'edit_user_profile', 'repro_user_profile_fields' );
64
65
/**
66
 * repro_user_save_profile_fields function.
67
 *
68
 * @access public
69
 * @param mixed $user_id User ID.
70
 * @return void
71
 */
72
function repro_user_save_profile_fields( $user_id ) {
0 ignored issues
show
Coding Style introduced by
repro_user_save_profile_fields uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
73
74
	if ( ! current_user_can( 'edit_user', $user_id ) ) {
75
		return false;
76
	}
77
78
	update_user_meta( $user_id, 'zillow_username', $_POST['zillow_username'] );
79
	update_user_meta( $user_id, 'trulia_username', $_POST['trulia_username'] );
80
	update_user_meta( $user_id, 'homescom_user_id', $_POST['homescom_user_id'] );
81
	update_user_meta( $user_id, 'realtorcom_url', $_POST['realtorcom_url'] );
82
83
} // End repro_user_save_profile_fields.
84
add_action( 'personal_options_update', 'repro_user_save_profile_fields' );
85
add_action( 'edit_user_profile_update', 'repro_user_save_profile_fields' );
86
87