[wp-trac] [WordPress Trac] #62043: Allow plugins and themes perform extra checks upon install/upgrade via filter

WordPress Trac noreply at wordpress.org
Fri Oct 18 20:29:46 UTC 2024


#62043: Allow plugins and themes perform extra checks upon install/upgrade via
filter
-------------------------+-------------------------------------------------
 Reporter:               |       Owner:  (none)
  LeonidasMilossis       |
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  6.8
Component:  Plugins      |     Version:  trunk
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:  coding-standards, php-
  2nd-opinion            |  compatibility
-------------------------+-------------------------------------------------
Changes (by dilip2615):

 * focuses:   => coding-standards, php-compatibility


Comment:

 Replying to [ticket:62043 LeonidasMilossis]:
 > WordPress has several hooks related to plugin installations or upgrades.
 The most relevant hooks are:

 [1] upgrader_process_complete: This fires after a plugin, theme, or
 WordPress core has been upgraded.
 [2] install_plugin_complete_actions: This filter is used to modify the
 install actions
     once a plugin is installed.
     You can add your custom checks by hooking into these actions.

     {{{#!php
 <?php
 add_action('upgrader_process_complete', 'my_custom_plugin_upgrade_checks',
 10, 2);
     function my_custom_plugin_upgrade_checks($upgrader_object, $options) {

         if ($options['type'] === 'plugin' && isset($options['plugins'])) {
             foreach ($options['plugins'] as $plugin) {
                 // Perform your custom checks for each plugin
                 if ($plugin === 'your-plugin/your-plugin.php') {
                     // Add your custom logic here
                     // Example: Check PHP version or other server
 requirements
                     if (version_compare(PHP_VERSION, '7.4', '<')) {
                         // Display a message or take action if PHP version
 is too low
                         wp_die('Your PHP version is too low for this
 plugin. Please upgrade to at least PHP 7.4.');
                     }
                 }
             }
         }
     }
 }}}


     For Theme Install/Upgrade
     For themes, you can use similar hooks:
     {{{#!php
 <?php
 add_action('upgrader_process_complete', 'my_custom_theme_upgrade_checks',
 10, 2);
     function my_custom_theme_upgrade_checks($upgrader_object, $options) {
         if ($options['type'] === 'theme' && isset($options['themes'])) {
             foreach ($options['themes'] as $theme) {
                 if ($theme === 'your-theme') {
                     if (!function_exists('some_required_function')) {
                         wp_die('This theme requires a specific PHP
 function that is not available on your server.');
                     }
                 }
             }
         }
     }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62043#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list