PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.4
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.4
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / vendor / wordproof / wordpress-sdk / app / Controllers / NoticeController.php

NoticeController.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.4, at vendor/wordproof/wordpress-sdk/app/Controllers/NoticeController.php

90 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WordProof\SDK\Controllers;
4
5 use WordProof\SDK\Helpers\ClassicNoticeHelper;
6 use WordProof\SDK\Helpers\TransientHelper;
7 use WordProof\SDK\Translations\TranslationsInterface;
8
9 class NoticeController
10 {
11 /**
12 * @var string[] The screens on which notices should be rendered.
13 */
14 private $screens = ['post'];
15
16 /**
17 * @var TranslationsInterface The translations objects,
18 */
19 private $translations;
20
21 public function __construct(TranslationsInterface $translations)
22 {
23 $this->translations = $translations;
24 }
25
26 /**
27 * Showing notices for the classic editor and delete them so they are only shown once.
28 *
29 * @action admin_notices
30 */
31 public function show()
32 {
33 $screen = get_current_screen();
34
35 if (!in_array($screen->base, $this->screens, true)) {
36 return;
37 }
38
39 $notice = TransientHelper::getOnce(ClassicNoticeHelper::$transientKey);
40
41 if (!isset($notice) || !$notice) {
42 return;
43 }
44
45 switch ($notice) {
46 case 'no_balance':
47 $type = 'error';
48 $message = $this->translations->getNoBalanceNotice();
49 $buttonText = $this->translations->getOpenSettingsButtonText();
50 $buttonEventName = 'wordproof:open_settings';
51 break;
52 case 'timestamp_success':
53 $type = 'success';
54 $message = $this->translations->getTimestampSuccessNotice();
55 break;
56 case 'timestamp_failed':
57 $type = 'error';
58 $message = $this->translations->getTimestampFailedNotice();
59 break;
60 case 'not_authenticated':
61 $type = 'error';
62 $message = $this->translations->getNotAuthenticatedNotice();
63 $buttonText = $this->translations->getOpenAuthenticationButtonText();
64 $buttonEventName = 'wordproof:open_authentication';
65 break;
66 default:
67 break;
68 }
69
70 if (isset($message) && isset($type)) {
71 $noticeClass = 'notice-' . $type;
72 echo \sprintf(
73 '<div class="notice %1$s is-dismissible"><p>%2$s</p>',
74 esc_attr($noticeClass),
75 esc_html($message)
76 );
77
78 if (isset($buttonText) && isset($buttonEventName)) {
79 echo \sprintf(
80 '<button class="button button-primary" onclick="window.dispatchEvent( new window.CustomEvent( \'%2$s\' ) )">%1$s</button>',
81 esc_html($buttonText),
82 esc_attr($buttonEventName)
83 );
84 }
85
86 echo '</div>';
87 }
88 }
89 }
90