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