PluginProbe
Extendify / 3.1.4
Extendify v3.1.4
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / app / Shared / Services / AutoUpdate / AutoUpdate.php

AutoUpdate.php in Extendify 3.1.4, at app/Shared/Services/AutoUpdate/AutoUpdate.php

84 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Manage WordPress auto-updates for Extendify.
5 */
6
7 namespace Extendify\Shared\Services\AutoUpdate;
8
9 defined('ABSPATH') || die('No direct access.');
10
11 use Extendify\PartnerData;
12
13 /**
14 * Enables auto-updates for plugins we install, plus a launch-time enable for
15 * the Extendable theme, WordPress core, and Extendify itself.
16 */
17
18 class AutoUpdate
19 {
20 /**
21 * Whether the auto-update feature is enabled for this site.
22 *
23 * @return boolean
24 */
25 public static function isEnabled()
26 {
27 return PartnerData::setting('useAutoUpdate')
28 || (defined('EXTENDIFY_DEVMODE') && constant('EXTENDIFY_DEVMODE'));
29 }
30
31 /**
32 * Opt a plugin into auto-updates (only ever adds; never installs or
33 * activates the plugin).
34 *
35 * @param string|null $pluginFile - The plugin file, e.g. "woocommerce/woocommerce.php".
36 * @return void
37 */
38 public static function enableAutoUpdateForPlugin($pluginFile)
39 {
40 if (!$pluginFile) {
41 return;
42 }
43
44 if (!function_exists('get_plugins')) {
45 require_once ABSPATH . 'wp-admin/includes/plugin.php';
46 }
47
48 // Only opt in plugins that are actually installed.
49 if (!array_key_exists($pluginFile, get_plugins())) {
50 return;
51 }
52
53 self::addToAutoUpdateList('auto_update_plugins', $pluginFile);
54 }
55
56 /**
57 * Enable automatic updates for all WordPress core releases.
58 *
59 * @return void
60 */
61 public static function enableAutoUpdateForCore()
62 {
63 update_option('auto_update_core_major', 'enabled');
64 }
65
66 /**
67 * Append a value to one of WordPress' auto-update list options if missing.
68 *
69 * @param string $optionKey - The option name (auto_update_plugins/themes).
70 * @param string $value - The plugin file or theme stylesheet to add.
71 * @return void
72 */
73 public static function addToAutoUpdateList($optionKey, $value)
74 {
75 $enabled = (array) get_option($optionKey, []);
76 if (in_array($value, $enabled, true)) {
77 return;
78 }
79
80 $enabled[] = $value;
81 update_option($optionKey, $enabled);
82 }
83 }
84