static function import() { $did_import_old_team = false; if (isset($_GET['import']) && $_GET['import'] == 'true') { OurTeam::import_old_team(); $did_import_old_team = true; } if (OurTeam::has_old_team_table()): ?> <h2>Team Directory Import</h2> <p> This tool is provided to import team from an older version of this plugin. This will copy old team members over to the new format, but it is advised that you backup your database before proceeding. Chances are you won't need it, but it's always better to be safe than sorry! WordPress provides some <a href="https://codex.wordpress.org/Backing_Up_Your_Database" target="_blank">instructions</a> on how to backup your database. </p> <p> Once you're ready to proceed, simply use the button below to import old team members to the newer version of the plugin. </p> <p> <a href="<?php echo get_admin_url(); ?>edit.php?post_type=team&page=team-directory-import&import=true" class="button button-primary">Import Old Team</a> </p> <?php else: ?> <?php if ($did_import_old_team): ?> <div class="updated"> <p> Old team was successfully imported! You can <a href="<?php echo get_admin_url(); ?>edit.php?post_type=team">view all team here</a>. </p> </div> <?php else: ?> <p> It doesn't look like you have any team members from an older version of the plugin. You're good to go! </p> <?php endif; ?> <?php endif; }
static function import_old_team() { global $wpdb; $old_categories_table = $wpdb->prefix . 'our_team_categories'; $old_our_team_table = $wpdb->prefix . 'our_team'; $old_templates_table = TEAM_TEMPLATES; # # Copy old categories over first # $old_team_categories_sql = " SELECT cat_id, name FROM $old_categories_table "; $old_team_categories = $wpdb->get_results($old_team_categories_sql); foreach ($old_team_categories as $category) { wp_insert_term($category->name, 'team_category'); } # # Now copy old team members over # $old_team = OurTeam::get_old_team(); foreach ($old_team as $team) { $new_team_array = array( 'post_title' => $team->name, 'post_content' => $team->bio, 'post_type' => 'team', 'post_status' => 'publish' ); $new_team_post_id = wp_insert_post($new_team_array); update_post_meta($new_team_post_id, 'position', $team->position); update_post_meta($new_team_post_id, 'email', $team->email_address); update_post_meta($new_team_post_id, 'phone_number', $team->phone_number); if (isset($team->category)) { $old_category_sql = " SELECT cat_id, name FROM $old_categories_table WHERE cat_id=$team->category "; $old_category = $wpdb->get_results($old_category_sql); $new_category = get_term_by('name', $old_category[0]->name, 'team_category'); wp_set_post_terms($new_team_post_id, array($new_category->term_id), 'team_category'); } if (isset($team->photo) && $team->photo != '') { $upload_dir = wp_upload_dir(); $upload_dir = $upload_dir['basedir']; $image_path = $upload_dir . '/team-photos/' . $team->photo; $filetype = wp_check_filetype($image_path); $attachment_id = wp_insert_attachment(array( 'post_title' => $team->photo, 'post_content' => '', 'post_status' => 'publish', 'post_mime_type' => $filetype['type'] ), $image_path, $new_team_post_id); set_post_thumbnail($new_team_post_id, $attachment_id); } } # # Now copy templates over # $old_html_template_sql = " SELECT template_code FROM $old_templates_table WHERE template_name='team_index_html' "; $old_html_template_results = $wpdb->get_results($old_html_template_sql); update_option('our_team_html_template', $old_html_template_results[0]->template_code); $old_css_template_sql = " SELECT template_code FROM $old_templates_table WHERE template_name='team_index_css' "; $old_css_template_results = $wpdb->get_results($old_css_template_sql); update_option('our_team_css_template', $old_css_template_results[0]->template_code); # # Now delete the old tables # $drop_tables_sql = " DROP TABLE $old_categories_table, $old_our_team_table, $old_templates_table "; $wpdb->get_results($drop_tables_sql); }
Author URI: https://illusivedesign.ca */ global $wpdb; $our_team_table = $wpdb->prefix . 'our_team'; define('OUR_TEAM_TABLE', $wpdb->prefix . 'our_team'); define('TEAM_TEMPLATES', $wpdb->prefix . 'our_team_templates'); define('STAFF_PHOTOS_DIRECTORY', WP_CONTENT_DIR . "/uploads/team-photos/"); require_once(dirname(__FILE__) . '/classes/team_settings.php'); TeamSettings::setupDefaults(); require_once(dirname(__FILE__) . '/classes/our_team.php'); require_once(dirname(__FILE__) . '/classes/our_team_shortcode.php'); require_once(dirname(__FILE__) . '/classes/our_team_admin.php'); OurTeam::register_post_types(); OurTeam::set_default_meta_fields_if_necessary(); OurTeamAdmin::register_admin_menu_items(); OurTeamShortcode::register_shortcode(); if (OurTeam::show_import_message()) { //OurTeamAdmin::register_import_old_team_message(); } register_activation_hook( __FILE__, array('OurTeam', 'set_default_templates_if_necessary')); ?>