How to create an admin panel in wordpress

I am very new to writing plugins for wordpress.

I am looking at writing a plugin where a user can upload an image, and a certain style(coded in the back end) is applied to the image. Then i would allow a user to use a short code to input the image.

Read More

(the above is just an example of what i need to do… its a little bit more complex than this but im sure i can code it up once i get a start)

So i the shortcode i can do.

Firstly how would i go about creating a admin panel that can upload an image, and store that image in the database.

when ever a user would upload the image the previous image would be overwritten.

If someone has a link to a good tutorial on creating admin panels that would be great. the ones out there are just not working for me.

Related posts

Leave a Reply

3 comments

  1. This is another good place to start: http://codex.wordpress.org/Writing_a_Plugin

    This code should get you going :

    yourPlugin.php
    
    <?php
    /*
    Plugin Name: Name Of The Plugin
    Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
    Description: A brief description of the Plugin.
    Version: The Plugin's Version Number, e.g.: 1.0
    Author: Name Of The Plugin Author
    Author URI: http://URI_Of_The_Plugin_Author
    License: A "Slug" license name e.g. GPL2
    */
    
    /*  Copyright YEAR  PLUGIN_AUTHOR_NAME  (email : PLUGIN AUTHOR EMAIL)
    
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License, version 2, as 
        published by the Free Software Foundation.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    */
    
    $object = new YourPlugin();
    
    //add a hook into the admin header to check if the user has agreed to the terms and conditions.
    add_action('admin_head',  array($object, 'adminHeader'));
    
    //add footer code
    add_action( 'admin_footer',  array($object, 'adminFooter'));
    
    // Hook for adding admin menus
    add_action('admin_menu',  array($object, 'addMenu'));
    
    //This will create [yourshortcode] shortcode
    add_shortcode('yourshortcode', array($object, 'shortcode'));
    
    class YourPlugin{
    
        /**
         * This will create a menu item under the option menu
         * @see http://codex.wordpress.org/Function_Reference/add_options_page
         */
        public function addMenu(){
            add_options_page('Your Plugin Options', 'Your Plugin', 'manage_options', 'my-unique-identifier', array($this, 'optionPage'));
        }
    
        /**
         * This is where you add all the html and php for your option page
         * @see http://codex.wordpress.org/Function_Reference/add_options_page
         */
        public function optionPage(){
            echo "add your option page html here or include another php file";
        }
    
        /**
         * this is where you add the code that will be returned wherever you put your shortcode
         * @see http://codex.wordpress.org/Shortcode_API
         */
        public function shortcode(){
            return "add your image and html here...";
        }
    }
    ?>
    

    Add this code to a yourPlugin.php file and place it in your plugin directory. E.g plugins/yourPlugin/yourPlugin.php

  2. Adding something like the following to your plugin should get you started

    /*****Options Page Initialization*****/
    // if an admin is loading the admin menu then call the admin actions function
    if(is_admin()) add_action('admin_menu', 'my_options');
    // actions to perform when the admin menu is loaded
    function my_options(){add_options_page("My Options", "My Options", "edit_pages", "my-options", "my_admin");}
    // function called when "My Options" is selected from the admin menu
    function my_admin(){include('admin-options.php');}
    

    Then you would create a file named admin-options.php with the admin page presentation and functionality. Try a “Hello World” in that file just to see it appear.

    This code is explained in great detail in the WordPress Codex http://codex.wordpress.org/Adding_Administration_Menus which will also give you some examples of how to properly build out your page in a standard way.