| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: WPOrLogin - Customize WordPress login |
| 4 |
* Plugin URI: https://oregoom.com/wporlogin/ |
| 5 |
* Description: Plugin to customize the WordPress login. |
| 6 |
* Version: 2.7 |
| 7 |
* Author: Oregoom |
| 8 |
* Author URI:https://oregoom.com/wporlogin/ |
| 9 |
* License: GPL2 |
| 10 |
* Text Domain: wporlogin |
| 11 |
* Domain Path: /languages/ |
| 12 |
*/ |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
//define("VERSION", 2.5); |
| 17 |
define('WPORLOGINBACKGROUNDIMAGE', array( |
| 18 |
plugin_dir_url( __FILE__ ).'img/wporlogin-img-fondo-0.jpg', |
| 19 |
plugin_dir_url( __FILE__ ).'img/wporlogin-img-fondo-1.jpg', |
| 20 |
plugin_dir_url( __FILE__ ).'img/wporlogin-img-fondo-2.jpg', |
| 21 |
plugin_dir_url( __FILE__ ).'img/wporlogin-img-fondo-3.jpg', |
| 22 |
plugin_dir_url( __FILE__ ).'img/wporlogin-img-fondo-4.jpg', |
| 23 |
plugin_dir_url( __FILE__ ).'img/wporlogin-img-fondo-5.jpg', |
| 24 |
plugin_dir_url( __FILE__ ).'img/wporlogin-img-fondo-6.jpg', |
| 25 |
plugin_dir_url( __FILE__ ).'img/wporlogin-img-fondo-7.jpg', |
| 26 |
plugin_dir_url( __FILE__ ).'img/wporlogin-img-fondo-8.jpg', |
| 27 |
plugin_dir_url( __FILE__ ).'img/wporlogin-img-fondo-9.jpg', |
| 28 |
plugin_dir_url( __FILE__ ).'img/wporlogin-img-fondo-10.jpg', |
| 29 |
plugin_dir_url( __FILE__ ).'img/wporlogin-img-fondo-11.jpg', |
| 30 |
plugin_dir_url( __FILE__ ).'img/wporlogin-img-fondo-12.jpg' |
| 31 |
)); |
| 32 |
|
| 33 |
require_once plugin_dir_path(__FILE__) .'includes/wporloginpage.php'; |
| 34 |
require_once plugin_dir_path(__FILE__) .'includes/remove-language-wporlogin.php'; |
| 35 |
|
| 36 |
|
| 37 |
function wporlogin_insert_script_upload(){ |
| 38 |
|
| 39 |
wp_enqueue_media();//PARA ABRIR LA BIBLIOTEMA MEDIOS |
| 40 |
|
| 41 |
//REGISTRAR EL SCRIPT JS |
| 42 |
wp_register_script('wporlogin_my_upload', plugin_dir_url( __FILE__ ).'js/img-fondo.js', array('jquery', 'wp-i18n'), '2.1', true ); |
| 43 |
wp_enqueue_script('wporlogin_my_upload'); //MOSTRAR EL SCRIPT JS EN ADMIN |
| 44 |
|
| 45 |
wp_set_script_translations('wporlogin_my_upload', 'wporlogin');//Cargar Translation |
| 46 |
|
| 47 |
} |
| 48 |
add_action("admin_enqueue_scripts", "wporlogin_insert_script_upload"); |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
//////////////////////////////////////////////////////////////////////////////// |
| 55 |
// WP LOGIN: AGREGAR NUEVO LOGO EN LUGAR DE WORDPRESS |
| 56 |
//////////////////////////////////////////////////////////////////////////////// |
| 57 |
|
| 58 |
function wporlogin_page_login() { |
| 59 |
|
| 60 |
//////////////////////////////////////////////////////////////////////////// |
| 61 |
// WP LOGIN: DISEÑO ESTANDAR AND PREMIUM (LOGO and BACKGROUND-IMAGE) |
| 62 |
// Version: 1.0 |
| 63 |
//////////////////////////////////////////////////////////////////////////// |
| 64 |
|
| 65 |
|
| 66 |
//FUNCION PARA OPTENER IMG DE FONDO |
| 67 |
function wporlogin_url_img_fondo_css(){ |
| 68 |
|
| 69 |
//COMPROBANDO SI LA VARIABLE ES NULO O VACIO |
| 70 |
if( get_option('wporlogin_background_images') ){ |
| 71 |
|
| 72 |
if(get_option('wporlogin_background_images') == 'wporlogin_free_images'){ |
| 73 |
|
| 74 |
//////////////////////////////////////////////////////////////////////////// |
| 75 |
// WP LOGIN: VARIABLE DE IMAGEN DE FONDO PARA CSS |
| 76 |
//////////////////////////////////////////////////////////////////////////// |
| 77 |
?> <style> |
| 78 |
:root{ |
| 79 |
--wporlogin-img-fondo: url(<?php echo esc_html(get_option('wporlogin-background-free-image')); ?>); /*URL DE IMAGEN GRATIS*/ |
| 80 |
} |
| 81 |
</style> <?php |
| 82 |
|
| 83 |
} elseif ( get_option('wporlogin_background_images') == 'wporlogin_my_images' ){ |
| 84 |
|
| 85 |
if(get_option('wporlogin_url_img_fondo')){ //URL DEL MY IMAGEN |
| 86 |
|
| 87 |
//////////////////////////////////////////////////////////////////////////// |
| 88 |
// WP LOGIN: VARIABLE DE IMAGEN DE FONDO PARA CSS |
| 89 |
//////////////////////////////////////////////////////////////////////////// |
| 90 |
?> <style> |
| 91 |
:root{ |
| 92 |
--wporlogin-img-fondo: url(<?php echo esc_html(get_option("wporlogin_url_img_fondo")); ?>); |
| 93 |
} |
| 94 |
</style> <?php |
| 95 |
|
| 96 |
} |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
//FUNCION PARA OPTENER URl DE LOGOTIPO |
| 105 |
function wporlogin_url_logo_css(){ |
| 106 |
|
| 107 |
if(get_option("wporlogin_url_logotipo")){ |
| 108 |
|
| 109 |
?><style> |
| 110 |
:root{ |
| 111 |
--wporlogin-logo: url(<?php echo esc_url(get_option('wporlogin_url_logotipo')); ?>); |
| 112 |
--wporlogin-width: 200px; |
| 113 |
--wporlogin-height: 84px; |
| 114 |
} |
| 115 |
</style><?php |
| 116 |
|
| 117 |
} else { |
| 118 |
|
| 119 |
$custom_logo_id = get_theme_mod( 'custom_logo' ); |
| 120 |
$image = wp_get_attachment_image_src( $custom_logo_id , 'full' ); |
| 121 |
/* |
| 122 |
* CONDICIÓN PARA SABER SI EL TEMA YA LO TIENE |
| 123 |
* ASIGNADO UN LOGO |
| 124 |
* |
| 125 |
* SI ES VERDAD, ENTONCES MUESTRA EL LOGO ASIGNADO |
| 126 |
* SI ES FALSO, MUESTRA EL LOGO DE WORDPRESS |
| 127 |
*/ |
| 128 |
if( has_custom_logo() ){ |
| 129 |
?><style> |
| 130 |
:root{ |
| 131 |
--wporlogin-logo: url(<?php echo esc_url( $image[0] ); ?>); |
| 132 |
--wporlogin-width: 200px; |
| 133 |
--wporlogin-height: auto; |
| 134 |
} |
| 135 |
</style><?php |
| 136 |
} else { |
| 137 |
?><style> |
| 138 |
:root{ |
| 139 |
--wporlogin-logo: url(<?php echo home_url( '/wp-admin/images/wordpress-logo.svg?ver=20131107' ); ?>); |
| 140 |
--wporlogin-width: 84px; |
| 141 |
--wporlogin-height: 84px; |
| 142 |
} |
| 143 |
</style><?php |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
//remove language |
| 152 |
function remove_language_wporlogin_css(){ |
| 153 |
|
| 154 |
if( get_option("remove_language_wporlogin") == 1 ){ |
| 155 |
|
| 156 |
?><style> |
| 157 |
:root{ |
| 158 |
--wporlogin-justify-content: center; |
| 159 |
--wporlogin-standard-min-height: 100vh; |
| 160 |
} |
| 161 |
</style><?php |
| 162 |
|
| 163 |
} else { |
| 164 |
|
| 165 |
?><style> |
| 166 |
:root{ |
| 167 |
--wporlogin-justify-content: flex-start; |
| 168 |
--wporlogin-standard-min-height: -100vh; |
| 169 |
} |
| 170 |
</style><?php |
| 171 |
|
| 172 |
} |
| 173 |
|
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
//////////////////////////////////////////////////////////////////////////// |
| 178 |
// WP LOGIN: CONDICIÓN PARA APLICAR CSS A PAGE LOGIN |
| 179 |
//////////////////////////////////////////////////////////////////////////// |
| 180 |
|
| 181 |
if (get_option('wporlogin_design') == 'wporlogin_design_basic'){ |
| 182 |
|
| 183 |
//function remove_language_wporlogin_css() |
| 184 |
remove_language_wporlogin_css(); |
| 185 |
|
| 186 |
wp_enqueue_style( 'wporlogin-style-design-basic', plugin_dir_url( __FILE__ ). 'css/wporlogin-style-design-basic.css', array(), '1.2', false ); |
| 187 |
|
| 188 |
} elseif (get_option('wporlogin_design') == 'wporlogin_design_standard'){ |
| 189 |
|
| 190 |
//function wporlogin_url_img_fondo_css() |
| 191 |
wporlogin_url_img_fondo_css(); |
| 192 |
//function wporlogin_url_logo_css() |
| 193 |
wporlogin_url_logo_css(); |
| 194 |
//function remove_language_wporlogin_css() |
| 195 |
remove_language_wporlogin_css(); |
| 196 |
|
| 197 |
wp_enqueue_style( 'wporlogin-style-design-standard', plugin_dir_url( __FILE__ ). 'css/wporlogin-style-design-standard.css', array(), '1.2', false ); |
| 198 |
|
| 199 |
} elseif (get_option('wporlogin_design') == 'wporlogin_design_premium'){ |
| 200 |
|
| 201 |
if(get_option('wporlogin-design-img-premium')) { |
| 202 |
|
| 203 |
if(get_option('wporlogin-design-img-premium') == 'wporlogin_design_img_premium_one'){ |
| 204 |
|
| 205 |
//function wporlogin_url_img_fondo_css() |
| 206 |
wporlogin_url_img_fondo_css(); |
| 207 |
//function wporlogin_url_logo_css() |
| 208 |
wporlogin_url_logo_css(); |
| 209 |
//function remove_language_wporlogin_css() |
| 210 |
remove_language_wporlogin_css(); |
| 211 |
|
| 212 |
wp_enqueue_style( 'wporlogin-style-design-premium-one', plugin_dir_url( __FILE__ ). 'css/wporlogin-style-design-premium-one.css', array(), '1.2', false ); |
| 213 |
|
| 214 |
} elseif (get_option('wporlogin-design-img-premium') == 'wporlogin_design_img_premium_two'){ |
| 215 |
|
| 216 |
//function wporlogin_url_img_fondo_css() |
| 217 |
wporlogin_url_img_fondo_css(); |
| 218 |
//function wporlogin_url_logo_css() |
| 219 |
wporlogin_url_logo_css(); |
| 220 |
//function remove_language_wporlogin_css() |
| 221 |
remove_language_wporlogin_css(); |
| 222 |
|
| 223 |
wp_enqueue_style( 'wporlogin-style-design-premium-two', plugin_dir_url( __FILE__ ). 'css/wporlogin-style-design-premium-two.css', array(), '1.2', false ); |
| 224 |
|
| 225 |
} elseif (get_option('wporlogin-design-img-premium') == 'wporlogin_design_img_premium_three'){ |
| 226 |
|
| 227 |
//function wporlogin_url_img_fondo_css() |
| 228 |
wporlogin_url_img_fondo_css(); |
| 229 |
//function wporlogin_url_logo_css() |
| 230 |
wporlogin_url_logo_css(); |
| 231 |
//function remove_language_wporlogin_css() |
| 232 |
remove_language_wporlogin_css(); |
| 233 |
|
| 234 |
wp_enqueue_style( 'wporlogin-style-design-premium-three', plugin_dir_url( __FILE__ ). 'css/wporlogin-style-design-premium-three.css', array(), '1.2', false ); |
| 235 |
|
| 236 |
} |
| 237 |
|
| 238 |
} |
| 239 |
|
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
//Cuando esta activo Google reCAPTCHA |
| 244 |
if(get_option( 'recaptcha_v2_wporlogin' ) == 1){ |
| 245 |
|
| 246 |
//script de ReCaptcha de Google |
| 247 |
//version 2.5 |
| 248 |
wp_register_script('recaptcha_login', 'https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit'); |
| 249 |
wp_enqueue_script('recaptcha_login'); |
| 250 |
|
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
} |
| 257 |
add_action('login_enqueue_scripts', 'wporlogin_page_login'); |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
// define the login_footer callback |
| 263 |
function wporlogin_add_menu_login_footer() { |
| 264 |
|
| 265 |
/////////////////////////////////////////////////////////////////////////////////////// |
| 266 |
// WP LOGIN: Si el Diseño es Premium |
| 267 |
/////////////////////////////////////////////////////////////////////////////////////// |
| 268 |
if(get_option('wporlogin_design') == 'wporlogin_design_premium'){ ?> |
| 269 |
|
| 270 |
<div class="login_oregoom"> |
| 271 |
|
| 272 |
Desarrollado por <a href="https://oregoom.com/wporlogin/" target="_black" class="text-info">Oregoom.com</a> |
| 273 |
|
| 274 |
</div> <?php |
| 275 |
|
| 276 |
} |
| 277 |
|
| 278 |
} |
| 279 |
add_action( 'login_footer', 'wporlogin_add_menu_login_footer', 10, 2 ); |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
/////////////////////////////////////////////////////////////////////////////////////// |
| 286 |
// WP LOGIN: CAMBIAR LA URL POR DEFECTO DEL LOGO - versión 1.0 |
| 287 |
/////////////////////////////////////////////////////////////////////////////////////// |
| 288 |
|
| 289 |
function wporlogin_mostrar_ruta_url_logotipo( $url ) { |
| 290 |
|
| 291 |
if(get_option("wporlogin_ruta_url_logotipo") ){ |
| 292 |
|
| 293 |
return esc_url(get_option('wporlogin_ruta_url_logotipo')); |
| 294 |
|
| 295 |
} else { |
| 296 |
|
| 297 |
if(get_option('wporlogin_design') == 'wporlogin_design_basic'){ |
| 298 |
|
| 299 |
//return home_url(); |
| 300 |
return get_bloginfo( 'url' ); |
| 301 |
|
| 302 |
} else { |
| 303 |
|
| 304 |
return $url; |
| 305 |
|
| 306 |
} |
| 307 |
|
| 308 |
} |
| 309 |
|
| 310 |
} |
| 311 |
add_filter('login_headerurl', 'wporlogin_mostrar_ruta_url_logotipo', 10, 1); |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
function wporlogin_mostrar_logotipo_title() { |
| 319 |
|
| 320 |
//////////////////////////////////////////////////////////////////////////// |
| 321 |
// WP LOGIN: CONDICIÓN PARA APLICAR CSS A PAGE LOGIN |
| 322 |
//////////////////////////////////////////////////////////////////////////// |
| 323 |
|
| 324 |
$wporlogin_design = get_option('wporlogin_design', false); |
| 325 |
|
| 326 |
if( ($wporlogin_design != false) && ($wporlogin_design == 'wporlogin_design_standard') ){ //Cuando existe diseño seleccionado |
| 327 |
|
| 328 |
if(get_option("wporlogin_titulo_logotipo")){ |
| 329 |
|
| 330 |
return esc_html(get_option('wporlogin_titulo_logotipo')); |
| 331 |
|
| 332 |
} |
| 333 |
|
| 334 |
} else { //cuando el diseño es Default |
| 335 |
|
| 336 |
if(isset($_GET['action'])){ |
| 337 |
|
| 338 |
$wporlogin_action = $_GET['action']; |
| 339 |
|
| 340 |
if($wporlogin_action == 'register'){ |
| 341 |
|
| 342 |
return __('Sign Up', 'wporlogin'); |
| 343 |
|
| 344 |
} else { |
| 345 |
|
| 346 |
if($wporlogin_action == 'lostpassword'){ |
| 347 |
|
| 348 |
return __('Reset Password', 'wporlogin'); |
| 349 |
|
| 350 |
} else { |
| 351 |
|
| 352 |
return __('Log In', 'wporlogin'); |
| 353 |
|
| 354 |
} |
| 355 |
|
| 356 |
} |
| 357 |
} else { |
| 358 |
|
| 359 |
return __('Log In', 'wporlogin'); |
| 360 |
|
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
} |
| 365 |
add_filter('login_headertext', 'wporlogin_mostrar_logotipo_title'); |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
/** |
| 371 |
* Cargar traducciones de texto |
| 372 |
* |
| 373 |
* @since 1.0.0 |
| 374 |
* |
| 375 |
*/ |
| 376 |
function wporlogin_textdomain() { |
| 377 |
load_plugin_textdomain( 'wporlogin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' ); |
| 378 |
} |
| 379 |
//Cargar traducciones de texto |
| 380 |
add_action( 'plugins_loaded', 'wporlogin_textdomain' ); |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
//Formulario reCaptcha de Google |
| 388 |
//FORMULARIO DE LOGIN |
| 389 |
|
| 390 |
//version 2.5 |
| 391 |
//fuente 1: https://stackoverflow.com/questions/54032404/how-to-integrate-recaptcha-into-default-login-form-comment-in-wordpress |
| 392 |
//fuente 2: https://stackoverflow.com/questions/54382995/wordpress-filter-wp-authenticate-user-not-getting-user-data |
| 393 |
add_action('login_form','add_captcha_to_login'); // Login Form Hook |
| 394 |
function add_captcha_to_login(){ |
| 395 |
|
| 396 |
if(get_option( 'recaptcha_v2_wporlogin' ) == 1){ |
| 397 |
|
| 398 |
if( get_option('recaptcha_v2_site_key_wporlogin') && get_option('recaptcha_v2_secret_key_wporlogin') ){ |
| 399 |
|
| 400 |
if(get_option('activa_acceso_recaptcha_v2_wporlogin') == 1){ |
| 401 |
|
| 402 |
$sitekey = get_option('recaptcha_v2_site_key_wporlogin'); ?> |
| 403 |
|
| 404 |
<script type="text/javascript"> |
| 405 |
var onloadCallback = function() { |
| 406 |
grecaptcha.render('html_element', { |
| 407 |
'sitekey' : '<?php echo $sitekey; ?>' |
| 408 |
}); |
| 409 |
}; |
| 410 |
</script><?php |
| 411 |
|
| 412 |
|
| 413 |
//Captcha Display Code ?> |
| 414 |
<div id="html_element" style="margin-bottom: 10px;"></div><?php |
| 415 |
|
| 416 |
} |
| 417 |
|
| 418 |
} |
| 419 |
|
| 420 |
} |
| 421 |
|
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
//Comprobando reCaptcha de Google |
| 427 |
//FORMULARIO DE LOGIN |
| 428 |
|
| 429 |
|
| 430 |
//version 2.5 |
| 431 |
add_filter('wp_authenticate_user', 'captcha_login_check', 10, 2); // Check Login Hook |
| 432 |
function captcha_login_check($user, $password){ |
| 433 |
|
| 434 |
if(get_option( 'recaptcha_v2_wporlogin' ) == 1){ |
| 435 |
|
| 436 |
if( get_option('recaptcha_v2_site_key_wporlogin') && get_option('recaptcha_v2_secret_key_wporlogin') ){ |
| 437 |
|
| 438 |
if( get_option('activa_acceso_recaptcha_v2_wporlogin') == 1 ){ |
| 439 |
|
| 440 |
//Captcha Check Code |
| 441 |
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){ |
| 442 |
// Google reCAPTCHA API secret key |
| 443 |
$secretKey = get_option('recaptcha_v2_secret_key_wporlogin'); |
| 444 |
|
| 445 |
// Verify the reCAPTCHA response |
| 446 |
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$_POST['g-recaptcha-response']); |
| 447 |
|
| 448 |
// Decode json data |
| 449 |
$responseData = json_decode($verifyResponse); |
| 450 |
|
| 451 |
// If reCAPTCHA response is valid |
| 452 |
if($responseData->success){ |
| 453 |
// Posted form data |
| 454 |
return $user; |
| 455 |
|
| 456 |
}else{ |
| 457 |
|
| 458 |
return new WP_Error("Captcha Invalid", __("<strong>ERROR</strong>: La verificación del robot falló, inténtelo de nuevo.")); |
| 459 |
|
| 460 |
} |
| 461 |
|
| 462 |
}else{ |
| 463 |
|
| 464 |
return new WP_Error("Captcha Invalid", __("<strong>ERROR</strong>: Por favor Marque la casilla reCAPTCHA.")); |
| 465 |
|
| 466 |
} |
| 467 |
|
| 468 |
} else { |
| 469 |
|
| 470 |
return $user; |
| 471 |
|
| 472 |
} |
| 473 |
|
| 474 |
} else { |
| 475 |
|
| 476 |
return $user; |
| 477 |
|
| 478 |
} |
| 479 |
|
| 480 |
} else { |
| 481 |
|
| 482 |
return $user; |
| 483 |
|
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
} |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
//Formulario de Registro WP |
| 493 |
// |
| 494 |
//Formulario reCaptcha de Google |
| 495 |
//version 2.5 |
| 496 |
//fuente 1: https://stackoverflow.com/questions/54032404/how-to-integrate-recaptcha-into-default-login-form-comment-in-wordpress |
| 497 |
//fuente 2: https://stackoverflow.com/questions/54382995/wordpress-filter-wp-authenticate-user-not-getting-user-data |
| 498 |
add_action('register_form','add_captcha_to_register'); // Register Form Hook |
| 499 |
function add_captcha_to_register(){ |
| 500 |
|
| 501 |
if(get_option( 'recaptcha_v2_wporlogin' ) == 1){ |
| 502 |
|
| 503 |
if( get_option('recaptcha_v2_site_key_wporlogin') && get_option('recaptcha_v2_secret_key_wporlogin') ){ |
| 504 |
|
| 505 |
if(get_option('activa_registro_recaptcha_v2_wporlogin') == 1){ |
| 506 |
|
| 507 |
$sitekey = get_option('recaptcha_v2_site_key_wporlogin'); ?> |
| 508 |
|
| 509 |
<script type="text/javascript"> |
| 510 |
var onloadCallback = function() { |
| 511 |
grecaptcha.render('html_element', { |
| 512 |
'sitekey' : '<?php echo $sitekey; ?>' |
| 513 |
}); |
| 514 |
}; |
| 515 |
</script><?php |
| 516 |
|
| 517 |
//Captcha Display Code ?> |
| 518 |
<div id="html_element" style="margin-bottom: 10px;"></div><?php |
| 519 |
|
| 520 |
} |
| 521 |
|
| 522 |
} |
| 523 |
|
| 524 |
} |
| 525 |
|
| 526 |
} |
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
//Comprobando reCaptcha de Google |
| 532 |
//FORMULARIO DE REGISTRO |
| 533 |
|
| 534 |
//version 2.5 |
| 535 |
add_filter('registration_errors', 'recaptcha_user_register_check', 10, 3); // Check register user Hook |
| 536 |
function recaptcha_user_register_check($errors, $sanitized_user_login, $user_email){ |
| 537 |
|
| 538 |
if(get_option( 'recaptcha_v2_wporlogin' ) == 1){ |
| 539 |
|
| 540 |
if( get_option('recaptcha_v2_site_key_wporlogin') && get_option('recaptcha_v2_secret_key_wporlogin') ){ |
| 541 |
|
| 542 |
if(get_option('activa_registro_recaptcha_v2_wporlogin') == 1){ |
| 543 |
|
| 544 |
//Captcha Check Code |
| 545 |
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){ |
| 546 |
// Google reCAPTCHA API secret key |
| 547 |
$secretKey = get_option('recaptcha_v2_secret_key_wporlogin'); |
| 548 |
|
| 549 |
// Verify the reCAPTCHA response |
| 550 |
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$_POST['g-recaptcha-response']); |
| 551 |
|
| 552 |
// Decode json data |
| 553 |
$responseData = json_decode($verifyResponse); |
| 554 |
|
| 555 |
// If reCAPTCHA response is valid |
| 556 |
if($responseData->success){ |
| 557 |
// Posted form data |
| 558 |
return $errors; |
| 559 |
|
| 560 |
}else{ |
| 561 |
|
| 562 |
$errors->add( 'captcha_error', __( '<strong>Error</strong>: La verificación del robot falló, inténtelo de nuevo.', 'my_textdomain' ) ); |
| 563 |
return $errors; |
| 564 |
|
| 565 |
} |
| 566 |
|
| 567 |
}else{ |
| 568 |
|
| 569 |
$errors->add( 'captcha_error', __( '<strong>Error</strong>: Por favor Marque la casilla reCAPTCHA.', 'my_textdomain' ) ); |
| 570 |
return $errors; |
| 571 |
|
| 572 |
} |
| 573 |
|
| 574 |
} else { |
| 575 |
|
| 576 |
return $errors; |
| 577 |
|
| 578 |
} |
| 579 |
|
| 580 |
} else { |
| 581 |
|
| 582 |
return $errors; |
| 583 |
|
| 584 |
} |
| 585 |
|
| 586 |
} else { |
| 587 |
|
| 588 |
return $errors; |
| 589 |
|
| 590 |
} |
| 591 |
|
| 592 |
} |