Skip to content

Commit

Permalink
Deregister funnel types not associated with the active theme
Browse files Browse the repository at this point in the history
  • Loading branch information
carlomanf committed Feb 20, 2021
1 parent 829f7de commit 7cf7442
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 49 deletions.
66 changes: 26 additions & 40 deletions src/funnel.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,42 +61,16 @@ public function __construct( $slug, $template )

public function register()
{
add_action( 'init', array( $this, 'register_taxonomies' ) );
add_filter( 'map_meta_cap', array( $this, 'assign_admin' ), 10, 4 );
add_action( 'wp_roles_init', array( $this, 'add_role' ) );
add_filter( 'editable_roles', array( $this, 'make_role_editable' ) );
add_filter( 'post_row_actions', array( $this, 'funnel_interior_edit' ), 10, 2 );
add_action( 'init', array( __CLASS__, 'post_parent_query_var' ) );
add_action( 'admin_menu', array( $this, 'remove_interiors' ) );
add_filter( 'wp_insert_post_data', array( $this, 'setup_interior' ) );
add_action( 'save_post', array( $this, 'update_post_author' ), 10, 2 );
add_filter( 'admin_url', array( $this, 'new_interior' ), 10, 2 );
add_action( 'wp_trash_post', array( $this, 'trash_exterior_promote_interior' ) );
}

public function get_all_funnels()
{
$exteriors = get_posts( 'post_type=' . $this->slug );
$funnels = array();

foreach ( $exteriors as $exterior )
{
$steps = array( $exterior );
$interiors = get_posts( 'post_type=' . $this->slug . '_int&post_parent=' . $exterior->ID );

foreach ( $interiors as $interior )
{
$steps[] = $interior;
}

$funnels[] = new Funnel( $exterior->ID, $steps );
}

return $funnels;
}

public function register_taxonomies()
{
$labels = array(
"name" => __( "Interiors", "wpfunnel" ),
"singular_name" => __( "Interior", "wpfunnel" ),
Expand Down Expand Up @@ -153,6 +127,32 @@ public function register_taxonomies()
register_post_type( $this->slug, $args );
}

public function get_all_funnels()
{
$exteriors = get_posts( 'post_type=' . $this->slug );
$funnels = array();

foreach ( $exteriors as $exterior )
{
$steps = array( $exterior );
$interiors = get_posts( 'post_type=' . $this->slug . '_int&post_parent=' . $exterior->ID );

foreach ( $interiors as $interior )
{
$steps[] = $interior;
}

$funnels[] = new Funnel( $exterior->ID, $steps );
}

return $funnels;
}

public function template()
{
return $this->template;
}

/**
* Determine whether a user is the owner of this funnel type
* They are an owner if they can edit the original template
Expand Down Expand Up @@ -239,20 +239,6 @@ public function funnel_interior_edit( $actions, $post ) {

return $actions;
}

/**
* Allow post parent as query var
* This is needed to view funnel interiors
*
* @since 1.0.3
*/
public static function post_parent_query_var()
{
if ( !is_admin() )
return;

$GLOBALS['wp']->add_query_var( 'post_parent' );
}

/**
* Validates whether the supplied post ID is a valid exterior
Expand Down
41 changes: 32 additions & 9 deletions src/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class WP_Funnel_Manager
*/
private $funnel_types = array();

/**
* Registered funnel types managed by this plugin.
*
* @since 1.2.0
* @var array
*/
private $registered_funnel_types = array();

/**
* Instantiate a WP_Funnel_Manager object.
*
Expand All @@ -31,6 +39,8 @@ class WP_Funnel_Manager
*/
public function __construct()
{
$this->theme = wp_get_theme()->get_stylesheet();

if ( ( $legacy = $this->is_legacy() ) )
{
$this->funnel_types[] = new Legacy_Funnel_Type();
Expand Down Expand Up @@ -80,9 +90,29 @@ public function is_legacy()

public function register_funnel_types()
{
$this->registered_funnel_types = array();

foreach ( $this->funnel_types as $type )
{
$type->register();
if ( has_term( $this->theme, 'wp_theme', $type->template() ) )
{
$type->register();
$this->registered_funnel_types[] = $type;
}
}

if ( empty( $this->registered_funnel_types ) )
{
add_action( 'admin_footer', array( $this, 'no_funnels_notice' ) );
}
else
{
/**
* Allow post parent as query var
* This is needed to view funnel interiors
*/
if ( is_admin() )
$GLOBALS['wp']->add_query_var( 'post_parent' );
}
}

Expand All @@ -93,14 +123,7 @@ public function register_funnel_types()
*/
public function run()
{
if ( empty( $this->funnel_types ) )
{
add_action( 'admin_footer', array( $this, 'no_funnels_notice' ) );
}
else
{
$this->register_funnel_types();
}
add_action( 'init', array( $this, 'register_funnel_types' ) );
}

public function no_funnels_notice()
Expand Down

0 comments on commit 7cf7442

Please sign in to comment.