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

Link to /blog displays index.php #58

Closed
bobbingwide opened this issue Apr 7, 2021 · 11 comments
Closed

Link to /blog displays index.php #58

bobbingwide opened this issue Apr 7, 2021 · 11 comments
Assignees
Labels
bug Something isn't working Gutenberg A bug / enhancement to Gutenberg help wanted Extra attention is needed

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented Apr 7, 2021

With Gutenberg 10.3.1 clicking on the link to the Posts page ( https://blocks.wp.a2z/blog/ ) leads to the display of index.php

Enable full site editing to view the Fizzie theme.

This problem appears to be associated with WordPress Multi Site.

In a single site install the posts page is supported by home.html, and the home page by front-page.html

The problem does not occur in https://s.b/wp55/fizzie/blog/

So the problem could also be associated with a subdomain installation.

@bobbingwide bobbingwide self-assigned this Apr 7, 2021
@bobbingwide bobbingwide added the bug Something isn't working label Apr 7, 2021
@bobbingwide
Copy link
Owner Author

I changed the slug on blocks.wp.a2z from blog to blog-posts. This results in a 301 for blog/ followed by a 20 for block-posts/. I'll change it back.

@bobbingwide
Copy link
Owner Author

This problem seems to be associated with WordPress/gutenberg#29026.

@bobbingwide
Copy link
Owner Author

This problem appears to be associated with WordPress Multi Site.

No, I was wrong there. The other sites I tried were running 10.2.1.

@bobbingwide
Copy link
Owner Author

Workaround: rename index.php so that it can't be found.
The problem with this is that currently index.php is required for the theme to be activated.
See https://wordpress.slack.com/archives/C02QB2JS7/p1617810024111300

@bobbingwide
Copy link
Owner Author

The parameters to gutenberg_override_query_template() are:

C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\full-site-editing\template-loader.php(66:0) gutenberg_override_query_template(1) 227 0 2021-04-07T16:22:43+00:00 2.892672 1.128170 cf=home_template 12583 36 8074 2097152/2097152 512M F=517 3 Array

    [0] => (string) "C:\apache\htdocs\wp-a2z/wp-content/themes/fizzie/index.php"
    [1] => (string) "home"
    [2] => Array

        [0] => (string) "home.php"
        [1] => (string) "index.php"

@bobbingwide
Copy link
Owner Author

bobbingwide commented Apr 7, 2021

Another workaround is to create home.php.

@bobbingwide
Copy link
Owner Author

For other requests the $template parameter (index 0 below) is not set.

C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\full-site-editing\template-loader.php(66:0) gutenberg_override_query_template(1) 227 0 2021-04-07T16:46:13+00:00 0.746457 0.261138 cf=archive_template 13481 30 1635 2097152/2097152 512M F=508 3 Array

    [0] => (string) ""
    [1] => (string) "archive"
    [2] => Array

        [0] => (string) "archive-block.php"
        [1] => (string) "archive.php"

Stack traces are:
For archive...

0. bw_lazy_backtrace C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\libs\bwtrace.php:108 0
1. bw_backtrace C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\full-site-editing\template-loader.php:67 0
2. gutenberg_override_query_template(,archive,array) C:\apache\htdocs\wp-a2z\wp-includes\class-wp-hook.php:292 3
3. apply_filters(,array) C:\apache\htdocs\wp-a2z\wp-includes\plugin.php:212 2
4. apply_filters(archive_template,,archive,array) C:\apache\htdocs\wp-a2z\wp-includes\template.php:63 4
5. get_query_template(archive,array) C:\apache\htdocs\wp-a2z\wp-includes\template.php:121 2
6. get_archive_template C:\apache\htdocs\wp-a2z\wp-includes\template.php:147 0
7. get_post_type_archive_template C:\apache\htdocs\wp-a2z\wp-includes\template-loader.php:82 0
8. require_once(C:\apache\htdocs\wp-a2z\wp-includes\template-loader.php) C:\apache\htdocs\wp-a2z\wp-blog-header.php:19 1
9. require(C:\apache\htdocs\wp-a2z\wp-blog-header.php) C:\apache\htdocs\wp-a2z\index.php:17 1

For home...

0. bw_lazy_backtrace C:\apache\htdocs\wordpress\wp-content\plugins\oik-bwtrace\libs\bwtrace.php:108 0
1. bw_backtrace C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\full-site-editing\template-loader.php:67 0
2. gutenberg_override_query_template(C:\apache\htdocs\wp-a2z/wp-content/themes/fizzie/index.php,home,array) C:\apache\htdocs\wp-a2z\wp-includes\class-wp-hook.php:292 3
3. apply_filters(C:\apache\htdocs\wp-a2z/wp-content/themes/fizzie/index.php,array) C:\apache\htdocs\wp-a2z\wp-includes\plugin.php:212 2
4. apply_filters(home_template,C:\apache\htdocs\wp-a2z/wp-content/themes/fizzie/index.php,home,array) C:\apache\htdocs\wp-a2z\wp-includes\template.php:63 4
5. get_query_template(home,array) C:\apache\htdocs\wp-a2z\wp-includes\template.php:358 2
6. get_home_template C:\apache\htdocs\wp-a2z\wp-includes\template-loader.php:82 0
7. require_once(C:\apache\htdocs\wp-a2z\wp-includes\template-loader.php) C:\apache\htdocs\wp-a2z\wp-blog-header.php:19 1
8. require(C:\apache\htdocs\wp-a2z\wp-blog-header.php) C:\apache\htdocs\wp-a2z\index.php:17 1

@bobbingwide
Copy link
Owner Author

bobbingwide commented Apr 7, 2021

It's only for home that the $templates array passed to get_query_template() includes index.php. Even though $current_template is the right template this gets overridden by the new logic

// Don't override the template if we find a template matching the slug we look for
// and which does not match a block template slug.
if ( $current_template_slug !== $current_block_template_slug && $current_template_slug === $template_item_slug ) {
			return $template;
}

$current_template

12876 36 8074 2097152/2097152 512M F=508 Current Template WP_Block_Template Object

    [type] => (string) "wp_template"
    [theme] => (string) "fizzie"
    [slug] => (string) "home"
    [id] => (string) "fizzie//home"
    [title] => (string) "Home"
    [content] => (string) "<div class="WP_DEBUG">home.html</div>
...

For home...

Index 1. $current_template_slug 2. $current_block_template_slug 3. $template_item_slug return $template
0 index home home No. 1. index is not 3 home
1 index home index Yes.

The correct logic should have chosen home.

@bobbingwide
Copy link
Owner Author

Wrapping the logic inside a test against the $current_template slug seems to resolve the problem for Fizzie, but I only have one PHP template and that's index.php

// Allow falling back to a PHP template if it has a higher priority than the block template.
	$current_template_slug       = basename( $template, '.php' );
	if ( $current_template_slug && 'index' !== $current_template_slug ) {
        $current_block_template_slug = is_object($current_template) ? $current_template->slug : false;
        foreach ($templates as $template_item) {
            $template_item_slug = gutenberg_strip_php_suffix($template_item);

            // Don't override the template if we find a template matching the slug we look for
            // and which does not match a block template slug.
            if ($current_template_slug !== $current_block_template_slug && $current_template_slug === $template_item_slug) {


                return $template;
            }
        }
    }

I can't copy any of the original PHP templates to test the logic since the original theme was a child theme of the Genesis framework so none of the functionality is available.

@bobbingwide bobbingwide added Gutenberg A bug / enhancement to Gutenberg help wanted Extra attention is needed labels Apr 7, 2021
@aristath
Copy link

aristath commented Apr 8, 2021

This PR should fix the issue: WordPress/gutenberg#30599

@bobbingwide
Copy link
Owner Author

Fixed in Gutenberg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Gutenberg A bug / enhancement to Gutenberg help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants