PluginProbe
UpdraftCentral Dashboard / trunk
UpdraftCentral Dashboard vtrunk
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 trunk, at modules/updates/loader.php

118 lines 5.2 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 add_filter('updraftcentral_sub_menus', array($this, 'add_sub_menus'));
23 }
24
25 /**
26 * Adds sub menu for the updates module
27 *
28 * @param array $menus An array containing the sub menus to display for each module
29 * @return array
30 */
31 public function add_sub_menus($menus) {
32 $menus['updates'] = array('Show all updates' => '.updraftcentral_action_show_all_updates');
33 return $menus;
34 }
35
36 public function run_updates_command($scheduled_commands) {
37 // N.B. Set the "force_refresh" to false to prevent the remote website to query the updates server (in wporg)
38 // as to avoid any unnecessary timeout while the process is going on and running in the background.
39 //
40 // Data should expire after 12 hrs (12*60*60 = 43200) from last retrieval. WordPress checks for updates every 12 hours
41 // or so, therefore, our 12 hrs check interval should be good. After expiration it will retrieve fresh data from the website
42 // to overwrite the old ones.
43 $scheduled_commands[] = array(
44 'command' => 'updates.get_updates',
45 'data' => array('force_refresh' => false),
46 'maximum_age' => 43200,
47 'is_long_running' => false // We're not issuing a force refresh here therefore this is not a long running process
48 );
49
50 // N.B. Setting commands as non-long running will combine (multiplexed) all non-long running commands into a single
51 // command and sent to the remote website. Request to the remote website will only be done once, instead of
52 // sending separate requests for each commands just like when you set the "is_long_running" field to true.
53
54 return $scheduled_commands;
55 }
56
57 /**
58 * Adds keyboard shortcut(s) available for this module
59 *
60 * @param array $shortcuts UpdraftCentral keyboard shortcuts
61 * @return array Updated UpdraftCentral keyboard shortcuts
62 */
63 public function keyboard_shortcuts($shortcuts) {
64 $shortcuts['mass_updates'] = array(
65 'key' => 'M',
66 'description' => __('Mass updates', 'updraftcentral'),
67 '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. */
68 'menu' => self::MODULE_NAME, /* Name of the navigation item or menu. */
69 'site_required' => false /* Content is not associated or linked to a site. */
70 );
71
72 return $shortcuts;
73 }
74
75 public function site_row_after_buttons() {
76 UpdraftCentral()->include_template(self::MODULE_NAME.'/site-row-buttons.php');
77 }
78
79 public function template_directories($template_directories) {
80 $template_directories[self::MODULE_NAME] = __DIR__.'/templates';
81
82 return $template_directories;
83 }
84
85 public function load_dashboard_js($enqueue_version) {
86 $min_or_not = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
87 // Code on top of the framework for doing actual work
88 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);
89
90 wp_enqueue_script('jquery-ui-progressbar', array('jquery', 'jquery-ui'));
91 wp_enqueue_script('day-js', UD_CENTRAL_URL.'/js/dayjs/dayjs.min.js', array(), $enqueue_version);
92 wp_enqueue_script('day-js-relative-time', UD_CENTRAL_URL.'/js/dayjs/relativeTime.js', array('day-js'), $enqueue_version);
93 wp_enqueue_script('day-js-localized-format', UD_CENTRAL_URL.'/js/dayjs/localizedFormat.js', array('day-js'), $enqueue_version);
94 }
95
96 public function load_dashboard_css($enqueue_version) {
97 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);
98 }
99
100 public function main_navigation_items($items) {
101 $items[self::MODULE_NAME] = array('label' => __('Updates', 'updraftcentral'), 'sort_order' => 30);
102
103 return $items;
104 }
105
106 public function udrclion($localize) {
107 $localize[self::MODULE_NAME] = include __DIR__.'/translations-dashboard.php';
108
109 return $localize;
110 }
111
112 public function dashboard_post_navigation() {
113 UpdraftCentral()->include_template(self::MODULE_NAME.'/management-actions.php');
114 }
115 }
116
117 new UpdraftCentral_Module_Updates();
118