Home / WordPress Add page template from plugins

WordPress Add page template from plugins

$var = new Prism_IG_Templates();
class Prism_IG_Templates {
	function __construct() {
		add_filter ('theme_page_templates', [$this, 'AddTemplate_Login']);
		add_filter ('page_template', [$this, 'ViewTemplate_Login']);

	}



	function AddTemplate_Login ($templates) {
		$template = dirname( __FILE__ ) . '/tem_user_login.php';
		$templates[basename ($template)] = 'User Login';
		return $templates;
	}
	function ViewTemplate_Login ($template) {
		$post = get_post();
		$page_template = get_post_meta( $post->ID, '_wp_page_template', true );
		if ('tem_user_login.php' == basename ($page_template )){
			$template = dirname( __FILE__ ) . '/tem_user_login.php';
			return $template;
		}
	}
}

all rights reserved