What errors are you getting when the site breaks? You may need to enable WP_DEBUG in your wp-contig.php file temporarily to see the error messages.
I get this error – Fatal error: Call to undefined function wpse_58429() in /var/www/html/wp-content/themes/viking/header.php on line 58
Where wpse_58429() is a function in my function file which is called in the header
Any ideas how I can call the function from my plugin ?
I tried to do this –
add_action( ‘call_wpse_58429’, ‘wpse_58429’ );
$current_user = do_action(‘wpse_58429’);
But then I get this error – Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘wpse_58429’ not found or invalid function name in /var/www/html/wp-includes/class-wp-hook.php on line 298
I tried then the following –
//add_action( ‘call_wpse_58429’, ‘wpse_58429’ );
$current_user = call_user_func(‘wpse_58429’);
Where I get this error –
Warning: call_user_func() expects parameter 1 to be a valid callback, function ‘wpse_58429’ not found or invalid function name in /var/www/html/wp-content/themes/viking/header.php on line 73
So all in all I am not sure the function gets into my theme from the plugin.
Appreciate any help I can get
It looks like you’re trying to use the function before it’s loaded. Plugins load before themes do, so if you’re trying to do that as soon as your plugin loads, the themes functions won’t be available yet.
The way to do it is to use the after_setup_theme action, as that is fired after the theme is loaded.
function my_function( ){
$current_user = wpse_58429();
}
add_action( ‘after_setup_theme’, ‘my_function’ );`
If that doesn’t work, go back to your themes author and ask for support. They’ll be able to help you more.
Thanks, I will contact the theme author