Skip to content

Instantly share code, notes, and snippets.

@Mosharush
Last active November 29, 2017 06:32
Show Gist options
  • Save Mosharush/e6e04316d2c0a78c6e54ecbabb5a7eee to your computer and use it in GitHub Desktop.
Save Mosharush/e6e04316d2c0a78c6e54ecbabb5a7eee to your computer and use it in GitHub Desktop.
Fake Wordpress filter integartion for allow add page template via plugins
<?php
// Spacial Hook! : Add cart page template for cart on admin page options
add_filter( 'theme_page_templates', 'add_cart_page_template_option_select' );
add_filter( 'page_template', 'add_cart_page_template_to_theme', 10, 3 );
function add_cart_page_template_option_select( $post_templates ) {
$post_templates[ 'some-page-name-non-exist-or-uniqe.php' ] = __( 'Page Template Name', 'text-domain' );
return $post_templates;
}
function add_cart_page_template_to_theme( $template, $type, $templates ) {
if( $type === 'page' && $templates[0] === 'some-page-name-non-exist-or-uniqe.php' ) {
$template_path = plugin_dir_path( __FILE__ ) . 'templates/real-page-template.php';
locate_template( $template_path );
$template = $template_path;
}
return $template;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment