YahnisElsts / plugin-update-checker

A custom update checker for WordPress plugins. Useful if you don't want to host your project in the official WP repository, but would still like it to support automatic updates. Despite the name, it also works with themes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Some assistance with a universal updater for a private repo

stingray82 opened this issue · comments

I haven't been including this in my plugins I have used a single plugin to update them all and its worked fine for 3 years, I have made some modifications to it over the years an early version is available in a public repo.

I can now update whatever I choose from my repo if it has it in there on any individual site (Thank You) but now I want to use MainWP to update my sites and I have issued

So setup using your server on my repo server:

image

What ever plugins are checked it will check my server for them and allow me to update form my repo

This works fine when I am on Plugins or wp-admin/update-core.php, I can manually update them one at a time or all together from update-core.php

but something isn't quite right; you'll see below:

image

So when I am off it update-core is updated and ready to go with 4 plugins (a) but plugins say (b)

now when i try to update with MainWP it isn't working it only thinks there is one plugin with an update, it doesn't see any of my custom plugins allowing them to be updated and I can't get it to override another plugin as I can on the direct site;

So I am a bit lost how I can get this to work my update plugin code is below

My plugin can be seen here: https://github.com/stingray82/ninja-updater-pd/ any help on what I am missing as I would like to get it to work with WPMain?

I see that in your plugin, the function that creates the update checker instances is attached to the admin_init hook. Could it be that MainWP performs updates in a context where the admin_init hook doesn't get triggered? In that case, the updates wouldn't show up because the update checker wouldn't have been initialized.

I'm not sure if that could also affect the numbers in the admin menu. Still, as a test, it might be worth moving the functions to a much earlier hook, like plugins_loaded.

This was perfect, it was so tiny I would never have worked it out thank you;

I now need to work out how to get it to run 4 times a day for updates and that should be it done now thanks again

it's running every single time and every single page I am running in my admin area, any suggestions on how to limit it to only plugins and updates or Ideally, 4 times a day for it to run and the updates be there for the twice-daily WordPress check is enough for me, I suspect this will work for the 4 times a day but I am not sure how to restrict where it runs.
`
// Activation hook
/register_activation_hook(FILE, 'ninja_updater_schedule_tasks');
// Deactivation hook
register_deactivation_hook(FILE, 'ninja_updater_deactivate');
add_action( 'ninja_updater_check_plugins', 'ninja_updater_check_plugins' );
add_action( 'ninja_updater_check_themes', 'ninja_updater_check_themes' );
/

function ninja_custom_cron_schedule( $schedules ) {
$schedules['every_six_hours'] = array(
'interval' => 21600, // Every 6 hours
'display' => __( 'Every 6 hours' ),
);
return $schedules;
}
add_filter( 'cron_schedules', 'ninja_custom_cron_schedule' );

function ninja_updater_schedule_tasks() {
error_log('ninja_updater_schedule_tasks has been executed at ' . date('Y-m-d H:i:s')); // Add this line for debugging

if (!wp_next_scheduled('ninja_updater_check_plugins')) {
    // Schedule plugin check every 6 hours
    wp_schedule_event(time(), 'every_six_hours', 'ninja_updater_check_plugins');
}

if (!wp_next_scheduled('ninja_updater_check_themes')) {
    // Schedule theme check every 6 hours
    wp_schedule_event(time(), 'every_six_hours', 'ninja_updater_check_themes');
}

}
// On Deactivate
function ninja_updater_deactivate() {
// Remove the scheduled events for checking plugins and themes
wp_clear_scheduled_hook('ninja_updater_check_plugins');
wp_clear_scheduled_hook('ninja_updater_check_themes');
}
`

Thanks Again

If you want to control when exactly PUC checks for updates, one way would be to pass 0 as the fourth argument to buildUpdateChecker(). This argument is the "check period", and setting it to zero disables automatic checks. Then you can have your plugin trigger update checks directly by calling the $updateChecker->checkForUpdates() method.

Note that you will still need to initialize the update checker on other pages, or the updates won't show up in the admin.

Thanks I think I understood but I think I've done something wrong now I get no checking at all, the modifications I made are here
https://github.com/stingray82/ninja-updater-pd/

You can see the commit here:
stingray82/ninja-updater-pd@9030db1

I will take another look this evening, thanks again for you help

$updateChecker was a placeholder. In practice, you of course need to call checkForUpdates() on your actual update checker instance(s). Also, as I mentioned, you'll need to pass a zero as the 4th argument to buildUpdateChecker(). The third argument is the slug, but you can use an empty string if you want PUC to automatically assign a slug.