| 1 |
<?php |
| 2 |
/** |
| 3 |
* Action Hooks for Jetpack Backup module. |
| 4 |
* |
| 5 |
* @package automattic/jetpack-backup |
| 6 |
*/ |
| 7 |
|
| 8 |
// If WordPress's plugin API is available already, use it. If not, |
| 9 |
// drop data into `$wp_filter` for `WP_Hook::build_preinitialized_hooks()`. |
| 10 |
if ( function_exists( 'add_filter' ) ) { |
| 11 |
$add_filter = 'add_filter'; |
| 12 |
$add_action = 'add_action'; |
| 13 |
} else { |
| 14 |
$add_filter = function ( $name, $cb, $priority = 10, $accepted_args = 1 ) { |
| 15 |
global $wp_filter; |
| 16 |
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 17 |
$wp_filter[ $name ][ $priority ][] = array( |
| 18 |
'accepted_args' => $accepted_args, |
| 19 |
'function' => $cb, |
| 20 |
); |
| 21 |
}; |
| 22 |
$add_action = $add_filter; |
| 23 |
} |
| 24 |
|
| 25 |
// Clean up expired Helper Scripts from a scheduled event. |
| 26 |
$add_action( 'jetpack_backup_cleanup_helper_scripts', array( 'Automattic\\Jetpack\\Backup\\V0005\\Helper_Script_Manager', 'cleanup_expired_helper_scripts' ) ); |
| 27 |
|
| 28 |
// Register REST routes. |
| 29 |
$add_action( 'rest_api_init', array( 'Automattic\\Jetpack\\Backup\\V0005\\REST_Controller', 'register_rest_routes' ) ); |
| 30 |
|
| 31 |
// Set up package version hook. |
| 32 |
$add_filter( 'jetpack_package_versions', 'Automattic\\Jetpack\\Backup\\Package_Version::send_package_version_to_tracker' ); |
| 33 |
|
| 34 |
// Register Jetpack Backup abilities with the WordPress Abilities API at autoload |
| 35 |
// time so the surface is available in any consumer that loads this package |
| 36 |
// (both the standalone Jetpack Backup plugin and the Jetpack plugin). The |
| 37 |
// `jetpack_wp_abilities_enabled` filter (default false) gates registration, |
| 38 |
// so this is a no-op until a site opts in. |
| 39 |
$add_action( |
| 40 |
'plugins_loaded', |
| 41 |
static function () { |
| 42 |
if ( ! apply_filters( 'jetpack_wp_abilities_enabled', false ) ) { |
| 43 |
return; |
| 44 |
} |
| 45 |
if ( ! class_exists( \Automattic\Jetpack\Backup\V0005\Abilities\Backup_Abilities::class ) ) { |
| 46 |
return; |
| 47 |
} |
| 48 |
\Automattic\Jetpack\Backup\V0005\Abilities\Backup_Abilities::init(); |
| 49 |
}, |
| 50 |
20 |
| 51 |
); |
| 52 |
|