Completed
Push — master ( 83468c...9c5987 )
by Miled
01:58
created

wsl.error.pages.php ➔ wsl_render_notice_page()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 56
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 56
rs 9.7251
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 31 and the first side effect is on line 14.

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
* WordPress Social Login
4
*
5
* http://miled.github.io/wordpress-social-login/ | https://github.com/miled/wordpress-social-login
6
*  (c) 2011-2015 Mohamed Mrassi and contributors | http://wordpress.org/plugins/wordpress-social-login/
7
*/
8
9
/**
10
* Generate WSL notices end errors pages.
11
*/
12
13
// Exit if accessed directly
14
if( !defined( 'ABSPATH' ) ) exit;
15
16
// --------------------------------------------------------------------
17
18
/**
19
* Display a simple notice to the user and kill WordPress execution
20
*
21
* This function is mainly used by bouncer
22
*
23
* Note:
24
*   In case you want to customize the content generated, you may redefine this function
25
*   Just make sure the script DIES at the end.
26
*
27
*   The $message to display for users is passed as a parameter.
28
*/
29
if( ! function_exists( 'wsl_render_notice_page' ) )
30
{
31
	function wsl_render_notice_page( $message )
32
	{
33
		$assets_base_url = WORDPRESS_SOCIAL_LOGIN_PLUGIN_URL . 'assets/img/';
34
?>
35
<!DOCTYPE html>
36
	<head>
37
		<meta name="robots" content="NOINDEX, NOFOLLOW">
38
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
39
        <meta name="viewport" content="width=device-width, initial-scale=1" />
40
		<title><?php bloginfo('name'); ?></title>
41
		<style type="text/css">
42
			body {
43
				background: #f3f6f8;
44
				color: #324155;
45
				font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen-Sans","Ubuntu","Cantarell","Helvetica Neue",sans-serif;
46
				font-size: 16px;
47
				line-height: 1.6;
48
			}
49
			div {
50
				position: absolute;
51
				top: 50%;
52
				left: 50%;
53
				transform: translate(-50%, -50%);
54
			}
55
			img {
56
				display: block;
57
				margin: 0 auto;
58
			}
59
			h1 {
60
				font-size: 1.4em;
61
				font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen-Sans","Ubuntu","Cantarell","Helvetica Neue",sans-serif;
62
				font-weight: 400;
63
				line-height: 1.6em;
64
				margin: 1em 0 .5em;
65
				transition: all .5s ease;
66
                text-align: center;
67
			}
68
            p{
69
                text-align: center;
70
            }
71
			a {
72
				text-decoration: none;
73
			}
74
		</style>
75
	<head>
76
	<body>
77
		<div>
78
			<img src="<?php echo $assets_base_url ?>error-52.png" />
79
80
            <p><?php echo nl2br( $message ); ?></p>
81
		</div>
82
	</body>
83
</html>
84
<?php
85
		die();
0 ignored issues
show
Coding Style Compatibility introduced by
The function wsl_render_notice_page() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
86
	}
87
}
88
89
// --------------------------------------------------------------------
90
91
/**
92
* Display an error page to the user and kill WordPress execution
93
*
94
* This function differ than wsl_render_notice_page as it have some extra parameters and also should allow debugging
95
*
96
* This function is used when WSL fails to authenticated a user with social networks
97
*
98
* Note:
99
*   In case you want to customize the content generated, you may redefine this function
100
*   Just make sure the script DIES at the end.
101
*
102
*   The $message to display for users is passed as a parameter and it's required.
103
*/
104
if( ! function_exists( 'wsl_render_error_page' ) )
105
{
106
	function wsl_render_error_page( $message, $notes = null, $provider = null, $api_error = null, $php_exception = null )
0 ignored issues
show
Unused Code introduced by
The parameter $message is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $provider is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
107
	{
108
		$assets_base_url = WORDPRESS_SOCIAL_LOGIN_PLUGIN_URL . 'assets/img/';
109
?>
110
<!DOCTYPE html>
111
	<head>
112
		<meta name="robots" content="NOINDEX, NOFOLLOW">
113
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
114
        <meta name="viewport" content="width=device-width, initial-scale=1" />
115
		<title><?php bloginfo('name'); ?> - <?php _wsl_e("Oops! We ran into an issue", 'wordpress-social-login') ?>.</title>
116
		<style type="text/css">
117
			body {
118
				background: #f3f6f8;
119
				color: #324155;
120
				font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen-Sans","Ubuntu","Cantarell","Helvetica Neue",sans-serif;
121
				font-size: 16px;
122
				line-height: 1.6;
123
			}
124
			div {
125
				position: absolute;
126
				top: 50%;
127
				left: 50%;
128
				transform: translate(-50%, -50%);
129
			}
130
			img {
131
				display: block;
132
				margin: 0 auto;
133
			}
134
			h1 {
135
				font-size: 1.4em;
136
				font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen-Sans","Ubuntu","Cantarell","Helvetica Neue",sans-serif;
137
				font-weight: 400;
138
				line-height: 1.6em;
139
				margin: 1em 0 .5em;
140
				transition: all .5s ease;
141
                text-align: center;
142
			}
143
            p{
144
                text-align: center;
145
            }
146
			a {
147
				text-decoration: none;
148
			}
149
		</style>
150
	</head>
151
	<body>
152
		<div>
153
			<img src="<?php echo $assets_base_url ?>error-60.png" />
154
155
			<h1><?php _wsl_e("We're unable to complete your request", 'wordpress-social-login') ?>!</h1>
156
157
            <p><?php echo htmlentities($api_error); ?></p>
158
159
            <?php
160
                // any hint or extra note?
161
                if( $notes )
162
                {
163
                    ?>
164
                        <p><?php _wsl_e( $notes, 'wordpress-social-login'); ?></p>
165
                    <?php
166
                }
167
            ?>
168
169
            <p><a href="<?php echo home_url(); ?>">&xlarr; <?php _wsl_e("Back to home", 'wordpress-social-login') ?></a></p>
170
		</div>
171
172
		<?php
173
			// Development mode on?
174
			if( get_option( 'wsl_settings_development_mode_enabled' ) )
175
			{
176
                ?><style>div {position: unset; transform: none;}</style><?php
177
178
                wsl_render_error_page_debug_section( $php_exception );
179
			}
180
		?>
181
	</body>
182
</html>
183
<?php
184
	# keep these 2 LOC
185
		do_action( 'wsl_clear_user_php_session' );
186
187
		die();
0 ignored issues
show
Coding Style Compatibility introduced by
The function wsl_render_error_page() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
188
	}
189
}
190
191
// --------------------------------------------------------------------
192
193
/**
194
* Display an extra debugging section to the error page, in case Mode Dev is on
195
*/
196
function wsl_render_error_page_debug_section( $php_exception = null )
197
{
198
?>
199
<hr />
200
201
<?php wsl_display_dev_mode_debugging_area(); ?>
202
203
<h3>Backtrace</h3>
204
<pre><?php echo wsl_generate_backtrace(); ?></pre>
205
206
<h3>Exception</h3>
207
<pre><?php print_r( $php_exception ); ?></pre>
208
209
<br />
210
211
<small>
212
	<?php _wsl_e("<strong>Note:</strong> This debugging area can be disabled from the plugin settings by setting <b>Development mode</b> to <b>Disabled</b>", 'wordpress-social-login'); ?>.
213
</small>
214
<?php
215
}
216
217
// --------------------------------------------------------------------
218