我创建了一个WP插件,它添加了一个CPT,允许用户选择自定义模板。
当我使用MVC design 但是当我搬到一个新的MVC style 它不会在前端输出,似乎也不会将自定义模板分配给页面!
我使用了以下挂钩:
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\')
);