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