| 1 |
<?php |
| 2 |
/** |
| 3 |
* Auto Update |
| 4 |
* |
| 5 |
* @package GamiPress\Admin\Auto_Update |
| 6 |
* @author GamiPress <contact@gamipress.com>, Ruben Garcia <rubengcdev@gmail.com> |
| 7 |
* @since 1.1.2 |
| 8 |
*/ |
| 9 |
// Exit if accessed directly |
| 10 |
if( !defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Filters the auto update plugin routine to allow GamiPress to be automatically updated. |
| 14 |
* |
| 15 |
* @since 1.1.2 |
| 16 |
* |
| 17 |
* @param bool $update Flag to update the plugin or not. |
| 18 |
* @param array $item Update data about a specific plugin. |
| 19 |
* |
| 20 |
* @return bool $update The new update state. |
| 21 |
*/ |
| 22 |
function gamipress_auto_update_plugin( $update, $item ) { |
| 23 |
|
| 24 |
$item = (array) $item; |
| 25 |
|
| 26 |
// If do not have everything we need, return |
| 27 |
if ( ! isset( $item['new_version'] ) || ! isset( $item['slug'] ) ) { |
| 28 |
return $update; |
| 29 |
} |
| 30 |
|
| 31 |
$automatic_updates = (bool) gamipress_get_option( 'automatic_updates', false ); |
| 32 |
|
| 33 |
// Return if not automatic updates enabled |
| 34 |
if( $automatic_updates !== true ) { |
| 35 |
return $update; |
| 36 |
} |
| 37 |
|
| 38 |
$automatic_updates_plugins = gamipress_get_option( 'automatic_updates_plugins', false ); |
| 39 |
|
| 40 |
// if not is an array, initialize |
| 41 |
if( ! is_array( $automatic_updates_plugins ) ) { |
| 42 |
$automatic_updates_plugins = array(); |
| 43 |
} |
| 44 |
|
| 45 |
// Automatic updates plugins is an array of plugin_slug => plugin_title, so we need the keys |
| 46 |
$automatic_updates_plugins = array_keys( $automatic_updates_plugins ); |
| 47 |
|
| 48 |
// Add gamipress to the plugins slugs |
| 49 |
$automatic_updates_plugins[] = 'gamipress'; |
| 50 |
|
| 51 |
// Just return true if automatic updates was checked and plugin is on the automatic updates plugins array |
| 52 |
if( in_array( $item['slug'], $automatic_updates_plugins ) ) { |
| 53 |
return $update; |
| 54 |
} |
| 55 |
|
| 56 |
return $update; |
| 57 |
|
| 58 |
} |
| 59 |
add_filter( 'auto_update_plugin', 'gamipress_auto_update_plugin', 10, 2 ); |