PluginProbe
Cooked – Recipe Management / 1.11.4
Cooked – Recipe Management v1.11.4
1.16.1 1.16.0 1.15.0 trunk 1.10.0 1.11.0 1.11.1 1.11.2 1.11.3 1.11.4 1.12.0 1.13.0 1.14.0 1.7.10 1.7.11 1.7.12 1.7.13 1.7.15.1 1.7.15.3 1.7.15.4 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 All 37 releases
cooked / includes / class.cooked-shortcodes.php

class.cooked-shortcodes.php in Cooked – Recipe Management 1.11.4, at includes/class.cooked-shortcodes.php

1,085 lines 50.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Cooked Shortcodes
4 *
5 * @package Cooked
6 * @subpackage Shortcodes
7 * @since 1.0.0
8 */
9
10 // Exit if accessed directly
11 if ( !defined( 'ABSPATH' ) ) exit;
12
13 /**
14 * Cooked_Shortcodes Class
15 *
16 * This class handles the settings creation and contains functions for retreiving those settings.
17 *
18 * @since 1.0.0
19 */
20
21 class Cooked_Shortcodes {
22
23 function __construct() {
24 // Allow shortcodes in widgets
25 add_filter( 'widget_text', 'do_shortcode' );
26
27 // Site-Wide
28 add_shortcode('cooked-browse', [$this, 'cooked_browse_shortcode'] );
29 add_shortcode('cooked-search', [$this, 'cooked_search_shortcode'] );
30 add_shortcode('cooked-recipe', [$this, 'cooked_recipe_shortcode'] );
31 add_shortcode('cooked-categories', [$this, 'cooked_categories_shortcode'] );
32 add_shortcode('cooked-recipe-list', [$this, 'cooked_recipe_list_shortcode'] );
33 add_shortcode('cooked-recipe-card', [$this, 'cooked_recipe_card_shortcode'] );
34
35 if ( shortcode_exists( 'timer' ) ):
36 add_shortcode('cooked-timer', [$this, 'cooked_timer'] );
37 else:
38 add_shortcode('cooked-timer', [$this, 'cooked_timer'] );
39 add_shortcode('timer', [$this, 'cooked_timer'] );
40 endif;
41
42 // Recipe-Only
43 add_shortcode('cooked-title', [$this, 'cooked_title_shortcode'] );
44 add_shortcode('cooked-gallery', [$this, 'cooked_gallery_shortcode'] );
45 add_shortcode('cooked-image', [$this, 'cooked_image_shortcode'] );
46 add_shortcode('cooked-info', [$this, 'cooked_info_shortcode'] );
47 add_shortcode('cooked-excerpt', [$this, 'cooked_excerpt_shortcode'] );
48 add_shortcode('cooked-notes', [$this, 'cooked_notes_shortcode'] );
49 add_shortcode('cooked-ingredients', [$this, 'cooked_ingredients_shortcode'] );
50 add_shortcode('cooked-directions', [$this, 'cooked_directions_shortcode'] );
51 add_shortcode('cooked-nutrition', [$this, 'cooked_nutrition_shortcode'] );
52
53 // Add preprocessing filter for shortcodes for Elementor, Divi, and other builders compatibility.
54 add_filter('pre_do_shortcode_tag', [$this, 'preprocess_shortcode'], 10, 4);
55 }
56
57 public function preprocess_shortcode($output, $tag, $attr, $m) {
58 // Tags to skip
59 $skip_tags = [
60 'cooked-search',
61 'cooked-browse',
62 'cooked-timer',
63 'cooked-recipe',
64 'cooked-recipe-list',
65 'cooked-recipe-card',
66 ];
67
68 // Only process for Cooked shortcodes
69 if (is_front_page() || strpos($tag, 'cooked-') === false || in_array($tag, $skip_tags)) {
70 return $output;
71 }
72
73 global $recipe_settings, $post;
74
75 // If recipe settings are empty, try to get them.
76 if (empty($recipe_settings)) {
77 // Try to get recipe settings from current post.
78 $post_id = isset($post->ID) ? $post->ID : false;
79 if ($post_id && get_post_type( $post_id ) === 'cp_recipe') {
80 $recipe_settings = Cooked_Recipes::get($post_id, true);
81 } else {
82 // We are in the editor but not on a recipe post type. Maybe a single recipe template?
83 // Uses the first recipe found in the database as a sample.
84 $recipe_settings = Cooked_Recipes::get(false, true, false, 1);
85 }
86
87 // If still empty and we have a specific recipe ID in attributes, try to get them.
88 if (empty($recipe_settings) && isset($attr['id'])) {
89 $recipe_settings = Cooked_Recipes::get(intval($attr['id']), true);
90 }
91 }
92
93 return $output;
94 }
95
96 public function cooked_search_shortcode( $atts, $content = null ) {
97 // Shortcode Attributes
98 $options = shortcode_atts(
99 [
100 'compact' => false,
101 'hide_browse' => false,
102 'hide_sorting' => false,
103 'inline_browse' => false,
104 ], $atts
105 );
106
107 return Cooked_Recipes::recipe_search_box( $options );
108 }
109
110 public function cooked_timer( $atts, $content = null ) {
111 global $cooked_timer_identifier;
112
113 // Shortcode Attributes
114 $atts = shortcode_atts(
115 [
116 'seconds' => 0,
117 'minutes' => 0,
118 'length' => 0, // Deprecated, left here for backwards compatibility with 2.x
119 'hours' => 0,
120 'desc' => ''
121 ], $atts
122 );
123
124 $desc = esc_attr($atts['desc']);
125 $seconds = $atts['seconds'];
126 $minutes = $atts['minutes'] ? $atts['minutes'] * 60 : $atts['length'] * 60;
127 $hours = $atts['hours'] * 60 * 60;
128 $seconds = $seconds + $minutes + $hours;
129
130 if (!$cooked_timer_identifier) {
131 $cooked_timer_identifier = 1;
132 } else {
133 $cooked_timer_identifier++;
134 }
135
136 $timer_id = md5( $seconds . $desc . $content ) . '_' . $cooked_timer_identifier;
137 $desc = $desc ? wp_strip_all_tags( $desc ) : wp_strip_all_tags( $content );
138
139 wp_enqueue_script( 'cooked-timer' );
140
141 return '<span class="cooked-timer"><a aria-label="' . esc_attr( $desc ) . '" data-timer-id="' . esc_attr( $timer_id ) . '" data-seconds="' . esc_attr( $seconds ) . '" data-desc="' . ( $desc ) . '"><i class="cooked-icon cooked-icon-clock"></i> ' . wp_kses_post( $content ) . '</a></span>';
142 }
143
144 public function cooked_browse_shortcode( $sc_atts, $content = null ) {
145 global $_cooked_settings;
146
147 if ( isset($_cooked_settings['advanced']) && !empty($_cooked_settings['advanced']) && in_array( 'disable_public_recipes', $_cooked_settings['advanced'] ) ) {
148 /* translators: referring to the bottom of the Settings page. */
149 return current_user_can( 'edit_cooked_settings' ) ? wpautop( sprintf( __('Public recipes are currently disabled. You can change this at the bottom of the %s page.','cooked'), '<a href="' . trailingslashit( admin_url() ) . 'admin.php?page=cooked_settings" target="_blank">' . __( 'Settings', 'cooked' ) . '</a>' ) ) : false;
150 }
151
152 if ( is_admin() ) return false;
153
154 $author_query_var = sanitize_key( get_query_var( 'recipe_author', false ) );
155 if ( !$author_query_var && isset( $_GET['recipe_author'] ) ) {
156 $author_query_var = sanitize_key( $_GET['recipe_author'] );
157 }
158
159 // Shortcode Attributes
160 $atts = shortcode_atts( apply_filters( 'cooked_browse_shortcode_default_attributes', [
161 'category' => false,
162 'order' => false,
163 'orderby' => false,
164 'show' => false,
165 'search' => 'true',
166 'pagination' => 'true',
167 'columns' => 3,
168 'layout' => false,
169 'author' => $author_query_var,
170 'compact' => false,
171 'hide_browse' => false,
172 'hide_sorting' => false,
173 'exclude' => false,
174 'inline_browse' => false,
175 'hide_excerpt' => false,
176 ] ), $sc_atts);
177
178 return Cooked_Recipes::list_view( $atts );
179 }
180
181 public function cooked_recipe_card_shortcode( $atts, $content = null ) {
182 if ( is_admin() ) return false;
183
184 // Shortcode Attributes
185 $atts = shortcode_atts([
186 'id' => false,
187 'category' => false,
188 'width' => false,
189 'style' => false,
190 'hide_total' => false,
191 'hide_image' => false,
192 'hide_title' => false,
193 'hide_excerpt' => false,
194 'hide_author' => false
195 ], $atts);
196
197 $recipe_id = intval( $atts['id'] );
198 $category_id = intval( $atts['category'] );
199 $width = Cooked_Functions::sanitize_text_field( $atts['width'] );
200 $style = Cooked_Functions::sanitize_text_field( $atts['style'] );
201 $hide_image = Cooked_Functions::sanitize_text_field( $atts['hide_image'] );
202 $hide_total = Cooked_Functions::sanitize_text_field( $atts['hide_total'] );
203 $hide_title = Cooked_Functions::sanitize_text_field( $atts['hide_title'] );
204 $hide_excerpt = Cooked_Functions::sanitize_text_field( $atts['hide_excerpt'] );
205 $hide_author = Cooked_Functions::sanitize_text_field( $atts['hide_author'] );
206
207 ob_start();
208
209 if ( $recipe_id ) {
210 echo Cooked_Recipes::card( $recipe_id, $width, $hide_image, $hide_title, $hide_excerpt, $hide_author, $style );
211 } elseif ( $category_id ) {
212 echo Cooked_Taxonomies::card( $category_id, $width, $hide_image, $hide_total, $style );
213 }
214
215 return ob_get_clean();
216 }
217
218 public function cooked_categories_shortcode( $atts, $content = null ) {
219 if ( is_admin() ) return false;
220
221 // Shortcode Attributes
222 $atts = shortcode_atts([
223 'hide_empty' => true,
224 'child_of' => false,
225 'style' => 'block'
226 ], $atts);
227
228 $hide_empty = Cooked_Functions::sanitize_text_field( $atts['hide_empty'] );
229 $child_of = Cooked_Functions::sanitize_text_field( $atts['child_of'] );
230 $style = Cooked_Functions::sanitize_text_field( $atts['style'] );
231 $parents_only = $child_of ? false : true;
232
233 ob_start();
234
235 $categories_array = Cooked_Settings::terms_array( 'cp_recipe_category', false, false, $hide_empty, $parents_only, $child_of );
236 if ( !empty($categories_array) ) {
237 echo $style == 'list' ? '<div class="cooked-recipe-term-list">' : '<div class="cooked-recipe-term-grid cooked-clearfix">';
238 foreach ( $categories_array as $key => $val ) {
239 Cooked_Taxonomies::single_taxonomy_block( $key, $style );
240 }
241 echo '</div>';
242 }
243
244 return ob_get_clean();
245 }
246
247 public function cooked_recipe_list_shortcode( $atts, $content = null ) {
248 if ( is_admin() ) return false;
249
250 // Shortcode Attributes
251 $atts = shortcode_atts( [
252 'orderby' => 'date',
253 'width' => '100%',
254 'recipes' => false,
255 'show' => 5,
256 'hide_image' => false,
257 'hide_author' => false
258 ], $atts);
259
260 $recipes = Cooked_Functions::sanitize_text_field( $atts['recipes'] );
261 $orderby = Cooked_Functions::sanitize_text_field( $atts['orderby'] );
262 $show = Cooked_Functions::sanitize_text_field( $atts['show'] );
263 $width = Cooked_Functions::sanitize_text_field( $atts['width'] );
264 $hide_image = Cooked_Functions::sanitize_text_field( $atts['hide_image'] );
265 $hide_author = Cooked_Functions::sanitize_text_field( $atts['hide_author'] );
266
267 if ( $recipes ) {
268 $recipes = preg_replace( '/\s+/', '', $recipes );
269 $recipes = explode( ',', $recipes );
270 }
271
272 ob_start();
273
274 Cooked_Recipes::recipe_list( $orderby, $show, $recipes, $width, $hide_image, $hide_author );
275
276 return ob_get_clean();
277 }
278
279 public function cooked_recipe_shortcode( $atts, $content = null ) {
280 if ( is_admin() ) return false;
281
282 // Shortcode Attributes
283 $atts = shortcode_atts([
284 'id' => false,
285 ], $atts);
286
287 global $recipe_settings, $_cooked_content_unfiltered;
288
289 ob_start();
290
291 $recipe_id = intval( $atts['id'] );
292
293 if ( $recipe_id ) {
294
295 $recipe_settings = Cooked_Recipes::get( $recipe_id, true );
296 if ( !$recipe_settings || $recipe_settings && empty( $recipe_settings ) ) {
297 return wpautop( '<strong>[cooked-recipe id="' . intval( $recipe_id ) . '"]</strong><br><em>' . __( '(recipe not found or in draft status)', 'cooked' ) . '</em>' );
298 } else {
299 load_template( COOKED_DIR . 'templates/front/recipe.php', false );
300 }
301
302 }
303
304 return do_shortcode( ob_get_clean() );
305 }
306
307 public function cooked_gallery_shortcode($atts, $content = null) {
308 global $recipe_settings;
309
310 if ( isset($recipe_settings['gallery']) && isset($recipe_settings['gallery']['type']) && $recipe_settings['gallery']['type'] == 'cooked' ) {
311 $gallery_options = apply_filters( 'cooked_recipe_gallery_options', [
312 'data-fit' => 'cover',
313 'data-nav' => 'dots',
314 'data-width' => '100%',
315 'data-loop' => 'true',
316 'data-allowfullscreen' => 'true',
317 'data-ratio' => '800/600',
318 'data-thumbmargin' => '10',
319 'data-thumbborderwidth' => '5',
320 'data-swipe' => 'true',
321 'data-thumbheight' => '75',
322 'data-thumbwidth' => '75'
323 ]);
324
325 // Generate the Shortcode Attributes
326 foreach ( $gallery_options as $opt_name => $opt_value ) {
327 $name_sans_data = str_replace( 'data-', '', $opt_name );
328 $gallery_atts[$name_sans_data] = $opt_value;
329 }
330
331 // Set the Shortcode Attributes
332 $atts = shortcode_atts(
333 $gallery_atts, $atts
334 );
335
336 // Check for Shortcode Attribute Customizations
337 foreach ( $gallery_options as $opt_name => $opt_value ) {
338 $name_sans_data = str_replace( 'data-', '', $opt_name );
339 if ( isset($atts[$name_sans_data]) && $atts[$name_sans_data] ) {
340 $gallery_options[$opt_name] = $atts[$name_sans_data];
341 }
342 }
343 } else {
344 $atts = [];
345 }
346
347 if ( isset($recipe_settings['gallery']) && isset($recipe_settings['gallery']['type']) ):
348
349 switch( $recipe_settings['gallery']['type'] ):
350
351 case 'cooked':
352
353 if ( isset($recipe_settings['gallery']['items']) && !empty($recipe_settings['gallery']['items']) || isset($recipe_settings['gallery']['video_url']) && $recipe_settings['gallery']['video_url'] ):
354
355 // Gallery Options
356 // Developers: Filter these to change!
357 // Full list here: http://fotorama.io/customize/options/
358
359 $gallery_options_array = [];
360
361 foreach ( $gallery_options as $data_key => $data_val ):
362 $gallery_options_array[] = $data_key . '="' . $data_val . '"';
363 endforeach;
364
365 $gallery_html = '<div class="cooked-recipe-gallery"' . ( !empty($gallery_options_array) ? ' ' . implode( ' ', $gallery_options_array ) : '' ) . '>';
366
367 $cooked_gallery_video_last_option = apply_filters( 'cooked_gallery_video_last_option', false );
368
369 if ( !$cooked_gallery_video_last_option && isset($recipe_settings['gallery']['video_url']) && $recipe_settings['gallery']['video_url'] ):
370 $gallery_html .= '<a href="' . esc_url($recipe_settings['gallery']['video_url']) . '" data-caption="' . esc_attr($recipe_settings['title']) . '">' . esc_html($recipe_settings['title']) . '</a>';
371 endif;
372
373 $gallery_items = ( isset($recipe_settings['gallery']['items']) && !empty($recipe_settings['gallery']['items']) ? apply_filters( 'cooked_gallery_items_output', $recipe_settings['gallery']['items'] ) : [] );
374
375 if ( isset($gallery_items) && !empty($gallery_items) ) {
376 foreach ( $gallery_items as $item ) {
377 $image_src = wp_get_attachment_image_src( $item, [900, 900] );
378 $image_title = get_the_title( $item );
379 if ( is_array($image_src) && isset($image_src[0]) ) {
380 $gallery_html .= '<a href="' . esc_url( $image_src[0] ) . '" data-alt="'.esc_attr( $image_title ).'" data-caption="'.esc_attr( $image_title ).'">
381 <img alt="'.esc_attr( $image_title ).'" src="' . wp_get_attachment_image_url( $item, 'thumbnail' ) . '" />
382 </a>';
383 }
384 }
385 }
386
387 if ( $cooked_gallery_video_last_option && isset($recipe_settings['gallery']['video_url']) && $recipe_settings['gallery']['video_url'] ):
388 $gallery_html .= '<a href="' . esc_url($recipe_settings['gallery']['video_url']) . '" data-caption="' . esc_attr($recipe_settings['title']) . '">' . esc_html($recipe_settings['title']) . '</a>';
389 endif;
390
391 // Enqueue Gallery Styles & Scripts
392 wp_enqueue_style( 'cooked-fotorama' );
393 wp_enqueue_script( 'cooked-fotorama' );
394
395 $gallery_html .= '</div>';
396 return wp_kses_post( $gallery_html );
397
398 endif;
399
400 break;
401
402 case 'envira':
403 return ( $recipe_settings['gallery']['envira'] ? '<div class="cooked-recipe-gallery-envira">' . do_shortcode('[envira-gallery id="' . intval( $recipe_settings['gallery']['envira'] ) . '"]') . '</div>' : '' );
404 break;
405
406 case 'soliloquy':
407 return ( $recipe_settings['gallery']['soliloquy'] ? '<div class="cooked-recipe-gallery-soliloquy">' . do_shortcode('[soliloquy id="' . intval( $recipe_settings['gallery']['soliloquy'] ) . '"]') . '</div>' : '' );
408 break;
409
410 case 'revslider':
411 return ( $recipe_settings['gallery']['revslider'] ? '<div class="cooked-recipe-gallery-revslider">' . do_shortcode('[rev_slider alias="' . intval( $recipe_settings['gallery']['revslider'] ) . '"]') . '</div>' : '' );
412 break;
413
414 endswitch;
415
416 endif;
417
418 return false;
419 }
420
421 public function cooked_info_shortcode($atts, $content = null) {
422 global $recipe, $recipe_settings, $_cooked_settings;
423
424 if ( !isset($recipe_settings['id']) && isset($recipe->ID) ):
425 $recipe_settings['id'] = $recipe->ID;
426 elseif ( !isset($recipe_settings['id']) ):
427 global $post;
428 $recipe_settings['id'] = $post->ID;
429 endif;
430
431 // Shortcode Attributes
432 $atts = shortcode_atts([
433 'left' => false,
434 'right' => false,
435 'include' => false,
436 'exclude' => false,
437 ], $atts);
438
439 $left = $atts['left'] ? array_map( 'trim', explode( ',', Cooked_Functions::sanitize_text_field($atts['left']) ) ) : false;
440 $right = $atts['right'] ? array_map( 'trim', explode( ',', Cooked_Functions::sanitize_text_field($atts['right']) ) ) : false;
441 $include = $atts['include'] ? array_map( 'trim', explode( ',', Cooked_Functions::sanitize_text_field($atts['include']) ) ) : false;
442 $exclude = $atts['exclude'] ? array_map( 'trim', explode( ',', Cooked_Functions::sanitize_text_field($atts['exclude']) ) ) : false;
443
444 $default_info_array = apply_filters( 'cooked_default_info_array', [
445 'author' => __('Author', 'cooked'),
446 'difficulty_level' => __('Difficulty', 'cooked'),
447 'servings' => __('Yields', 'cooked'),
448 'prep_time' => __('Prep Time', 'cooked'),
449 'cook_time' => __('Cook Time', 'cooked'),
450 'total_time' => __('Total Time', 'cooked'),
451 'taxonomies' => !empty($_cooked_settings['recipe_taxonomies']) ? $_cooked_settings['recipe_taxonomies'] : []
452 ]);
453
454 if ( $left ):
455 // Left Content
456 foreach( $left as $val ):
457 $info_array['left'][$val] = isset( $default_info_array[$val] ) ? $default_info_array[$val] : '';
458 endforeach;
459 if ( $right ):
460 // Right Content
461 foreach( $right as $val ):
462 $info_array['right'][$val] = isset( $default_info_array[$val] ) ? $default_info_array[$val] : '';
463 endforeach;
464 endif;
465 elseif ( $right ):
466 // Right Content
467 foreach( $right as $val ):
468 $info_array['right'][$val] = isset( $default_info_array[$val] ) ? $default_info_array[$val] : '';
469 endforeach;
470 elseif ( $include ):
471 // Include Content (left)
472 foreach( $include as $val ):
473 $info_array[$val] = isset( $default_info_array[$val] ) ? $default_info_array[$val] : '';
474 endforeach;
475 elseif ( $exclude ):
476 // Exclude Content (left)
477 $info_array = $default_info_array;
478 foreach( $exclude as $val ):
479 unset($info_array[$val]);
480 endforeach;
481 else:
482 $info_array = $default_info_array;
483 endif;
484
485 ob_start();
486
487 if ( !empty( $info_array ) ):
488
489 $available_methods = apply_filters( 'cooked_available_info_shortcode_methods', [
490 'cooked_info_author' => 'Cooked_Recipes',
491 'cooked_info_difficulty' => 'Cooked_Recipes',
492 'cooked_info_servings' => 'Cooked_Recipes',
493 'cooked_info_print' => 'Cooked_Recipes',
494 'cooked_info_fullscreen' => 'Cooked_Recipes',
495 'cooked_info_prep_time' => 'Cooked_Recipes',
496 'cooked_info_cook_time' => 'Cooked_Recipes',
497 'cooked_info_total_time' => 'Cooked_Recipes',
498 'cooked_info_taxonomies' => 'Cooked_Recipes'
499 ]);
500
501 if ( isset($info_array['left']) && !empty($info_array['left']) ):
502 echo '<section class="cooked-left">';
503 foreach( $info_array['left'] as $name => $val ):
504 $function = 'cooked_info_' . $name;
505 if ( array_key_exists( $function, $available_methods ) ):
506 $class = ( $available_methods[$function] == 'Cooked_Recipes' ? $this : $available_methods[$function] );
507 if ( method_exists( $class, $function ) ):
508 $class::$function( $recipe_settings );
509 endif;
510 endif;
511 endforeach;
512 echo '</section>';
513
514 if ( isset($info_array['right']) && !empty($info_array['right']) ):
515 echo '<section class="cooked-right">';
516 foreach( $info_array['right'] as $name => $val ):
517 $function = 'cooked_info_' . $name;
518 if ( array_key_exists( $function, $available_methods ) ):
519 $class = ( $available_methods[$function] == 'Cooked_Recipes' ? $this : $available_methods[$function] );
520 if ( method_exists( $class, $function ) ):
521 $class::$function( $recipe_settings );
522 endif;
523 endif;
524 endforeach;
525 echo '</section>';
526 endif;
527
528 elseif ( isset($info_array['right']) && !empty($info_array['right']) ):
529
530 echo '<section class="cooked-right">';
531 foreach ( $info_array['right'] as $name => $val ):
532 $function = 'cooked_info_' . $name;
533 if ( array_key_exists( $function, $available_methods ) ):
534 $class = ( $available_methods[$function] == 'Cooked_Recipes' ? $this : $available_methods[$function] );
535 if ( method_exists( $class, $function ) ):
536 $class::$function( $recipe_settings );
537 endif;
538 endif;
539 endforeach;
540 echo '</section>';
541
542 else:
543
544 foreach ( $info_array as $name => $val ):
545 $function = 'cooked_info_' . $name;
546 if ( array_key_exists( $function, $available_methods ) ):
547 $class = ( $available_methods[$function] == 'Cooked_Recipes' ? $this : $available_methods[$function] );
548 if ( method_exists( $class, $function ) ):
549 $class::$function( $recipe_settings );
550 endif;
551 endif;
552 endforeach;
553
554 endif;
555
556 endif;
557
558 $cooked_info_html = ob_get_clean();
559
560 if ( $cooked_info_html ):
561 add_filter('wp_kses_allowed_html', [$this, 'cooked_kses_servings_switcher']);
562 add_filter('wp_kses_allowed_html', [$this, 'cooked_kses_cooked_donut']);
563 $cooked_info_html = '<div class="cooked-recipe-info cooked-clearfix">' . wp_kses_post( $cooked_info_html ) . '</div>';
564 $cooked_info_html = apply_filters( 'cooked_info_shortcode_output', $cooked_info_html, $recipe_settings );
565 return $cooked_info_html;
566 //return '<div class="cooked-recipe-info cooked-clearfix">' . $cooked_info_html . '</div>'; // @TODO: Fix this
567 endif;
568 }
569
570 function cooked_kses_servings_switcher($tags) {
571 $tags['select'] = [
572 'name' => true,
573 'id' => true,
574 'class' => true,
575 ];
576 $tags['option'] = [
577 'value' => true,
578 'selected' => true
579 ];
580 return $tags;
581 }
582
583 function cooked_kses_cooked_donut($tags) {
584 $tags['script'] = [
585 'type' => true
586 ];
587 return $tags;
588 }
589
590 public static function cooked_info_author() {
591 global $recipe_settings, $_cooked_settings;
592
593 if (in_array('author', $_cooked_settings['recipe_info_display_options'])) {
594 $browse_page_id = isset($_cooked_settings['browse_page']) && $_cooked_settings['browse_page'] ? $_cooked_settings['browse_page'] : false;
595 $front_page_id = get_option( 'page_on_front' );
596 $browse_page_url = $browse_page_id ? get_permalink( $browse_page_id ) : false;
597 $author = !empty($recipe_settings['author']) ? $recipe_settings['author'] : false;
598
599 if ( !empty($author['id']) && !empty($browse_page_id) ) {
600 // Generate author slug from user_nicename, fallback to user ID if nicename is empty
601 if ( !empty($author['user_nicename']) ) {
602 $author_slug = urlencode(sanitize_title($author['user_nicename']));
603 } else {
604 // Fallback to user ID if user_nicename is empty or missing
605 $author_slug = $author['id'];
606 }
607
608 $permalink = $front_page_id != $browse_page_id && get_option('permalink_structure') ?
609 esc_url( untrailingslashit( $browse_page_url ) . '/' . $_cooked_settings['recipe_author_permalink'] . '/' . trailingslashit( $author_slug ) ) :
610 esc_url( trailingslashit( get_home_url() ) . 'index.php?page_id=' . $_cooked_settings['browse_page'] . '&recipe_author=' . $author['id'] );
611
612 $permalink = apply_filters( 'cooked_author_permalink', $permalink, $author['id'], $author_slug );
613 } else {
614 $permalink = false;
615 }
616
617 $author_links = isset( $_cooked_settings['disable_author_links'][0] ) && $_cooked_settings['disable_author_links'][0] == 'disabled' ? false : true;
618 $clickable = isset($_cooked_settings['advanced']) && !empty($_cooked_settings['advanced']) && in_array( 'disable_public_recipes', $_cooked_settings['advanced'] ) || !$author_links ? false : true;
619 $hide_avatars = isset( $_cooked_settings['hide_author_avatars'][0] ) && $_cooked_settings['hide_author_avatars'][0] == 'hidden' ? true : false;
620
621 echo '<span class="cooked-author' . ( $hide_avatars ? ' cooked-no-avatar' : '' ) . '">';
622 echo !$hide_avatars ? '<span class="cooked-author-avatar">' . ( !empty($author) ? wp_kses_post( $author['profile_photo'] ) : '' ) . '</span>' : '';
623 echo '<strong class="cooked-meta-title">' . __('Author', 'cooked') . '</strong>' . ( $clickable && $permalink ? '<a href="' . esc_url( $permalink ) . '">' : '' ) . (!empty($author) ? $author['name'] : '') . ( $clickable && $permalink ? '</a>' : '' );
624 echo '</span>';
625
626 wp_reset_postdata();
627 }
628 }
629
630 public static function cooked_info_difficulty( $recipe ) {
631 global $_cooked_settings;
632
633 if (in_array('difficulty_level', $_cooked_settings['recipe_info_display_options']) && isset($recipe['difficulty_level']) && $recipe['difficulty_level']) {
634 $dl_html = '<span class="cooked-difficulty-level"><strong class="cooked-meta-title">' . __('Difficulty','cooked') . '</strong>' . Cooked_Recipes::difficulty_level( $recipe['difficulty_level'] ) . '</span>';
635 echo apply_filters( 'cooked_show_difficulty_level', $dl_html, $recipe['difficulty_level'] );
636 }
637 }
638
639 public static function cooked_info_servings( $recipe ) {
640 global $_cooked_settings;
641
642 if (in_array('servings', $_cooked_settings['recipe_info_display_options'])) {
643 $servings = isset($recipe['nutrition']['servings']) && $recipe['nutrition']['servings'] ? $recipe['nutrition']['servings'] : 1;
644 Cooked_Recipes::serving_size_switcher( $servings );
645 }
646 }
647
648 public static function cooked_info_print() {
649 global $recipe_settings, $_cooked_settings;
650
651 $recipe_post_url = get_permalink( $recipe_settings['id'] );
652 $query_args['print'] = 1;
653 $servings = (float)esc_html( get_query_var( 'servings', false ) );
654 $query_args['servings'] = !empty($servings) ? $servings : false;
655 echo '<span class="cooked-print"><a aria-label="' . __('Print', 'cooked') . '" target="_blank" rel="nofollow" href="' . add_query_arg( $query_args, $recipe_post_url ) . '" class="cooked-print-icon"><i class="cooked-icon cooked-icon-print"></i></a></span>';
656 }
657
658 public static function cooked_info_fullscreen() {
659 global $recipe_settings, $_cooked_settings;
660
661 echo '<span aria-label="' . __('Fullscreen', 'cooked') . '" role="button" class="cooked-fsm-button" data-recipe-id="' . esc_attr( $recipe_settings['id'] ) . '"><i class="cooked-icon cooked-icon-fullscreen"></i></span>';
662 wp_enqueue_script('cooked-nosleep');
663 }
664
665 public static function cooked_info_prep_time( $recipe ) {
666 global $_cooked_settings;
667
668 if (!empty($_cooked_settings['recipe_info_display_options']) && in_array('timing_prep',$_cooked_settings['recipe_info_display_options'])) {
669 $prep_time = isset($recipe['prep_time']) ? esc_html( $recipe['prep_time'] ) : 0;
670 echo $prep_time ? '<span class="cooked-prep-time cooked-time"><span class="cooked-time-icon"><i class="cooked-icon cooked-icon-clock"></i></span><strong class="cooked-meta-title">' . __('Prep Time','cooked') . '</strong>' . Cooked_Measurements::time_format( $prep_time ) . '</span>' : '';
671 }
672 }
673
674 public static function cooked_info_cook_time( $recipe ) {
675 global $_cooked_settings;
676
677 if (!empty($_cooked_settings['recipe_info_display_options']) && in_array('timing_cook', $_cooked_settings['recipe_info_display_options'])) {
678 $cook_time = isset($recipe['cook_time']) ? esc_html( $recipe['cook_time'] ) : 0;
679 echo $cook_time ? '<span class="cooked-cook-time cooked-time"><span class="cooked-time-icon"><i class="cooked-icon cooked-icon-clock"></i></span><strong class="cooked-meta-title">' . __('Cook Time','cooked') . '</strong>' . Cooked_Measurements::time_format( $cook_time ) . '</span>' : '';
680 }
681 }
682
683 public static function cooked_info_total_time( $recipe ) {
684 global $_cooked_settings;
685
686 if (!empty($_cooked_settings['recipe_info_display_options']) && in_array('timing_total',$_cooked_settings['recipe_info_display_options'])) {
687 $total_time = isset($recipe['total_time']) ? esc_html( $recipe['total_time'] ) : 0;
688
689 if ( $total_time ) {
690 echo $total_time ? '<span class="cooked-total-time cooked-time"><span class="cooked-time-icon"><i class="cooked-icon cooked-icon-clock"></i></span><strong class="cooked-meta-title">' . __('Total Time','cooked') . '</strong>' . Cooked_Measurements::time_format( $total_time ) . '</span>' : '';
691 } else {
692 $prep_time = isset($recipe['prep_time']) ? esc_html( $recipe['prep_time'] ) : 0;
693 $cook_time = isset($recipe['cook_time']) ? esc_html( $recipe['cook_time'] ) : 0;
694
695 if ( $prep_time && $cook_time ) {
696 $total_time = $prep_time + $cook_time;
697 echo $total_time ? '<span class="cooked-total-time cooked-time"><span class="cooked-time-icon"><i class="cooked-icon cooked-icon-clock"></i></span><strong class="cooked-meta-title">' . __('Total Time','cooked') . '</strong>' . Cooked_Measurements::time_format( $total_time ) . '</span>' : '';
698 }
699 }
700 }
701 }
702
703 public static function cooked_info_taxonomies() {
704 global $recipe_settings, $_cooked_settings, $clickable;
705
706 $clickable = isset($_cooked_settings['advanced']) && !empty($_cooked_settings['advanced']) && in_array( 'disable_public_recipes', $_cooked_settings['advanced'] ) ? false : true;
707
708 if (!empty($_cooked_settings['recipe_info_display_options']) && in_array('taxonomies', $_cooked_settings['recipe_info_display_options'])):
709
710 global $recipe_terms_list;
711 $recipe_terms_list = '';
712
713 do_action( 'cooked_info_taxonomies_shortcode_before', $recipe_settings );
714
715 if (!empty($_cooked_settings['recipe_taxonomies']) && in_array('cp_recipe_category', $_cooked_settings['recipe_taxonomies'])):
716 if ( $clickable ):
717 $recipe_terms_list .= get_the_term_list( $recipe_settings['id'], 'cp_recipe_category', '<span class="cooked-taxonomy cooked-category"><strong class="cooked-meta-title">' . __('Category','cooked') . '</strong>', ', ', '</span>' );
718 else:
719 $_recipe_terms_array = [];
720 $recipe_terms_list .= '<span class="cooked-taxonomy cooked-category"><strong class="cooked-meta-title">' . __('Category','cooked') . '</strong>';
721 $recipe_terms_array = wp_get_object_terms( $recipe_settings['id'], 'cp_recipe_category' );
722 if ( !empty($recipe_terms_array) ):
723 if ( ! is_wp_error( $recipe_terms_array ) ):
724 foreach( $recipe_terms_array as $recipe_term ):
725 $_recipe_terms_array[] = esc_html( $recipe_term->name );
726 endforeach;
727 endif;
728 endif;
729 $recipe_terms_list .= implode( ', ', $_recipe_terms_array );
730 $recipe_terms_list .= '</span>';
731 endif;
732 endif;
733
734 do_action( 'cooked_info_taxonomies_shortcode_after', $recipe_settings );
735
736 if ( $recipe_terms_list ):
737 echo wp_filter_post_kses( $recipe_terms_list );
738 endif;
739
740 endif;
741 }
742
743 public function cooked_excerpt_shortcode($atts, $content = null) {
744 global $_cooked_settings, $recipe_settings;
745
746 if (isset($_cooked_settings['recipe_info_display_options']) && is_array($_cooked_settings['recipe_info_display_options']) && in_array('excerpt', $_cooked_settings['recipe_info_display_options'])) {
747 ob_start();
748
749 if (isset($recipe_settings['excerpt']) && $recipe_settings['excerpt']) {
750 $excerpt = Cooked_Recipes::format_content($recipe_settings['excerpt']);
751 echo '<div class="cooked-recipe-excerpt cooked-clearfix">' . do_shortcode($excerpt) . '</div>';
752 }
753
754 return ob_get_clean();
755 }
756 }
757
758 public function cooked_notes_shortcode($atts, $content = null) {
759 global $_cooked_settings, $recipe_settings;
760
761 // Shortcode Attributes
762 $atts = shortcode_atts([
763 'show_header' => false,
764 ], $atts);
765
766 $show_header = Cooked_Functions::sanitize_text_field($atts['show_header']);
767 $show_header = !$show_header || $show_header == 'false' ? false : $show_header;
768
769 if (isset($_cooked_settings['recipe_info_display_options']) && is_array($_cooked_settings['recipe_info_display_options']) && in_array('notes', $_cooked_settings['recipe_info_display_options'])) {
770 ob_start();
771
772 if (isset($recipe_settings['notes']) && !empty($recipe_settings['notes'])) {
773 $notes = Cooked_Recipes::format_content($recipe_settings['notes']);
774 $show_header = $show_header ? '<div class="cooked-heading">' . __('Notes', 'cooked') . '</div>' : '';
775
776 echo '<div class="cooked-recipe-notes cooked-clearfix">';
777 echo $show_header;
778 echo do_shortcode($notes);
779 echo '</div>';
780 }
781
782 return ob_get_clean();
783 }
784 }
785
786 public function cooked_title_shortcode($atts, $content = null) {
787 global $recipe, $recipe_settings;
788
789 if (!isset($recipe_settings['id'])) {
790 $recipe_settings['id'] = $recipe->ID;
791 }
792
793 return get_the_title($recipe_settings['id']);
794 }
795
796 public function cooked_image_shortcode($atts, $content = null) {
797 global $recipe, $recipe_settings;
798
799 if ( !isset($recipe_settings['id']) ):
800 $recipe_settings['id'] = $recipe->ID;
801 endif;
802
803 $recipe = get_post( $recipe_settings['id'] );
804 wp_reset_postdata();
805
806 ob_start();
807
808 if (has_post_thumbnail($recipe)) :
809 echo '<div class="cooked-post-featured-image">';
810 echo get_the_post_thumbnail( $recipe, 'cooked-large' );
811 echo '</div>';
812 endif;
813
814 return ob_get_clean();
815 }
816
817 public function cooked_ingredients_shortcode($atts, $content = null) {
818 global $recipe_settings;
819
820 // Shortcode Attributes
821 $atts = shortcode_atts([
822 'checkboxes' => true,
823 ], $atts);
824
825 $checkboxes = Cooked_Functions::sanitize_text_field($atts['checkboxes']);
826 $checkboxes = !$checkboxes || $checkboxes == 'false' ? false : $checkboxes;
827
828 ob_start();
829
830 do_action( 'cooked_ingredients_shortcode_before', $recipe_settings );
831
832 if ( isset($recipe_settings['ingredients']) && !empty($recipe_settings['ingredients']) ):
833 echo '<div class="cooked-recipe-ingredients">';
834 foreach ( $recipe_settings['ingredients'] as $ing ):
835 Cooked_Recipes::single_ingredient( $ing, $checkboxes );
836 endforeach;
837 echo '</div>';
838 endif;
839
840 do_action( 'cooked_ingredients_shortcode_after', $recipe_settings );
841
842 return ob_get_clean();
843 }
844
845 public function cooked_directions_shortcode($atts, $content = null) {
846 global $recipe_settings;
847
848 // Shortcode Attributes
849 $atts = shortcode_atts(apply_filters('cooked_directions_shortcode_atts', [
850 'numbers' => true,
851 ]), $atts);
852
853 $step = 0;
854 $numbers = Cooked_Functions::sanitize_text_field( $atts['numbers'] );
855 $numbers = !$numbers || $numbers == 'false' ? false : $numbers;
856
857 ob_start();
858
859 if (isset($recipe_settings['directions']) && !empty($recipe_settings['directions'])) {
860 echo '<div class="cooked-recipe-directions">';
861 foreach ($recipe_settings['directions'] as $dir) {
862 if (!isset($dir['section_heading_name'])) {
863 $step++;
864 $number = $numbers ? $step : false;
865 } else {
866 $number = 0;
867 }
868
869 Cooked_Recipes::single_direction($dir, $number, false, $step, $atts);
870 }
871 echo '</div>';
872 }
873
874 return ob_get_clean();
875 }
876
877 public function cooked_nutrition_shortcode($atts, $content = null) {
878 global $_cooked_settings, $recipe_settings;
879
880 // Shortcode Attributes
881 $atts = shortcode_atts([
882 'id' => false,
883 'float' => false,
884 ], $atts);
885
886 if ( isset( $atts['id'] ) && $atts['id'] ):
887 $recipe_settings = Cooked_Recipes::get( intval( $atts['id'] ), true );
888 else:
889 $recipe_settings = !empty($recipe_settings) ? $recipe_settings : false;
890 endif;
891
892 $float = Cooked_Functions::sanitize_text_field($atts['float']);
893
894 $_nf_fields = Cooked_Measurements::nutrition_facts();
895 $nutrition_facts = isset($recipe_settings['nutrition']) && !empty($recipe_settings['nutrition']) ? $recipe_settings['nutrition'] : false;
896
897 ob_start();
898
899 if ( $nutrition_facts ):
900
901 $servings_change = (float)esc_html( get_query_var( 'servings', $recipe_settings['nutrition']['servings'] ) );
902
903 $top_facts = $_nf_fields['top'];
904 if (!empty($top_facts)):
905
906 // Start output buffer for top facts.
907 ob_start();
908
909 echo '<div class="cooked-nut-servings">';
910 foreach ( $top_facts as $slug => $nf ):
911 if ( $slug === 'serving_size' ):
912 echo '<div class="cooked-serving-size"><strong>' . esc_html($nf['name']) . '</strong> ';
913 echo '<p class="cooked-right"><strong class="cooked-nut-label" data-labeltype="' . esc_attr($slug) . '">' . esc_html( isset($nutrition_facts[$slug]) ? $nutrition_facts[$slug] : '' ) . '</strong></p>';
914 echo '</div>';
915 else:
916 echo '<p><strong class="cooked-nut-label" data-labeltype="' . esc_attr( $slug ) . '">' . $servings_change . '</strong> ' . esc_html(strtolower($nf['name'])) . '</p>';
917 endif;
918 endforeach;
919 echo '</div>';
920
921 // Get top facts content from buffer.
922 $top_facts_content = ob_get_clean();
923
924 endif;
925
926 $mid_facts = $_nf_fields['mid'];
927 if (!empty($mid_facts)):
928
929 // Start output buffer for mid-facts.
930 ob_start();
931
932 foreach ( $mid_facts as $slug => $nf ):
933 if ( isset( $nutrition_facts[$slug] ) && $nutrition_facts[$slug] || isset( $nutrition_facts[$slug] ) && $nutrition_facts[$slug] === '0' ):
934 echo '<dt class="cooked-calories no-after"><strong>' . esc_html($nf['name']) . '</strong>';
935 echo '<strong class="cooked-nut-label">' . esc_html( $nutrition_facts[$slug] ) . '</strong>';
936 echo '</dt>';
937 endif;
938 endforeach;
939
940 // Get mid facts content from buffer.
941 $mid_facts_content = ob_get_clean();
942
943 endif;
944
945 $main_facts = $_nf_fields['main'];
946 $nut_loops = 0;
947
948 if (!empty($main_facts)):
949
950 // Start output buffer for main facts.
951 ob_start();
952
953 foreach ( $main_facts as $slug => $nf ):
954
955 if ( isset( $nutrition_facts[$slug] ) && $nutrition_facts[$slug] || isset( $nutrition_facts[$slug] ) && $nutrition_facts[$slug] === '0' ):
956
957 echo '<dt>';
958 echo '<strong>' . $nf['name'] . '</strong> <strong class="cooked-nut-label">' . esc_html( $nutrition_facts[$slug] ) . '</strong>' . ( isset($nf['measurement']) ? '<strong class="cooked-nut-label cooked-nut-measurement">' . esc_html( $nf['measurement'] ) . '</strong>' : '' );
959 echo ( isset( $nf['pdv'] ) && $nutrition_facts[$slug] ? '<strong class="cooked-nut-right"><span class="cooked-nut-percent">' . ceil( ( esc_html( $nutrition_facts[$slug] ) / $nf['pdv'] ) * 100 ) . '</span>%</strong>' : '' );
960
961 if ( isset($nf['subs']) ):
962 foreach( $nf['subs'] as $sub_slug => $sub_nf ):
963 if ( isset( $nutrition_facts[$sub_slug] ) && $nutrition_facts[$sub_slug] || isset( $nutrition_facts[$sub_slug] ) && $nutrition_facts[$sub_slug] === '0' ):
964 echo '<dl>';
965 if ($sub_slug === 'trans_fat'):
966 echo '<dt>';
967 echo $sub_nf['nutrition_info_name'] . ' <strong class="cooked-nut-label" data-labeltype="' . esc_attr( $sub_slug ) . '">' . esc_html( $nutrition_facts[$sub_slug] ) . '</strong>' . ( isset($sub_nf['measurement']) ? '<strong class="cooked-nut-label" data-labeltype="' . esc_attr( $sub_slug ) . '_measurement">' . esc_html($sub_nf['measurement']) . '</strong>' : '' );
968 echo '</dt>';
969 elseif ($sub_slug === 'added_sugars'):
970 echo '<dl><dt>';
971 echo __('Includes', 'cooked') . ' <strong class="cooked-nut-label" data-labeltype="' . esc_attr( $sub_slug ) . '">' . esc_html( $nutrition_facts[$sub_slug] ) . '</strong>' . ( isset($sub_nf['measurement']) ? '<strong class="cooked-nut-label" data-labeltype="' . esc_attr( $sub_slug ) . '_measurement">' . esc_html($sub_nf['measurement']) . '</strong>' : '' ) . ' ' . esc_html($sub_nf['name']);
972 echo ( isset( $sub_nf['pdv'] ) ? '<strong class="cooked-nut-right"><span class="cooked-nut-percent" data-pdv="' . esc_attr($sub_nf['pdv']) . '" data-labeltype="' . esc_attr($sub_slug) . '">' . ceil( ( esc_html( $nutrition_facts[$sub_slug] ) / $sub_nf['pdv'] ) * 100 ) . '</span>%</strong>' : '' );
973 echo '</dt></dl>';
974 else:
975 echo '<dt>';
976 echo esc_html( $sub_nf['name'] ) . ' <strong class="cooked-nut-label">' . esc_html( $nutrition_facts[$sub_slug] ) . '</strong>' . ( isset($sub_nf['measurement']) ? '<strong class="cooked-nut-label cooked-nut-measurement">' . esc_html( $sub_nf['measurement'] ) . '</strong>' : '' );
977 echo ( isset( $sub_nf['pdv'] ) && $nutrition_facts[$sub_slug] ? '<strong class="cooked-nut-right"><span class="cooked-nut-percent">' . ceil( ( esc_html( $nutrition_facts[$sub_slug] ) / $sub_nf['pdv'] ) * 100 ) . '</span>%</strong>' : '' );
978 echo '</dt>';
979 endif;
980 echo '</dl>';
981 endif;
982 endforeach;
983 endif;
984
985 echo '</dt>';
986
987 endif;
988
989 endforeach;
990
991 // Get main facts content from buffer.
992 $main_facts_content = ob_get_clean();
993
994 endif;
995
996 $bottom_facts = $_nf_fields['bottom'];
997
998 if (!empty($bottom_facts)):
999
1000 // Start output buffer for bottom facts.
1001 ob_start();
1002
1003 foreach ( $bottom_facts as $slug => $nf ):
1004 if ( isset( $nutrition_facts[$slug] ) && $nutrition_facts[$slug] || isset( $nutrition_facts[$slug] ) && $nutrition_facts[$slug] === '0' ):
1005 echo '<dt>';
1006 echo '<strong>' . esc_html($nf['name']) . ' <span class="cooked-nut-label" data-labeltype="' . esc_attr( $slug ) . '">' . esc_html( $nutrition_facts[$slug] ) . '</span>' . ( isset($nf['measurement']) ? '<span class="cooked-nut-label" data-labeltype="' . esc_attr( $slug ) . '_measurement">' . esc_html($nf['measurement']) . '</span>' : '' );
1007 echo ( isset( $nf['pdv'] ) ? '<strong class="cooked-nut-right"><span class="cooked-nut-percent" data-pdv="' . esc_attr($nf['pdv']) . '" data-labeltype="' . esc_attr($slug) . '">' . ceil( ( esc_html( $nutrition_facts[$slug] ) / $nf['pdv'] ) * 100 ) . '</span>%</strong>' : '' );
1008 echo '</dt>';
1009 endif;
1010 endforeach;
1011
1012 // Get bottom facts content from buffer.
1013 $bottom_facts_content = ob_get_clean();
1014
1015 endif;
1016
1017 // Start a buffer for all nutrition facts content
1018 ob_start();
1019
1020 if ( isset($top_facts_content) && $top_facts_content ):
1021 echo wp_kses_post( $top_facts_content );
1022 endif;
1023
1024 if ( isset($mid_facts_content) && $mid_facts_content || isset($main_facts_content) && $main_facts_content ):
1025
1026 echo '<hr class="cooked-nut-hr" />';
1027 echo '<dl>';
1028
1029 echo '<dt><strong class="cooked-nut-heading">' . __('Amount per serving','cooked') . '</strong></dt>';
1030
1031 if ( isset($mid_facts_content) && $mid_facts_content ):
1032 echo '<section class="cooked-clearfix">';
1033 echo wp_kses_post( $mid_facts_content );
1034 echo '</section>';
1035 endif;
1036
1037 if ( isset($main_facts_content) && $main_facts_content ):
1038 echo '<dt class="cooked-nut-spacer"></dt>';
1039 echo '<dt class="cooked-nut-no-border"><strong class="cooked-nut-heading cooked-nut-right">' . __('% Daily Value *','cooked'). '</strong></dt>';
1040 echo '<section class="cooked-clearfix">';
1041 echo wp_kses_post( $main_facts_content );
1042 echo '</section>';
1043 endif;
1044
1045 echo '</dl>';
1046 echo '<hr class="cooked-nut-hr" />';
1047
1048 endif;
1049
1050 if ( isset($bottom_facts_content) && $bottom_facts_content ):
1051 echo '<dl class="cooked-nut-bottom cooked-clearfix">';
1052 echo wp_kses_post( $bottom_facts_content );
1053 echo '</dl>';
1054 endif;
1055
1056 $nutrition_facts_content = ob_get_clean();
1057
1058 if ( isset($nutrition_facts_content) && $nutrition_facts_content ):
1059
1060 echo '<div class="cooked-nutrition-label' . ( $float ? ' cooked-float-'.esc_attr( $float ) : '' ) . '">';
1061 echo '<div class="cooked-nutrition-title">' . __('Nutrition Facts', 'cooked') . '</div>';
1062 echo wp_kses_post( $nutrition_facts_content );
1063 if ( isset($main_facts_content) && $main_facts_content || isset($bottom_facts_content) && $bottom_facts_content ):
1064 echo '<div class="cooked-nut-spacer"></div>';
1065 echo '<p class="cooked-daily-value-text">* ' . __('The % Daily Value (DV) tells you how much a nutrient in a serving of food contributes to a daily diet. 2,000 calories a day is used for general nutrition advice.','cooked') . '</p>';
1066 endif;
1067
1068 // Add the Edamam attribution "Powered by Edamam" if the Edamam API is enabled.
1069 // More Information: https://developer.edamam.com/attribution
1070 if (!empty($_cooked_settings['enable_nutrition_api'])) :
1071 echo '<div class="cooked-nutrition-edamam">';
1072 do_action( 'cooked_nutrition_facts_powered_by_edamam' );
1073 echo '</div>';
1074 endif;
1075
1076 echo '</div>';
1077
1078 endif;
1079
1080 endif;
1081
1082 return ob_get_clean();
1083 }
1084 }
1085