Merge pull request #11992 from woocommerce/orphaned-variations-11979
Adds a system status tool for clearing orphaned variations
This commit is contained in:
commit
6b9e2bbd1a
|
@ -120,6 +120,11 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
|
||||||
'name' => __( 'Expired Transients', 'woocommerce' ),
|
'name' => __( 'Expired Transients', 'woocommerce' ),
|
||||||
'button' => __( 'Clear expired transients', 'woocommerce' ),
|
'button' => __( 'Clear expired transients', 'woocommerce' ),
|
||||||
'desc' => __( 'This tool will clear ALL expired transients from WordPress.', 'woocommerce' ),
|
'desc' => __( 'This tool will clear ALL expired transients from WordPress.', 'woocommerce' ),
|
||||||
|
),
|
||||||
|
'delete_orphaned_variations' => array(
|
||||||
|
'name' => __( 'Orphaned Variations', 'woocommerce' ),
|
||||||
|
'button' => __( 'Delete orphaned variations', 'woocommerce' ),
|
||||||
|
'desc' => __( 'This tool will delete all variations which have no parent.', 'woocommerce' ),
|
||||||
),
|
),
|
||||||
'recount_terms' => array(
|
'recount_terms' => array(
|
||||||
'name' => __( 'Term counts', 'woocommerce' ),
|
'name' => __( 'Term counts', 'woocommerce' ),
|
||||||
|
@ -199,7 +204,6 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update (execute) a tool.
|
* Update (execute) a tool.
|
||||||
|
|
||||||
* @param WP_REST_Request $request
|
* @param WP_REST_Request $request
|
||||||
* @return WP_Error|WP_REST_Response
|
* @return WP_Error|WP_REST_Response
|
||||||
*/
|
*/
|
||||||
|
@ -375,6 +379,16 @@ class WC_REST_System_Status_Tools_Controller extends WC_REST_Controller {
|
||||||
|
|
||||||
$message = sprintf( __( '%d Transients Rows Cleared', 'woocommerce' ), $rows + $rows2 );
|
$message = sprintf( __( '%d Transients Rows Cleared', 'woocommerce' ), $rows + $rows2 );
|
||||||
break;
|
break;
|
||||||
|
case 'delete_orphaned_variations' :
|
||||||
|
/**
|
||||||
|
* Delete orphans
|
||||||
|
*/
|
||||||
|
$result = absint( $wpdb->query( "DELETE products
|
||||||
|
FROM {$wpdb->posts} products
|
||||||
|
LEFT JOIN {$wpdb->posts} wp ON wp.ID = products.post_parent
|
||||||
|
WHERE wp.ID IS NULL AND products.post_type = 'product_variation';" ) );
|
||||||
|
$message = sprintf( __( '%d Orphaned Variations Deleted', 'woocommerce' ), $result );
|
||||||
|
break;
|
||||||
case 'reset_roles' :
|
case 'reset_roles' :
|
||||||
// Remove then re-add caps and roles
|
// Remove then re-add caps and roles
|
||||||
WC_Install::remove_roles();
|
WC_Install::remove_roles();
|
||||||
|
|
Loading…
Reference in New Issue