Skip to content

Commit

Permalink
Merge pull request #3112 from pods-framework/feature/3109
Browse files Browse the repository at this point in the history
Issue #3109: Support multiple possible option names for post types and taxonomies (2.x)
  • Loading branch information
sc0ttkclark committed Aug 21, 2015
2 parents a9f01cd + 71c3320 commit 553725c
Showing 1 changed file with 84 additions and 18 deletions.
102 changes: 84 additions & 18 deletions components/Migrate-CPTUI/Migrate-CPTUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,49 @@

class Pods_Migrate_CPTUI extends PodsComponent {

/** @var array
*
* Support option names for multiple versions, list from newest to oldest
*/
private $post_option_name_list = array(
'cptui_post_types',
'cpt_custom_post_types'
);

/** @var array
*
* Support option names for multiple versions, list from newest to oldest
*/
private $taxonomy_option_name_list = array(
'cptui_taxonomies',
'cpt_custom_tax_types'
);

private $api = null;

private $post_types = null;
private $post_option_name = null;

private $taxonomy_option_name = null;

private $post_types = array();

private $taxonomies = null;
private $taxonomies = array();

/**
* Do things like register scripts and stylesheets
*
* @since 2.0
*/
public function __construct () {
$this->post_types = (array) get_option( 'cpt_custom_post_types', array() );
$this->taxonomies = (array) get_option( 'cpt_custom_tax_types', array() );
public function __construct() {

$this->post_option_name = $this->get_option_name( $this->post_option_name_list );
if ( ! isnull( $this->post_option_name ) ) {
$this->post_types = (array) get_option( $this->post_option_name, array() );
}
$this->taxonomy_option_name = $this->get_option_name( $this->taxonomy_option_name_list );
if ( ! isnull( $this->taxonomy_option_name ) ) {
$this->taxonomies = (array) get_option( $this->taxonomy_option_name, array() );
}
}

/**
Expand Down Expand Up @@ -106,15 +135,25 @@ public function ajax_migrate ( $params ) {
}

if ( 1 == pods_var( 'cleanup', $params, 0 ) ) {
if ( !empty( $post_types ) )
update_option( 'cpt_custom_post_types', $post_types );
else
delete_option( 'cpt_custom_post_types' );

if ( !empty( $taxonomies ) )
update_option( 'cpt_custom_tax_types', $taxonomies );
else
delete_option( 'cpt_custom_tax_types' );
if ( ! empty( $post_types ) ) {
if ( ! isnull( $this->post_option_name ) ) {
update_option( $this->post_option_name, $post_types );
}
} else {
if ( ! isnull( $this->post_option_name ) ) {
delete_option( $this->post_option_name );
}
}

if ( ! empty( $taxonomies ) ) {
if ( ! isnull( $this->taxonomy_option_name ) ) {
update_option( $this->taxonomy_option_name, $taxonomies );
}
} else {
if ( ! isnull( $this->taxonomy_option_name ) ) {
delete_option( $this->taxonomy_option_name );
}
}
}
}

Expand Down Expand Up @@ -274,8 +313,35 @@ private function migrate_taxonomy ( $taxonomy ) {
*
* @since 2.0
*/
public function clean () {
delete_option( 'cpt_custom_post_types' );
delete_option( 'cpt_custom_tax_types' );
public function clean() {

if ( ! isnull( $this->post_option_name ) ) {
delete_option( $this->post_option_name );
}

if ( ! isnull( $this->taxonomy_option_name ) ) {
delete_option( $this->taxonomy_option_name );
}

}
}

/**
* @param array $option_name_list List of possible option names.
*
* @return null|string The first found option name, or NULL if none were found
*/
private function get_option_name( $option_name_list ) {

$option_name_list = (array) $option_name_list;

foreach ( $option_name_list as $this_option_name ) {
if ( null !== get_option( $this_option_name, null ) ) {
return $this_option_name;
}
}

return null;

}

}

0 comments on commit 553725c

Please sign in to comment.