countries ? (array) WC()->countries->get_european_union_countries() : array(); return array_values( array_unique( array_merge( array_map( 'strval', $eu ), self::EEA_EXTRA ) ) ); } /** * True when WooCommerce's selling locations take in a country of the EU or the EEA. * * @return bool */ public static function sells_to_eea() { if ( ! function_exists( 'WC' ) || ! WC()->countries ) { return false; } return array() !== array_intersect( array_keys( (array) WC()->countries->get_allowed_countries() ), self::eea_countries() ); } /** * WooCommerce's selling locations in a few words: all countries, all but * some, or specific countries. * * @return string */ public static function selling_label() { $allowed = (string) get_option( 'woocommerce_allowed_countries', 'all' ); if ( 'specific' === $allowed ) { return __( 'specific countries', 'careback' ); } if ( 'all_except' === $allowed ) { return __( 'all countries, except some', 'careback' ); } return __( 'all countries', 'careback' ); } /** * Withdrawals still being worked on: the open statuses, the withdrawal type. * * @param Requests_Repository $requests The requests table. * @return int */ public static function open_withdrawals( Requests_Repository $requests ) { return (int) $requests->count( Statuses::open(), '', array( 'withdrawal' ) ); } /** * The request list narrowed to the open withdrawals. * * @return string */ public static function open_withdrawals_url() { $query = 'admin.php?page=careback&type[]=withdrawal'; foreach ( Statuses::open() as $status ) { $query .= '&status[]=' . rawurlencode( (string) $status ); } return admin_url( $query ); } /** * The day it was switched off, in the site's date format, or ''. * * @param Settings $settings Plugin settings. * @return string */ public static function off_since( Settings $settings ) { $at = (int) $settings->get( 'withdrawal_off_at', 0 ); return $at > 0 ? (string) wp_date( (string) get_option( 'date_format' ), $at ) : ''; } /** * What the settings form asks of the switch: the values to store and the * result the redirect carries ('' when nothing changed). Off is stored only * with the confirmation; On always. A form that sends no switch changes * nothing. The caller checked the nonce and the capability. * * @param Settings $settings Settings as stored. * @param array $posted The posted form (Admin::save()). * @return array{0:array,1:string} */ public static function from_post( Settings $settings, array $posted ) { if ( ! isset( $posted['withdrawal_enabled'] ) || ! is_scalar( $posted['withdrawal_enabled'] ) ) { return array( array(), '' ); } $want_on = '0' !== sanitize_key( $posted['withdrawal_enabled'] ); $confirm = ! empty( $posted['withdrawal_off_confirm'] ); $is_on = Routes::withdrawal_offered( $settings ); if ( $want_on ) { return $is_on ? array( array(), '' ) : array( array( 'withdrawal_enabled' => 1, 'withdrawal_off_at' => 0, 'withdrawal_off_by' => 0, ), 'on', ); } if ( ! $is_on ) { return array( array(), '' ); } if ( ! $confirm ) { return array( array(), 'unconfirmed' ); } return array( array( 'withdrawal_enabled' => 0, 'withdrawal_off_at' => time(), 'withdrawal_off_by' => get_current_user_id(), ), 'off', ); } /** * The notice at the top of Settings after a save: the switch's result, or * "Settings saved." alone. * * @return void */ public static function saved_notice() { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- a notice after the redirect; nothing is changed. if ( ! isset( $_GET['updated'] ) ) { return; } $result = isset( $_GET[ self::RESULT_ARG ] ) ? sanitize_key( wp_unslash( $_GET[ self::RESULT_ARG ] ) ) : ''; // phpcs:enable WordPress.Security.NonceVerification.Recommended if ( 'unconfirmed' === $result ) { printf( '
%1$s %2$s %3$s %5$s
%s
0 ) : ?>