/**
 * 
 * Set the default options in WordPress on activation of the plugin
 * 
 * @since 0.5
 * 
 */
function mdp_plugin_activate()
{
    $type_of_activation = mpd_do_version_log();
    $mdp_default_options = mdp_get_default_options();
    $sites = mpd_wp_get_sites();
    foreach ($sites as $site) {
        $siteid = $site['blog_id'];
        switch_to_blog($siteid);
        if (!($options = get_option('mdp_settings'))) {
            $options = array();
            foreach ($mdp_default_options as $mdp_default_option => $option_value) {
                $options[$mdp_default_option] = $option_value;
            }
            update_option('mdp_settings', $options);
        } else {
            //Add default option for exsisting users with new checkboxes
            $options = get_option('mdp_settings');
            $options['mdp_copy_content_images'] = 'content-image';
            $options['mdp_default_tags_copy'] = 'tags';
            $options['mdp_default_featured_image'] = 'feat';
            $options['restrict_option_setting'] = 'none';
            $options['role_option_setting'] = 'Administrator';
            $options = apply_filters('mpd_activation_options', $options);
            update_option('mdp_settings', $options);
        }
        restore_current_blog();
    }
}
/**
 * @ignore
 */
function mpd_bulk_admin_script()
{
    if (is_multisite()) {
        $defaultoptions = mdp_get_default_options();
        $sites = mpd_wp_get_sites();
        $options = get_option('mdp_settings');
        $post_status = isset($_REQUEST["post_status"]) ? $_REQUEST["post_status"] : null;
        $active_mpd = apply_filters('mpd_is_active', true);
        if (isset($options['add_bulk_settings']) || $defaultoptions['add_bulk_settings'] == 'allow-batch' && !$options) {
            ?>

          <?php 
            if (!$post_status && $active_mpd) {
                ?>

            <script type="text/javascript">

              jQuery(document).ready(function() {

                <?php 
                foreach ($sites as $site) {
                    ?>

                  <?php 
                    $blog_details = get_blog_details($site['blog_id']);
                    ?>
 

                    <?php 
                    if ($site['blog_id'] != get_current_blog_id() && current_user_can_for_blog($site['blog_id'], mpd_get_required_cap())) {
                        ?>
 

                      jQuery('<option>').val("dup-<?php 
                        echo $site['blog_id'];
                        ?>
").text('<?php 
                        _e('Duplicate to ');
                        echo $blog_details->blogname;
                        ?>
').appendTo("select[name='action']");
                      jQuery('<option>').val("dup-<?php 
                        echo $site['blog_id'];
                        ?>
").text('<?php 
                        _e('Duplicate to ');
                        echo $blog_details->blogname;
                        ?>
').appendTo("select[name='action2']");

                    <?php 
                    }
                    ?>
                    
                  <?php 
                }
                ?>

              });
              
            </script>

          <?php 
            }
            ?>

        <?php 
        }
    }
}
/**
 * This function returns the current default prefix for the duplication.
 *
 * Returns either the core default value or the value of prefix saved by user in settings
 *
 * @since 0.5
 * @param none
 * @return string
*/
function mpd_get_prefix()
{
    if ($options = get_option('mdp_settings')) {
        $prefix = $options['mdp_default_prefix'];
    } else {
        $defaultOptions = mdp_get_default_options();
        $prefix = $defaultOptions['mdp_default_prefix'];
    }
    return $prefix;
}