public function output($recipe, $args = array())
 {
     if (!$this->output_block($recipe, $args) || !isset($args['ingredient_name'])) {
         return '';
     }
     $taxonomy = get_term_by('name', $args['ingredient_name'], 'ingredient');
     $taxonomy_slug = is_object($taxonomy) ? $taxonomy->slug : $args['ingredient_name'];
     $ingredient_links = WPUltimateRecipe::option('recipe_ingredient_links', 'archive_custom');
     $output = $this->before_output();
     $plural = WPURP_Taxonomy_MetaData::get('ingredient', $taxonomy_slug, 'plural');
     $plural = is_array($plural) ? false : $plural;
     $plural_data = $plural ? ' data-singular="' . esc_attr($args['ingredient_name']) . '" data-plural="' . esc_attr($plural) . '"' : '';
     $output .= '<span' . $this->style() . $plural_data . '>';
     $closing_tag = '';
     if (!empty($taxonomy) && $ingredient_links != 'disabled') {
         if ($ingredient_links == 'archive_custom' || $ingredient_links == 'custom') {
             $custom_link = WPURP_Taxonomy_MetaData::get('ingredient', $taxonomy_slug, 'link');
         } else {
             $custom_link = false;
         }
         if (WPURP_Taxonomy_MetaData::get('ingredient', $taxonomy_slug, 'hide_link') !== '1') {
             if ($custom_link !== false && $custom_link !== '') {
                 $nofollow = WPUltimateRecipe::option('recipe_ingredient_custom_links_nofollow', '0') == '1' ? ' rel="nofollow"' : '';
                 $output .= '<a href="' . $custom_link . '" class="custom-ingredient-link" target="' . WPUltimateRecipe::option('recipe_ingredient_custom_links_target', '_blank') . '"' . $nofollow . '>';
                 $closing_tag = '</a>';
             } else {
                 if ($ingredient_links != 'custom') {
                     $output .= '<a href="' . get_term_link($taxonomy_slug, 'ingredient') . '">';
                     $closing_tag = '</a>';
                 }
             }
         }
     }
     $output .= $plural && $args['ingredient_quantity_normalized'] != 1 ? $plural : $args['ingredient_name'];
     $output .= $closing_tag;
     $output .= '</span>';
     return $this->after_output($output, $recipe);
 }
Ejemplo n.º 2
0
 private function ingredients_list($recipe, $args)
 {
     $out = '';
     $previous_group = '';
     foreach ($recipe->ingredients() as $ingredient) {
         if (isset($ingredient['ingredient_id'])) {
             $term = get_term($ingredient['ingredient_id'], 'ingredient');
             if ($term !== null && !is_wp_error($term)) {
                 $ingredient['ingredient'] = $term->name;
             }
         }
         if (isset($ingredient['group']) && $ingredient['group'] != $previous_group) {
             $out .= '<li class="group"' . $this->style(array('li', 'li-group')) . '>' . $ingredient['group'] . '</li>';
             $previous_group = $ingredient['group'];
         }
         $fraction = WPUltimateRecipe::option('recipe_adjustable_servings_fractions', '0') == '1' ? true : false;
         $fraction = strpos($ingredient['amount'], '/') === false ? $fraction : true;
         $meta = $args['template_type'] == 'recipe' && $args['desktop'] ? ' itemprop="ingredients"' : '';
         $out .= '<li class="wpurp-recipe-ingredient"' . $this->style(array('li', 'li-ingredient')) . $meta . '>';
         $out .= '<span class="recipe-ingredient-quantity-unit"' . $this->style('quantity-unit') . '><span class="wpurp-recipe-ingredient-quantity recipe-ingredient-quantity" data-normalized="' . $ingredient['amount_normalized'] . '" data-fraction="' . $fraction . '" data-original="' . $ingredient['amount'] . '"' . $this->style('quantity') . '>' . $ingredient['amount'] . '</span> <span class="wpurp-recipe-ingredient-unit recipe-ingredient-unit" data-original="' . $ingredient['unit'] . '"' . $this->style('unit') . '>' . $ingredient['unit'] . '</span></span>';
         $taxonomy = get_term_by('name', $ingredient['ingredient'], 'ingredient');
         $plural = WPURP_Taxonomy_MetaData::get('ingredient', $taxonomy->slug, 'plural');
         $plural = is_array($plural) ? false : $plural;
         $plural_data = $plural ? ' data-singular="' . esc_attr($ingredient['ingredient']) . '" data-plural="' . esc_attr($plural) . '"' : '';
         $out .= ' <span class="wpurp-recipe-ingredient-name recipe-ingredient-name"' . $this->style('name') . $plural_data . '>';
         $ingredient_links = WPUltimateRecipe::option('recipe_ingredient_links', 'archive_custom');
         $closing_tag = '';
         if (!empty($taxonomy) && $ingredient_links != 'disabled') {
             if ($ingredient_links == 'archive_custom' || $ingredient_links == 'custom') {
                 $custom_link = WPURP_Taxonomy_MetaData::get('ingredient', $taxonomy->slug, 'link');
             } else {
                 $custom_link = false;
             }
             if (WPURP_Taxonomy_MetaData::get('ingredient', $taxonomy->slug, 'hide_link') !== '1') {
                 if ($custom_link !== false && $custom_link !== '') {
                     $nofollow = WPUltimateRecipe::option('recipe_ingredient_custom_links_nofollow', '0') == '1' ? ' rel="nofollow"' : '';
                     $out .= '<a href="' . $custom_link . '" class="custom-ingredient-link" target="' . WPUltimateRecipe::option('recipe_ingredient_custom_links_target', '_blank') . '"' . $nofollow . $this->style('link') . '>';
                     $closing_tag = '</a>';
                 } else {
                     if ($ingredient_links != 'custom') {
                         $out .= '<a href="' . get_term_link($taxonomy->slug, 'ingredient') . '"' . $this->style('link') . '>';
                         $closing_tag = '</a>';
                     }
                 }
             }
         }
         $out .= $plural && $ingredient['amount_normalized'] != 1 ? $plural : $ingredient['ingredient'];
         $out .= $closing_tag;
         $out .= '</span>';
         if ($ingredient['notes'] != '') {
             $out .= ' ';
             $out .= '<span class="wpurp-recipe-ingredient-notes recipe-ingredient-notes"' . $this->style('notes') . '>' . $ingredient['notes'] . '</span>';
         }
         $out .= '</li>';
     }
     return $out;
 }
 *
 * Create ingredients from all your WooCommerce products, including links to those products
 */
$limit = 100;
$offset = 0;
$message = 'No WooCommerce Products found';
while (true) {
    // Edit these arguments to limit the WooCommerce Products
    $args = array('post_type' => 'product', 'post_status' => 'publish', 'orderby' => 'name', 'order' => 'ASC', 'posts_per_page' => $limit, 'offset' => $offset);
    $query = new WP_Query($args);
    if (!$query->have_posts()) {
        break;
    }
    $posts = $query->posts;
    foreach ($posts as $post) {
        $name = $post->post_title;
        $link = get_permalink($post->ID);
        $term = term_exists($name, 'ingredient');
        if ($term === 0 || $term === null) {
            $term = wp_insert_term($name, 'ingredient');
        }
        $term = get_term(intval($term['term_id']), 'ingredient');
        WPURP_Taxonomy_MetaData::set('ingredient', $term->slug, 'link', $link);
        wp_cache_delete($post->ID, 'posts');
        wp_cache_delete($post->ID, 'post_meta');
    }
    $message = 'Successfully created ingredients from WooCommerce products';
    $offset += $limit;
    wp_cache_flush();
}
WPUltimateRecipe::get()->helper('notices')->add_admin_notice('<strong>WP Ultimate Recipe</strong> ' . $message);
Ejemplo n.º 4
0
 /**
  * TODO Refactor this.
  */
 private function tags_list($recipe)
 {
     $tags = array();
     $tag_links = WPUltimateRecipe::option('recipe_tags_links', 'archive_custom');
     $taxonomies = WPUltimateRecipe::get()->tags();
     unset($taxonomies['ingredient']);
     foreach ($taxonomies as $taxonomy => $options) {
         if (!in_array($taxonomy, WPUltimateRecipe::option('recipe_tags_hide_in_recipe', array()))) {
             $terms = get_the_terms($recipe->ID(), $taxonomy);
             if ($terms && !is_wp_error($terms)) {
                 $links = array();
                 foreach ($terms as $term) {
                     $opening_tag = '';
                     $closing_tag = '';
                     if ($tag_links !== 'disabled') {
                         if ($tag_links == 'archive_custom' || $tag_links == 'custom') {
                             $custom_link = WPURP_Taxonomy_MetaData::get($taxonomy, $term->slug, 'wpurp_link');
                         } else {
                             $custom_link = false;
                         }
                         if ($custom_link !== false && $custom_link !== '') {
                             $nofollow = WPUltimateRecipe::option('recipe_tags_custom_links_nofollow', '0') == '1' ? ' rel="nofollow"' : '';
                             $opening_tag = '<a href="' . $custom_link . '" class="custom-tag-link" target="' . WPUltimateRecipe::option('recipe_tags_custom_links_target', '_blank') . '"' . $nofollow . '>';
                             $closing_tag = '</a>';
                         } else {
                             if ($tag_links != 'custom') {
                                 $opening_tag = '<a href="' . get_term_link($term->slug, $taxonomy) . '">';
                                 $closing_tag = '</a>';
                             }
                         }
                     }
                     $links[] = $opening_tag . $term->name . $closing_tag;
                 }
                 // Get name at this point in time to have correct WPML translation
                 $tax = get_taxonomy($taxonomy);
                 $label = __($tax->labels->singular_name, 'wp-ultimate-recipe');
                 $tags[$label] = join(', ', $links);
             }
         }
     }
     // Categories as tags
     if (WPUltimateRecipe::is_addon_active('custom-taxonomies') && WPUltimateRecipe::option('recipe_tags_show_in_recipe', '0') == '1') {
         $categories = wp_get_post_categories($recipe->ID());
         $category_groups = array();
         foreach ($categories as $category) {
             $cat = get_category($category);
             if (!is_null($cat->parent) && $cat->parent != 0) {
                 $category_groups[$cat->parent][] = $cat;
             }
         }
         foreach ($category_groups as $group => $categories) {
             $group_category = get_category($group);
             $group_name = $group_category->name;
             $cats = array();
             foreach ($categories as $cat) {
                 $link = get_category_link($cat->cat_ID);
                 $cats[] = '<a href="' . $link . '">' . $cat->name . '</a>';
             }
             $tags[$group_name] = implode(', ', $cats);
         }
     }
     return apply_filters('wpurp_output_recipe_block_recipe-tags_terms', $tags, $recipe);
 }