Page.php
108 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Onboarding class |
| 5 | * |
| 6 | * @package Give |
| 7 | */ |
| 8 | |
| 9 | namespace Give\Onboarding\Setup; |
| 10 | |
| 11 | use Give\DonationForms\V2\DonationFormsAdminPage; |
| 12 | |
| 13 | defined('ABSPATH') || exit; |
| 14 | |
| 15 | /** |
| 16 | * Organizes WordPress actions and helper methods for Onboarding. |
| 17 | * |
| 18 | * @since 2.8.0 |
| 19 | */ |
| 20 | class Page |
| 21 | { |
| 22 | |
| 23 | const ENABLED = 'enabled'; |
| 24 | const DISABLED = 'disabled'; |
| 25 | |
| 26 | /** |
| 27 | * Dismiss the Setup Page. |
| 28 | * |
| 29 | * @since 2.8.0 |
| 30 | */ |
| 31 | public function dismissSetupPage() |
| 32 | { |
| 33 | if (wp_verify_nonce($_GET['_wpnonce'], 'dismiss_setup_page')) { |
| 34 | give_update_option('setup_page_enabled', self::DISABLED); |
| 35 | |
| 36 | wp_redirect(DonationFormsAdminPage::getUrl()); |
| 37 | exit; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Helper method for checking the if the Setup Page is enabled. |
| 43 | * |
| 44 | * @since 2.8.0 |
| 45 | * |
| 46 | * @return string |
| 47 | */ |
| 48 | public static function getSetupPageEnabledOrDisabled() |
| 49 | { |
| 50 | return give_get_option('setup_page_enabled', self::DISABLED); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Add Setup submenu page to admin menu |
| 55 | * |
| 56 | * @since 2.8.0 |
| 57 | */ |
| 58 | public function add_page() |
| 59 | { |
| 60 | add_submenu_page( |
| 61 | 'edit.php?post_type=give_forms', |
| 62 | esc_html__('Set up GiveWP', 'give'), |
| 63 | esc_html__('Setup', 'give'), |
| 64 | 'manage_give_settings', |
| 65 | 'give-setup', |
| 66 | [$this, 'render_page'] |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Enqueue scripts and styles. |
| 72 | * |
| 73 | * @since 2.8.0 |
| 74 | */ |
| 75 | public function enqueue_scripts() |
| 76 | { |
| 77 | if (!isset($_GET['page']) || 'give-setup' !== $_GET['page']) { |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | wp_enqueue_style( |
| 82 | 'give-admin-setup-style', |
| 83 | GIVE_PLUGIN_URL . 'assets/dist/css/admin-setup.css', |
| 84 | [], |
| 85 | GIVE_VERSION |
| 86 | ); |
| 87 | wp_enqueue_style('givewp-admin-fonts'); |
| 88 | wp_enqueue_script( |
| 89 | 'give-admin-setup-script', |
| 90 | GIVE_PLUGIN_URL . 'assets/dist/js/admin-setup.js', |
| 91 | ['jquery'], |
| 92 | GIVE_VERSION, |
| 93 | $in_footer = true |
| 94 | ); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Render the submenu page |
| 99 | * |
| 100 | * @since 2.8.0 |
| 101 | */ |
| 102 | public function render_page() |
| 103 | { |
| 104 | $view = give()->make(PageView::class); |
| 105 | echo $view->render(); |
| 106 | } |
| 107 | } |
| 108 |