__('CrewCommerce company account', 'crewcommerce'), 'callback' => array($this, 'export'), ); return $exporters; } public function register_eraser($erasers) { $erasers['crewcommerce'] = array( 'eraser_friendly_name' => __('CrewCommerce company account', 'crewcommerce'), 'callback' => array($this, 'erase'), ); return $erasers; } public function add_privacy_policy_content() { if (!function_exists('wp_add_privacy_policy_content')) { return; } $text = '
' . __('If you buy from us as part of a business account, we record which company you belong to and your role in it. When an order needs approval we record who requested it, who approved or rejected it, any note they left, and when.', 'crewcommerce') . '
' . '' . __('Your company’s Admin and Managers can see your membership and your requests. We use this information to run your company’s purchasing approvals and to answer questions about past orders.', 'crewcommerce') . '
'; wp_add_privacy_policy_content('CrewCommerce', wp_kses_post($text)); } /** * Exporter callback: one batch of up to PER_PAGE items per page. */ public function export($email_address, $page = 1) { global $wpdb; $user = get_user_by('email', $email_address); if (!$user) { return array('data' => array(), 'done' => true); } $uid = (int) $user->ID; $page = max(1, (int) $page); $offset = ($page - 1) * self::PER_PAGE; $items = array(); // Page 1 carries the membership; the other groups page together. if ($page === 1) { $team = CrewCommerce_Team_Accounts::get_instance(); $company_id = $team->get_user_company($uid); if ($company_id) { $row = $wpdb->get_row($wpdb->prepare( // phpcs:ignore WordPress.DB.DirectDatabaseQuery "SELECT role, created_at FROM {$wpdb->prefix}crewcommerce_team_members WHERE user_id = %d AND company_id = %d", $uid, $company_id )); $items[] = array( 'group_id' => 'crewcommerce-membership', 'group_label' => __('Company membership', 'crewcommerce'), 'item_id' => 'crewcommerce-membership-' . $uid, 'data' => array( array('name' => __('Company', 'crewcommerce'), 'value' => get_the_title($company_id)), array('name' => __('Role', 'crewcommerce'), 'value' => $row ? ucfirst($row->role) : ''), array('name' => __('Joined', 'crewcommerce'), 'value' => $row ? $row->created_at : ''), ), ); } } $workflows = $wpdb->get_results($wpdb->prepare( // phpcs:ignore WordPress.DB.DirectDatabaseQuery "SELECT id, order_id, requester_id, approver_id, status, notes, created_at, updated_at FROM {$wpdb->prefix}crewcommerce_approval_workflows WHERE requester_id = %d OR approver_id = %d ORDER BY id ASC LIMIT %d OFFSET %d", $uid, $uid, self::PER_PAGE, $offset )); foreach ($workflows as $wf) { $order = wc_get_order($wf->order_id); $number = $order ? $order->get_order_number() : $wf->order_id; $as_requester = ((int) $wf->requester_id === $uid); $data = array( array('name' => __('Order', 'crewcommerce'), 'value' => '#' . $number), array('name' => __('Your part', 'crewcommerce'), 'value' => $as_requester ? __('Requested approval', 'crewcommerce') : __('Approver', 'crewcommerce')), array('name' => __('Status', 'crewcommerce'), 'value' => ucfirst($wf->status)), array('name' => __('Requested', 'crewcommerce'), 'value' => $wf->created_at), array('name' => __('Last updated', 'crewcommerce'), 'value' => $wf->updated_at), ); if (!$as_requester && $wf->notes !== null && $wf->notes !== '') { $data[] = array('name' => __('Your decision notes', 'crewcommerce'), 'value' => $wf->notes); } $items[] = array( 'group_id' => 'crewcommerce-approvals', 'group_label' => __('Order approvals', 'crewcommerce'), 'item_id' => 'crewcommerce-approval-' . $wf->id, 'data' => $data, ); } $done = count($workflows) < self::PER_PAGE; return array('data' => $items, 'done' => $done); } /** * Eraser: removes the company membership (kept for a company Admin, who has * to be replaced first). Approval decisions stay, as part of the order record. */ public function erase($email_address, $page = 1) { global $wpdb; $user = get_user_by('email', $email_address); $response = array('items_removed' => false, 'items_retained' => false, 'messages' => array(), 'done' => true); if (!$user) { return $response; } $uid = (int) $user->ID; $team = CrewCommerce_Team_Accounts::get_instance(); $company_id = $team->get_user_company($uid); if ($company_id) { if ($team->get_user_role($uid) === 'admin') { $response['items_retained'] = true; $response['messages'][] = sprintf( /* translators: %s: company name */ __('Kept this person\'s membership of %s because they are its Admin. Make someone else the company Admin, then run the erasure again.', 'crewcommerce'), get_the_title($company_id) ); } else { $team->remove_team_member($uid, $company_id); $response['items_removed'] = true; } } $decisions = (int) $wpdb->get_var($wpdb->prepare( // phpcs:ignore WordPress.DB.DirectDatabaseQuery "SELECT COUNT(*) FROM {$wpdb->prefix}crewcommerce_approval_workflows WHERE requester_id = %d OR approver_id = %d", $uid, $uid )); if ($decisions > 0) { $response['items_retained'] = true; $response['messages'][] = __('Kept approval records (who requested and who approved each order) because they are part of the order history.', 'crewcommerce'); } return $response; } }