wpml-tf-promote-notices.php
2.07 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
<?php
/**
* Class WPML_TF_Promote_Notices
*
* @author OnTheGoSystems
*/
class WPML_TF_Promote_Notices {
const NOTICE_GROUP = 'wpml-tf-promote';
const NOTICE_NEW_SITE = 'notice-new-site';
const DOC_URL = 'https://wpml.org/documentation/getting-started-guide/getting-visitor-feedback-about-your-sites-translations/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmlcore';
/** @var SitePress $sitepress */
private $sitepress;
public function __construct( SitePress $sitepress ) {
$this->sitepress = $sitepress;
}
/**
* @param int $user_id
*/
public function show_notice_for_new_site( $user_id ) {
$notices = wpml_get_admin_notices();
$settings_url = admin_url( '?page=' . WPML_PLUGIN_FOLDER . '/menu/languages.php#wpml-translation-feedback-options' );
$user_lang = $this->sitepress->get_user_admin_language( $user_id );
$this->sitepress->switch_lang( $user_lang );
$text = '<h2>' . __( 'Want to know if recent translations you received have problems?', 'sitepress' ) . '</h2>';
$text .= '<p>';
$text .= __( 'You got back several jobs from translation and they now appear on your site.', 'sitepress' );
$text .= ' ' . __( 'WPML lets you open these pages for feedback, so that visitors can tell you if they notice anything wrong.', 'sitepress' );
$text .= '<br><br>';
$text .= '<a href="' . $settings_url . '" class="button-secondary">' . __( 'Enable Translation Feedback', 'sitepress' ) . '</a>';
$text .= ' <a href="' . self::DOC_URL . '" target="_blank">' . __( 'Learn more about translation feedback', 'sitepress' ) . '</a>';
$text .= '</p>';
$notice = $notices->get_new_notice( self::NOTICE_NEW_SITE, $text, self::NOTICE_GROUP );
$notice->set_dismissible( true );
$notice->set_css_class_types( 'notice-info' );
$notice->add_user_restriction( $user_id );
if ( ! $notices->is_notice_dismissed( $notice ) ) {
$notices->add_notice( $notice );
}
$this->sitepress->switch_lang( null );
}
public function remove() {
$notices = wpml_get_admin_notices();
$notices->remove_notice( self::NOTICE_GROUP, self::NOTICE_NEW_SITE );
}
}