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