Skip to main content
added 360 characters in body
Source Link

within my singleton I have these functions

/**class plugin {

  private *static CREATE$_instance;

 DATABASE TABLEprivate function __construct() {
   * creates//does all tableadd_actions & filters
   * @access$this->_register_hooks();
  }


  public static function getInstance() {
   * @sinceif 1.0( ! ( self::$_instance instanceof self ) ) {
   */     self::$_instance = new self();
    }

    return self::$_instance;
  }

  static function create_order_table() {
    global $wpdb;

      $table_name = $wpdb->prefix . "order";
      $charset_collate = $wpdb->get_charset_collate();

      $sql = "CREATE TABLE $table_name (
        id mediumint(9) NOT NULL AUTO_INCREMENT,
        name varchar(200) NOT NULL,
        description int(11) NOT NULL,
        alt_text int(11) NOT NULL,
        sort_order int(11) NOT NULL,
        time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
        PRIMARY KEY  (id)
      ) $charset_collate;";

      require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
      dbDelta( $sql );

      add_option( 'db_version', DB_VERSION );
  }

 


 /**
  * ATIVATION
  * on activation the plugin creates databases
  * @access privatepublic
  * @since 1.0
  */
    public function activate() {

        // DATABASE
        //creates table
    register_activation_hook( __FILE__, array( &$this, 'create_order_table' ) );
  }
}
    



    

and after I init my class I do this:

global $plugin;

if ( ! $plugin ) {
  $plugin = plugin::getInstance();
  $plugin->activate();
}

but nothing happens, why isn't it taking?

Any help is much appreciated.

within my singleton I have these functions

/**
   * CREATE DATABASE TABLE
   * creates  table
   * @access public
   * @since 1.0
   */
    static function create_order_table() {
    global $wpdb;

      $table_name = $wpdb->prefix . "order";
      $charset_collate = $wpdb->get_charset_collate();

    $sql = "CREATE TABLE $table_name (
        id mediumint(9) NOT NULL AUTO_INCREMENT,
        name varchar(200) NOT NULL,
        description int(11) NOT NULL,
        alt_text int(11) NOT NULL,
        sort_order int(11) NOT NULL,
        time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
        PRIMARY KEY  (id)
      ) $charset_collate;";

    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
      dbDelta( $sql );

      add_option( 'db_version', DB_VERSION );
  }

 


 /**
  * ATIVATION
  * on activation the plugin creates databases
  * @access private
  * @since 1.0
  */
    public function activate() {

        // DATABASE
        //creates table
    register_activation_hook( __FILE__, array( &$this, 'create_order_table' ) );
}

and after I init my class I do this:

$plugin->activate();

but nothing happens, why isn't it taking?

Any help is much appreciated.

within my singleton I have these functions

class plugin {

  private static $_instance;

  private function __construct() {
    //does all add_actions & filters
    $this->_register_hooks();
  }


  public static function getInstance() {
    if ( ! ( self::$_instance instanceof self ) ) {
        self::$_instance = new self();
    }

    return self::$_instance;
  }

  static function create_order_table() {
    global $wpdb;

      $table_name = $wpdb->prefix . "order";
      $charset_collate = $wpdb->get_charset_collate();

      $sql = "CREATE TABLE $table_name (
        id mediumint(9) NOT NULL AUTO_INCREMENT,
        name varchar(200) NOT NULL,
        description int(11) NOT NULL,
        alt_text int(11) NOT NULL,
        sort_order int(11) NOT NULL,
        time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
        PRIMARY KEY  (id)
      ) $charset_collate;";

      require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
      dbDelta( $sql );

      add_option( 'db_version', DB_VERSION );
  }


 /**
  * ATIVATION
  * on activation the plugin creates databases
  * @access public
  * @since 1.0
  */
  public function activate() {

        // DATABASE
        //creates table
    register_activation_hook( __FILE__, array( &$this, 'create_order_table' ) );
  }
}
    



    

and after I init my class I do this:

global $plugin;

if ( ! $plugin ) {
  $plugin = plugin::getInstance();
  $plugin->activate();
}

but nothing happens, why isn't it taking?

Any help is much appreciated.

Source Link

Singleton plugin activation; create database

within my singleton I have these functions

/**
   * CREATE DATABASE TABLE
   * creates  table
   * @access public
   * @since 1.0
   */
    static function create_order_table() {
    global $wpdb;

      $table_name = $wpdb->prefix . "order";
      $charset_collate = $wpdb->get_charset_collate();

    $sql = "CREATE TABLE $table_name (
        id mediumint(9) NOT NULL AUTO_INCREMENT,
        name varchar(200) NOT NULL,
        description int(11) NOT NULL,
        alt_text int(11) NOT NULL,
        sort_order int(11) NOT NULL,
        time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
        PRIMARY KEY  (id)
      ) $charset_collate;";

    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
      dbDelta( $sql );

      add_option( 'db_version', DB_VERSION );
  }




 /**
  * ATIVATION
  * on activation the plugin creates databases
  * @access private
  * @since 1.0
  */
    public function activate() {

        // DATABASE
        //creates table
    register_activation_hook( __FILE__, array( &$this, 'create_order_table' ) );
}

and after I init my class I do this:

$plugin->activate();

but nothing happens, why isn't it taking?

Any help is much appreciated.