Conditions | 35 |
Paths | > 20000 |
Total Lines | 261 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
41 | function wsl_render_auth_widget( $args = array() ) |
||
42 | { |
||
43 | $auth_mode = isset( $args['mode'] ) && $args['mode'] ? $args['mode'] : 'login'; |
||
44 | |||
45 | // validate auth-mode |
||
46 | if( ! in_array( $auth_mode, array( 'login', 'link', 'test' ) ) ) |
||
47 | { |
||
48 | return; |
||
49 | } |
||
50 | |||
51 | // auth-mode eq 'login' => display wsl widget only for NON logged in users |
||
52 | // > this is the default mode of wsl widget. |
||
53 | if( $auth_mode == 'login' && is_user_logged_in() ) |
||
54 | { |
||
55 | return; |
||
56 | } |
||
57 | |||
58 | // auth-mode eq 'link' => display wsl widget only for LOGGED IN users |
||
59 | // > this will allows users to manually link other social network accounts to their WordPress account |
||
60 | if( $auth_mode == 'link' && ! is_user_logged_in() ) |
||
61 | { |
||
62 | return; |
||
63 | } |
||
64 | |||
65 | // auth-mode eq 'test' => display wsl widget only for LOGGED IN users only on dashboard |
||
66 | // > used in Authentication Playground on WSL admin dashboard |
||
67 | if( $auth_mode == 'test' && ! is_user_logged_in() && ! is_admin() ) |
||
68 | { |
||
69 | return; |
||
70 | } |
||
71 | |||
72 | // Bouncer :: Allow authentication? |
||
73 | if( get_option( 'wsl_settings_bouncer_authentication_enabled' ) == 2 ) |
||
74 | { |
||
75 | return; |
||
76 | } |
||
77 | |||
78 | // HOOKABLE: This action runs just before generating the WSL Widget. |
||
79 | do_action( 'wsl_render_auth_widget_start' ); |
||
80 | |||
81 | GLOBAL $WORDPRESS_SOCIAL_LOGIN_PROVIDERS_CONFIG; |
||
82 | |||
83 | ob_start(); |
||
84 | |||
85 | // Icon set. If eq 'none', we show text instead |
||
86 | $social_icon_set = get_option( 'wsl_settings_social_icon_set' ); |
||
87 | |||
88 | // wpzoom icons set, is shown by default |
||
89 | if( empty( $social_icon_set ) ) |
||
90 | { |
||
91 | $social_icon_set = "wpzoom/"; |
||
92 | } |
||
93 | |||
94 | $assets_base_url = WORDPRESS_SOCIAL_LOGIN_PLUGIN_URL . 'assets/img/32x32/' . $social_icon_set . '/'; |
||
95 | |||
96 | $assets_base_url = isset( $args['assets_base_url'] ) && $args['assets_base_url'] ? $args['assets_base_url'] : $assets_base_url; |
||
97 | |||
98 | // HOOKABLE: |
||
99 | $assets_base_url = apply_filters( 'wsl_render_auth_widget_alter_assets_base_url', $assets_base_url ); |
||
100 | |||
101 | // get the current page url, which we will use to redirect the user to, |
||
102 | // unless Widget::Force redirection is set to 'yes', then this will be ignored and Widget::Redirect URL will be used instead |
||
103 | $redirect_to = wsl_get_current_url(); |
||
104 | |||
105 | // Use the provided redirect_to if it is given and this is the login page. |
||
106 | if ( in_array( $GLOBALS["pagenow"], array( "wp-login.php", "wp-register.php" ) ) && !empty( $_REQUEST["redirect_to"] ) ) |
||
107 | { |
||
108 | $redirect_to = $_REQUEST["redirect_to"]; |
||
109 | } |
||
110 | |||
111 | // build the authentication url which will call for wsl_process_login() : action=wordpress_social_authenticate |
||
112 | $authenticate_base_url = add_query_arg( |
||
113 | array( |
||
114 | 'action' => 'wordpress_social_authenticate', |
||
115 | 'mode' => 'login', |
||
116 | ), |
||
117 | site_url( 'wp-login.php', 'login_post' ) |
||
118 | ); |
||
119 | |||
120 | // if not in mode login, we overwrite the auth base url |
||
121 | // > admin auth playground |
||
122 | if( $auth_mode == 'test' ) |
||
123 | { |
||
124 | $authenticate_base_url = add_query_arg( |
||
125 | array( |
||
126 | 'action' => 'wordpress_social_authenticate', |
||
127 | 'mode' => 'test', |
||
128 | ), |
||
129 | home_url() |
||
130 | ); |
||
131 | } |
||
132 | |||
133 | // > account linking |
||
134 | elseif( $auth_mode == 'link' ) |
||
135 | { |
||
136 | $authenticate_base_url = add_query_arg( |
||
137 | array( |
||
138 | 'action' => 'wordpress_social_authenticate', |
||
139 | 'mode' => 'link', |
||
140 | ), |
||
141 | home_url() |
||
142 | ); |
||
143 | } |
||
144 | |||
145 | // Connect with caption |
||
146 | $connect_with_label = _wsl__( get_option( 'wsl_settings_connect_with_label' ), 'wordpress-social-login' ); |
||
147 | |||
148 | $connect_with_label = isset( $args['caption'] ) ? $args['caption'] : $connect_with_label; |
||
149 | |||
150 | // HOOKABLE: |
||
151 | $connect_with_label = apply_filters( 'wsl_render_auth_widget_alter_connect_with_label', $connect_with_label ); |
||
152 | ?> |
||
153 | |||
154 | <!-- |
||
155 | wsl_render_auth_widget |
||
156 | WordPress Social Login <?php echo wsl_get_version(); ?>. |
||
157 | http://wordpress.org/plugins/wordpress-social-login/ |
||
158 | --> |
||
159 | <?php |
||
160 | // Widget::Custom CSS |
||
161 | $widget_css = get_option( 'wsl_settings_authentication_widget_css' ); |
||
162 | |||
163 | // HOOKABLE: |
||
164 | $widget_css = apply_filters( 'wsl_render_auth_widget_alter_widget_css', $widget_css, $redirect_to ); |
||
165 | |||
166 | // show the custom widget css if not empty |
||
167 | if( ! empty( $widget_css ) ) |
||
168 | { |
||
169 | ?> |
||
170 | |||
171 | <style type="text/css"> |
||
172 | <?php |
||
173 | echo |
||
174 | preg_replace( |
||
175 | array( '%/\*(?:(?!\*/).)*\*/%s', '/\s{2,}/', "/\s*([;{}])[\r\n\t\s]/", '/\\s*;\\s*/', '/\\s*{\\s*/', '/;?\\s*}\\s*/' ), |
||
176 | array( '', ' ', '$1', ';', '{', '}' ), |
||
177 | $widget_css ); |
||
178 | ?> |
||
179 | </style> |
||
180 | <?php |
||
181 | } |
||
182 | ?> |
||
183 | |||
184 | <div class="wp-social-login-widget"> |
||
185 | |||
186 | <div class="wp-social-login-connect-with"><?php echo $connect_with_label; ?></div> |
||
187 | |||
188 | <div class="wp-social-login-provider-list"> |
||
189 | <?php |
||
190 | // Widget::Authentication display |
||
191 | $wsl_settings_use_popup = get_option( 'wsl_settings_use_popup' ); |
||
192 | |||
193 | // if a user is visiting using a mobile device, WSL will fall back to more in page |
||
194 | $wsl_settings_use_popup = function_exists( 'wp_is_mobile' ) ? wp_is_mobile() ? 2 : $wsl_settings_use_popup : $wsl_settings_use_popup; |
||
195 | |||
196 | $no_idp_used = true; |
||
197 | |||
198 | // display provider icons |
||
199 | foreach( $WORDPRESS_SOCIAL_LOGIN_PROVIDERS_CONFIG AS $item ) |
||
200 | { |
||
201 | $provider_id = isset( $item["provider_id"] ) ? $item["provider_id"] : '' ; |
||
202 | $provider_name = isset( $item["provider_name"] ) ? $item["provider_name"] : '' ; |
||
203 | |||
204 | // provider enabled? |
||
205 | if( get_option( 'wsl_settings_' . $provider_id . '_enabled' ) ) |
||
206 | { |
||
207 | // restrict the enabled providers list |
||
208 | if( isset( $args['enable_providers'] ) ) |
||
209 | { |
||
210 | $enable_providers = explode( '|', $args['enable_providers'] ); // might add a couple of pico seconds |
||
211 | |||
212 | if( ! in_array( strtolower( $provider_id ), $enable_providers ) ) |
||
213 | { |
||
214 | continue; |
||
215 | } |
||
216 | } |
||
217 | |||
218 | // build authentication url |
||
219 | $authenticate_url = add_query_arg( |
||
220 | array( |
||
221 | 'provider' => $provider_id, |
||
222 | 'redirect_to' => urlencode( $redirect_to ), |
||
223 | ), |
||
224 | $authenticate_base_url |
||
225 | ); |
||
226 | |||
227 | // http://codex.wordpress.org/Function_Reference/esc_url |
||
228 | $authenticate_url = esc_url( $authenticate_url ); |
||
229 | |||
230 | // in case, Widget::Authentication display is set to 'popup', then we overwrite 'authenticate_url' |
||
231 | // > /assets/js/connect.js will take care of the rest |
||
232 | if( $wsl_settings_use_popup == 1 && $auth_mode != 'test' ) |
||
233 | { |
||
234 | $authenticate_url= "javascript:void(0);"; |
||
235 | } |
||
236 | |||
237 | // HOOKABLE: allow user to rebuilt the auth url |
||
238 | $authenticate_url = apply_filters( 'wsl_render_auth_widget_alter_authenticate_url', $authenticate_url, $provider_id, $auth_mode, $redirect_to, $wsl_settings_use_popup ); |
||
239 | |||
240 | // HOOKABLE: allow use of other icon sets |
||
241 | $provider_icon_markup = apply_filters( 'wsl_render_auth_widget_alter_provider_icon_markup', $provider_id, $provider_name, $authenticate_url ); |
||
242 | |||
243 | if( $provider_icon_markup != $provider_id ) |
||
244 | { |
||
245 | echo $provider_icon_markup; |
||
246 | } |
||
247 | else |
||
248 | { |
||
249 | ?> |
||
250 | |||
251 | <a rel="nofollow" href="<?php echo $authenticate_url; ?>" title="<?php echo sprintf( _wsl__("Connect with %s", 'wordpress-social-login'), $provider_name ) ?>" class="wp-social-login-provider wp-social-login-provider-<?php echo strtolower( $provider_id ); ?>" data-provider="<?php echo $provider_id ?>" role="button"> |
||
252 | <?php if( $social_icon_set == 'none' ){ echo apply_filters( 'wsl_render_auth_widget_alter_provider_name', $provider_name ); } else { ?><img alt="<?php echo $provider_name ?>" src="<?php echo $assets_base_url . strtolower( $provider_id ) . '.png' ?>" aria-hidden="true" /><?php } ?> |
||
253 | |||
254 | </a> |
||
255 | <?php |
||
256 | } |
||
257 | |||
258 | $no_idp_used = false; |
||
259 | } |
||
260 | } |
||
261 | |||
262 | // no provider enabled? |
||
263 | if( $no_idp_used ) |
||
264 | { |
||
265 | ?> |
||
266 | <p style="background-color: #FFFFE0;border:1px solid #E6DB55;padding:5px;"> |
||
267 | <?php _wsl_e( '<strong>WordPress Social Login is not configured yet</strong>.<br />Please navigate to <strong>Settings > WP Social Login</strong> to configure this plugin.<br />For more information, refer to the <a rel="nofollow" href="http://miled.github.io/wordpress-social-login">online user guide</a>.', 'wordpress-social-login') ?>. |
||
268 | </p> |
||
269 | <style>#wp-social-login-connect-with{display:none;}</style> |
||
270 | <?php |
||
271 | } |
||
272 | ?> |
||
273 | |||
274 | </div> |
||
275 | |||
276 | <div class="wp-social-login-widget-clearing"></div> |
||
277 | |||
278 | </div> |
||
279 | |||
280 | <?php |
||
281 | // provide popup url for hybridauth callback |
||
282 | if( $wsl_settings_use_popup == 1 ) |
||
283 | { |
||
284 | ?> |
||
285 | <input type="hidden" id="wsl_popup_base_url" value="<?php echo esc_url( $authenticate_base_url ) ?>" /> |
||
286 | <input type="hidden" id="wsl_login_form_uri" value="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" /> |
||
287 | |||
288 | <?php |
||
289 | } |
||
290 | |||
291 | // HOOKABLE: This action runs just after generating the WSL Widget. |
||
292 | do_action( 'wsl_render_auth_widget_end' ); |
||
293 | ?> |
||
294 | <!-- wsl_render_auth_widget --> |
||
295 | |||
296 | <?php |
||
297 | // Display WSL debugging area bellow the widget. |
||
298 | // wsl_display_dev_mode_debugging_area(); // ! keep this line commented unless you know what you are doing :) |
||
299 | |||
300 | return ob_get_clean(); |
||
301 | } |
||
302 | |||
570 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.