| 1 |
<?php |
| 2 |
/** |
| 3 |
* Global functions for Perfops One features. |
| 4 |
* |
| 5 |
* @package @package PerfOpsOne |
| 6 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 7 |
* @since 2.0.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
global $wp_version; |
| 11 |
|
| 12 |
use Decalog\System\Plugin; |
| 13 |
|
| 14 |
if ( ! function_exists( 'poo_switch_autoupdate_callback' ) ) { |
| 15 |
/** |
| 16 |
* Ajax callback for autoupdate switching. |
| 17 |
* |
| 18 |
* @since 2.0.0 |
| 19 |
*/ |
| 20 |
function poo_switch_autoupdate_callback() { |
| 21 |
check_ajax_referer( 'poo-auto-update', 'nonce' ); |
| 22 |
$plugin = new Plugin( filter_input( INPUT_POST, 'plugin' ) ); |
| 23 |
if ( ! current_user_can( 'update_plugins' ) || ! wp_is_auto_update_enabled_for_type( 'plugin' ) || ( is_multisite() && ! is_network_admin() ) ) { |
| 24 |
wp_die( 403 ); |
| 25 |
} |
| 26 |
if ( $plugin->switch_auto_update() ) { |
| 27 |
wp_die( 200 ); |
| 28 |
} else { |
| 29 |
wp_die( 500 ); |
| 30 |
} |
| 31 |
} |
| 32 |
add_action( 'wp_ajax_poo_switch_autoupdate', 'poo_switch_autoupdate_callback' ); |
| 33 |
} |
| 34 |
|