Skip to content

get_block_templates() in determine_template_post_type triggers Ultimate Member redirect bug #45

@kooyaniks

Description

@kooyaniks

Bug Description

When using Spectra with Ultimate Member and a block theme, all single posts/pages return a 302 redirect to the homepage for non-logged-in users.

Root Cause

determine_template_post_type() calls get_block_templates() early during every page load. When a page-user block template exists, WordPress creates a WP_Query to look up the page with slug "user" (the UM profile page). Ultimate Member's filter_protected_posts() hook intercepts this query and calls exit(wp_redirect(homepage)), killing the entire request before the actual page renders.

Steps to Reproduce

  1. Install Spectra 2.19.20 and Ultimate Member 2.11.2
  2. Use a block theme (e.g., Spectra One)
  3. Customize the User page template in the Site Editor (creates a page-user template)
  4. Visit any article as a logged-out user
  5. Result: 302 redirect to homepage instead of the article

Expected Behavior

Template resolution via get_block_templates() should not trigger third-party post filters that can terminate the request.

Suggested Fix

Temporarily suppress third-party the_posts filters during get_block_templates():

// In determine_template_post_type(), before calling get_block_templates():
add_filter('the_posts', function($posts, $query) {
    if (!$query->is_main_query()) {
        $query->set('suppress_filters', true);
    }
    return $posts;
}, 1, 2);

Environment

  • Spectra: 2.19.20
  • Ultimate Member: 2.11.2
  • WordPress: 6.x with block theme
  • PHP: 8.1

Full Analysis

Full root cause analysis, code flow diagram, diagnostic tools, and fix: https://github.com/kooyaniks/um-spectra-redirect-bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions