|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace EventEspresso\core\services\request\middleware; |
|
4
|
|
|
|
|
5
|
|
|
use EventEspresso\core\services\request\RequestInterface; |
|
6
|
|
|
use EventEspresso\core\services\request\ResponseInterface; |
|
7
|
|
|
use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice; |
|
8
|
|
|
use EventEspresso\core\exceptions\InvalidDataTypeException; |
|
9
|
|
|
|
|
10
|
|
|
defined('EVENT_ESPRESSO_VERSION') || exit; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class NonProductionReadyVersionWarning |
|
16
|
|
|
* Displays a warning banner if a non-production version of EE is being run |
|
17
|
|
|
* |
|
18
|
|
|
* @package EventEspresso\core\services\request\middleware |
|
19
|
|
|
* @author Brent Christensen |
|
20
|
|
|
* @since 4.9.52 |
|
21
|
|
|
*/ |
|
22
|
|
|
class PreProductionVersionWarning extends Middleware |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* converts a Request to a Response |
|
27
|
|
|
* |
|
28
|
|
|
* @param RequestInterface $request |
|
29
|
|
|
* @param ResponseInterface $response |
|
30
|
|
|
* @return ResponseInterface |
|
31
|
|
|
*/ |
|
32
|
|
View Code Duplication |
public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->request = $request; |
|
35
|
|
|
$this->response = $response; |
|
36
|
|
|
$this->displayPreProductionVersionWarning(); |
|
37
|
|
|
$this->response = $this->processRequestStack($this->request, $this->response); |
|
38
|
|
|
return $this->response; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
45
|
|
|
* |
|
46
|
|
|
* @return void |
|
47
|
|
|
*/ |
|
48
|
|
|
public function displayPreProductionVersionWarning() |
|
49
|
|
|
{ |
|
50
|
|
|
// skip AJAX requests |
|
51
|
|
|
if ($this->request->isAjax()) { |
|
52
|
|
|
return; |
|
53
|
|
|
} |
|
54
|
|
|
// skip stable releases |
|
55
|
|
|
if (substr(EVENT_ESPRESSO_VERSION, -5) !== '.beta') { |
|
56
|
|
|
return; |
|
57
|
|
|
} |
|
58
|
|
|
// site admin has authorized use of non-stable release candidate for production |
|
59
|
|
|
if (defined('ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE') && ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE) { |
|
60
|
|
|
return; |
|
61
|
|
|
} |
|
62
|
|
|
// post release candidate warning |
|
63
|
|
|
if ($this->request->isAdmin()) { |
|
64
|
|
|
add_action('admin_notices', array($this, 'preProductionVersionAdminNotice'), -999); |
|
65
|
|
|
} else { |
|
66
|
|
|
add_action('shutdown', array($this, 'preProductionVersionWarningNotice'), 10); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* displays admin notice that current version of EE is not a stable release |
|
74
|
|
|
* |
|
75
|
|
|
* @return void |
|
76
|
|
|
* @throws InvalidDataTypeException |
|
77
|
|
|
*/ |
|
78
|
|
|
public function preProductionVersionAdminNotice() |
|
79
|
|
|
{ |
|
80
|
|
|
new PersistentAdminNotice( |
|
81
|
|
|
'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION, |
|
82
|
|
|
$this->warningNotice() |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* displays message on frontend of site notifying admin that current version of EE is not a stable release |
|
89
|
|
|
* |
|
90
|
|
|
* @return void |
|
91
|
|
|
*/ |
|
92
|
|
|
public function preProductionVersionWarningNotice() |
|
93
|
|
|
{ |
|
94
|
|
|
echo '<div id="ee-release-candidate-notice-dv" class="ee-really-important-notice-dv"><p>'; |
|
95
|
|
|
echo $this->warningNotice(); |
|
96
|
|
|
echo '</p></div>'; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @return string |
|
102
|
|
|
*/ |
|
103
|
|
|
private function warningNotice() |
|
104
|
|
|
{ |
|
105
|
|
|
return sprintf( |
|
106
|
|
|
esc_html__( |
|
107
|
|
|
'This version of Event Espresso is for testing and/or evaluation purposes only. It is %1$snot%2$s considered a stable release and should therefore %1$snot%2$s be activated on a live or production website.', |
|
108
|
|
|
'event_espresso' |
|
109
|
|
|
), |
|
110
|
|
|
'<strong>', |
|
111
|
|
|
'</strong>' |
|
112
|
|
|
); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
// Location: NonProductionReadyVersionWarning.php |
|
117
|
|
|
|