PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 2.4.2
WP 2FA – Two-factor authentication for WordPress v2.4.2
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 / Utils / class-generate-modal.php
wp-2fa / includes / classes / Utils Last commit date
class-abstract-migration.php 3 years ago class-date-time-utils.php 3 years ago class-debugging.php 3 years ago class-generate-modal.php 3 years ago class-migration.php 3 years ago class-request-utils.php 3 years ago class-settings-utils.php 3 years ago class-user-utils.php 3 years ago index.php 5 years ago
class-generate-modal.php
78 lines
1 <?php
2 /**
3 * Responsible for modal dialogs generation.
4 *
5 * @package wp2fa
6 * @subpackage utils
7 * @copyright 2023 WP White Security
8 * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
9 * @link https://wordpress.org/plugins/wp-2fa/
10 */
11
12 namespace WP2FA\Utils;
13
14 use \WP2FA\WP2FA as WP2FA;
15
16 /**
17 * Utility class for creating modal popup markup.
18 *
19 * @package WP2FA\Utils
20 * @since 1.4.2
21 */
22 class Generate_Modal {
23
24 /**
25 * General modals based on given args.
26 *
27 * @param string $modal_id Unique ID for the modal.
28 * @param string $modal_title (Optional) Modal title.
29 * @param string $modal_content The HTML content we want to show in the modal.
30 * @param array $modal_footer_buttons The HTML content we want to show at the footer of the modal, usually buttons.
31 * @param string $should_modal_autoopen (Optional) if anything is passed we will open the modal automatically.
32 * @param string $max_width (Optional) Max possible width of modal.
33 */
34 public static function generate_modal( $modal_id, $modal_title, $modal_content, $modal_footer_buttons = array(), $should_modal_autoopen = '', $max_width = '' ) {
35
36 $buttons = '';
37 $modal = '';
38 $title = ( ! empty( $modal_title ) ) ? '<header class="modal__header"><h4 class="modal__title" id="modal-' . esc_attr( $modal_id ) . '-title">' . $modal_title . '</h4></header>' : false;
39
40 if ( ! empty( $modal_footer_buttons ) ) {
41 foreach ( $modal_footer_buttons as $button_markup ) {
42 $buttons .= $button_markup;
43 }
44 }
45
46 $styling_class = ( empty( WP2FA::get_wp2fa_white_label_setting( 'enable_wizard_styling' ) ) ) ? 'default_styling' : 'enable_styling';
47
48 if ( ! empty( $should_modal_autoopen ) ) {
49 $modal_class = 'wp2fa-modal micromodal-slide is-open ' . $styling_class;
50 $hidden = 'false';
51 } else {
52 $modal_class = 'wp2fa-modal micromodal-slide ' . $styling_class;
53 $hidden = 'true';
54 }
55
56 $max_width_styles = ( ! empty( $max_width ) ) ? 'style="max-width:' . esc_attr( $max_width ) . '; min-width: 0;"' : false;
57
58 $modal = '
59 <div class="' . $modal_class . '" id="' . esc_attr( $modal_id ) . '" aria-hidden="' . esc_attr( $hidden ) . '">
60 <div class="modal__overlay" tabindex="-1">
61 <div class="modal__container" role="dialog" aria-modal="true" aria-labelledby="modal-' . esc_attr( $modal_id ) . '-title" ' . $max_width_styles . '>
62 ' . $title . '
63 <main class="modal__content wp2fa-form-styles" id="modal-' . esc_attr( $modal_id ) . '-content">
64 ' . wpautop( $modal_content ) . '
65 </main>
66 <footer class="modal__footer">
67 ' . $buttons . '
68 </footer>
69 </div>
70 </div>
71 </div>
72 ';
73
74 return $modal;
75 }
76
77 }
78