PluginProbe
UpdraftCentral Dashboard / 0.8.13
UpdraftCentral Dashboard v0.8.13
0.8.33 0.7.2 0.7.3 0.7.4 0.8.0 0.8.1 0.8.10 0.8.11 0.8.12 0.8.13 0.8.14 0.8.15 0.8.16 0.8.17 0.8.18 0.8.19 0.8.2 0.8.20 0.8.21 0.8.22 0.8.23 0.8.24 0.8.25 0.8.26 0.8.27 All 51 releases
updraftcentral / modules / updates / loader.php

loader.php in UpdraftCentral Dashboard 0.8.13, at modules/updates/loader.php

103 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('UD_CENTRAL_DIR')) die('Security check');
4
5 class UpdraftCentral_Module_Updates {
6 const MODULE_NAME = 'updates';
7
8 public function __construct() {
9 add_action('updraftcentral_load_dashboard_js', array($this, 'load_dashboard_js'));
10 add_action('updraftcentral_load_dashboard_css', array($this, 'load_dashboard_css'));
11 add_filter('updraftcentral_udrclion', array($this, 'udrclion'));
12 add_action('updraftcentral_dashboard_post_navigation', array($this, 'dashboard_post_navigation'));
13 add_filter('updraftcentral_main_navigation_items', array($this, 'main_navigation_items'));
14 add_action('updraftcentral_site_row_after_buttons', array($this, 'site_row_after_buttons'));
15 add_filter('updraftcentral_template_directories', array($this, 'template_directories'));
16
17 // Add available shortcuts for this module
18 add_filter('updraftcentral_keyboard_shortcuts', array($this, 'keyboard_shortcuts'));
19
20 // Run updates retrieval in the background using cron
21 add_filter('updraftcentral_scheduled_commands', array($this, 'run_updates_command'));
22 }
23
24 public function run_updates_command($scheduled_commands) {
25 // N.B. Set the "force_refresh" to false to prevent the remote website to query the updates server (in wporg)
26 // as to avoid any unnecessary timeout while the process is going on and running in the background.
27 //
28 // Data should expire after 12 hrs (12*60*60 = 43200) from last retrieval. WordPress checks for updates every 12 hours
29 // or so, therefore, our 12 hrs check interval should be good. After expiration it will retrieve fresh data from the website
30 // to overwrite the old ones.
31 $scheduled_commands[] = array(
32 'command' => 'updates.get_updates',
33 'data' => array('force_refresh' => false),
34 'maximum_age' => 43200,
35 'is_long_running' => false // We're not issuing a force refresh here therefore this is not a long running process
36 );
37
38 // N.B. Setting commands as non-long running will combine (multiplexed) all non-long running commands into a single
39 // command and sent to the remote website. Request to the remote website will only be done once, instead of
40 // sending separate requests for each commands just like when you set the "is_long_running" field to true.
41
42 return $scheduled_commands;
43 }
44
45 /**
46 * Adds keyboard shortcut(s) available for this module
47 *
48 * @param array $shortcuts UpdraftCentral keyboard shortcuts
49 * @return array Updated UpdraftCentral keyboard shortcuts
50 */
51 public function keyboard_shortcuts($shortcuts) {
52 $shortcuts['mass_updates'] = array(
53 'key' => 'M',
54 'description' => __('Mass updates', 'updraftcentral'),
55 'action' => 'updraftcentral_action_show_all_updates', /* ID or class name or a jQuery selector or a callback function (only applicable when registered from javascript). Element to trigger to load the content. */
56 'menu' => self::MODULE_NAME, /* Name of the navigation item or menu. */
57 'site_required' => false /* Content is not associated or linked to a site. */
58 );
59
60 return $shortcuts;
61 }
62
63 public function site_row_after_buttons() {
64 UpdraftCentral()->include_template(self::MODULE_NAME.'/site-row-buttons.php');
65 }
66
67 public function template_directories($template_directories) {
68 $template_directories[self::MODULE_NAME] = __DIR__.'/templates';
69
70 return $template_directories;
71 }
72
73 public function load_dashboard_js($enqueue_version) {
74 $min_or_not = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
75 // Code on top of the framework for doing actual work
76 wp_enqueue_script('updraftcentral-dashboard-activities-'.self::MODULE_NAME, UD_CENTRAL_URL.'/modules/'.self::MODULE_NAME.'/'.self::MODULE_NAME.$min_or_not.'.js', array('updraftcentral-dashboard', 'jquery'), $enqueue_version);
77
78 wp_enqueue_script('jquery-ui-progressbar', array('jquery', 'jquery-ui'));
79 }
80
81 public function load_dashboard_css($enqueue_version) {
82 wp_enqueue_style('updraftcentral-dashboard-css-'.self::MODULE_NAME, UD_CENTRAL_URL.'/modules/'.self::MODULE_NAME.'/'.self::MODULE_NAME.'.css', array('updraftcentral-dashboard-css'), $enqueue_version);
83 }
84
85 public function main_navigation_items($items) {
86 $items[self::MODULE_NAME] = array('label' => __('Updates', 'updraftcentral'), 'sort_order' => 30);
87
88 return $items;
89 }
90
91 public function udrclion($localize) {
92 $localize[self::MODULE_NAME] = include __DIR__.'/translations-dashboard.php';
93
94 return $localize;
95 }
96
97 public function dashboard_post_navigation() {
98 UpdraftCentral()->include_template(self::MODULE_NAME.'/management-actions.php');
99 }
100 }
101
102 new UpdraftCentral_Module_Updates();
103