Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.33 KB | None | 0 0
  1. public static function plugin_activated() {
  2. // Information needed for creating the plugin's pages
  3. $page_definitions = array(
  4. 'member-login' => array(
  5. 'title' => __( 'Sign In', 'personalize-login' ),
  6. 'content' => '[custom-login-form]'
  7. ),
  8. 'member-account' => array(
  9. 'title' => __( 'Your Account', 'personalize-login' ),
  10. 'content' => '[account-info]'
  11. ),
  12. 'member-register' => array(
  13. 'title' => __( 'Register', 'personalize-login' ),
  14. 'content' => '[custom-register-form]'
  15. ),
  16. 'member-password-lost' => array(
  17. 'title' => __( 'Forgot Your Password?', 'personalize-login' ),
  18. 'content' => '[custom-password-lost-form]'
  19. ),
  20. 'member-password-reset' => array(
  21. 'title' => __( 'Pick a New Password', 'personalize-login' ),
  22. 'content' => '[custom-password-reset-form]'
  23. )
  24. );
  25.  
  26. foreach ( $page_definitions as $slug => $page ) {
  27. // Check that the page doesn't exist already
  28. $query = new WP_Query( 'pagename=' . $slug );
  29. if ( ! $query->have_posts() ) {
  30. // Add the page using the data from the array above
  31. wp_insert_post(
  32. array(
  33. 'post_content' => $page['content'],
  34. 'post_name' => $slug,
  35. 'post_title' => $page['title'],
  36. 'post_status' => 'publish',
  37. 'post_type' => 'page',
  38. 'ping_status' => 'closed',
  39. 'comment_status' => 'closed',
  40. )
  41. );
  42. }
  43. }
  44. }
  45.  
  46. //
  47. // REDIRECT FUNCTIONS
  48. //
  49.  
  50. /**
  51. * Redirect the user to the custom login page instead of wp-login.php.
  52. */
  53. public function redirect_to_custom_login() {
  54. if ( $_SERVER['REQUEST_METHOD'] == 'GET' ) {
  55. if ( is_user_logged_in() ) {
  56. $this->redirect_logged_in_user();
  57. exit;
  58. }
  59.  
  60. // The rest are redirected to the login page
  61. $login_url = home_url( 'member-login' );
  62. if ( ! empty( $_REQUEST['redirect_to'] ) ) {
  63. $login_url = add_query_arg( 'redirect_to', $_REQUEST['redirect_to'], $login_url );
  64. }
  65.  
  66. if ( ! empty( $_REQUEST['checkemail'] ) ) {
  67. $login_url = add_query_arg( 'checkemail', $_REQUEST['checkemail'], $login_url );
  68. }
  69.  
  70. wp_redirect( $login_url );
  71. exit;
  72. }
  73. }
  74.  
  75. /**
  76. * Redirect the user after authentication if there were any errors.
  77. *
  78. * @param Wp_User|Wp_Error $user The signed in user, or the errors that have occurred during login.
  79. * @param string $username The user name used to log in.
  80. * @param string $password The password used to log in.
  81. *
  82. * @return Wp_User|Wp_Error The logged in user, or error information if there were errors.
  83. */
  84. public function maybe_redirect_at_authenticate( $user, $username, $password ) {
  85. // Check if the earlier authenticate filter (most likely,
  86. // the default WordPress authentication) functions have found errors
  87. if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
  88. if ( is_wp_error( $user ) ) {
  89. $error_codes = join( ',', $user->get_error_codes() );
  90.  
  91. $login_url = home_url( 'member-login' );
  92. $login_url = add_query_arg( 'login', $error_codes, $login_url );
  93.  
  94. wp_redirect( $login_url );
  95. exit;
  96. }
  97. }
  98.  
  99. return $user;
  100. }
  101.  
  102. /**
  103. * Returns the URL to which the user should be redirected after the (successful) login.
  104. *
  105. * @param string $redirect_to The redirect destination URL.
  106. * @param string $requested_redirect_to The requested redirect destination URL passed as a parameter.
  107. * @param WP_User|WP_Error $user WP_User object if login was successful, WP_Error object otherwise.
  108. *
  109. * @return string Redirect URL
  110. */
  111. public function redirect_after_login( $redirect_to, $requested_redirect_to, $user ) {
  112. $redirect_url = home_url();
  113.  
  114. if ( ! isset( $user->ID ) ) {
  115. return $redirect_url;
  116. }
  117.  
  118. if ( user_can( $user, 'manage_options' ) ) {
  119. // Use the redirect_to parameter if one is set, otherwise redirect to admin dashboard.
  120. if ( $requested_redirect_to == '' ) {
  121. $redirect_url = admin_url();
  122. } else {
  123. $redirect_url = $redirect_to;
  124. }
  125. } else {
  126. // Non-admin users always go to their account page after login
  127. $redirect_url = home_url( 'member-account' );
  128. }
  129.  
  130. return wp_validate_redirect( $redirect_url, home_url() );
  131. }
  132.  
  133.  
  134. public function redirect_after_logout() {
  135. $redirect_url = home_url( 'member-login?logged_out=true' );
  136. wp_redirect( $redirect_url );
  137. exit;
  138. }
  139.  
  140. public function redirect_to_custom_register() {
  141. if ( 'GET' == $_SERVER['REQUEST_METHOD'] ) {
  142. if ( is_user_logged_in() ) {
  143. $this->redirect_logged_in_user();
  144. } else {
  145. wp_redirect( home_url( 'member-register' ) );
  146. }
  147. exit;
  148. }
  149. }
  150.  
  151. /**
  152. * Redirects the user to the custom "Forgot your password?" page instead of
  153. * wp-login.php?action=lostpassword.
  154. */
  155. public function redirect_to_custom_lostpassword() {
  156. if ( 'GET' == $_SERVER['REQUEST_METHOD'] ) {
  157. if ( is_user_logged_in() ) {
  158. $this->redirect_logged_in_user();
  159. exit;
  160. }
  161.  
  162. wp_redirect( home_url( 'member-password-lost' ) );
  163. exit;
  164. }
  165. }
  166.  
  167. /**
  168. * Redirects to the custom password reset page, or the login page
  169. * if there are errors.
  170. */
  171. public function redirect_to_custom_password_reset() {
  172. if ( 'GET' == $_SERVER['REQUEST_METHOD'] ) {
  173. // Verify key / login combo
  174. $user = check_password_reset_key( $_REQUEST['key'], $_REQUEST['login'] );
  175. if ( ! $user || is_wp_error( $user ) ) {
  176. if ( $user && $user->get_error_code() === 'expired_key' ) {
  177. wp_redirect( home_url( 'member-login?login=expiredkey' ) );
  178. } else {
  179. wp_redirect( home_url( 'member-login?login=invalidkey' ) );
  180. }
  181. exit;
  182. }
  183.  
  184. $redirect_url = home_url( 'member-password-reset' );
  185. $redirect_url = add_query_arg( 'login', esc_attr( $_REQUEST['login'] ), $redirect_url );
  186. $redirect_url = add_query_arg( 'key', esc_attr( $_REQUEST['key'] ), $redirect_url );
  187.  
  188. wp_redirect( $redirect_url );
  189. exit;
  190. }
  191. }
  192.  
  193.  
  194. //
  195. // FORM RENDERING SHORTCODES
  196. //
  197.  
  198. /**
  199. * A shortcode for rendering the login form.
  200. *
  201. * @param array $attributes Shortcode attributes.
  202. * @param string $content The text content for shortcode. Not used.
  203. *
  204. * @return string The shortcode output
  205. */
  206. public function render_login_form( $attributes, $content = null ) {
  207. // Parse shortcode attributes
  208. $default_attributes = array( 'show_title' => false );
  209. $attributes = shortcode_atts( $default_attributes, $attributes );
  210.  
  211. if ( is_user_logged_in() ) {
  212. return __( 'You are already signed in.', 'personalize-login' );
  213. }
  214.  
  215. // Pass the redirect parameter to the WordPress login functionality: by default,
  216. // don't specify a redirect, but if a valid redirect URL has been passed as
  217. // request parameter, use it.
  218. $attributes['redirect'] = '';
  219. if ( isset( $_REQUEST['redirect_to'] ) ) {
  220. $attributes['redirect'] = wp_validate_redirect( $_REQUEST['redirect_to'], $attributes['redirect'] );
  221. }
  222.  
  223. // Error messages
  224. $errors = array();
  225. if ( isset( $_REQUEST['login'] ) ) {
  226. $error_codes = explode( ',', $_REQUEST['login'] );
  227.  
  228. foreach ( $error_codes as $code ) {
  229. $errors []= $this->get_error_message( $code );
  230. }
  231. }
  232. $attributes['errors'] = $errors;
  233.  
  234. // Check if user just logged out
  235. $attributes['logged_out'] = isset( $_REQUEST['logged_out'] ) && $_REQUEST['logged_out'] == true;
  236.  
  237. // Check if the user just registered
  238. $attributes['registered'] = isset( $_REQUEST['registered'] );
  239.  
  240. // Check if the user just requested a new password
  241. $attributes['lost_password_sent'] = isset( $_REQUEST['checkemail'] ) && $_REQUEST['checkemail'] == 'confirm';
  242.  
  243. // Check if user just updated password
  244. $attributes['password_updated'] = isset( $_REQUEST['password'] ) && $_REQUEST['password'] == 'changed';
  245.  
  246. // Render the login form using an external template
  247. return $this->get_template_html( 'login_form', $attributes );
  248. }
  249.  
  250. /**
  251. * A shortcode for rendering the new user registration form.
  252. *
  253. * @param array $attributes Shortcode attributes.
  254. * @param string $content The text content for shortcode. Not used.
  255. *
  256. * @return string The shortcode output
  257. */
  258. public function render_register_form( $attributes, $content = null ) {
  259. // Parse shortcode attributes
  260. $default_attributes = array( 'show_title' => false );
  261. $attributes = shortcode_atts( $default_attributes, $attributes );
  262.  
  263. if ( is_user_logged_in() ) {
  264. return __( 'You are already signed in.', 'personalize-login' );
  265. } elseif ( ! get_option( 'users_can_register' ) ) {
  266. return __( 'Registering new users is currently not allowed.', 'personalize-login' );
  267. } else {
  268. // Retrieve possible errors from request parameters
  269. $attributes['errors'] = array();
  270. if ( isset( $_REQUEST['register-errors'] ) ) {
  271. $error_codes = explode( ',', $_REQUEST['register-errors'] );
  272.  
  273. foreach ( $error_codes as $error_code ) {
  274. $attributes['errors'] []= $this->get_error_message( $error_code );
  275. }
  276. }
  277.  
  278. // Retrieve recaptcha key
  279. $attributes['recaptcha_site_key'] = get_option( 'personalize-login-recaptcha-site-key', null );
  280.  
  281. return $this->get_template_html( 'register_form', $attributes );
  282. }
  283. }
  284.  
  285. /**
  286. * A shortcode for rendering the form used to initiate the password reset.
  287. *
  288. * @param array $attributes Shortcode attributes.
  289. * @param string $content The text content for shortcode. Not used.
  290. *
  291. * @return string The shortcode output
  292. */
  293. public function render_password_lost_form( $attributes, $content = null ) {
  294. // Parse shortcode attributes
  295. $default_attributes = array( 'show_title' => false );
  296. $attributes = shortcode_atts( $default_attributes, $attributes );
  297.  
  298. if ( is_user_logged_in() ) {
  299. return __( 'You are already signed in.', 'personalize-login' );
  300. } else {
  301. // Retrieve possible errors from request parameters
  302. $attributes['errors'] = array();
  303. if ( isset( $_REQUEST['errors'] ) ) {
  304. $error_codes = explode( ',', $_REQUEST['errors'] );
  305.  
  306. foreach ( $error_codes as $error_code ) {
  307. $attributes['errors'] []= $this->get_error_message( $error_code );
  308. }
  309. }
  310.  
  311. return $this->get_template_html( 'password_lost_form', $attributes );
  312. }
  313. }
  314.  
  315. /**
  316. * A shortcode for rendering the form used to reset a user's password.
  317. *
  318. * @param array $attributes Shortcode attributes.
  319. * @param string $content The text content for shortcode. Not used.
  320. *
  321. * @return string The shortcode output
  322. */
  323. public function render_password_reset_form( $attributes, $content = null ) {
  324. // Parse shortcode attributes
  325. $default_attributes = array( 'show_title' => false );
  326. $attributes = shortcode_atts( $default_attributes, $attributes );
  327.  
  328. if ( is_user_logged_in() ) {
  329. return __( 'You are already signed in.', 'personalize-login' );
  330. } else {
  331. if ( isset( $_REQUEST['login'] ) && isset( $_REQUEST['key'] ) ) {
  332. $attributes['login'] = $_REQUEST['login'];
  333. $attributes['key'] = $_REQUEST['key'];
  334.  
  335. // Error messages
  336. $errors = array();
  337. if ( isset( $_REQUEST['error'] ) ) {
  338. $error_codes = explode( ',', $_REQUEST['error'] );
  339.  
  340. foreach ( $error_codes as $code ) {
  341. $errors []= $this->get_error_message( $code );
  342. }
  343. }
  344. $attributes['errors'] = $errors;
  345.  
  346. return $this->get_template_html( 'password_reset_form', $attributes );
  347. } else {
  348. return __( 'Invalid password reset link.', 'personalize-login' );
  349. }
  350. }
  351. }
  352.  
  353. /**
  354. * An action function used to include the reCAPTCHA JavaScript file
  355. * at the end of the page.
  356. */
  357. public function add_captcha_js_to_footer() {
  358. echo "<script src='https://www.google.com/recaptcha/api.js?hl=en'></script>";
  359. }
  360.  
  361. /**
  362. * Renders the contents of the given template to a string and returns it.
  363. *
  364. * @param string $template_name The name of the template to render (without .php)
  365. * @param array $attributes The PHP variables for the template
  366. *
  367. * @return string The contents of the template.
  368. */
  369. private function get_template_html( $template_name, $attributes = null ) {
  370. if ( ! $attributes ) {
  371. $attributes = array();
  372. }
  373.  
  374. ob_start();
  375.  
  376. do_action( 'personalize_login_before_' . $template_name );
  377.  
  378. require( 'templates/' . $template_name . '.php');
  379.  
  380. do_action( 'personalize_login_after_' . $template_name );
  381.  
  382. $html = ob_get_contents();
  383. ob_end_clean();
  384.  
  385. return $html;
  386. }
  387.  
  388.  
  389. //
  390. // ACTION HANDLERS FOR FORMS IN FLOW
  391. //
  392.  
  393. /**
  394. * Handles the registration of a new user.
  395. *
  396. * Used through the action hook "login_form_register" activated on wp-login.php
  397. * when accessed through the registration action.
  398. */
  399. public function do_register_user() {
  400. if ( 'POST' == $_SERVER['REQUEST_METHOD'] ) {
  401. $redirect_url = home_url( 'member-register' );
  402.  
  403. if ( ! get_option( 'users_can_register' ) ) {
  404. // Registration closed, display error
  405. $redirect_url = add_query_arg( 'register-errors', 'closed', $redirect_url );
  406. } elseif ( ! $this->verify_recaptcha() ) {
  407. // Recaptcha check failed, display error
  408. $redirect_url = add_query_arg( 'register-errors', 'captcha', $redirect_url );
  409. } else {
  410. $email = $_POST['email'];
  411. $first_name = sanitize_text_field( $_POST['first_name'] );
  412. $last_name = sanitize_text_field( $_POST['last_name'] );
  413.  
  414. $result = $this->register_user( $email, $first_name, $last_name );
  415.  
  416. if ( is_wp_error( $result ) ) {
  417. // Parse errors into a string and append as parameter to redirect
  418. $errors = join( ',', $result->get_error_codes() );
  419. $redirect_url = add_query_arg( 'register-errors', $errors, $redirect_url );
  420. } else {
  421. // Success, redirect to login page.
  422. $redirect_url = home_url( 'member-login' );
  423. $redirect_url = add_query_arg( 'registered', $email, $redirect_url );
  424. }
  425. }
  426.  
  427. wp_redirect( $redirect_url );
  428. exit;
  429. }
  430. }
  431.  
  432. /**
  433. * Initiates password reset.
  434. */
  435. public function do_password_lost() {
  436. if ( 'POST' == $_SERVER['REQUEST_METHOD'] ) {
  437. $errors = retrieve_password();
  438. if ( is_wp_error( $errors ) ) {
  439. // Errors found
  440. $redirect_url = home_url( 'member-password-lost' );
  441. $redirect_url = add_query_arg( 'errors', join( ',', $errors->get_error_codes() ), $redirect_url );
  442. } else {
  443. // Email sent
  444. $redirect_url = home_url( 'member-login' );
  445. $redirect_url = add_query_arg( 'checkemail', 'confirm', $redirect_url );
  446. if ( ! empty( $_REQUEST['redirect_to'] ) ) {
  447. $redirect_url = $_REQUEST['redirect_to'];
  448. }
  449. }
  450.  
  451. wp_safe_redirect( $redirect_url );
  452. exit;
  453. }
  454. }
  455.  
  456. /**
  457. * Resets the user's password if the password reset form was submitted.
  458. */
  459. public function do_password_reset() {
  460. if ( 'POST' == $_SERVER['REQUEST_METHOD'] ) {
  461. $rp_key = $_REQUEST['rp_key'];
  462. $rp_login = $_REQUEST['rp_login'];
  463.  
  464. $user = check_password_reset_key( $rp_key, $rp_login );
  465.  
  466. if ( ! $user || is_wp_error( $user ) ) {
  467. if ( $user && $user->get_error_code() === 'expired_key' ) {
  468. wp_redirect( home_url( 'member-login?login=expiredkey' ) );
  469. } else {
  470. wp_redirect( home_url( 'member-login?login=invalidkey' ) );
  471. }
  472. exit;
  473. }
  474. if ( strlen( $_POST['pass1'] ) < 3 )
  475. {
  476. //passwords so small
  477. $redirect_url = home_url( 'member-password-reset' );
  478. $redirect_url = add_query_arg( 'error', 'password_reset_mismatch1', $redirect_url );
  479. }
  480.  
  481.  
  482. if ( isset( $_POST['pass1'] ) ) {
  483. if ( $_POST['pass1'] != $_POST['pass2'] ) {
  484. // Passwords don't match
  485. $redirect_url = home_url( 'member-password-reset' );
  486.  
  487. $redirect_url = add_query_arg( 'key', $rp_key, $redirect_url );
  488. $redirect_url = add_query_arg( 'login', $rp_login, $redirect_url );
  489. $redirect_url = add_query_arg( 'error', 'password_reset_mismatch', $redirect_url );
  490.  
  491. wp_redirect( $redirect_url );
  492. exit;
  493. }
  494.  
  495. if ( empty( $_POST['pass1'] ) ) {
  496. // Password is empty
  497. $redirect_url = home_url( 'member-password-reset' );
  498.  
  499. $redirect_url = add_query_arg( 'key', $rp_key, $redirect_url );
  500. $redirect_url = add_query_arg( 'login', $rp_login, $redirect_url );
  501. $redirect_url = add_query_arg( 'error', 'password_reset_empty', $redirect_url );
  502.  
  503. wp_redirect( $redirect_url );
  504. exit;
  505.  
  506. }
  507.  
  508. // Parameter checks OK, reset password
  509. reset_password( $user, $_POST['pass1'] );
  510. wp_redirect( home_url( 'member-login?password=changed' ) );
  511. } else {
  512. echo "Invalid request.";
  513. }
  514.  
  515. exit;
  516. }
  517. }
  518.  
  519.  
  520. //
  521. // OTHER CUSTOMIZATIONS
  522. //
  523.  
  524. /**
  525. * Returns the message body for the password reset mail.
  526. * Called through the retrieve_password_message filter.
  527. *
  528. * @param string $message Default mail message.
  529. * @param string $key The activation key.
  530. * @param string $user_login The username for the user.
  531. * @param WP_User $user_data WP_User object.
  532. *
  533. * @return string The mail message to send.
  534. */
  535. public function replace_retrieve_password_message( $message, $key, $user_login, $user_data ) {
  536. // Create new message
  537. $msg = __( 'Hello!', 'personalize-login' ) . "rnrn";
  538. $msg .= sprintf( __( 'You asked us to reset your password for your account using the email address %s.', 'personalize-login' ), $user_login ) . "rnrn";
  539. $msg .= __( "If this was a mistake, or you didn't ask for a password reset, just ignore this email and nothing will happen.", 'personalize-login' ) . "rnrn";
  540. $msg .= __( 'To reset your password, visit the following address:', 'personalize-login' ) . "rnrn";
  541. $msg .= site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . "rnrn";
  542. $msg .= __( 'Thanks!', 'personalize-login' ) . "rn";
  543.  
  544. return $msg;
  545. }
  546.  
  547.  
  548. //
  549. // HELPER FUNCTIONS
  550. //
  551.  
  552. /**
  553. * Validates and then completes the new user signup process if all went well.
  554. *
  555. * @param string $email The new user's email address
  556. * @param string $first_name The new user's first name
  557. * @param string $last_name The new user's last name
  558. *
  559. * @return int|WP_Error The id of the user that was created, or error if failed.
  560. */
  561. private function register_user( $email, $first_name, $last_name ) {
  562. $errors = new WP_Error();
  563.  
  564. // Email address is used as both username and email. It is also the only
  565. // parameter we need to validate
  566. if ( ! is_email( $email ) ) {
  567. $errors->add( 'email', $this->get_error_message( 'email' ) );
  568. return $errors;
  569. }
  570.  
  571. if ( username_exists( $email ) || email_exists( $email ) ) {
  572. $errors->add( 'email_exists', $this->get_error_message( 'email_exists') );
  573. return $errors;
  574. }
  575.  
  576. // Generate the password so that the subscriber will have to check email...
  577. $password = wp_generate_password( 12, false );
  578.  
  579. $user_data = array(
  580. 'user_login' => $email,
  581. 'user_email' => $email,
  582. 'user_pass' => $password,
  583. 'first_name' => $first_name,
  584. 'last_name' => $last_name,
  585. 'nickname' => $first_name,
  586. );
  587.  
  588. $user_id = wp_insert_user( $user_data );
  589. wp_new_user_notification( $user_id, $password );
  590.  
  591. return $user_id;
  592. }
  593.  
  594. /**
  595. * Checks that the reCAPTCHA parameter sent with the registration
  596. * request is valid.
  597. *
  598. * @return bool True if the CAPTCHA is OK, otherwise false.
  599. */
  600. private function verify_recaptcha() {
  601. // This field is set by the recaptcha widget if check is successful
  602. if ( isset ( $_POST['g-recaptcha-response'] ) ) {
  603. $captcha_response = $_POST['g-recaptcha-response'];
  604. } else {
  605. return false;
  606. }
  607.  
  608. // Verify the captcha response from Google
  609. $response = wp_remote_post(
  610. 'https://www.google.com/recaptcha/api/siteverify',
  611. array(
  612. 'body' => array(
  613. 'secret' => get_option( 'personalize-login-recaptcha-secret-key' ),
  614. 'response' => $captcha_response
  615. )
  616. )
  617. );
  618.  
  619. $success = false;
  620. if ( $response && is_array( $response ) ) {
  621. $decoded_response = json_decode( $response['body'] );
  622. $success = $decoded_response->success;
  623. }
  624.  
  625. return $success;
  626. }
  627.  
  628. /**
  629. * Redirects the user to the correct page depending on whether he / she
  630. * is an admin or not.
  631. *
  632. * @param string $redirect_to An optional redirect_to URL for admin users
  633. */
  634. private function redirect_logged_in_user( $redirect_to = null ) {
  635. $user = wp_get_current_user();
  636. if ( user_can( $user, 'manage_options' ) ) {
  637. if ( $redirect_to ) {
  638. wp_safe_redirect( $redirect_to );
  639. } else {
  640. wp_redirect( admin_url() );
  641. }
  642. } else {
  643. wp_redirect( home_url( 'member-account' ) );
  644. }
  645. }
  646.  
  647. /**
  648. * Finds and returns a matching error message for the given error code.
  649. *
  650. * @param string $error_code The error code to look up.
  651. *
  652. * @return string An error message.
  653. */
  654. private function get_error_message( $error_code ) {
  655. switch ( $error_code ) {
  656. // Login errors
  657.  
  658. case 'empty_username':
  659. return __( 'You do have an email address, right?', 'personalize-login' );
  660.  
  661. case 'empty_password':
  662. return __( 'You need to enter a password to login.', 'personalize-login' );
  663.  
  664. case 'invalid_username':
  665. return __(
  666. "We don't have any users with that email address. Maybe you used a different one when signing up?",
  667. 'personalize-login'
  668. );
  669.  
  670. case 'incorrect_password':
  671. $err = __(
  672. "The password you entered wasn't quite right. <a href='%s'>Did you forget your password</a>?",
  673. 'personalize-login'
  674. );
  675. return sprintf( $err, wp_lostpassword_url() );
  676.  
  677. // Registration errors
  678.  
  679. case 'email':
  680. return __( 'The email address you entered is not valid.', 'personalize-login' );
  681.  
  682. case 'email_exists':
  683. return __( 'An account exists with this email address.', 'personalize-login' );
  684.  
  685. case 'closed':
  686. return __( 'Registering new users is currently not allowed.', 'personalize-login' );
  687.  
  688. case 'captcha':
  689. return __( 'The Google reCAPTCHA check failed. Are you a robot?', 'personalize-login' );
  690.  
  691. // Lost password
  692.  
  693. case 'empty_username':
  694. return __( 'You need to enter your email address to continue.', 'personalize-login' );
  695.  
  696. case 'invalid_email':
  697. case 'invalidcombo':
  698. return __( 'There are no users registered with this email address.', 'personalize-login' );
  699.  
  700. // Reset password
  701.  
  702. case 'expiredkey':
  703. case 'invalidkey':
  704. return __( 'The password reset link you used is not valid anymore.', 'personalize-login' );
  705.  
  706. case 'password_reset_mismatch':
  707. return __( "The two passwords you entered don't match.", 'personalize-login' );
  708. case 'password_reset_mismatch1':
  709. return __( "The two passwords you entered are short.", 'personalize-login' );
  710. case 'password_reset_mismatch1':
  711. return("the password are two small");
  712.  
  713.  
  714. case 'password_reset_empty':
  715. return __( "Sorry, we don't accept empty passwords.", 'personalize-login' );
  716.  
  717. default:
  718. break;
  719. }
  720.  
  721. return __( 'An unknown error occurred. Please try again later.', 'personalize-login' );
  722. }
  723.  
  724.  
  725. //
  726. // PLUGIN SETUP
  727. //
  728.  
  729. /**
  730. * Registers the settings fields needed by the plugin.
  731. */
  732. public function register_settings_fields() {
  733. // Create settings fields for the two keys used by reCAPTCHA
  734. register_setting( 'general', 'personalize-login-recaptcha-site-key' );
  735. register_setting( 'general', 'personalize-login-recaptcha-secret-key' );
  736.  
  737. add_settings_field(
  738. 'personalize-login-recaptcha-site-key',
  739. '<label for="personalize-login-recaptcha-site-key">' . __( 'reCAPTCHA site key' , 'personalize-login' ) . '</label>',
  740. array( $this, 'render_recaptcha_site_key_field' ),
  741. 'general'
  742. );
  743.  
  744. add_settings_field(
  745. 'personalize-login-recaptcha-secret-key',
  746. '<label for="personalize-login-recaptcha-secret-key">' . __( 'reCAPTCHA secret key' , 'personalize-login' ) . '</label>',
  747. array( $this, 'render_recaptcha_secret_key_field' ),
  748. 'general'
  749. );
  750. }
  751.  
  752. public function render_recaptcha_site_key_field() {
  753. $value = get_option( 'personalize-login-recaptcha-site-key', '' );
  754. echo '<input type="text" id="personalize-login-recaptcha-site-key" name="personalize-login-recaptcha-site-key" value="' . esc_attr( $value ) . '" />';
  755. }
  756.  
  757. public function render_recaptcha_secret_key_field() {
  758. $value = get_option( 'personalize-login-recaptcha-secret-key', '' );
  759. echo '<input type="text" id="personalize-login-recaptcha-secret-key" name="personalize-login-recaptcha-secret-key" value="' . esc_attr( $value ) . '" />';
  760. }
  761.  
  762. }
  763.  
  764. // Initialize the plugin
  765. $personalize_login_pages_plugin = new Personalize_Login_Plugin();
  766.  
  767. // Create the custom pages at plugin activation
  768. register_activation_hook( __FILE__, array( 'Personalize_Login_Plugin', 'plugin_activated' ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement