| 1 |
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 |
|
| 3 |
/** |
| 4 |
* Auto update endpoint class. |
| 5 |
* |
| 6 |
* POST /sites/%s/maybe_auto_update |
| 7 |
*/ |
| 8 |
class Jetpack_JSON_API_Maybe_Auto_Update_Endpoint extends Jetpack_JSON_API_Endpoint { |
| 9 |
|
| 10 |
/** |
| 11 |
* Needed capabilities. |
| 12 |
* |
| 13 |
* @var array |
| 14 |
*/ |
| 15 |
protected $needed_capabilities = array( 'update_core', 'update_plugins', 'update_themes' ); |
| 16 |
|
| 17 |
/** |
| 18 |
* Update results. |
| 19 |
* |
| 20 |
* @var array |
| 21 |
*/ |
| 22 |
protected $update_results = array(); |
| 23 |
|
| 24 |
/** |
| 25 |
* The result. |
| 26 |
* |
| 27 |
* @return array |
| 28 |
*/ |
| 29 |
protected function result() { |
| 30 |
add_action( 'automatic_updates_complete', array( $this, 'get_update_results' ), 100, 1 ); |
| 31 |
|
| 32 |
wp_maybe_auto_update(); |
| 33 |
|
| 34 |
$result = array(); |
| 35 |
$result['log'] = $this->update_results; |
| 36 |
|
| 37 |
if ( empty( $result['log'] ) ) { |
| 38 |
$possible_reasons_for_failure = Jetpack_Autoupdate::get_possible_failures(); |
| 39 |
|
| 40 |
if ( $possible_reasons_for_failure ) { |
| 41 |
$result['log']['error'] = $possible_reasons_for_failure; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
return $result; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Get update results. |
| 50 |
* |
| 51 |
* @param array $results - the results. |
| 52 |
*/ |
| 53 |
public function get_update_results( $results ) { |
| 54 |
$this->update_results = $results; |
| 55 |
} |
| 56 |
} |
| 57 |
|