load_menu_icon(); // Early return if not on plugin's admin page (prevents loading heavy data). if ( 'toplevel_page_ajaxpress' !== $screen && 'settings_page_ajaxpress' !== $screen ) { return false; } wp_enqueue_media(); // Enqueue code editor for syntax highlighting wp_enqueue_code_editor(array( 'type' => 'text/javascript', 'codemirror' => array( 'mode' => 'javascript', 'lineNumbers' => true, 'indentUnit' => 2, 'tabSize' => 2, ), )); wp_enqueue_style('ajaxpress-admin', AJAXPRESS_URL . 'public/css/admin.min.css', array(), AJAXPRESS_VERSION); wp_enqueue_script('ajaxpress-admin', AJAXPRESS_URL . 'public/js/admin.min.js', array(), AJAXPRESS_VERSION, true); // Inline CSS. $inline_css = $this->get_inline_css(); wp_add_inline_style('ajaxpress-admin', $inline_css); // Inline script. $inline_script = $this->get_inline_script(); wp_localize_script('ajaxpress-admin', 'ajaxpress_admin_vars', $inline_script); do_action('ajaxpress_loaded'); return true; } /** * Load AjaxPress menu icon. * * @return void */ public function load_menu_icon() { $css = '.wp-menu-image.dashicons-ajaxpress { position: relative; transform: rotate(45deg); } .wp-menu-image.dashicons-ajaxpress:after { content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%); background: url(' . AJAXPRESS_URL . '/public/images/logo.gif) no-repeat center center; background-size: 80%; width: 36px; height: 34px; }'; wp_enqueue_style('ajaxpress_menu_icon', esc_url(AJAXPRESS_URL) . '/public/css/blank.css', array(), AJAXPRESS_VERSION); wp_add_inline_style('ajaxpress_menu_icon', $css); } /** * Get Inline CSS. * * @return string */ public function get_inline_css() { $css = '#wpcontent { padding-left: 0 !important; }'; return $css; } /** * Get server information. * * @return array */ private function get_server_info() { global $wpdb; $server_software = isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : 'N/A'; $platform = 'N/A'; if ( stripos( $server_software, 'nginx' ) !== false ) { $platform = 'nginx'; } elseif ( stripos( $server_software, 'apache' ) !== false ) { $platform = 'apache'; } elseif ( stripos( $server_software, 'litespeed' ) !== false ) { $platform = 'litespeed'; } elseif ( stripos( $server_software, 'iis' ) !== false ) { $platform = 'iis'; } elseif ( 'N/A' !== $server_software ) { $platform = $server_software; } return array( 'php_version' => phpversion(), 'mysql_version' => $wpdb->db_version(), 'server_platform' => $platform, 'server_os' => function_exists( 'php_uname' ) ? php_uname( 's' ) : PHP_OS, 'server_software' => $server_software, ); } /** * Get Inline Script. * * @return array */ public function get_inline_script() { $options = new \AjaxPress\Options(); $script = array( 'rest' => array( 'url' => rest_url('ajaxpress'), 'nonce' => wp_create_nonce('wp_rest'), ), 'site' => array( 'url' => get_site_url(), 'name' => get_bloginfo('name'), 'language' => get_bloginfo('language'), 'admin_email' => get_bloginfo('admin_email'), 'active_plugins' => get_option('active_plugins', array()), 'active_theme' => get_option('template', ''), 'is_multisite' => is_multisite(), 'wp_version' => get_bloginfo('version'), 'timezone' => wp_timezone_string(), ), 'plugin' => array( 'url' => plugin_dir_url(AJAXPRESS), 'version' => AJAXPRESS_VERSION, ), 'server_info' => $this->get_server_info(), 'strings' => \AjaxPress\Language::get_strings(), 'default_settings' => $options->get_default_settings(), 'settings' => $options->get_settings(), 'license' => (array) get_option( 'ajaxpress_license', [] ), 'diagnostic_permission' => get_option( 'ajaxpress_diagnostic_permission', '' ), ); return $script; } } // Let's start. Enqueues::start(); }