PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 4.0.0
WP 2FA – Two-factor authentication for WordPress v4.0.0
4.0.0 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 5 days ago class-date-time-utils.php 5 days ago class-debugging.php 5 days ago class-generate-modal.php 5 days ago class-migration.php 5 days ago class-request-utils.php 5 days ago class-settings-utils.php 5 days ago class-upgrade-guard.php 5 days ago class-user-utils.php 5 days ago class-validator.php 5 days ago class-white-label.php 5 days ago index.php 5 days ago
class-generate-modal.php
85 lines
1 <?php
2 /**
3 * Responsible for modal dialogs generation.
4 *
5 * @package wp2fa
6 * @subpackage utils
7 * @copyright 2026 Melapress
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 declare(strict_types=1);
13
14 namespace WP2FA\Utils;
15
16 defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
17
18 use WP2FA\WP2FA;
19
20 if ( ! class_exists( '\WP2FA\Utils\Generate_Modal' ) ) {
21
22 /**
23 * Utility class for creating modal popup markup.
24 *
25 * @package WP2FA\Utils
26 *
27 * @since 1.4.2
28 */
29 class Generate_Modal {
30
31 /**
32 * General modals based on given args.
33 *
34 * @param string $modal_id Unique ID for the modal.
35 * @param string $modal_title (Optional) Modal title.
36 * @param string $modal_content The HTML content we want to show in the modal.
37 * @param array $modal_footer_buttons The HTML content we want to show at the footer of the modal, usually buttons.
38 * @param string $should_modal_autoopen (Optional) if anything is passed we will open the modal automatically.
39 * @param string $max_width (Optional) Max possible width of modal.
40 */
41 public static function generate_modal( $modal_id, $modal_title, $modal_content, $modal_footer_buttons = array(), $should_modal_autoopen = '', $max_width = '' ) {
42
43 $buttons = '';
44 $modal = '';
45 $title = ( ! empty( $modal_title ) ) ? '<header class="modal__header"><h4 class="modal__title" id="modal-' . \esc_attr( $modal_id ) . '-title">' . \esc_html( $modal_title ) . '</h4></header>' : false;
46
47 if ( ! empty( $modal_footer_buttons ) ) {
48 foreach ( $modal_footer_buttons as $button_markup ) {
49 $buttons .= wp_kses_post( $button_markup );
50 }
51 }
52
53 $styling_class = ( empty( WP2FA::get_wp2fa_white_label_setting( 'enable_wizard_styling' ) ) ) ? 'default_styling' : 'enable_styling';
54
55 if ( ! empty( $should_modal_autoopen ) ) {
56 $modal_class = 'wp2fa-modal micromodal-slide is-open ' . $styling_class;
57 $hidden = 'false';
58 } else {
59 $modal_class = 'wp2fa-modal micromodal-slide ' . $styling_class;
60 $hidden = 'true';
61 }
62
63 $max_width_styles = ( ! empty( $max_width ) ) ? 'style="max-width:' . \esc_attr( $max_width ) . '; min-width: 0;"' : '';
64
65 $modal = '
66 <div class="' . esc_attr( $modal_class ) . '" id="' . \esc_attr( $modal_id ) . '" aria-hidden="' . \esc_attr( $hidden ) . '">
67 <div class="modal__overlay" tabindex="-1">
68 <div class="modal__container" role="dialog" aria-dialog="true" aria-labelledby="modal-' . \esc_attr( $modal_id ) . '-title" ' . $max_width_styles . '>
69 ' . $title . '
70 <main class="modal__content wp2fa-form-styles" id="modal-' . \esc_attr( $modal_id ) . '-content">
71 ' . wp_kses_post( wpautop( $modal_content ) ) . '
72 </main>
73 <footer class="modal__footer">
74 ' . $buttons . '
75 </footer>
76 </div>
77 </div>
78 </div>
79 ';
80
81 return $modal;
82 }
83 }
84 }
85