' . esc_html__( 'Suggested text:', 'agevow-age-verification-age-gate' ) . ' '; $note = function ( $text ) { return '

' . esc_html( $text ) . '

'; }; $para = function ( $text ) use ( $suggest ) { return '

' . $suggest . esc_html( $text ) . '

'; }; $html = $note( __( 'Agevow keeps no birth date, no IP address and nothing about a visitor who only answers the age gate, and it sends nothing about your visitors or customers to any other company or service. Its More plugins page asks WordPress.org for our plugin list only when you open it (see the readme\'s External services). The suggested text below says what it does keep; change it to match your settings (Agevow › Settings).', 'agevow-age-verification-age-gate' ) ); $html .= $para( sprintf( /* translators: %d: how many days a visitor who confirmed their age is not asked again. */ _n( 'Some pages and products of this site are only for people who have reached a minimum age, and we ask your age before you see them. Your answer stays in your browser. When you confirm your age, your browser keeps a small mark — the cookie agevow_ok, and the same mark in your browser\'s storage — that holds only the minimum age you confirmed and the day you confirmed it, so that you are not asked again for %d day. If you say that you have not reached the minimum age, your browser remembers that until you close the tab. Your browser also tells this site that the question was asked and how it was answered; we keep only a count of those answers for each day, with nothing that identifies you.', 'Some pages and products of this site are only for people who have reached a minimum age, and we ask your age before you see them. Your answer stays in your browser. When you confirm your age, your browser keeps a small mark — the cookie agevow_ok, and the same mark in your browser\'s storage — that holds only the minimum age you confirmed and the day you confirmed it, so that you are not asked again for %d days. If you say that you have not reached the minimum age, your browser remembers that until you close the tab. Your browser also tells this site that the question was asked and how it was answered; we keep only a count of those answers for each day, with nothing that identifies you.', $days, 'agevow-age-verification-age-gate' ), $days ) ); $html .= $para( __( 'When an order holds a product that is only for people who have reached a minimum age, the checkout asks you to confirm your age or to give your date of birth. Your date of birth is used only to work out, at that moment, whether you have reached the minimum age; it is never kept and never sent anywhere. With your order we keep that your age was checked: how (a confirmation or a date of birth), the minimum age, the result and the time. We keep this for as long as we keep the order. If an order is refused because of the age given, we keep a count of the refusal — where it was asked, how, at what minimum age and when — with no order and nothing that identifies you.', 'agevow-age-verification-age-gate' ) ); $months = Remember::months(); if ( $months > 0 ) { $html .= $para( sprintf( /* translators: %d: how many months a customer's age check is remembered. */ _n( 'If you are logged in to your account when your age is checked at checkout, your account keeps that you passed: the minimum age, how your age was checked and when — never your date of birth — so that you are not asked again at checkout for %d month. If you order without an account, you are asked every time.', 'If you are logged in to your account when your age is checked at checkout, your account keeps that you passed: the minimum age, how your age was checked and when — never your date of birth — so that you are not asked again at checkout for %d months. If you order without an account, you are asked every time.', $months, 'agevow-age-verification-age-gate' ), $months ) ); } $html .= $para( __( 'When someone who runs this site changes the settings of the age check, the change, its time and their user account are kept, so that the site can show which settings were in force on a given day.', 'agevow-age-verification-age-gate' ) ); $html .= $para( __( 'None of this is sent to any other company or service.', 'agevow-age-verification-age-gate' ) ); $html .= $note( __( 'Tools › Export Personal Data: a customer\'s export holds the age checks of their orders and the check remembered on their account, and a user\'s export holds the settings changes they made. Tools › Erase Personal Data: a customer\'s age checks are taken off their orders when WooCommerce\'s "Remove personal data from orders on request" is ticked (WooCommerce › Settings › Accounts & Privacy) — otherwise they are kept with the order, as the order itself is — the check remembered on their account is always removed, and a user\'s account is taken off the settings history, which then reads "a former user". The daily counts hold no personal data.', 'agevow-age-verification-age-gate' ) ); $html .= $note( __( 'This is not legal advice.', 'agevow-age-verification-age-gate' ) ); return $html; } // ── the lists WordPress's tools read ───────────────────────────────────── /** * Our two exporters. * * @param mixed $exporters The site's exporters. * @return array> */ public static function exporters( $exporters ) { $exporters = is_array( $exporters ) ? $exporters : array(); $exporters['agevow-checks'] = array( 'exporter_friendly_name' => __( 'Agevow age checks', 'agevow-age-verification-age-gate' ), 'callback' => array( self::class, 'export_checks' ), ); $exporters['agevow-history'] = array( 'exporter_friendly_name' => __( 'Agevow settings history', 'agevow-age-verification-age-gate' ), 'callback' => array( self::class, 'export_history' ), ); return $exporters; } /** * Our two erasers, placed before every other (see init()). * * @param mixed $erasers The site's erasers. * @return array> */ public static function erasers( $erasers ) { $ours = array( 'agevow-checks' => array( 'eraser_friendly_name' => __( 'Agevow age checks', 'agevow-age-verification-age-gate' ), 'callback' => array( self::class, 'erase_checks' ), ), 'agevow-history' => array( 'eraser_friendly_name' => __( 'Agevow settings history', 'agevow-age-verification-age-gate' ), 'callback' => array( self::class, 'erase_history' ), ), ); $rest = is_array( $erasers ) ? $erasers : array(); unset( $rest['agevow-checks'], $rest['agevow-history'] ); return array_merge( $ours, $rest ); } // ── the age checks of a customer's orders ──────────────────────────────── /** * One page of a customer's orders, found the way WooCommerce's own exporter and * eraser find them: the e-mail on the order, or the account with that e-mail. * * @param string $email The person's e-mail. * @param int $page 1-based. * @return array */ public static function orders( $email, $page ) { $email = is_string( $email ) ? trim( $email ) : ''; if ( ! function_exists( 'wc_get_orders' ) || ! is_email( $email ) ) { return array(); } $customer = array( $email ); $user = get_user_by( 'email', $email ); if ( $user ) { $customer[] = (int) $user->ID; } $orders = wc_get_orders( array( 'limit' => self::ORDERS_PER_PAGE, 'page' => max( 1, (int) $page ), 'customer' => $customer, 'orderby' => 'ID', 'order' => 'ASC', ) ); return is_array( $orders ) ? array_values( array_filter( $orders, function ( $order ) { return $order instanceof \WC_Order; } ) ) : array(); } /** * The checks an order carries: its rows, or — when no row is left (a table * restored without them) — the order's own record. * * @param \WC_Order $order The order. * @return array> source (may be ''), method, min_age, result, checked_at. */ public static function checks_of( $order ) { $rows = Checks::of_order( (int) $order->get_id() ); if ( array() !== $rows ) { return $rows; } $meta = $order->get_meta( Checks::ORDER_META, true ); if ( ! is_array( $meta ) || ! isset( $meta['method'], $meta['min_age'], $meta['result'] ) ) { return array(); } return array( array( 'source' => isset( $meta['remembered'] ) ? 'remembered' : '', 'method' => (string) $meta['method'], 'min_age' => (int) $meta['min_age'], 'result' => (string) $meta['result'], 'checked_at' => isset( $meta['time'] ) ? (string) $meta['time'] : '', 'ref' => isset( $meta['remembered'] ) ? (string) $meta['remembered'] : null, ), ); } /** * Export: the age checks of the person's orders. * * @param string $email The person's e-mail. * @param int $page 1-based. * @return array{data: array>, done: bool} */ public static function export_checks( $email, $page = 1 ) { $orders = self::orders( $email, $page ); $items = 1 === (int) $page ? self::export_mark( $email ) : array(); foreach ( $orders as $order ) { foreach ( self::checks_of( $order ) as $i => $check ) { $data = array( array( 'name' => __( 'Order', 'agevow-age-verification-age-gate' ), 'value' => (string) $order->get_order_number(), ), array( 'name' => __( 'Checked', 'agevow-age-verification-age-gate' ), 'value' => '' !== $check['checked_at'] ? Record::local( $check['checked_at'] ) : '', ), ); if ( '' !== $check['source'] ) { $data[] = array( 'name' => __( 'Where', 'agevow-age-verification-age-gate' ), 'value' => Record::where( $check ), ); } $data[] = array( 'name' => __( 'How', 'agevow-age-verification-age-gate' ), 'value' => Record::method_word( $check['method'] ), ); $data[] = array( 'name' => __( 'Minimum age', 'agevow-age-verification-age-gate' ), /* translators: %d: a minimum age, 18 to 25. */ 'value' => sprintf( __( '%d+', 'agevow-age-verification-age-gate' ), (int) $check['min_age'] ), ); $data[] = array( 'name' => __( 'Result', 'agevow-age-verification-age-gate' ), 'value' => Record::result_word( $check['result'] ), ); $items[] = array( 'group_id' => 'agevow-checks', 'group_label' => __( 'Age checks', 'agevow-age-verification-age-gate' ), 'group_description' => __( 'The age checks of your orders: how your age was checked, at what minimum age, the result and when. No date of birth is kept.', 'agevow-age-verification-age-gate' ), 'item_id' => 'agevow-check-' . (int) $order->get_id() . '-' . (int) $i, 'data' => $data, ); } } return array( 'data' => $items, 'done' => count( $orders ) < self::ORDERS_PER_PAGE, ); } /** * Export: the age check remembered on the person's account (B1), or nothing. * * @param string $email The person's e-mail. * @return array> */ public static function export_mark( $email ) { $user = is_string( $email ) && is_email( trim( $email ) ) ? get_user_by( 'email', trim( $email ) ) : false; $mark = $user ? Remember::of( (int) $user->ID ) : null; if ( null === $mark ) { return array(); } return array( array( 'group_id' => 'agevow-remembered', 'group_label' => __( 'Remembered age check', 'agevow-age-verification-age-gate' ), 'group_description' => __( 'Your account keeps that you passed the age check at checkout, so that you are not asked again for a while: the minimum age, how and when. No date of birth is kept.', 'agevow-age-verification-age-gate' ), 'item_id' => 'agevow-remembered-' . (int) $user->ID, 'data' => array( array( 'name' => __( 'Checked', 'agevow-age-verification-age-gate' ), 'value' => Record::local( $mark['time'] ), ), array( 'name' => __( 'How', 'agevow-age-verification-age-gate' ), 'value' => Record::method_word( $mark['method'] ), ), array( 'name' => __( 'Minimum age', 'agevow-age-verification-age-gate' ), /* translators: %d: a minimum age, 18 to 25. */ 'value' => sprintf( __( '%d+', 'agevow-age-verification-age-gate' ), (int) $mark['min_age'] ), ), ), ), ); } /** * Erase: take the age checks off the person's orders — or say they were kept with * the order, when the shop keeps orders' personal data. * * @param string $email The person's e-mail. * @param int $page 1-based. * @return array{items_removed: bool, items_retained: bool, messages: string[], done: bool} */ public static function erase_checks( $email, $page = 1 ) { $out = array( 'items_removed' => false, 'items_retained' => false, 'messages' => array(), 'done' => true, ); // The account's remembered check (B1): always removed — it only spares the // customer the question, and without it they are asked again. $user = 1 === (int) $page && is_string( $email ) && is_email( trim( $email ) ) ? get_user_by( 'email', trim( $email ) ) : false; if ( $user && Remember::forget( (int) $user->ID ) ) { $out['items_removed'] = true; $out['messages'][] = __( 'Removed the remembered age check from the account: the customer is asked again at their next order.', 'agevow-age-verification-age-gate' ); } $orders = self::orders( $email, $page ); foreach ( $orders as $order ) { if ( array() === self::checks_of( $order ) ) { continue; } if ( self::erases( $order ) ) { Checks::unlink_order( (int) $order->get_id() ); $out['items_removed'] = true; /* translators: %s: an order number. */ $out['messages'][] = sprintf( __( 'Removed the age check from order %s.', 'agevow-age-verification-age-gate' ), $order->get_order_number() ); } else { $out['items_retained'] = true; /* translators: %s: an order number. */ $out['messages'][] = sprintf( __( 'The age check of order %s is kept with the order, and is removed whenever the order\'s personal data is.', 'agevow-age-verification-age-gate' ), $order->get_order_number() ); } } $out['done'] = count( $orders ) < self::ORDERS_PER_PAGE; return $out; } /** * Whether an erasure request takes the check off this order: WooCommerce's own * setting for orders ("Remove personal data from orders on request", off unless the * shop turned it on), filterable per order (`agevow_privacy_erase_check`). * * @param \WC_Order $order The order. * @return bool */ public static function erases( $order ) { $erase = 'yes' === get_option( 'woocommerce_erasure_request_removes_order_data', 'no' ); /** * Filters whether an erasure request takes the age check off this order. * * @param bool $erase WooCommerce's setting for orders. * @param \WC_Order $order The order. */ return (bool) apply_filters( 'agevow_privacy_erase_check', $erase, $order ); } /** * WooCommerce is removing an order's personal data (its eraser, the orders * screen's bulk action, its clean-up of old orders): the check goes with it. * * @param mixed $order The order. * @return void */ public static function order_erased( $order ) { if ( $order instanceof \WC_Order ) { Checks::unlink_order( (int) $order->get_id() ); } } // ── a user's changes in the settings history ───────────────────────────── /** * Export: the changes the person's account made to the settings. * * @param string $email The person's e-mail. * @param int $page 1-based. * @return array{data: array>, done: bool} */ public static function export_history( $email, $page = 1 ) { $user = is_string( $email ) && is_email( trim( $email ) ) ? get_user_by( 'email', trim( $email ) ) : false; if ( ! $user ) { return array( 'data' => array(), 'done' => true, ); } $rows = History::by_user( (int) $user->ID, $page, self::HISTORY_PER_PAGE ); $items = array(); foreach ( $rows as $entry ) { $items[] = array( 'group_id' => 'agevow-history', 'group_label' => __( 'Age check settings changes', 'agevow-age-verification-age-gate' ), 'group_description' => __( 'The changes your account made to the settings of the age check, and when.', 'agevow-age-verification-age-gate' ), 'item_id' => 'agevow-history-' . (int) $entry['id'], 'data' => array( array( 'name' => __( 'Changed', 'agevow-age-verification-age-gate' ), 'value' => Record::local( $entry['changed_at'] ), ), array( 'name' => __( 'Change', 'agevow-age-verification-age-gate' ), 'value' => Record::describe( $entry ), ), ), ); } return array( 'data' => $items, 'done' => count( $rows ) < self::HISTORY_PER_PAGE, ); } /** * Erase: take the person's account off the settings history. * * @param string $email The person's e-mail. * @param int $page 1-based (one page does it all). * @return array{items_removed: bool, items_retained: bool, messages: string[], done: bool} */ public static function erase_history( $email, $page = 1 ) { unset( $page ); $out = array( 'items_removed' => false, 'items_retained' => false, 'messages' => array(), 'done' => true, ); $user = is_string( $email ) && is_email( trim( $email ) ) ? get_user_by( 'email', trim( $email ) ) : false; $n = $user ? History::forget_user( (int) $user->ID ) : 0; if ( $n > 0 ) { $out['items_removed'] = true; /* translators: %d: how many changes. */ $out['messages'][] = sprintf( _n( 'Took the account off %d change in the age check\'s settings history.', 'Took the account off %d changes in the age check\'s settings history.', $n, 'agevow-age-verification-age-gate' ), $n ); } return $out; } }