Is it save to require plugin.php early to be able to use get_plugin_data() earlier?

I’d like to avoid hard coding my plugin’s version at multiple places. To realize this the function get_plugin_data() comes in handy. But here the fun comes to an unpleasant stop. Checking for a plugin update to execute related housekeeping for example should be done early (e.g. plugins_loaded) but unfortunately wp-admin/includes/plugin.php is not loaded before admin_init is fired.

Using a later hook is not possible here. This might be a solution for some plugins but it doesn’t work for me, as my plugin hooks into the login process and needs to do its on update processing before that…

My question is: is it save to require( ABSPATH . 'wp-admin/includes/plugin.php')
earlier in my plugin? The file contains some function definitions and adds a filter. That’s it.

I tried it. At first glance it works and I cannot see any implications but maybe you are aware of some? I’d be happy about any hint, positive or negative. Thank you!

2 Answers
2

At first glance it works and I cannot see any implications but maybe
you are aware of some?

You say that you are not getting errors, which I would have expected but it looks as though WordPress uses require_once() so you are probably safe:

39  /** WordPress Plugin Administration API */
40  require_once(ABSPATH . 'wp-admin/includes/plugin.php');

This kind of hack tends to indicate that you are doing something wrong though.

Leave a Comment