PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 1.4.1
WP 2FA – Two-factor authentication for WordPress v1.4.1
1.7.1 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.8.0 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0 3.0.1 3.1.0 3.1.1 3.1.1.2 trunk 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.7.0
wp-2fa / includes / classes / Shortcodes / Shortcodes.php
wp-2fa / includes / classes / Shortcodes Last commit date
Shortcodes.php 6 years ago
Shortcodes.php
129 lines
1 <?php // phpcs:ignore
2
3 namespace WP2FA\Shortcodes;
4
5 use \WP2FA\WP2FA as WP2FA;
6 use \WP2FA\Admin\UserNotices as UserNotices;
7 use \WP2FA\Authenticator\Authentication as Authentication;
8 use \WP2FA\Core as Core;
9 use \WP2FA\Authenticator\BackupCodes as BackupCodes;
10 use \WP2FA\Admin\UserProfile as UserProfile;
11
12 /**
13 * Class for handling our crons.
14 */
15 class Shortcodes {
16
17 /**
18 * Constructor.
19 */
20 public function __construct() {
21 add_shortcode( 'wp-2fa-setup-form', array( $this, 'user_setup_2fa_form' ) );
22 add_shortcode( 'wp-2fa-setup-notice', array( $this, 'user_setup_2fa_notice' ) );
23 add_action( 'wp_enqueue_scripts', array( $this, 'register_2fa_shortcode_scripts' ) );
24 }
25
26 /**
27 * Register scripts and styles.
28 */
29 public function register_2fa_shortcode_scripts() {
30 // Add our front end stuff, which we only want to load when the shortcode is present.
31 wp_register_script( 'wp_2fa_frontend_scripts', Core\script_url( 'wp-2fa', 'admin' ), array( 'jquery' ), WP_2FA_VERSION, true );
32 wp_register_script( 'wp_2fa_micro_modals', Core\script_url( 'micro-modal', 'admin' ), array(), WP_2FA_VERSION, true );
33 wp_register_style( 'wp_2fa_styles', Core\style_url( 'styles', 'frontend' ) );
34 }
35
36 /**
37 * Output setup form.
38 */
39 public function user_setup_2fa_form( $atts ) {
40 extract(
41 shortcode_atts(
42 array(
43 'show_preamble' => 'true',
44 ),
45 $atts
46 )
47 );
48
49 if ( ! is_admin() && is_user_logged_in() ) {
50 wp_enqueue_script( 'wp_2fa_frontend_scripts' );
51 wp_enqueue_script( 'wp_2fa_micro_modals' );
52 wp_enqueue_style( 'wp_2fa_styles' );
53
54 $data_array = array(
55 'ajaxURL' => admin_url( 'admin-ajax.php' ),
56 'roles' => WP2FA::wp_2fa_get_roles(),
57 'nonce' => wp_create_nonce( 'wp-2fa-settings-nonce' ),
58 'codesPreamble' => esc_html__( 'These are the 2FA backup codes for the user', 'wp-2fa' ),
59 'readyText' => esc_html__( 'I\'m ready', 'wp-2fa' ),
60 'codeReSentText' => esc_html__( 'New code sent', 'wp-2fa' ),
61 'allDoneHeading' => esc_html__( 'All done.', 'wp-2fa' ),
62 'allDoneText' => esc_html__( 'Your login just got more secure.', 'wp-2fa' ),
63 'closeWizard' => esc_html__( 'Close Wizard', 'wp-2fa' ),
64 );
65 wp_localize_script( 'wp_2fa_frontend_scripts', 'wp2faData', $data_array );
66
67 $forms = new UserProfile();
68 ob_start();
69 echo '<form id="your-profile" class="wp-2fa-configuration-form">';
70 $forms->inline_2fa_profile_form( 'output_shortcode', $show_preamble );
71 echo '</form>';
72 $content = ob_get_contents();
73 ob_end_clean();
74 return $content;
75 } elseif ( ! is_admin() && ! is_user_logged_in() ) {
76 if ( ! empty( WP2FA::get_wp2fa_setting( 'custom-user-page-id' ) ) ) {
77 $new_page_id = WP2FA::get_wp2fa_setting( 'custom-user-page-id' );
78 $redirect_to = get_permalink( $new_page_id );
79 }
80 ob_start();
81 echo '<p>' . esc_html__( 'You must be logged in to view this page.', 'wp-2fa' ) . ' <a href="' . esc_url( wp_login_url( $redirect_to ) ) . '">' . esc_html__( 'Login here.', 'wp-2fa' ) . '</a></p>';
82 $content = ob_get_contents();
83 ob_end_clean();
84 return $content;
85 }
86 }
87
88 /**
89 * Output setup nag.
90 */
91 public function user_setup_2fa_notice( $atts ) {
92 extract(
93 shortcode_atts(
94 array(
95 'configure_2fa_url' => '',
96 ),
97 $atts
98 )
99 );
100 $notice = new UserNotices();
101
102 if ( ! is_admin() && is_user_logged_in() ) {
103 wp_enqueue_script( 'wp_2fa_frontend_scripts' );
104 wp_enqueue_script( 'wp_2fa_micro_modals' );
105 wp_enqueue_style( 'wp_2fa_styles' );
106
107 $data_array = array(
108 'ajaxURL' => admin_url( 'admin-ajax.php' ),
109 'roles' => WP2FA::wp_2fa_get_roles(),
110 'nonce' => wp_create_nonce( 'wp-2fa-settings-nonce' ),
111 'codesPreamble' => esc_html__( 'These are the 2FA backup codes for the user', 'wp-2fa' ),
112 'readyText' => esc_html__( 'I\'m ready', 'wp-2fa' ),
113 'codeReSentText' => esc_html__( 'New code sent', 'wp-2fa' ),
114 'allDoneHeading' => esc_html__( 'All done.', 'wp-2fa' ),
115 'allDoneText' => esc_html__( 'Your login just got more secure.', 'wp-2fa' ),
116 'closeWizard' => esc_html__( 'Close Wizard', 'wp-2fa' ),
117 );
118 wp_localize_script( 'wp_2fa_frontend_scripts', 'wp2faData', $data_array );
119
120 ob_start();
121 echo $notice->user_setup_2fa_nag( 'output_shortcode', $configure_2fa_url );
122 $content = ob_get_contents();
123 ob_end_clean();
124 return $content;
125 }
126 }
127
128 }
129