'ids', 'number' => 0 ) ) as $site_id ) { switch_to_blog( (int) $site_id ); self::site(); restore_current_blog(); } return; } self::site(); } /** * Clean up the current site. * * @return void */ private static function site() { global $wpdb; foreach ( array( 'rtkt_requests', 'rtkt_request_items', 'rtkt_log', 'rtkt_credit' ) as $table ) { $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $wpdb->prefix . $table ) ); } foreach ( array( 'rtkt_settings', 'rtkt_version', 'rtkt_db_version', 'rtkt_pro_db_version', 'rtkt_last_error' ) as $option ) { delete_option( $option ); } delete_transient( 'rtkt_activation_redirect' ); foreach ( array( 'admin_request', 'customer_request', 'customer_withdrawal', 'customer_update', 'customer_link' ) as $email ) { delete_option( 'woocommerce_rtkt_' . $email . '_settings' ); } // Order and order-item meta (exchange orders, store credit), both storages. $order_meta = array( '_rtkt_exchange_for', '_rtkt_credit_spent', '_rtkt_credit_restored' ); $in = implode( ', ', array_fill( 0, count( $order_meta ), '%s' ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- placeholders built above. $wpdb->query( $wpdb->prepare( "DELETE FROM %i WHERE meta_key IN ($in)", array_merge( array( $wpdb->postmeta ), $order_meta ) ) ); $hpos = $wpdb->prefix . 'wc_orders_meta'; if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $hpos ) ) === $hpos ) { // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- placeholders built above. $wpdb->query( $wpdb->prepare( "DELETE FROM %i WHERE meta_key IN ($in)", array_merge( array( $hpos ), $order_meta ) ) ); } $wpdb->query( $wpdb->prepare( 'DELETE FROM %i WHERE meta_key = %s', $wpdb->prefix . 'woocommerce_order_itemmeta', '_rtkt_credit' ) ); $wpdb->query( $wpdb->prepare( 'DELETE FROM %i WHERE option_name LIKE %s OR option_name LIKE %s', $wpdb->options, $wpdb->esc_like( '_transient_rtkt_' ) . '%', $wpdb->esc_like( '_transient_timeout_rtkt_' ) . '%' ) ); $wpdb->query( $wpdb->prepare( 'DELETE FROM %i WHERE meta_key IN (%s, %s)', $wpdb->postmeta, '_rtkt_no_return', '_rtkt_no_withdrawal' ) ); $wpdb->query( $wpdb->prepare( 'DELETE FROM %i WHERE meta_key LIKE %s', $wpdb->usermeta, $wpdb->esc_like( 'rtkt_' ) . '%' ) ); // Protected label uploads (Pro). $uploads = wp_upload_dir( null, false ); $dir = trailingslashit( $uploads['basedir'] ) . 'returnkit-labels'; if ( is_dir( $dir ) ) { // scandir, not glob: the folder holds dotfiles (.htaccess) too. foreach ( array_diff( (array) scandir( $dir ), array( '.', '..' ) ) as $file ) { if ( is_file( $dir . '/' . $file ) ) { wp_delete_file( $dir . '/' . $file ); } } if ( ! array_diff( (array) scandir( $dir ), array( '.', '..' ) ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_rmdir -- our own, now-empty folder. rmdir( $dir ); } } } }