wordpress插件 - 网站数据库

时间:2015-10-31 08:09:50

标签: php mysql wordpress

您好,感谢您停下来并抽出时间回答我的问题。 首先,我从未编写过Wordpress的插件,这是我的第一个菜鸟。

我制作了主题并使用了第三方插件并对其进行了编辑。然而,这是一个全新的球赛。

我希望能够做到以下其中一项 - 以最好者为准。

  1. 1表 - 所有网络站点都有自己的数据,但它们都存储在一个表中。
  2. CREATE TABLE myplugin (
    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    networkid INT(30) NOT NULL,
    datereserved DATE NOT NULL,
    timeslot TIME NOT NULL,
    bookedby VARCHAR(60),
    datetimebookedon TIMESTAMP,
    paidstatus INT(1) NOT NULL,
    paidstripid VARCHAR(40)
    )
    

    或者我应该将它拆分成自己的表格,如果是这样的话?

    这里是代码但不是我想要的。我认为这很容易,而不是火箭科学 - 请一个简单的插件,在一个插件格式中概述hello world,这个插件可以用于创建数据库的单个和网络站点,这将是很好的 - 这是很难要求的。一小时的视频毫无意义。

    <?php
    defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
    /**
     * Plugin Name: Book Online
     * Plugin URI: http://harrower.xyz
     * Description: This plugin allows your customers to schedual a time to meet with you and pay any fee that you require.
     * Version: 1.0.0
     * Author: Harrower.xyz
     * Author URI: http://harrower.xyz
     * License: GPL2
     */
     /**
      * Start the plugin only if in Admin side and if site is Multisite
      */
     if( is_admin() && is_multisite() )
     {
         add_action(
             'plugins_loaded',
             array ( book_online_multisite::get_instance(), 'plugin_setup' )
         );
     }
    
     class book_online_multisite
     {
         protected static $instance = NULL;
         public $blogs = array();
         public $plugin_url = '';
         public $plugin_path = '';
    
         public static function get_instance()
         {
             NULL === self::$instance and self::$instance = new self;
             return self::$instance;
         }
    
         /**
          * Plugin URL and Path work as normal
          */
         public function plugin_setup()
         {
             $this->plugin_url    = plugins_url( '/', __FILE__ );
             $this->plugin_path   = plugin_dir_path( __FILE__ );
             add_action(
                 'book-online-dashboard.php',
                 array( $this, 'load_blogs' )
             );
             add_action( 'admin_menu', 'register_my_custom_menu_page' );
         }
    
    
         // this is the menu area
         function register_my_custom_menu_page() {
    
         add_menu_page( 'Book Online', 'Book Online <span class="update-plugins count-1"><span class="plugin-count">1</span></span>', 'manage_options', 'book-online/book-online-admin.php', 'book-online-admin-menu', 'dashicons-clock', 6 );
    
    
         }
    
    
    
    
    
    /// function to create the DB / Options / Defaults
     function book_online_options_install() {
        global $wpdb;
        global $bonlinedb;
    
        $book_online_caldb = $wpdb->prefix . "booking_online_calendar";
        $book_online_customersdb = $wpdb->prefix . "booking_online_customers";
    
        // create the ECPT metabox database table
        if($wpdb->get_var("show tables like '$book_online_customersdb'") != $book_online_customersdb)
        {
        //$bonlinedb = $wpdb->prefix . 'bookonline';
            $sql = "CREATE TABLE  `$book_online_customersdb` (
            `id` INT() NOT NULL AUTO_INCREMENT,
            `booking_date`DATE NOT NULL,
            UNIQUE KEY id (id)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;";
    
            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
            dbDelta($sql);
        }
    
    
      // create the ECPT metabox database table
        if($wpdb->get_var("show tables like '$book_online_caldb'") != $book_online_caldb)
        {
            $sql = "CREATE TABLE `$book_online_caldb` (
            `id` INT() NOT NULL AUTO_INCREMENT,
        `bid` INT() NOT NULL,
        `booking_time` TIME NOT NULL,
        `status` INT() NOT NULL DEFAULT  '0';
            UNIQUE KEY id (id))ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;";
    
            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
            dbDelta($sql);
        }
    
      // this is the menu area
      function register_my_custom_menu_page() {
    
      add_menu_page( 'Book Online', 'Book Online <span class="update-plugins count-1"><span class="plugin-count">1</span></span>', 'manage_options', 'book-online/book-online-admin.php', 'book-online-admin-menu', 'dashicons-clock', 6 );
      add_submenu_page( 'book-online-admin-menu', 'My Custom Page', 'My Custom Page',
          'manage_options', 'my-top-level-slug');
      add_submenu_page( 'ook-online-admin-menu', 'My Custom Submenu Page', 'My Custom Submenu Page',
          'manage_options', 'my-secondary-slug');
    
      }
    
    
      add_action( 'admin_menu', 'register_my_custom_menu_page' );
    /*
    
    
    
         public function __construct() {}
    
         public function load_blogs()
         {
             /**
              * Using "is_network" property from $current_screen global variable.
              * Run only in /wp-admin/network/plugins.php
              */
             global $current_screen;
             if( !$current_screen->is_network )
                 return;
    
              /*
              *A couple of Multisite-only filter hooks and a regular one.
              */
            add_action(
                     'network_admin_plugin_action_links',
                     array( $this, 'list_plugins' ),
                     10, 4
            );
            * add_filter(
            *         'views_plugins-network', // 'views_{$current_screen->id}'
            *         array( $this, 'inactive_views' ),
            *         10, 1
             *);
             *add_action(
            *         'admin_print_scripts',
          *           array( $this, 'enqueue')
          *   );
             */
             /**
              * This query is quite frequent to retrieve all blog IDs.
              */
             global $wpdb;
             $this->blogs = $wpdb->get_results(
                     " SELECT blog_id, domain
                     FROM {$wpdb->blogs}
                     WHERE site_id = '{$wpdb->siteid}'
                     AND spam = '0'
                     AND deleted = '0'
                     AND archived = '0' "
             );
         }
    
         /**
          * Enqueue script and style normally.
          */
         public function enqueue()
         {
             wp_enqueue_script(
                     'ndbae-js',
                     $this->plugin_url . 'core/ndbae.js',
                     array(),
                     false,
                     true
             );
             wp_enqueue_style(
                     'main',
                     $this->plugin_url . 'core/main.css'
             );
         }
    
         /**
          * Check if plugin is active in any blog
          * Using Multisite function get_blog_option
          */
         private function get_network_plugins_active( $plug )
         {
             $active_in_blogs = array();
             foreach( $this->blogs as $blog )
             {
                 $the_plugs = get_blog_option( $blog['blog_id'], 'active_plugins' );
                 foreach( $the_plugs as $value )
                 {
                     if( $value == $plug )
                         $active_in_blogs[] = $blog['domain'];
                 }
             }
             return $active_in_blogs;
         }
     }
    
    
    class book_online_single_site{
    
    
    
     // function to create the DB / Options / Defaults
     function book_online_options_install() {
            global $wpdb;
        global $bonlinedb;
    
        $book_online_caldb = $wpdb->prefix . "booking_online_calendar";
        $book_online_customersdb = $wpdb->prefix . "booking_online_customers";
    
        // create the ECPT metabox database table
        if($wpdb->get_var("show tables like '$book_online_customersdb'") != $book_online_customersdb)
        {
        //$bonlinedb = $wpdb->prefix . 'bookonline';
            $sql = "CREATE TABLE  `$book_online_customersdb` (
            `id` INT() NOT NULL AUTO_INCREMENT,
            `booking_date`DATE NOT NULL,
            UNIQUE KEY id (id)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;";
    
            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
            dbDelta($sql);
        }
    
    
      // create the ECPT metabox database table
        if($wpdb->get_var("show tables like '$book_online_caldb'") != $book_online_caldb)
        {
            $sql = "CREATE TABLE `$book_online_caldb` (
            `id` INT() NOT NULL AUTO_INCREMENT,
        `bid` INT() NOT NULL,
        `booking_time` TIME NOT NULL,
        `status` INT() NOT NULL DEFAULT  '0';
            UNIQUE KEY id (id))ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;";
    
            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
            dbDelta($sql);
        }
    
      // this is the menu area
      function register_my_custom_menu_page() {
    
      add_menu_page( 'Book Online', 'Book Online <span class="update-plugins count-1"><span class="plugin-count">1</span></span>', 'manage_options', 'book-online/book-online-admin.php', 'book-online-admin-menu', 'dashicons-clock', 6 );
      add_submenu_page( 'book-online-admin-menu', 'My Custom Page', 'My Custom Page',
          'manage_options', 'my-top-level-slug');
      add_submenu_page( 'ook-online-admin-menu', 'My Custom Submenu Page', 'My Custom Submenu Page',
          'manage_options', 'my-secondary-slug');
    
      }
    
    
      add_action( 'admin_menu', 'register_my_custom_menu_page' );
    
    
      add_action( 'wp_head', 'book_online' );
        function book_online() {
          echo 'I am in the head section';
        }
    
        add_shortcode( 'bookonline', 'book_online_live' );
        function book_online_live() {
          return 'this is a test';
        }
    
        // run the install scripts upon plugin activation
        register_activation_hook(__FILE__,'book_online_options_install');
    
     }
    
    
    
    }
     ?>
    

0 个答案:

没有答案