Support » Developing with WordPress » Hooking wp_update_plugins: is this an action or filter

  • I would like to hook the event wp_update_plugins. I’ve googled around for my following questions but I could not find the answers.

    – Is this event a filter or an action? So should I use add_filter() or add_action()?
    – Should my callback return anything? See my callback below? I don’t want to break any user functionality by the callback not returning the correct value and stopping default plugin updating from occurring.

        public function my_callback() {
            // do my code
    
            // do I need to return anything here? 
        }
Viewing 4 replies - 1 through 4 (of 4 total)
  • I am surprised that my goto reference on hooks and filters does not have this hook listed:
    https://adambrown.info/p/wp_hooks/hook

    Viewing the source of the present version 4.9.4 I find that it is an action.
    It does not return anything.

    All I can suggest is that you read the sourcecode.

    Simon Prosser

    (@pross)

    Theme Review Admin

    If look at the actual source on github and search for your string, you’ll see it isnt an action or a filter, wp_update_plugins is a function.

    https://github.com/WordPress/WordPress/search?utf8=%E2%9C%93&q=wp_update_plugins&type=

    You can also use the WP code reference:

    https://developer.wordpress.org/reference/

    Enter a term (in this case wp_update_plugins) into the search box and click/tap the search icon. If the term you entered has multiple meanings, all will be displayed, and you can select one to view its details. In this specific case you will see the function details because the term is unique.

    Moderator bcworkz

    (@bcworkz)

    By looking at source as Ross suggests, the only hook evident is “plugins_update_check_locales” filter. Even if you don’t care about checking locales, you can still use the filter as an action, just return the passed parameter unchanged after doing your action thing.

    FWIW, some of the WP functions called from wp_update_plugins() might also have usable hooks, but you cannot be assured they fire because of a call from wp_update_plugins(), unless there is additional context that can be inferred or asserted.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Hooking wp_update_plugins: is this an action or filter’ is closed to new replies.