WordPress plugin dir and files

Am building a simple plugin. When i activate it in wordpress admin i get a menu to work. But the question is how do i display my pages that i have made for the admin plugin.

I have been struggling with this the last three days but simply cant find the right way.

Read More

Code below.

vip.php

<?php
/*
Plugin Name: Testproject 0.0.1
Plugin URI: http://none.com
Description: Vip script for glamour bloggers
Author: Z
Version: 0.0.1
Author URI: http://none.com
*/

function vip_install()
{
    global $wpdb;
    $table = "vip_stat";
    $structure = "CREATE TABLE $table (
        id INT(9) NOT NULL AUTO_INCREMENT,
        number INT(9) DEFAULT 0,
        type TEXT(9) ,
        code INT(9) DEFAULT 0,
        cost TEXT(9) ,
        time TEXT(15) ,
        used INT(9) DEFAULT 1,
        utime TEXT(15) ,
        username TEXT(15) ,

    UNIQUE KEY id (id)
    );";
    $wpdb->query($structure);

    global $wpdb;
    $table = "vip_sales";
    $structure2 = "CREATE TABLE $table (
        id INT(9) NOT NULL AUTO_INCREMENT,
        type TEXT(9) ,
        date TEXT(9) ,
        price INT(9) DEFAULT 0,

    UNIQUE KEY id (id)
    );";
    $wpdb->query($structure2);
}

add_action( 'admin_menu', 'add_vip_menu' );

//Menu stuff

function add_vip_menu ()
{
     add_menu_page( 'Vip', 'Vip', 'manage_options', 'vip_stats', 'vip_stats' );
     //Sub menu display
    add_submenu_page( 'vip_stats', 'Stats', 'Stats', 'manage_options', 'vipstat', 'vip_status' );
    add_submenu_page( 'vip_stats', 'SMS', 'SMS', 'manage_options', 'vipsms', 'vip_sms' );
};

//Main menu code

function vip_stats ()
{
    //Here i would like to point to this file to display
   // /diagram/index.php 
};

//Sub code
function vip_status ()
    ////here i want to show this file
    // Here i want: /searchadmin/search.php
};

function vip_sms ()
{
    //Here i want to show this file
    // /sms/index.php
};

function vip_uninstall()
{
    global $wpdb;

    $uninstall = "DROP TABLE `vip_stat` ";
    $wpdb->query($uninstall);

     $uninstall2 = "DROP TABLE `vip_sales` ";
    $wpdb->query($uninstall2);

    remove_menu_page( Vip );
    mysqli_close($link);
};

register_activation_hook(__FILE__, 'vip_install');

register_deactivation_hook(__FILE__, 'vip_uninstall');

Related posts

Leave a Reply

1 comment

  1. Say the function was something like:

    add_submenu_page( 'vip_stats', 'SMS', 'SMS', 'manage_options', 'vipsms', 'vip_sms' );
    
    function vip_sms ()
    {
        ?>
        <div class="wrap">
            <div id="icon-options-general" class="icon32"></div>
            <h2>SMS</h2>
            <div id="poststuff">
                <div id="post-body" class="metabox-holder columns-2">
                    <!-- main content -->
                    <div id="post-body-content">
                        <div class="meta-box-sortables ui-sortable">
                            <div class="postbox">
                                <h3><span>Main Content Header</span></h3>
                                <div class="inside">
                                    <?php _e( 'Content Space' ); ?>
                                </div> <!-- .inside -->
                            </div> <!-- .postbox -->
                        </div> <!-- .meta-box-sortables .ui-sortable -->
                    </div> <!-- post-body-content -->
                    <!-- sidebar -->
                    <div id="postbox-container-1" class="postbox-container">
                        <div class="meta-box-sortables">
                            <h3><span>Sidebar Content Header</span></h3>
                            <div class="postbox">
                                <?php _e( 'Content Space' ); ?>
                            </div> <!-- .postbox -->
                        </div> <!-- .meta-box-sortables -->
                    </div> <!-- #postbox-container-1 .postbox-container -->
                </div> <!-- #post-body .metabox-holder .columns-2 -->
                <br class="clear">
            </div> <!-- #poststuff -->
        </div> <!-- .wrap -->
        <?php
    }
    

    Simply move all that HTML output to a PHP file and do a include_once:

    add_submenu_page( 'vip_stats', 'SMS', 'SMS', 'manage_options', 'vipsms', 'vip_sms' );
    
    function vip_sms ()
    {
        include_once 'includes/sms.php';
    }
    

    And the file /your-plugin/includes/sms.php would be:

    <?php
    /* Included file sms.php */
    ?>
    <div class="wrap">
        <div id="icon-options-general" class="icon32"></div>
        <h2>Name String</h2>
        <div id="poststuff">
            <div id="post-body" class="metabox-holder columns-2">
                <!-- main content -->
                <div id="post-body-content">
                    <div class="meta-box-sortables ui-sortable">
                        <div class="postbox">
                            <h3><span>Main Content Header</span></h3>
                            <div class="inside">
                                <?php _e( 'Content Space' ); ?>
                            </div> <!-- .inside -->
                        </div> <!-- .postbox -->
                    </div> <!-- .meta-box-sortables .ui-sortable -->
                </div> <!-- post-body-content -->
                <!-- sidebar -->
                <div id="postbox-container-1" class="postbox-container">
                    <div class="meta-box-sortables">
                        <h3><span>Sidebar Content Header</span></h3>
                        <div class="postbox">
                            <?php _e( 'Content Space' ); ?>
                        </div> <!-- .postbox -->
                    </div> <!-- .meta-box-sortables -->
                </div> <!-- #postbox-container-1 .postbox-container -->
            </div> <!-- #post-body .metabox-holder .columns-2 -->
            <br class="clear">
        </div> <!-- #poststuff -->
    </div> <!-- .wrap -->
    

    Admin styles by Frank Bultge’s WordPress Admin Style.

    Related: Is there any plugin development framework?