I created a WP plugin which adds a CPT and allows user to select custom template.
It was working when I used an MVC design but when I moved to a new MVC style it doesn't output on frontend and seems also doesn't assign custom template to page!
I used the following hooks:
add_filter(
'theme_page_templates', array( $this, 'add_new_template' )
);
add_filter(
'quick_edit_dropdown_pages_args',
array( $this, 'register_project_templates' )
);
add_filter(
'wp_insert_post_data',
array( $this, 'register_project_templates' )
);
// Add your templates to this array.
$this->templates = array(
'api.php' => 'API',
'print_invoice.php' => 'Print Invoice',
'wpc-post.php' => 'custom Post',
'dashboard.php' => 'Dashboard',
);
// self::create_dashboard_page();
add_action('add_meta_boxes', array($this, 'meta_box_visibility'));
add_action('save_post', array($this, 'wporg_save_postdata'), 10, 2);
/* Filter the single_template with our custom function*/
add_filter( 'template_include', array($this, 'my_plugin_templates'));
add_filter(
'manage_dashboard_posts_columns',
array($this, 'custom_post_type_columns')
);
add_action(
'manage_dashboard_posts_custom_column',
array($this, 'custom_column_content')
);
I created a WP plugin which adds a CPT and allows user to select custom template.
It was working when I used an MVC design but when I moved to a new MVC style it doesn't output on frontend and seems also doesn't assign custom template to page!
I used the following hooks:
add_filter(
'theme_page_templates', array( $this, 'add_new_template' )
);
add_filter(
'quick_edit_dropdown_pages_args',
array( $this, 'register_project_templates' )
);
add_filter(
'wp_insert_post_data',
array( $this, 'register_project_templates' )
);
// Add your templates to this array.
$this->templates = array(
'api.php' => 'API',
'print_invoice.php' => 'Print Invoice',
'wpc-post.php' => 'custom Post',
'dashboard.php' => 'Dashboard',
);
// self::create_dashboard_page();
add_action('add_meta_boxes', array($this, 'meta_box_visibility'));
add_action('save_post', array($this, 'wporg_save_postdata'), 10, 2);
/* Filter the single_template with our custom function*/
add_filter( 'template_include', array($this, 'my_plugin_templates'));
add_filter(
'manage_dashboard_posts_columns',
array($this, 'custom_post_type_columns')
);
add_action(
'manage_dashboard_posts_custom_column',
array($this, 'custom_column_content')
);
Share
Improve this question
asked Apr 11, 2020 at 15:18
TarikTarik
1215 bronze badges
1 Answer
Reset to default 1Using the following code I was able to load the custom template.
public function register_hook_callbacks(){
// Enqueue Styles & Scripts.
add_action( 'wp_enqueue_scripts',
array( $this, 'enqueue_scripts' ) );
add_filter('template_include',
array( $this, 'view_project_template')
);
}