I’m trying to create a WordPress update automation plugin. here I got two option to make enable and disable the updates.

  1. Via define

ex :defined( 'AUTOMATIC_UPDATER_DISABLED',true )

2.via add_filter

ex:add_filter( 'allow_major_auto_core_updates', '__return_true', 1 );

my problem is
if I have disabled the updates via define
and also have enabled it via add_filter
which one will work ? does add_filter override ‘define’? or define override ‘add_filter’?

1
1

Skimming through the Core_Upgrader::should_update_to_version() method, it looks like we can override the

 defined( 'WP_AUTO_UPDATE_CORE' )    // true (all), false, minor

check, used to setup the local boolean variables$upgrade_dev, $upgrade_minor and $upgrade_major, with the following filters:

...
apply_filters( 'allow_dev_auto_core_updates',   $upgrade_dev   ) 
...
apply_filters( 'allow_minor_auto_core_updates', $upgrade_minor )
...
apply_filters( 'allow_major_auto_core_updates', $upgrade_major )
...

So these filters have the last word over the WP_AUTO_UPDATE_CORE constant check.

Similarly, the automatic_updater_disabled filter can override the AUTOMATIC_UPDATER_DISABLED constant check.

But note that we can’t override the constant itself.

Leave a Reply

Your email address will not be published. Required fields are marked *