Closed wpplumber closed 4 years ago
Inside register_hook_callbacks
of Admin_Settings
controller, you can add your own add_action and add_filter calls.
I did, but when accessing the page which should use the custom template it doesn't show and seems using the theme template?
should it be something on locate_template()? any wiki in case you're busy?
I have not created a separate wiki for it. For Frontend related activities, ideally a separate controller should be created and that should be hooked on ROUTE_TYPE::FRONTEND
Router. I suppose as of now you have created a single controller and have added everything into it. You can try replacing ROUTE_TYPE::ADMIN
with ROUTE_TYPE::ANY
in routes.php & see if it works.
If that does not work too, please provide me a psuedo code which worked w/o MVC.
$router
->register_route_of_type(ROUTE_TYPE::FRONTEND)
->with_controller('Dashboard@register_hook_callbacks')
->with_model('Dashboard')
->with_view('Dashboard');
Result:
$router
->register_route_of_type(ROUTE_TYPE::ANY)
->with_controller('Dashboard@register_hook_callbacks')
->with_model('Dashboard')
->with_view('Dashboard');
With ROUTE_TYPE::ANY
, full class name (including namespace) should be passed to with_controller
, with_model
and with_view
.
I was able to see the template called in debug mode after adding the following to /core/class-view.php
$template = $template_path . $template_name; // To test
// Get default template.
if ( ! $template ) {
$template = $default_path . $template_name;
}
Do you use a solution for pages using custom template to manage them since you use the following:
public static function render_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
if ( $args && is_array( $args ) ) {
extract( $args ); // @codingStandardsIgnoreLine.
}
$located = static::locate_template( $template_name, $template_path, $default_path );
if ( false == $located ) {
return;
}
ob_start();
do_action( 'plugin_name_before_template_render', $template_name, $template_path, $located, $args );
include( $located );
do_action( 'plugin_name_after_template_render', $template_name, $template_path, $located, $args );
return ob_get_clean(); // @codingStandardsIgnoreLine.
}
Using the following hook related to template within the controller of that permalink fixed the issue 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')
);
}
thank you @sumitpore for this work repository.
I had the template save operation working before while using an OOP architecture but when I moved the plugin code to this WP boilerplate I got the following message error!
Is it something with permission? I used the following route for backoffice page.