When is wp_loaded
initiated?
Im trying to add function that downloads a big file for the plugin DB, and I need it to be executed whenever user/admin/unknown user get in the frontend, after the site is fully loaded, so that it would not be any delay with the site speed, and user experience.
I use this script:
// add update check when admin login
if (is_admin()) {
function wp_plugin_update() {
include( plugin_dir_path( __FILE__ ) . 'wp-plugin-update.php');
}
add_action( 'admin_init', 'wp_shabbat_update' );
}
// add update check when user enter the site after footer loaded
if (!(is_admin() )) {
function wp_plugin_update() {
include( plugin_dir_path( __FILE__ ) . 'wp-plugin-update.php');
}
add_action( 'wp_loaded', 'wp_plugin_update' );
}
Can I only use this and it will work with admin and when user enter the site? :
function wp_plugin_update() {
include( plugin_dir_path( __FILE__ ) . 'wp-plugin-update.php');
}
add_action( 'wp_loaded', 'wp_plugin_update' );
wp_loaded
action is triggered in admin and in frontend no matter what user visits the site, it is triggered even for guest users. I think you are falling into a XY problem. Can you explain what you are trying to do? Also, you are wrong when you connectis_admin()
function and "check when admin login".is_admin()
checks if the user is in the administration section of the site (wp-admin) no matter what roles the user has assigned.