How can I create a simple interface for my WP plugin?

I’ve made a simple plugin to style the WP default backend.

<?php

/*
Plugin Name: Admin CSS
Description: Custom Admin style. Made by LOOT
Author: LOOT
Version: 1.2
Author URI: http://weareloot.com
*/

function admin_theme() {
    wp_enqueue_style('admin_theme', plugins_url('adminstyle.css', __FILE__));

}
function topbarstyle() {
    wp_enqueue_style('topbarstyle', plugins_url('topbarstyle.css', __FILE__));
}
add_action('admin_enqueue_scripts', 'admin_theme');
add_action('login_enqueue_scripts', 'admin_theme');
add_action('admin_enqueue_scripts', 'topbarstyle');
add_action('wp_head', 'topbarstyle' );
?>

Then I have a bunch of CSS files and some colours defined in the topbarstyle.css like this:

/* General Colours */
:root {
    --color1: #f5f5f5;
    --color2: #d8d7da;
    --color-accent: #2748f3;
    --color-dark: #23282d;
}

I’d want to implement a settings page where those colours can be modified.
I’m a total newbie in PHP and I’m trying to find resources, but thought I’d ask this over here as well
Thanks!

1 Answer
1

This should get you started. Once you’re more confident in plugin design I recommend using plugin boiler-plates you can create for free here: https://wppb.me/ They’ll look pretty scary at first but as you gain confidence and knowledge, you won’t be able to live without them.

Note: this is me just typing, expect typos.

    function My_Cool_Menu() {
        $icon_url = plugin_dir_url(__FILE__) . 'images/MyMenuIcon.png';
        add_menu_page('My Cool Page Title', 'My Cool Menu Title', 'edit_posts', 
        'MyPluginSlug', 'My_Cool_Plugin_main_menu', $icon_url);
    }

    function My_Cool_Plugin_main_menu() {
        //create your html admin menus, buttons and such in this file
        include_once( 'MyCoolAdminPage.php' );
    }


add_action('admin_menu', 'My_Cool_Menu');

edit and be sure you learn all about nonces!

Leave a Comment