Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Improve protection
Browse files Browse the repository at this point in the history
  • Loading branch information
Aljullu committed Nov 8, 2023
1 parent 6268749 commit d55197b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/BlockTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function render_woocommerce_template_part( $attributes ) {
*/
public function get_block_template_fallback( $template, $id, $template_type ) {
// Add protection against invalid ids.
if ( ! is_string( $id ) || ! str_contains( $id, '//' ) ) {
if ( ! is_string( $id ) || ! strstr( $id, '//' ) ) {
return null;
}
// Add protection against invalid template types.
Expand All @@ -194,10 +194,11 @@ public function get_block_template_fallback( $template, $id, $template_type ) {
) {
return null;
}
$template_name_parts = explode( '//', $id );
list( $theme, $slug ) = $template_name_parts;
$template_name_parts = explode( '//', $id );
$theme = $template_name_parts[0] ?? '';
$slug = $template_name_parts[1] ?? '';

if ( ! BlockTemplateUtils::template_is_eligible_for_product_archive_fallback( $slug ) ) {
if ( empty( $theme ) || empty( $slug ) || ! BlockTemplateUtils::template_is_eligible_for_product_archive_fallback( $slug ) ) {
return null;
}

Expand Down

0 comments on commit d55197b

Please sign in to comment.