AdminNoticeHandler.php
4 years ago
RequestHandler.php
4 years ago
TopLevelMenuRedirect.php
4 years ago
TopLevelMenuRedirect.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Onboarding\Setup\Handlers; |
| 4 | |
| 5 | defined('ABSPATH') || exit; |
| 6 | |
| 7 | /** |
| 8 | * Redirect the top level "Donations" menu to the Setup submenu. |
| 9 | * This normalizes the Setup Page URL so that assets load correctly. |
| 10 | */ |
| 11 | class TopLevelMenuRedirect implements RequestHandler |
| 12 | { |
| 13 | |
| 14 | /** |
| 15 | * @inheritdoc |
| 16 | * |
| 17 | * @since 2.8.0 |
| 18 | */ |
| 19 | public function maybeHandle() |
| 20 | { |
| 21 | if (isset($_GET['page']) && 'give-setup' == $_GET['page'] && ! isset($_GET['post_type'])) { |
| 22 | $this->handle(); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @inheritdoc |
| 28 | * |
| 29 | * @since 2.8.0 |
| 30 | */ |
| 31 | public function handle() |
| 32 | { |
| 33 | wp_redirect( |
| 34 | $this->getRedirectUrl() |
| 35 | ); |
| 36 | exit; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @since 2.8.0 |
| 41 | */ |
| 42 | protected function getRedirectUrl() |
| 43 | { |
| 44 | return add_query_arg( |
| 45 | [ |
| 46 | 'post_type' => 'give_forms', |
| 47 | 'page' => 'give-setup', |
| 48 | ], |
| 49 | admin_url('edit.php') |
| 50 | ); |
| 51 | } |
| 52 | } |
| 53 |