private function processTaxonomy(&$taxonomy)
 {
     $currentTerms = get_terms($taxonomy->slug, array('hide_empty' => false));
     $done = false;
     while (!$done) {
         $deferred = 0;
         foreach ($taxonomy->terms as &$term) {
             if (!$term->done) {
                 $parentId = $this->parentId($term->term->parent, $taxonomy);
                 if ($parentId || $term->term->parent == 0) {
                     $existingTermId = $this->findExistingTerm($term, $currentTerms);
                     $args = array('description' => $term->term->description, 'parent' => $parentId, 'slug' => $term->term->slug, 'term_group' => $term->term->term_group, 'name' => $term->term->name);
                     if ($existingTermId > 0) {
                         $ret = wp_update_term($existingTermId, $taxonomy->slug, $args);
                         $term->id = $existingTermId;
                     } else {
                         $id = wp_insert_term($term->term->name, $taxonomy->slug, $args);
                         $term->id = $id['term_id'];
                     }
                     $term->done = true;
                 } else {
                     ++$deferred;
                 }
             }
             if ($deferred == 0) {
                 $done = true;
             }
         }
     }
 }
Exemple #2
0
 public function set($key, $value, $override = false)
 {
     if ($key !== "name" && $key !== "taxonomy") {
         $data = array($key => $value);
         wp_update_term($this->id["term_id"], $this->taxonomy, $data);
     }
 }
 /**
  * initialize_container - Initialiaze the PAIR containers if the associated
  * option is checked
  *
  * @param  {type} $option    the checkbox to evaluate
  * @param  {type} $oldValue  the oldvalue (should be false)
  * @param  {type} $_newValue the new checkbox value (should be true)
  * @return {type}            description
  */
 function initialize_container($force = false)
 {
     if (isset($_GET['settings-updated']) || $force) {
         $ldp_container_init = get_option('ldp_container_init', false);
         if ($ldp_container_init || $force) {
             //TODO: Initialize the PAIR containers
             $pair_terms = array('initiative' => array('label' => __('Initiative', 'wpldp'), 'rdftype' => 'pair:initiative'), 'organization' => array('label' => __('Organization', 'wpldp'), 'rdftype' => 'foaf:organization'), 'group' => array('label' => __('Group', 'wpldp'), 'rdftype' => 'foaf:group'), 'document' => array('label' => __('Document', 'wpldp'), 'rdftype' => 'foaf:document'), 'goodorservice' => array('label' => __('Good or Service', 'wpldp'), 'rdftype' => 'goodRelation:goodOrService'), 'artwork' => array('label' => __('Artwork', 'wpldp'), 'rdftype' => 'schema:artwork'), 'event' => array('label' => __('Event', 'wpldp'), 'rdftype' => 'schema:event'), 'place' => array('label' => __('Place', 'wpldp'), 'rdftype' => 'schema:place'), 'theme' => array('label' => __('Theme', 'wpldp'), 'rdftype' => 'pair:theme'), 'thesis' => array('label' => __('Thesis', 'wpldp'), 'rdftype' => 'pair:thesis'), 'person' => array('label' => __('Person', 'wpldp'), 'rdftype' => 'pair:person'));
             foreach ($pair_terms as $term => $properties) {
                 // Loop on the models files (or hardcoded array) and push them each as taxonomy term in the database
                 $model = file_get_contents(__DIR__ . '/models/' . $term . '.json');
                 $term_id = null;
                 if (!term_exists($term, 'ldp_container')) {
                     $new_term = wp_insert_term($properties['label'], 'ldp_container', array('slug' => $term, 'description' => sprintf(__('The %1$s object model', 'wpldp'), $term)));
                     $term_id = $new_term['term_id'];
                 } else {
                     $existing_term = get_term_by('slug', $term, 'ldp_container');
                     $updated_term = wp_update_term($existing_term->term_id, 'ldp_container', array('slug' => $term, 'description' => sprintf(__('The %1$s object model', 'wpldp'), $term)));
                     $term_id = $existing_term->term_id;
                 }
                 if (!empty($term_id)) {
                     $term_meta = get_option("ldp_container_{$term_id}");
                     if (!is_array($term_meta)) {
                         $term_meta = array();
                     }
                     $term_meta['ldp_rdf_type'] = $properties['rdftype'];
                     $term_meta['ldp_model'] = stripslashes_deep($model);
                     update_option("ldp_container_{$term_id}", $term_meta);
                 }
             }
         }
     }
 }
Exemple #4
0
function wp_insert_category($catarr)
{
    global $wpdb;
    extract($catarr, EXTR_SKIP);
    if (trim($cat_name) == '') {
        return 0;
    }
    $cat_ID = (int) $cat_ID;
    // Are we updating or creating?
    if (!empty($cat_ID)) {
        $update = true;
    } else {
        $update = false;
    }
    $name = $cat_name;
    $description = $category_description;
    $slug = $category_nicename;
    $parent = $category_parent;
    $parent = (int) $parent;
    if (empty($parent) || !category_exists($parent) || $cat_ID && cat_is_ancestor_of($cat_ID, $parent)) {
        $parent = 0;
    }
    $args = compact('name', 'slug', 'parent', 'description');
    if ($update) {
        $cat_ID = wp_update_term($cat_ID, 'category', $args);
    } else {
        $cat_ID = wp_insert_term($cat_name, 'category', $args);
    }
    if (is_wp_error($cat_ID)) {
        return 0;
    }
    return $cat_ID['term_id'];
}
	/**
	 * Handle tab logic
	 */
	public function handle()
	{
		// Actions
		add_action('admin_enqueue_scripts', array(&$this, 'action_admin_enqueue_scripts'));
		
		// Taxonomies
		$taxonomies = get_taxonomies(array(
			'hierarchical' => true
		), 'objects');
		$taxonomy_current = (isset($_GET['taxonomy'])  && isset($taxonomies[$_GET['taxonomy']])) ? $taxonomies[$_GET['taxonomy']] : current($taxonomies);
		
		// Terms hierarchy
		if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST) && wp_verify_nonce($_POST['jwbp-terms-reorganize-nonce'], 'jwbp-terms-reorganize')) {
			$terms_parents = $_POST['jwbp-term-parent'];
			
			foreach ($terms_parents as $index => $term_parent) {
				wp_update_term($index, $taxonomy_current->name, array(
					'parent' => $term_parent
				));
			}
			
			// Remove hierarchy from cache
			delete_option($taxonomy_current->name . '_children');
			
			// Add message to notify user of completion
			$this->add_message(sprintf(__('%s hierarchy successfully updated.', 'bulkpress'), $taxonomy_current->labels->singular_name));
		}
	}
Exemple #6
0
 function groundup_activation()
 {
     // Check to see if activation has already been run
     if (!get_option('groundup_activated') == 'activated') {
         add_option('groundup_activated', 'activated');
         // Remove default site description
         if (get_bloginfo('description') == 'Just another WordPress site') {
             update_option('blogdescription', '');
         }
         // Allow shortcodes in widgets
         add_filter('widget_text', 'shortcode_unautop');
         add_filter('widget_text', 'do_shortcode', 11);
         // Change Uploads folder to /media
         update_option('uploads_use_yearmonth_folders', 0);
         update_option('upload_path', 'media');
         update_option('upload_url_path', get_home_url() . '/media');
         // Pretty Permalinks
         update_option('category_base', '/site/');
         update_option('permalink_structure', '/%category%/%postname%/');
         // change start of week to Sunday
         update_option('start_of_week', 0);
         // Change default 'Uncategorized' to 'General'
         $category = get_term_by('id', '1', 'category');
         if ($category->name == 'Uncategorized') {
             $category->name = 'General';
             $category->slug = strtolower(str_replace('_', ' ', 'general'));
         }
         wp_update_term($category->term_id, 'category', array('slug' => $category->slug, 'name' => $category->name));
         // Disable Smilies
         update_option('use_smilies', 0);
         // Set default comment status to closed
         update_option('default_comment_status', 'closed');
         update_option('default_ping_status', 'closed');
         // Set Timezone
         $timezone = "America/New_York";
         //$timezone = "America/Chicago";
         //$timezone = "America/Denver";
         //$timezone = "America/Los_Angeles";
         update_option('timezone_string', $timezone);
         // Clean up widget settings that weren't set at installation to prevent unecessary queries
         add_option('widget_pages', array('_multiwidget' => 1));
         add_option('widget_calendar', array('_multiwidget' => 1));
         add_option('widget_tag_cloud', array('_multiwidget' => 1));
         add_option('widget_nav_menu', array('_multiwidget' => 1));
         // Update default media sizes - additional sizes are added through groundup_init
         update_option('thumbnail_size_w', 330);
         update_option('thumbnail_size_h', 330);
         update_option('thumbnail_crop', true);
         update_option('medium_size_w', 600);
         update_option('medium_size_h', 400);
         update_option('large_size_w', 1200);
         update_option('large_size_h', 800);
         update_option('embed_size_w', 1200);
         update_option('embed_size_h', 800);
         // Add default menus
         groundup_register_nav_menus(array('Primary', 'Secondary', 'Mobile', 'Footer'));
         groundup_create_nav_menus(array('Primary', 'Secondary', 'Mobile', 'Footer'));
     }
 }
function kws_rt_taxonomy_save()
{
    global $tag_ID;
    $a = array('description');
    foreach ($a as $v) {
        wp_update_term($tag_ID, $v, $_POST[$v]);
    }
}
 function update_object($term, $fields)
 {
     $fields = array_merge(array('taxonomy' => $this->taxonomy), $fields);
     if (is_object($term)) {
         $taxonomy = $term->taxonomy;
     }
     $term_id_pair = wp_update_term($term, $taxonomy, $fields);
     return $term_id_pair['term_id'];
 }
 public function test_update_term_is_synced()
 {
     $args = array('name' => 'Non Catégorisé', 'slug' => 'non-categorise');
     wp_update_term($this->term_object['term_id'], $this->taxonomy, $args);
     $this->client->do_sync();
     $terms = $this->get_terms();
     $server_terms = $this->server_replica_storage->get_terms($this->taxonomy);
     $this->assertEquals($terms, $server_terms);
 }
function ubik_quick_terms_description_save($term_id)
{
    $tax = get_taxonomy($_REQUEST['taxonomy']);
    if (current_filter() === 'edited_' . $tax->name && current_user_can($tax->cap->edit_terms)) {
        $description = filter_input(INPUT_POST, 'description', FILTER_SANITIZE_STRING);
        remove_action(current_filter(), __FUNCTION__);
        // Removing action to avoid recursion
        wp_update_term($term_id, $tax->name, array('description' => $description));
    }
}
/**
 * Install known types in WordPress.
 */
function wl_core_install_entity_type_data()
{
    // Ensure the custom type and the taxonomy are registered.
    wl_entity_type_register();
    wl_entity_type_taxonomy_register();
    // Set the taxonomy data.
    // Note: parent types must be defined before child types.
    // TODO: Manage both generic and custom fields as fields.
    $terms = array('thing' => array('label' => 'Thing', 'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.', 'css' => 'wl-thing', 'uri' => 'http://schema.org/Thing', 'same_as' => array('*'), 'custom_fields' => array(WL_CUSTOM_FIELD_SAME_AS => array('predicate' => 'http://schema.org/sameAs', 'type' => WL_DATA_TYPE_URI, 'export_type' => 'http://schema.org/Thing', 'constraints' => '', 'input_field' => 'sameas')), 'microdata_template' => '', 'templates' => array('subtitle' => '{{id}}')), 'creative-work' => array('label' => 'CreativeWork', 'description' => 'A creative work (or a Music Album).', 'parents' => array('thing'), 'css' => 'wl-creative-work', 'uri' => 'http://schema.org/CreativeWork', 'same_as' => array('http://schema.org/MusicAlbum', 'http://schema.org/Product'), 'custom_fields' => array(), 'microdata_template' => '', 'templates' => array('subtitle' => '{{id}}')), 'event' => array('label' => 'Event', 'description' => 'An event.', 'parents' => array('thing'), 'css' => 'wl-event', 'uri' => 'http://schema.org/Event', 'same_as' => array('http://dbpedia.org/ontology/Event'), 'custom_fields' => array(WL_CUSTOM_FIELD_CAL_DATE_START => array('predicate' => 'http://schema.org/startDate', 'type' => WL_DATA_TYPE_DATE, 'export_type' => 'xsd:date', 'constraints' => ''), WL_CUSTOM_FIELD_CAL_DATE_END => array('predicate' => 'http://schema.org/endDate', 'type' => WL_DATA_TYPE_DATE, 'export_type' => 'xsd:date', 'constraints' => ''), WL_CUSTOM_FIELD_LOCATION => array('predicate' => 'http://schema.org/location', 'type' => WL_DATA_TYPE_URI, 'export_type' => 'http://schema.org/PostalAddress', 'constraints' => array('uri_type' => 'Place'))), 'microdata_template' => '{{startDate}}
                                {{endDate}}
                                {{location}}', 'templates' => array('subtitle' => '{{id}}')), 'organization' => array('label' => 'Organization', 'description' => 'An organization, including a government or a newspaper.', 'parents' => array('thing'), 'css' => 'wl-organization', 'uri' => 'http://schema.org/Organization', 'same_as' => array('http://rdf.freebase.com/ns/organization.organization', 'http://rdf.freebase.com/ns/government.government', 'http://schema.org/Newspaper'), 'custom_fields' => array(WL_CUSTOM_FIELD_FOUNDER => array('predicate' => 'http://schema.org/founder', 'type' => WL_DATA_TYPE_URI, 'export_type' => 'http://schema.org/Person', 'constraints' => array('uri_type' => 'Person'))), 'microdata_template' => '{{founder}}', 'templates' => array('subtitle' => '{{id}}')), 'person' => array('label' => 'Person', 'description' => 'A person (or a music artist).', 'parents' => array('thing'), 'css' => 'wl-person', 'uri' => 'http://schema.org/Person', 'same_as' => array('http://rdf.freebase.com/ns/people.person', 'http://rdf.freebase.com/ns/music.artist', 'http://dbpedia.org/class/yago/LivingPeople'), 'custom_fields' => array(), 'microdata_template' => '', 'templates' => array('subtitle' => '{{id}}')), 'place' => array('label' => 'Place', 'description' => 'A place.', 'parents' => array('thing'), 'css' => 'wl-place', 'uri' => 'http://schema.org/Place', 'same_as' => array('http://rdf.freebase.com/ns/location.location', 'http://www.opengis.net/gml/_Feature'), 'custom_fields' => array(WL_CUSTOM_FIELD_GEO_LATITUDE => array('predicate' => 'http://schema.org/latitude', 'type' => WL_DATA_TYPE_DOUBLE, 'export_type' => 'xsd:double', 'constraints' => '', 'input_field' => 'coordinates'), WL_CUSTOM_FIELD_GEO_LONGITUDE => array('predicate' => 'http://schema.org/longitude', 'type' => WL_DATA_TYPE_DOUBLE, 'export_type' => 'xsd:double', 'constraints' => '', 'input_field' => 'coordinates'), WL_CUSTOM_FIELD_ADDRESS => array('predicate' => 'http://schema.org/address', 'type' => WL_DATA_TYPE_STRING, 'export_type' => 'http://schema.org/PostalAddress', 'constraints' => '')), 'microdata_template' => '<span itemprop="geo" itemscope itemtype="http://schema.org/GeoCoordinates">
                                    {{latitude}}
                                    {{longitude}}
                                </span>
                                {{address}}', 'templates' => array('subtitle' => '{{id}}')), 'localbusiness' => array('label' => 'LocalBusiness', 'description' => 'A local business.', 'parents' => array('place', 'organization'), 'css' => 'wl-local-business', 'uri' => 'http://schema.org/LocalBusiness', 'same_as' => array('http://rdf.freebase.com/ns/business/business_location', 'https://schema.org/Store'), 'custom_fields' => array(), 'microdata_template' => '', 'templates' => array('subtitle' => '{{id}}')));
    foreach ($terms as $slug => $term) {
        // Create the term if it does not exist, then get its ID
        $term_id = term_exists($term['label']);
        if ($term_id == 0 || is_null($term_id)) {
            $result = wp_insert_term($term['label'], WL_ENTITY_TYPE_TAXONOMY_NAME);
        } else {
            $result = get_term($term_id, WL_ENTITY_TYPE_TAXONOMY_NAME, ARRAY_A);
        }
        // Check for errors.
        if (is_wp_error($result)) {
            wl_write_log('wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]');
            continue;
        }
        // Check if 'parent' corresponds to an actual term and get its ID.
        if (!isset($term['parents'])) {
            $term['parents'] = array();
        }
        $parent_ids = array();
        foreach ($term['parents'] as $parent_slug) {
            $parent_id = get_term_by('slug', $parent_slug, WL_ENTITY_TYPE_TAXONOMY_NAME);
            $parent_ids[] = intval($parent_id->term_id);
            // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
        }
        // Define a parent in the WP taxonomy style (not important for WL)
        if (empty($parent_ids)) {
            // No parent
            $parent_id = 0;
        } else {
            // Get first parent
            $parent_id = $parent_ids[0];
        }
        // Update term with description, slug and parent
        wp_update_term($result['term_id'], WL_ENTITY_TYPE_TAXONOMY_NAME, array('description' => $term['description'], 'slug' => $slug, 'parent' => $parent_id));
        // Inherit custom fields and microdata template from parent.
        $term = wl_entity_type_taxonomy_type_inheritage($term, $parent_ids);
        // Add custom metadata to the term.
        wl_entity_type_taxonomy_update_term($result['term_id'], $term['css'], $term['uri'], $term['same_as'], $term['custom_fields'], $term['templates'], $term['microdata_template']);
    }
}
 /**
  * Update the menu name if option is updated
  * @since 1.1.5
  */
 public function updateMenuName($option, $old_value, $value)
 {
     if ($option == 'nestedpages_menu') {
         $menu = get_term_by('id', $old_value, 'nav_menu');
         if ($menu) {
             delete_option('nestedpages_menu');
             // Delete the option to prevent infinite loop
             update_option('nestedpages_menu', $old_value);
             wp_update_term($menu->term_id, 'nav_menu', array('name' => $value, 'slug' => sanitize_title($value)));
         }
     }
 }
 function move_folder($folderId, $inFolderId)
 {
     global $wplr;
     $termId = $wplr->get_meta("mediafolder_term_id", $folderId);
     $parentTermId = $wplr->get_meta("mediafolder_term_id", $inFolderId);
     $result = wp_update_term($termId, 'wpmf-category', array('parent' => $parentTermId));
     if (is_wp_error($result)) {
         error_log("Issue while moving the folder.");
         error_log($result->get_error_message());
         return;
     }
 }
 /**
  * @ticket 22526
  */
 function test_category_name_change()
 {
     $term = self::factory()->category->create_and_get(array('name' => 'Foo'));
     $post_id = self::factory()->post->create();
     wp_set_post_categories($post_id, $term->term_id);
     $post = get_post($post_id);
     $cats1 = get_the_category($post->ID);
     $this->assertEquals($term->name, reset($cats1)->name);
     wp_update_term($term->term_id, 'category', array('name' => 'Bar'));
     $cats2 = get_the_category($post->ID);
     $this->assertNotEquals($term->name, reset($cats2)->name);
 }
 /**
  * Update to-do list category
  * @static
  * @return int
  */
 public static function update_category()
 {
     $category_id = absint($_POST['cleverness_todo_cat_id']);
     $term = wp_update_term($category_id, 'todocategories', array('name' => $_POST['cleverness_todo_cat_name']));
     if (!is_wp_error($term)) {
         $options = get_option('CTDL_categories');
         $options["category_{$category_id}"] = absint($_POST['cleverness_todo_cat_visibility']);
         update_option('CTDL_categories', $options);
         return $term['term_id'];
     } else {
         return 0;
     }
 }
 public static function create($name, $language, $document_id)
 {
     $desc = array('lingotek' => array('type' => 'string', 'md5' => md5(self::get_content($name)), 'source' => $language->mo_id, 'status' => 'importing', 'translations' => array()));
     $terms = wp_get_object_terms($language->mo_id, 'post_translations');
     // the translation already exists but was previously disassociated
     if ($key = array_search($name, wp_list_pluck($terms, 'name'))) {
         wp_update_term((int) $terms[$key]->term_id, 'post_translations', array('slug' => $document_id, 'name' => $name, 'description' => serialize($desc)));
     } else {
         wp_insert_term($name, 'post_translations', array('slug' => $document_id, 'description' => serialize($desc)));
     }
     wp_set_object_terms($language->mo_id, $document_id, 'post_translations', true);
     // add terms
 }
 function ready_ecommerce_setup()
 {
     global $wpdb;
     /* Language Support */
     load_theme_textdomain('ready_ecommerce', get_template_directory() . '/languages');
     $locale = get_locale();
     $locale_file = get_template_directory() . "/languages/{$locale}.php";
     if (is_readable($locale_file)) {
         require_once $locale_file;
     }
     /* Add default posts and comments RSS feed links to head */
     add_theme_support('automatic-feed-links');
     /* This theme uses wp_nav_menu() in two location.*/
     register_nav_menus(array('primary' => __('Primary Menu', 'ready_ecommerce'), 'top' => __('Top "Drop-Down" Menu', 'ready_ecommerce')));
     /* Create theme custom menu */
     $name = 'Ready! Ecommerce Menu';
     $menu = wp_get_nav_menu_object($name);
     if (!$menu) {
         $menu_id = wp_create_nav_menu($name);
         $options = get_option('nav_menu_options');
         $options['auto_add'][] = $menu_id;
         update_option('nav_menu_options', $options);
         $itemData = array('menu-item-type' => 'custom', 'menu-item-url' => get_home_url('/'), 'menu-item-title' => 'Home');
         wp_update_nav_menu_item($menu_id, 0, $itemData);
         // if Ready! Commerce plugin is already installed add the pages to menu
         require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
         // Need for plugins_api
     } else {
         $menu_id = $menu->term_id;
     }
     /* Set Custom Menu */
     if (!has_nav_menu('primary')) {
         $locations = get_theme_mod('nav_menu_locations');
         $locations['primary'] = $menu_id;
         set_theme_mod('nav_menu_locations', $locations);
     }
     if (!has_nav_menu('top')) {
         $locations = get_theme_mod('nav_menu_locations');
         $locations['top'] = $menu_id;
         set_theme_mod('nav_menu_locations', $locations);
     }
     /* Activate Social Links Module */
     $social_links = new SocialLinks();
     $social_links->social_links_install();
     /* Add support for the Aside and Gallery Post Formats */
     add_theme_support('post-formats', array('aside', 'image', 'gallery'));
     if (class_exists('frame')) {
         frame::_()->getModule('options')->getModel('')->put(array('code' => 'default_theme', 'value' => 'ready_ecommerce_theme'));
     }
     wp_update_term(1, 'category', array('name' => 'Shop', 'slug' => 'shop'));
 }
 public function testUpdateSplittedTerms()
 {
     // Remove split_shared_term to prevent automatic categories update for memberships.
     remove_action('split_shared_term', array('IB_Educator_Main', 'split_shared_term'));
     // Split shared term.
     $new_term = wp_update_term($this->terms['term3']['term_id'], 'ib_educator_category', array('name' => 'Edu'));
     // Update shared terms for use in memberships.
     $install = new Edr_Install();
     $install->update_1_4_4();
     $ms = Edr_Memberships::get_instance();
     $meta = $ms->get_membership_meta($this->posts[0]);
     // The term_id stored in the membership's categories setting should be updated.
     $this->assertEquals(array($new_term['term_id'], $this->terms['term4']['term_id']), $meta['categories']);
 }
 public static function createChildCategory($name, $slug, $parent_id)
 {
     $term = get_term_by('slug', $slug, 'category');
     if ($term) {
         $category = wp_update_term($term->term_id, 'category', array('slug' => $slug, 'parent' => $parent_id));
         return $category['term_id'];
     } else {
         $category = wp_insert_term($name, 'category', array('slug' => $slug, 'parent' => $parent_id));
         if (is_wp_error($category)) {
             $error_string = $category->get_error_message();
             echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
         }
         return $category['term_id'];
     }
 }
 /**
  * @ticket 24189
  */
 function test_object_term_cache_when_term_changes()
 {
     $post_id = self::$post_ids[0];
     $tag_id = self::factory()->tag->create(array('name' => 'Amaze Tag', 'description' => 'My Amazing Tag'));
     $tt_1 = wp_set_object_terms($post_id, $tag_id, 'post_tag');
     $terms = get_the_terms($post_id, 'post_tag');
     $this->assertEquals($tag_id, $terms[0]->term_id);
     $this->assertEquals('My Amazing Tag', $terms[0]->description);
     $_updated = wp_update_term($tag_id, 'post_tag', array('description' => 'This description is even more amazing!'));
     $_new_term = get_term($tag_id, 'post_tag');
     $this->assertEquals($tag_id, $_new_term->term_id);
     $this->assertEquals('This description is even more amazing!', $_new_term->description);
     $terms = get_the_terms($post_id, 'post_tag');
     $this->assertEquals($tag_id, $terms[0]->term_id);
     $this->assertEquals('This description is even more amazing!', $terms[0]->description);
 }
/**
 * Install known types in WordPress.
 */
function wl_core_install_entity_type_data()
{
    // global $wl_logger;
    // $wl_logger->trace( 'Installing entity type data...' );
    // Ensure the custom type and the taxonomy are registered.
    wl_entity_type_register();
    wl_entity_type_taxonomy_register();
    // Set the taxonomy data.
    // Note: parent types must be defined before child types.
    $terms = array('thing' => array('label' => 'Thing', 'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.'), 'creative-work' => array('label' => 'CreativeWork', 'description' => 'A creative work (or a Music Album).', 'parents' => array('thing')), 'event' => array('label' => 'Event', 'description' => 'An event.', 'parents' => array('thing')), 'organization' => array('label' => 'Organization', 'description' => 'An organization, including a government or a newspaper.', 'parents' => array('thing')), 'person' => array('label' => 'Person', 'description' => 'A person (or a music artist).', 'parents' => array('thing')), 'place' => array('label' => 'Place', 'description' => 'A place.', 'parents' => array('thing')), 'localbusiness' => array('label' => 'LocalBusiness', 'description' => 'A local business.', 'parents' => array('place', 'organization')));
    foreach ($terms as $slug => $term) {
        // Create the term if it does not exist, then get its ID
        $term_id = term_exists($slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
        if ($term_id == 0 || is_null($term_id)) {
            $result = wp_insert_term($slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
        } else {
            $term_id = $term_id['term_id'];
            $result = get_term($term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A);
        }
        // Check for errors.
        if (is_wp_error($result)) {
            wl_write_log('wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]');
            continue;
        }
        // Check if 'parent' corresponds to an actual term and get its ID.
        if (!isset($term['parents'])) {
            $term['parents'] = array();
        }
        $parent_ids = array();
        foreach ($term['parents'] as $parent_slug) {
            $parent_id = get_term_by('slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
            $parent_ids[] = intval($parent_id->term_id);
            // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
        }
        // Define a parent in the WP taxonomy style (not important for WL)
        if (empty($parent_ids)) {
            // No parent
            $parent_id = 0;
        } else {
            // Get first parent
            $parent_id = $parent_ids[0];
        }
        // Update term with description, slug and parent
        wp_update_term($result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array('name' => $term['label'], 'slug' => $slug, 'description' => $term['description'], 'parent' => $parent_id));
    }
}
 /**
  * Generate a callback for date-type meta boxes created with date_metabox().
  *
  * This function generates a standardized callback for taxonomy meta boxes created with the date_metabox() function
  * included with this plugin (see above). The callback takes input parameters from $_POST, sanitizes them, then
  * stores them hierarchically as:
  *
  *      Year (parent)
  *      ---- Month (child)
  *      ---- ---- Day (child)
  *
  * This function will not work properly if the target taxonomy was not registered with hierarchical=true, it will also
  * or any taxonomies that have not had their default metaboxes replaced with date_metabox();
  *
  * @see date_meta_box() This function relies on POST data passed from a meta box created with this.
  *
  * @uses wp_insert_term() Used to add the term to the database.
  * @uses get_term_by() Used to get the object of terms stored with wp_insert_term().
  * @uses wp_set_object_terms Used to attach the newly created terms to the post.
  * @param int     $post_id,   probably leave this as is. This is the ID of the post to which the terms should attach
  * @param string  $taxonomy,  The taxonomy to which the terms belong
  * @param boolean $multiples, Determines whether the term shoud append (true) or replace (false) existing terms
  * @return identical to wp_set_object_terms
  */
 public function date($post_id, $taxonomy, $multiples = false, $date = array(), $timezone = null, $term_num = null)
 {
     global $post;
     $rmTerm = 'rm_' . $taxonomy . '_' . $term_num;
     if (isset($_POST[$rmTerm]) and !empty($_POST[$rmTerm])) {
         $tounset = get_term_by('name', $_POST[$rmTerm], $taxonomy);
         if ($tounset) {
             $this->Taxonomy->remove_post_term($post_id, $tounset->term_id, $taxonomy);
         }
     } elseif (!empty($date)) {
         wp_set_object_terms($post_id, $date->format('c'), $taxonomy, $append = $multiples);
         if (isset($timezone)) {
             $term = get_term_by('name', $date->format('c'), $taxonomy);
             wp_update_term($term->term_id, $taxonomy, $args = array('description' => $timezone));
         }
     }
 }
 /**
  * Mise à jour d'une taxinomie / Update the taxonomy
  *
  * @param array|Object $data Les données de la taxinomie a sauvegarder dans la base de données / Datas o ftaxonomy to save into database
  *
  * @return Object L'objet sauvegardé / The saved object
  */
 public function update($data)
 {
     $object = $data;
     /**	Dans le cas d'un tableau on le lit pour construire l'objet / If passed data is an array read and build an object from it	*/
     if (is_array($data)) {
         $object = new $this->model_name($data, $this->meta_key);
     }
     /**	Sauvegarde des données dans la base de données / Save data into database	*/
     $wp_category_danger = wp_update_term($object->id, $this->get_taxonomy(), $object->do_wp_object());
     if (!is_wp_error($wp_category_danger)) {
         /** Mise à jour des options / Save options */
         if (!empty($object->option)) {
             $this->save_meta_data($object);
         }
     }
     return $object;
 }
function wpleads_add_list_to_wplead_list_category_taxonomy($post_id, $list_title, $list_slug = null)
{
    $wplead_cat_id = get_post_meta($post_id, 'wplead_list_category_id', true);
    if ($wplead_cat_id) {
        wp_update_term($wplead_cat_id, 'wplead_list_category', array('name' => $list_title));
    } else {
        //add category taxonomy in wpleads
        $term = wp_insert_term($list_title, 'wplead_list_category', $args = array('slug' => $list_slug));
        if (is_object($term)) {
            $term_error_array = $term->error_data;
            $term_id = $term_error_array['term_exists'];
        } else {
            $term_id = $term['term_id'];
        }
        update_post_meta($post_id, 'wplead_list_category_id', $term_id);
    }
}
 /**
  * Saves/Updates term children (price group children).
  *
  * @author Zane M. Kolnik
  * @since 1.5.1
  * @package AJAX
  */
 public function save_term()
 {
     parse_str($_POST['form'], $form_data);
     wp_verify_nonce($_POST['security'], $_POST['action']);
     $taxonomy = $_POST['taxonomy'];
     // Update the price group name if it has changed
     if (!empty($form_data['price_group']['term_id'])) {
         $parent_obj = get_term_by('id', $form_data['price_group']['term_id'], $taxonomy);
         if (!empty($parent_obj) && $parent_obj->name != $form_data['price_group']['term_name']) {
             wp_update_term($form_data['price_group']['term_id'], $taxonomy, array('name' => $form_data['price_group']['term_name']));
         }
     }
     if (!empty($form_data['terms_children'])) {
         foreach ($form_data['terms_children'] as $k => $v) {
             wp_update_term($k, $taxonomy, array('name' => $v['name']));
             // Dynamically save ALL fields that are NOT 'name' as
             // term meta! It would have been nice to store all
             // meta into an array and loop over saving that,
             // can't wait for term meta to make it into core.
             foreach ($v as $kk => $vv) {
                 if ($k != 'name') {
                     sell_media_update_term_meta($k, $kk, $vv);
                 }
             }
         }
     }
     // Dynamically add new prices for this price group
     if (!empty($form_data['new_child'])) {
         foreach ($form_data['new_child'] as $child) {
             if (!empty($child['name'])) {
                 $term = wp_insert_term($child['name'], $taxonomy, array('parent' => $child['parent']));
                 // Dynamically save ALL fields that are NOT 'name' as
                 // term meta!
                 if (!is_wp_error($term)) {
                     foreach ($child as $k => $v) {
                         if ($k != 'name') {
                             sell_media_update_term_meta($term['term_id'], $k, $v);
                         }
                     }
                 }
             }
         }
     }
     wp_send_json(array('sell_media' => true));
 }
function insert_taxonomy_category($category_array)
{
    global $wpdb;
    for ($i = 0; $i < count($category_array); $i++) {
        $parent_catid = 0;
        if (is_array($category_array[$i])) {
            $cat_name_arr = $category_array[$i];
            for ($j = 0; $j < count($cat_name_arr); $j++) {
                $catname = $cat_name_arr[$j];
                if ($j > 1) {
                    $catid = $wpdb->get_var("select term_id from {$wpdb->terms} where name=\"{$catname}\"");
                    if (!$catid) {
                        $last_catid = wp_insert_term($catname, 'category');
                    }
                } else {
                    $catid = $wpdb->get_var("select term_id from {$wpdb->terms} where name=\"{$catname}\"");
                    if (!$catid) {
                        $last_catid = wp_insert_term($catname, 'category');
                    }
                }
            }
        } else {
            $catname = $category_array[$i];
            $catid = $wpdb->get_var("select term_id from {$wpdb->terms} where name=\"{$catname}\"");
            if (!$catid) {
                wp_insert_term($catname, 'category');
            }
        }
    }
    for ($i = 0; $i < count($category_array); $i++) {
        $parent_catid = 0;
        if (is_array($category_array[$i])) {
            $cat_name_arr = $category_array[$i];
            for ($j = 0; $j < count($cat_name_arr); $j++) {
                $catname = $cat_name_arr[$j];
                if ($j > 0) {
                    $parentcatname = $cat_name_arr[0];
                    $parent_catid = $wpdb->get_var("select term_id from {$wpdb->terms} where name=\"{$parentcatname}\"");
                    $last_catid = $wpdb->get_var("select term_id from {$wpdb->terms} where name=\"{$catname}\"");
                    wp_update_term($last_catid, 'category', $args = array('parent' => $parent_catid));
                }
            }
        }
    }
}
function wp_insert_category($catarr, $wp_error = false)
{
    $cat_defaults = array('cat_ID' => 0, 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => '');
    $cat_arr = wp_parse_args($cat_arr, $cat_defaults);
    extract($catarr, EXTR_SKIP);
    if (trim($cat_name) == '') {
        if (!$wp_error) {
            return 0;
        } else {
            return new WP_Error('cat_name', __('You did not enter a category name.'));
        }
    }
    $cat_ID = (int) $cat_ID;
    // Are we updating or creating?
    if (!empty($cat_ID)) {
        $update = true;
    } else {
        $update = false;
    }
    $name = $cat_name;
    $description = $category_description;
    $slug = $category_nicename;
    $parent = $category_parent;
    $parent = (int) $parent;
    if ($parent < 0) {
        $parent = 0;
    }
    if (empty($parent) || !category_exists($parent) || $cat_ID && cat_is_ancestor_of($cat_ID, $parent)) {
        $parent = 0;
    }
    $args = compact('name', 'slug', 'parent', 'description');
    if ($update) {
        $cat_ID = wp_update_term($cat_ID, 'category', $args);
    } else {
        $cat_ID = wp_insert_term($cat_name, 'category', $args);
    }
    if (is_wp_error($cat_ID)) {
        if ($wp_error) {
            return $cat_ID;
        } else {
            return 0;
        }
    }
    return $cat_ID['term_id'];
}
 /**
  * Impose some data onto the region
  * How the data is interpreted depends
  * on the region
  * 
  * @param string $key
  * @param mixed $value
  * @return true|WP_Error
  */
 public function impose($key, $value)
 {
     if (!taxonomy_exists($key)) {
         return new \WP_Error('invalid-taxonomy', "Invalid taxonomy");
     }
     foreach ($value as $slug => $term_values) {
         $term = get_term_by('slug', $slug, $key);
         if (!$term) {
             $ret = wp_insert_term($slug, $key);
             if (is_wp_error($ret)) {
                 return $ret;
             }
             $term = get_term_by('id', $ret['term_id'], $key);
         }
         foreach ($term_values as $yml_field => $term_value) {
             switch ($yml_field) {
                 case 'name':
                 case 'description':
                     if ($term_value == $term->{$yml_field}) {
                         break;
                     }
                     wp_update_term($term->term_id, $key, array($yml_field => $term_value));
                     break;
                 case 'parent':
                     if ($term_value) {
                         $parent_term = get_term_by('slug', $term_value, $key);
                         if (!$parent_term) {
                             return new \WP_Error('invalid-parent', sprintf("Parent is invalid for term: %s", $slug));
                         }
                         if ($parent_term->term_id == $term->parent) {
                             break;
                         }
                         wp_update_term($term->term_id, $key, array('parent' => $parent_term->term_id));
                     } else {
                         if (!$term_value && $term->parent) {
                             wp_update_term($term->term_id, $key, array('parent' => 0));
                         }
                     }
                     break;
             }
         }
     }
     return true;
 }
Exemple #29
0
 /**
  * Tests the model function that expects slashed data
  *
  */
 function test_wp_update_term()
 {
     $taxonomies = array('category', 'post_tag');
     foreach ($taxonomies as $taxonomy) {
         $id = $this->factory->term->create(array('taxonomy' => $taxonomy));
         $update = wp_update_term($id, $taxonomy, array('name' => $this->slash_1, 'description' => $this->slash_3));
         $term = get_term($id, $taxonomy);
         $this->assertEquals(wp_unslash($this->slash_1), $term->name);
         $this->assertEquals(wp_unslash($this->slash_3), $term->description);
         $update = wp_update_term($id, $taxonomy, array('name' => $this->slash_3, 'description' => $this->slash_5));
         $term = get_term($id, $taxonomy);
         $this->assertEquals(wp_unslash($this->slash_3), $term->name);
         $this->assertEquals(wp_unslash($this->slash_5), $term->description);
         $update = wp_update_term($id, $taxonomy, array('name' => $this->slash_2, 'description' => $this->slash_4));
         $term = get_term($id, $taxonomy);
         $this->assertEquals(wp_unslash($this->slash_2), $term->name);
         $this->assertEquals(wp_unslash($this->slash_4), $term->description);
     }
 }
Exemple #30
0
 function test_synced_term_is_updated()
 {
     $master = new Master();
     $taxonomy = 'post_tag';
     $term = wp_insert_term('test_term', $taxonomy, array('description' => 'test description'));
     if (is_wp_error($term)) {
         var_dump($term);
         throw new Exception("Error in wp_insert_term");
     }
     $term_id = $term['term_id'];
     $tt_id = $term['term_taxonomy_id'];
     $result = wp_set_post_terms($this->ID, array($term_id), $taxonomy);
     $remote_id = $master->push($this->post, $this->site);
     wp_update_term($term_id, $taxonomy, array("description" => "updated desc"));
     $master->update_term($term_id, $tt_id, $taxonomy);
     $local_terms = wp_get_post_terms($this->ID, $taxonomy);
     $remote_terms = wp_get_post_terms($remote_id, $taxonomy);
     $this->assertEquals('updated desc', $local_terms[0]->description);
     $this->assertEquals('updated desc', $remote_terms[0]->description);
 }