/** * Updates post prominence term descriptions iff they use the old language * * This function can be added to the `init` action to force an update of prominence term descriptions: * add_action('init', 'largo_update_prominence_term_descriptions'); * * This function does not touch custom prominence term descriptions, except those that are identical to the descriptions of current or 0.3 prominence term descriptions. * * @since 0.4 * @uses largo_update_prominence_term_description_single */ function largo_update_prominence_term_descriptions() { // see https://github.com/INN/Largo/issues/210 $terms = get_terms('prominence', array('hide_empty' => false, 'fields' => 'all')); // prevent PHP warnings in case no terms returned if (gettype($terms) != "array") { return false; } $term_descriptions = array_map(function ($arg) { return $arg->description; }, $terms); $largoOldProminenceTerms = array(array('name' => __('Sidebar Featured Widget', 'largo'), 'description' => __('If you are using the Featured Posts widget in a sidebar, add this label to posts to determine which to display in the widget.', 'largo'), 'olddescription' => __('If you are using the Sidebar Featured Posts widget, add this label to posts to determine which to display in the widget.', 'largo'), 'slug' => 'sidebar-featured'), array('name' => __('Footer Featured Widget', 'largo'), 'description' => __('If you are using the Featured Posts widget in the footer, add this label to posts to determine which to display in the widget.', 'largo'), 'olddescription' => __('If you are using the Footer Featured Posts widget, add this label to posts to determine which to display in the widget.', 'largo'), 'slug' => 'footer-featured'), array('name' => __('Featured in Category', 'largo'), 'description' => __('This will allow you to designate a story to appear more prominently on category archive pages.', 'largo'), 'olddescription' => __('Not yet implemented, in the future this will allow you to designate a story (or stories) to appear more prominently on category archive pages.', 'largo'), 'slug' => 'category-featured'), array('name' => __('Homepage Featured', 'largo'), 'description' => __('Add this label to posts to display them in the featured area on the homepage.', 'largo'), 'olddescription' => __('If you are using the Newspaper or Carousel optional homepage layout, add this label to posts to display them in the featured area on the homepage.', 'largo'), 'slug' => 'homepage-featured'), array('name' => __('Homepage Top Story', 'largo'), 'description' => __('If you are using a "Big story" homepage layout, add this label to a post to make it the top story on the homepage', 'largo'), 'olddescription' => __('If you are using the Newspaper or Carousel optional homepage layout, add this label to label to a post to make it the top story on the homepage.', 'largo'), 'slug' => 'top-story'), array('name' => __('Featured in Series', 'largo'), 'description' => __('Select this option to allow this post to float to the top of any/all series landing pages sorting by Featured first.', 'largo'), 'olddescription' => __('Select this option to allow this post to float to the top of any/all series landing pages sorting by Featured first.', 'largo'), 'slug' => 'series-featured')); foreach ($largoOldProminenceTerms as $update) { largo_update_prominence_term_description_single($update, $term_descriptions); } }
function test_largo_update_prominence_term_description_single() { $update = array('name' => 'Term 9', 'description' => 'Term 9 From Outer Space', 'olddescription' => 'Term Description 9', 'slug' => 'term-9'); $term_descriptions = array('Term Description 9'); $return = largo_update_prominence_term_description_single($update, $term_descriptions); $this->assertTrue(is_array($return)); $term9 = get_term_by('slug', 'term-9', 'prominence', 'ARRAY_A'); $this->assertEquals('Term 9 From Outer Space', $term9['description']); }