Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.90 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Our core class.
  5. *
  6. * This contains all the cool jazz that makes this plugin work.
  7. *
  8. * @version 2.0.5.2
  9. * @since 1.0
  10. */
  11. class Geissinger_WP_Modal_Login {
  12.  
  13. // Set the version number
  14. public $plugin_version = '2.0.6';
  15.  
  16.  
  17. /**
  18. * Loads all of our required hooks and filters and other cool doodads.
  19. *
  20. * @version 1.2
  21. * @since 1.0
  22. */
  23. public function __construct() {
  24. global $wpml_settings;
  25.  
  26. // Register our source code with the wp_footer().
  27. add_action( 'wp_footer', array( $this, 'login_form' ) );
  28.  
  29. // Add our JavaScript and Stylesheets to the front-end.
  30. add_action( 'wp_enqueue_scripts', array( $this, 'print_resources' ) );
  31.  
  32. // Add the users custom CSS if they wish to add any.
  33. if ( isset( $wpml_settings['custom-css'] ) )
  34. add_action( 'wp_head', array( $this, 'print_custom_css' ) );
  35.  
  36. // Add our lost password field.
  37. add_action( 'after_wpml_form', array( $this, 'additional_options' ) );
  38.  
  39. // Add our shortcode action.
  40. add_shortcode( 'wp-modal-login', array( $this, 'modal_login_btn_shortcode' ) );
  41.  
  42. // Register our widget but only if the user has allowed the widget option.
  43. if ( isset( $wpml_settings['display-widget'] ) )
  44. add_action( 'widgets_init', create_function( '', 'register_widget( "Geissinger_WP_Modal_Login_Widget" );' ) );
  45.  
  46. // Allow us to run Ajax on the login.
  47. add_action( 'wp_ajax_nopriv_ajaxlogin', array( $this, 'ajax_login' ) );
  48. }
  49.  
  50.  
  51. /**
  52. * Add all of our scripts and styles with WordPress.
  53. * @return void
  54. *
  55. * @version 2.1
  56. * @since 1.0
  57. */
  58. public function print_resources() {
  59. global $wpml_settings;
  60.  
  61. $theme = $wpml_settings['modal-theme'];
  62.  
  63. wp_enqueue_style( 'wpml-styles', plugins_url( 'css/wp-modal-login.css', dirname( __FILE__ ) ), null, $this->plugin_version, 'screen' );
  64.  
  65. // Load the right Modal Theme
  66. if ( ! isset( $theme ) || $theme == 'default' ) {
  67. wp_enqueue_style( 'wpml-default-theme', plugins_url( 'css/default.css', dirname( __FILE__ ) ), null, $this->plugin_version, 'screen' );
  68. } elseif ( $theme == 'theme-1' ) {
  69. wp_enqueue_style( 'wpml-theme-1', plugins_url( 'css/theme-1.css', dirname( __FILE__ ) ), null, $this->plugin_version, 'screen' );
  70. } elseif ( $theme == 'theme-2' ) {
  71. wp_enqueue_style( 'wpml-theme-2', plugins_url( 'css/theme-2.css', dirname( __FILE__ ) ), null, $this->plugin_version, 'screen' );
  72. }
  73.  
  74. wp_enqueue_script( 'wpml-script', plugins_url( 'js/wp-modal-login.js', dirname( __FILE__ ) ), array( 'jquery' ), $this->plugin_version, true );
  75.  
  76. // Only run our ajax stuff when the user isn't logged in.
  77. // Change 'regurl' to redirect users post-registration
  78. if ( ! is_user_logged_in() ) {
  79.  
  80. wp_localize_script( 'wpml-script', 'wpml_script', array(
  81. 'ajax' => admin_url( 'admin-ajax.php' ),
  82. 'redirecturl' => apply_filters( 'wpml_redirect_to', $_SERVER['REQUEST_URI'] ),
  83. 'regurl' => apply_filters( 'wpml_redirect_to', 'http://www.EXAMPLE.com/path/' ),
  84. 'loadingmessage' => __( 'Checking Credentials...', 'geissinger-wpml' ),
  85. ) );
  86. }
  87. }
  88.  
  89. /**
  90. * Display any custom CSS that may be entered into the admin area
  91. * @return String
  92. *
  93. * @version 1.0.1
  94. * @since 2.0
  95. */
  96. public function print_custom_css() {
  97. global $wpml_settings;
  98.  
  99. echo '<style text="text/css">' . sanitize_text_field( $wpml_settings['custom-css'] ) . "</style>\n";
  100. }
  101.  
  102. /**
  103. * The main function behind a large section of the Ajax-y goodness.
  104. * @return void
  105. *
  106. * @version 1.1.2
  107. * @since 2.0
  108. */
  109. public function ajax_login() {
  110. // Check our nonce and make sure it's correct.
  111. check_ajax_referer( 'ajax-form-nonce', 'security' );
  112.  
  113. // Get our form data.
  114. $data = array();
  115.  
  116. // Check that we are submitting the login form
  117. if ( isset( $_REQUEST['login'] ) ) {
  118. $data['user_login'] = sanitize_user( $_REQUEST['username'] );
  119. $data['user_password'] = sanitize_text_field( $_REQUEST['password'] );
  120. $data['rememberme'] = sanitize_text_field( $_REQUEST['rememberme'] );
  121. $user_login = wp_signon( $data, false );
  122.  
  123. // Check the results of our login and provide the needed feedback
  124. if ( is_wp_error( $user_login ) ) {
  125. echo json_encode( array(
  126. 'loggedin' => false,
  127. 'message' => __( 'Wrong Username or Password!', 'geissinger-wpml' ),
  128. ) );
  129. } else {
  130. echo json_encode( array(
  131. 'loggedin' => true,
  132. 'message' => __( 'Login Successful!', 'geissinger-wpml' ),
  133. ) );
  134. }
  135. }
  136.  
  137. // Check if we are submitting the register form
  138. elseif ( isset( $_REQUEST['register'] ) ) {
  139. $user_data = array(
  140. 'user_login' => sanitize_user( $_REQUEST['username'] ),
  141. 'user_email' => sanitize_email( $_REQUEST['email'] ),
  142. );
  143. $user_register = $this->register_new_user( $user_data['user_login'], $user_data['user_email'] );
  144.  
  145. // Check if there were any issues with creating the new user
  146. if ( is_wp_error( $user_register ) ) {
  147. echo json_encode( array(
  148. 'registered' => false,
  149. 'message' => $user_register->get_error_message(),
  150. ) );
  151. } else {
  152. echo json_encode( array(
  153. 'registered' => true,
  154. 'message' => __( 'Registration complete. Please check your e-mail.', 'geissinger-wpml' ),
  155. ) );
  156. }
  157. }
  158.  
  159. // Check if we are submitting the forgotten pwd form
  160. elseif ( isset( $_REQUEST['forgotten'] ) ) {
  161.  
  162. // Check if we are sending an email or username and sanitize it appropriately
  163. if ( is_email( $_REQUEST['username'] ) ) {
  164. $username = sanitize_email( $_REQUEST['username'] );
  165. } else {
  166. $username = sanitize_user( $_REQUEST['username'] );
  167. }
  168.  
  169. // Send our information
  170. $user_forgotten = $this->retrieve_password( $username );
  171.  
  172. // Check if there were any errors when requesting a new password
  173. if ( is_wp_error( $user_forgotten ) ) {
  174. echo json_encode( array(
  175. 'reset' => false,
  176. 'message' => $user_forgotten->get_error_message(),
  177. ) );
  178. } else {
  179. echo json_encode( array(
  180. 'reset' => true,
  181. 'message' => __( 'Password Reset. Please check your email.', 'geissinger-wpml' ),
  182. ) );
  183. }
  184. }
  185.  
  186. die();
  187. }
  188.  
  189.  
  190. /**
  191. * When users register an account we want to sanitize the information and generate a new password, add to the database and email both the site admin and the new user account with an auto-generated password.
  192. * @param String $user_login The username to be set to the new user account
  193. * @param String $user_email The email to be set to the new user account
  194. * @return String
  195. *
  196. * @version 1.1
  197. * @since 2.0
  198. */
  199. function register_new_user( $user_login, $user_email ) {
  200. $errors = new WP_Error();
  201. $sanitized_user_login = sanitize_user( $user_login );
  202. $user_email = apply_filters( 'user_registration_email', $user_email );
  203.  
  204. // Check the username was sanitized
  205. if ( $sanitized_user_login == '' ) {
  206. $errors->add( 'empty_username', __( 'Please enter a username.', 'geissinger-wpml' ) );
  207. } elseif ( ! validate_username( $user_login ) ) {
  208. $errors->add( 'invalid_username', __( 'This username is invalid because it uses illegal characters. Please enter a valid username.', 'geissinger-wpml' ) );
  209. $sanitized_user_login = '';
  210. } elseif ( username_exists( $sanitized_user_login ) ) {
  211. $errors->add( 'username_exists', __( 'This username is already registered. Please choose another one.', 'geissinger-wpml' ) );
  212. }
  213.  
  214. // Check the e-mail address
  215. if ( $user_email == '' ) {
  216. $errors->add( 'empty_email', __( 'Please type your e-mail address.', 'geissinger-wpml' ) );
  217. } elseif ( ! is_email( $user_email ) ) {
  218. $errors->add( 'invalid_email', __( 'The email address isn\'t correct.', 'geissinger-wpml' ) );
  219. $user_email = '';
  220. } elseif ( email_exists( $user_email ) ) {
  221. $errors->add( 'email_exists', __( 'This email is already registered, please choose another one.', 'geissinger-wpml' ) );
  222. }
  223.  
  224. $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );
  225.  
  226. if ( $errors->get_error_code() )
  227. return $errors;
  228.  
  229. $user_pass = wp_generate_password( 12, false );
  230. $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email );
  231.  
  232. if ( ! $user_id ) {
  233. $errors->add( 'registerfail', __( 'Couldn\'t register you... please contact the site administrator', 'geissinger-wpml' ) );
  234.  
  235. return $errors;
  236. }
  237.  
  238. update_user_option( $user_id, 'default_password_nag', true, true ); // Set up the Password change nag.
  239.  
  240. wp_new_user_notification( $user_id, $user_pass );
  241.  
  242. return $user_id;
  243. }
  244.  
  245.  
  246. /**
  247. * Setup our password retrieve function for the users that need to reset their login password.
  248. * @param String $user_data The username or email we need to search for to reset the password.
  249. * @return Mixed
  250. *
  251. * @version 1.1
  252. * @since 2.0
  253. */
  254. function retrieve_password( $user_data ) {
  255. global $wpdb, $current_site;
  256.  
  257. $errors = new WP_Error();
  258.  
  259. if ( empty( $user_data ) ) {
  260. $errors->add( 'empty_username', __( 'Please enter a username or e-mail address.', 'geissinger-wpml' ) );
  261. } else if ( strpos( $user_data, '@' ) ) {
  262. $user_data = get_user_by( 'email', trim( $user_data ) );
  263. if ( empty( $user_data ) )
  264. $errors->add( 'invalid_email', __( 'There is no user registered with that email address.', 'geissinger-wpml' ) );
  265. } else {
  266. $login = trim( $user_data );
  267. $user_data = get_user_by( 'login', $login );
  268. }
  269.  
  270. do_action( 'lostpassword_post' );
  271.  
  272. if ( $errors->get_error_code() )
  273. return $errors;
  274.  
  275. if ( ! $user_data ) {
  276. $errors->add( 'invalidcombo', __( 'Invalid username or e-mail.', 'geissinger-wpml' ) );
  277. return $errors;
  278. }
  279.  
  280. // redefining user_login ensures we return the right case in the email
  281. $user_login = $user_data->user_login;
  282. $user_email = $user_data->user_email;
  283.  
  284. do_action( 'retreive_password', $user_login ); // Misspelled and deprecated
  285. do_action( 'retrieve_password', $user_login );
  286.  
  287. $allow = apply_filters( 'allow_password_reset', true, $user_data->ID );
  288.  
  289. if ( ! $allow )
  290. return new WP_Error( 'no_password_reset', __( 'Password reset is not allowed for this user', 'geissinger-wpml' ) );
  291. else if ( is_wp_error( $allow ) )
  292. return $allow;
  293.  
  294.  
  295. if ( empty( $key ) ) {
  296. // Generate something random for a key...
  297. $key = wp_generate_password( 20, false );
  298. do_action( 'retrieve_password_key', $user_login, $key );
  299. // Now insert the key, hashed, into the DB.
  300. if ( empty( $wp_hasher ) ) {
  301. require_once ABSPATH . 'wp-includes/class-phpass.php';
  302. $wp_hasher = new PasswordHash( 8, true );
  303. }
  304. $hashed = $wp_hasher->HashPassword( $key );
  305. // Now insert the new md5 key into the db
  306. $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user_login ) );
  307.  
  308.  
  309. // OLD $wpdb->update( $wpdb->users, array( 'user_activation_key' => $key ), array( 'user_login' => $user_login ) );
  310. }
  311. $message = __( 'Someone requested that the password be reset for the following account:', 'geisinger-wpml' ) . "\r\n\r\n";
  312. $message .= network_home_url( '/' ) . "\r\n\r\n";
  313. $message .= sprintf( __( 'Username: %s' ), $user_login ) . "\r\n\r\n";
  314. $message .= __( 'If this was a mistake, just ignore this email and nothing will happen.', 'geisinger-wpml' ) . "\r\n\r\n";
  315. $message .= __( 'To reset your password, visit the following address:', 'geisinger-wpml' ) . "\r\n\r\n";
  316. $message .= '<' . network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . ">\r\n";
  317.  
  318. if ( is_multisite() ) {
  319. $blogname = $GLOBALS['current_site']->site_name;
  320. } else {
  321. // The blogname option is escaped with esc_html on the way into the database in sanitize_option
  322. // we want to reverse this for the plain text arena of emails.
  323. $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
  324. }
  325.  
  326. $title = sprintf( __( '[%s] Password Reset' ), $blogname );
  327. $title = apply_filters( 'retrieve_password_title', $title );
  328. $message = apply_filters( 'retrieve_password_message', $message, $key );
  329.  
  330. if ( $message && ! wp_mail( $user_email, $title, $message ) ) {
  331. $errors->add( 'noemail', __( 'The e-mail could not be sent. Possible reason: your host may have disabled the mail() function.', 'geissinger-wpml' ) );
  332.  
  333. return $errors;
  334.  
  335. wp_die();
  336. }
  337. return true;
  338. }
  339.  
  340.  
  341. /**
  342. * The source code for our login form. Version 2 supports ajaxable Login, Registration and Forgotten Password forms.
  343. * @return html
  344. * @actions before_wpml_title Add items before the modal window title.
  345. * before_wpml_form Add items before the form itself, or after the title.
  346. * inside_wpml_form_first Add items before any of the form items but inside the form wrapper.
  347. * login_form Default WP action for custom login forms.
  348. * inside_wpml_form_submit Add items in the submit wrapper.
  349. * inside_wpml_form_last Add items at the end of the form wrapper after the submit button.
  350. * after_wpml_form Add items after the form itself.
  351. *
  352. * @version 2.0.1
  353. * @since 1.0
  354. */
  355. public function login_form() {
  356. global $user_ID, $user_identity, $wpml_settings;
  357. get_currentuserinfo(); ?>
  358.  
  359. <div id="login-box" class="login-popup">
  360. <a href="#" class="close-btn"></a>
  361.  
  362. <?php do_action( 'before_wpml_title' ); ?>
  363.  
  364. <?php if( ! $user_ID ) : ?>
  365. <div class="section-container">
  366.  
  367. <?php // Login Form ?>
  368. <div id="login" class="wpml-content">
  369.  
  370. <h2><?php _e( 'Login to Dandy', 'geissinger-wpml' ); ?></h2>
  371.  
  372. <?php do_action( 'before_wpml_login' ); ?>
  373.  
  374. <form action="login" method="post" id="form" class="group" name="loginform">
  375.  
  376. <?php do_action( 'inside_wpml_login_first' ); ?>
  377.  
  378. <p>
  379. <label class="field-titles hide" for="login_user"><?php _e( 'Username', 'geissinger-wpml' ); ?></label>
  380. <input type="text" name="log" id="login_user" class="input" placeholder="USERNAME" value="<?php if ( isset( $user_login ) ) echo esc_attr( $user_login ); ?>" size="20" />
  381. </p>
  382.  
  383. <p>
  384. <label class="field-titles hide" for="login_pass"><?php _e( 'Password', 'geissinger-wpml' ); ?></label>
  385. <input type="password" name="pwd" id="login_pass" class="input" placeholder="PASSWORD" value="" size="20" />
  386. </p>
  387.  
  388. <p class="submit">
  389. <?php do_action( 'inside_wpml_login_submit' ); ?>
  390. <input type="submit" name="wp-sumbit" id="wp-submit" class="button button-primary button-large" value="<?php _e( 'Submit', 'geissinger-wpml' ); ?>" />
  391. <input type="hidden" name="login" value="true" />
  392. <?php wp_nonce_field( 'ajax-form-nonce', 'security' ); ?>
  393. </p><!--[END .submit]-->
  394.  
  395. <?php do_action( 'login_form' ); ?>
  396.  
  397. <?php do_action( 'inside_wpml_login_last' ); ?>
  398.  
  399. </form><!--[END #loginform]-->
  400. </div><!--[END #login]-->
  401.  
  402.  
  403. <?php // Registration form ?>
  404. <?php if ( ! isset( $wpml_settings['remove-reg'] ) ) {
  405. if ( ( get_option( 'users_can_register' ) && ! is_multisite() ) || ( $multisite_reg == 'all' || $multisite_reg == 'blog' || $multisite_reg == 'user' ) ) : ?>
  406. <div id="register" class="wpml-content" style="display:none;">
  407.  
  408. <h2><?php _e( 'Create account', 'geissinger-wpml' ); ?></h2>
  409.  
  410. <?php do_action( 'before_wpml_register' ); ?>
  411.  
  412. <form action="register" method="post" id="form" class="group" name="loginform">
  413.  
  414. <?php do_action( 'inside_wpml_register_first' ); ?>
  415.  
  416. <p>
  417. <label class="field-titles hide" for="reg_user"><?php _e( 'Username', 'geissinger-wpml' ); ?></label>
  418. <input type="text" name="user_login" id="reg_user" class="input" placeholder="USERNAME" value="<?php if ( isset( $user_login ) ) echo esc_attr( stripslashes( $user_login ) ); ?>" size="20" />
  419. </p>
  420.  
  421. <p>
  422. <label class="field-titles hide" for="reg_email"><?php _e( 'Email', 'geissinger-wpml' ); ?></label>
  423. <input type="text" name="user_email" id="reg_email" class="input" placeholder="EMAIL ADDRESS" value="<?php if ( isset( $user_email ) ) echo esc_attr( stripslashes( $user_email ) ); ?>" size="20" />
  424. </p>
  425.  
  426. <p class="submit">
  427. <?php do_action( 'inside_wpml_register_submit' ); ?>
  428. <input type="submit" name="user-submit" id="user-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Sign Up', 'geissinger-wpml' ); ?>" />
  429. <input type="hidden" name="register" value="true" />
  430. <?php wp_nonce_field( 'ajax-form-nonce', 'security' ); ?>
  431. </p><!--[END .submit]-->
  432.  
  433. <?php do_action( 'register_form' ); ?>
  434.  
  435. <!-- Terms & Conditions -->
  436. <div style="width:100%;">
  437. <p id="terms-of-use">
  438. <small>By creating an account, you agree to our <a style="text-decoration:underline;" href="http://dandyapps.staging.wpengine.com/terms-of-use/">Terms &#038; Conditions</a></small>
  439. </p>
  440. </div>
  441.  
  442. <?php do_action( 'inside_wpml_register_last' ); ?>
  443.  
  444. </form>
  445.  
  446. </div><!--[END #register]-->
  447. <?php endif;
  448. } ?>
  449.  
  450. <?php // Forgotten Password ?>
  451. <div id="forgotten" class="wpml-content" style="display:none;">
  452.  
  453. <h2><?php _e( 'Password reset', 'geissinger-wpml' ); ?></h2>
  454.  
  455. <?php do_action( 'before_wpml_forgotten' ); ?>
  456.  
  457. <form action="forgotten" method="post" id="form" class="group" name="loginform">
  458.  
  459. <?php do_action( 'inside_wpml_forgotton_first' ); ?>
  460.  
  461. <p>
  462. <label class="field-titles hide" for="forgot_login"><?php _e( 'Username or Email', 'geissinger-wpml' ); ?></label>
  463. <input type="text" name="forgot_login" id="forgot_login" class="input" placeholder="EMAIL ADDRESS" value="<?php if ( isset( $user_login ) ) echo esc_attr( stripslashes( $user_login ) ); ?>" size="20" />
  464. </p>
  465.  
  466. <p class="submit">
  467. <?php do_action( 'inside_wpml_forgotten_submit' ); ?>
  468. <input type="submit" name="user-submit" id="user-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Reset Password', 'geissinger-wpml' ); ?>">
  469. <input type="hidden" name="forgotten" value="true" />
  470. <?php wp_nonce_field( 'ajax-form-nonce', 'security' ); ?>
  471. </p>
  472.  
  473. <?php do_action( 'login_form', 'resetpass' ); ?>
  474.  
  475. <?php do_action( 'inside_wpml_forgotten_last' ); ?>
  476.  
  477. </form>
  478.  
  479. </div><!--[END #forgotten]-->
  480. </div><!--[END .section-container]-->
  481. <?php endif; ?>
  482.  
  483. <?php do_action( 'after_wpml_form' ); ?>
  484. </div><!--[END #login-box]-->
  485. <?php }
  486.  
  487.  
  488. /**
  489. * Adds some additional fields to the login_form(). Hooked through 'after_wpml_form'.
  490. * @return void
  491. *
  492. * @version 1.1
  493. * @since 2.0
  494. */
  495. public function additional_options() {
  496.  
  497. echo '<div id="additional-settings">';
  498.  
  499. echo '<div class="hide-register" style="display: block;"><a href="#register" class="wpml-nav">' . __( 'NEED AN ACCOUNT?', 'geissinger-wpml' ) . '</a></div>';
  500.  
  501. echo '<div class="hide-forgotten" style="display: block;"><a href="#forgotten" class="wpml-nav">' . __( 'FORGOT PASSWORD?', 'geissinger-wpml' ) . '</a></div>';
  502.  
  503. echo '<div class="hide-login" style="display: block;"><a href="#login" class="wpml-nav">' . __( 'ALREADY HAVE AN ACCOUNT?', 'geissinger-wpml' ) . '</a></div>';
  504.  
  505. echo '</div>';
  506. }
  507.  
  508.  
  509. /**
  510. * Outputs the HTML for our login link.
  511. * @param String $login_text The text for the login link. Default 'Login'.
  512. * @param String $logout_text The text for the logout link. Default 'Logout'.
  513. * @param String $logout_url The url to redirect to when users logout. Empty by default.
  514. * @param Bool $show_admin The setting to display the link to the admin area when logged in.
  515. * @return HTML
  516. *
  517. * @version 1.1
  518. * @since 1.0
  519. */
  520. public function modal_login_btn( $login_text = 'Login', $logout_text = 'Logout', $logout_url = '', $show_admin = 1 ) {
  521. // Check if we have an over riding logout redirection set. Other wise, default to the home page.
  522. if ( isset( $logout_url ) && $logout_url == '' )
  523. $logout_url = home_url();
  524.  
  525. // Is the user logged in? If so, serve them the logout button, else we'll show the login button.
  526. if ( is_user_logged_in() ) {
  527. $link = '<a href="' . wp_logout_url( esc_url( $logout_url ) ) . '" class="logout wpml-btn">' . sprintf( _x( '%s', 'Logout Text', 'geissinger-wpml' ), sanitize_text_field( $logout_text ) ) . '</a>';
  528. if ( $show_admin )
  529. $link .= ' <a href="' . esc_url( admin_url() ) . '">' . __( 'View Admin', 'geissinger-wpml' ) . '</a>';
  530. } else {
  531. $link = '<a href="#login-box" class="login wpml-btn login-window">' . sprintf( _x( '%s', 'Login Text', 'geissinger-wpml' ), sanitize_text_field( $login_text ) ) . '</a></li>';
  532. }
  533.  
  534. return $link;
  535. }
  536.  
  537.  
  538. /**
  539. * The shortcode function. When we use the [wp-modal-login] shortcode, it will pull from this function.
  540. * @param Array $atts Contains all or any attributes used on the shortcode.
  541. * @return String
  542. *
  543. * @version 1.0
  544. * @since 1.0
  545. */
  546.  
  547. function modal_login_btn_shortcode( $atts ) {
  548. extract( shortcode_atts( array(
  549. 'login_text' => 'Login',
  550. 'logout_text' => 'Logout',
  551. 'logout_url' => home_url(),
  552. ), $atts ) );
  553.  
  554. if ( is_user_logged_in() ) {
  555. $link = '<a href="' . wp_logout_url( esc_url( $logout_url ) ) . '" class="logout wpml-btn">' . sprintf( _x( '%s', 'Shortcode Logout Text', 'geissinger-wpml' ), sanitize_text_field( $logout_text ) ) . '</a>';
  556. } else {
  557. $link = '<a href="#login-box" class="login wpml-btn login-window">' . sprintf( _x( '%s', 'Shortcode Login Text', 'geissinger-wpml' ), sanitize_text_field( $login_text ) ) . '</a></li>';
  558. }
  559.  
  560. return $link;
  561. }
  562.  
  563. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement