Skip to content

Commit

Permalink
Some corrections to #17 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
carlomanf committed Dec 9, 2022
1 parent 4a31f6d commit 331d2f0
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/funnel.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,37 +194,38 @@ private function construct_template( &$template )
$template->id = wp_get_theme()->get_stylesheet() . '//single-' . $this->slug;
$template->theme = wp_get_theme()->get_stylesheet();
$template->content = $this->blocks;
$template->slug = $this->slug;
$template->slug = 'single-' . $this->slug;
$template->source = 'custom';
$template->type = 'wp_template';
$template->description = $this->title . ' is a WP Funnel Manager funnel type.';
$template->title = $this->title;
$template->status = 'publish';
$template->has_theme_file = false;
$template->is_custom = true;
$template->is_custom = !array_key_exists( $template->slug, get_default_block_template_types() );
$template->author = $this->author;
}

public function add_template( $query_result, $query, $template_type )
{
if ( $template_type === 'wp_template' )
if ( $template_type === 'wp_template' && (
!isset( $query['slug__in'] ) || in_array( 'single-' . $this->slug, $query['slug__in'], true )
) && (
!isset( $query['wp_id'] ) || (int) $query['wp_id'] === $this->wp_id
) )
{
$id = wp_get_theme()->get_stylesheet() . '//single-' . $this->slug;
$replace_key = count( $query_result );

foreach ( array_keys( $query_result ) as $key )
{
if ( $query_result[ $key ]->id === $id )
{
$replace_key = $key;
break;
}
}

if ( $query_result[ $key ]->id !== $id )
{
$key = count( $query_result );
}

$this->construct_template( $query_result[ $key ] );
$this->construct_template( $query_result[ $replace_key ] );
}

return $query_result;
Expand Down

0 comments on commit 331d2f0

Please sign in to comment.