2021-11-17 22:08:52 +00:00
|
|
|
<?php
|
|
|
|
|
2023-08-09 00:20:34 +00:00
|
|
|
defined( 'ABSPATH' ) || exit;
|
2021-11-17 22:08:52 +00:00
|
|
|
|
|
|
|
register_woocommerce_admin_test_helper_rest_route(
|
|
|
|
'/tools/get-update-versions/v1',
|
|
|
|
'tools_get_wc_admin_versions',
|
|
|
|
array(
|
|
|
|
'methods' => 'GET',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
register_woocommerce_admin_test_helper_rest_route(
|
|
|
|
'/tools/trigger-selected-update-callbacks/v1',
|
|
|
|
'trigger_selected_update_callbacks',
|
|
|
|
array(
|
|
|
|
'methods' => 'POST',
|
2023-08-09 00:20:34 +00:00
|
|
|
'args' => array(
|
|
|
|
'version' => array(
|
2021-11-17 22:08:52 +00:00
|
|
|
'description' => 'Name of the update version',
|
|
|
|
'type' => 'string',
|
|
|
|
'sanitize_callback' => 'sanitize_text_field',
|
2023-08-09 00:20:34 +00:00
|
|
|
),
|
2021-11-17 22:08:52 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2023-08-09 00:20:34 +00:00
|
|
|
/**
|
|
|
|
* A tool to get the list of WooCommerce Admin update versions.
|
|
|
|
*/
|
2021-11-17 22:08:52 +00:00
|
|
|
function tools_get_wc_admin_versions() {
|
2023-08-09 00:20:34 +00:00
|
|
|
$db_updates = \WC_Install::get_db_update_callbacks();
|
2021-11-17 22:08:52 +00:00
|
|
|
|
|
|
|
return new WP_REST_Response( array_keys( $db_updates ), 200 );
|
|
|
|
}
|
|
|
|
|
2023-08-09 00:20:34 +00:00
|
|
|
/**
|
|
|
|
* Triggers the selected version update callback.
|
|
|
|
*
|
|
|
|
* @param WP_REST_Request $request The full request data.
|
|
|
|
*/
|
2021-11-17 22:08:52 +00:00
|
|
|
function trigger_selected_update_callbacks( $request ) {
|
|
|
|
$version = $request->get_param( 'version' );
|
|
|
|
if ( ! isset( $version ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-09 00:20:34 +00:00
|
|
|
$db_updates = \WC_Install::get_db_update_callbacks();
|
2021-11-17 22:08:52 +00:00
|
|
|
$update_callbacks = $db_updates[ $version ];
|
|
|
|
|
|
|
|
foreach ( $update_callbacks as $update_callback ) {
|
2024-07-16 11:55:38 +00:00
|
|
|
\WC_Install::run_update_callback( $update_callback );
|
2021-11-17 22:08:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|