PluginProbe
Age Gate / trunk
Age Gate vtrunk
trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 All 112 releases
age-gate / src / Admin / Update.php

Update.php in Age Gate trunk, at src/Admin/Update.php

112 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AgeGate\Admin;
4
5 class Update
6 {
7 public function __construct()
8 {
9 add_action('init', [$this, 'updateCheck'], 1);
10 add_action('in_plugin_update_message-age-gate/age-gate.php', [$this, 'updateWarnings']);
11 }
12
13 /**
14 * Check for version changes
15 *
16 * @return void
17 */
18 public function updateCheck()
19 {
20 if (AGE_GATE_VERSION !== get_option('age_gate_version')) {
21 \AgeGate\Update\Activate::activate();
22 }
23 }
24
25 public function updateWarnings($plugin)
26 {
27 $current = $plugin['Version'];
28 $new = $plugin['new_version'];
29
30 $method = 'get' . $this->getMagnitude($current, $new) . 'Message';
31
32 $devs = [
33 'dev',
34 'alpha',
35 'beta',
36 'rc',
37 ];
38
39 $version = AGE_GATE_VERSION . $current;
40
41 $found = false;
42
43 foreach ($devs as $str) {
44 if ($found) {
45 continue;
46 }
47
48 $found = stripos($version, $str) !== false;
49 }
50
51 if ($found) {
52 echo wp_kses_post($this->getDevMessage());
53 return;
54 }
55
56 echo wp_kses_post($this->$method());
57 }
58
59 private function getMagnitude($current, $new)
60 {
61 $current = explode('.', (string) $current);
62 $new = explode('.', (string) $new);
63
64 if ($new[0] > $current[0]) {
65 return 'Major';
66 } elseif ($new[1] > $current[1]) {
67 return 'Minor';
68 } elseif (isset($new[2]) && isset($current[2]) && $new[2] > $current[2]) {
69 return 'Patch';
70 }
71 return 'unknown';
72 }
73
74 private function getPatchMessage()
75 {
76 return '<br><br>' . __('This is a patch release of Age Gate, updating directly should not cause any issues, however do ensure you have backed up any previous version settings.', 'age-gate') . ' ';
77 }
78
79 private function getMinorMessage()
80 {
81 $message = '<br><br><b>' . __('WARNING', 'age-gate') . ':</b> ' . __('This is a minor release of Age Gate that could have unexpected results on your site.', 'age-gate') . ' ';
82 $message .= __('While it should be safe to update, it is advised that you test locally or on a staging site first.', 'age-gate');
83 return $message;
84 }
85
86 private function getMajorMessage()
87 {
88 $message = '<br><br><b>' . __('WARNING', 'age-gate') . ':</b> ' . __('This is a milestone release of Age Gate that could have unexpected results on your site.', 'age-gate') . ' ';
89 $message .= __('It is advised that you do not update on a live website and test locally or on a staging site first.', 'age-gate') . '<br><br>';
90 $message .= __('The update link has been disabled just to be safe, but if you are sure you want to update you can enable the update link here: ', 'age-gate') . '<button class="button-link age-gate-enable-update" type="button">' . __('Enable update', 'age-gate') . '</button>';
91 $message .= $this->disableUpdate();
92 return $message;
93 }
94
95 private function getDevMessage()
96 {
97 $message = '<br><br><b>' . __('WARNING', 'age-gate') . ':</b> ' . __('You are updating from a development version of Age Gate, some features, settings or functionality may no longer be available. Check the release notes and proceed with caution', 'age-gate') . ' <button class="button-link age-gate-enable-update" type="button">' . __('Enable update', 'age-gate') . '</button>';
98 $message .= $this->disableUpdate();
99
100 return $message;
101 }
102
103 private function getUnknownMessage()
104 {
105 }
106
107 private function disableUpdate()
108 {
109 return '<style>#age-gate-update .update-link {pointer-events: none;cursor: default; opacity:0.3;}</style>';
110 }
111 }
112