public function update_post_type($post_id, $link, $post_type)
 {
     if ($post_type === 'idx_page') {
         global $wpdb;
         $wpdb->update($wpdb->prefix . "posts", array('post_name' => $link, 'post_type' => 'idx_page'), array('ID' => $post_id));
     } else {
         $post = get_post($post_id);
         $link = $post->post_name;
         set_post_type($post_id, $post_type);
     }
 }
 public function update_post_type($post_info)
 {
     $meta_keys = array('_agent_title' => '_employee_title', '_agent_license' => '_employee_license', '_agent_designations' => '_employee_designations', '_agent_phone' => '_employee_phone', '_agent_mobile' => '_employee_mobile', '_agent_email' => '_employee_email', '_agent_website' => '_employee_website', '_agent_address' => '_employee_address', '_agent_city' => '_employee_city', '_agent_state' => '_employee_state', '_agent_zip' => '_employee_zip', '_agent_facebook' => '_employee_facebook', '_agent_twitter' => '_employee_twitter', '_agent_linkedin' => '_employee_linkedin', '_agent_googleplus' => '_employee_googleplus', '_agent_pinterest' => '_employee_pinterest', '_agent_youtube' => '_employee_youtube', '_agent_instagram' => '_employee_instagram');
     foreach ($post_info as $post) {
         foreach ($meta_keys as $old_key => $new_key) {
             $old_value = get_post_meta($post->ID, $old_key, true);
             update_post_meta($post->ID, $new_key, $old_value);
         }
         set_post_type($post->ID, 'employee');
     }
 }
 /**
  * this method is called when the /plots url is hit using a POST method as defined in the register routes above
  * @param  [type]   $data    : the data in the post
  * @return [string] $new_data: geojson data served in response to the post - just the same posted data served back
  */
 function create_plot($data)
 {
     if (!empty($type) && $type !== $this->type) {
         return new WP_Error('json_post_invalid_type', __('Invalid post type'), array('status' => 400));
     }
     $retval = $this->insert_post($data);
     if (is_wp_error($retval)) {
         return $retval;
     }
     // convert to post type
     set_post_type($retval, 'plots');
     // add geojson meta data
     add_post_meta($retval, 'map_data', $data['plot'], true);
     // add the area type
     wp_set_object_terms($retval, $data['areatype'], 'area-type');
     // add the suggested use types
     $suggestedUses = explode(',', $data['suggestedUses']);
     wp_set_object_terms($retval, $suggestedUses, 'suggested-use');
     if (isset($data['imageId'])) {
         set_post_thumbnail($retval, $data['imageId']);
     }
     $data = (array) get_post($retval, 'view');
     // hack :-(
     $keys_to_remove = ['post_status', 'post_type', 'post_parent', 'post_link', 'post_format', 'post_slug', 'post_guid', 'post_menu_order', 'post_comment_status', 'post_ping_status', 'post_sticky', 'post_meta', 'post_date', 'post_modified', 'post_date_tz', 'post_date_gmt', 'post_modified_tz', 'post_modified_gmt', 'post_terms', 'post_author', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_content_filtered', 'guid', 'menu_order', 'post_mime_type', 'comment_count', 'filter'];
     if ($data['post_type'] === EDIBLE_POST_TYPE) {
         $data['geo_json'] = get_post_meta($data['ID'])['map_data'];
         foreach ($keys_to_remove as $key) {
             unset($data[$key]);
         }
     }
     if (has_post_thumbnail($data['ID'])) {
         $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($data['ID']));
     }
     // this is slighly complex to gather the terms into an array
     $suggestedUsesTerms = get_the_terms($data['ID'], 'suggested-use');
     $suggestedUses = array();
     if ($suggestedUsesTerms) {
         foreach ($suggestedUsesTerms as $key => $term) {
             $suggestedUses[] = $term->name;
         }
     }
     $suggestedUses = json_encode($suggestedUses);
     //n.b. PHP 5.2 and above
     // we should unpack the geojson as it's not properly stored. my bad but hopefully easy to fix..
     $new_data = array('id' => $data['ID'], 'title' => $data['post_title'], 'content' => $data['post_content'], 'excerpt' => $data['post_excerpt'], 'geo_json' => $data['geo_json'], 'area_type' => get_the_terms($data['ID'], 'area-type')[0]->name, 'suggested_uses' => $suggestedUses, 'image' => $thumb[0]);
     return $new_data;
 }
Esempio n. 4
0
 function testGetPostsNew()
 {
     require_once 'php/timber-post-subclass.php';
     $term_id = $this->factory->term->create();
     $posts = array();
     $posts[] = $this->factory->post->create();
     $posts[] = $this->factory->post->create();
     $posts[] = $this->factory->post->create();
     foreach ($posts as $post_id) {
         set_post_type($post_id, 'page');
         wp_set_object_terms($post_id, $term_id, 'post_tag', true);
     }
     $term = new TimberTerm($term_id);
     $gotten_posts = $term->get_posts('post_type=page');
     $this->assertEquals(count($posts), count($gotten_posts));
     $gotten_posts = $term->get_posts('post_type=page', 'TimberPostSubclass');
     $this->assertEquals(count($posts), count($gotten_posts));
     $this->assertEquals($gotten_posts[0]->foo(), 'bar');
     $gotten_posts = $term->get_posts(array('post_type' => 'page'), 'TimberPostSubclass');
     $this->assertEquals($gotten_posts[0]->foo(), 'bar');
     $this->assertEquals(count($posts), count($gotten_posts));
 }
Esempio n. 5
0
function cp_convert_posts2Ads()
{
    global $wpdb, $app_version;
    echo '<div id="message2" class="updated" style="padding:10px 20px;">';
    // setup post conversion and stop if there are no valid ad listings in the posts table to convert
    $blogCatIDs = array();
    $blogCatIDs = cp_get_blog_cat_ids_array();
    // get all posts not in blog cats for quick check
    $args = array('category__not_in' => $blogCatIDs, 'post_status' => 'any', 'numberposts' => 10);
    $theposts = get_posts($args);
    if (count($theposts) < 1) {
        wp_die('<h3>Migration script error</h3><p>Process did not run. No ad listings were found. You only have blog posts or your blog parent category ID is incorrect.</p>');
    }
    // convert all the NON-BLOG categories to be part of the new ad_cat taxonomy
    echo '<p>Converting ad categories.........</p>';
    // get all category ids
    $cat_ids = get_all_category_ids();
    $cat_count_total = count($cat_ids);
    echo '<ul>';
    $cat_count = 0;
    foreach ($cat_ids as $cat_id) {
        // only move categories not belonging to the blog cats or blog sub cats
        if (!in_array($cat_id, $blogCatIDs)) {
            $wpdb->update($wpdb->term_taxonomy, array('taxonomy' => APP_TAX_CAT), array('term_id' => $cat_id));
            $thisCat = get_category($cat_id);
            echo '<li style="color:#009900"><strong>' . $thisCat->name . '</strong> (ID:' . $cat_id . ')' . ' category has been moved</li>';
            $cat_count++;
        } else {
            $thisCat = get_category($cat_id);
            echo '<li><strong>' . $thisCat->name . '</strong> (ID:' . $cat_id . ')' . ' category has been skipped</li>';
        }
    }
    echo '</ul>';
    //convert all the NON-BLOG posts to be part of the new "ad_listing" taxonomy
    echo '<br /><p><strong>Converting posts........</strong></p>';
    $newTagsSummary = array();
    $post_count = 0;
    $ad_count = 0;
    $tag_count = 0;
    echo '<ul>';
    // get all the posts
    $args = array('post_status' => 'any', 'numberposts' => -1);
    $theposts = get_posts($args);
    foreach ($theposts as $post) {
        setup_postdata($post);
        // get the post terms
        $oldTags = wp_get_post_terms($post->ID);
        $newTags = array();
        // get the cat object array for the post
        $post_cats = get_the_category($post->ID);
        // grab the first cat id found
        $cat_id = $post_cats[0]->cat_ID;
        //check if the post is in a blog category
        if (!in_array($cat_id, $blogCatIDs)) {
            // if yes, then first see if it has any tags
            if (!empty($oldTags)) {
                foreach ($oldTags as $thetag) {
                    $newTags[] = $thetag->name;
                    $newTagsSummary[] = '<li style="color:#009900"><strong>"' . $thetag->name . '"</strong> tag has been copied</li>';
                    $tag_count++;
                }
            }
            // copy the tag array over if it's not empty
            if (!empty($newTags)) {
                wp_set_post_terms($post->ID, $newTags, APP_TAX_TAG);
            }
            //now change the post to an ad
            set_post_type($post->ID, APP_POST_TYPE);
            echo '<li style="color:#009900"><strong>"' . $post->post_title . '"</strong> (ID:' . $post->ID . ') post was converted</li>';
            $ad_count++;
            // not an ad so must be a blog post
        } else {
            // see if it has tags since we still want to echo them not moved
            if (!empty($oldTags)) {
                foreach ($oldTags as $thetag) {
                    $newTags[] = $thetag->name;
                    $newTagsSummary[] = '<li><strong>"' . $thetag->name . '"</strong> tag has been skipped</li>';
                    //$tag_count++;
                }
            }
            echo '<li><strong>"<a href="post.php?post=' . $post->ID . '&action=edit" target="_blank">' . $post->post_title . '</a>"</strong> (ID:' . $post->ID . ') post has been skipped (in blog or blog-sub category)</li>';
        }
        $post_count++;
    }
    echo '<br/><p><strong>Copying tags...........</strong></p>';
    // get the total count of tags
    $all_tags = get_tags();
    $tags_count_total = count($all_tags);
    // calculate the results
    $blog_cats_total = $cat_count_total - $cat_count;
    $blog_posts_total = $post_count - $ad_count;
    $blog_tags_total = $tags_count_total - $tag_count;
    // print out all the tags
    foreach ($newTagsSummary as $key => $value) {
        echo $value;
    }
    echo '</ul><br/>';
    echo '<h3>Migration Summary</h3>';
    echo '<p>Total categories converted: <strong>' . $cat_count . '/' . $cat_count_total . '</strong>  <small>(excluded ' . $blog_cats_total . ' blog categories)</small><br/>';
    echo 'Total posts converted: <strong>' . $ad_count . '/' . $post_count . '</strong>  <small>(excluded ' . $blog_posts_total . ' blog posts)</small><br/>';
    echo 'Total tags copied: <strong>' . $tag_count . '/' . $tags_count_total . '</strong>  <small>(excluded ' . $blog_tags_total . ' tags not assigned to ads)</small><br/>';
    echo '<br/><p><strong>The ads conversion utility has completed!</strong><br/><br/>Note: If for some reason an ad did not get converted, you can manually do it via the "Post Type" option on the edit post page.</p>';
    //reset the old version to current so this script doesn't appear again
    // update_option('cp_version_old', $app_version);
    ?>

	<form action="admin.php?page=settings" id="msgForm" method="post">
		<p class="submit btop">
			<input type="submit" value="Run Migration Script Again?" name="convert" />
		</p>
		<input type="hidden" value="convertToCustomPostType" name="submitted" />
	</form>

	<p><strong>IMPORTANT: </strong>If you navigate away from this page, you will no longer be able to access this script. If you wish to run it again, open another browser tab and make your changes there first. Then come back and push the above button and the script will re-run.</p>

	<?php 
    echo '</div>';
}
 function timetable_ajax_events_settings_save()
 {
     $timetable_events_settings = get_option("timetable_events_settings");
     $slug_old = $timetable_events_settings["slug"];
     $timetable_slug_old = $timetable_events_settings["slug"];
     $timetable_events_settings["slug"] = !empty($_POST["events_slug"]) ? $_POST["events_slug"] : __("events", "timetable");
     $timetable_events_settings["label_singular"] = !empty($_POST["events_label_singular"]) ? $_POST["events_label_singular"] : __("Event", "timetable");
     $timetable_events_settings["label_plural"] = !empty($_POST["events_label_plural"]) ? $_POST["events_label_plural"] : __("Events", "timetable");
     if (update_option("timetable_events_settings", $timetable_events_settings) && $timetable_slug_old != $_POST["events_slug"]) {
         require_once "post-type-events.php";
         $events = get_posts(array('post_type' => $slug_old, 'posts_per_page' => -1));
         foreach ($events as $event) {
             set_post_type($event->ID, $timetable_events_settings["slug"]);
         }
         //delete rewrite rules, they will be regenerated automatically by WP on next request
         delete_option('rewrite_rules');
     }
     exit;
 }
Esempio n. 7
0
function bulk_convert_posts()
{
    // check for invalid post type choices
    if ($_POST['new_post_type'] == -1 || $_POST['old_post_type'] == -1) {
        echo '<p class="error">' . __('Could not convert posts. One of the post types was not set.', 'convert-post-types') . '</p>';
        return;
    }
    if (!post_type_exists($_POST['new_post_type']) || !post_type_exists($_POST['old_post_type'])) {
        echo '<p class="error">' . __('Could not convert posts. One of the selected post types does not exist.', 'convert-post-types') . '</p>';
        return;
    }
    $query = array('posts_per_page' => -1, 'post_status' => 'any', 'post_type' => $_POST['old_post_type']);
    if (!empty($_POST['convert_cat']) && $_POST['convert_cat'] > 1) {
        $query['cat'] = $_POST['convert_cat'];
    }
    if (!empty($_POST['page_parent']) && $_POST['page_parent'] > 0) {
        $query['post_parent'] = $_POST['page_parent'];
    }
    $items = get_posts($query);
    if (!is_array($items)) {
        echo '<p class="error">' . __('Could not find any posts matching your criteria.', 'convert-post-types') . '</p>';
        return;
    }
    global $wp_taxonomies;
    foreach ($items as $post) {
        // Update the post into the database
        $update['ID'] = $post->ID;
        if (!($new_post_type_object = get_post_type_object($_POST['new_post_type']))) {
            echo '<p class="error">' . sprintf(__('Could not convert post #%d. %s', 'convert-post-types'), $post->ID, _('The new post type was not valid.')) . '</p>';
        } else {
            // handle post categories now; otherwise all posts will receive the default
            if ('post' == $new_post_type_object->name && isset($_POST['post_category']) && !empty($_POST['post_category'])) {
                wp_set_post_terms($post->ID, $_POST['post_category'], 'post_category', false);
            }
            set_post_type($post->ID, $new_post_type_object->name);
            // WPML support. Thanks to Jenny Beaumont! http://www.jennybeaumont.com/post-type-switcher-wpml-fix/
            if (function_exists('icl_object_id')) {
                // adjust field 'element_type' in table 'wp_icl_translations'
                // from 'post_OLDNAME' to 'post_NEWNAME'
                // the post_id you look for is in column: 'element_id'
                if ($post->post_type == 'revision') {
                    if (is_array($post->ancestors)) {
                        $ID = $post->ancestors[0];
                    }
                } else {
                    $ID = $post->ID;
                }
                global $wpdb;
                $wpdb->update($wpdb->prefix . 'icl_translations', array('element_type' => 'post_' . $new_post_type_object->name), array('element_id' => $ID, 'element_type' => 'post_' . $post->post_type));
                $wpdb->print_error();
            }
        }
        // set new taxonomy terms
        foreach ($wp_taxonomies as $tax) {
            // hierarchical custom taxonomies
            if (isset($_POST['tax_input'][$tax->name]) && !empty($_POST['tax_input'][$tax->name]) && is_array($_POST['tax_input'][$tax->name])) {
                wp_set_post_terms($post->ID, $_POST['tax_input'][$tax->name], $tax->name, false);
                echo '<p class="msg">' . sprintf(__('Set %s to %s', 'convert-post-types'), $tax->label, $term->{$name}) . '</p>';
            }
            // all flat taxonomies
            if (isset($_POST[$tax->name]) && !empty($_POST[$tax->name]) && 'post_category' != $tax->name) {
                wp_set_post_terms($post->ID, $_POST[$tax->name], $tax->name, false);
                if ('post_category' == $tax->name) {
                    echo '<p class="msg">' . sprintf(__('Set %s to %s', 'convert-post-types'), $tax->label, join(', ', $_POST[$tax->name])) . '</p>';
                } else {
                    echo '<p class="msg">' . sprintf(__('Set %s to %s', 'convert-post-types'), $tax->label, $_POST[$tax->name]) . '</p>';
                }
            }
        }
    }
    echo '<div class="updated"><p><strong>' . __('Posts converted.', 'convert-post-types') . '</strong></p></div>';
}
 public function update_settings()
 {
     $preload = $_POST['preload'];
     $postType = $_POST['postType'];
     $settings = CubePortfolioMain::$settings;
     if ($settings['postType'] !== $postType) {
         if (post_type_exists($postType)) {
             echo 0;
             exit;
         }
         $query = new WP_Query(array('post_type' => $settings['postType'], 'posts_per_page' => -1));
         $postTypesOldArray = array();
         if ($query->have_posts()) {
             while ($query->have_posts()) {
                 $query->the_post();
                 $id = get_the_ID();
                 $postTypesOldArray[] = get_permalink($id);
                 set_post_type($id, $postType);
             }
             // next time when the page is loaded flush the permalinks
             $settings['flush_rewrite_rules'] = true;
         }
         // update cbp items
         $this->update_items_postType($postTypesOldArray, $settings['postType'], $postType);
         // update taxonomy
         $this->wpdb->update('wp_term_taxonomy', array('taxonomy' => $postType . '_category'), array('taxonomy' => $settings['postType'] . '_category'));
         $settings['postType'] = $postType;
     }
     $settings['preload'] = $preload;
     update_option('cubeportfolio_settings', $settings);
     // send this message to frontend
     echo 1;
     exit;
 }
 /**
  * Runs at plugin init. Checks the plugin's version and does updates
  * as needed.
  */
 public function update_plugin_data()
 {
     // Get the stored plugin version. If the version is not set, this is a clean installation.
     // If the version differs from current version, the plugin has been updated and we'll
     // run an update if necessary.
     $plugin_version = get_option($this->plugin_name . '_plugin-version', false);
     if ($plugin_version == $this->version) {
         // Already at current version
         return false;
     } else {
         // The plugin was just updated. Update the version right away to prevent concurrency issues
         // with more than one thread running the updates at once.
         update_option($this->plugin_name . '_plugin-version', $this->version);
         if ($plugin_version === false) {
             // This is a clean installation, no need to run updates.
             /*
              * Exception: Because we added this update functionality only at version 0.5.5 of the plugin,
              * we need to make an exception for people running that version.
              *
              * This is hacky and will lead to some people running the update unnecessarily, but since
              * there are still only a small number of installs so far, it's better than not doing it.
              */
             if ($this->version == '0.5.5') {
                 $plugin_version = '0.5.4';
             } else {
                 return false;
             }
         }
         // Do the updates based on previous version
         if (version_compare($plugin_version, '0.5.5') < 0) {
             // Update product meta box and post type id for old products created before
             // the update.
             $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'product'));
             foreach ($posts as $post) {
                 if (get_post_meta($post->ID, 'wp_license_manager_product_meta', true) == '') {
                     $meta = array();
                     $meta['file_bucket'] = get_post_meta($post->ID, '_product_file_bucket', true);
                     $meta['file_name'] = get_post_meta($post->ID, '_product_file_name', true);
                     $meta['version'] = get_post_meta($post->ID, '_product_version', true);
                     $meta['tested'] = get_post_meta($post->ID, '_product_tested', true);
                     $meta['requires'] = get_post_meta($post->ID, '_product_requires', true);
                     $meta['updated'] = get_post_meta($post->ID, '_product_updated', true);
                     $meta['banner_low'] = get_post_meta($post->ID, '_product_banner_low', true);
                     $meta['banner_high'] = get_post_meta($post->ID, '_product_banner_high', true);
                     update_post_meta($post->ID, 'wp_license_manager_product_meta', $meta);
                 }
                 // Update post type to a better name
                 set_post_type($post->ID, 'wplm_product');
             }
         }
     }
 }
Esempio n. 10
0
/**
 * Change all achievements of one type to a new type.
 *
 * @since 1.4.0
 *
 * @param string $original_type Original achievement type.
 * @param string $new_type      New achievement type.
 */
function badgeos_update_achievements_achievement_types($original_type = '', $new_type = '')
{
    $items = get_posts(array('posts_per_page' => -1, 'post_status' => 'any', 'post_type' => $original_type, 'fields' => 'id'));
    foreach ($items as $item) {
        set_post_type($item->ID, $new_type);
    }
}
 /**
  * Set the post type on save_post but only when editing
  *
  * We do a bunch of sanity checks here, to make sure we're only changing the
  * post type when the user explicitly intends to.
  *
  * - Not during autosave
  * - Check nonce
  * - Check user capabilities
  * - Check $_POST input name
  * - Check if revision or current post-type
  * - Check new post-type exists
  * - Check that user can publish posts of new type
  *
  * @since 1.0.0
  *
  * @param  int     $post_id
  * @param  object  $post
  *
  * @return If any number of condtions are met
  */
 public function save_post($post_id, $post)
 {
     // Post type information.
     $post_type = $_REQUEST['pts_post_type'];
     $post_type_object = get_post_type_object($post_type);
     // Add nonce for security and authentication.
     $nonce_name = $_REQUEST['pts-nonce-select'];
     $nonce_action = 'post-type-selector';
     // Check if a nonce is set.
     if (!isset($nonce_name)) {
         return;
     }
     // Check if a nonce is valid.
     if (!wp_verify_nonce($nonce_name, $nonce_action)) {
         return;
     }
     // Check if the user has permissions to 'edit_post'.
     if (!current_user_can('edit_post', $post_id)) {
         return;
     }
     // Check if it's not an autosave.
     if (wp_is_post_autosave($post_id)) {
         return;
     }
     // Check if it's not a revision.
     if (wp_is_post_revision($post_id)) {
         return;
     }
     // Check if a post type is set.
     if (empty($post_type)) {
         return;
     }
     // Check if a post type object is set.
     if (empty($post_type_object)) {
         return;
     }
     // Check if it's not a revision.
     if (in_array($post->post_type, array($post_type, 'revision'), true)) {
         return;
     }
     // Check if the user has permissions to 'publish_posts'.
     if (!current_user_can($post_type_object->cap->publish_posts)) {
         return;
     }
     // Set the new post type.
     set_post_type($post_id, $post_type_object->name);
 }
 /**
  * Will upgrade data from old free plugin to pro plugin
  */
 public static function upgradeData()
 {
     $num_upgraded = 0;
     if (isset($_POST['upgradeEventsCalendar']) && check_admin_referer('upgradeEventsCalendar')) {
         /*
         				
         				TODO: migrate the following:
         				
         				* option "sp_events_calendar_options" needs to be renamed as TribeEvents::OPTIONNAME
         				* posts of type "sp_events" need to be moved to TribeEvents::POSTTYPE
         				* posts of type "sp_venue" need to be moved to TribeEvents::VENUE_POST_TYPE
         				* posts of type "sp_organizer" need to be moved to TribeEvents::ORGANIZER_POST_TYPE
         				* categories of type "sp_events_cat" need to be moved to TribeEvents::TAXONOMY
         				* options that saved using on/enabled/yes need to be set to 1 and off/disabled/no being 0
         				* update plugin meta for EVERY event post meta to replace on/enabled/yes with 1 and off/disabled/no to be 0
         */
         $posts = self::getLegacyEvents();
         // we don't want the old event category
         $eventCat = get_term_by('name', 'Events', 'category');
         // existing event cats
         $existingEventCats = (array) get_terms(TribeEvents::TAXONOMY, array('fields' => 'names'));
         // store potential new event cats;
         $newEventCats = array();
         // first create log needed new event categories
         foreach ($posts as $key => $post) {
             // we don't want the old Events category
             $cats = self::removeEventCat(get_the_category($post->ID), $eventCat);
             // see what new ones we need
             $newEventCats = self::mergeCatList($cats, $newEventCats);
             // store on the $post to keep from re-querying
             $posts[$key]->cats = self::getCatNames($cats);
         }
         // dedupe
         $newEventCats = array_unique($newEventCats);
         // let's create new events cats
         foreach ($newEventCats as $cat) {
             // leave alone existing ones
             if (in_array($cat, $existingEventCats)) {
                 continue;
             }
             // make 'em!
             wp_insert_term($cat, TribeEvents::TAXONOMY);
         }
         // now we know what we're in for
         $masterCats = get_terms(TribeEvents::TAXONOMY, array('hide_empty' => false));
         // let's convert those posts
         foreach ($posts as $post) {
             // new post_type sir
             set_post_type($post->ID, TribeEvents::POSTTYPE);
             // set new events cats. we stored the array above, remember?
             if (!empty($post->cats)) {
                 wp_set_object_terms($post->ID, $post->cats, TribeEvents::TAXONOMY);
             }
             self::convertVenue($post);
             // Translate the post's setting for google maps display
             self::translateGoogleMaps($post);
             $num_upgraded++;
         }
         if ($num_upgraded > 0) {
             self::$upgradeMessage = sprintf(__('You successfully migrated (%d) entries.', 'tribe-events-calendar'), $num_upgraded);
         }
     }
 }
 /**
  * Prepares sites to use the plugin during single or network-wide activation
  *
  * @since    1.0
  *
  * @param    bool    $network_wide
  */
 public function activate($network_wide)
 {
     global $wpdb;
     $contents = $wpdb->get_results("SELECT DISTINCT post_id\n\t\t\t\t   FROM {$wpdb->postmeta}\n\t\t\t\t  WHERE meta_key IN ('_wpml_content_type', '_wpmoly_content_type')\n\t\t\t\t    AND meta_value='movie'");
     foreach ($contents as $p) {
         set_post_type($p->post_id, 'movie');
         delete_post_meta($p->post_id, '_wpmoly_content_type', 'movie');
         delete_post_meta($p->post_id, '_wpml_content_type', 'movie');
     }
     self::register_post_type();
 }
Esempio n. 14
0
 /**
  * Set the post type on save_post but only when editing
  *
  * We do a bunch of sanity checks here, to make sure we're only changing the
  * post type when the user explicitly intends to.
  *
  * - Not during autosave
  * - Check nonce
  * - Check user capabilities
  * - Check $_POST input name
  * - Check if revision or current post-type
  * - Check new post-type exists
  * - Check that user can publish posts of new type
  *
  * @since PostTypeSwitcher (0.3)
  * @param int $post_id
  * @param object $post
  * @return If any number of condtions are met
  */
 public function save_post($post_id, $post)
 {
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     if (!isset($_REQUEST['pts-nonce-select'])) {
         return;
     }
     if (!wp_verify_nonce($_REQUEST['pts-nonce-select'], 'post-type-selector')) {
         return;
     }
     if (!current_user_can('edit_post', $post_id)) {
         return;
     }
     if (empty($_REQUEST['pts_post_type'])) {
         return;
     }
     if (in_array($post->post_type, array($_REQUEST['pts_post_type'], 'revision'))) {
         return;
     }
     if (!($new_post_type_object = get_post_type_object($_REQUEST['pts_post_type']))) {
         return;
     }
     if (!current_user_can($new_post_type_object->cap->publish_posts)) {
         return;
     }
     set_post_type($post_id, $new_post_type_object->name);
 }
Esempio n. 15
0
 function process_bulk_action()
 {
     global $wp_rewrite, $wpdb;
     if ('convert' === $this->current_action()) {
         $output = "<div id=\"viceversa-status\" class=\"updated\">\n            <input type=\"button\" class=\"viceversa-close-icon button-secondary\" title=\"Close\" value=\"x\" />";
         if (VICEVERSA_DEBUG) {
             $output .= "<strong>" . __('Debug Mode', 'vice-versa') . "</strong>\n";
         }
         switch ($_POST['p_type']) {
             case 'page':
                 $categories = array('ids' => array(), 'titles' => array());
                 $do_bulk = false;
                 foreach ($_POST['parents'] as $category) {
                     if ($category != "") {
                         $data = explode("|", $category);
                         $categories[$data[3]]['ids'] = array();
                         $categories[$data[3]]['titles'] = array();
                         if ($data[3] == 0) {
                             $do_bulk = true;
                         }
                     }
                 }
                 foreach ($_POST['parents'] as $category) {
                     if ($category != "") {
                         $data = explode("|", $category);
                         array_push($categories[$data[3]]['ids'], $data[0]);
                         array_push($categories[$data[3]]['titles'], $data[2]);
                     }
                 }
                 $output .= "<p>\n";
                 foreach ($_POST['post'] as $viceversa_page) {
                     $viceversa_data = explode("|", $viceversa_page);
                     $viceversa_url = site_url() . "/?p=" . $viceversa_data[0];
                     if ($do_bulk) {
                         $ids = $categories[0]['ids'];
                         $titles = $categories[0]['titles'];
                     } else {
                         $ids = $categories[$viceversa_data[0]]['ids'];
                         $titles = $categories[$viceversa_data[0]]['titles'];
                     }
                     $catlist = "";
                     if ($titles) {
                         foreach ($titles as $cat) {
                             $catlist .= $cat . ", ";
                         }
                     }
                     $catlist = trim($catlist, ', ') == "" ? get_cat_name(1) : trim($catlist, ', ');
                     $cat_array = count($ids) < 1 ? array(1) : $ids;
                     if (!VICEVERSA_DEBUG) {
                         $wpdb->update($wpdb->posts, array('guid' => $viceversa_url, 'post_parent' => $cat_array[0]), array('ID' => intval($viceversa_data[0])), array('%s', '%d'), array('%d'));
                         clean_page_cache(intval($viceversa_data[0]));
                         set_post_type(intval($viceversa_data[0]), 'post');
                         wp_set_post_categories(intval($viceversa_data[0]), $cat_array);
                     }
                     $new_permalink = get_permalink(intval($viceversa_data[0]));
                     $output .= sprintf(__('<strong>' . __('Page', 'vice-versa') . '</strong> #%s <code><a href="%s" target="_blank" title="' . __('New Permalink', 'vice-versa') . '">%s</a></code> ' . __('was successfully converted to a <strong>Post</strong> and assigned to category(s)', 'vice-versa') . ' <code>%s</code>. <a href="%s" target="_blank" title="' . __('New Permalink', 'vice-versa') . '">' . __('New Permalink', 'vice-versa') . '</a>', 'vice-versa'), $viceversa_data[0], $new_permalink, $viceversa_data[2], $catlist, $new_permalink) . "<br />\n";
                 }
                 if (!VICEVERSA_DEBUG) {
                     $wp_rewrite->flush_rules();
                 }
                 break;
             default:
                 $parents = array();
                 $do_bulk = false;
                 foreach ($_POST['parents'] as $parent) {
                     if ($parent != "") {
                         $data = explode("|", $parent);
                         if ($data[3] == 0) {
                             $do_bulk = true;
                         }
                         $parents[intval($data[3])] = $data[0] . "|" . $data[2];
                     }
                 }
                 $output .= "<p>\n";
                 if (!$_POST['post']) {
                     $output .= __('No items were selected. Please select items using the checkboxes.', 'vice-versa');
                 } else {
                     foreach ($_POST['post'] as $viceversa_post) {
                         $viceversa_data = explode("|", $viceversa_post);
                         $viceversa_url = site_url() . "/?page_id=" . $viceversa_data[0];
                         if ($do_bulk) {
                             $p = $parents[0];
                         } else {
                             $p = $parents[$viceversa_data[0]];
                         }
                         $parent = $p == "" ? "0|" . __('No Parent', 'vice-versa') . "" : $p;
                         $parent = explode("|", $parent);
                         if (!VICEVERSA_DEBUG) {
                             $wpdb->update($wpdb->posts, array('guid' => $viceversa_url, 'post_parent' => intval($parent[0])), array('ID' => intval($viceversa_data[0])), array('%s', '%d'), array('%d'));
                             clean_post_cache(intval($viceversa_data[0]));
                             set_post_type(intval($viceversa_data[0]), 'page');
                             wp_set_post_categories(intval($viceversa_data[0]), array(intval($parent[0])));
                         }
                         $permalink = get_permalink(intval($viceversa_data[0]));
                         $output .= sprintf(__('<strong>' . __('Post', 'vice-versa') . '</strong> #%s <code><a href="%s" target="_blank" title="' . __('New Permalink', 'vice-versa') . '">%s</a></code> ' . __('was successfully converted to a <strong>Page</strong> and assigned to parent', 'vice-versa') . ' #%s <code>%s</code>. <a href="%s" target="_blank" title="' . __('New Permalink', 'vice-versa') . '">' . __('New Permalink', 'vice-versa') . '</a>', 'vice-versa'), $viceversa_data[0], $permalink, $viceversa_data[2], $parent[0], $parent[1], $permalink) . "<br />\n";
                     }
                     if (!VICEVERSA_DEBUG) {
                         $wp_rewrite->flush_rules();
                     }
                 }
         }
         $output .= "</p></div>\n";
         define("VICEVERSA_STATUS", $output);
     }
     // $this->current_action
 }
                    $terms = get_the_terms($recipe->ID, $tag);
                    if ($terms !== false && !is_wp_error($terms)) {
                        $term_ids = array();
                        foreach ($terms as $term) {
                            $existing_term = term_exists($term->name, $tag);
                            $term_ids[] = (int) $existing_term['term_id'];
                        }
                        wp_set_object_terms($post->ID, $term_ids, $tag);
                    }
                }
                // Photo
                $photo_id = get_post_thumbnail_id($recipe->ID);
                if ($photo_id != '' && $photo_id != false) {
                    set_post_thumbnail($post->ID, $photo_id);
                }
                // Change the slug of the recipe so we don't have any collisions
                $update_slug = array('ID' => $recipe_id, 'post_name' => $recipe->post_name . '-recipe');
                wp_update_post($update_slug);
                // Change post content shortcode
                $update_content = array('ID' => $post_id, 'post_content' => preg_replace("/\\[ultimate-recipe\\s[^]]+]/", "[recipe]", $post->post_content));
                wp_update_post($update_content);
                // Move recipe to trash
                wp_trash_post($recipe->ID);
                // Switch post type to recipe
                set_post_type($post->ID, 'recipe');
                $migrate_result[] = array('recipe' => $recipe_id, 'migrated' => true);
            }
        }
    }
}
var_dump($migrate_result);
 function process_products()
 {
     $this->results = 0;
     $timeout = 600;
     if (!ini_get('safe_mode')) {
         set_time_limit($timeout);
     }
     global $wpdb;
     // weight unit in WPEC = pound, ounce, gram, kilogram
     // weight unit in WC = lbs, kg
     $weight_unit = get_option('woocommerce_weight_unit');
     if ($weight_unit) {
         $weight_unit = 'kg';
     }
     // dimension unit in WPEC = in, cm, meter
     // weight unit in WC = in, cm
     $dimension_unit = get_option('woocommerce_dimension_unit');
     if ($dimension_unit) {
         $dimension_unit = 'cm';
     }
     $count = $wpdb->get_var("SELECT count(*) FROM {$wpdb->posts} WHERE post_type = 'wpsc-product' AND post_parent = '0'");
     if ($count) {
         $products = $wpdb->get_results("SELECT ID,post_title FROM {$wpdb->posts} WHERE post_type = 'wpsc-product' AND post_parent = '0'");
         foreach ($products as $product) {
             $id = $product->ID;
             $title = $product->post_title;
             $meta = get_post_custom($product->ID);
             $meta_data = unserialize($meta['_wpsc_product_metadata'][0]);
             // product_url (external)
             if (!empty($meta_data['external_link'])) {
                 update_post_meta($id, 'product_url', $meta_data['external_link']);
                 $product_type = 'external';
             } else {
                 $product_type = 'simple';
             }
             // product_type : simple/grouped/external/variable
             wp_set_object_terms($id, $product_type, 'product_type');
             // regular_price
             if (isset($meta['_wpsc_price'][0])) {
                 update_post_meta($id, '_regular_price', $meta['_wpsc_price'][0]);
                 delete_post_meta($id, '_wpsc_price');
             }
             // sale_price
             if (isset($meta['_wpsc_special_price'][0]) && $meta['_wpsc_special_price'][0] > 0) {
                 update_post_meta($id, '_sale_price', $meta['_wpsc_special_price'][0]);
                 delete_post_meta($id, '_wpsc_special_price');
             }
             // price (regular_price/sale_price)
             if (isset($meta['_wpsc_special_price'][0]) && $meta['_wpsc_special_price'][0] > 0) {
                 update_post_meta($id, '_price', $meta['_wpsc_special_price'][0]);
             } else {
                 update_post_meta($id, '_price', $meta['_wpsc_price'][0]);
             }
             // sale_price_dates_from
             update_post_meta($id, '_sale_price_dates_from', '');
             // sale_price_dates_to
             update_post_meta($id, '_sale_price_dates_to', '');
             // visibility: visible
             update_post_meta($id, '_visibility', 'visible');
             // featured: yes / no
             $featured_ids = get_option('sticky_products');
             if (!is_array($featured_ids)) {
                 $featured_ids = array($featured_ids);
             }
             $featured = in_array($id, $featured_ids) ? 'yes' : 'no';
             update_post_meta($id, '_featured', $featured);
             // sku:
             if (isset($meta['_wpsc_sku'][0])) {
                 update_post_meta($id, '_sku', $meta['_wpsc_sku'][0]);
                 delete_post_meta($id, '_wpsc_sku');
             }
             // stock_status : instock / outofstock
             // manage_stock : yes / no
             // stock : external = 0
             // backorders : no
             if (isset($meta['_wpsc_stock'][0])) {
                 if ($meta['_wpsc_stock'][0] === '') {
                     update_post_meta($id, '_stock_status', 'instock');
                     update_post_meta($id, '_manage_stock', 'no');
                     update_post_meta($id, '_stock', '0');
                     update_post_meta($id, '_backorders', 'no');
                 } elseif ($meta['_wpsc_stock'][0] === '0') {
                     update_post_meta($id, '_stock_status', 'outofstock');
                     update_post_meta($id, '_manage_stock', 'yes');
                     update_post_meta($id, '_stock', '0');
                     update_post_meta($id, '_backorders', 'no');
                 } elseif ($meta['_wpsc_stock'][0] > 0) {
                     update_post_meta($id, '_stock_status', 'instock');
                     update_post_meta($id, '_manage_stock', 'yes');
                     update_post_meta($id, '_stock', $meta['_wpsc_stock'][0]);
                     update_post_meta($id, '_backorders', 'no');
                 }
             }
             // virtual (yes/no)
             update_post_meta($id, '_virtual', 'no');
             // downloadable (yes/no)
             // file_path (downloadable)
             $args = array('post_parent' => $id, 'post_type' => 'wpsc-product-file', 'post_status' => 'any', 'numberposts' => 1);
             $downloads = (array) get_posts($args);
             if (count($downloads)) {
                 update_post_meta($id, '_downloadable', 'yes');
                 update_post_meta($id, '_file_path', $downloads[0]->guid);
             }
             // weight
             if (isset($meta_data['weight']) && $meta_data['weight']) {
                 $old_weight = $meta_data['weight'];
                 $old_weight_unit = $meta_data['weight_unit'];
                 $new_weight = $this->convert_weight($old_weight, $old_weight_unit, $weight_unit);
                 update_post_meta($id, '_weight', $new_weight);
             }
             // length
             if (isset($meta_data['dimensions']['length']) && $meta_data['dimensions']['length']) {
                 $old_length = $meta_data['dimensions']['length'];
                 $old_length_unit = $meta_data['dimensions']['length_unit'];
                 $new_length = $this->convert_dimension($old_length, $old_length_unit, $dimension_unit);
                 update_post_meta($id, '_length', $new_length);
             }
             // width
             if (isset($meta_data['dimensions']['width']) && $meta_data['dimensions']['width']) {
                 $old_width = $meta_data['dimensions']['width'];
                 $old_width_unit = $meta_data['dimensions']['width_unit'];
                 $new_width = $this->convert_dimension($old_width, $old_width_unit, $dimension_unit);
                 update_post_meta($id, '_width', $new_width);
             }
             // height
             if (isset($meta_data['dimensions']['height']) && $meta_data['dimensions']['height']) {
                 $old_height = $meta_data['dimensions']['height'];
                 $old_height_unit = $meta_data['dimensions']['height_unit'];
                 $new_height = $this->convert_dimension($old_height, $old_height_unit, $dimension_unit);
                 update_post_meta($id, '_height', $new_height);
             }
             // tax_status
             update_post_meta($id, '_tax_status', 'taxable');
             // tax_class
             update_post_meta($id, '_tax_class', '');
             // per_product_shipping
             if ($product_type == 'simple' || $product_type == 'variable') {
                 if (isset($meta_data['shipping']['local']) && $meta_data['shipping']['local']) {
                     update_post_meta($id, 'per_product_shipping', $meta_data['shipping']['local']);
                 }
             }
             // auto-generate thumbnail if one doesn't exist
             if (!has_post_thumbnail($id)) {
                 printf('<p>' . __('Featured image does not exist. Auto-generating thumbnail for product.', 'woo_wpec') . '</p>', $title);
                 self::generate_thumbmail($id);
             }
             // convert post type
             if (set_post_type($id, 'product')) {
                 $this->results++;
                 printf('<p>' . __('<b>%s</b> product was converted', 'woo_wpec') . '</p>', $title);
             }
         }
     }
 }
 /**
  * Bulk Convert Posts (or Pages) to Movie.
  * 
  * @since    2.1.4
  * 
  * @param    array    List of Post IDs to update
  * 
  * @return   WP_Error|bool    True on success, WP_Error if any post was not updated
  */
 public static function bulk_convert_posts($post_ids)
 {
     $error = new WP_Error();
     if (!is_array($post_ids)) {
         $post_ids = array($post_ids);
     }
     foreach ($post_ids as $post_id) {
         $update = set_post_type($post_id, $post_type = 'movie');
         if (!$update) {
             $error->add($post_id, sprintf(__('Error update Post #%d post_type.', 'wpmovielibrary'), $post_id));
         }
     }
     if (!empty($error->errors)) {
         return $error;
     }
     return true;
 }
Esempio n. 19
0
/**
 * Converts post type between original and newly renamed.
 *
 * @since 1.1.0
 *
 * @param string $original_slug Original post type slug.
 * @param string $new_slug      New post type slug.
 */
function cptui_convert_post_type_posts($original_slug = '', $new_slug = '')
{
    $args = array('posts_per_page' => -1, 'post_type' => $original_slug);
    $convert = new WP_Query($args);
    if ($convert->have_posts()) {
        while ($convert->have_posts()) {
            $convert->the_post();
            set_post_type(get_the_ID(), $new_slug);
        }
    }
    cptui_delete_post_type($original_slug);
}
Esempio n. 20
0
function seamless_donations_donations_legacy_import()
{
    $donations_imported = get_option('dgx_donate_donations_legacy_import');
    if (!$donations_imported) {
        // we need to convert the posts of type dgx-donation to type donation (the hyphen doesn't
        // work for some of the UI elements
        $args = array('post_type' => 'dgx-donation', 'posts_per_page' => -1);
        $donation_array = get_posts($args);
        while ($donation_option = current($donation_array)) {
            set_post_type($donation_option->ID, 'donation');
            next($donation_array);
        }
        // write out the legacy import completed flag
        $plugin_version = 'sd40';
        update_option('_dgx_donate_donations_legacy_import', $plugin_version);
    }
}
 function update_products()
 {
     $args = array('post_type' => $this->old_post_type, 'posts_per_page' => -1, 'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'trash'));
     $products = new WP_Query($args);
     $count = 0;
     // wp-e stores all the featured products in one place
     $featured_products = get_option('sticky_products', false);
     while ($products->have_posts()) {
         $products->the_post();
         $post_id = get_the_id();
         $count++;
         // ______ POST TYPE ______
         set_post_type($post_id, 'product');
         // ______________________________
         // get the serialized wpec product metadata
         $_wpsc_product_metadata = get_post_meta($post_id, '_wpsc_product_metadata', true);
         // ______ PRICE ______
         $regular_price = get_post_meta($post_id, '_wpsc_price', true);
         update_post_meta($post_id, '_regular_price', $regular_price);
         $sale_price = get_post_meta($post_id, '_wpsc_special_price', true);
         if ($sale_price != '' && $sale_price != $regular_price) {
             update_post_meta($post_id, '_price', $sale_price);
             update_post_meta($post_id, '_sale_price', $sale_price);
         } else {
             update_post_meta($post_id, '_price', $regular_price);
         }
         // ______________________________
         // ______ INVENTORY ______
         $stock = get_post_meta($post_id, '_wpsc_stock', true);
         if ($stock != '') {
             $manage_stock = 'yes';
             $backorders = 'no';
             if ((int) $stock > 0) {
                 $stock_status = 'instock';
             } else {
                 $stock_status = 'outofstock';
             }
         } else {
             $manage_stock = 'no';
             $backorders = 'yes';
             $stock_status = 'instock';
         }
         // stock qty
         update_post_meta($post_id, '_stock', $stock);
         // stock status
         update_post_meta($post_id, '_stock_status', $stock_status);
         // manage stock
         update_post_meta($post_id, '_manage_stock', $manage_stock);
         // backorders
         update_post_meta($post_id, '_backorders', $backorders);
         // ______________________________
         // ______ PRODUCT TYPE AND VISIBILITY ______
         // setting all products to simple
         $product_type = 'simple';
         wp_set_object_terms($post_id, $product_type, 'product_type');
         if ($stock_status == 'instock') {
             $visibility = 'visible';
         } else {
             $visibility = 'hidden';
         }
         // visibility
         update_post_meta($post_id, '_visibility', $visibility);
         // ______________________________
         // ______ OTHER PRODUCT DATA ______
         // sku code
         $sku = get_post_meta($post_id, '_wpsc_sku', true);
         if ($sku == null) {
             // try the old name
             $sku = $_wpsc_product_metadata['_wpsc_sku'];
         }
         update_post_meta($post_id, '_sku', $sku);
         // tax status
         $tax_status = 'taxable';
         update_post_meta($post_id, '_tax_status', $sku);
         // tax class empty sets it to stndard
         $tax_class = '';
         update_post_meta($post_id, '_tax_class', $sku);
         // weight
         $weight = $_wpsc_product_metadata['weight'];
         update_post_meta($post_id, '_weight', $weight);
         /*
          * WPEC use to use ['_wpsc_dimensions'] but then changed to use ['dimensions']
          * some products may still have the old variable name
          */
         $dimensions = $_wpsc_product_metadata['dimensions'];
         if ($dimensions == null) {
             // try the old name
             $dimensions = $_wpsc_product_metadata['_wpsc_dimensions'];
         }
         // height
         $height = $dimensions['height'];
         update_post_meta($post_id, '_height', $height);
         //length
         $length = $dimensions['length'];
         update_post_meta($post_id, '_length', $length);
         //width
         $width = $dimensions['width'];
         update_post_meta($post_id, '_width', $width);
         /* woocommerce option update, weight unit and dimentions unit */
         if ($count == 1) {
             /*
              * wpec stores weight unit and dimentions on a per product basis
              * as i expect most shops will use the same values for all products we can just take a single product
              * and just use those values for the global values used store wide in woocommerce
              */
             $weight_unit = $_wpsc_product_metadata['weight_unit'];
             $dimentions_unit = $dimensions['height_unit'];
             if ($weight_unit == "pound" || $weight_unit == "ounce" || $weight_unit == "gram") {
                 $weight_unit = "lbs";
             } else {
                 $weight_unit = "kg";
             }
             if ($dimentions_unit == "cm" || $dimentions_unit == "meter") {
                 $dimentions_unit = "cm";
             } else {
                 $dimentions_unit = "in";
             }
             update_option('woocommerce_weight_unit', $weight_unit);
             update_option('woocommerce_dimension_unit', $dimentions_unit);
         }
         // featured?
         if (in_array($post_id, $featured_products)) {
             $featured = 'yes';
         } else {
             $featured = 'no';
         }
         update_post_meta($post_id, '_featured', $featured);
         // ______________________________
         // ______ PRODUCT IMAGES ______
         /*
          * if products have multiple images wpec puts those pictures into the post gallery
          * because of this those pictures don't need to be ammended and should still be working
          * we only need to update the featured image
          * wpec uses the first one in the galley as the product image so we just have to set that as 
          * the featured image
          */
         $args = array('post_type' => 'attachment', 'numberposts' => 1, 'post_status' => null, 'post_parent' => $post_id, 'post_mime_type' => 'image');
         $attachments = get_posts($args);
         if ($attachments) {
             foreach ($attachments as $attachment) {
                 set_post_thumbnail($post_id, $attachment->ID);
             }
         }
         // ______________________________
         // add product to log
         $this->log["products"][] = array("id" => $post_id, "title" => get_the_title(), "link" => "?post=" . $post_id . "&action=edit");
     }
 }
Esempio n. 22
0
function ht_g42up_options()
{
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    ob_start();
    echo "<div class='wrap'>";
    echo "<h2>" . __(' GovIntranet 4.2 upgrade') . "</h2>";
    if ($_REQUEST['action'] == "processimport") {
        global $wpdb;
        global $post;
        $need_to_know_news = new WP_Query(array('post_type' => 'news', 'post_status' => 'any', 'post_format' => 'post-format-status', 'posts_per_page' => -1));
        if ($need_to_know_news->have_posts()) {
            while ($need_to_know_news->have_posts()) {
                $need_to_know_news->the_post();
                wp_remove_object_terms($post->ID, 'post-format-status', 'post_format');
                $newsterms = get_the_terms($post->ID, 'news-type');
                $new = '';
                if (count($newsterms) > 0) {
                    foreach ($newsterms as $nt) {
                        if ($nt->term_id == 0) {
                            continue;
                        }
                        $term_title = $nt->slug;
                        $term_desc = $nt->description;
                        unset($new);
                        if ($term_title && strtolower($term_title) != 'uncategorized') {
                            $termslug = "news-update-" . $term_title;
                            $new = term_exists($termslug, 'news-update-type');
                        }
                        if (!is_array($new)) {
                            $new = wp_insert_term($nt->name, 'news-update-type', array('slug' => $termslug, 'description' => $term_desc));
                            $newid = $new['term_id'];
                        } else {
                            $newid = $new['term_id'];
                        }
                        wp_set_object_terms($post->ID, $termslug, 'news-update-type', true);
                        wp_remove_object_terms($post->ID, $term_title, 'news-type');
                        sleep(0.1);
                    }
                }
                $newsterms = get_the_terms($post->ID, 'post_tag');
                $new = '';
                if (count($newsterms) > 0) {
                    foreach ($newsterms as $nt) {
                        $term_title = $nt->slug;
                        wp_remove_object_terms($post->ID, $term_title, 'post_tag');
                    }
                }
                $d = get_post_meta($post->ID, 'news_expiry_date', true);
                add_post_meta($post->ID, 'news_update_expiry_date', $d);
                $d = get_post_meta($post->ID, 'news_expiry_time', true);
                add_post_meta($post->ID, 'news_update_expiry_time', $d);
                $d = get_post_meta($post->ID, 'news_expiry_action', true);
                add_post_meta($post->ID, 'news_update_expiry_action', $d);
                $d = get_post_meta($post->ID, 'news_auto_expiry', true);
                add_post_meta($post->ID, 'news_update_auto_expiry', $d);
                delete_post_meta($post->ID, 'news_expiry_date');
                delete_post_meta($post->ID, 'news_expiry_time');
                delete_post_meta($post->ID, 'news_expiry_action');
                delete_post_meta($post->ID, 'news_auto_expiry');
                delete_post_meta($post->ID, 'related');
                delete_post_meta($post->ID, 'related_team');
                delete_post_meta($post->ID, 'keywords');
                delete_post_meta($post->ID, 'document_attachments');
                delete_post_meta($post->ID, '_news_expiry_date');
                delete_post_meta($post->ID, '_news_expiry_time');
                delete_post_meta($post->ID, '_news_expiry_action');
                delete_post_meta($post->ID, '_news_auto_expiry');
                delete_post_meta($post->ID, '_related');
                delete_post_meta($post->ID, '_related_team');
                delete_post_meta($post->ID, '_keywords');
                delete_post_meta($post->ID, '_document_attachments');
                if (set_post_type($post->ID, 'news-update')) {
                    echo "<BR> Upgraded " . esc_attr($post->post_title);
                } else {
                    echo "<BR> Skipped " . esc_attr($post->post_title);
                }
            }
        }
        echo "<h1>Finished</h1>";
    } else {
        echo "\n\t\t<p></p> \n\t\t <form method='post'>\n\t\t \t<p>This action will upgrade your need to know news posts to GovIntranet 4.2 news updates</p>\n\t\t \t<p>It is not essential to perform this upgrade. 'Need to know' news will still work.</p>\n\t\t \t<p>Only proceed if you wish to change 'Need to know' news to Updates.</p>\n\t\t\t<p><input type='submit' value='Upgrade now' class='button-primary' /></p>\n\t\t\t<input type='hidden' name='page' value='g42up' />\n\t\t\t<input type='hidden' name='action' value='processimport' />\n\t\t  </form><br />\n\t\t";
    }
    echo "</div>";
    ob_end_flush();
}
Esempio n. 23
0
	/**
	 * Handle the "Convert to [Post|Comic]" bulk action.
	 */
	public function bulk_edit() {
		if ( empty( $_REQUEST['post'] ) )
			return;

		$wp_list_table = _get_list_table( 'WP_Posts_List_Table' );
		$action = $wp_list_table->current_action();

		check_admin_referer( 'bulk-posts' );

		if ( 'post2comic' == $action || 'comic2post' == $action ) {
			if ( ! current_user_can( 'publish_posts' ) )
				wp_die( __( 'You are not allowed to make this change.', 'jetpack' ) );

			$post_ids = array_map( 'intval', $_REQUEST['post'] );

			$modified_count = 0;

			foreach ( $post_ids as $post_id ) {
				$destination_post_type = ( $action == 'post2comic' ) ? self::POST_TYPE : 'post';
				$origin_post_type = ( $destination_post_type == 'post' ) ? self::POST_TYPE : 'post';

				if ( current_user_can( 'edit_post', $post_id ) ) {
					$post = get_post( $post_id );

					// Only convert posts that are post => comic or comic => post.
					// (e.g., Ignore comic => comic, page => post, etc. )
					if ( $post->post_type != $destination_post_type && $post->post_type == $origin_post_type ) {
						$post_type_object = get_post_type_object( $destination_post_type );

						if ( current_user_can( $post_type_object->cap->publish_posts ) ) {
							set_post_type( $post_id, $destination_post_type );
							$modified_count++;
						}
					}
				}
			}

			$sendback = remove_query_arg( array( 'exported', 'untrashed', 'deleted', 'ids' ), wp_get_referer() );

			if ( ! $sendback )
				$sendback = add_query_arg( array( 'post_type', get_post_type() ), admin_url( 'edit.php' ) );

			$pagenum = $wp_list_table->get_pagenum();
			$sendback = add_query_arg( array( 'paged' => $pagenum, 'post_type_changed' => $modified_count ), $sendback );

			wp_safe_redirect( $sendback );
			exit();
		}
	}
 function process_acm_ad_conversion()
 {
     if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'process_acm_ad_conversion')) {
         wp_die();
     }
     global $wpdb;
     $acm_tags = ACM_Mods::other_acm_ad_tag_ids(array());
     foreach ($acm_tags as $ad) {
         $ad_height = $ad['url_vars']['height'];
         $ad_width = $ad['url_vars']['width'];
         $query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND ( post_name = %s OR post_title = %s )", 'acm-tag', sanitize_title($ad['tag']), $ad['tag']);
         $result = $wpdb->get_row($query, 'OBJECT');
         if ($result !== NULL) {
             $ad_code_query = $wpdb->prepare("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'tag' AND meta_value=%s LIMIT 500", $ad['tag']);
             $ad_code = $wpdb->get_row($ad_code_query, 'OBJECT');
             if (NULL !== $ad_code) {
                 update_post_meta($result->ID, 'dfp_ad_unit', get_post_meta($ad_code->post_id, 'tag_name', TRUE));
                 update_post_meta($result->ID, 'dfp_network_code', get_post_meta($ad_code->post_id, 'dfp_id', TRUE));
                 update_post_meta($result->ID, 'tag_id', get_post_meta($ad_code->post_id, 'tag_id', TRUE));
                 update_post_meta($result->ID, 'conditionals', get_post_meta($ad_code->post_id, 'conditionals', TRUE));
                 update_post_meta($result->ID, 'operator', get_post_meta($ad_code->post_id, 'operator', TRUE));
                 update_post_meta($result->ID, 'priority', get_post_meta($ad_code->post_id, 'priority', TRUE));
             }
             $wpdb->query("UPDATE {$wpdb->postmeta} SET meta_key = 'ad_height' WHERE meta_key = '_ad_height' AND post_id = {$result->ID}");
             // dfp_id (DFP Network Code)
             $wpdb->query("UPDATE {$wpdb->postmeta} SET meta_key = 'ad_width' WHERE meta_key = '_ad_width' AND post_id = {$result->ID}");
             // dfp_id (DFP Network Code)
             set_post_type($result->ID, 'ad_unit');
             update_post_meta($result->ID, 'admap_to_use', 0);
         }
     }
     $old_widgets = get_option('sidebars_widgets');
     $new_widgets = array();
     foreach ($old_widgets as $sidebar => $the_widgets) {
         if (is_array($the_widgets)) {
             $new_widgets[$sidebar] = array();
             if (!empty($the_widgets)) {
                 foreach ($the_widgets as $the_widget) {
                     $new_widgets[$sidebar][] = str_replace('acm_ad_zones', 'dfp_ad_unit', $the_widget);
                 }
             }
         } else {
             $new_widgets[$sidebar] = $the_widgets;
         }
     }
     update_option('sidebars_widgets', $new_widgets);
     // Update the widgets to the new widget
     $wpdb->query("UPDATE {$wpdb->options} SET option_name = 'widget_dfp_ad_unit' WHERE option_name = 'widget_acm_ad_zones';");
     wp_die('Successfully converted from ACM Mods to HBI Ad Manager');
 }