Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
66.67% |
10 / 15 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Enable_Magic_Links | |
66.67% |
10 / 15 |
|
0.00% |
0 / 3 |
7.33 | |
0.00% |
0 / 1 |
| get_is_checked_value | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get_is_not_checked_value | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __construct | |
76.92% |
10 / 13 |
|
0.00% |
0 / 1 |
4.20 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * This settings field is a checkbox to enable adding "send magic link" buttons on login screens. |
| 4 | * |
| 5 | * @link https://BrianHenry.ie |
| 6 | * @since 1.0.0 |
| 7 | * |
| 8 | * @package bh-wp-autologin-urls |
| 9 | */ |
| 10 | |
| 11 | namespace BrianHenryIE\WP_Autologin_URLs\Admin\Settings_Fields; |
| 12 | |
| 13 | use BrianHenryIE\WP_Autologin_URLs\Settings_Interface; |
| 14 | use BrianHenryIE\WP_Autologin_URLs\API\Settings; |
| 15 | |
| 16 | /** |
| 17 | * Class |
| 18 | */ |
| 19 | class Enable_Magic_Links extends Checkbox_Setting_Element_Abstract { |
| 20 | |
| 21 | /** |
| 22 | * This is what is POSTed when the checkbox is ticked. |
| 23 | */ |
| 24 | protected function get_is_checked_value(): string { |
| 25 | return 'magic_links_is_enabled'; |
| 26 | } |
| 27 | protected function get_is_not_checked_value(): string { |
| 28 | return 'magic_links_is_not_enabled'; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Admin_Enable constructor. |
| 33 | * |
| 34 | * @param string $settings_page_slug_name The slug of the page this setting is being displayed on. |
| 35 | * @param Settings_Interface $settings The existing settings saved in the database. |
| 36 | */ |
| 37 | public function __construct( string $settings_page_slug_name, Settings_Interface $settings ) { |
| 38 | |
| 39 | parent::__construct( $settings_page_slug_name ); |
| 40 | |
| 41 | $this->value = $settings->is_magic_link_enabled() ? 'magic_links_is_enabled' : 'magic_links_is_not_enabled'; |
| 42 | |
| 43 | $this->id = Settings::MAGIC_LINK_ENABLED; |
| 44 | $this->title = __( 'Enable magic links?', 'bh-wp-autologin-urls' ); |
| 45 | |
| 46 | $this->register_setting_args['type'] = 'string'; |
| 47 | $this->register_setting_args['default'] = 'magic_links_is_not_enabled'; |
| 48 | |
| 49 | $this->add_settings_field_args['helper'] = __( 'Add a button beside login buttons allowing users to send themselves an email with an instant login link.', 'bh-wp-autologin-urls' ); |
| 50 | |
| 51 | $login_screens_links = '<a href="' . wp_login_url() . '">' . str_replace( trailingslashit( site_url() ), '', wp_login_url() ) . '</a>'; |
| 52 | if ( function_exists( 'wc_get_page_permalink' ) ) { |
| 53 | $login_screens_links .= ', <a href="' . wc_get_page_permalink( 'myaccount' ) . '">' . str_replace( trailingslashit( site_url() ), '', wc_get_page_permalink( 'myaccount' ) ) . '</a>'; |
| 54 | |
| 55 | // If "Allow customers to log into an existing account during checkout" is checked. |
| 56 | if ( 'yes' === get_option( 'woocommerce_enable_checkout_login_reminder' ) ) { |
| 57 | $login_screens_links .= ', <a href="' . wc_get_page_permalink( 'checkout' ) . '">' . str_replace( trailingslashit( site_url() ), '', wc_get_page_permalink( 'checkout' ) ) . '</a>'; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /* translators: hyperlinks to login screens */ |
| 62 | $this->add_settings_field_args['supplemental'] = __( 'default: false', 'bh-wp-autologin-urls' ) . '<br/>' . sprintf( __( 'When enabling magic links, be sure to check the appearance of the button on your login screens (%s) and make appropriate CSS changes if necessary.', 'bh-wp-autologin-urls' ), $login_screens_links ); |
| 63 | } |
| 64 | } |