Skip to content

Instantly share code, notes, and snippets.

@danielpataki
Last active February 22, 2021 16:21
Show Gist options
  • Save danielpataki/b45306318d19af77e24f to your computer and use it in GitHub Desktop.
Save danielpataki/b45306318d19af77e24f to your computer and use it in GitHub Desktop.

Revisions

  1. Daniel Pataki revised this gist Feb 1, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions update.php
    Original file line number Diff line number Diff line change
    @@ -26,6 +26,9 @@ function my_plugin_create_db() {
    UNIQUE KEY id (id)
    ) $charset_collate;";
    dbDelta( $sql );

    update_option( 'my_plugin_version', '2.0' );

    }


  2. Daniel Pataki revised this gist Feb 1, 2015. 1 changed file with 10 additions and 9 deletions.
    19 changes: 10 additions & 9 deletions update.php
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    function my_plugin_create_db() {

    global $wpdb;
    $version = get_option( 'my_plugin_version', '1.0' );
    $version = get_option( 'my_plugin_version', '1.0' );
    $charset_collate = $wpdb->get_charset_collate();
    $table_name = $wpdb->prefix . 'my_analysis';

    @@ -17,14 +17,15 @@ function my_plugin_create_db() {
    dbDelta( $sql );

    if ( version_compare( $version, '2.0' ) < 0 ) {
    $sql = "CREATE TABLE $table_name (
    id mediumint(9) NOT NULL AUTO_INCREMENT,
    time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    views smallint(5) NOT NULL,
    clicks smallint(5) NOT NULL,
    blog_id smallint(5) NOT NULL,
    UNIQUE KEY id (id)
    ) $charset_collate;";
    $sql = "CREATE TABLE $table_name (
    id mediumint(9) NOT NULL AUTO_INCREMENT,
    time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    views smallint(5) NOT NULL,
    clicks smallint(5) NOT NULL,
    blog_id smallint(5) NOT NULL,
    UNIQUE KEY id (id)
    ) $charset_collate;";
    dbDelta( $sql );
    }


  3. Daniel Pataki revised this gist Feb 1, 2015. 2 changed files with 36 additions and 1 deletion.
    31 changes: 31 additions & 0 deletions update.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    function my_plugin_create_db() {

    global $wpdb;
    $version = get_option( 'my_plugin_version', '1.0' );
    $charset_collate = $wpdb->get_charset_collate();
    $table_name = $wpdb->prefix . 'my_analysis';

    $sql = "CREATE TABLE $table_name (
    id mediumint(9) NOT NULL AUTO_INCREMENT,
    time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    views smallint(5) NOT NULL,
    clicks smallint(5) NOT NULL,
    UNIQUE KEY id (id)
    ) $charset_collate;";

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

    if ( version_compare( $version, '2.0' ) < 0 ) {
    $sql = "CREATE TABLE $table_name (
    id mediumint(9) NOT NULL AUTO_INCREMENT,
    time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    views smallint(5) NOT NULL,
    clicks smallint(5) NOT NULL,
    blog_id smallint(5) NOT NULL,
    UNIQUE KEY id (id)
    ) $charset_collate;";
    }


    }
    6 changes: 5 additions & 1 deletion version.php
    Original file line number Diff line number Diff line change
    @@ -1 +1,5 @@
    define( 'MY_PLUGIN_VERSION', '1.0' );
    function my_plugin_create_db() {
    global $wpdb;
    $version = get_option( 'my_plugin_version', '1.0' );
    // ...
    }
  4. Daniel Pataki revised this gist Feb 1, 2015. 1 changed file with 1 addition and 6 deletions.
    7 changes: 1 addition & 6 deletions version.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1 @@
    define( 'MY_PLUGIN_VERSION', '1.0' );

    register_activation_hook( __FILE__, 'my_plugin_create_db' );
    function my_plugin_create_db() {
    // Create DB Here
    }
    define( 'MY_PLUGIN_VERSION', '1.0' );
  5. Daniel Pataki revised this gist Jan 21, 2015. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions version.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    define( 'MY_PLUGIN_VERSION', '1.0' );

    register_activation_hook( __FILE__, 'my_plugin_create_db' );
    function my_plugin_create_db() {
    // Create DB Here
    }
  6. Daniel Pataki revised this gist Jan 21, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions create.php
    Original file line number Diff line number Diff line change
    @@ -7,8 +7,8 @@ function my_plugin_create_db() {
    $sql = "CREATE TABLE $table_name (
    id mediumint(9) NOT NULL AUTO_INCREMENT,
    time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    views tinyint(3) NOT NULL,
    clicks tinyint(3) NOT NULL,
    views smallint(5) NOT NULL,
    clicks smallint(5) NOT NULL,
    UNIQUE KEY id (id)
    ) $charset_collate;";

  7. Daniel Pataki revised this gist Jan 21, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions create.php
    Original file line number Diff line number Diff line change
    @@ -7,8 +7,8 @@ function my_plugin_create_db() {
    $sql = "CREATE TABLE $table_name (
    id mediumint(9) NOT NULL AUTO_INCREMENT,
    time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    views smallint(5) NOT NULL,
    clicks smalling(5) NOT NULL,
    views tinyint(3) NOT NULL,
    clicks tinyint(3) NOT NULL,
    UNIQUE KEY id (id)
    ) $charset_collate;";

  8. Daniel Pataki renamed this gist Jan 21, 2015. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions create-db.php → create.php
    Original file line number Diff line number Diff line change
    @@ -7,9 +7,8 @@ function my_plugin_create_db() {
    $sql = "CREATE TABLE $table_name (
    id mediumint(9) NOT NULL AUTO_INCREMENT,
    time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    name tinytext NOT NULL,
    text text NOT NULL,
    url varchar(55) DEFAULT '' NOT NULL,
    views smallint(5) NOT NULL,
    clicks smalling(5) NOT NULL,
    UNIQUE KEY id (id)
    ) $charset_collate;";

  9. Daniel Pataki revised this gist Jan 21, 2015. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions create-db.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    function my_plugin_create_db() {

    global $wpdb;
    $charset_collate = $wpdb->get_charset_collate();
    $table_name = $wpdb->prefix . 'my_analysis';

    $sql = "CREATE TABLE $table_name (
    id mediumint(9) NOT NULL AUTO_INCREMENT,
    time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    name tinytext NOT NULL,
    text text NOT NULL,
    url varchar(55) DEFAULT '' NOT NULL,
    UNIQUE KEY id (id)
    ) $charset_collate;";

    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    dbDelta( $sql );
    }
  10. Daniel Pataki created this gist Jan 21, 2015.
    4 changes: 4 additions & 0 deletions activation.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    register_activation_hook( __FILE__, 'my_plugin_create_db' );
    function my_plugin_create_db() {
    // Create DB Here
    }