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

Remove conditional_template_part function #289

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions source/wp-content/themes/wporg-news-2021/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
add_action( 'pre_get_posts', __NAMESPACE__ . '\override_category_query_args' );
add_filter( 'body_class', __NAMESPACE__ . '\clarify_body_classes' );
add_filter( 'post_class', __NAMESPACE__ . '\specify_post_classes', 10, 3 );
add_filter( 'theme_file_path', __NAMESPACE__ . '\conditional_template_part', 10, 2 );
add_filter( 'render_block_data', __NAMESPACE__ . '\custom_query_block_attributes' );
add_filter( 'template_redirect', __NAMESPACE__ . '\jetpack_likes_workaround' );
add_filter( 'the_title', __NAMESPACE__ . '\update_the_title', 10, 2 );
Expand Down Expand Up @@ -306,32 +305,6 @@ function specify_post_classes( $classes, $extra_classes, $post_id ) {
return $classes;
}

/**
* Crudely simulate the $name parameter to get_template_part() for the wp:template-part block
* Example: <!-- wp:template-part {"slug":"foo-bar{-test}"} -->
* will attempt to use "foo-bar-test", and fall back to "foo-bar" if that template file does not exist
*/
function conditional_template_part( $path, $file ) {
if ( false !== strpos( $path, '{' ) && ! file_exists( $path ) ) {
if ( preg_match( '/[{]([-\w]+)[}]/', $path, $matches ) ) {
$name = $matches[1];
// Try "foo-bar-test"
$new_path = str_replace( '{' . $name . '}', $name, $path );
if ( file_exists( $new_path ) ) {
$path = $new_path;
} else {
// If that doesn't exist, try "foo-bar"
$new_path = str_replace( '{' . $name . '}', '', $path );
if ( file_exists( $new_path ) ) {
$path = $new_path;
}
}
}
}

return $path;
}

/**
* Support some additional pseudo-attributes for the wp:query block; notably category slugs.
*
Expand Down