Пример #1
0
/**
 * 
 * Static function to allow MDP default options to be referenced globally
 * 
 * @since 0.5
 * @return array
 * 
 */
function mdp_get_default_options()
{
    $mdp_default_options = array('mdp_default_prefix' => __('Copy of', MPD_DOMAIN), 'mdp_default_tags_copy' => 'tags', 'mdp_default_featured_image' => 'feat', 'mdp_copy_content_images' => 'content-image', 'meta_box_show_radio' => 'all');
    $mpd_post_types = get_post_types();
    $post_types_to_ignore = mpd_get_post_types_to_ignore();
    foreach ($mpd_post_types as $mpd_post_type) {
        if (!in_array($mpd_post_type, $post_types_to_ignore)) {
            $mdp_default_options['meta_box_post_type_selector_' . $mpd_post_type] = $mpd_post_type;
        }
    }
    $mdp_default_options = apply_filters('mdp_default_options', $mdp_default_options);
    return $mdp_default_options;
}
/**
 * Get a list of post types the user wants to show the MPD Metabox (if the 'Some Post Types' option was selected in settings)
 *
 * This function checks the settings for MPD and returns all the option values that are associated with post types
 *
 * @since 0.4
 * @return array Containing post types for use with MPD Metabox
 *
*/
function mpd_get_some_postypes_to_show_options()
{
    $post_types = array();
    $options = get_option('mdp_settings');
    $post_types_to_ignore = mpd_get_post_types_to_ignore();
    foreach ($options as $key => $value) {
        //Find all the options in the options array that refer to post type display and assign them to a new key => value array
        if (substr($key, 0, 28) == "meta_box_post_type_selector_" && !in_array($value, $post_types_to_ignore)) {
            $post_types[] = $value;
        }
    }
    return $post_types;
}
/**
 * 
 * Register the settings for MPD
 * 
 * @since 0.4
 * @return null
 * 
 */
function mdp_settings_init()
{
    register_setting(MPD_SETTING_PAGE, 'mdp_settings');
    do_action('mdp_start_plugin_setting_page');
    add_settings_section(MPD_SETTING_SECTION, '<h2>' . __('Multisite Post Duplicator Settings Page' . '</h2>', MPD_DOMAIN), 'mdp_settings_section_callback', MPD_SETTING_PAGE);
    mpd_settings_field('meta_box_show_radio', __('What Post Types you want to show the MPD Meta Box?', MPD_DOMAIN), 'meta_box_show_radio_render');
    $mpd_post_types = get_post_types();
    $loopcount = 1;
    $post_types_to_ignore = mpd_get_post_types_to_ignore();
    foreach ($mpd_post_types as $mpd_post_type) {
        if (!in_array($mpd_post_type, $post_types_to_ignore)) {
            mpd_settings_field('meta_box_post_type_selector_' . $mpd_post_type, $loopcount == 1 ? __("Select post types to show the MPD Meta Box on", MPD_DOMAIN) : "", 'meta_box_post_type_selector_render', array('mdpposttype' => $mpd_post_type));
            $loopcount++;
        }
    }
    mpd_settings_field('mdp_default_prefix', __('Default Prefix', MPD_DOMAIN), 'mdp_default_prefix_render');
    mpd_settings_field('mdp_default_tags_copy', __('Copy post tags when duplicating?', MPD_DOMAIN), 'mdp_default_tags_copy_render');
    mpd_settings_field('mdp_default_featured_image', __('Copy featured image when duplicating?', MPD_DOMAIN), 'mdp_default_feat_image_copy_render');
    mpd_settings_field('mdp_copy_content_images', __('Copy post content images to destination media library?', MPD_DOMAIN), 'mdp_copy_content_image_render');
    do_action('mdp_end_plugin_setting_page');
}
/**
 *
 * This is the markup to display in the Multisite Post Duplicator Tools page
 * @since 0.1
 * 
 */
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_post_obj = mpd_duplicate_over_multisite($mdp_PostID, $mdp_NewBlog, $mdp_PostType, $mdp_userID, $mdp_prefix, $mdp_postStatus);
        $success = true;
    }
    $post_types = get_post_types();
    $post_types_to_ignore = mpd_get_post_types_to_ignore();
    ob_start();
    ?>

	<div class="wrap">

    	<h2><?php 
    _e('Multisite Post Duplicator', MPD_DOMAIN);
    ?>
</h2>

    	<?php 
    if (!is_multisite()) {
        ?>

    		<h2><?php 
        _e('Attention!', MPD_DOMAIN);
        ?>
</h2>

    		<p><?php 
        _e('At the moment this plugin is solely for funtioning on a mulitisite. It appears this site doees not have multisite enabled', MPD_DOMAIN);
        ?>
</p>
			
			<?php 
        return;
        ?>

		<?php 
    }
    ?>

    	<?php 
    if ($success) {
        ?>

    		<div class="updated">

    			<p><?php 
        _e('Congratulations. The page/post was duplicated successfully.', MPD_DOMAIN);
        ?>
 <a href="<?php 
        echo $new_post_obj['edit_url'];
        ?>
"><?php 
        _e('Edit this post', MPD_DOMAIN);
        ?>
</a></p>

    		</div>

		<?php 
    }
    ?>

    	<form id="thefirstform" action="<?php 
    echo $_SERVER['REQUEST_URI'];
    ?>
" method="post">

    		<div class="metabox">

    			<h2><?php 
    _e('Options', MPD_DOMAIN);
    ?>
</h2>

    			<p><?php 
    _e('Select your preferences for the duplication.', MPD_DOMAIN);
    ?>
</p>

    			<h3><?php 
    _e('Select the status of the new post that will be created.', MPD_DOMAIN);
    ?>
</h3>

    			<?php 
    $post_statuses = get_post_statuses();
    ?>

    			<?php 
    foreach ($post_statuses as $post_status_key => $post_status_value) {
        ?>

    				<input type="radio" name="mpd-post-status" value="<?php 
        echo $post_status_key;
        ?>
" <?php 
        echo $post_status_key == 'draft' ? 'checked' : '';
        ?>
/><?php 
        echo $post_status_value;
        ?>


    			<?php 
    }
    ?>

    			<h3><?php 
    _e('Select a prefix, if any, for the new post/page to be created', MPD_DOMAIN);
    ?>
:</h3>
				
    			<input type="text" name="mdp-prefix" value="<?php 
    echo mpd_get_prefix();
    ?>
"/>
    		
			</div>

			<div class="metabox">

				<h2><?php 
    _e('Process the duplication', MPD_DOMAIN);
    ?>
</h2>

	    		<h3>1. <?php 
    _e('Select the post type of the post you want to duplicate', MPD_DOMAIN);
    ?>
</h3>
	    		
	    		<input type="hidden" name="action" value="add_foobar">

		    	<select name="el0" class="el0" style="width:300px;">

		    		<option></option>

		    		<option value="any" > - <?php 
    _e('All Post Types', MPD_DOMAIN);
    ?>
 -</option>

		    		<?php 
    foreach ($post_types as $post_type) {
        ?>

		    			<?php 
        if (!in_array($post_type, $post_types_to_ignore)) {
            ?>

			    			<option value="<?php 
            echo $post_type;
            ?>
">

			    				<?php 
            echo ucfirst($post_type);
            ?>

			    			</option>
		    			
		    			<?php 
        }
        ?>

					<?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 
}