• Resolved Shailesh

    (@shaileshsavaliya)


    Hi,
    I am writing plugin. I have added 1 custom table in database.

    Suppose my plugin’s current version is 1.0
    After few days i am upgrading plugin and now its version 1.2.
    Same for after some time and now version is 1.3 and ….. 1.4

    Now for every release of plugin version I have made some changes in database.

    Than how can i upgrade database. I know about store db version in options table.

    But i don’t know because some user update his plugin from 1.1 -> 1.2, other is from 1.1 -> 1.4……… some is 1.2 -> 1.4..etc.. Than there is only way to add all conditions to code or any other solution is available?????

Viewing 1 replies (of 1 total)
  • Thread Starter Shailesh

    (@shaileshsavaliya)

    I got the answere

    $db_version = get_option( 'my_plugin_version' );
    
    if ( version_compare( $db_version, '1.1', '<' ) ) {
        // Initial update code added in 1.1
    }
    
    if ( version_compare( $db_version, '1.2', '<' ) ) {
        // Additional update code added in 1.2
    }
    
    if ( version_compare( $db_version, '1.3', '<' ) ) {
        // And so forth
    }
    
    update_option( 'my_plugin_version', '1.3' );
Viewing 1 replies (of 1 total)
  • The topic ‘WordPress plugin DB upgrade’ is closed to new replies.