Code Duplication    Length = 27-29 lines in 4 locations

projects/plugins/jetpack/modules/shortcodes/recipe.php 4 locations

@@ 344-372 (lines=29) @@
341
	 *
342
	 * @return string HTML for recipe notes shortcode.
343
	 */
344
	public static function recipe_notes_shortcode( $atts, $content = '' ) {
345
		$atts = shortcode_atts(
346
			array(
347
				'title' => '', // string.
348
			),
349
			$atts,
350
			'recipe-notes'
351
		);
352
353
		$html = '';
354
355
		// Print a title if one exists.
356
		if ( '' !== $atts['title'] ) {
357
			$html .= '<h4 class="jetpack-recipe-notes-title">' . esc_html( $atts['title'] ) . '</h4>';
358
		}
359
360
		$html .= '<div class="jetpack-recipe-notes">';
361
362
		// Format content using list functionality, if desired.
363
		$html .= self::output_list_content( $content, 'notes' );
364
365
		$html .= '</div>';
366
367
		// Sanitize html.
368
		$html = wp_kses( $html, self::kses_tags() );
369
370
		// Return the HTML block.
371
		return $html;
372
	}
373
374
	/**
375
	 * Our [recipe-ingredients] shortcode.
@@ 383-409 (lines=27) @@
380
	 *
381
	 * @return string HTML for recipe ingredients shortcode.
382
	 */
383
	public static function recipe_ingredients_shortcode( $atts, $content = '' ) {
384
		$atts = shortcode_atts(
385
			array(
386
				'title' => esc_html_x( 'Ingredients', 'recipe', 'jetpack' ), // string.
387
			),
388
			$atts,
389
			'recipe-ingredients'
390
		);
391
392
		$html = '<div class="jetpack-recipe-ingredients">';
393
394
		// Print a title unless the user has opted to exclude it.
395
		if ( 'false' !== $atts['title'] ) {
396
			$html .= '<h4 class="jetpack-recipe-ingredients-title">' . esc_html( $atts['title'] ) . '</h4>';
397
		}
398
399
		// Format content using list functionality.
400
		$html .= self::output_list_content( $content, 'ingredients' );
401
402
		$html .= '</div>';
403
404
		// Sanitize html.
405
		$html = wp_kses( $html, self::kses_tags() );
406
407
		// Return the HTML block.
408
		return $html;
409
	}
410
411
	/**
412
	 * Our [recipe-nutrition] shortcode.
@@ 420-446 (lines=27) @@
417
	 *
418
	 * @return string HTML for recipe nutrition shortcode.
419
	 */
420
	public static function recipe_nutrition_shortcode( $atts, $content = '' ) {
421
		$atts = shortcode_atts(
422
			array(
423
				'title' => esc_html_x( 'Nutrition', 'recipe', 'jetpack' ), // string.
424
			),
425
			$atts,
426
			'recipe-nutrition'
427
		);
428
429
		$html = '<div class="jetpack-recipe-nutrition p-nutrition nutrition">';
430
431
		// Print a title unless the user has opted to exclude it.
432
		if ( 'false' !== $atts['title'] ) {
433
			$html .= '<h4 class="jetpack-recipe-nutrition-title">' . esc_html( $atts['title'] ) . '</h4>';
434
		}
435
436
		// Format content using list functionality.
437
		$html .= self::output_list_content( $content, 'nutrition' );
438
439
		$html .= '</div>';
440
441
		// Sanitize html.
442
		$html = wp_kses( $html, self::kses_tags() );
443
444
		// Return the HTML block.
445
		return $html;
446
	}
447
448
	/**
449
	 * Reusable function to check for shortened formatting.
@@ 549-575 (lines=27) @@
546
	 *
547
	 * @return string HTML for recipe directions shortcode.
548
	 */
549
	public static function recipe_directions_shortcode( $atts, $content = '' ) {
550
		$atts = shortcode_atts(
551
			array(
552
				'title' => esc_html_x( 'Directions', 'recipe', 'jetpack' ), // string.
553
			),
554
			$atts,
555
			'recipe-directions'
556
		);
557
558
		$html = '<div class="jetpack-recipe-directions e-instructions">';
559
560
		// Print a title unless the user has specified to exclude it.
561
		if ( 'false' !== $atts['title'] ) {
562
			$html .= '<h4 class="jetpack-recipe-directions-title">' . esc_html( $atts['title'] ) . '</h4>';
563
		}
564
565
		// Format content using list functionality.
566
		$html .= self::output_list_content( $content, 'directions' );
567
568
		$html .= '</div>';
569
570
		// Sanitize html.
571
		$html = wp_kses( $html, self::kses_tags() );
572
573
		// Return the HTML block.
574
		return $html;
575
	}
576
577
	/**
578
	 * Outputs time meta tag.