Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WC Status: Template Overrides with .blade.php file paths #2

Open
ouun opened this issue Jul 13, 2018 · 1 comment
Open

WC Status: Template Overrides with .blade.php file paths #2

ouun opened this issue Jul 13, 2018 · 1 comment

Comments

@ouun
Copy link

ouun commented Jul 13, 2018

Hi there,

as the roots forum has too many separated WooCommerce topics, I'm happy that you started this for bringing everything together. I did a couple of adjustments and I'll be happy to provide them later. For now I had the issue that I want to set the template version within the custom WC .blade.php files by using at the beginning of each file e.g.:
`{{--
Displays a single product content
@Version 3.4.0
--}}´

That will help to solve compatibily issues later when using the WC Status page to see all overrides.
However the current 'wc_get_template'filter returns the path to the .php files in the cache with a filename which isn't readable. So I'm trying to find a solution to return the blade path instead for that specific scenario. I tried to minimize the extra code to a minimum but it's quite hard to limit my addition to only that specific request.

This is what I came up so far:


add_filter( 'wc_get_template', function ( $located, $template_name, $args, $template_path, $default_path) {
    $bladeTemplate = locate_template( [ $template_name, 'resources/views/' . WC()->template_path() . $template_name ] );

    // If we're in dashboard on the WC status page and the request comes from class 'WC_REST_System_Status_Controller' and function 'get_theme_info':
    // return .blade.php path
    if ( is_admin() ) {
        if( strpos(get_current_screen()->id, 'wc-status') ) {
            $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5);
            foreach($backtrace as $call) {
                if( (isset($call['class']) && $call['function']) && ($call['class'] == 'WC_REST_System_Status_Controller') && $call['function'] == 'get_theme_info') {
                    return $bladeTemplate;
                }
            }
        }
    }

    if ( $bladeTemplate ) {
        return template_path( $bladeTemplate, $args );
    }
    return $located;
}, PHP_INT_MAX, 5 );

Maybe you have a better idea or some input to make this as performant as possible. Until now I'm also not sure whether this could be useful for other WC parts as well.

Best Regards,

Philipp

https://discourse.roots.io/t/wc-status-template-overrides-with-blade-php-file-paths/12938

@mtx-z
Copy link
Owner

mtx-z commented Jul 17, 2018

Hello,

thanks for the report.
Ah I see :

  • Version number is correctly parsed in the php cache file (from blade compilation)
  • But file path is the cache file one, not the blade one

I'll check if there's a better way to detect status page before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants