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 … Read more

Difference between hooks Plugin_loaded and admin_int?

As per my understanding, functions attached to plugin_loaded and admin_init hooks are called whenever any admin page is loaded. What’s the difference between them? 1 Answer 1 plugins_loaded fires once activated plugins have loaded. This fires on both admin and public screens. admin_init fires as an admin screen or script is being initialized. This fires … Read more

Use wp init hook to call other hooks?

I want to know if it is a good practice according to WordPress theme or plugin development. add_action(‘init’,’all_my_hooks’); function all_my_hooks(){ // some initialization stuff here and then add_action(‘admin_init’,—–); add_action(‘admin_menu’,—-); // more like so } thanks 2 In general: Yes, wait for a dedicated hook to start your own code. Never just throw an object instance … Read more

How do I Enqueue styles/scripts on Certain /wp-admin Pages?

I have two simple functions that load stuff using wp_enqueue_style() and wp_enqueue_script(), something like these: function admin_custom_css() { wp_enqueue_style( ‘stylesheet_name’, ‘stylesheet.css’) }; function admin_custom_js { wp_enqueue_script( ‘javascript_file’, ‘script.js’) }; … and a few admin pages, created with add_menu_page() and add_submenu_page() function my_menu() { add_menu_page(‘Page 1’, ‘bar’, ‘something’, ‘else’, ‘foo’); add_submenu_page( ‘theme_menu’, ‘Subpage 1’, ‘Subpage’, ‘something’, … Read more