function mpd_admin_menu_markup() { global $wp_post_types; $success = false; if (isset($_POST['duplicate-submit'])) { $mdp_PostType = $_POST['el0']; $mdp_PostID = $_POST['el1']; $mdp_NewBlog = $_POST['el2']; $mdp_userID = $_POST['el3']; $mdp_prefix = $_POST['mdp-prefix']; $mdp_postStatus = $_POST['mpd-post-status']; $new_postid = duplicate_over_multisite($mdp_PostID, $mdp_NewBlog, $mdp_PostType, $mdp_userID, $mdp_prefix, $mdp_postStatus); $success = true; } $post_types = get_post_types(); ob_start(); ?> <div class="wrap"> <h2>Multisite Post Duplicator</h2> <?php if (!is_multisite()) { ?> <h2>Attention!</h2> <p>At the moment this plugin is solely for funtioning on a mulitisite. It appears this site doees not have multisite enabled.</p> <?php return; ?> <?php } ?> <?php if ($success) { ?> <div class="updated mdp-updated"> <h3><strong>Congratuations. The page/post was duplicated successfully.</strong></h3> </div> <?php } ?> <form id="thefirstform" action="<?php echo $_SERVER['REQUEST_URI']; ?> " method="post"> <div class="metabox"> <h2>Options</h2> <p>Select your preferences for the duplication.</p> <h3>Select the status of the new post that will be created</h3> <?php $post_statuses = array('publish', 'future', 'draft', 'pending', 'private'); ?> <?php foreach ($post_statuses as $post_status) { ?> <input type="radio" name="mpd-post-status" value="<?php echo $post_status; ?> " <?php echo $post_status == 'draft' ? 'checked' : ''; ?> /><?php echo ucfirst($post_status); ?> <?php } ?> <h3>Select a prefix, if any, for the new post/page to be created:</h3> <input type="text" name="mdp-prefix" value="Copy of"/> </div> <div class="metabox"> <h2>Process the duplication</h2> <h3>1. Select the post type of the post you want to duplicate</h3> <input type="hidden" name="action" value="add_foobar"> <select name="el0" class="el0" style="width:300px;"> <option></option> <option value="any" > - All Post Types -</option> <?php foreach ($post_types as $post_type) { ?> <option value="<?php echo $post_type; ?> "> <?php echo ucfirst($post_type); ?> </option> <?php } ?> <?php wp_reset_postdata(); ?> </select> <div class="el0sc spinner-container"><img src="<?php echo plugins_url('../css/select2-spinner.gif', __FILE__); ?> "/></div> <div class="el1-container"></div> <div class="el2-container"></div> <div class="el3-container"></div> </div> </form> </div> <?php }
function mpd_clone_post($data) { // Other "don't save" operations as remove or create new one: if (!count($_POST)) { return $data; } if ($_POST["post_status"] != "auto-draft" && isset($_POST['mpd_blogs']) && count($_POST['mpd_blogs']) && $_POST["post_ID"] == $data) { $mpd_blogs = $_POST['mpd_blogs']; foreach ($mpd_blogs as $mpd_blog_id) { duplicate_over_multisite($_POST["ID"], $mpd_blog_id, $_POST["post_type"], $_POST["post_author"], $_POST["mpd-prefix"], $_POST["mpd-new-status"]); } } return $data; }