Wordpress - Plugin Template

A template for building plugins.

Structure

The following structure I use to create my first wp-plugin.

/css/

This style.css is only for the admin dashboard side.

/*
STYLESHEET FOR WORDPRESS ADMIN DASHBOARD
*/

/font-end/

The two examples above are index.php and main.php. Here you can simply add your own /css/ folder too.

index.php

<div id="test">
User Front End Code
</div>

main.php

<?php
add_shortcode( 'shortcode_code', 'my_shortcode_function' );

function my_shortcode_function( $atts, $content=null ) {
    $a = shortcode_atts( array(
        'licence' => 'gpl',
    ), $atts );

    //front-end user index.php
    //assign any php file to this shortcode
    include plugin_dir_path( __FILE__ ) . "index.php";
}
?>

/includes/

The /includes/ will store functions including pages that need to be displayed in the wordpress admin navigation menu.

index.php

<?php
    function myFunctionName(){
        echo 'Hello World';
    }
?>

menu.php

<?php
    function myFunctionMenu(){
        add_menu_page('PluginName', 'PluginName', 'manage_options', 'PluginName', 'myFunctionName', plugins_url('../images/logo.png', __FILE__));
    }
?>

main.php root

Here is where the code gets tied together.

<?php
    /*
    Plugin Name: My Plugin Name
    Plugin URI: http://newbworld.com
    Description: Simple description goes here
    Author: WordpressUsername
    Version 1.0
    Author URI: http://newbworld.com
    */

    //Includes Wordpress Admin Dashboard Files
    include( plugin_dir_path( __FILE__ ) . 'includes/menu.php');
    include( plugin_dir_path( __FILE__ ) . 'includes/index.php');

    //Front-end user files
    include( plugin_dir_path( __FILE__ ) . 'font-end/main.php');

    //Activation
    register_activation_hook( __FILE__ , 'myFunctionName');

    //Stylesheet Wordpress Admin Dashboard
    wp_register_style("my_style", plugins_url( 'css/style.css', __FILE__ ));
    wp_enqueue_style("my_style");

    //Menus
    add_action('admin_menu', 'myFunctionMenu');
?>

The structure is totally up to you. But for wordpress, I would much prefer seperating the admin and front-end code.