| @@ -3,8 +3,97 @@ | ||
| 3 | 3 | namespace FlyWP; |
| 4 | 4 | |
| 5 | 5 | class Admin { |
| 6 | 6 | |
| 7 | + /** | |
| 8 | + * Admin page slug. | |
| 9 | + */ | |
| 10 | + const PAGE_SLUG = 'flywp'; | |
| 11 | + | |
| 12 | + /** | |
| 13 | + * Screen name. | |
| 14 | + * | |
| 15 | + * @var string | |
| 16 | + */ | |
| 17 | + const SCREEN_NAME = 'tools_page_flywp'; | |
| 18 | + | |
| 19 | + public $fastcgi = null; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * Admin constructor. | |
| 23 | + */ | |
| 7 | 24 | public function __construct() { |
| 8 | - // code | |
| 25 | + add_action( 'admin_menu', [ $this, 'register_admin_page' ] ); | |
| 26 | + | |
| 27 | + $this->fastcgi = new Admin\Fastcgi_Cache(); | |
| 28 | + | |
| 29 | + new Admin\Adminbar(); | |
| 30 | + new Admin\Opcache(); | |
| 31 | + new Admin\Plugins(); | |
| 32 | + } | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * Register admin page. | |
| 36 | + */ | |
| 37 | + public function register_admin_page() { | |
| 38 | + $hook = add_submenu_page( | |
| 39 | + 'tools.php', | |
| 40 | + __( 'FlyWP', 'flywp' ), | |
| 41 | + __( 'FlyWP', 'flywp' ), | |
| 42 | + 'manage_options', | |
| 43 | + self::PAGE_SLUG, | |
| 44 | + [ $this, 'render_admin_page' ] | |
| 45 | + ); | |
| 46 | + | |
| 47 | + add_action( "admin_print_styles-{$hook}", [ $this, 'enqueue_styles' ] ); | |
| 48 | + add_action( "admin_print_scripts-{$hook}", [ $this, 'enqueue_js' ] ); | |
| 49 | + add_filter( 'removable_query_args', [ $this, 'removable_query_args' ] ); | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Get admin page url. | |
| 54 | + * | |
| 55 | + * @return string | |
| 56 | + */ | |
| 57 | + public function page_url() { | |
| 58 | + return admin_url( 'tools.php?page=' . self::PAGE_SLUG ); | |
| 59 | + } | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * Add query args to removable query args. | |
| 63 | + * | |
| 64 | + * @param array $args | |
| 65 | + * | |
| 66 | + * @return array | |
| 67 | + */ | |
| 68 | + public function removable_query_args( $args ) { | |
| 69 | + $args[] = 'fly-notice'; | |
| 70 | + | |
| 71 | + return $args; | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * Enqueue admin styles. | |
| 76 | + */ | |
| 77 | + public function enqueue_styles() { | |
| 78 | + $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | |
| 79 | + | |
| 80 | + wp_enqueue_style( 'flywp-admin-styles', FLYWP_PLUGIN_URL . '/assets/css/app' . $min . '.css', [], FLYWP_VERSION ); | |
| 81 | + } | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * Enqueue admin scripts. | |
| 85 | + */ | |
| 86 | + public function enqueue_js() { | |
| 87 | + $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | |
| 88 | + | |
| 89 | + wp_enqueue_script( 'flywp-chart', FLYWP_PLUGIN_URL . '/assets/js/chart.min.js', [], FLYWP_VERSION, true ); | |
| 90 | + wp_enqueue_script( 'flywp-admin-js', FLYWP_PLUGIN_URL . '/assets/js/admin' . $min . '.js', [ 'jquery', 'flywp-chart' ], FLYWP_VERSION, true ); | |
| 91 | + } | |
| 92 | + | |
| 93 | + /** | |
| 94 | + * Render admin page. | |
| 95 | + */ | |
| 96 | + public function render_admin_page() { | |
| 97 | + include FLYWP_PLUGIN_DIR . '/views/admin.php'; | |
| 9 | 98 | } |
| 10 | 99 | } |