/** * Detects if taxonomy terms were split and updates the corresponding taxonomy meta's accordingly. */ private function upgrade_21() { $taxonomies = get_option('wpseo_taxonomy_meta', array()); if (!empty($taxonomies)) { foreach ($taxonomies as $taxonomy => $tax_metas) { foreach ($tax_metas as $term_id => $tax_meta) { if (function_exists('wp_get_split_term') && ($new_term_id = wp_get_split_term($term_id, $taxonomy))) { $taxonomies[$taxonomy][$new_term_id] = $taxonomies[$taxonomy][$term_id]; unset($taxonomies[$taxonomy][$term_id]); } } } update_option('wpseo_taxonomy_meta', $taxonomies); } }
/** * Add action links to Stream drop row in admin list screen * * @filter wp_stream_action_links_{connector} * * @param array $links Previous links registered * @param Record $record Stream record * * @return array Action links */ public function action_links($links, $record) { if ($record->object_id && 'deleted' !== $record->action && ($term = get_term_by('term_taxonomy_id', $record->object_id, $record->context))) { if (!is_wp_error($term)) { $tax_obj = get_taxonomy($term->taxonomy); $tax_label = isset($tax_obj->labels->singular_name) ? $tax_obj->labels->singular_name : null; if (function_exists('wp_get_split_term')) { $term_id = wp_get_split_term($term->term_id, $term->taxonomy); } $term_id = empty($term_id) ? $term->term_id : $term_id; $links[sprintf(_x('Edit %s', 'Term singular name', 'stream'), $tax_label)] = get_edit_term_link($term_id, $term->taxonomy); $links[esc_html__('View', 'stream')] = wp_stream_is_vip() ? \wpcom_vip_get_term_link($term_id, $term->taxonomy) : get_term_link($term_id, $term->taxonomy); } } return $links; }
/** * Create Flowplayer Playlist HTML Output * * Retrieves a media files and settings to display a video. * * @since 1.3.0 * * @param array $atts Shortcode attributes */ private static function playlist_output($atts) { $playlist_id = $atts['playlist']; $playlist_options = get_option('playlist_' . absint($playlist_id)); // Check if old id is being used in the shortcode if (!$playlist_options && function_exists('wp_get_split_term')) { $new_term_id = wp_get_split_term(absint($playlist_id), 'playlist'); $playlist_options = get_option('playlist_' . absint($new_term_id)); if ($playlist_options) { $playlist_id = $new_term_id; } } $atts = Flowplayer5_Playlist::get_videos_by_id($playlist_id); if (!$atts) { return; } if (!$playlist_options) { $playlist_options['fp5-select-skin'] = 'minimalist'; } ob_start(); require 'views/partials/playlist.php'; $html = ob_get_clean(); return $html; }
function acf_get_valid_terms($terms = false, $taxonomy = 'category') { // bail early if function does not yet exist or if (!function_exists('wp_get_split_term') || empty($terms)) { return $terms; } // vars $is_array = is_array($terms); // force into array $terms = acf_force_type_array($terms); // force ints $terms = array_map('intval', $terms); // attempt to find new terms foreach ($terms as $i => $term_id) { $new_term_id = wp_get_split_term($term_id, $taxonomy); if ($new_term_id) { $terms[$i] = $new_term_id; } } // revert array if needed if (!$is_array) { $terms = $terms[0]; } // return return $terms; }
public static function maybe_get_split_term($old_term_id = '', $taxonomy = '') { $term_id = $old_term_id; if ('tag' == $taxonomy) { $taxonomy = 'post_tag'; } if (function_exists('wp_get_split_term') && ($new_term_id = wp_get_split_term($old_term_id, $taxonomy))) { $term_id = $new_term_id; } return $term_id; }
/** * Upgrade routine for 2.12.0 * @access private * @ignore */ function eventorganiser_021200_update() { global $wpdb; //Venues $meta_venue_ids = $wpdb->get_col("SELECT DISTINCT eo_venue_id FROM {$wpdb->eo_venuemeta} ORDER BY {$wpdb->eo_venuemeta}.meta_id"); if ($meta_venue_ids) { foreach ($meta_venue_ids as $old_venue_id) { $new_venue_id = wp_get_split_term($old_venue_id, 'event-venue'); //If $new_venue_id is false, the term ID never changed //If $new_venue_id is in $meta_venue_ids, then it already has data in the meta table if ($new_venue_id && !in_array($new_venue_id, $meta_venue_ids)) { $wpdb->update($wpdb->eo_venuemeta, array('eo_venue_id' => $new_venue_id), array('eo_venue_id' => $old_venue_id)); wp_cache_delete($new_venue_id, 'eo_venue_meta'); } } } //Categories $category_options = $wpdb->get_col("SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE 'eo-event-category\\_%'"); if ($category_options) { foreach ($category_options as $option_name) { $old_cat_id = (int) substr($option_name, 18); //18 = length of eo-event-category_ if ($old_cat_id) { $new_cat_id = wp_get_split_term($old_cat_id, 'event-category'); if ($new_cat_id && !get_option("eo-event-category_{$new_cat_id}")) { $value = get_option("eo-event-category_{$old_cat_id}"); update_option("eo-event-category_{$new_cat_id}", $value); delete_option("eo-event-category_{$old_cat_id}"); } } } } }
public function db_update() { $current_db_version = get_option('o2o_db_version'); if (version_compare($current_db_version, '1.1', '<')) { //convert all o2o_term_id meta_keys to be taxonomy specific to adjust for term splitting //and fix any previously split terms $connections = $this->get_connection_factory()->get_connections(); $taxonomy_map = array(); foreach ($connections as $connection) { if (method_exists($connection, 'get_taxonomy')) { foreach ($connection->to() as $post_type) { if (!isset($taxonomy_map[$post_type])) { $taxonomy_map[$post_type] = array(); } $taxonomy_map[$post_type][] = $connection->get_taxonomy(); } } } $wp_query = new WP_Query(array('fields' => 'ids', 'meta_query' => array(array('key' => 'o2o_term_id', 'compare' => 'EXISTS')), 'post_status' => 'any', 'post_type' => array_keys($taxonomy_map), 'posts_per_page' => 100, 'update_post_term_cache' => false, 'cache_results' => false, 'orderby' => 'ID')); foreach ($wp_query->posts as $post_id) { $term_id = get_post_meta($post_id, 'o2o_term_id', true); $post_type = get_post_type($post_id); if (isset($taxonomy_map[$post_type])) { foreach ($taxonomy_map[$post_type] as $taxonomy) { if (function_exists('wp_get_split_term') && false !== ($new_term_id = wp_get_split_term($term_id, $taxonomy))) { add_post_meta($post_id, 'o2o_term_id_' . $taxonomy, $new_term_id, true); } else { add_post_meta($post_id, 'o2o_term_id_' . $taxonomy, $term_id, true); } } } delete_post_meta($post_id, 'o2o_term_id'); } if ($wp_query->found_posts < 100) { update_option('o2o_db_version', '1.1'); } } }
/** * wpv_compat_get_split_term * * In WordPress 4.2, wp_get_split_term() was introduced to get the new term_id for a term that had been splitted * because its term_id was shared across several taxonomies * * @since 1.8.0 * * @param int $term_id The term_id to check * @param string $taxonomy The taxonomy to get the term_id from -* * @return bool|int The new term_id if it has changed and the function is available, false otherwise */ function wpv_compat_get_split_term( $term_id, $taxonomy ) { if ( function_exists( 'wp_get_split_term' ) ) { return wp_get_split_term( $term_id, $taxonomy ); } else { return false; } }
public function update_1_4_4() { if (!function_exists('wp_get_split_term')) { return; } // Update term ids for memberships (due to term splitting since WP 4.2). $memberships = get_posts(array('post_type' => 'ib_edu_membership', 'posts_per_page' => -1)); if (!empty($memberships)) { foreach ($memberships as $post) { $meta = get_post_meta($post->ID, '_ib_educator_membership', true); if (is_array($meta) && isset($meta['categories']) && is_array($meta['categories'])) { $update = false; foreach ($meta['categories'] as $key => $term_id) { $new_term_id = wp_get_split_term($term_id, 'ib_educator_category'); if ($new_term_id) { $meta['categories'][$key] = $new_term_id; $update = true; } } if ($update) { update_post_meta($post->ID, '_ib_educator_membership', $meta); } } } } }
/** * Split todocategories taxonomy options * * @static * @since 3.4 */ public static function split_taxonomies() { // update dashboard options $dashboard = get_option('CTDL_dashboard_settings', array()); if (is_array($dashboard['category'])) { foreach ($dashboard['category'] as $key => $value) { $new_term_id = wp_get_split_term($value, 'todocategories'); if ($new_term_id) { $dashboard['category'][$key] = $new_term_id; update_option('CTDL_dashboard_settings', $dashboard); } } } else { $new_term_id = wp_get_split_term($dashboard['category'], 'todocategories'); if ($new_term_id) { $dashboard['category'] = $new_term_id; update_option('CTDL_dashboard_settings', $dashboard); } } // update category options $visibility = get_option('CTDL_categories', array()); foreach ($visibility as $key => $value) { $key = substr($key, 9); $new_term_id = wp_get_split_term($key, 'todocategories'); if ($new_term_id) { $visibility['category_' . $new_term_id] = $value; update_option('CTDL_categories', $visibility); } } // update widget options $widgets = get_option('widget_cleverness-to-do-widget', array()); foreach ($widgets as &$widget) { $new_term_id = wp_get_split_term($widget['category'], 'todocategories'); if ($new_term_id) { $widget['category'] = $new_term_id; } } update_option('widget_cleverness-to-do-widget', $widgets); }
public function test_wp_get_split_term() { $found = wp_get_split_term($this->terms['t1']['term_id'], 'wptests_tax_3'); $this->assertEquals($this->terms['t3']['term_id'], $found); }
private static function upgrade_check() { $db_version = get_option('VSEO_Version', '0.0'); if ($db_version < 0.1) { Voce_Settings_API::GetInstance()->set_setting('robots-nodp', 'vseo-general', true); Voce_Settings_API::GetInstance()->set_setting('robots-noydir', 'vseo-general', true); } if ($db_version < 0.2 && function_exists('wp_get_split_term')) { $term_meta = $updated_term_meta = get_option('vseo_term_meta'); if (is_array($term_meta)) { foreach ($term_meta as $taxonomy_term => $term_data) { $tax_term_arr = explode('_', $taxonomy_term); if (is_array($tax_term_arr) && !empty($tax_term_arr)) { $term_id = array_pop($tax_term_arr); $taxonomy = implode('_', $tax_term_arr); $new_term_id = wp_get_split_term($term_id, $taxonomy); if ($new_term_id !== false) { unset($updated_term_meta[$taxonomy_term]); $updated_term_meta[sprintf('%s_%s', $taxonomy, $new_term_id)] = $term_data; } } } update_option('vseo_term_meta', $updated_term_meta); } } update_option('VSEO_Version', self::DB_VERSION); }
/** * Use this function to update BD references of a pre-split term ID to use the new term ID. * @since 3.6.4 */ public function process_term_split($old_id = 0) { global $wpdb; if (!$old_id) { return; } $new_id = wp_get_split_term($old_id, WPBDP_CATEGORY_TAX); if (!$new_id) { return; } // Fees. $fees = $wpdb->get_results("SELECT id, categories FROM {$wpdb->prefix}wpbdp_fees"); foreach ($fees as &$f) { $categories = unserialize($f->categories); if (isset($categories['all']) && $categories['all'] || empty($categories['categories'])) { continue; } $index = array_search($old_id, $categories['categories']); if ($index === false) { continue; } $categories['categories'][$index] = $new_id; $wpdb->update($wpdb->prefix . 'wpbdp_fees', array('categories' => serialize($categories)), array('id' => $f->id)); } // Listing fees. $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}wpbdp_listing_fees SET category_id = %d WHERE category_id = %d", $new_id, $old_id)); // Payments. $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}wpbdp_payments_items SET rel_id_1 = %d WHERE ( rel_id_1 = %d AND ( item_type = %s OR item_type = %s ) )", $new_id, $old_id, 'fee', 'recurring_fee')); // Category images. $imgs = get_option('wpbdp[category_images]', false); if (empty($imgs) || !is_array($imgs)) { return; } if (!empty($imgs['images']) && isset($imgs['images'][$old_id])) { $imgs['images'][$new_id] = $imgs['images'][$old_id]; unset($imgs['images'][$old_id]); } if (!empty($imgs['temp']) && isset($imgs['temp'][$old_id])) { $imgs['temp'][$new_id] = $imgs['temp'][$old_id]; unset($imgs['temp'][$old_id]); } update_option('wpbdp[category_images]', $imgs); }
/** * If the data was exported PRE-4.2, but then imported POST-4.2, then the term_id * this term-taxonomy refers to may be out-of-date so we need to update it. * see https://make.wordpress.org/core/2015/02/16/taxonomy-term-splitting-in-4-2-a-developer-guide/ * @param type $model_object_data * @return array new model object data */ protected function _handle_split_term_ids($model_object_data) { if (isset($model_object_data['term_id']) && isset($model_object_data['taxonomy']) && apply_filters('FHEE__EE_Import__handle_split_term_ids__function_exists', function_exists('wp_get_split_term'), $model_object_data)) { $new_term_id = wp_get_split_term($model_object_data['term_id'], $model_object_data['taxonomy']); if ($new_term_id) { $model_object_data['term_id'] = $new_term_id; } } return $model_object_data; }