| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Controller for enabling plugin auto-updates. |
| 5 |
*/ |
| 6 |
|
| 7 |
namespace Extendify\Shared\Controllers; |
| 8 |
|
| 9 |
defined('ABSPATH') || die('No direct access.'); |
| 10 |
|
| 11 |
use Extendify\Shared\Services\AutoUpdate\AutoUpdate; |
| 12 |
|
| 13 |
/** |
| 14 |
* Opts a plugin we installed into WordPress auto-updates. |
| 15 |
*/ |
| 16 |
|
| 17 |
class AutoUpdateController |
| 18 |
{ |
| 19 |
/** |
| 20 |
* Enable auto-updates for a plugin we just installed. |
| 21 |
* |
| 22 |
* @param \WP_REST_Request $request - The request. |
| 23 |
* @return \WP_REST_Response |
| 24 |
*/ |
| 25 |
public static function enable($request) |
| 26 |
{ |
| 27 |
$plugin = sanitize_text_field((string) $request->get_param('plugin')); |
| 28 |
if (AutoUpdate::isEnabled() && $plugin) { |
| 29 |
// The WP install response gives the plugin file without its ".php". |
| 30 |
AutoUpdate::enableAutoUpdateForPlugin(plugin_basename($plugin . '.php')); |
| 31 |
} |
| 32 |
|
| 33 |
return new \WP_REST_Response(['success' => true]); |
| 34 |
} |
| 35 |
} |
| 36 |
|