| @@ -1,52 +1,53 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | -namespace passster; | |
| 4 | - | |
| 5 | -class PS_Form { | |
| 6 | - /** | |
| 7 | - * Contains instance or null | |
| 8 | - * | |
| 9 | - * @var object|null | |
| 10 | - */ | |
| 11 | - private static $instance = null; | |
| 12 | - | |
| 13 | - /** | |
| 14 | - * Returns instance of PS_Form. | |
| 15 | - * | |
| 16 | - * @return object | |
| 17 | - */ | |
| 18 | - public static function get_instance() { | |
| 19 | - if ( null === self::$instance ) { | |
| 20 | - self::$instance = new self(); | |
| 21 | - } | |
| 22 | - return self::$instance; | |
| 23 | - } | |
| 24 | - | |
| 25 | - /** | |
| 26 | - * Get password form markup and replace placeholders | |
| 27 | - * | |
| 28 | - * @return string | |
| 29 | - */ | |
| 30 | - public static function get_password_form() : string { | |
| 31 | - $options = get_option( 'passster' ); | |
| 32 | - ob_start(); | |
| 33 | - include apply_filters( 'passster_password_form', PASSSTER_PATH . '/inc/templates/password-form.php' ); | |
| 34 | - $password_form = ob_get_contents(); | |
| 35 | - ob_end_clean(); | |
| 36 | - $password_form_placeholders = array( | |
| 37 | - '[PASSSTER_AUTH]' => 'passster_password', | |
| 38 | - '[PS_AJAX_LOADER]' => PASSSTER_URL . '/assets/public/ps-loader.svg', | |
| 39 | - ); | |
| 40 | - $show_password = $options['show_password']; | |
| 41 | - if ( $show_password ) { | |
| 42 | - $password_form_placeholders['[PASSSTER_SHOW_PASSWORD]'] = '<label for="passster-password-hint"><input name="passster-password-hint" id="passster-password-hint" type="checkbox" onclick="showPassword()"/> ' . esc_html__( 'Show Password', 'content-protector' ) . '</label>'; | |
| 43 | - } else { | |
| 44 | - $password_form_placeholders['[PASSSTER_SHOW_PASSWORD]'] = ''; | |
| 45 | - } | |
| 46 | - foreach ( $password_form_placeholders as $placeholder => $string ) { | |
| 47 | - $password_form = str_replace( $placeholder, $string, $password_form ); | |
| 48 | - } | |
| 49 | - return $password_form; | |
| 50 | - } | |
| 51 | - | |
| 52 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace passster; | |
| 4 | + | |
| 5 | +class PS_Form { | |
| 6 | + /** | |
| 7 | + * Contains instance or null | |
| 8 | + * | |
| 9 | + * @var object|null | |
| 10 | + */ | |
| 11 | + private static $instance = null; | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * Returns instance of PS_Form. | |
| 15 | + * | |
| 16 | + * @return object | |
| 17 | + */ | |
| 18 | + public static function get_instance() { | |
| 19 | + if ( null === self::$instance ) { | |
| 20 | + self::$instance = new self(); | |
| 21 | + } | |
| 22 | + return self::$instance; | |
| 23 | + } | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * Get password form markup and replace placeholders | |
| 27 | + * | |
| 28 | + * @return string | |
| 29 | + */ | |
| 30 | + public static function get_password_form() : string { | |
| 31 | + $options = get_option( 'passster' ); | |
| 32 | + ob_start(); | |
| 33 | + include apply_filters( 'passster_password_form', PASSSTER_PATH . '/inc/templates/password-form.php' ); | |
| 34 | + $password_form = ob_get_contents(); | |
| 35 | + ob_end_clean(); | |
| 36 | + $password_form_placeholders = array( | |
| 37 | + '[PASSSTER_AUTH]' => 'passster_password', | |
| 38 | + '[PS_AJAX_LOADER]' => PASSSTER_URL . '/assets/public/ps-loader.svg', | |
| 39 | + ); | |
| 40 | + $show_password = $options['show_password'] ?? false; | |
| 41 | + $show_password_label = $options['show_password_label'] ?? __( 'Show Password', 'content-protector' ); | |
| 42 | + if ( $show_password ) { | |
| 43 | + $password_form_placeholders['[PASSSTER_SHOW_PASSWORD]'] = '<label for="passster-password-hint"><input name="passster-password-hint" id="passster-password-hint" type="checkbox" onclick="showPassword()"/> ' . esc_html( $show_password_label ) . '</label>'; | |
| 44 | + } else { | |
| 45 | + $password_form_placeholders['[PASSSTER_SHOW_PASSWORD]'] = ''; | |
| 46 | + } | |
| 47 | + foreach ( $password_form_placeholders as $placeholder => $string ) { | |
| 48 | + $password_form = str_replace( $placeholder, $string, $password_form ); | |
| 49 | + } | |
| 50 | + return $password_form; | |
| 51 | + } | |
| 52 | + | |
| 53 | +} | |