-
Notifications
You must be signed in to change notification settings - Fork 93
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
Fix : block theme deprecated error. #207
base: develop
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request modifies the document template in Changes
Sequence Diagram(s)sequenceDiagram
participant T as Template
participant WP as WordPress
T->>WP: Check wp_is_block_theme()
alt Block Theme Active
T->>T: Call block_header_area()
T->>WP: Output minimal HTML structure (doctype, <html>, wp_head(), wp_body_open())
else Non-block Theme
T->>WP: Call get_header()
end
sequenceDiagram
participant T as Template
participant WP as WordPress
alt Block Theme Active
T->>T: Call block_footer_area()
T->>WP: Close HTML structure appropriately
else Non-block Theme
T->>WP: Call get_footer()
end
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
templates/single-docs.php (1)
2-22
: Consider refactoring duplicate block rendering logic.The header and footer block rendering functions share identical logic. Consider refactoring to reduce code duplication.
+// Helper function to render block template parts +if (!function_exists('render_block_template_part')) { + function render_block_template_part($part) { + if (function_exists('block_template_part')) { + block_template_part($part); + } elseif (function_exists('wp_block_template_part')) { + wp_block_template_part($part); + } else { + // Fallback when neither function exists + error_log("No block template rendering function available"); + } + } +} + // Helper function to render header blocks if (!function_exists('block_header_area')) { function block_header_area() { - if (function_exists('block_template_part')) { - block_template_part('header'); - } elseif (function_exists('wp_block_template_part')) { - wp_block_template_part('header'); - } + render_block_template_part('header'); } } // Helper function to render footer blocks if (!function_exists('block_footer_area')) { function block_footer_area() { - if (function_exists('block_template_part')) { - block_template_part('footer'); - } elseif (function_exists('wp_block_template_part')) { - wp_block_template_part('footer'); - } + render_block_template_part('footer'); } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
templates/single-docs.php
(2 hunks)
🔇 Additional comments (2)
templates/single-docs.php (2)
191-203
: LGTM! Clean and consistent theme closure implementation.The conditional theme closure mirrors the opening structure and includes all necessary WordPress hooks.
29-29
: Verify the fix for block theme deprecated error.The implementation properly checks for block theme support and uses the appropriate functions. Let's verify this resolves the deprecation error.
✅ Verification successful
🏁 Script executed:
#!/bin/bash # Description: Check for any remaining deprecated function calls related to block themes # Search for deprecated block theme related functions rg -i "deprecated.*block.*theme|block.*theme.*deprecated" --type phpLength of output: 70
I'll now run an additional script to gather more context around the code change in
templates/single-docs.php
, specifically around the usage ofwp_is_block_theme
to verify that the deprecated functionality has indeed been replaced.
🏁 Script executed:
#!/bin/bash # Check for usage of wp_is_block_theme and show context around the change in templates/single-docs.php echo "=== Searching for wp_is_block_theme usage ===" rg -n "wp_is_block_theme" templates/single-docs.php echo -e "\n=== Displaying lines 20-40 of templates/single-docs.php for context ===" sed -n '20,40p' templates/single-docs.phpLength of output: 1015
Block Theme Deprecation Fix Confirmed
The conditional check using
wp_is_block_theme
is correctly implemented intemplates/single-docs.php
(e.g., lines 29 and 193). The context displayed confirms that the block theme handling is in place, and no deprecated function calls were found.
// For block themes, we need to output the minimal HTML structure | ||
if (function_exists('wp_is_block_theme') && wp_is_block_theme()) { | ||
?> | ||
<!DOCTYPE html> | ||
<html <?php language_attributes(); ?>> | ||
<head> | ||
<meta charset="<?php bloginfo( 'charset' ); ?>"> | ||
<?php wp_head(); ?> | ||
</head> | ||
<body <?php body_class(); ?>> | ||
<?php wp_body_open(); ?> | ||
<div class="wp-site-blocks"> | ||
<?php block_header_area(); ?> | ||
<?php | ||
} else { | ||
get_header(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add viewport meta tag for responsive design.
When outputting the minimal HTML structure for block themes, include the viewport meta tag to ensure proper responsive behavior.
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
<?php wp_head(); ?>
</head>
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
// For block themes, we need to output the minimal HTML structure | |
if (function_exists('wp_is_block_theme') && wp_is_block_theme()) { | |
?> | |
<!DOCTYPE html> | |
<html <?php language_attributes(); ?>> | |
<head> | |
<meta charset="<?php bloginfo( 'charset' ); ?>"> | |
<?php wp_head(); ?> | |
</head> | |
<body <?php body_class(); ?>> | |
<?php wp_body_open(); ?> | |
<div class="wp-site-blocks"> | |
<?php block_header_area(); ?> | |
<?php | |
} else { | |
get_header(); | |
} | |
// For block themes, we need to output the minimal HTML structure | |
if (function_exists('wp_is_block_theme') && wp_is_block_theme()) { | |
?> | |
<!DOCTYPE html> | |
<html <?php language_attributes(); ?>> | |
<head> | |
<meta charset="<?php bloginfo( 'charset' ); ?>"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<?php wp_head(); ?> | |
</head> | |
<body <?php body_class(); ?>> | |
<?php wp_body_open(); ?> | |
<div class="wp-site-blocks"> | |
<?php block_header_area(); ?> | |
<?php | |
} else { | |
get_header(); | |
} |
fixes #142
Summary by CodeRabbit