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