1 | <?php |
||
7 | class Jetpack_Display_Posts_Widget extends Jetpack_Display_Posts_Widget__Base { |
||
8 | /** |
||
9 | * @var string Widget options key prefix. |
||
10 | */ |
||
11 | public $widget_options_key_prefix = 'display_posts_site_data_'; |
||
12 | |||
13 | /** |
||
14 | * @var string The name of the cron that will update widget data. |
||
15 | */ |
||
16 | public static $cron_name = 'jetpack_display_posts_widget_cron_update'; |
||
17 | |||
18 | |||
19 | // DATA STORE |
||
20 | |||
21 | /** |
||
22 | * Gets blog data from the cache. |
||
23 | * |
||
24 | * @param string $site |
||
25 | * |
||
26 | * @return array|WP_Error |
||
27 | */ |
||
28 | public function get_blog_data( $site ) { |
||
47 | |||
48 | /** |
||
49 | * Update a widget instance. |
||
50 | * |
||
51 | * @param string $site The site to fetch the latest data for. |
||
52 | * |
||
53 | * @return array - the new data |
||
54 | */ |
||
55 | public function update_instance( $site ) { |
||
83 | |||
84 | |||
85 | // WIDGET API |
||
86 | |||
87 | public function update( $new_instance, $old_instance ) { |
||
99 | |||
100 | |||
101 | // CRON |
||
102 | |||
103 | /** |
||
104 | * Activates widget update cron task. |
||
105 | */ |
||
106 | public static function activate_cron() { |
||
111 | |||
112 | /** |
||
113 | * Deactivates widget update cron task. |
||
114 | * |
||
115 | * This is a wrapper over the static method as it provides some syntactic sugar. |
||
116 | */ |
||
117 | public function deactivate_cron() { |
||
120 | |||
121 | /** |
||
122 | * Deactivates widget update cron task. |
||
123 | */ |
||
124 | public static function deactivate_cron_static() { |
||
128 | |||
129 | /** |
||
130 | * Checks if the update cron should be running and returns appropriate result. |
||
131 | * |
||
132 | * @return bool If the cron should be running or not. |
||
133 | */ |
||
134 | public function should_cron_be_running() { |
||
165 | |||
166 | /** |
||
167 | * Main cron code. Updates all instances of the widget. |
||
168 | * |
||
169 | * @return bool |
||
170 | */ |
||
171 | public function cron_task() { |
||
195 | |||
196 | /** |
||
197 | * Get a list of unique sites from all instances of the widget. |
||
198 | * |
||
199 | * @return array|bool |
||
200 | */ |
||
201 | public function get_instances_sites() { |
||
230 | |||
231 | |||
232 | // MOCKABLES |
||
233 | |||
234 | /** |
||
235 | * This is just to make method mocks in the unit tests easier. |
||
236 | * |
||
237 | * @param string $param Option key to get |
||
238 | * |
||
239 | * @return mixed |
||
240 | * |
||
241 | * @codeCoverageIgnore |
||
242 | */ |
||
243 | public function wp_get_option( $param ) { |
||
246 | |||
247 | /** |
||
248 | * This is just to make method mocks in the unit tests easier. |
||
249 | * |
||
250 | * @param string $option_name Option name to be added |
||
251 | * @param mixed $option_value Option value |
||
252 | * |
||
253 | * @return mixed |
||
254 | * |
||
255 | * @codeCoverageIgnore |
||
256 | */ |
||
257 | public function wp_add_option( $option_name, $option_value ) { |
||
260 | |||
261 | /** |
||
262 | * This is just to make method mocks in the unit tests easier. |
||
263 | * |
||
264 | * @param string $option_name Option name to be updated |
||
265 | * @param mixed $option_value Option value |
||
266 | * |
||
267 | * @return mixed |
||
268 | * |
||
269 | * @codeCoverageIgnore |
||
270 | */ |
||
271 | public function wp_update_option( $option_name, $option_value ) { |
||
274 | } |
||
275 |