1 | <?php |
||
20 | class Update { |
||
21 | |||
22 | /** |
||
23 | * Previous version. |
||
24 | * |
||
25 | * @access protected |
||
26 | * @var string |
||
27 | */ |
||
28 | private $installed_ver = '0.0.0'; |
||
29 | |||
30 | /** |
||
31 | * Current version. |
||
32 | * |
||
33 | * @access private |
||
34 | * @var string |
||
35 | */ |
||
36 | private $new_ver = '0.0.0'; |
||
37 | |||
38 | /** |
||
39 | * Existing posts. |
||
40 | * |
||
41 | * @access private |
||
42 | * @var array |
||
43 | */ |
||
44 | private $posts = array(); |
||
45 | |||
46 | /** |
||
47 | * Update path. |
||
48 | * |
||
49 | * @access private |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | private $update_path = array( |
||
54 | '2.1.0', |
||
55 | '2.2.0', |
||
56 | '3.0.0', |
||
57 | '3.0.13', |
||
58 | ); |
||
59 | |||
60 | /** |
||
61 | * Constructor. |
||
62 | * |
||
63 | * @since 3.0.0 |
||
64 | * |
||
65 | * @param string $version (optional) Current plugin version, defaults to value in plugin constant. |
||
66 | */ |
||
67 | public function __construct( $version = SIMPLE_CALENDAR_VERSION ) { |
||
77 | |||
78 | /** |
||
79 | * Update to current version. |
||
80 | * |
||
81 | * Runs all the update scripts through version steps. |
||
82 | * |
||
83 | * @since 3.0.0 |
||
84 | */ |
||
85 | public function run_updates() { |
||
136 | |||
137 | /** |
||
138 | * Handle redirects to welcome page after install and updates. |
||
139 | * |
||
140 | * Transient must be present, the user must have access rights, and we must ignore the network/bulk plugin updaters. |
||
141 | * |
||
142 | * @since 3.0.0 |
||
143 | */ |
||
144 | public function admin_redirects() { |
||
167 | |||
168 | /** |
||
169 | * Get posts. |
||
170 | * |
||
171 | * @since 3.0.0 |
||
172 | * |
||
173 | * @param $post_type |
||
174 | * |
||
175 | * @return array |
||
176 | */ |
||
177 | private function get_posts( $post_type ) { |
||
202 | |||
203 | /** |
||
204 | * Update. |
||
205 | * |
||
206 | * Runs an update script for the specified version passed in argument. |
||
207 | * |
||
208 | * @since 3.0.0 |
||
209 | * |
||
210 | * @param string $version |
||
211 | */ |
||
212 | private function update( $version ) { |
||
220 | |||
221 | } |
||
222 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: