Forums

[resolved] Coding plugin for upgrade (2 posts)

  1. ed4becky
    Member
    Posted 1 year ago #

    I understand from another thread that 3.1 will no longer call the activation hook when a plugin is upgraded.

    was wondering if someone could point me to a good example of calling upgrade code outside of the activation, so it is called the minimal number of times.

    My plugin has an internal version number I can use to check against, I'm just not sure of the best place to put the check against the version number and the call to the upgrade function

  2. ed4becky
    Member
    Posted 1 year ago #

    I ended up putting the check in the admin_init hook.

    function rootsPersonaUpgrade() {
      $currentVersion = get_option('rootsPersonaVersion');
      if(!isset($currentVersion) || empty($currentVersion)
    	|| $this->rootsPersonaVersion != $currentVersion) {
    	$installer = new rootsPersonaInstaller();
    	$installer->rootsPersonaUpgrade(ABSPATH . $this->plugin_dir,
    					$this->rootsPersonaVersion);
      }
    }

    then

    add_action( 'admin_init', array($rootsPersonaplugin, 'rootsPersonaUpgrade' ));

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.