partial-alerts-template.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin
  6. *
  7. * @uses string $type
  8. * @uses string $dashicon
  9. * @uses string $i18n_title
  10. * @uses string $i18n_issues
  11. * @uses string $i18n_no_issues
  12. * @uses string $i18n_muted_issues_title
  13. * @uses int $active_total
  14. * @uses int $dismissed_total
  15. * @uses int $total
  16. * @uses array $active
  17. * @uses array $dismissed
  18. */
  19. if ( ! function_exists( '_yoast_display_alerts' ) ) {
  20. /**
  21. * Create the alert HTML with restore/dismiss button.
  22. *
  23. * @param array $list List of alerts.
  24. * @param string $status Status of the alerts (active/dismissed).
  25. *
  26. * @return string The output to render.
  27. */
  28. function _yoast_display_alerts( $list, $status ) {
  29. $alerts = '';
  30. foreach ( $list as $notification ) {
  31. switch ( $status ) {
  32. case 'active':
  33. $button = sprintf(
  34. '<button type="button" class="button dismiss"><span class="screen-reader-text">%1$s</span><span class="dashicons dashicons-hidden"></span></button>',
  35. esc_html__( 'Hide this item.', 'wordpress-seo' )
  36. );
  37. break;
  38. case 'dismissed':
  39. $button = sprintf(
  40. '<button type="button" class="button restore"><span class="screen-reader-text">%1$s</span><span class="dashicons yoast-svg-icon-eye"></span></button>',
  41. esc_html__( 'Show this item.', 'wordpress-seo' )
  42. );
  43. break;
  44. }
  45. $alerts .= sprintf(
  46. '<div class="yoast-alert-holder" id="%1$s" data-nonce="%2$s" data-json="%3$s">%4$s%5$s</div>',
  47. esc_attr( $notification->get_id() ),
  48. esc_attr( $notification->get_nonce() ),
  49. esc_attr( $notification->get_json() ),
  50. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: Needs to be fixed in https://github.com/Yoast/wordpress-seo-premium/issues/2548.
  51. $notification,
  52. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: $button is properly escaped.
  53. $button
  54. );
  55. }
  56. return $alerts;
  57. }
  58. }
  59. $wpseo_i18n_summary = $i18n_issues;
  60. if ( ! $active ) {
  61. $dashicon = 'yes';
  62. $wpseo_i18n_summary = $i18n_no_issues;
  63. }
  64. ?>
  65. <h3 class="yoast-alerts-header" id="<?php echo esc_attr( 'yoast-' . $type . '-header' ); ?>">
  66. <span class="dashicons <?php echo esc_attr( 'dashicons-' . $dashicon ); ?>"></span>
  67. <?php echo esc_html( $i18n_title ); ?> (<?php echo (int) $active_total; ?>)
  68. </h3>
  69. <div id="<?php echo esc_attr( 'yoast-' . $type ); ?>">
  70. <?php if ( $total ) : ?>
  71. <p><?php echo esc_html( $wpseo_i18n_summary ); ?></p>
  72. <div class="container yoast-alerts-active" id="<?php echo esc_attr( 'yoast-' . $type . '-active' ); ?>">
  73. <?php
  74. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: _yoast_display_alerts is considered a safe function.
  75. echo _yoast_display_alerts( $active, 'active' );
  76. ?>
  77. </div>
  78. <?php
  79. if ( $dismissed ) {
  80. $dismissed_paper = new WPSEO_Paper_Presenter(
  81. esc_html( $i18n_muted_issues_title ),
  82. null,
  83. [
  84. 'paper_id' => esc_attr( $type . '-dismissed' ),
  85. 'paper_id_prefix' => 'yoast-',
  86. 'class' => 'yoast-alerts-dismissed',
  87. 'content' => _yoast_display_alerts( $dismissed, 'dismissed' ),
  88. 'collapsible' => true,
  89. 'collapsible_header_class' => 'yoast-alert',
  90. ]
  91. );
  92. // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: current usage is considered safe.
  93. echo $dismissed_paper->get_output();
  94. }
  95. ?>
  96. <?php else : ?>
  97. <p><?php echo esc_html( $i18n_no_issues ); ?></p>
  98. <?php endif; ?>
  99. </div>