/** * Post Expirator Activation/Upgrade */ function postexpirator_upgrade() { // Check for current version, if not exists, run activation $version = get_option('postexpiratorVersion'); if ($version === false) { //not installed, run default activation postexpirator_activate(); update_option('postexpiratorVersion', POSTEXPIRATOR_VERSION); } elseif ($version !== POSTEXPIRATOR_VERSION) { switch (POSTEXPIRATOR_VERSION) { case '1.6.1': update_option('postexpiratorVersion', POSTEXPIRATOR_VERSION); update_option('expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT); break; } } }
/** * Post Expirator Activation/Upgrade */ function postexpirator_upgrade() { // Check for current version, if not exists, run activation $version = get_option('postexpiratorVersion'); if ($version === false) { //not installed, run default activation postexpirator_activate(); update_option('postexpiratorVersion', POSTEXPIRATOR_VERSION); } else { if (version_compare($version, '1.6.1') == -1) { update_option('postexpiratorVersion', POSTEXPIRATOR_VERSION); update_option('expirationdateDefaultDate', POSTEXPIRATOR_EXPIREDEFAULT); } if (version_compare($version, '1.6.2') == -1) { update_option('postexpiratorVersion', POSTEXPIRATOR_VERSION); } if (version_compare($version, '2.0.0-rc1') == -1) { global $wpdb; // Schedule Events/Migrate Config $results = $wpdb->get_results($wpdb->prepare('select post_id, meta_value from ' . $wpdb->postmeta . ' as postmeta, ' . $wpdb->posts . ' as posts where postmeta.post_id = posts.ID AND postmeta.meta_key = %s AND postmeta.meta_value >= %d', 'expiration-date', time())); foreach ($results as $result) { wp_schedule_single_event($result->meta_value, 'postExpiratorExpire', array($result->post_id)); $opts = array(); $opts['id'] = $result->post_id; $posttype = get_post_type($result->post_id); if ($posttype == 'page') { $opts['expireType'] = strtolower(get_option('expirationdateExpiredPageStatus', 'Draft')); } else { $opts['expireType'] = strtolower(get_option('expirationdateExpiredPostStatus', 'Draft')); } $cat = get_post_meta($result->post_id, '_expiration-date-category', true); if (isset($cat) && !empty($cat)) { $opts['category'] = $cat; $opts['expireType'] = 'category'; } update_post_meta($result->post_id, '_expiration-date-options', $opts); } // update meta key to new format $wpdb->query($wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_key = %s WHERE meta_key = %s", '_expiration-date', 'expiration-date')); // migrate defaults $pagedefault = get_option('expirationdateExpiredPageStatus'); $postdefault = get_option('expirationdateExpiredPostStatus'); if ($pagedefault) { update_option('expirationdateDefaultsPage', array('expireType' => $pagedefault)); } if ($postdefault) { update_option('expirationdateDefaultsPost', array('expireType' => $postdefault)); } delete_option('expirationdateCronSchedule'); delete_option('expirationdateAutoEnabled'); delete_option('expirationdateExpiredPageStatus'); delete_option('expirationdateExpiredPostStatus'); update_option('postexpiratorVersion', POSTEXPIRATOR_VERSION); } if (version_compare($version, '2.0.1') == -1) { // Forgot to do this in 2.0.0 if (is_multisite()) { global $current_blog; wp_clear_scheduled_hook('expirationdate_delete_' . $current_blog->blog_id); } else { wp_clear_scheduled_hook('expirationdate_delete'); } update_option('postexpiratorVersion', POSTEXPIRATOR_VERSION); } if (version_compare($version, '2.1.0') == -1) { update_option('postexpiratorVersion', POSTEXPIRATOR_VERSION); } if (version_compare($version, '2.1.1') == -1) { update_option('postexpiratorVersion', POSTEXPIRATOR_VERSION); } } }
/** * Post Expirator Activation/Upgrade */ function postexpirator_upgrade() { // Check for current version, if not exists, run activation $version = get_option('postexpiratorVersion'); if ($version === false) { //not installed, run default activation postexpirator_activate(); update_option('postexpiratorVersion', POSTEXPIRATOR_VERSION); } }