parent = $parent; add_action( 'admin_menu', array( $this, 'admin_menu' ) ); } public function is_action( $action ) { if ( !empty( $_POST['action'] ) && $_POST['action'] === $action ) { return true; } return false; } public function process_import() { if ( !$this->is_action( 'import' ) ) { return; } if ( empty( $_POST['import_code'] ) ) { return; } $import_code = stripslashes($_POST['import_code']); $import_array = json_decode( $import_code, true ); if ( empty( $import_array['0']['post']['ID'] ) ) { return false; } $imported = array(); $errors = array(); foreach ($import_array as $key => $to_import) { unset($to_import['post']['ID']); $insert_id = wp_insert_post( $to_import['post'], false ); if ( !empty( $insert_id ) ) { $imported[] = array( 'ID' => $insert_id, 'post_title' => $to_import['post']['post_title'], ); } else { $errors[] = $to_import; } } return array( 'imported' => $imported, 'errors' => $errors, ); } public function get_export_array( $ids=array() ) { $response = array(); foreach ($ids as $key => $id) { $post = get_post( $id ); if ( empty( $post->post_type ) || $post->post_type !== 'da_image' ) { continue; } $response[$key] = array( 'id' => $id, 'post' => (array)$post, ); $metadata = get_post_meta( $id, '', true ); foreach ($metadata as $meta_key => $meta_value) { if ( strpos( $meta_key, '_da_' ) !== 0 ) { continue; } $response[$key]['post']['meta_input'][$meta_key] = maybe_unserialize( $meta_value[0] ); } } return $response; } public function get_export_json( $ids=array() ) { $export_array = $this->get_export_array( $ids ); return json_encode( $export_array ); } public function admin_menu() { global $submenu; add_submenu_page( 'edit.php?post_type=da_image', __( 'Import / Export', 'draw-attention' ), __( 'Import / Export', 'draw-attention' ), 'delete_others_posts', 'import_export', array( $this, 'output_import_export_page' ) ); } public function output_import_export_page() { // only allow users with capability: "delete_others_posts" if ( ! current_user_can( 'delete_others_posts' ) ) { return; } ?>

Import

If you've already exported from another site, paste the export code below:


process_import(); ?> $value): ?>

Successfully imported

Note: the image itself isn't transferred over, so you will need to reupload it. But most importantly all the colors and shapes are transferred over!


Export

Choose images to export

'da_image', 'post_status' => 'any', 'posts_per_page' => -1, ) ); $export_ids = ( empty( $_POST['export_ids'] ) ) ? array() : (array)$_POST['export_ids']; foreach ($da_images->posts as $key => $da_image): ?> ID, $export_ids ) ) echo 'checked="checked"'; ?> />
is_action( 'export' ) ): ?> Please select one or more images above to export get_export_json( $export_ids ); ?>