Force update plugin to a required version that is above the current version

Hello all, I have implemented force update using stand alone plugin update checker class but this uses the url that I put in the managed plugin repositories. We have a updatePlugin.xml file. Our main requirement is that if the plugin version is 1.1.1 and the latest version is 1.1.5 and the required version 1.1.3 then the force auto update should install 1.1.3. Currently it is updating to 1.1.5. How to proceed? Please help. 

0
1 comment

Hello, Harshitgarg777 

I can see your query, I give you my best see below and follow inst…

 

You want to know how to force auto-update a plugin to a specific version, using the plugin update checker class and the updatePlugin.xml file. This is a common scenario for WordPress plugin developers who want to control the update process and avoid compatibility issues.

The plugin update checker class is a library that allows you to implement custom update notifications and automatic updates for your WordPress plugins. The updatePlugin.xml file is a file that contains the metadata of your plugin, such as the version, download URL, changelog, etc.

 

To force auto-update a plugin to a specific version, you need to do the following steps:

* Edit the updatePlugin.xml file and change the version and download the URL to the desired version. For example, if you want to update the plugin to version 1.1.3, change the version tag to <version>1.1.3</version> and the download_url tag to <download_url>https://example.co/DogNeedsBest/m/my-plugin-1.1.3.zip</download_url>.
* Upload the updatePlugin.xml file to the same location as before, or change the metadata URL in the plugin update checker class to point to the new location.
* Use the forceCheck() method of the plugin update checker class to trigger an update check. You can do this by adding the following code to your plugin:
 

// Get the plugin update checker instance
$updateChecker = Puc_v4_Factory::buildUpdateChecker(
   'https://example.com/updatePlugin.xml', // The metadata URL
   __FILE__, // The plugin file
   'my-plugin' // The plugin slug
);

// Force an update check
$updateChecker->forceCheck();
 

* Alternatively, you can use the checkForUpdates() method of the plugin update checker class to check for updates manually. You can do this by adding the following code to your plugin:


// Get the plugin update checker instance
$updateChecker = Puc_v4_Factory::buildUpdateChecker(
   'https://example.com/updatePlugin.xml', // The metadata URL
   __FILE__, // The plugin file
   'my-plugin' // The plugin slug
);

// Check for updates manually
$updateChecker->checkForUpdates();

 

* After the update check, the plugin update checker class will display an update notification on the WordPress dashboard and allow you to update the plugin to the specified version.
 

I hope this helps. If you have any other questions, feel free to ask me. Have a great day! 😊.

 

 

Best regard,
BookerE1
 

0

Please sign in to leave a comment.