Skip to content

Commit

Permalink
Workaround for WordPress/gutenberg#29484
Browse files Browse the repository at this point in the history
  • Loading branch information
carlomanf committed Jun 28, 2023
1 parent 407b19d commit bc1003f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
3 changes: 2 additions & 1 deletion init.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

// Load funnel type classes.
require WP_FUNNEL_DIR . 'src/legacy.php';
require WP_FUNNEL_DIR . 'src/funnel.php';
require WP_FUNNEL_DIR . 'src/dynamic.php';
require WP_FUNNEL_DIR . 'src/natural.php';

// Load other classes.
require WP_FUNNEL_DIR . 'src/plugin.php';
Expand Down
4 changes: 2 additions & 2 deletions src/funnel.php → src/dynamic.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

/**
* Main funnel class.
* Dynamic funnel class.
*/
namespace WP_Funnel_Manager;

class Funnel_Type extends Legacy_Funnel_Type
class Dynamic_Funnel_Type extends Legacy_Funnel_Type
{
private $wp_id;
private $title;
Expand Down
45 changes: 45 additions & 0 deletions src/natural.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* Natural funnel class.
*/
namespace WP_Funnel_Manager;

class Natural_Funnel_Type extends Dynamic_Funnel_Type
{
private $added_wp_link_pages = array();

public function __construct( $slug, $wp_id, $title, $blocks, $author )
{
parent::__construct( $slug, $wp_id, $title, $blocks, $author );
}

public function register()
{
parent::register();

// Workaround for https://github.com/WordPress/gutenberg/issues/29484
add_filter( 'the_content', array( $this, 'add_wp_link_pages' ), 0 );
add_filter( 'wp_link_pages_args', array( $this, 'added_wp_link_pages' ) );
}

public function added_wp_link_pages( $parsed_args )
{
$id = get_the_ID();
( get_post_type() !== $this->slug || isset( $this->added_wp_link_pages[ $id ] ) ) or $this->added_wp_link_pages[ $id ] = true;
return $parsed_args;
}

public function add_wp_link_pages( $content )
{
$id = get_the_ID();

if ( get_post_type() === $this->slug && $GLOBALS['multipage'] && !isset( $this->added_wp_link_pages[ $id ] ) )
{
$this->added_wp_link_pages[ $id ] = false;
return $content . wp_link_pages( array( 'echo' => 0 ) );
}

return $content;
}
}
4 changes: 2 additions & 2 deletions src/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function register_funnel_types()

if ( !$this->is_legacy || $slug !== 'funnel' )
{
$this->funnel_types[] = new Funnel_Type( $slug, $post->ID, $post->post_title, $post->post_content, $post->post_author );
$this->funnel_types[] = new Natural_Funnel_Type( $slug, $post->ID, $post->post_title, $post->post_content, $post->post_author );
}
}
}
Expand Down Expand Up @@ -163,7 +163,7 @@ public function menu()
$parent_capability = $this->is_legacy ? 'edit_posts' : $new_type_capability;

// Workaround for core ticket #52043. If the bug is encountered, the menu for one of the funnel types needs to be registered separately here.
$type = Funnel_Type::get_type_for_parent_menu();
$type = Dynamic_Funnel_Type::get_type_for_parent_menu();

if ( !is_null( $type ) || $this->is_legacy && $this->is_templated && !current_user_can( $parent_capability ) && current_user_can( $new_type_capability ) )
{
Expand Down

0 comments on commit bc1003f

Please sign in to comment.