abstracts
2 months ago
admin
2 months ago
ads
3 months ago
compatibility
3 months ago
crons
3 months ago
frontend
2 months ago
groups
3 months ago
importers
2 months ago
installation
1 year ago
interfaces
4 months ago
license
3 months ago
placements
3 months ago
rest
1 year ago
traits
4 months ago
utilities
3 months ago
array_ad_conditions.php
1 year ago
cap_map.php
3 years ago
class-assets-registry.php
3 months ago
class-autoloader.php
1 year ago
class-constants.php
1 year ago
class-content-injector.php
2 months ago
class-entities.php
3 months ago
class-modal.php
1 year ago
class-modules.php
1 year ago
class-options.php
1 year ago
class-plugin.php
2 months ago
class-post-data.php
10 months ago
class-shortcodes.php
2 months ago
class-upgrades.php
1 year ago
class-widget.php
11 months ago
default-hooks.php
4 months ago
functions-ad.php
1 year ago
functions-components.php
3 months ago
functions-conditional.php
1 year ago
functions-core.php
1 year ago
functions-group.php
1 year ago
functions-placement.php
1 year ago
functions.php
3 months ago
index.php
2 years ago
load_modules.php
2 years ago
class-modal.php
107 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Modal. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 1.50.0 |
| 8 | */ |
| 9 | |
| 10 | namespace AdvancedAds; |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | /** |
| 15 | * Modal. |
| 16 | */ |
| 17 | class Modal { |
| 18 | /** |
| 19 | * Default values for the view file. |
| 20 | * |
| 21 | * @var array |
| 22 | */ |
| 23 | private $view_arguments = [ |
| 24 | 'modal_slug' => '', |
| 25 | 'modal_content' => '', |
| 26 | 'modal_title' => '', |
| 27 | 'cancel_action' => true, |
| 28 | 'close_action' => '', |
| 29 | 'close_form' => '', |
| 30 | 'close_validation' => '', |
| 31 | 'template' => '', |
| 32 | 'dismiss_button_styling' => '', |
| 33 | 'container_styling' => '', |
| 34 | 'background_styling' => '', |
| 35 | ]; |
| 36 | |
| 37 | /** |
| 38 | * Create modal. |
| 39 | * |
| 40 | * @param array $arguments The passed view arguments, overwriting the default values. |
| 41 | * @param bool $render Whether to render the modal from the constructor. Defaults to true. |
| 42 | * |
| 43 | * @return Modal |
| 44 | */ |
| 45 | public static function create( array $arguments, $render = true ) { |
| 46 | return new Modal( $arguments, $render ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Create modal from file. |
| 51 | * |
| 52 | * @param array $arguments The passed view arguments, overwriting the default values. |
| 53 | * @param string $file File path to include content from. |
| 54 | * @param bool $render Whether to render the modal from the constructor. Defaults to true. |
| 55 | * |
| 56 | * @return Modal |
| 57 | */ |
| 58 | public static function create_from_file( array $arguments, $file, $render = true ) { |
| 59 | ob_start(); |
| 60 | require $file; |
| 61 | |
| 62 | $arguments['modal_content'] = ob_get_clean(); |
| 63 | |
| 64 | return new Modal( $arguments, $render ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Modal constructor. |
| 69 | * |
| 70 | * @param array $arguments The passed view arguments, overwriting the default values. |
| 71 | * @param bool $render Whether to render the modal from the constructor. Defaults to true. |
| 72 | */ |
| 73 | public function __construct( array $arguments, $render = true ) { |
| 74 | $this->view_arguments = array_intersect_key( |
| 75 | wp_parse_args( |
| 76 | array_map( |
| 77 | function ( $value ) { |
| 78 | return (string) $value; |
| 79 | }, |
| 80 | $arguments |
| 81 | ), |
| 82 | $this->view_arguments |
| 83 | ), |
| 84 | $this->view_arguments |
| 85 | ); |
| 86 | |
| 87 | if ( $render ) { |
| 88 | $this->render(); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Render the modal. |
| 94 | * |
| 95 | * @return void |
| 96 | */ |
| 97 | public function render() { |
| 98 | extract( $this->view_arguments, EXTR_OVERWRITE ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract |
| 99 | |
| 100 | $file = '' !== $this->view_arguments['template'] |
| 101 | ? $this->view_arguments['template'] |
| 102 | : ADVADS_ABSPATH . 'admin/views/modal.php'; |
| 103 | |
| 104 | require $file; |
| 105 | } |
| 106 | } |
| 107 |