add-ons: cancellation of archive_template when there are no publications

I have a plugin that contains a single PHP template for both single_template Y archive_template for multiple types of messages. I am loading an application on the client side in this template, so I only need a single template for the four variants.

The code I have is:

add_filter (& # 39; single_template & # 39 ;, & # 39; react_template & # 39;);
add_filter (& # 39; archive_template & # 39 ;, & # 39; react_template & # 39;);

react_template ($ template) function {

global $ post;
if ($ post-> post_type == & # 39; tutorial & # 39; || $ post-> post_type == & # 39; control panel & # 39;) {
if (file_exists (PLUGIN_DIR. & # 39; templates / learning.php & # 39;)) {
returns PLUGIN_DIR & # 39; templates / learning.php & # 39 ;;
}
}

returns $ template;
}

This works perfectly for my needs. However, if do not posts exist for anyone tutorial or board guys I get an error because $ post It is null.

It is not a big problem since in the production there will always be numerous publications in the system, but it bothers me. I do not want to have a template with a name for each type. Is there any way to make my file template work when there are no publications?