AbstractMigration.php
4 years ago
DateTimeUtils.php
4 years ago
Debugging.php
5 years ago
GenerateModal.php
4 years ago
Migration.php
4 years ago
RequestUtils.php
4 years ago
SettingsUtils.php
4 years ago
UserUtils.php
4 years ago
index.php
5 years ago
GenerateModal.php
66 lines
| 1 | <?php |
| 2 | namespace WP2FA\Utils; |
| 3 | |
| 4 | use WP2FA\WP2FA as WP2FA; |
| 5 | |
| 6 | /** |
| 7 | * Utility class for creating modal popup markup. |
| 8 | * |
| 9 | * @package WP2FA\Utils |
| 10 | * @since 1.4.2 |
| 11 | */ |
| 12 | class GenerateModal { |
| 13 | |
| 14 | /** |
| 15 | * General modals based on given args. |
| 16 | * |
| 17 | * @param string $modal_id Unique ID for the modal. |
| 18 | * @param string $modal_title (Optional) Modal title. |
| 19 | * @param string $modal_content The HTML content we want to show in the modal. |
| 20 | * @param array $modal_footer_buttons The HTML content we want to show at the footer of the modal, usually buttons. |
| 21 | * @param string $should_modal_autoopen (Optional) if anything is passed we will open the modal automatically. |
| 22 | * @param string $should_modal_autoopen (Optional) Max possible width of modal. |
| 23 | */ |
| 24 | public static function generate_modal( $modal_id, $modal_title, $modal_content, $modal_footer_buttons = [], $should_modal_autoopen = '', $max_width = '' ) { |
| 25 | |
| 26 | $buttons = ''; |
| 27 | $modal = ''; |
| 28 | $title = ( ! empty( $modal_title ) ) ? '<header class="modal__header"><h4 class="modal__title" id="modal-'. esc_attr( $modal_id ) .'-title">'. $modal_title .'</h4></header>' : false; |
| 29 | |
| 30 | if ( ! empty( $modal_footer_buttons ) ) { |
| 31 | foreach ( $modal_footer_buttons as $button_markup ) { |
| 32 | $buttons .= $button_markup ; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | if ( ! empty( $should_modal_autoopen ) ) { |
| 37 | $modal_class = 'wp2fa-modal micromodal-slide is-open'; |
| 38 | $hidden = 'false'; |
| 39 | } else { |
| 40 | $modal_class = 'wp2fa-modal micromodal-slide'; |
| 41 | $hidden = 'true'; |
| 42 | } |
| 43 | |
| 44 | $max_width_styles = ( ! empty( $max_width ) ) ? 'style="max-width:'. esc_attr( $max_width ) .'; min-width: 0;"' : false; |
| 45 | |
| 46 | $modal = ' |
| 47 | <div class="'. $modal_class .'" id="'. esc_attr( $modal_id ) .'" aria-hidden="'. esc_attr( $hidden ) .'"> |
| 48 | <div class="modal__overlay" tabindex="-1" data-micromodal-close> |
| 49 | <div class="modal__container" role="dialog" aria-modal="true" aria-labelledby="modal-'. esc_attr( $modal_id ) .'-title" '. $max_width_styles .'> |
| 50 | '. $title .' |
| 51 | <main class="modal__content wp2fa-form-styles" id="modal-'. esc_attr( $modal_id ) .'-content"> |
| 52 | '. wpautop( $modal_content ) .' |
| 53 | </main> |
| 54 | <footer class="modal__footer"> |
| 55 | '. $buttons .' |
| 56 | </footer> |
| 57 | </div> |
| 58 | </div> |
| 59 | </div> |
| 60 | '; |
| 61 | |
| 62 | return $modal; |
| 63 | } |
| 64 | |
| 65 | } |
| 66 |