class-wpml-xml-config-log-notice.php
2.67 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
<?php
use WPML\API\Sanitize;
/**
* @author OnTheGo Systems
*/
class WPML_XML_Config_Log_Notice {
const NOTICE_ERROR_GROUP = 'wpml-config-update';
const NOTICE_ERROR_ID = 'wpml-config-update-error';
/** @var WPML_Config_Update_Log */
private $log;
public function __construct( WPML_Log $log ) {
$this->log = $log;
}
public function add_hooks() {
if ( is_admin() ) {
add_action( 'wpml_loaded', array( $this, 'refresh_notices' ) );
}
}
public function refresh_notices() {
$notices = wpml_get_admin_notices();
if ( $this->log->is_empty() ) {
$notices->remove_notice( self::NOTICE_ERROR_GROUP, self::NOTICE_ERROR_ID );
return;
}
$text = '<p>' . esc_html__( 'WPML could not load configuration files, which your site needs.', 'sitepress' ) . '</p>';
$notice = $notices->create_notice( self::NOTICE_ERROR_ID, $text, self::NOTICE_ERROR_GROUP );
$notice->set_css_class_types( array( 'error' ) );
$log_url = add_query_arg( array( 'page' => WPML_Config_Update_Log::get_support_page_log_section() ), get_admin_url( null, 'admin.php#xml-config-log' ) );
$show_logs = $notices->get_new_notice_action( __( 'Detailed error log', 'sitepress' ), $log_url );
$return_url = null;
if ( $this->is_admin_user_action() ) {
$admin_uri = preg_replace( '#^/wp-admin/#', '', $_SERVER['SCRIPT_NAME'] );
$return_url = get_admin_url( null, $admin_uri );
$return_url_qs = $_GET;
unset( $return_url_qs[ self::NOTICE_ERROR_GROUP . '-action' ], $return_url_qs[ self::NOTICE_ERROR_GROUP . '-nonce' ] );
$return_url = add_query_arg( $return_url_qs, $return_url );
}
$retry_url = add_query_arg(
array(
self::NOTICE_ERROR_GROUP . '-action' => 'wpml_xml_update_refresh',
self::NOTICE_ERROR_GROUP . '-nonce' => wp_create_nonce( 'wpml_xml_update_refresh' ),
),
$return_url
);
$retry = $notices->get_new_notice_action( __( 'Retry', 'sitepress' ), $retry_url, false, false, true );
$notice->add_action( $show_logs );
$notice->add_action( $retry );
$notice->set_dismissible( true );
$notice->set_restrict_to_page_prefixes(
array(
'sitepress-multilingual-cms',
'wpml-translation-management',
'wpml-package-management',
'wpml-string-translation',
)
);
$notice->set_restrict_to_screen_ids( array( 'dashboard', 'plugins', 'themes' ) );
$notice->add_exclude_from_page( WPML_Config_Update_Log::get_support_page_log_section() );
$notices->add_notice( $notice );
}
/**
* @return bool
*/
private function is_admin_user_action() {
return is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX )
&& ( 'heartbeat' !== Sanitize::stringProp( 'action', $_POST ) )
&& ( ! defined( 'DOING_CRON' ) || ! DOING_CRON );
}
}