bobbingwide / fizzie

Fizzie theme - a Full Site Editing theme using Gutenberg blocks
9 stars 1 forks source link

Link to /blog displays index.php #58

Closed bobbingwide closed 1 year ago

bobbingwide commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

This problem seems to be associated with https://github.com/WordPress/gutenberg/pull/29026.

bobbingwide commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Another workaround is to create home.php.

bobbingwide commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.

aristath commented 3 years ago

This PR should fix the issue: https://github.com/WordPress/gutenberg/pull/30599

bobbingwide commented 1 year ago

Fixed in Gutenberg.