Created
December 13, 2013 12:47
-
-
Save benallfree/7943757 to your computer and use it in GitHub Desktop.
Add import/export to CPT.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: custom-post-type-ui.php | |
=================================================================== | |
--- custom-post-type-ui.php (revision 821057) | |
+++ custom-post-type-ui.php (working copy) | |
@@ -59,6 +59,7 @@ | |
add_submenu_page( 'cpt_main_menu', __( 'Add New', 'cpt-plugin' ), __( 'Add New', 'cpt-plugin' ), 'manage_options', 'cpt_sub_add_new', 'cpt_add_new' ); | |
add_submenu_page( 'cpt_main_menu', __( 'Manage Post Types', 'cpt-plugin' ), __( 'Manage Post Types', 'cpt-plugin' ), 'manage_options', 'cpt_sub_manage_cpt', 'cpt_manage_cpt' ); | |
add_submenu_page( 'cpt_main_menu', __( 'Manage Taxonomies', 'cpt-plugin' ), __( 'Manage Taxonomies', 'cpt-plugin' ), 'manage_options', 'cpt_sub_manage_taxonomies', 'cpt_manage_taxonomies' ); | |
+ add_submenu_page( 'cpt_main_menu', __( 'Import/Export', 'cpt-plugin' ), __( 'Import/Export', 'cpt-plugin' ), 'manage_options', 'cpt_sub_import_export', 'cpt_import_export' ); | |
} | |
//temp fix, should do: http://planetozh.com/blog/2008/04/how-to-load-javascript-with-your-wordpress-plugin/ | |
@@ -565,6 +566,63 @@ | |
cpt_footer(); | |
} | |
+ | |
+function cpt_import_export() { | |
+ global $CPT_URL, $wp_post_types; | |
+ | |
+ $RETURN_URL = ( isset( $_GET['return'] ) ) ? 'action="' . cpt_check_return( esc_attr( $_GET['return'] ) ) . '"' : ''; | |
+ | |
+ if(isset($_POST['import'])) | |
+ { | |
+// check_admin_referer('cpt_import'); | |
+ $data = trim($_POST['import']); | |
+ $data = stripslashes_deep($data); | |
+ $settings = json_decode($data,true); | |
+ if($settings) | |
+ { | |
+ $settings = array_values($settings); | |
+ update_option( 'cpt_custom_post_types', $settings ); | |
+ } | |
+ } | |
+ //flush rewrite rules | |
+ flush_rewrite_rules(); | |
+?> | |
+ <div class="wrap"> | |
+ <?php screen_icon( 'plugins' ); ?> | |
+ <h2><?php _e( 'Import/Export', 'cpt-plugin' ); ?> </h2> | |
+ | |
+ <h2><?php _e( 'Import', 'cpt-plugin' ); ?></h2> | |
+ <p><?php _e( 'To import custom post types, paste the JSON text shown from a previous export', 'cpt-plugin' ); ?> | |
+ <form method="post" <?php echo $RETURN_URL; ?>> | |
+ <?php | |
+ if ( function_exists( 'wp_nonce_field' ) ) | |
+ wp_nonce_field( 'cpt_import' ); | |
+ ?> | |
+ <p> | |
+ <textarea name="import" style="width: 300px; height: 200px"> | |
+ </textarea> | |
+ </p> | |
+ <p> | |
+ <input type="submit" value="Import"/> | |
+ </p> | |
+ </form> | |
+ <h2><?php _e( 'Export', 'cpt-plugin' ); ?></h2> | |
+ <p><?php _e( 'The following is a JSON export of your current CPT settings. Copy this information to a different installation or simply save it for backup purposes.', 'cpt-plugin' ); ?> | |
+ <p> | |
+ <?php | |
+ $cpt_post_types = get_option( 'cpt_custom_post_types', array() ); | |
+ $json = json_encode($cpt_post_types); | |
+ | |
+ ?> | |
+ <textarea style="width: 300px; height: 200px"><?php echo(esc_html($json))?></textarea> | |
+ </p> | |
+ </div> | |
+<?php | |
+//load footer | |
+cpt_footer(); | |
+} | |
+ | |
+ | |
//manage custom post types page | |
function cpt_manage_cpt() { | |
global $CPT_URL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment