Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/seo-by-rank-math/includes/admin/class-notices.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + /**
3 + * The admin notices.
4 + *
5 + * @since 0.9.0
6 + * @package RankMath
7 + * @subpackage RankMath\Admin
8 + * @author Rank Math <support@rankmath.com>
9 + */
10 +
11 + namespace RankMath\Admin;
12 +
13 + use RankMath\Runner;
14 + use RankMath\Helper;
15 + use RankMath\Traits\Ajax;
16 + use RankMath\Traits\Hooker;
17 + use RankMath\Helpers\Sitepress;
18 + use RankMath\Helpers\Param;
19 +
20 + defined( 'ABSPATH' ) || exit;
21 +
22 + /**
23 + * Notices class.
24 + */
25 + class Notices implements Runner {
26 +
27 + use Hooker;
28 + use Ajax;
29 +
30 + /**
31 + * Register hooks.
32 + */
33 + public function hooks() {
34 + $this->action( 'admin_init', 'notices' );
35 + $this->action( 'wp_helpers_notification_dismissed', 'notice_dismissible' );
36 + }
37 +
38 + /**
39 + * Run all notices routine.
40 + */
41 + public function notices() {
42 + $this->is_plugin_configured();
43 + $this->new_post_type();
44 + $this->convert_wpml_settings();
45 + $this->permalink_changes_warning();
46 + $this->react_settings_ui_notice();
47 + }
48 +
49 + /**
50 + * Show a persistent admin notice when the React Settings UI is disabled.
51 + *
52 + * Adds a dismissible, persistent error when the temporary option to
53 + * disable the React-based Settings UI is turned off. The notice is removed
54 + * when the React Settings UI is enabled again.
55 + *
56 + * @since 1.0.255
57 + * @return void
58 + */
59 + private function react_settings_ui_notice() {
60 + // Only relevant for admins in the dashboard context.
61 + if ( ! current_user_can( 'manage_options' ) ) {
62 + return;
63 + }
64 +
65 + $notice_id = 'rank_math_react_settings_ui_disabled';
66 +
67 + if ( ! Helper::is_react_enabled() ) {
68 + $message = sprintf(
69 + // Translators: 1: opening anchor tag, 2: closing anchor tag.
70 + __( 'The React Settings UI is currently disabled, and the classic settings interface is active. Note: The PHP-based settings interface will be removed in an upcoming release. %1$sEnable the React Settings UI%2$s to switch back.', 'rank-math' ),
71 + '<a href="' . esc_url( Helper::get_dashboard_url() ) . '">',
72 + '</a>'
73 + );
74 +
75 + Helper::add_notification(
76 + $message,
77 + [
78 + 'type' => 'error',
79 + 'id' => $notice_id,
80 + ]
81 + );
82 + return;
83 + }
84 +
85 + // React UI is enabled; ensure any prior notice is removed.
86 + Helper::remove_notification( $notice_id );
87 + }
88 +
89 + /**
90 + * Set known post type after notice dismissal.
91 + *
92 + * @param string $notification_id Notification id.
93 + */
94 + public function notice_dismissible( $notification_id ) {
95 + if ( 'new_post_type' === $notification_id ) {
96 + $current = get_post_types( [ 'public' => true ] );
97 + update_option( 'rank_math_known_post_types', $current );
98 +
99 + if ( Helper::is_module_active( 'sitemap' ) ) {
100 + \RankMath\Sitemap\Cache::invalidate_storage();
101 + }
102 + return;
103 + }
104 +
105 + if ( 'convert_wpml_settings' === $notification_id ) {
106 + update_option( 'rank_math_wpml_notice_dismissed', true );
107 + }
108 +
109 + if ( 'rank-math-site-url-mismatch' === $notification_id ) {
110 + update_option( 'rank_math_siteurl_mismatch_notice_dismissed', true );
111 + }
112 + }
113 +
114 + /**
115 + * If plugin configuration not done.
116 + */
117 + private function is_plugin_configured() {
118 + if ( 'mts-install-plugins' === Param::get( 'page' ) ) {
119 + return;
120 + }
121 +
122 + if ( rank_math()->notification->get_notification_by_id( 'plugin_not_setup' ) && ! Helper::is_configured() ) {
123 + $message = sprintf(
124 + '<b>Warning!</b> You didn\'t set up your Rank Math SEO plugin yet, which means you\'re missing out on essential settings and tweaks! <a href="%s">Complete your setup by clicking here.</a>',
125 + Helper::get_admin_url( 'wizard' )
126 + );
127 + Helper::add_notification(
128 + $message,
129 + [
130 + 'type' => 'warning',
131 + 'id' => 'plugin_not_setup',
132 + ]
133 + );
134 + }
135 + }
136 +
137 + /**
138 + * Add notification if a new post type is detected.
139 + */
140 + private function new_post_type() {
141 + $known = get_option( 'rank_math_known_post_types', [] );
142 + $current = Helper::get_accessible_post_types();
143 + $new = array_diff( $current, $known );
144 +
145 + if ( empty( $new ) ) {
146 + return;
147 + }
148 +
149 + $list = '<code>' . implode( '</code>, <code>', $new ) . '</code>';
150 + /* Translators: placeholder is the post type name. */
151 + $message = __( 'Rank Math has detected a new post type: %1$s. You may want to check the settings of the <a href="%2$s">Titles &amp; Meta page</a>.', 'rank-math' );
152 + $count = count( $new );
153 + if ( $count > 1 ) {
154 + /* Translators: placeholder is the post type names separated with commas. */
155 + $message = __( 'Rank Math has detected new post types: %1$s. You may want to check the settings of the <a href="%2$s">Titles &amp; Meta page</a>.', 'rank-math' );
156 + }
157 +
158 + $message = $this->do_filter( 'admin/notice/new_post_type', $message, $count );
159 + $message = sprintf( wp_kses_post( $message ), $list, Helper::get_settings_url( 'titles', 'post-type-' . key( $new ) ), Helper::get_settings_url( 'sitemap', 'post-type-' . key( $new ) ) );
160 + Helper::add_notification(
161 + $message,
162 + [
163 + 'type' => 'info',
164 + 'id' => 'new_post_type',
165 + ]
166 + );
167 + }
168 +
169 + /**
170 + * Function to show Show String Translation plugin notice and convert the settings.
171 + */
172 + private function convert_wpml_settings() {
173 + if ( ! Sitepress::get()->is_active() || get_option( 'rank_math_wpml_data_converted' ) ) {
174 + return;
175 + }
176 +
177 + if ( ! function_exists( 'icl_add_string_translation' ) ) {
178 + if ( ! get_option( 'rank_math_wpml_notice_dismissed' ) ) {
179 + Helper::add_notification(
180 + __( 'Please activate the WPML String Translation plugin to convert Rank Math Setting values in different languages.', 'rank-math' ),
181 + [
182 + 'type' => 'error',
183 + 'id' => 'convert_wpml_settings',
184 + ]
185 + );
186 + }
187 + return;
188 + }
189 +
190 + $languages = icl_get_languages(); // @phpstan-ignore-line
191 + foreach ( $languages as $lang_code => $language ) {
192 +
193 + foreach ( [ 'general', 'titles' ] as $option ) {
194 + $data = get_option( "rank-math-options-{$option}_$lang_code" );
195 + if ( empty( $data ) ) {
196 + continue;
197 + }
198 +
199 + $common_data = array_intersect( array_keys( $data ), $this->get_translatable_options() );
200 + if ( empty( $common_data ) ) {
201 + continue;
202 + }
203 +
204 + foreach ( $common_data as $option_key ) {
205 + $string_id = icl_get_string_id( Helper::get_settings( "$option.$option_key" ), "admin_texts_rank-math-options-$option" ); // @phpstan-ignore-line
206 + icl_add_string_translation( $string_id, $lang_code, $data[ $option_key ], 10 ); // @phpstan-ignore-line
207 + }
208 + }
209 + }
210 +
211 + update_option( 'rank_math_wpml_data_converted', true );
212 + }
213 +
214 + /**
215 + * Get Translatable option keys.
216 + *
217 + * @return array
218 + */
219 + private function get_translatable_options() {
220 + $options = [
221 + 'img_alt_format',
222 + 'img_title_format',
223 + 'breadcrumbs_separator',
224 + 'breadcrumbs_prefix',
225 + 'breadcrumbs_home_link',
226 + 'breadcrumbs_home_label',
227 + 'breadcrumbs_archive_format',
228 + 'breadcrumbs_search_format',
229 + 'breadcrumbs_404_label',
230 + 'rss_before_content',
231 + 'rss_after_content',
232 +
233 + 'title_separator',
234 + 'homepage_title',
235 + 'homepage_description',
236 + 'homepage_facebook_title',
237 + 'homepage_facebook_description',
238 + 'author_archive_title',
239 + 'author_archive_description',
240 + 'date_archive_title',
241 + 'date_archive_description',
242 + 'search_title',
243 + '404_title',
244 + ];
245 +
246 + $post_types = Helper::get_accessible_post_types();
247 + foreach ( $post_types as $post_type => $data ) {
248 + $options = array_merge(
249 + $options,
250 + [
251 + "pt_{$post_type}_title",
252 + "pt_{$post_type}_description",
253 + "pt_{$post_type}_archive_title",
254 + "pt_{$post_type}_archive_description",
255 + "pt_{$post_type}_default_snippet_name",
256 + "pt_{$post_type}_default_snippet_desc",
257 + ]
258 + );
259 + }
260 +
261 + $taxonomies = Helper::get_accessible_taxonomies();
262 + foreach ( $taxonomies as $taxonomy => $data ) {
263 + $options = array_merge(
264 + $options,
265 + [
266 + "tax_{$taxonomy}_title",
267 + "tax_{$taxonomy}_description",
268 + ]
269 + );
270 + }
271 +
272 + return $options;
273 + }
274 +
275 + /**
276 + * Maybe add notice on Permalinks page about the risks of changing the permalinks on a live site.
277 + *
278 + * @return void
279 + */
280 + public function permalink_changes_warning() {
281 + global $pagenow;
282 + if ( 'options-permalink.php' !== $pagenow ) {
283 + return;
284 + }
285 +
286 + $this->action( 'admin_enqueue_scripts', 'add_permalink_changes_warning', 12 );
287 + }
288 +
289 + /**
290 + * Add the notice for the Permalinks page.
291 + *
292 + * @return void
293 + */
294 + public function add_permalink_changes_warning() {
295 + wp_enqueue_script( 'rank-math-core-permalink-settings' );
296 + $message = __( '<b>Rank Math Warning:</b> Changing the permalinks on a live, indexed site may result in serious loss of traffic if done incorrectly. Consider adding a new redirection from the old URL format to the new one.', 'rank-math' );
297 + Helper::add_notification(
298 + $message,
299 + [
300 + 'type' => 'warning',
301 + 'screen' => 'options-permalink',
302 + 'classes' => 'hidden rank-math-notice-permalinks-warning is-dismissible',
303 + ]
304 + );
305 + }
306 + }
307 +