Use of Templates in a Plugin

You would need to add a filter to the page_template hook that will look for whatever criteria you need.

For example, if your plugin was for a custom post type you would have something like this:

function myCustomTemplate( $page_template ) {

   // Check theme for template file
   $located = locate_template( 'single-{{postype}}' );

   if ( ! empty( $located ) && is_singular( '{{posttype}}' ) ) {
      $page_template = dirname( __FILE__ ) . 'templates/my-custom-template.php';
   }

   return $page_template;
}
add_filter( 'page_template', 'myCustomTemplate' );

The $located check looks to see if the user’s current theme already has a file to display the custom post type already since you probably do not want to override that. If it doesn’t and the post type is the custom post type your plugin defines, then it will tell WordPress to use the one with your plugin.