PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.5.1
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.5.1
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 / src / presenters / admin / notice-presenter.php

notice-presenter.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.5.1, at src/presenters/admin/notice-presenter.php

127 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Presenters\Admin;
4
5 use WPSEO_Admin_Asset_Manager;
6 use Yoast\WP\SEO\Presenters\Abstract_Presenter;
7
8 /**
9 * Represents the presenter class for Yoast-styled WordPress admin notices.
10 */
11 class Notice_Presenter extends Abstract_Presenter {
12
13 /**
14 * The title of the admin notice.
15 *
16 * @var string
17 */
18 private $title;
19
20 /**
21 * The content of the admin notice.
22 *
23 * @var string
24 */
25 private $content;
26
27 /**
28 * The filename of the image for the notice. Should be a file in the 'images' folder.
29 *
30 * @var string
31 */
32 private $image_filename;
33
34 /**
35 * HTML string to be displayed after the main content, usually a button.
36 *
37 * @var string
38 */
39 private $button;
40
41 /**
42 * Whether the notice should be dismissible.
43 *
44 * @var bool
45 */
46 private $is_dismissible;
47
48 /**
49 * The id for the div of the notice.
50 *
51 * @var string
52 */
53 private $id;
54
55 /**
56 * An instance of the WPSEO_Admin_Asset_Manager class.
57 *
58 * @var WPSEO_Admin_Asset_Manager
59 */
60 protected $asset_manager;
61
62 /**
63 * Notice_Presenter constructor.
64 *
65 * @param string $title Title of the admin notice.
66 * @param string $content Content of the admin notice.
67 * @param string|null $image_filename Optional. The filename of the image of the admin notice,
68 * should be inside the 'images' folder.
69 * @param string|null $button Optional. An HTML string to be displayed after the main content,
70 * usually a button.
71 * @param bool $is_dismissible Optional. Whether the admin notice should be dismissible.
72 * @param string $id Optional. The id of the notice.
73 */
74 public function __construct( $title, $content, $image_filename = null, $button = null, $is_dismissible = false, $id = '' ) {
75 $this->title = $title;
76 $this->content = $content;
77 $this->image_filename = $image_filename;
78 $this->button = $button;
79 $this->is_dismissible = $is_dismissible;
80 $this->id = $id;
81
82 if ( ! $this->asset_manager ) {
83 $this->asset_manager = new WPSEO_Admin_Asset_Manager();
84 }
85
86 $this->asset_manager->enqueue_style( 'notifications' );
87 }
88
89 /**
90 * Presents the Notice.
91 *
92 * @return string The styled Notice.
93 */
94 public function present() {
95 $dismissible = ( $this->is_dismissible ) ? ' is-dismissible' : '';
96 $id = ( $this->id ) ? ' id="' . $this->id . '"' : '';
97
98 // WordPress admin notice.
99 $out = '<div' . $id . ' class="notice notice-yoast yoast' . $dismissible . '">';
100 $out .= '<div class="notice-yoast__container">';
101
102 // Header.
103 $out .= '<div>';
104 $out .= '<div class="notice-yoast__header">';
105 $out .= '<span class="yoast-icon"></span>';
106 $out .= \sprintf(
107 '<h1 class="notice-yoast__header-heading">%s</h1>',
108 \esc_html( $this->title )
109 );
110 $out .= '</div>';
111 $out .= '<p>' . $this->content . '</p>';
112 if ( ! \is_null( $this->button ) ) {
113 $out .= '<p>' . $this->button . '</p>';
114 }
115 $out .= '</div>';
116
117 if ( ! \is_null( $this->image_filename ) ) {
118 $out .= '<img src="' . \esc_url( \plugin_dir_url( \WPSEO_FILE ) . 'images/' . $this->image_filename ) . '" alt="" height="60" width="75"/>';
119 }
120
121 $out .= '</div>';
122 $out .= '</div>';
123
124 return $out;
125 }
126 }
127