Exemplo n.º 1
0
/**
 * Create our settings page output.
 *
 * @since 1.0.0
 *
 * @return string HTML output for the page.
 */
function cptui_importexport()
{
    if (!empty($_GET)) {
        if (!empty($_GET['action']) && 'taxonomies' == $_GET['action']) {
            $tab = 'taxonomies';
        } elseif (!empty($_GET['action']) && 'get_code' == $_GET['action']) {
            $tab = 'get_code';
        } else {
            $tab = 'post_types';
        }
    }
    if (!empty($_POST)) {
        $notice = cptui_import_types_taxes_settings($_POST);
    }
    if (isset($notice)) {
        echo $notice;
    }
    echo '<div class="wrap">';
    # Create our tabs.
    cptui_settings_tab_menu($page = 'importexport');
    if (isset($tab) && ('post_types' == $tab || 'taxonomies' == $tab)) {
        ?>
	<p><?php 
        _e('If you are wanting to migrate registered post types or taxonomies from this site to another, that will also use Custom Post Type UI, use the import and export functionality. If you are moving away from Custom Post Type UI, use the information in the "Get Code" tab.', 'cpt-plugin');
        ?>
</p>

	<p><?php 
        printf('<strong>%s</strong>: %s', __('NOTE', 'cpt-plugin'), __('This will not export the associated posts, just the settings.', 'cpt-plugin'));
        ?>
	</p>
	<table class="form-table cptui-table">
		<?php 
        if (!empty($_GET) && empty($_GET['action'])) {
            ?>
		<tr>
			<td>
				<h3><?php 
            _e('Import Post Types', 'cpt-plugin');
            ?>
</h3>
				<form method="post">
					<textarea class="cptui_post_import" placeholder="<?php 
            esc_attr_e('Paste content here.', 'cpt-plugin');
            ?>
" name="cptui_post_import"></textarea>
					<p class="wp-ui-highlight"><strong><?php 
            _e('Note:', 'cpt-plugin');
            ?>
</strong> <?php 
            _e('Importing will overwrite previous registered settings.', 'cpt-plugin');
            ?>
</p>
					<p><strong><?php 
            _e('To import post types from a different WordPress site, paste the exported content from that site and click the "Import" button.', 'cpt-plugin');
            ?>
</strong></p>
					<p><input class="button button-primary" type="submit" value="<?php 
            esc_attr_e('Import', 'cpt-plugin');
            ?>
"/></p>
				</form>
			</td>
			<td>
				<h3><?php 
            _e('Export Post Types', 'cpt-plugin');
            ?>
</h3>
				<?php 
            $cptui_post_types = get_option('cptui_post_types', array());
            if (!empty($cptui_post_types)) {
                $content = esc_html(json_encode($cptui_post_types));
            } else {
                $content = __('No post types registered yet.', 'cpt-plugin');
            }
            ?>
				<textarea title="<?php 
            esc_attr_e('To copy the system info, click below then press Ctrl + C (PC) or Cmd + C (Mac).', 'cpt-plugin');
            ?>
" onclick="this.focus();this.select()" readonly="readonly" class="cptui_post_import"><?php 
            echo $content;
            ?>
</textarea>
				<p><strong><?php 
            _e('Use the content above to import current post types into a different WordPress site. You can also use this to simply back up your post type settings.', 'cpt-plugin');
            ?>
</strong></p>
			</td>
		</tr>
		<?php 
        } elseif (!empty($_GET) && 'taxonomies' == $_GET['action']) {
            ?>
		<tr>
			<td>
				<h3><?php 
            _e('Import Taxonomies', 'cpt-plugin');
            ?>
</h3>
				<form method="post">
					<textarea class="cptui_tax_import" placeholder="<?php 
            esc_attr_e('Paste content here.', 'cpt-plugin');
            ?>
" name="cptui_tax_import"></textarea>
					<p class="wp-ui-highlight"><strong><?php 
            _e('Note:', 'cpt-plugin');
            ?>
</strong> <?php 
            _e('Importing will overwrite previous registered settings.', 'cpt-plugin');
            ?>
</p>
					<p><strong><?php 
            _e('To import taxonomies from a different WordPress site, paste the exported content from that site and click the "Import" button.', 'cpt-plugin');
            ?>
</strong></p>
					<p><input class="button button-primary" type="submit" value="<?php 
            esc_attr_e('Import', 'cpt-plugin');
            ?>
"/></p>
				</form>
			</td>
			<td>
				<h3><?php 
            _e('Export Taxonomies', 'cpt-plugin');
            ?>
</h3>
				<?php 
            $cptui_taxonomies = get_option('cptui_taxonomies', array());
            if (!empty($cptui_taxonomies)) {
                $content = esc_html(json_encode($cptui_taxonomies));
            } else {
                $content = __('No taxonomies registered yet.', 'cpt-plugin');
            }
            ?>
				<textarea title="<?php 
            esc_attr_e('To copy the system info, click below then press Ctrl + C (PC) or Cmd + C (Mac).', 'cpt-plugin');
            ?>
" onclick="this.focus();this.select()" readonly="readonly" class="cptui_tax_import"><?php 
            echo $content;
            ?>
</textarea>
				<p><strong><?php 
            _e('Use the content above to import current taxonomies into a different WordPress site. You can also use this to simply back up your taxonomy settings.', 'cpt-plugin');
            ?>
</strong></p>
			</td>
		</tr>
		<?php 
        }
        ?>
	</table>

	<?php 
    } else {
        ?>
		<h2><?php 
        _e('Get Post Type and Taxonomy Code', 'cpt-plugin');
        ?>
</h2>

		<h3><?php 
        _e('All CPT UI Post Types', 'cpt-plugin');
        ?>
</h3>
		<label for="cptui_post_type_get_code"><?php 
        _e('Copy/paste the code below into your functions.php file.', 'cpt-plugin');
        ?>
</label>
		<textarea name="cptui_post_type_get_code" id="cptui_post_type_get_code" class="cptui_post_type_get_code" onclick="this.focus();this.select()" readonly="readonly"><?php 
        cptui_get_post_type_code();
        ?>
</textarea>

		<h3><?php 
        _e('All CPT UI Taxonomies', 'cpt-plugin');
        ?>
</h3>
		<label for="cptui_tax_get_code"><?php 
        _e('Copy/paste the code below into your functions.php file.', 'cpt-plugin');
        ?>
</label>
		<textarea name="cptui_tax_get_code" id="cptui_tax_get_code" class="cptui_tax_get_code" onclick="this.focus();this.select()" readonly="readonly"><?php 
        cptui_get_taxonomy_code();
        ?>
</textarea>
	<?php 
    }
    echo '</div><!-- End .wrap -->';
}
/**
 * Content for the Get Code tab.
 *
 * @since 1.2.0
 *
 * @internal
 */
function cptui_render_getcode_section()
{
    ?>
	<h1><?php 
    _e('Get Post Type and Taxonomy Code', 'custom-post-type-ui');
    ?>
</h1>

		<h2><?php 
    _e('All CPT UI Post Types', 'custom-post-type-ui');
    ?>
</h2>

		<?php 
    $cptui_post_types = cptui_get_post_type_data();
    ?>
		<label for="cptui_post_type_get_code"><?php 
    _e('Copy/paste the code below into your functions.php file.', 'custom-post-type-ui');
    ?>
</label>
		<textarea name="cptui_post_type_get_code" id="cptui_post_type_get_code" class="cptui_post_type_get_code" onclick="this.focus();this.select()" onfocus="this.focus();this.select();" readonly="readonly" aria-readonly="true"><?php 
    cptui_get_post_type_code($cptui_post_types);
    ?>
</textarea>

		<?php 
    if (!empty($cptui_post_types)) {
        foreach ($cptui_post_types as $post_type) {
            ?>
				<h2><?php 
            $type = !empty($post_type['label']) ? $post_type['label'] : $post_type['name'];
            printf(__('%s Post Type', 'custom-post-type-ui'), $type);
            ?>
</h2>
				<label for="cptui_post_type_get_code_<?php 
            echo $post_type['name'];
            ?>
"><?php 
            _e('Copy/paste the code below into your functions.php file.', 'custom-post-type-ui');
            ?>
</label>
				<textarea name="cptui_post_type_get_code_<?php 
            echo $post_type['name'];
            ?>
" id="cptui_post_type_get_code_<?php 
            echo $post_type['name'];
            ?>
" class="cptui_post_type_get_code" onclick="this.focus();this.select()" onfocus="this.focus();this.select();" readonly="readonly" aria-readonly="true"><?php 
            cptui_get_post_type_code(array($post_type), true);
            ?>
</textarea>
			<?php 
        }
    }
    ?>

		<h2><?php 
    _e('All CPT UI Taxonomies', 'custom-post-type-ui');
    ?>
</h2>

		<?php 
    $cptui_taxonomies = cptui_get_taxonomy_data();
    ?>
		<label for="cptui_tax_get_code"><?php 
    _e('Copy/paste the code below into your functions.php file.', 'custom-post-type-ui');
    ?>
</label>
		<textarea name="cptui_tax_get_code" id="cptui_tax_get_code" class="cptui_tax_get_code" onclick="this.focus();this.select()" onfocus="this.focus();this.select();" readonly="readonly" aria-readonly="true"><?php 
    cptui_get_taxonomy_code($cptui_taxonomies);
    ?>
</textarea>

		<?php 
    if (!empty($cptui_taxonomies)) {
        foreach ($cptui_taxonomies as $taxonomy) {
            ?>
				<h2><?php 
            $tax = !empty($taxonomy['label']) ? $taxonomy['label'] : $taxonomy['name'];
            printf(__('%s Taxonomy', 'custom-post-type-ui'), $tax);
            ?>
</h2>
				<label for="cptui_tax_get_code_<?php 
            echo $taxonomy['name'];
            ?>
"><?php 
            _e('Copy/paste the code below into your functions.php file.', 'custom-post-type-ui');
            ?>
</label>
				<textarea name="cptui_tax_get_code_<?php 
            echo $taxonomy['name'];
            ?>
" id="cptui_tax_get_code_<?php 
            echo $taxonomy['name'];
            ?>
" class="cptui_tax_get_code" onclick="this.focus();this.select()" onfocus="this.focus();this.select();" readonly="readonly" aria-readonly="true"><?php 
            cptui_get_taxonomy_code(array($taxonomy), true);
            ?>
</textarea>
			<?php 
        }
    }
    ?>
	<?php 
}