PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.3
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.3
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 / alert-presenter.php

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

73 lines 1.5 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 Alert boxes.
10 */
11 class Alert_Presenter extends Abstract_Presenter {
12
13 /**
14 * Content of the Alert.
15 *
16 * @var string
17 */
18 private $content = '';
19
20 /**
21 * The type of the Alert.
22 *
23 * Can be: "error", "info", "success" or "warning".
24 * Controls the colours and icon of the Alert.
25 *
26 * @var string
27 */
28 private $type;
29
30 /**
31 * An instance of the WPSEO_Admin_Asset_Manager class.
32 *
33 * @var WPSEO_Admin_Asset_Manager
34 */
35 protected $asset_manager;
36
37 /**
38 * Alert_Presenter constructor.
39 *
40 * @param string $content Content of the Alert.
41 * @param string $type Type of the Alert (error/info/success/warning), default is warning.
42 */
43 public function __construct( $content, $type = 'warning' ) {
44 $this->content = $content;
45 $this->type = $type;
46
47 if ( ! $this->asset_manager ) {
48 $this->asset_manager = new WPSEO_Admin_Asset_Manager();
49 }
50
51 $this->asset_manager->enqueue_style( 'alert' );
52 }
53
54 /**
55 * Presents the Alert.
56 *
57 * @return string The styled Alert.
58 */
59 public function present() {
60 $icon_file = 'images/alert-' . $this->type . '-icon.svg';
61
62 $out = '<div class="yoast-alert yoast-alert--' . $this->type . '">';
63 $out .= '<span>';
64 $out .= '<img class="yoast-alert__icon" src="' . \esc_url( \plugin_dir_url( \WPSEO_FILE ) . $icon_file ) . '" alt="" />';
65 $out .= '</span>';
66
67 $out .= '<span>' . $this->content . '</span>';
68 $out .= '</div>';
69
70 return $out;
71 }
72 }
73