Duplicate Page Hierarchy
-
I believe this is more like a feature request, but it would be great if I can duplicate a page hierarchy instead of simple pages.
It would imply recognizing page childs, clone them, and change internal links between those pages only.
I’ll try to look at plugin code, but I’m not a PHP developer 😛
Anyone wants to contribute as well, so that we can improve this great plugin?
-
ok..my bad!
I see now that the plugin already clones child pages 🙂
but still it doesn’t update the internal links which I believe would be important!Also I would love to be able to select the parent for the cloned page (only the parent..the childs would automatically follow I believe).
Eventually I could do this by hand, after cloning, but it would be great to make it automatically!so still development to contribute 🙂
One approach will be to add:
//Update internal links for child pages if (get_option('duplicate_post_copychildren') == 1) { //error_log( 'old post data: ' . print_r( $post, true ) . ", new post data: " . print_r( $new_post, true ) . // ", old post permalink: " . get_permalink( $post->ID) . ", new post permalink: " . get_permalink( $new_post_id)); $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 ); }at the end of duplicate_post_create_duplicate method.
The problem is that this will only update child links, but not parent links. Although this serves 99% of my links it still would be improved by cloning child pages within main method instead on a registered action.
Since 99% of my links are solved I’ll now try to work on defining a parent from where to copy to.
I believe I’ve had published this before, but just in case something went wrong I publish it again.
In case this is being deleted for some reason please comment the thread and I won’t re-post this.I’m not a PHP developer, neither wordpress…so probably better solutions can be found to this code.
So to add the Clone Into functionality into the Page List I’ve added the option at duplicate_post_make_duplicate_link_row:this is including jquery at every page…definally better solution to this can be found!
$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>' ;At the duplicate-post-common.php is needed to change duplicate_post_get_clone_post_link 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 finally to ask for a new parent page for the cloned one:
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); } } }Hope this can help on improving this great plugin!
The topic ‘Duplicate Page Hierarchy’ is closed to new replies.