Plugin Directory

Changeset 2213289


Ignore:
Timestamp:
12/16/2019 11:24:56 PM (6 years ago)
Author:
benhallbenhall
Message:

Support for an Upgrade Callback

Location:
wpdevhub-dlm/trunk/classes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wpdevhub-dlm/trunk/classes/class.DSCF_DLM_Utilities.php

    r1981731 r2213289  
    3030     * @static
    3131     * @param $currentVersion
    32      * @param $installCallback
    33      */
    34     public static function checkForUpgrade($currentVersion, $installCallback){
     32     * @param $upgradeCallback
     33     */
     34    public static function checkForUpgrade($currentVersion, $upgradeCallback){
    3535        global $wpdb;
    3636        $installedVersion = DSCF_DLM_Utilities::getInstalledVersionNumber();
    3737        if ( $currentVersion != $installedVersion) {
    38             // Upgrade the Database
    39             call_user_func($installCallback);
     38            // Run items in the upgrade callback (should be "upgradePlugin")
     39            call_user_func($upgradeCallback);
    4040
    4141            // Update the version number in the Options Database
  • wpdevhub-dlm/trunk/classes/core/class.DSCF_DLM_StandardMain.php

    r1981731 r2213289  
    8282        register_deactivation_hook(__FILE__, array(static::$classname, 'wpActionDeactivate'));
    8383
    84         // Check for a Database Upgrade
    85         if(static::SWITCH_USE_DATABASE){
    86             DSCF_DLM_Utilities::checkForUpgrade(static::CURRENT_VERSION, array(static::$classname,'installDatabase'));
    87         }
     84        // Check for a Plugin Upgrade
     85        DSCF_DLM_Utilities::checkForUpgrade(static::CURRENT_VERSION, array(static::$classname,'upgradePlugin'));
    8886
    8987        // Register the settings
     
    390388        $object = new $classname();
    391389
    392         add_filter( 'the_content', array($classname, 'wpFilterTheContent'));
    393         add_filter( 'the_excerpt', array($classname, 'wpFilterTheExcerpt'));
    394         add_filter( 'get_the_excerpt', array($classname, 'wpFilterTheExcerpt'));
     390        add_filter( 'the_content', array($classname, 'wpFilterTheContent'), 9); // Put before 10 so that we grab content before applying filters
     391        add_filter( 'the_excerpt', array($classname, 'wpFilterTheExcerpt'), 9);
     392        add_filter( 'get_the_excerpt', array($classname, 'wpFilterTheExcerpt'), 9);
    395393        add_filter( 'get_the_archive_title', array($classname, 'wpFilterGetTheArchiveTitle'));
    396394
     
    419417    }
    420418
     419    /*
     420     * Migrates the plugin from one version to another.  Is triggered by the CURRENT_VERSION being different
     421     */
     422    public static function upgradePlugin(){
     423
     424        // First call the install database routine and update the scheme as needed
     425        call_user_func(array(static::$classname, 'installDatabase'));
     426
     427        // get the current installed version
     428        $oldVersion = DSCF_DLM_Utilities::getInstalledVersionNumber();
     429
     430        // Now loop through and migrate the plugin one by one.  That way if installed version is 2 and new version is 5, this will be called 3 times.
     431        for($i = $oldVersion; $i <= static::CURRENT_VERSION; $i++){
     432            static::migratePluginVersions($i);
     433        }
     434
     435    }
     436
     437    // Child plugins will implement this to indicate routines that need to be executed when migrating off an old plugin version
     438    public static function migratePluginVersions($oldVersion){}
     439
    421440}
Note: See TracChangeset for help on using the changeset viewer.