first-time-configuration-notice-integration.php
5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
namespace Yoast\WP\SEO\Integrations\Admin;
use WPSEO_Admin_Asset_Manager;
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
use Yoast\WP\SEO\Helpers\First_Time_Configuration_Notice_Helper;
use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Integrations\Integration_Interface;
use Yoast\WP\SEO\Presenters\Admin\Notice_Presenter;
/**
* First_Time_Configuration_Notice_Integration class
*/
class First_Time_Configuration_Notice_Integration implements Integration_Interface {
/**
* The options' helper.
*
* @var Options_Helper
*/
private $options_helper;
/**
* The admin asset manager.
*
* @var WPSEO_Admin_Asset_Manager
*/
private $admin_asset_manager;
/**
* The first time configuration notice helper.
*
* @var First_Time_Configuration_Notice_Helper
*/
private $first_time_configuration_notice_helper;
/**
* {@inheritDoc}
*/
public static function get_conditionals() {
return [ Admin_Conditional::class ];
}
/**
* First_Time_Configuration_Notice_Integration constructor.
*
* @param Options_Helper $options_helper The options helper.
* @param First_Time_Configuration_Notice_Helper $first_time_configuration_notice_helper The first time configuration notice helper.
* @param WPSEO_Admin_Asset_Manager $admin_asset_manager The admin asset manager.
*/
public function __construct(
Options_Helper $options_helper,
First_Time_Configuration_Notice_Helper $first_time_configuration_notice_helper,
WPSEO_Admin_Asset_Manager $admin_asset_manager
) {
$this->options_helper = $options_helper;
$this->admin_asset_manager = $admin_asset_manager;
$this->first_time_configuration_notice_helper = $first_time_configuration_notice_helper;
}
/**
* {@inheritDoc}
*/
public function register_hooks() {
\add_action( 'wp_ajax_dismiss_first_time_configuration_notice', [ $this, 'dismiss_first_time_configuration_notice' ] );
\add_action( 'admin_notices', [ $this, 'first_time_configuration_notice' ] );
}
/**
* Dismisses the First-time configuration notice.
*
* @return bool
*/
public function dismiss_first_time_configuration_notice() {
// Check for nonce.
if ( ! \check_ajax_referer( 'wpseo-dismiss-first-time-configuration-notice', 'nonce', false ) ) {
return false;
}
return $this->options_helper->set( 'dismiss_configuration_workout_notice', true );
}
/**
* Determines whether and where the "First-time SEO Configuration" admin notice should be displayed.
*
* @return bool Whether the "First-time SEO Configuration" admin notice should be displayed.
*/
public function should_display_first_time_configuration_notice() {
return $this->first_time_configuration_notice_helper->should_display_first_time_configuration_notice();
}
/**
* Displays an admin notice when the first-time configuration has not been finished yet.
*
* @return void
*/
public function first_time_configuration_notice() {
if ( ! $this->should_display_first_time_configuration_notice() ) {
return;
}
$this->admin_asset_manager->enqueue_style( 'monorepo' );
$title = $this->first_time_configuration_notice_helper->get_first_time_configuration_title();
$link_url = \esc_url( \self_admin_url( 'admin.php?page=wpseo_dashboard#top#first-time-configuration' ) );
if ( ! $this->first_time_configuration_notice_helper->should_show_alternate_message() ) {
$content = \sprintf(
/* translators: 1: Link start tag to the first-time configuration, 2: Yoast SEO, 3: Link closing tag. */
\__( 'Get started quickly with the %1$s%2$s First-time configuration%3$s and configure Yoast SEO with the optimal SEO settings for your site!', 'wordpress-seo' ),
'<a href="' . $link_url . '">',
'Yoast SEO',
'</a>'
);
}
else {
$content = \sprintf(
/* translators: 1: Link start tag to the first-time configuration, 2: Link closing tag. */
\__( 'We noticed that you haven\'t fully configured Yoast SEO yet. Optimize your SEO settings even further by using our improved %1$s First-time configuration%2$s.', 'wordpress-seo' ),
'<a href="' . $link_url . '">',
'</a>'
);
}
$notice = new Notice_Presenter(
$title,
$content,
'mirrored_fit_bubble_woman_1_optim.svg',
null,
true,
'yoast-first-time-configuration-notice'
);
//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output from present() is considered safe.
echo $notice->present();
// Enable permanently dismissing the notice.
echo '<script>
jQuery( document ).ready( function() {
jQuery( "body" ).on( "click", "#yoast-first-time-configuration-notice .notice-dismiss", function() {
const data = {
"action": "dismiss_first_time_configuration_notice",
"nonce": "' . \esc_js( \wp_create_nonce( 'wpseo-dismiss-first-time-configuration-notice' ) ) . '"
};
jQuery.post( ajaxurl, data, function( response ) {
jQuery( this ).parent( "#yoast-first-time-configuration-notice" ).hide();
});
} );
} );
</script>';
}
}