Endpoints
4 years ago
Repositories
4 years ago
resources
4 years ago
DonationFormsAdminPage.php
4 years ago
ServiceProvider.php
4 years ago
DonationFormsAdminPage.php
70 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\DonationForms; |
| 4 | |
| 5 | use Give\Helpers\EnqueueScript; |
| 6 | |
| 7 | /** |
| 8 | * @since 2.19.0 |
| 9 | */ |
| 10 | class DonationFormsAdminPage |
| 11 | { |
| 12 | /** |
| 13 | * Register menu item |
| 14 | */ |
| 15 | public function register() |
| 16 | { |
| 17 | remove_submenu_page('edit.php?post_type=give_forms', 'edit.php?post_type=give_forms'); |
| 18 | add_submenu_page( |
| 19 | 'edit.php?post_type=give_forms', |
| 20 | esc_html__('Donation Forms', 'give'), |
| 21 | esc_html__('All Forms', 'give'), |
| 22 | 'edit_give_forms', |
| 23 | 'give-forms', |
| 24 | [$this, 'render'], |
| 25 | 1 |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Load scripts |
| 31 | */ |
| 32 | public function loadScripts() |
| 33 | { |
| 34 | $data = [ |
| 35 | 'apiRoot' => esc_url_raw(rest_url('give-api/v2/admin/forms')), |
| 36 | 'apiNonce' => wp_create_nonce('wp_rest'), |
| 37 | ]; |
| 38 | |
| 39 | EnqueueScript::make('give-admin-donation-forms', 'assets/dist/js/give-admin-donation-forms.js') |
| 40 | ->loadInFooter() |
| 41 | ->registerTranslations() |
| 42 | ->registerLocalizeData('GiveDonationForms', $data)->enqueue(); |
| 43 | |
| 44 | wp_enqueue_style( |
| 45 | 'give-admin-ui-font', |
| 46 | 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@400..700&display=swap', |
| 47 | [], |
| 48 | null |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Render admin page |
| 54 | */ |
| 55 | public function render() |
| 56 | { |
| 57 | echo '<div id="give-admin-donation-forms-root"></div>'; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Helper function to determine if current page is Give Add-ons admin page |
| 62 | * |
| 63 | * @return bool |
| 64 | */ |
| 65 | public static function isShowing() |
| 66 | { |
| 67 | return isset($_GET['page']) && $_GET['page'] === 'give-forms'; |
| 68 | } |
| 69 | } |
| 70 |