The template loaded only looks in the theme and the core plugin. You can filter the final result however:
return apply_filters( 'job_manager_locate_template', $template, $template_name, $template_path );
Okay, I’m completely lost and I realise it doesn’t really fall inside the scope of support you’d offer…
Just wondering if there’s anyone out there that could give some more hands-on guidance 🙂
Okay, this is pretty messy. Bearing in mind I’m a front end dev, is there a better way of doing the following:
add_filter('job_manager_locate_template', 'tgs_job_manager_locate_template', 10, 3);
function tgs_job_manager_locate_template($template_name, $template_path, $default_path) {
$default_path = plugin_dir_path( __FILE__ ) . 'templates/';
$end = end((explode('/', $template_name)));
$template = $default_path . $end;
// Return what we found
return $template;
}
It’s got some issues, but for the most part the filter does seem to make use of the template files located in the override plugin instead of looking into the core WP Job Manager plugin or the theme…
ANY help would be appreciated 🙂
Why do you need the $end part?
I think you just need to prepend:
trailingslashit( $template_path ) . $template_name
With your custom path (to your plugin). So it would look in your plugin’s template folder, but maintain the path for that specific file.
You could also wrap it in a file_exists for $template so you don’t override core templates, only your custom ones.
The issue that I have with $template_name (and the reason why I used that $end bit) is that when I used $template_name in the override plugin, it adds the entire path as well, not just the name of the template.
The file_exists is a good idea! Will look into that more 🙂
To give you some more insight – the following function:
function tgs_job_manager_locate_template($template_name, $template_path, $default_path) {
$default_path = plugin_dir_path( __FILE__ ) . 'templates/';
$template = trailingslashit( $template_path ) . $template_name;
print_r($template);
return $template;
}
give me this:
job-submit.php/C:\wamp\www\wordpress\wp-content\plugins\wp-job-manager/templates/job-submit.php
This:
function tgs_job_manager_locate_template($template_name, $template_path, $default_path) {
$default_path = plugin_dir_path( __FILE__ ) . 'templates/';
$template = trailingslashit( $default_path ) . $template_name;
print_r($template);
return $template;
}
gives me this:
C:\wamp\www\wordpress\wp-content\plugins\wpjm-field-editor/templates/C:\wamp\www\wordpress\wp-content\plugins\wp-job-manager/templates/job-submit.php
And finally, this:
function tgs_job_manager_locate_template($template_name, $template_path, $default_path) {
$default_path = plugin_dir_path( __FILE__ ) . 'templates/';
$end = end((explode('/', $template_name)));
$template = $default_path . $end;
print_r($template);
return $template;
}
Gives me this:
C:\wamp\www\wordpress\wp-content\plugins\wpjm-field-editor/templates/job-submit.php
The first two examples above gives me fatal errors, while the last one means that I have to copy the files from the “form-fields” directory into the “templates” directory otherwise the job submission doesn’t work. Lastly, some templates does seem impervious to change (e.g. content-single-job_listing.php) with my $end method above 🙂