/** * Include the necessary files and main hooks. * * @since 2.0 */ protected function __construct() { # Load the textdomain $mofile = UPT_DIR . "/languages/ultimate-post-types-" . get_locale() . ".mo"; if (file_exists($mofile)) { load_textdomain('ultimate-post-types', $mofile); } # Check if the parent plugin is active if (!defined('ULTIMATE_FIELDS_MAIN_FILE')) { return add_action('admin_notices', array($this, 'missing_parent_notice')); } # Include classes and start them require_once UPT_DIR . 'lib/abstract-class-upt-editable.php'; require_once UPT_DIR . 'lib/class-upt-post-type.php'; UPT_Post_Type::instance(); require_once UPT_DIR . 'lib/class-upt-taxonomy.php'; UPT_Taxonomy::instance(); # Add the needed styles add_action('uf_enqueue_scripts', array($this, 'scripts_styles')); # Disable post types from showing up in the UF interface. add_filter('uf.ui.excluded_post_types', array($this, 'exclude_own_post_types')); # IF needed, this will flush rewrites. add_action('init', array($this, 'init')); # Adds the template theme add_action('uf.extend', array($this, 'add_themes')); # Add extra export screens add_filter('uf.ui.settings.export.tabs', array($this, 'add_export_screens')); # Add extra import processors add_filter('uf.ui.settings.importer', array($this, 'change_importer'), 10, 2); }
/** * Imports a post type. * * @since 2.0 * * @param mixed[] $post_type The data about the post type. */ public function import_post_type($post_type) { # Create the post type handling class $helper = UPT_Post_Type::instance(); # Create the post $post_id = wp_insert_post(array('post_type' => $helper->get_slug(), 'post_title' => $post_type['data']['name'], 'post_status' => 'publish', 'post_content' => '')); # Transform the data for easy checks $meta = array(); foreach ($post_type['data'] as $key => $value) { $meta['upt_pt_' . $key] = $value; } # Add the necessary meta $container = $helper->setup_fields(); foreach ($container->get_fields() as $field) { $id = $field->get_id(); if (isset($meta[$id])) { update_post_meta($post_id, $id, $meta[$id]); } } # Make sure fields are imported as well update_post_meta($post_id, 'fields_tab_fields', $this->add_container_fields($post_id, $post_type['fields'])); }