rudrastyh / misha-update-checker Goto Github PK
View Code? Open in Web Editor NEWThis simple plugin does nothing, only gets updates from a custom server
This simple plugin does nothing, only gets updates from a custom server
Hello,
I've encountered an issue with my custom update script in a WordPress plugin when caching is disabled. The problem arises irrespective of which admin page is accessed, resulting in multiple unnecessary remote requests.
The relevant part of my __construct() function looks like this:
public function __construct() { $this->cache_allowed = true; }
Despite this setting, the update function $this->request() is being called multiple times (around 9 times) during a single admin page load. This behavior seems to occur on every admin page load, leading to a significant number of redundant requests to my backend.
I have calculated how the many times the function is called:
int(1) int(2) int(3) int(4) int(5) int(6) int(7) int(8) int(9)
This issue appears to be related to the number of plugins installed on the site (currently, I have only three plugins, including the one with this update functionality).
I am seeking advice or solutions to optimize the update check mechanism to prevent these excessive requests. Any insights or recommendations would be greatly appreciated.
Thank you!
Please fix:
public function purge( )
to
public function purge( $upgrader_object, $options )
as you mentioned it would need two parameters when adding add_action so It would not show error.
It appears since the newest WordPress version (6.0+), upon a successful new version upgrade, the plugin folder gets renamed to something like misha-update-checker-n17qiE
with an additional random string appended to the original folder name.
Do you happen to have any idea why?
Hello there!
First, I want to tank you because this plugin works amazingly good that I create a custom post type with custom fields to have an endpoint to use it as a plugin's repository. Everything worked well until I try to see the details of my second plugin.
When I click on "View version x.x details" this is what I get.
The first plugin that I create works just fine.
All the validations to show the updates works just fine.
Do you have any ideas of how could I fix this?
Hello,
I just wanted to ask if anyone has had any luck getting this updater-checker project working with updating themes?
It is working for plugin's no problem, and I found equivalent theme action hooks to replace the plugin-specific hooks, such as:
add_filter( 'plugins_api', array( $this, 'info' ), 20, 3 );
add_filter( 'site_transient_update_plugins', array( $this, 'update' ) );
add_action( 'upgrader_process_complete', array( $this, 'purge' ), 10, 2 );
add_filter( 'themes_api', array( $this, 'info' ), 20, 3 );
add_filter( 'site_transient_update_themes', array( $this, 'update' ) );
add_action( 'upgrader_process_complete', array( $this, 'purge' ), 10, 2 );
Currently I can instantiate the update-checker with my theme, and it hits the update() function and see's that there is a new version of the theme available, but unfortunately the update notification on the theme does not display like it does for plugins.
I'm going to dive into the WP source code for updating to see if I can figure this out, but just wanted to run this by the user's of this repo to see if anyone had any ideas
Thank you!
Your plugins_api
filter called to info()
method.
The info()
method that return false;
after checked something is incorrect.
The return false;
will be mess with another plugins information that is using the self hosted.
To be correct, it should return $res;
.
Example:
function info( $res, $action, $args ) {
// print_r( $action );
// print_r( $args );
// do nothing if you're not getting plugin information right now
if( 'plugin_information' !== $action ) {
return $res;
}
// do nothing if it is not our plugin
if( $this->plugin_slug !== $args->slug ) {
return $res;
}
// get updates
$remote = $this->request();
if( ! $remote ) {
return $res;
}
// your code
}
Great and very useful piece of code. What I'm trying to understand is why the "View Details" link is only visible when a new update is available. I'm fairly new to plugin development and I cant work out how to display the link constantly even if no new update is available.
"if ($this->cache_allowed",???,cache_allowed is false,why?
Hi Misha, first of all BIG thanks for sharing the code and the awesome clear tutorial!
I've got a question.
When the plugin has NOT been activated it will not check for available updates, right?
Is that by design in your code? Or does the WordPress update mechanism only check those with a lower interval (and am I thus too impatient, since I started today with your code)?
Steven
I have tested this on several sites that are not WPMU and it works great. The only issue is, this plugin does not show update available in a WordPress Multisite unless it is network activated. In other words, it does show the update available icon in the top menu bar, but when you click on it, it shows no update available if the plugin is activated on a single site in the network.
What I have discovered is, it has to be Network Activated for it to allow you to click "Update" in the plugins list only in the Network Admin. I know it's possible for this to work on sub-sites as I've seen this done with the GeneratePress Premium plugin. I'm just wondering if you know of an easy fix for this.
Hello,
I have used the source code from this project and it has worked great, but now I have run into an issue I am a little stumped on.
In the update() function:
public function update( $transient ) {
if ( empty($transient->checked ) ) {
return $transient;
}
$remote = $this->request();
if(
$remote
&& version_compare( $this->version, $remote->version, '<' )
&& version_compare( $remote->requires, get_bloginfo( 'version' ), '<=' )
&& version_compare( $remote->requires_php, PHP_VERSION, '<' )
)
{
$res = new stdClass();
$res->slug = $this->plugin_slug;
$res->plugin = plugin_basename( __FILE__ );
$res->new_version = $remote->version;
$res->tested = $remote->tested;
$res->package = $remote->download_url;
$transient->response[ $res->plugin ] = $res;
}
return $transient;
}
We have the line, which tells WordPress which URL to download the .zip file from:
$res->package = $remote->download_url;
My question: This worked great until we required an access-token (As a header on the request) to request that .zip file, now the call fails because the header is not added to the request, but I am stumped as to how I can tell wordpress to add the authorization header to the request and just wanted to see if anyone had any ideas on how to do that?
Things I tried:
$res->package = $response
but then I get the error on my plugin page "Update failed: Download failed. A valid URL was not provided." so that is making me realize it needs to be a valid URL, it cant be the .zip itselfSo that has left me a little stumped on how to accomplish this, I feel it should be totally doable somehow... Somehow??
Any help or discussion on this is much appreciated, thank you!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.