Admin
4 years ago
Exceptions
4 years ago
Factories
4 years ago
Helpers
4 months ago
Pipeline
1 year ago
Repositories
3 years ago
Routes
2 weeks ago
Tabs
9 months ago
resources
4 months ago
App.php
1 year ago
Block.php
1 year ago
Helpers.php
1 year ago
Profile.php
1 year ago
RequestHandler.php
5 months ago
ServiceProvider.php
2 years ago
Shortcode.php
2 years ago
RequestHandler.php
148 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\DonorDashboards; |
| 4 | |
| 5 | use _WP_Dependency; |
| 6 | use Give\DonorDashboards\Admin\Settings; |
| 7 | use Give\Framework\Permissions\Facades\UserPermissions; |
| 8 | use WP_Query; |
| 9 | |
| 10 | /** |
| 11 | * @since 2.10.0 |
| 12 | */ |
| 13 | class RequestHandler |
| 14 | { |
| 15 | |
| 16 | /** |
| 17 | * Register 'give-embed' query var |
| 18 | * |
| 19 | * @param array $vars |
| 20 | * |
| 21 | * @return array |
| 22 | */ |
| 23 | public function filterQueryVars($vars) |
| 24 | { |
| 25 | $vars[] = 'give-embed'; |
| 26 | $vars[] = 'give-generate-donor-dashboard-page'; |
| 27 | $vars[] = 'give-generated-donor-dashboard-page'; |
| 28 | |
| 29 | return $vars; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Load donor dashboard markup, if donor dashboard exists in query vars |
| 34 | * |
| 35 | * @param WP_Query $query |
| 36 | * |
| 37 | * @return void |
| 38 | */ |
| 39 | public function parseRequest($query) |
| 40 | { |
| 41 | if (is_admin() && UserPermissions::settings()->canManage() && ! wp_doing_ajax() && array_key_exists( |
| 42 | 'give-generate-donor-dashboard-page', |
| 43 | $query->query_vars |
| 44 | )) { |
| 45 | (new Settings())->generateDonorDashboardPage(); |
| 46 | wp_safe_redirect( |
| 47 | admin_url('edit.php?post_type=give_forms&page=give-settings&give-generated-donor-dashboard-page=1') |
| 48 | ); |
| 49 | exit; |
| 50 | } |
| 51 | |
| 52 | if (array_key_exists( |
| 53 | 'give-embed', |
| 54 | $query->query_vars |
| 55 | ) && $query->query_vars['give-embed'] === 'donor-dashboard') { |
| 56 | $this->setUpFrontendHooks(); |
| 57 | |
| 58 | $app = new App(); |
| 59 | echo $app->getIframeContent(); |
| 60 | exit; // and exit |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Setup frontend hooks |
| 66 | * |
| 67 | * @since 2.10.0 |
| 68 | */ |
| 69 | public function setUpFrontendHooks() |
| 70 | { |
| 71 | add_action('give_embed_head', [$this, 'noRobots']); |
| 72 | add_action('give_embed_head', 'wp_enqueue_scripts', 1); |
| 73 | add_action('give_embed_head', [$this, 'handleEnqueueScripts'], 2); |
| 74 | add_action('give_embed_head', 'wp_print_styles', 8); |
| 75 | add_action('give_embed_head', 'wp_print_head_scripts', 9); |
| 76 | add_action('give_embed_footer', 'wp_print_footer_scripts', 20); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Display a noindex meta tag. |
| 81 | * |
| 82 | * Outputs a noindex meta tag that tells web robots not to index and follow content. |
| 83 | * |
| 84 | * @since 2.10.0 |
| 85 | */ |
| 86 | public function noRobots() |
| 87 | { |
| 88 | echo "<meta name='robots' content='noindex,nofollow'/>\n"; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Handle enqueue script |
| 93 | * |
| 94 | * @since 2.10.0 |
| 95 | */ |
| 96 | public function handleEnqueueScripts() |
| 97 | { |
| 98 | global $wp_scripts, $wp_styles; |
| 99 | wp_enqueue_scripts(); |
| 100 | |
| 101 | $wp_styles->dequeue($this->getListOfScriptsToDequeue($wp_styles->registered)); |
| 102 | $wp_scripts->dequeue($this->getListOfScriptsToDequeue($wp_scripts->registered)); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Get filter list to dequeue scripts and style |
| 107 | * |
| 108 | * @since 2.10.0 |
| 109 | * |
| 110 | * @param array $scripts |
| 111 | * |
| 112 | * @return array |
| 113 | */ |
| 114 | private function getListOfScriptsToDequeue($scripts) |
| 115 | { |
| 116 | $list = []; |
| 117 | $skip = []; |
| 118 | $themeDir = get_template_directory_uri(); |
| 119 | |
| 120 | /* @var _WP_Dependency $data */ |
| 121 | foreach ($scripts as $handle => $data) { |
| 122 | // Do not unset dependency. |
| 123 | if (in_array($handle, $skip, true)) { |
| 124 | continue; |
| 125 | } |
| 126 | |
| 127 | // Do not allow styles and scripts from theme. |
| 128 | if (false !== strpos((string)$data->src, $themeDir)) { |
| 129 | $list[] = $handle; |
| 130 | continue; |
| 131 | } |
| 132 | |
| 133 | if ( |
| 134 | 0 === strpos($handle, 'give') || |
| 135 | false !== strpos($data->src, '\give') |
| 136 | ) { |
| 137 | // Store dependencies to skip. |
| 138 | $skip = array_merge($skip, $data->deps); |
| 139 | continue; |
| 140 | } |
| 141 | |
| 142 | $list[] = $handle; |
| 143 | } |
| 144 | |
| 145 | return $list; |
| 146 | } |
| 147 | } |
| 148 |