*/ class Ai_Preloader_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; add_action( 'admin_menu', array( $this, 'register_my_custom_menu_page' ) ); add_action( 'admin_init', array( $this, 'display_options' ) ); } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Ai_Preloader_Loader as all of the hooks are defined * in that particular class. * * The Ai_Preloader_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/ai-preloader-admin.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Ai_Preloader_Loader as all of the hooks are defined * in that particular class. * * The Ai_Preloader_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_script( 'picker-alpha', plugin_dir_url( __FILE__ ) . 'js/wp-color-picker-alpha.min.js', array( 'wp-color-picker' ), $this->version, false ); wp_enqueue_script( 'picker', plugin_dir_url( __FILE__ ) . 'js/color-picker.js', array( 'wp-color-picker' ), $this->version, false ); wp_enqueue_media(); wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/ai-preloader-admin.js', array( 'jquery' ), $this->version, false ); } /** * Register a custom menu page. */ function register_my_custom_menu_page() { add_menu_page( __( 'AI Preloader', 'ai-preloader' ), 'AI Preloader', 'manage_options', 'ai-menu-page', array( $this, 'myAdminPage' ), 'dashicons-marker', 6 ); } public function myAdminPage() { require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/admin-menu-page.php'; } /* WordPress Settings API */ function display_options() { //section name, display name, callback to print description of section, page to which section is attached. add_settings_section("header_section", "", array( $this, 'display_header_options_content' ), "ai-menu-page"); //setting name, display name, callback to print form element, page in which field is displayed, section to which it belongs. //last field section is optional. add_settings_field("demo-select", "Preloader Style", array( $this, 'demo_select_display' ), "ai-menu-page", "header_section"); add_settings_field("loader_bg", "Preloader BG", array( $this, 'loader_bg_field_callback' ), "ai-menu-page", "header_section"); add_settings_field("primary_color", "Primary Color", array( $this, 'primary_color_field_callback' ), "ai-menu-page", "header_section"); add_settings_field("loader_image", "Preloader Image", array( $this, 'loader_img_field_callback' ), "ai-menu-page", "header_section"); add_settings_field("display_on", "Display Preloader", array( $this, 'display_on_field_callback' ), "ai-menu-page", "header_section"); //section name, form element name, callback for sanitization register_setting("header_section", "demo-select"); register_setting("header_section", "loader_bg"); register_setting("header_section", "primary_color"); register_setting("header_section", "loader_image"); register_setting("header_section", "display_on"); } function display_header_options_content(){ //echo "The header of the theme"; } function demo_select_display(){ ?>

Choose CSS loader style here.

'; echo '

Choose background color, default color is #111.

'; } function primary_color_field_callback() { echo ''; echo '

Choose primary color, default color is #EE4040.

'; } function loader_img_field_callback(){ $picture = esc_attr( get_option('loader_image') ); if( empty($picture) ){ ?>

Preloader Image will override the CSS loader.

Preloader Image will override the CSS loader

preview-img