PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
← All changes | src/Addons/Tools/API/ToolsEndpoints.php +50 -1 6.4.0 → 8.0.2 View file →
@@ -104,9 +104,21 @@
104 104 }
105 105
106 106 public function cleanupData( WP_REST_Request $request ) {
107 107 $cleanStandard = filter_var( $request->get_param( 'clean_standard' ), FILTER_VALIDATE_BOOLEAN );
108 - $roles = $request->get_param( 'roles' ); // array of role keys
108 + $cleanUsers = filter_var( $request->get_param( 'clean_users' ), FILTER_VALIDATE_BOOLEAN );
109 + $cleanAllRoles = filter_var( $request->get_param( 'clean_all_roles' ), FILTER_VALIDATE_BOOLEAN );
110 +
111 + if ( $cleanAllRoles ) {
112 + global $wp_roles;
113 + if ( ! isset( $wp_roles ) ) {
114 + $wp_roles = new \WP_Roles();
115 + }
116 + $roles = array_keys( $wp_roles->get_names() );
117 + } else {
118 + $roles = $request->get_param( 'roles' ); // array of role keys
119 + }
120 +
109 121 $categories = $request->get_param( 'categories' ); // array of term ids
110 122 $products = $request->get_param( 'products' ); // array of product ids
111 123
112 124 $metaKeysToDelete = array();
@@ -190,8 +202,45 @@
190 202 'message' => 'Database error during cleanup.',
191 203 ) );
192 204 }
193 205 }
206 +
207 + if ( $cleanUsers ) {
208 + global $wpdb;
209 +
210 + $userMetaLikeQueries = array(
211 + "meta_key LIKE '\_user\_%\_tiered_price\_pricing\_type'",
212 + "meta_key LIKE '\_user\_%\_tiered_price\_regular\_price'",
213 + "meta_key LIKE '\_user\_%\_tiered_price\_sale\_price'",
214 + "meta_key LIKE '\_user\_%\_tiered_price\_discount'",
215 + "meta_key LIKE '\_user\_%\_tiered_price\_discount\_type'",
216 + "meta_key LIKE '\_user\_%\_tiered_price\_rules\_type'",
217 + "meta_key LIKE '\_user\_%\_percentage\_price\_rules'",
218 + "meta_key LIKE '\_user\_%\_fixed\_price\_rules'",
219 + "meta_key LIKE '\_user\_%\_tiered_price\_minimum\_qty'",
220 + "meta_key LIKE '\_user\_%\_tiered_price\_tax\_status'",
221 + "meta_key LIKE '\_user\_%\_tiered_price\_tax\_class'"
222 + );
223 +
224 + $likeQuery = implode( ' OR ', $userMetaLikeQueries );
225 +
226 + if ( empty( $products ) && empty( $categories ) ) {
227 + $query = "DELETE FROM {$wpdb->postmeta} WHERE ($likeQuery)";
228 + $userDeletedCount = $wpdb->query( $query );
229 + } else {
230 + if ( ! empty( $postIds ) ) {
231 + $postIdsIn = implode( ',', $postIds );
232 + $query = "DELETE FROM {$wpdb->postmeta} WHERE ($likeQuery) AND post_id IN ($postIdsIn)";
233 + $userDeletedCount = $wpdb->query( $query );
234 + }
235 + }
236 +
237 + if ( $userDeletedCount !== false ) {
238 + $deletedCount += $userDeletedCount;
239 + }
240 + }
241 +
242 + delete_option( \TierPricingTable\Admin\Tips\Tip::SEEN_TIPS_OPTION_KEY );
194 243
195 244 $message = sprintf( 'Successfully cleaned up %d product records.', $deletedCount );
196 245
197 246 return rest_ensure_response( array(