Import duplicate pages
-
I’m testing the plugin, and have been able to import the html.
One of mine needs would be to import different versions of the same page.Currently this would duplicate the page at wordpress, and I would need it to either delete and replace, or even better to add a version to the page.
I don’t seem to find any option to do so..is there any way to do it?
Maybe some tweek at the plugin code?
-
After researching the code, it seems like it should be doing the update (new version):
But for some reason it’s not considering the update..
Since I don’t know about PHP, and all the plugin logic, what would be the reasons for not entering this code?if (is_post_type_hierarchical($options['type']) && dirname($path) != $options['root_directory'] && in_array(basename($path), $index_files) ) { $post_id = array_search(dirname($path), $this->filearr); if ($post_id !== 0) $updatepost = true; } if ($updatepost) { $my_post['ID'] = $post_id; wp_update_post( $my_post ); } else // insert new post $post_id = wp_insert_post($my_post);[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]
after some trial and error I’ve managed to have a “ugly” version on this development.
I share here the solution such that maybe it can be integrated.To add a new functionality to the Page List (edit.php), that by cloning will pop-up a frame to select the new parent page.
(this is importing jquery in all entries..it must be a better way, but it worked fine for the current purpose!!)$actions['clone_into'] = '<script type="text/javascript" src="/wp-admin/jquery-2.0.3.min.js"></script>'. '<a href="#" id='."'".'post' . $post->ID ."'" . '">' . __('Clone Into', DUPLICATE_POST_I18N_DOMAIN) . '</a>' . '<script type="text/javascript">' . 'function getOrCreateDiv() {' . 'var myDiv = $("#postInto");' . 'if(myDiv.size() == 0) {' . '$("body").append("".concat("<div id='."'postInto'".' ",' . '"style='."'display:none; z-index:100; width: 278px; height: 100px; position:absolute; top:40%; left:40%'> </div>".'"));' . 'myDiv = $("#postInto"); ' . '}'. 'return myDiv;'. '}'. '$( "#post'.$post->ID.'" ).click(function( event ) {'. 'var myDiv=getOrCreateDiv();'. 'myDiv.html("<iframe src='."'".duplicate_post_get_clone_post_link( $post->ID , 'display', "parent")."' marginwidth='5' marginheight='5' width='100%' height='100%' style='background-color:#BBB; border-style:outset; border-width:5px; ' ></iframe>".'");'. 'myDiv.toggle();'. '});'. '</script>' ;So the method duplicate_post_get_clone_post_link at duplicate-post-common.php was changed to support multiple “modes”
function duplicate_post_get_clone_post_link( $id = 0, $context = 'display', $mode = "draft" ) { if ( !duplicate_post_is_current_user_allowed_to_copy() ) return; if ( !$post = &get_post( $id ) ) return; if ($mode == "draft") $action_name = "duplicate_post_save_as_new_post_draft"; else if ($mode == "status") $action_name = "duplicate_post_save_as_new_post"; else if ($mode == "parent") $action_name = "duplicate_post_save_as_new_post_into"; ...and then the new method that is called twice, first to present the frame with a page list, and then second to trigger the clone into functionality:
function duplicate_post_save_as_new_post_into($status = ''){ if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'duplicate_post_save_as_new_post_into' == $_REQUEST['action'] ) ) ) { wp_die(__('No post to duplicate has been supplied!', DUPLICATE_POST_I18N_DOMAIN)); } $id = (isset($_GET['post']) ? $_GET['post'] : $_POST['post']); if (! ( isset( $_GET['parent']) || isset( $_POST['parent']) ) ) { $search = array ( 'post_type' => 'page', 'post_status' => 'publish'); $pages = get_pages($search); echo '<html><head><script type="text/javascript"> function closeDiv() {window.top.location.href = "' . admin_url( 'edit.php?post_type=page') . '";}</script></head><body>'; echo '<form action="admin.php" method="get">'; echo "<p> Please select the Destination Parent Page:</p>"; echo '<select name="parent">'; foreach ( $pages as $page ) { echo '<option value="'. $page->ID .'">' . $page->post_title . "</option>"; } echo '</select>'; echo '<input type="hidden" name="action" value="duplicate_post_save_as_new_post_into">'; echo '<input type="hidden" name="post" value="'. $id .'">'; echo '<input type="submit" value="Clone!" style="float:right;">'; echo '<input type="button" value="Cancel" style="float:left;" onclick="closeDiv()" >'; echo "</form></body></html>"; } else { // Get the original post //echo '<script type="text/javascript"> alert("tenho parent");</script>'; $parentId = (isset($_GET['parent']) ? $_GET['parent'] : $_POST['parent']); $post = get_post($id); // Copy the post and insert it if (isset($post) && $post!=null) { $new_id = duplicate_post_create_duplicate($post, $status, $parentId); if ($status == ''){ // Close iframe and Redirect to the post list screen echo '<script type="text/javascript"> window.top.location.href = "' . admin_url( 'edit.php?post_type='.$post->post_type) . ';</script>'; } else { // Close iframe and Redirect to the edit screen for the new draft post echo '<script type="text/javascript"> window.top.location.href = "' . admin_url( 'post.php?action=edit&post='.$new_id) . ';</script>'; } exit; } else { $post_type_obj = get_post_type_object( $post->post_type ); wp_die(esc_attr(__('Copy creation failed, could not find original:', DUPLICATE_POST_I18N_DOMAIN)) . ' ' . $id); } } }Finally to update internal child links was added this code to the end of duplicate_post_create_duplicate.
(Since I’m using “.html on PAGES” plugin I needed to have that taken care on replacing the paths)://Update internal links for child pages if (get_option('duplicate_post_copychildren') == 1) { $real_new_post = get_post($new_post_id); $new_post = array(); $new_post['ID'] = $new_post_id; $new_post['post_content'] = str_replace( str_replace(".html", "", get_permalink($post->ID)), str_replace(".html", "", get_permalink( $new_post_id)), $real_new_post->post_content); // Update the post into the database wp_update_post( $new_post ); }Any other support I can give to include this functionality just say.
never mind about the code on last point…it was about other plugin..
sorry my confusionjust a smaller change.
at import-html-pages/html-import-options.php I’ve changed at line 480 the
<option value='0'><?php _e('Default Template'); ?></option> <?php page_template_dropdown(); ?>into:
<?php page_template_dropdown($options['page_template']); ?>this seems to fix the problem that on option load the selected Page Template doesn’t show.
so considering the initial requirement to update the page, instead of inserting a new one I believe I have the solution:
The first if will take care of index.html files, allowing them to update the dummy page for the folder, while maintaining its title and correct page parent.
The rest of the code serves for the identification of older pages taking into consideration the page path (according to the page parent uri plus this page).if ($updatepost) { $my_post['ID'] = $post_id; $myPostParent = $my_post['post_parent ']; $postname = $my_post['post_title']; unset($my_post['post_parent']); unset($my_post['post_title']); wp_update_post( $my_post ); $my_post['post_parent'] = $myPostParent; $my_post['post_title'] = $postname; } else {// insert new post if ($my_post['post_parent'] !== false) { $pageByParent = get_page_by_path( get_page_uri($my_post['post_parent']) . "/" . sanitize_title($my_post['post_title'])); if($old_page !== false) { $old_page = $pageByParent; } } else { $old_page = get_page_by_title($my_post['post_title']); }
The topic ‘Import duplicate pages’ is closed to new replies.