Plugin Directory

Changeset 3807599


Ignore:
Timestamp:
11/17/2026 02:32:48 PM (4 days ago)
Author:
anishamdi
Message:

Update to version 1.1.0 from GitHub

Location:
takeed-refusal-guard
Files:
6 added
24 edited
1 copied

Legend:

Unmodified
Added
Removed
  • takeed-refusal-guard/tags/1.1.0/includes/class-takrg-admin.php

    r3806545 r3807599  
    3030                add_action( 'admin_post_takrg_import', array( __CLASS__, 'handle_import' ) );
    3131                add_action( 'admin_post_takrg_export', array( __CLASS__, 'handle_export' ) );
     32                add_action( 'admin_post_takrg_rule_add', array( __CLASS__, 'handle_rule_add' ) );
     33                add_action( 'admin_post_takrg_rule_delete', array( __CLASS__, 'handle_rule_delete' ) );
     34                add_action( 'admin_post_takrg_scan', array( __CLASS__, 'handle_scan' ) );
     35                add_action( 'admin_post_takrg_breaker_reset', array( __CLASS__, 'handle_breaker_reset' ) );
     36                add_action( 'admin_notices', array( __CLASS__, 'breaker_notice' ) );
    3237                // Orders list: legacy (posts) screen and HPOS screen.
    3338                add_filter( 'manage_edit-shop_order_columns', array( __CLASS__, 'add_column' ) );
    … …  
    314319
    315320        /**
     321         * Add an allow-list or block-list rule (exact value or wildcard pattern).
     322         */
     323        public static function handle_rule_add() {
     324                self::guard( 'takrg_rule_add' );
     325                // phpcs:disable WordPress.Security.NonceVerification.Missing -- Verified in guard().
     326                $type    = isset( $_POST['takrg_type'] ) && TAKRG_Rules::BLOCK === sanitize_key( wp_unslash( $_POST['takrg_type'] ) ) ? TAKRG_Rules::BLOCK : TAKRG_Rules::ALLOW;
     327                $value   = isset( $_POST['takrg_value'] ) ? sanitize_text_field( wp_unslash( $_POST['takrg_value'] ) ) : '';
     328                $country = TAKRG_Recorder::country_for( isset( $_POST['takrg_country'] ) ? sanitize_text_field( wp_unslash( $_POST['takrg_country'] ) ) : '' );
     329                // phpcs:enable WordPress.Security.NonceVerification.Missing
     330                $id = TAKRG_Rules::add( $type, $value, $country );
     331                TAKRG_Checkout::reset_cache();
     332                self::back( $id ? 'rule_added' : 'rule_invalid' );
     333        }
     334
     335        /**
     336         * Delete a rule.
     337         */
     338        public static function handle_rule_delete() {
     339                self::guard( 'takrg_rule_delete' );
     340                // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified in guard().
     341                TAKRG_Rules::delete( isset( $_POST['takrg_id'] ) ? absint( $_POST['takrg_id'] ) : 0 );
     342                TAKRG_Checkout::reset_cache();
     343                self::back( 'removed', 1 );
     344        }
     345
     346        /**
     347         * Turns the protection back on after the safety breaker tripped.
     348         */
     349        public static function handle_breaker_reset() {
     350                self::guard( 'takrg_breaker_reset' );
     351                TAKRG_Breaker::reset();
     352                self::back( 'breaker_reset' );
     353        }
     354
     355        /**
     356         * Adds the refusals of orders that are already in a counted status (500 orders per click, newest page first).
     357         * Safe to repeat: an order that already has a record is skipped.
     358         */
     359        public static function handle_scan() {
     360                self::guard( 'takrg_scan' );
     361                // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified in guard().
     362                $page  = isset( $_POST['takrg_page'] ) ? max( 1, absint( $_POST['takrg_page'] ) ) : 1;
     363                $added = 0;
     364                $more  = false;
     365                for ( $i = 0; $i < 5; $i++, $page++ ) {
     366                        $orders = wc_get_orders(
     367                                array(
     368                                        'status'  => TAKRG_Settings::counted_statuses(),
     369                                        'limit'   => 100,
     370                                        'paged'   => $page,
     371                                        'orderby' => 'ID',
     372                                        'order'   => 'ASC',
     373                                        'return'  => 'objects',
     374                                )
     375                        );
     376                        foreach ( $orders as $order ) {
     377                                list( $phone, $email ) = TAKRG_Recorder::identity( $order );
     378                                $added                += TAKRG_Store::add( $phone, $email, $order->get_id(), 'scan' ) ? 1 : 0;
     379                        }
     380                        if ( count( $orders ) < 100 ) {
     381                                break;
     382                        }
     383                        $more = true;
     384                }
     385                TAKRG_Checkout::reset_cache();
     386                wp_safe_redirect(
     387                        add_query_arg(
     388                                array(
     389                                        'page'      => self::SLUG,
     390                                        'takrg_msg' => ( $more && count( $orders ) >= 100 ) ? 'scan_more' : 'scanned',
     391                                        'takrg_num' => $added,
     392                                        'takrg_pg'  => $page,
     393                                ),
     394                                admin_url( 'admin.php' )
     395                        )
     396                );
     397                exit;
     398        }
     399
     400        /**
     401         * Admin notice when the safety breaker has tripped (every admin screen, for shop managers).
     402         */
     403        public static function breaker_notice() {
     404                if ( ! current_user_can( self::CAP ) || ! TAKRG_Breaker::is_tripped() ) {
     405                        return;
     406                }
     407                echo '<div class="notice notice-warning"><p><strong>' . esc_html__( 'Takeed Refusal Guard switched itself to "tag only".', 'takeed-refusal-guard' ) . '</strong> '
     408                        . esc_html__( 'More than half of the recent checkout attempts were restricted, so the plugin stopped restricting Cash on Delivery to protect your sales.', 'takeed-refusal-guard' )
     409                        . ' <a href="' . esc_url( admin_url( 'admin.php?page=' . self::SLUG ) ) . '">' . esc_html__( 'Review and turn it back on', 'takeed-refusal-guard' ) . '</a></p></div>';
     410        }
     411
     412        /**
    316413         * Notice texts by key.
    317414         *
    … …  
    331428                                /* translators: %d: number of records. */
    332429                                return array( 'success', sprintf( _n( '%d record imported.', '%d records imported.', $num, 'takeed-refusal-guard' ), $num ) );
     430                        case 'rule_added':
     431                                return array( 'success', __( 'Rule added.', 'takeed-refusal-guard' ) );
     432                        case 'rule_invalid':
     433                                return array( 'error', __( 'Enter an e-mail address, a phone number, or a pattern such as *@example.com or +21620* (not already in the list).', 'takeed-refusal-guard' ) );
     434                        case 'breaker_reset':
     435                                return array( 'success', __( 'Protection turned back on.', 'takeed-refusal-guard' ) );
     436                        case 'scanned':
     437                                /* translators: %d: number of records. */
     438                                return array( 'success', sprintf( _n( 'Scan finished: %d record added.', 'Scan finished: %d records added.', $num, 'takeed-refusal-guard' ), $num ) );
     439                        case 'scan_more':
     440                                /* translators: %d: number of records. */
     441                                return array( 'success', sprintf( _n( '%d record added. More orders remain: press "Continue scan".', '%d records added. More orders remain: press "Continue scan".', $num, 'takeed-refusal-guard' ), $num ) );
    333442                        case 'invalid':
    334443                                return array( 'error', __( 'Enter a valid phone number or e-mail address.', 'takeed-refusal-guard' ) );
    … …  
    375484                // phpcs:enable WordPress.Security.NonceVerification.Recommended
    376485                $per_page = 50;
    377                 $total    = TAKRG_Store::total();
    378                 $rows     = TAKRG_Store::all( $per_page, ( $paged - 1 ) * $per_page );
    379                 $statuses = TAKRG_Settings::selectable_statuses();
    380                 $post_url = admin_url( 'admin-post.php' );
    381                 $actions  = array(
     486                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display only: a page number.
     487                $scan_page = isset( $_GET['takrg_pg'] ) ? max( 1, absint( $_GET['takrg_pg'] ) ) : 1;
     488                $total     = TAKRG_Store::total();
     489                $rows      = TAKRG_Store::all( $per_page, ( $paged - 1 ) * $per_page );
     490                $statuses  = TAKRG_Settings::selectable_statuses();
     491                $post_url  = admin_url( 'admin-post.php' );
     492                $actions   = array(
    382493                        'tag'    => array( __( 'Tag only (default)', 'takeed-refusal-guard' ), __( 'Adds an order note and the meta "_takrg_risk". Nothing is blocked.', 'takeed-refusal-guard' ) ),
    383494                        'hide'   => array( __( 'Hide Cash on Delivery', 'takeed-refusal-guard' ), __( 'Cash on Delivery is not offered to this customer; other payment methods stay available.', 'takeed-refusal-guard' ) ),
    … …  
    391502                        <?php endif; ?>
    392503
     504                        <?php if ( TAKRG_Breaker::is_tripped() ) : ?>
     505                                <div class="notice notice-warning inline">
     506                                        <p><strong><?php esc_html_e( 'The safety breaker switched the plugin to "tag only".', 'takeed-refusal-guard' ); ?></strong>
     507                                                <?php esc_html_e( 'More than half of the checkout attempts in an hour were restricted. Check the activity log below, then turn the protection back on.', 'takeed-refusal-guard' ); ?></p>
     508                                        <form method="post" action="<?php echo esc_url( $post_url ); ?>">
     509                                                <input type="hidden" name="action" value="takrg_breaker_reset" />
     510                                                <?php wp_nonce_field( 'takrg_breaker_reset' ); ?>
     511                                                <p><button type="submit" class="button"><?php esc_html_e( 'Turn protection back on', 'takeed-refusal-guard' ); ?></button></p>
     512                                        </form>
     513                                </div>
     514                        <?php endif; ?>
     515                        <?php if ( 'live' !== $s['mode'] ) : ?>
     516                                <div class="notice notice-info inline"><p><strong><?php esc_html_e( 'Test mode is on.', 'takeed-refusal-guard' ); ?></strong>
     517                                        <?php esc_html_e( 'Nothing is hidden or refused: orders are only tagged, and the activity log below shows what the plugin would have done. When the log looks right, switch to Live.', 'takeed-refusal-guard' ); ?></p></div>
     518                        <?php endif; ?>
     519
    393520                        <form method="post" action="options.php">
    394521                                <?php settings_fields( 'takrg_settings_group' ); ?>
    395522                                <table class="form-table" role="presentation">
     523                                        <tr>
     524                                                <th scope="row"><?php esc_html_e( 'Mode', 'takeed-refusal-guard' ); ?></th>
     525                                                <td>
     526                                                        <fieldset>
     527                                                                <label><input type="radio" name="takrg_settings[mode]" value="test" <?php checked( $s['mode'], 'test' ); ?> /> <strong><?php esc_html_e( 'Test mode (default)', 'takeed-refusal-guard' ); ?></strong></label>
     528                                                                <p class="description"><?php esc_html_e( 'Only tags orders and writes what it would have done to the activity log.', 'takeed-refusal-guard' ); ?></p>
     529                                                                <label><input type="radio" name="takrg_settings[mode]" value="live" <?php checked( $s['mode'], 'live' ); ?> /> <strong><?php esc_html_e( 'Live', 'takeed-refusal-guard' ); ?></strong></label>
     530                                                                <p class="description"><?php esc_html_e( 'Applies the action below. A safety breaker returns to "tag only" if more than 50% of the checkout attempts in an hour (at least 5) are restricted.', 'takeed-refusal-guard' ); ?></p>
     531                                                        </fieldset>
     532                                                </td>
     533                                        </tr>
    396534                                        <tr>
    397535                                                <th scope="row"><label for="takrg_threshold"><?php esc_html_e( 'Refusals before acting', 'takeed-refusal-guard' ); ?></label></th>
    … …  
    431569                                                </td>
    432570                                        </tr>
     571                                        <tr>
     572                                                <th scope="row"><label for="takrg_retention"><?php esc_html_e( 'Forget refusals after (months)', 'takeed-refusal-guard' ); ?></label></th>
     573                                                <td>
     574                                                        <input type="number" min="0" max="120" id="takrg_retention" name="takrg_settings[retention]" value="<?php echo esc_attr( (string) $s['retention'] ); ?>" class="small-text" />
     575                                                        <p class="description"><?php esc_html_e( '0 keeps them until you delete them. Older records and log entries are removed once a day.', 'takeed-refusal-guard' ); ?></p>
     576                                                </td>
     577                                        </tr>
    433578                                </table>
    434579                                <?php submit_button(); ?>
    … …  
    462607                                        <button type="submit" class="button"><?php esc_html_e( 'Remove all records of this number or e-mail', 'takeed-refusal-guard' ); ?></button>
    463608                                </p>
     609                        </form>
     610
     611                        <h2><?php esc_html_e( 'Allow-list and block-list', 'takeed-refusal-guard' ); ?></h2>
     612                        <p class="description"><?php esc_html_e( 'Allow: never act on this customer, whatever the refusals. Block: always treat this customer as having reached the threshold. Use an e-mail, a phone number, or a pattern with * such as *@example.com or +21620*.', 'takeed-refusal-guard' ); ?></p>
     613                        <form method="post" action="<?php echo esc_url( $post_url ); ?>">
     614                                <input type="hidden" name="action" value="takrg_rule_add" />
     615                                <?php wp_nonce_field( 'takrg_rule_add' ); ?>
     616                                <p>
     617                                        <select name="takrg_type" aria-label="<?php esc_attr_e( 'List', 'takeed-refusal-guard' ); ?>">
     618                                                <option value="allow"><?php esc_html_e( 'Allow', 'takeed-refusal-guard' ); ?></option>
     619                                                <option value="block"><?php esc_html_e( 'Block', 'takeed-refusal-guard' ); ?></option>
     620                                        </select>
     621                                        <input type="text" name="takrg_value" class="regular-text" dir="ltr" aria-label="<?php esc_attr_e( 'Value', 'takeed-refusal-guard' ); ?>" />
     622                                        <select name="takrg_country" aria-label="<?php esc_attr_e( 'Country', 'takeed-refusal-guard' ); ?>"><?php self::country_options( (string) $s['default_country'] ); ?></select>
     623                                        <button type="submit" class="button"><?php esc_html_e( 'Add rule', 'takeed-refusal-guard' ); ?></button>
     624                                </p>
     625                        </form>
     626                        <?php $rules = TAKRG_Rules::all( 100 ); ?>
     627                        <?php if ( $rules ) : ?>
     628                                <table class="widefat striped">
     629                                        <thead><tr>
     630                                                <th><?php esc_html_e( 'List', 'takeed-refusal-guard' ); ?></th>
     631                                                <th><?php esc_html_e( 'Value', 'takeed-refusal-guard' ); ?></th>
     632                                                <th><?php esc_html_e( 'Date (UTC)', 'takeed-refusal-guard' ); ?></th>
     633                                                <th></th>
     634                                        </tr></thead>
     635                                        <tbody>
     636                                        <?php foreach ( $rules as $r ) : ?>
     637                                                <tr>
     638                                                        <td><?php echo 'block' === $r['type'] ? esc_html__( 'Block', 'takeed-refusal-guard' ) : esc_html__( 'Allow', 'takeed-refusal-guard' ); ?></td>
     639                                                        <td dir="ltr"><?php echo esc_html( 'phone' === $r['kind'] ? '+' . $r['value'] : $r['value'] ); ?></td>
     640                                                        <td><?php echo esc_html( $r['created_at'] ); ?></td>
     641                                                        <td>
     642                                                                <form method="post" action="<?php echo esc_url( $post_url ); ?>">
     643                                                                        <input type="hidden" name="action" value="takrg_rule_delete" />
     644                                                                        <input type="hidden" name="takrg_id" value="<?php echo esc_attr( (string) $r['id'] ); ?>" />
     645                                                                        <?php wp_nonce_field( 'takrg_rule_delete' ); ?>
     646                                                                        <button type="submit" class="button-link button-link-delete"><?php esc_html_e( 'Delete', 'takeed-refusal-guard' ); ?></button>
     647                                                                </form>
     648                                                        </td>
     649                                                </tr>
     650                                        <?php endforeach; ?>
     651                                        </tbody>
     652                                </table>
     653                        <?php endif; ?>
     654
     655                        <h2><?php esc_html_e( 'Count refusals from existing orders', 'takeed-refusal-guard' ); ?></h2>
     656                        <form method="post" action="<?php echo esc_url( $post_url ); ?>">
     657                                <input type="hidden" name="action" value="takrg_scan" />
     658                                <input type="hidden" name="takrg_page" value="<?php echo esc_attr( (string) $scan_page ); ?>" />
     659                                <?php wp_nonce_field( 'takrg_scan' ); ?>
     660                                <p>
     661                                        <button type="submit" class="button"><?php echo $scan_page > 1 ? esc_html__( 'Continue scan', 'takeed-refusal-guard' ) : esc_html__( 'Scan existing orders', 'takeed-refusal-guard' ); ?></button>
     662                                </p>
     663                                <p class="description"><?php esc_html_e( 'Adds a record for every order that is already in a counted status. Orders that already have a record are skipped, so it is safe to repeat.', 'takeed-refusal-guard' ); ?></p>
    464664                        </form>
    465665
    … …  
    533733                        }
    534734                        ?>
     735
     736                        <h2><?php esc_html_e( 'Activity log', 'takeed-refusal-guard' ); ?></h2>
     737                        <p class="description"><?php esc_html_e( 'The last events. Customers are masked. In test mode, "Would apply" is what Live mode would have done.', 'takeed-refusal-guard' ); ?></p>
     738                        <table class="widefat striped">
     739                                <thead><tr>
     740                                        <th><?php esc_html_e( 'Date (UTC)', 'takeed-refusal-guard' ); ?></th>
     741                                        <th><?php esc_html_e( 'Event', 'takeed-refusal-guard' ); ?></th>
     742                                        <th><?php esc_html_e( 'Action', 'takeed-refusal-guard' ); ?></th>
     743                                        <th><?php esc_html_e( 'Customer', 'takeed-refusal-guard' ); ?></th>
     744                                        <th><?php esc_html_e( 'Refusals', 'takeed-refusal-guard' ); ?></th>
     745                                        <th><?php esc_html_e( 'Order', 'takeed-refusal-guard' ); ?></th>
     746                                        <th><?php esc_html_e( 'Details', 'takeed-refusal-guard' ); ?></th>
     747                                </tr></thead>
     748                                <tbody>
     749                                <?php $events = TAKRG_Log::all( 50 ); ?>
     750                                <?php if ( ! $events ) : ?>
     751                                        <tr><td colspan="7"><?php esc_html_e( 'Nothing yet.', 'takeed-refusal-guard' ); ?></td></tr>
     752                                <?php endif; ?>
     753                                <?php foreach ( $events as $e ) : ?>
     754                                        <tr>
     755                                                <td><?php echo esc_html( $e['created_at'] ); ?></td>
     756                                                <td><?php echo esc_html( self::event_label( $e['event'] ) ); ?></td>
     757                                                <td><?php echo esc_html( $e['action'] ); ?></td>
     758                                                <td dir="ltr"><?php echo esc_html( $e['who'] ); ?></td>
     759                                                <td><?php echo esc_html( (string) $e['refusals'] ); ?></td>
     760                                                <td><?php echo $e['order_id'] ? esc_html( '#' . $e['order_id'] ) : '&ndash;'; ?></td>
     761                                                <td><?php echo esc_html( $e['detail'] ); ?></td>
     762                                        </tr>
     763                                <?php endforeach; ?>
     764                                </tbody>
     765                        </table>
    535766                </div>
    536767                <?php
    537768        }
     769
     770        /**
     771         * Readable name of a log event.
     772         *
     773         * @param string $event Event key.
     774         * @return string
     775         */
     776        private static function event_label( $event ) {
     777                $labels = array(
     778                        'tagged'      => __( 'Order tagged', 'takeed-refusal-guard' ),
     779                        'would_apply' => __( 'Would apply (test mode)', 'takeed-refusal-guard' ),
     780                        'applied'     => __( 'Applied', 'takeed-refusal-guard' ),
     781                        'breaker'     => __( 'Safety breaker', 'takeed-refusal-guard' ),
     782                        'error'       => __( 'Error (order allowed)', 'takeed-refusal-guard' ),
     783                );
     784                return isset( $labels[ $event ] ) ? $labels[ $event ] : $event;
     785        }
    538786}
  • takeed-refusal-guard/tags/1.1.0/includes/class-takrg-checkout.php

    r3806545 r3807599  
    2929                add_action( 'woocommerce_after_checkout_validation', array( __CLASS__, 'validate_classic' ), 10, 2 );
    3030                add_action( 'woocommerce_store_api_checkout_update_order_from_request', array( __CLASS__, 'validate_store_api' ), 10, 2 );
     31                add_filter( 'rest_request_before_callbacks', array( __CLASS__, 'record_store_api_attempt' ), 10, 3 );
    3132                add_action( 'woocommerce_review_order_before_payment', array( __CLASS__, 'render_notice' ) );
    3233                add_action( 'wp_enqueue_scripts', array( __CLASS__, 'refresh_script' ), 20 );
    … …  
    4445
    4546        /**
    46          * Refusal count for raw (not yet normalised) checkout values, and the settings that apply.
     47         * Judges a customer given as typed at the checkout: refusal count, allow-list, block rules, threshold.
     48         *
     49         * @param string $phone   Phone as typed.
     50         * @param string $email   E-mail as typed.
     51         * @param string $country Billing country.
     52         * @return array count, risky, allowed, key (opaque customer key), who (masked).
     53         */
     54        public static function assess( $phone, $email, $country = '' ) {
     55                $np  = TAKRG_Phone::normalize( $phone, TAKRG_Recorder::country_for( $country ) );
     56                $ne  = TAKRG_Phone::normalize_email( $email );
     57                $key = $np . '|' . $ne;
     58                if ( isset( self::$counts[ $key ] ) ) {
     59                        return self::$counts[ $key ];
     60                }
     61                $allowed = ( '' !== $np || '' !== $ne ) && TAKRG_Rules::matches( TAKRG_Rules::ALLOW, $np, $ne );
     62                $count   = TAKRG_Store::count( $np, $ne );
     63                if ( ! $allowed && ( '' !== $np || '' !== $ne ) && TAKRG_Rules::matches( TAKRG_Rules::BLOCK, $np, $ne ) ) {
     64                        $count = max( $count, (int) TAKRG_Settings::get( 'threshold' ) );
     65                }
     66                $risky                = ! $allowed && self::is_risky( $count, $phone, $email );
     67                self::$counts[ $key ] = array(
     68                        'count'   => $count,
     69                        'risky'   => $risky,
     70                        'allowed' => $allowed,
     71                        'key'     => substr( hash( 'sha256', $key . wp_salt( 'auth' ) ), 0, 12 ),
     72                        'who'     => TAKRG_Log::mask( $np, $ne ),
     73                );
     74                return self::$counts[ $key ];
     75        }
     76
     77        /**
     78         * Refusal count for raw (not yet normalised) checkout values.
    4779         *
    4880         * @param string $phone   Phone as typed.
    … …  
    5284         */
    5385        public static function count_for( $phone, $email, $country = '' ) {
    54                 $phone = TAKRG_Phone::normalize( $phone, TAKRG_Recorder::country_for( $country ) );
    55                 $email = TAKRG_Phone::normalize_email( $email );
    56                 $key   = $phone . '|' . $email;
    57                 if ( ! isset( self::$counts[ $key ] ) ) {
    58                         self::$counts[ $key ] = TAKRG_Store::count( $phone, $email );
    59                 }
    60                 return self::$counts[ $key ];
     86                return self::assess( $phone, $email, $country )['count'];
    6187        }
    6288
    … …  
    7298                $risky = $count >= (int) TAKRG_Settings::get( 'threshold' ) && $count > 0;
    7399                return (bool) apply_filters( 'takrg_is_risky', $risky, $count, $phone, $email );
     100        }
     101
     102        /**
     103         * Runs a check. Any exception means "allow": a failure of this plugin must never stop a sale.
     104         *
     105         * @param callable $check    The check.
     106         * @param mixed    $fallback What to return when the check fails.
     107         * @return mixed
     108         */
     109        private static function guard( $check, $fallback ) {
     110                try {
     111                        return $check();
     112                } catch ( \Throwable $e ) {
     113                        TAKRG_Log::add(
     114                                'error',
     115                                array(
     116                                        'detail' => get_class( $e ) . ': ' . $e->getMessage(),
     117                                )
     118                        );
     119                        return $fallback;
     120                }
    74121        }
    75122
    … …  
    126173        private static function request_risk() {
    127174                list( $phone, $email, $country ) = self::request_identity();
    128                 $count                           = self::count_for( $phone, $email, $country );
    129                 return array( self::is_risky( $count, $phone, $email ), $count );
     175                $a                               = self::assess( $phone, $email, $country );
     176                return array( $a['risky'], $a['count'] );
    130177        }
    131178
    … …  
    138185         */
    139186        public static function filter_gateways( $gateways ) {
    140                 if ( ! is_array( $gateways ) || ! isset( $gateways[ self::COD ] ) || 'hide' !== TAKRG_Settings::get( 'action' ) ) {
     187                if ( ! is_array( $gateways ) || ! isset( $gateways[ self::COD ] ) ) {
    141188                        return $gateways;
    142189                }
    143                 if ( is_admin() && ! wp_doing_ajax() ) {
    144                         return $gateways;
    145                 }
    146                 list( $risky ) = self::request_risk();
    147                 if ( $risky ) {
    148                         unset( $gateways[ self::COD ] );
    149                 }
    150                 return $gateways;
     190                return self::guard(
     191                        function () use ( $gateways ) {
     192                                if ( 'hide' !== TAKRG_Settings::effective_action() || ( is_admin() && ! wp_doing_ajax() ) ) {
     193                                        return $gateways;
     194                                }
     195                                list( $risky ) = self::request_risk();
     196                                if ( $risky ) {
     197                                        unset( $gateways[ self::COD ] );
     198                                }
     199                                return $gateways;
     200                        },
     201                        $gateways
     202                );
    151203        }
    152204
    … …  
    161213
    162214        /**
    163          * Whether this shop's action restricts cash on delivery.
    164          *
    165          * @return bool
    166          */
    167         private static function restricts() {
    168                 return in_array( TAKRG_Settings::get( 'action' ), array( 'hide', 'notice' ), true );
     215         * Decides one checkout attempt: should cash on delivery be refused for this customer? Also feeds the safety
     216         * breaker and the activity log. Never throws.
     217         *
     218         * @param string $phone   Phone as typed.
     219         * @param string $email   E-mail as typed.
     220         * @param string $country Billing country.
     221         * @param string $method  Chosen payment method.
     222         * @param bool   $record  Whether this attempt still has to be counted by the safety breaker.
     223         * @return bool True when the plugin must refuse cash on delivery.
     224         */
     225        private static function refuse_cod( $phone, $email, $country, $method, $record = true ) {
     226                return (bool) self::guard(
     227                        function () use ( $phone, $email, $country, $method, $record ) {
     228                                $intended = (string) TAKRG_Settings::get( 'action' );
     229                                $live     = 'live' === TAKRG_Settings::get( 'mode' ) && ! TAKRG_Breaker::is_tripped();
     230                                $a        = self::assess( $phone, $email, $country );
     231                                $acts     = $a['risky'] && in_array( $intended, array( 'hide', 'notice' ), true );
     232                                if ( $record && 'live' === TAKRG_Settings::get( 'mode' ) ) {
     233                                        TAKRG_Breaker::record( $a['key'], $acts );
     234                                }
     235                                if ( ! $acts ) {
     236                                        return false;
     237                                }
     238                                if ( self::COD !== $method ) {
     239                                        return false;
     240                                }
     241                                TAKRG_Log::add(
     242                                        $live ? 'applied' : 'would_apply',
     243                                        array(
     244                                                'action'   => $intended,
     245                                                'who'      => $a['who'],
     246                                                'refusals' => $a['count'],
     247                                        )
     248                                );
     249                                return $live;
     250                        },
     251                        false
     252                );
    169253        }
    170254
    … …  
    176260         */
    177261        public static function validate_classic( $data, $errors ) {
    178                 if ( ! self::restricts() || ! is_array( $data ) || ! isset( $data['payment_method'] ) || self::COD !== $data['payment_method'] ) {
     262                if ( ! is_array( $data ) ) {
    179263                        return;
    180264                }
    181                 $phone   = isset( $data['billing_phone'] ) ? (string) $data['billing_phone'] : '';
    182                 $email   = isset( $data['billing_email'] ) ? (string) $data['billing_email'] : '';
    183                 $country = isset( $data['billing_country'] ) ? (string) $data['billing_country'] : '';
    184                 $count   = self::count_for( $phone, $email, $country );
    185                 if ( self::is_risky( $count, $phone, $email ) ) {
     265                $method = isset( $data['payment_method'] ) ? (string) $data['payment_method'] : '';
     266                if ( self::refuse_cod( isset( $data['billing_phone'] ) ? (string) $data['billing_phone'] : '', isset( $data['billing_email'] ) ? (string) $data['billing_email'] : '', isset( $data['billing_country'] ) ? (string) $data['billing_country'] : '', $method ) ) {
    186267                        $errors->add( 'takrg_cod_unavailable', self::message() );
    187268                }
     269        }
     270
     271        /**
     272         * Block checkout: counts the attempt for the safety breaker as soon as the Store API receives it, before
     273         * WooCommerce itself may refuse the payment method (action "hide").
     274         *
     275         * @param mixed           $response Response so far.
     276         * @param array           $handler  Route handler.
     277         * @param WP_REST_Request $request  Request.
     278         * @return mixed The response, unchanged.
     279         */
     280        public static function record_store_api_attempt( $response, $handler, $request ) {
     281                unset( $handler );
     282                if ( $request instanceof WP_REST_Request && 'POST' === $request->get_method() && 1 === preg_match( '#^/wc/store/v\d+/checkout$#', $request->get_route() ) ) {
     283                        self::guard(
     284                                function () use ( $request ) {
     285                                        $b = $request->get_param( 'billing_address' );
     286                                        $b = is_array( $b ) ? $b : array();
     287                                        $a = self::assess( isset( $b['phone'] ) ? (string) $b['phone'] : '', isset( $b['email'] ) ? (string) $b['email'] : '', isset( $b['country'] ) ? (string) $b['country'] : '' );
     288                                        if ( 'live' === TAKRG_Settings::get( 'mode' ) ) {
     289                                                TAKRG_Breaker::record( $a['key'], $a['risky'] && in_array( TAKRG_Settings::get( 'action' ), array( 'hide', 'notice' ), true ) );
     290                                        }
     291                                },
     292                                null
     293                        );
     294                }
     295                return $response;
    188296        }
    189297
    … …  
    196304         */
    197305        public static function validate_store_api( $order, $request ) {
    198                 if ( ! self::restricts() || self::COD !== (string) $request['payment_method'] ) {
    199                         return;
    200                 }
    201                 $phone   = (string) $order->get_billing_phone();
    202                 $email   = (string) $order->get_billing_email();
    203                 $country = (string) $order->get_billing_country();
    204                 $count   = self::count_for( $phone, $email, $country );
    205                 if ( self::is_risky( $count, $phone, $email ) && class_exists( '\Automattic\WooCommerce\StoreApi\Exceptions\RouteException' ) ) {
     306                $refuse = self::guard(
     307                        function () use ( $order, $request ) {
     308                                return self::refuse_cod( (string) $order->get_billing_phone(), (string) $order->get_billing_email(), (string) $order->get_billing_country(), (string) $request['payment_method'], false );
     309                        },
     310                        false
     311                );
     312                if ( $refuse && class_exists( '\Automattic\WooCommerce\StoreApi\Exceptions\RouteException' ) ) {
    206313                        throw new \Automattic\WooCommerce\StoreApi\Exceptions\RouteException( 'takrg_cod_unavailable', esc_html( self::message() ), 400 );
    207314                }
    … …  
    214321         */
    215322        public static function refresh_script() {
    216                 if ( 'tag' === TAKRG_Settings::get( 'action' ) || ! function_exists( 'is_checkout' ) || ! is_checkout() ) {
     323                if ( 'tag' === TAKRG_Settings::effective_action() || ! function_exists( 'is_checkout' ) || ! is_checkout() ) {
    217324                        return;
    218325                }
    … …  
    227334        private static function notice_html() {
    228335                $inner = '';
    229                 if ( 'notice' === TAKRG_Settings::get( 'action' ) ) {
     336                if ( 'notice' === TAKRG_Settings::effective_action() ) {
    230337                        list( $risky ) = self::request_risk();
    231338                        if ( $risky ) {
    … …  
    241348         */
    242349        public static function render_notice() {
    243                 if ( 'notice' === TAKRG_Settings::get( 'action' ) ) {
    244                         echo wp_kses_post( self::notice_html() );
     350                if ( 'notice' === TAKRG_Settings::effective_action() ) {
     351                        echo wp_kses_post( self::guard( array( __CLASS__, 'notice_html' ), '' ) );
    245352                }
    246353        }
    … …  
    253360         */
    254361        public static function notice_fragment( $fragments ) {
    255                 if ( 'notice' === TAKRG_Settings::get( 'action' ) && is_array( $fragments ) ) {
    256                         $fragments['.takrg-notice-slot'] = wp_kses_post( self::notice_html() );
     362                if ( 'notice' === TAKRG_Settings::effective_action() && is_array( $fragments ) ) {
     363                        $html = self::guard( array( __CLASS__, 'notice_html' ), '' );
     364                        if ( '' !== $html ) {
     365                                $fragments['.takrg-notice-slot'] = wp_kses_post( $html );
     366                        }
    257367                }
    258368                return $fragments;
    … …  
    277387         */
    278388        public static function tag_order( $order ) {
    279                 if ( ! $order || $order->get_meta( '_takrg_risk' ) ) {
    280                         return;
    281                 }
    282                 list( $phone, $email ) = TAKRG_Recorder::identity( $order );
    283                 $count                 = TAKRG_Store::count( $phone, $email );
    284                 if ( ! self::is_risky( $count, $phone, $email ) ) {
    285                         return;
    286                 }
    287                 $order->update_meta_data( '_takrg_risk', $count );
    288                 /* translators: %d: number of refused cash-on-delivery orders. */
    289                 $order->add_order_note( sprintf( _n( 'COD risk: this customer (phone or e-mail) refused %d earlier order.', 'COD risk: this customer (phone or e-mail) refused %d earlier orders.', $count, 'takeed-refusal-guard' ), $count ) );
    290                 $order->save();
    291                 do_action( 'takrg_order_tagged', $order, $count );
     389                self::guard(
     390                        function () use ( $order ) {
     391                                if ( ! $order || $order->get_meta( '_takrg_risk' ) ) {
     392                                        return;
     393                                }
     394                                $a = self::assess( $order->get_billing_phone(), $order->get_billing_email(), $order->get_billing_country() );
     395                                if ( ! $a['risky'] ) {
     396                                        return;
     397                                }
     398                                $count = $a['count'];
     399                                $order->update_meta_data( '_takrg_risk', $count );
     400                                /* translators: %d: number of refused cash-on-delivery orders. */
     401                                $order->add_order_note( sprintf( _n( 'COD risk: this customer (phone or e-mail) refused %d earlier order.', 'COD risk: this customer (phone or e-mail) refused %d earlier orders.', $count, 'takeed-refusal-guard' ), $count ) );
     402                                $order->save();
     403                                TAKRG_Log::add(
     404                                        'tagged',
     405                                        array(
     406                                                'action'   => 'tag',
     407                                                'who'      => $a['who'],
     408                                                'refusals' => $count,
     409                                                'order_id' => $order->get_id(),
     410                                        )
     411                                );
     412                                do_action( 'takrg_order_tagged', $order, $count );
     413                        },
     414                        null
     415                );
    292416        }
    293417}
  • takeed-refusal-guard/tags/1.1.0/includes/class-takrg-plugin.php

    r3806545 r3807599  
    1313final class TAKRG_Plugin {
    1414
     15        const CRON = 'takrg_daily_cleanup';
     16
    1517        /**
    16          * Activation: create the table.
     18         * Activation: create the tables and schedule the daily cleanup.
    1719         */
    1820        public static function activate() {
    1921                TAKRG_Store::install();
     22                self::schedule();
     23        }
     24
     25        /**
     26         * Deactivation: stop the daily cleanup.
     27         */
     28        public static function deactivate() {
     29                wp_clear_scheduled_hook( self::CRON );
     30        }
     31
     32        /**
     33         * Schedules the daily cleanup (retention) once.
     34         */
     35        public static function schedule() {
     36                if ( ! wp_next_scheduled( self::CRON ) ) {
     37                        wp_schedule_event( time() + HOUR_IN_SECONDS, 'daily', self::CRON );
     38                }
     39        }
     40
     41        /**
     42         * Daily cleanup: records older than the retention the administrator chose.
     43         */
     44        public static function cleanup() {
     45                TAKRG_Store::purge_older_than( (int) TAKRG_Settings::get( 'retention' ) );
     46        }
     47
     48        /**
     49         * Update from an older version. Shops that already use 1.0.x keep the behaviour they chose (live); only a
     50         * fresh installation starts in test mode.
     51         */
     52        public static function upgrade() {
     53                $from = (string) get_option( TAKRG_Store::DB_VERSION_OPTION, '' );
     54                TAKRG_Store::install();
     55                if ( '' !== $from && version_compare( $from, '2', '<' ) ) {
     56                        $saved = get_option( TAKRG_Settings::OPTION, null );
     57                        if ( is_array( $saved ) && ! isset( $saved['mode'] ) ) {
     58                                $saved['mode'] = 'live';
     59                                update_option( TAKRG_Settings::OPTION, $saved );
     60                        }
     61                }
    2062        }
    2163
    … …  
    2870                }
    2971                if ( get_option( TAKRG_Store::DB_VERSION_OPTION ) !== TAKRG_Store::DB_VERSION ) {
    30                         TAKRG_Store::install();
     72                        self::upgrade();
    3173                }
     74                self::schedule();
     75                add_action( self::CRON, array( __CLASS__, 'cleanup' ) );
    3276                TAKRG_Recorder::init();
    3377                TAKRG_Checkout::init();
  • takeed-refusal-guard/tags/1.1.0/includes/class-takrg-privacy.php

    r3806545 r3807599  
    109109                        );
    110110                }
     111                if ( 1 === $page && $email ) { // The person's own allow-list / block-list entries.
     112                        foreach ( TAKRG_Rules::for_person( $email, self::phones_of( $email ) ) as $rule ) {
     113                                $export[] = array(
     114                                        'group_id'          => 'takrg-rules',
     115                                        'group_label'       => __( 'COD allow-list and block-list entries', 'takeed-refusal-guard' ),
     116                                        'group_description' => __( 'Entries added by the shop administrator.', 'takeed-refusal-guard' ),
     117                                        'item_id'           => 'takrg-rule-' . $rule['id'],
     118                                        'data'              => array(
     119                                                array(
     120                                                        'name'  => __( 'List', 'takeed-refusal-guard' ),
     121                                                        'value' => $rule['type'],
     122                                                ),
     123                                                array(
     124                                                        'name'  => __( 'Value', 'takeed-refusal-guard' ),
     125                                                        'value' => $rule['value'],
     126                                                ),
     127                                                array(
     128                                                        'name'  => __( 'Date (UTC)', 'takeed-refusal-guard' ),
     129                                                        'value' => $rule['created_at'],
     130                                                ),
     131                                        ),
     132                                );
     133                        }
     134                }
    111135                return array(
    112136                        'data' => $export,
    … …  
    132156                        }
    133157                        $removed += TAKRG_Store::delete_by_identity( '', $email );
     158                        $removed += TAKRG_Rules::delete_exact( $email, $phones );
    134159                        TAKRG_Checkout::reset_cache();
    135160                }
    … …  
    152177                        'Takeed Refusal Guard for WooCommerce',
    153178                        wp_kses_post(
    154                                 '<p class="privacy-policy-tutorial">' . __( 'Takeed Refusal Guard stores, in your own database, the phone number (digits only), the e-mail address, the order number and the date of each order that was refused at delivery. Nothing is sent to the plugin author or to any third party.', 'takeed-refusal-guard' ) . '</p>' .
     179                                '<p class="privacy-policy-tutorial">' . __( 'Takeed Refusal Guard stores, in your own database, the phone number (digits only), the e-mail address, the order number and the date of each order that was refused at delivery, the entries you add to its allow-list and block-list, and an activity log in which customers appear masked. Nothing is sent to the plugin author or to any third party.', 'takeed-refusal-guard' ) . '</p>' .
    155180                                '<p><strong class="privacy-policy-tutorial">' . __( 'Suggested text:', 'takeed-refusal-guard' ) . '</strong> ' . __( 'If you refuse a cash-on-delivery parcel, we keep your phone number and e-mail address together with the order number so that we can offer other payment methods for your next orders. You can ask us to erase this record.', 'takeed-refusal-guard' ) . '</p>'
    156181                        )
  • takeed-refusal-guard/tags/1.1.0/includes/class-takrg-recorder.php

    r3806545 r3807599  
    2727                add_filter( 'handle_bulk_actions-woocommerce_page_wc-orders', array( __CLASS__, 'handle_bulk' ), 10, 3 );
    2828                add_action( 'takrg_signal', array( __CLASS__, 'on_signal' ), 10, 4 );
     29                add_filter( 'woocommerce_order_actions', array( __CLASS__, 'order_actions' ) );
     30                add_action( 'woocommerce_order_action_takrg_mark_refused', array( __CLASS__, 'action_mark_refused' ) );
     31                add_action( 'woocommerce_order_action_takrg_clear_refusal', array( __CLASS__, 'action_clear_refusal' ) );
    2932        }
    3033
    … …  
    9194
    9295        /**
     96         * Entries of the "Order actions" box on the order screen (legacy and HPOS).
     97         *
     98         * @param array $actions Order actions.
     99         * @return array
     100         */
     101        public static function order_actions( $actions ) {
     102                $actions['takrg_mark_refused']  = __( 'Mark as refused at delivery', 'takeed-refusal-guard' );
     103                $actions['takrg_clear_refusal'] = __( 'Clear the refusal record of this order', 'takeed-refusal-guard' );
     104                return $actions;
     105        }
     106
     107        /**
     108         * Order action: set the refused status.
     109         *
     110         * @param WC_Order $order Order.
     111         */
     112        public static function action_mark_refused( $order ) {
     113                if ( $order && current_user_can( TAKRG_Admin::CAP ) ) {
     114                        $order->update_status( self::STATUS, __( 'Marked as refused at delivery.', 'takeed-refusal-guard' ) );
     115                }
     116        }
     117
     118        /**
     119         * Order action: forget this order's refusal (it was a mistake).
     120         *
     121         * @param WC_Order $order Order.
     122         */
     123        public static function action_clear_refusal( $order ) {
     124                if ( $order && current_user_can( TAKRG_Admin::CAP ) ) {
     125                        TAKRG_Store::remove_for_order( $order->get_id() );
     126                        TAKRG_Checkout::reset_cache();
     127                        $order->add_order_note( __( 'Refusal record cleared.', 'takeed-refusal-guard' ) );
     128                }
     129        }
     130
     131        /**
    93132         * Country used to read a number typed without a country code: the order's own billing country when we
    94133         * support it, else the configured default.
  • takeed-refusal-guard/tags/1.1.0/includes/class-takrg-settings.php

    r3806545 r3807599  
    2323        public static function defaults() {
    2424                return array(
     25                        'mode'            => 'test',
    2526                        'threshold'       => 1,
    2627                        'action'          => 'tag',
    2728                        'statuses'        => array( 'takeed-refused' ),
    2829                        'default_country' => self::guess_country(),
     30                        'retention'       => 0,
    2931                );
     32        }
     33
     34        /**
     35         * The action that is really applied now. Test mode and a tripped safety breaker both mean "tag only".
     36         *
     37         * @return string tag | hide | notice.
     38         */
     39        public static function effective_action() {
     40                if ( 'live' !== self::get( 'mode' ) || TAKRG_Breaker::is_tripped() ) {
     41                        return 'tag';
     42                }
     43                $action = self::get( 'action' );
     44                return in_array( $action, self::ACTIONS, true ) ? $action : 'tag';
    3045        }
    3146
    … …  
    93108                $out      = $defaults;
    94109
     110                $mode        = isset( $input['mode'] ) ? sanitize_key( $input['mode'] ) : '';
     111                $out['mode'] = in_array( $mode, array( 'test', 'live' ), true ) ? $mode : 'test';
     112
     113                $out['retention'] = isset( $input['retention'] ) ? min( 120, absint( $input['retention'] ) ) : 0;
     114
    95115                $out['threshold'] = isset( $input['threshold'] ) ? max( 1, min( 100, absint( $input['threshold'] ) ) ) : $defaults['threshold'];
    96116
  • takeed-refusal-guard/tags/1.1.0/includes/class-takrg-store.php

    r3806545 r3807599  
    1515
    1616        const DB_VERSION_OPTION = 'takrg_db_version';
    17         const DB_VERSION        = '1';
     17        const DB_VERSION        = '2';
    1818
    1919        /**
    … …  
    4949) {$charset};"
    5050                );
     51                TAKRG_Rules::install();
     52                TAKRG_Log::install();
    5153                update_option( self::DB_VERSION_OPTION, self::DB_VERSION );
     54        }
     55
     56        /**
     57         * Deletes records older than a number of months (retention). 0 keeps everything.
     58         *
     59         * @param int $months Months to keep.
     60         */
     61        public static function purge_older_than( $months ) {
     62                global $wpdb;
     63                $months = absint( $months );
     64                if ( $months < 1 ) {
     65                        return;
     66                }
     67                $before = gmdate( 'Y-m-d H:i:s', time() - $months * 30 * DAY_IN_SECONDS );
     68                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Our own table.
     69                $wpdb->query( $wpdb->prepare( 'DELETE FROM %i WHERE created_at < %s', self::table(), $before ) );
     70                TAKRG_Log::purge_before( $before );
    5271        }
    5372
  • takeed-refusal-guard/tags/1.1.0/languages/takeed-refusal-guard.pot

    r3806545 r3807599  
    1010"X-Domain: takeed-refusal-guard\n"
    1111
    12 #: includes/class-takrg-admin.php:52 includes/class-takrg-admin.php:388
     12#: includes/class-takrg-admin.php:57 includes/class-takrg-admin.php:499
    1313msgid "Refusal Guard"
    1414msgstr ""
    1515
    16 #: includes/class-takrg-admin.php:81 includes/class-takrg-admin.php:85
     16#: includes/class-takrg-admin.php:86 includes/class-takrg-admin.php:90
    1717msgid "COD risk"
    1818msgstr ""
    1919
    20 #: includes/class-takrg-admin.php:128
     20#: includes/class-takrg-admin.php:133
    2121msgid "No refusals"
    2222msgstr ""
    2323
    24 #: includes/class-takrg-admin.php:139 includes/class-takrg-admin.php:369
     24#: includes/class-takrg-admin.php:144 includes/class-takrg-admin.php:478
    2525msgid "You are not allowed to do this."
    2626msgstr ""
    2727
    28 #: includes/class-takrg-admin.php:326
     28#: includes/class-takrg-admin.php:407
     29msgid "Takeed Refusal Guard switched itself to \"tag only\"."
     30msgstr ""
     31
     32#: includes/class-takrg-admin.php:408
     33msgid "More than half of the recent checkout attempts were restricted, so the plugin stopped restricting Cash on Delivery to protect your sales."
     34msgstr ""
     35
     36#: includes/class-takrg-admin.php:409
     37msgid "Review and turn it back on"
     38msgstr ""
     39
     40#: includes/class-takrg-admin.php:423
    2941msgid "%d record added."
    3042msgid_plural "%d records added."
    … …  
    3244msgstr[1] ""
    3345
    34 #: includes/class-takrg-admin.php:329
     46#: includes/class-takrg-admin.php:426
    3547msgid "%d record removed."
    3648msgid_plural "%d records removed."
    … …  
    3850msgstr[1] ""
    3951
    40 #: includes/class-takrg-admin.php:332
     52#: includes/class-takrg-admin.php:429
    4153msgid "%d record imported."
    4254msgid_plural "%d records imported."
    … …  
    4456msgstr[1] ""
    4557
    46 #: includes/class-takrg-admin.php:334
     58#: includes/class-takrg-admin.php:431
     59msgid "Rule added."
     60msgstr ""
     61
     62#: includes/class-takrg-admin.php:433
     63msgid "Enter an e-mail address, a phone number, or a pattern such as *@example.com or +21620* (not already in the list)."
     64msgstr ""
     65
     66#: includes/class-takrg-admin.php:435
     67msgid "Protection turned back on."
     68msgstr ""
     69
     70#: includes/class-takrg-admin.php:438
     71msgid "Scan finished: %d record added."
     72msgid_plural "Scan finished: %d records added."
     73msgstr[0] ""
     74msgstr[1] ""
     75
     76#: includes/class-takrg-admin.php:441
     77msgid "%d record added. More orders remain: press \"Continue scan\"."
     78msgid_plural "%d records added. More orders remain: press \"Continue scan\"."
     79msgstr[0] ""
     80msgstr[1] ""
     81
     82#: includes/class-takrg-admin.php:443
    4783msgid "Enter a valid phone number or e-mail address."
    4884msgstr ""
    4985
    50 #: includes/class-takrg-admin.php:336
     86#: includes/class-takrg-admin.php:445
    5187msgid "Choose a .csv file of 1 MB or less."
    5288msgstr ""
    5389
    54 #: includes/class-takrg-admin.php:348
     90#: includes/class-takrg-admin.php:457
    5591msgid "Tunisia (+216)"
    5692msgstr ""
    5793
    58 #: includes/class-takrg-admin.php:349
     94#: includes/class-takrg-admin.php:458
    5995msgid "Morocco (+212)"
    6096msgstr ""
    6197
    62 #: includes/class-takrg-admin.php:350
     98#: includes/class-takrg-admin.php:459
    6399msgid "Algeria (+213)"
    64100msgstr ""
    65101
    66 #: includes/class-takrg-admin.php:351
     102#: includes/class-takrg-admin.php:460
    67103msgid "Egypt (+20)"
    68104msgstr ""
    69105
    70 #: includes/class-takrg-admin.php:352
     106#: includes/class-takrg-admin.php:461
    71107msgid "Saudi Arabia (+966)"
    72108msgstr ""
    73109
    74 #: includes/class-takrg-admin.php:353
     110#: includes/class-takrg-admin.php:462
    75111msgid "United Arab Emirates (+971)"
    76112msgstr ""
    77113
    78 #: includes/class-takrg-admin.php:354
     114#: includes/class-takrg-admin.php:463
    79115msgid "Kuwait (+965)"
    80116msgstr ""
    81117
    82 #: includes/class-takrg-admin.php:355
     118#: includes/class-takrg-admin.php:464
    83119msgid "Qatar (+974)"
    84120msgstr ""
    85121
    86 #: includes/class-takrg-admin.php:356
     122#: includes/class-takrg-admin.php:465
    87123msgid "Oman (+968)"
    88124msgstr ""
    89125
    90 #: includes/class-takrg-admin.php:357
     126#: includes/class-takrg-admin.php:466
    91127msgid "Bahrain (+973)"
    92128msgstr ""
    93129
    94 #: includes/class-takrg-admin.php:382
     130#: includes/class-takrg-admin.php:493
    95131msgid "Tag only (default)"
    96132msgstr ""
    97133
    98 #: includes/class-takrg-admin.php:382
     134#: includes/class-takrg-admin.php:493
    99135msgid "Adds an order note and the meta \"_takrg_risk\". Nothing is blocked."
    100136msgstr ""
    101137
    102 #: includes/class-takrg-admin.php:383
     138#: includes/class-takrg-admin.php:494
    103139msgid "Hide Cash on Delivery"
    104140msgstr ""
    105141
    106 #: includes/class-takrg-admin.php:383
     142#: includes/class-takrg-admin.php:494
    107143msgid "Cash on Delivery is not offered to this customer; other payment methods stay available."
    108144msgstr ""
    109145
    110 #: includes/class-takrg-admin.php:384
     146#: includes/class-takrg-admin.php:495
    111147msgid "Show a notice"
    112148msgstr ""
    113149
    114 #: includes/class-takrg-admin.php:384
     150#: includes/class-takrg-admin.php:495
    115151msgid "Shows a neutral message asking the customer to choose another payment method, and refuses Cash on Delivery on submit."
    116152msgstr ""
    117153
    118 #: includes/class-takrg-admin.php:397
     154#: includes/class-takrg-admin.php:506
     155msgid "The safety breaker switched the plugin to \"tag only\"."
     156msgstr ""
     157
     158#: includes/class-takrg-admin.php:507
     159msgid "More than half of the checkout attempts in an hour were restricted. Check the activity log below, then turn the protection back on."
     160msgstr ""
     161
     162#: includes/class-takrg-admin.php:511
     163msgid "Turn protection back on"
     164msgstr ""
     165
     166#: includes/class-takrg-admin.php:516
     167msgid "Test mode is on."
     168msgstr ""
     169
     170#: includes/class-takrg-admin.php:517
     171msgid "Nothing is hidden or refused: orders are only tagged, and the activity log below shows what the plugin would have done. When the log looks right, switch to Live."
     172msgstr ""
     173
     174#: includes/class-takrg-admin.php:524
     175msgid "Mode"
     176msgstr ""
     177
     178#: includes/class-takrg-admin.php:527
     179msgid "Test mode (default)"
     180msgstr ""
     181
     182#: includes/class-takrg-admin.php:528
     183msgid "Only tags orders and writes what it would have done to the activity log."
     184msgstr ""
     185
     186#: includes/class-takrg-admin.php:529
     187msgid "Live"
     188msgstr ""
     189
     190#: includes/class-takrg-admin.php:530
     191msgid "Applies the action below. A safety breaker returns to \"tag only\" if more than 50% of the checkout attempts in an hour (at least 5) are restricted."
     192msgstr ""
     193
     194#: includes/class-takrg-admin.php:535
    119195msgid "Refusals before acting"
    120196msgstr ""
    121197
    122 #: includes/class-takrg-admin.php:400
     198#: includes/class-takrg-admin.php:538
    123199msgid "A customer (same phone number or same e-mail) with at least this many refusals is treated as a risk."
    124200msgstr ""
    125201
    126 #: includes/class-takrg-admin.php:404
     202#: includes/class-takrg-admin.php:542
    127203msgid "Action at checkout"
    128204msgstr ""
    129205
    130 #: includes/class-takrg-admin.php:415
     206#: includes/class-takrg-admin.php:553
    131207msgid "Statuses that count as a refusal"
    132208msgstr ""
    133209
    134 #: includes/class-takrg-admin.php:423
     210#: includes/class-takrg-admin.php:561
    135211msgid "Default: only \"Refused at delivery\". Be careful with statuses such as Cancelled: customers cancel for many reasons."
    136212msgstr ""
    137213
    138 #: includes/class-takrg-admin.php:427
     214#: includes/class-takrg-admin.php:565
    139215msgid "Default country"
    140216msgstr ""
    141217
    142 #: includes/class-takrg-admin.php:430
     218#: includes/class-takrg-admin.php:568
    143219msgid "Used to read phone numbers typed without a country code."
    144220msgstr ""
    145221
    146 #: includes/class-takrg-admin.php:438
     222#: includes/class-takrg-admin.php:572
     223msgid "Forget refusals after (months)"
     224msgstr ""
     225
     226#: includes/class-takrg-admin.php:575
     227msgid "0 keeps them until you delete them. Older records and log entries are removed once a day."
     228msgstr ""
     229
     230#: includes/class-takrg-admin.php:583
    147231msgid "Add or remove a number"
    148232msgstr ""
    149233
    150 #: includes/class-takrg-admin.php:443 includes/class-takrg-admin.php:457 includes/class-takrg-admin.php:490 includes/class-takrg-privacy.php:93
     234#: includes/class-takrg-admin.php:588 includes/class-takrg-admin.php:602 includes/class-takrg-admin.php:690 includes/class-takrg-privacy.php:93
    151235msgid "Phone"
    152236msgstr ""
    153237
    154 #: includes/class-takrg-admin.php:445 includes/class-takrg-admin.php:459
     238#: includes/class-takrg-admin.php:590 includes/class-takrg-admin.php:604 includes/class-takrg-admin.php:622
    155239msgid "Country"
    156240msgstr ""
    157241
    158 #: includes/class-takrg-admin.php:446 includes/class-takrg-admin.php:460 includes/class-takrg-admin.php:491 includes/class-takrg-privacy.php:97
     242#: includes/class-takrg-admin.php:591 includes/class-takrg-admin.php:605 includes/class-takrg-admin.php:691 includes/class-takrg-privacy.php:97
    159243msgid "E-mail"
    160244msgstr ""
    161245
    162 #: includes/class-takrg-admin.php:448
     246#: includes/class-takrg-admin.php:593 includes/class-takrg-admin.php:744
    163247msgid "Refusals"
    164248msgstr ""
    165249
    166 #: includes/class-takrg-admin.php:450
     250#: includes/class-takrg-admin.php:595
    167251msgid "Add"
    168252msgstr ""
    169253
    170 #: includes/class-takrg-admin.php:462
     254#: includes/class-takrg-admin.php:607
    171255msgid "Remove all records of this number or e-mail"
    172256msgstr ""
    173257
    174 #: includes/class-takrg-admin.php:466
     258#: includes/class-takrg-admin.php:611
     259msgid "Allow-list and block-list"
     260msgstr ""
     261
     262#: includes/class-takrg-admin.php:612
     263msgid "Allow: never act on this customer, whatever the refusals. Block: always treat this customer as having reached the threshold. Use an e-mail, a phone number, or a pattern with * such as *@example.com or +21620*."
     264msgstr ""
     265
     266#: includes/class-takrg-admin.php:617 includes/class-takrg-admin.php:630 includes/class-takrg-privacy.php:120
     267msgid "List"
     268msgstr ""
     269
     270#: includes/class-takrg-admin.php:618 includes/class-takrg-admin.php:638
     271msgid "Allow"
     272msgstr ""
     273
     274#: includes/class-takrg-admin.php:619 includes/class-takrg-admin.php:638
     275msgid "Block"
     276msgstr ""
     277
     278#: includes/class-takrg-admin.php:621 includes/class-takrg-admin.php:631 includes/class-takrg-privacy.php:124
     279msgid "Value"
     280msgstr ""
     281
     282#: includes/class-takrg-admin.php:623
     283msgid "Add rule"
     284msgstr ""
     285
     286#: includes/class-takrg-admin.php:632 includes/class-takrg-admin.php:694 includes/class-takrg-admin.php:740 includes/class-takrg-privacy.php:105 includes/class-takrg-privacy.php:128
     287msgid "Date (UTC)"
     288msgstr ""
     289
     290#: includes/class-takrg-admin.php:646 includes/class-takrg-admin.php:713
     291msgid "Delete"
     292msgstr ""
     293
     294#: includes/class-takrg-admin.php:655
     295msgid "Count refusals from existing orders"
     296msgstr ""
     297
     298#: includes/class-takrg-admin.php:661
     299msgid "Continue scan"
     300msgstr ""
     301
     302#: includes/class-takrg-admin.php:661
     303msgid "Scan existing orders"
     304msgstr ""
     305
     306#: includes/class-takrg-admin.php:663
     307msgid "Adds a record for every order that is already in a counted status. Orders that already have a record are skipped, so it is safe to repeat."
     308msgstr ""
     309
     310#: includes/class-takrg-admin.php:666
    175311msgid "Import and export"
    176312msgstr ""
    177313
    178 #: includes/class-takrg-admin.php:472
     314#: includes/class-takrg-admin.php:672
    179315msgid "Import CSV"
    180316msgstr ""
    181317
    182 #: includes/class-takrg-admin.php:474
     318#: includes/class-takrg-admin.php:674
    183319msgid "One row per refusal: phone,email (a header row is optional). Numbers without a country code use the default country."
    184320msgstr ""
    185321
    186 #: includes/class-takrg-admin.php:479
     322#: includes/class-takrg-admin.php:679
    187323msgid "Export CSV"
    188324msgstr ""
    189325
    190 #: includes/class-takrg-admin.php:485
     326#: includes/class-takrg-admin.php:685
    191327msgid "Stored refusals (%d)"
    192328msgstr ""
    193329
    194 #: includes/class-takrg-admin.php:492 includes/class-takrg-privacy.php:101
     330#: includes/class-takrg-admin.php:692 includes/class-takrg-admin.php:745 includes/class-takrg-privacy.php:101
    195331msgid "Order"
    196332msgstr ""
    197333
    198 #: includes/class-takrg-admin.php:493
     334#: includes/class-takrg-admin.php:693
    199335msgid "Source"
    200336msgstr ""
    201337
    202 #: includes/class-takrg-admin.php:494 includes/class-takrg-privacy.php:105
    203 msgid "Date (UTC)"
    204 msgstr ""
    205 
    206 #: includes/class-takrg-admin.php:499
     338#: includes/class-takrg-admin.php:699
    207339msgid "No refusals recorded yet."
    208340msgstr ""
    209341
    210 #: includes/class-takrg-admin.php:513
    211 msgid "Delete"
    212 msgstr ""
    213 
    214 #: includes/class-takrg-checkout.php:159
     342#: includes/class-takrg-admin.php:736
     343msgid "Activity log"
     344msgstr ""
     345
     346#: includes/class-takrg-admin.php:737
     347msgid "The last events. Customers are masked. In test mode, \"Would apply\" is what Live mode would have done."
     348msgstr ""
     349
     350#: includes/class-takrg-admin.php:741
     351msgid "Event"
     352msgstr ""
     353
     354#: includes/class-takrg-admin.php:742
     355msgid "Action"
     356msgstr ""
     357
     358#: includes/class-takrg-admin.php:743
     359msgid "Customer"
     360msgstr ""
     361
     362#: includes/class-takrg-admin.php:746
     363msgid "Details"
     364msgstr ""
     365
     366#: includes/class-takrg-admin.php:751
     367msgid "Nothing yet."
     368msgstr ""
     369
     370#: includes/class-takrg-admin.php:778
     371msgid "Order tagged"
     372msgstr ""
     373
     374#: includes/class-takrg-admin.php:779
     375msgid "Would apply (test mode)"
     376msgstr ""
     377
     378#: includes/class-takrg-admin.php:780
     379msgid "Applied"
     380msgstr ""
     381
     382#: includes/class-takrg-admin.php:781
     383msgid "Safety breaker"
     384msgstr ""
     385
     386#: includes/class-takrg-admin.php:782
     387msgid "Error (order allowed)"
     388msgstr ""
     389
     390#: includes/class-takrg-breaker.php:158
     391msgid "Takeed Refusal Guard switched itself to \"tag only\""
     392msgstr ""
     393
     394#: includes/class-takrg-breaker.php:161
     395msgid "%1$d of the last %2$d checkout attempts were restricted, which is more than half. To protect your sales the plugin now only tags orders. Review the activity log under WooCommerce > Refusal Guard, then turn the protection back on there."
     396msgstr ""
     397
     398#: includes/class-takrg-checkout.php:211
    215399msgid "Cash on delivery is not available for this order. Please choose another payment method."
    216400msgstr ""
    217401
    218 #: includes/class-takrg-checkout.php:289
     402#: includes/class-takrg-checkout.php:401
    219403msgid "COD risk: this customer (phone or e-mail) refused %d earlier order."
    220404msgid_plural "COD risk: this customer (phone or e-mail) refused %d earlier orders."
    … …  
    230414msgstr ""
    231415
    232 #: includes/class-takrg-privacy.php:154
    233 msgid "Takeed Refusal Guard stores, in your own database, the phone number (digits only), the e-mail address, the order number and the date of each order that was refused at delivery. Nothing is sent to the plugin author or to any third party."
    234 msgstr ""
    235 
    236 #: includes/class-takrg-privacy.php:155
     416#: includes/class-takrg-privacy.php:115
     417msgid "COD allow-list and block-list entries"
     418msgstr ""
     419
     420#: includes/class-takrg-privacy.php:116
     421msgid "Entries added by the shop administrator."
     422msgstr ""
     423
     424#: includes/class-takrg-privacy.php:179
     425msgid "Takeed Refusal Guard stores, in your own database, the phone number (digits only), the e-mail address, the order number and the date of each order that was refused at delivery, the entries you add to its allow-list and block-list, and an activity log in which customers appear masked. Nothing is sent to the plugin author or to any third party."
     426msgstr ""
     427
     428#: includes/class-takrg-privacy.php:180
    237429msgid "Suggested text:"
    238430msgstr ""
    239431
    240 #: includes/class-takrg-privacy.php:155
     432#: includes/class-takrg-privacy.php:180
    241433msgid "If you refuse a cash-on-delivery parcel, we keep your phone number and e-mail address together with the order number so that we can offer other payment methods for your next orders. You can ask us to erase this record."
    242434msgstr ""
    243435
    244 #: includes/class-takrg-recorder.php:38 includes/class-takrg-recorder.php:56
     436#: includes/class-takrg-recorder.php:41 includes/class-takrg-recorder.php:59
    245437msgctxt "Order status"
    246438msgid "Refused at delivery"
    247439msgstr ""
    248440
    249 #: includes/class-takrg-recorder.php:44
     441#: includes/class-takrg-recorder.php:47
    250442msgid "Refused at delivery <span class=\"count\">(%s)</span>"
    251443msgid_plural "Refused at delivery <span class=\"count\">(%s)</span>"
    … …  
    253445msgstr[1] ""
    254446
    255 #: includes/class-takrg-recorder.php:67
     447#: includes/class-takrg-recorder.php:70
    256448msgid "Change status to refused at delivery"
    257449msgstr ""
    258450
    259 #: includes/class-takrg-recorder.php:86
     451#: includes/class-takrg-recorder.php:89 includes/class-takrg-recorder.php:114
    260452msgid "Marked as refused at delivery."
    261453msgstr ""
    262454
    263 #: includes/class-takrg-recorder.php:130
     455#: includes/class-takrg-recorder.php:102
     456msgid "Mark as refused at delivery"
     457msgstr ""
     458
     459#: includes/class-takrg-recorder.php:103
     460msgid "Clear the refusal record of this order"
     461msgstr ""
     462
     463#: includes/class-takrg-recorder.php:127
     464msgid "Refusal record cleared."
     465msgstr ""
     466
     467#: includes/class-takrg-recorder.php:169
    264468msgid "Refusal recorded by Takeed Refusal Guard."
    265469msgstr ""
  • takeed-refusal-guard/tags/1.1.0/readme.txt

    r3807459 r3807599  
    88WC requires at least: 7.1
    99WC tested up to: 11.3
    10 Stable tag: 1.0.0
     10Stable tag: 1.1.0
    1111License: GPLv2 or later
    1212License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    2727   * **Show a neutral notice** asking the customer to choose another payment method.
    2828
     29**Safe by design (new in 1.1)**
     30
     31* **Test mode is the default on a new installation.** Orders are only tagged, and an activity log shows what the plugin would have done. Switch to Live when the log looks right.
     32* **Safety breaker.** If more than 50% of the checkout attempts in an hour are restricted (and there are at least 5 attempts), the plugin returns to "tag only" by itself and tells the administrator. It stays there until you turn it back on.
     33* **Fail-open.** If anything goes wrong while the plugin checks a customer, the order goes through.
     34* **Allow-list.** Customers you trust are never touched, whatever their refusals.
     35
    2936**What makes it different**
    3037
    … …  
    3845
    3946* A **COD risk** column in the orders list (legacy and HPOS screens) showing the refusal count of the customer.
     47* **Block-list and patterns**: add an e-mail, a phone number or a pattern such as `*@example.com` or `+21620*`.
     48* **Order actions** on the order screen: mark as refused, or clear a refusal that was a mistake.
     49* **Count refusals from existing orders** with one click, and **forget old refusals** automatically after a number of months you choose.
     50* **Activity log** of the last 500 events, with customers masked.
    4051* Settings under **WooCommerce > Refusal Guard**: threshold, action, counted statuses, default country, add or remove numbers by hand, CSV import and export.
    4152* WordPress personal data exporter and eraser for the stored records.
    … …  
    8899There is no hard dependency between this plugin and any other Takeed plugin.
    89100
     101= What is the safety breaker? =
     102
     103A circuit breaker against mistakes. If more than half of the checkout attempts of the last hour were restricted (with at least 5 attempts, and one customer counted once), something is wrong, for example a rule that is too wide. The plugin then only tags orders, shows a notice in the admin and sends the administrator an e-mail (through your own mail setup). The restriction comes back only when you press "Turn protection back on". The attempt that trips the breaker is still restricted; from the next checkout on, Cash on Delivery is available again.
     104
     105= What happens if the plugin fails during checkout? =
     106
     107The order goes through. Any error while checking a customer lets the order continue, and the error is written to the activity log.
     108
     109= I update from 1.0. Will my shop change? =
     110
     111No. Sites that already used 1.0 keep the action they chose and stay in Live mode. Only new installations start in Test mode.
     112
    90113= Does it send data anywhere? =
    91114
    … …  
    105128* The records are included in the WordPress personal data export (Tools > Export Personal Data) and removed by the erasure tool (Tools > Erase Personal Data), matched by e-mail address and by the phone numbers tied to it.
    106129* A suggested paragraph is added to your privacy policy page (Settings > Privacy).
    107 * Deleting the plugin removes its table and its options.
     130* The activity log shows customers masked (the first and last digits of a phone number; the first letter and the domain of an e-mail address). Allow-list and block-list entries are included in the export and the erasure when they are exact matches of the person.
     131* With "Forget refusals after (months)" you choose how long records are kept; the default keeps them until you delete them.
     132* Deleting the plugin removes its tables (refusals, rules, log) and its options.
    108133
    109134== Changelog ==
     135
     136= 1.1.0 =
     137* New installations start in Test mode: orders are tagged and an activity log shows what the plugin would have done.
     138* Safety breaker: more than 50% of the checkout attempts in an hour (at least 5) returns the plugin to "tag only" and notifies the administrator.
     139* Fail-open: any error while checking a customer lets the order through.
     140* Allow-list, block-list and wildcard patterns (e-mail and phone prefix).
     141* Order screen actions: mark as refused, clear a refusal. Bulk action unchanged.
     142* Count refusals from existing orders. Optional retention in months. Activity log with masked customers.
     143* Privacy exporter and eraser include allow-list and block-list entries.
     144* Sites updating from 1.0 keep their action and stay in Live mode.
    110145
    111146= 1.0.0 =
    … …  
    114149== Upgrade Notice ==
    115150
     151= 1.1.0 =
     152Adds Test mode (default for new installations), a safety breaker, an allow-list and an activity log. Existing sites keep their current behaviour.
     153
    116154= 1.0.0 =
    117155First release.
  • takeed-refusal-guard/tags/1.1.0/takeed-refusal-guard.php

    r3806545 r3807599  
    33 * Plugin Name:       Takeed Refusal Guard for WooCommerce
    44 * Description:       Remembers customers who refused a cash-on-delivery parcel and flags, or limits, cash on delivery on their next order. Built-in phone formats for Tunisia, Morocco, Algeria, Egypt and the Gulf.
    5  * Version:           1.0.0
     5 * Version:           1.1.0
    66 * Requires at least: 6.2
    77 * Requires PHP:      7.4
    … …  
    2121defined( 'ABSPATH' ) || exit;
    2222
    23 define( 'TAKRG_VERSION', '1.0.0' );
     23define( 'TAKRG_VERSION', '1.1.0' );
    2424define( 'TAKRG_FILE', __FILE__ );
    2525define( 'TAKRG_DIR', plugin_dir_path( __FILE__ ) );
    … …  
    2727require_once TAKRG_DIR . 'includes/class-takrg-phone.php';
    2828require_once TAKRG_DIR . 'includes/class-takrg-settings.php';
     29require_once TAKRG_DIR . 'includes/class-takrg-rules.php';
     30require_once TAKRG_DIR . 'includes/class-takrg-log.php';
     31require_once TAKRG_DIR . 'includes/class-takrg-breaker.php';
    2932require_once TAKRG_DIR . 'includes/class-takrg-store.php';
    3033require_once TAKRG_DIR . 'includes/class-takrg-recorder.php';
    … …  
    4750
    4851register_activation_hook( __FILE__, array( 'TAKRG_Plugin', 'activate' ) );
     52register_deactivation_hook( __FILE__, array( 'TAKRG_Plugin', 'deactivate' ) );
    4953
    5054add_action( 'plugins_loaded', array( 'TAKRG_Plugin', 'boot' ) );
  • takeed-refusal-guard/tags/1.1.0/uninstall.php

    r3806545 r3807599  
    1515        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange -- Uninstall removes our own table.
    1616        $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $wpdb->prefix . 'takrg_refusals' ) );
     17        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange -- Uninstall removes our own table.
     18        $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $wpdb->prefix . 'takrg_rules' ) );
     19        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange -- Uninstall removes our own table.
     20        $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $wpdb->prefix . 'takrg_log' ) );
    1721        delete_option( 'takrg_settings' );
    1822        delete_option( 'takrg_db_version' );
     23        delete_option( 'takrg_breaker' );
     24        wp_clear_scheduled_hook( 'takrg_daily_cleanup' );
    1925}
    2026
  • takeed-refusal-guard/trunk/includes/class-takrg-admin.php

    r3806545 r3807599  
    3030                add_action( 'admin_post_takrg_import', array( __CLASS__, 'handle_import' ) );
    3131                add_action( 'admin_post_takrg_export', array( __CLASS__, 'handle_export' ) );
     32                add_action( 'admin_post_takrg_rule_add', array( __CLASS__, 'handle_rule_add' ) );
     33                add_action( 'admin_post_takrg_rule_delete', array( __CLASS__, 'handle_rule_delete' ) );
     34                add_action( 'admin_post_takrg_scan', array( __CLASS__, 'handle_scan' ) );
     35                add_action( 'admin_post_takrg_breaker_reset', array( __CLASS__, 'handle_breaker_reset' ) );
     36                add_action( 'admin_notices', array( __CLASS__, 'breaker_notice' ) );
    3237                // Orders list: legacy (posts) screen and HPOS screen.
    3338                add_filter( 'manage_edit-shop_order_columns', array( __CLASS__, 'add_column' ) );
    … …  
    314319
    315320        /**
     321         * Add an allow-list or block-list rule (exact value or wildcard pattern).
     322         */
     323        public static function handle_rule_add() {
     324                self::guard( 'takrg_rule_add' );
     325                // phpcs:disable WordPress.Security.NonceVerification.Missing -- Verified in guard().
     326                $type    = isset( $_POST['takrg_type'] ) && TAKRG_Rules::BLOCK === sanitize_key( wp_unslash( $_POST['takrg_type'] ) ) ? TAKRG_Rules::BLOCK : TAKRG_Rules::ALLOW;
     327                $value   = isset( $_POST['takrg_value'] ) ? sanitize_text_field( wp_unslash( $_POST['takrg_value'] ) ) : '';
     328                $country = TAKRG_Recorder::country_for( isset( $_POST['takrg_country'] ) ? sanitize_text_field( wp_unslash( $_POST['takrg_country'] ) ) : '' );
     329                // phpcs:enable WordPress.Security.NonceVerification.Missing
     330                $id = TAKRG_Rules::add( $type, $value, $country );
     331                TAKRG_Checkout::reset_cache();
     332                self::back( $id ? 'rule_added' : 'rule_invalid' );
     333        }
     334
     335        /**
     336         * Delete a rule.
     337         */
     338        public static function handle_rule_delete() {
     339                self::guard( 'takrg_rule_delete' );
     340                // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified in guard().
     341                TAKRG_Rules::delete( isset( $_POST['takrg_id'] ) ? absint( $_POST['takrg_id'] ) : 0 );
     342                TAKRG_Checkout::reset_cache();
     343                self::back( 'removed', 1 );
     344        }
     345
     346        /**
     347         * Turns the protection back on after the safety breaker tripped.
     348         */
     349        public static function handle_breaker_reset() {
     350                self::guard( 'takrg_breaker_reset' );
     351                TAKRG_Breaker::reset();
     352                self::back( 'breaker_reset' );
     353        }
     354
     355        /**
     356         * Adds the refusals of orders that are already in a counted status (500 orders per click, newest page first).
     357         * Safe to repeat: an order that already has a record is skipped.
     358         */
     359        public static function handle_scan() {
     360                self::guard( 'takrg_scan' );
     361                // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Verified in guard().
     362                $page  = isset( $_POST['takrg_page'] ) ? max( 1, absint( $_POST['takrg_page'] ) ) : 1;
     363                $added = 0;
     364                $more  = false;
     365                for ( $i = 0; $i < 5; $i++, $page++ ) {
     366                        $orders = wc_get_orders(
     367                                array(
     368                                        'status'  => TAKRG_Settings::counted_statuses(),
     369                                        'limit'   => 100,
     370                                        'paged'   => $page,
     371                                        'orderby' => 'ID',
     372                                        'order'   => 'ASC',
     373                                        'return'  => 'objects',
     374                                )
     375                        );
     376                        foreach ( $orders as $order ) {
     377                                list( $phone, $email ) = TAKRG_Recorder::identity( $order );
     378                                $added                += TAKRG_Store::add( $phone, $email, $order->get_id(), 'scan' ) ? 1 : 0;
     379                        }
     380                        if ( count( $orders ) < 100 ) {
     381                                break;
     382                        }
     383                        $more = true;
     384                }
     385                TAKRG_Checkout::reset_cache();
     386                wp_safe_redirect(
     387                        add_query_arg(
     388                                array(
     389                                        'page'      => self::SLUG,
     390                                        'takrg_msg' => ( $more && count( $orders ) >= 100 ) ? 'scan_more' : 'scanned',
     391                                        'takrg_num' => $added,
     392                                        'takrg_pg'  => $page,
     393                                ),
     394                                admin_url( 'admin.php' )
     395                        )
     396                );
     397                exit;
     398        }
     399
     400        /**
     401         * Admin notice when the safety breaker has tripped (every admin screen, for shop managers).
     402         */
     403        public static function breaker_notice() {
     404                if ( ! current_user_can( self::CAP ) || ! TAKRG_Breaker::is_tripped() ) {
     405                        return;
     406                }
     407                echo '<div class="notice notice-warning"><p><strong>' . esc_html__( 'Takeed Refusal Guard switched itself to "tag only".', 'takeed-refusal-guard' ) . '</strong> '
     408                        . esc_html__( 'More than half of the recent checkout attempts were restricted, so the plugin stopped restricting Cash on Delivery to protect your sales.', 'takeed-refusal-guard' )
     409                        . ' <a href="' . esc_url( admin_url( 'admin.php?page=' . self::SLUG ) ) . '">' . esc_html__( 'Review and turn it back on', 'takeed-refusal-guard' ) . '</a></p></div>';
     410        }
     411
     412        /**
    316413         * Notice texts by key.
    317414         *
    … …  
    331428                                /* translators: %d: number of records. */
    332429                                return array( 'success', sprintf( _n( '%d record imported.', '%d records imported.', $num, 'takeed-refusal-guard' ), $num ) );
     430                        case 'rule_added':
     431                                return array( 'success', __( 'Rule added.', 'takeed-refusal-guard' ) );
     432                        case 'rule_invalid':
     433                                return array( 'error', __( 'Enter an e-mail address, a phone number, or a pattern such as *@example.com or +21620* (not already in the list).', 'takeed-refusal-guard' ) );
     434                        case 'breaker_reset':
     435                                return array( 'success', __( 'Protection turned back on.', 'takeed-refusal-guard' ) );
     436                        case 'scanned':
     437                                /* translators: %d: number of records. */
     438                                return array( 'success', sprintf( _n( 'Scan finished: %d record added.', 'Scan finished: %d records added.', $num, 'takeed-refusal-guard' ), $num ) );
     439                        case 'scan_more':
     440                                /* translators: %d: number of records. */
     441                                return array( 'success', sprintf( _n( '%d record added. More orders remain: press "Continue scan".', '%d records added. More orders remain: press "Continue scan".', $num, 'takeed-refusal-guard' ), $num ) );
    333442                        case 'invalid':
    334443                                return array( 'error', __( 'Enter a valid phone number or e-mail address.', 'takeed-refusal-guard' ) );
    … …  
    375484                // phpcs:enable WordPress.Security.NonceVerification.Recommended
    376485                $per_page = 50;
    377                 $total    = TAKRG_Store::total();
    378                 $rows     = TAKRG_Store::all( $per_page, ( $paged - 1 ) * $per_page );
    379                 $statuses = TAKRG_Settings::selectable_statuses();
    380                 $post_url = admin_url( 'admin-post.php' );
    381                 $actions  = array(
     486                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display only: a page number.
     487                $scan_page = isset( $_GET['takrg_pg'] ) ? max( 1, absint( $_GET['takrg_pg'] ) ) : 1;
     488                $total     = TAKRG_Store::total();
     489                $rows      = TAKRG_Store::all( $per_page, ( $paged - 1 ) * $per_page );
     490                $statuses  = TAKRG_Settings::selectable_statuses();
     491                $post_url  = admin_url( 'admin-post.php' );
     492                $actions   = array(
    382493                        'tag'    => array( __( 'Tag only (default)', 'takeed-refusal-guard' ), __( 'Adds an order note and the meta "_takrg_risk". Nothing is blocked.', 'takeed-refusal-guard' ) ),
    383494                        'hide'   => array( __( 'Hide Cash on Delivery', 'takeed-refusal-guard' ), __( 'Cash on Delivery is not offered to this customer; other payment methods stay available.', 'takeed-refusal-guard' ) ),
    … …  
    391502                        <?php endif; ?>
    392503
     504                        <?php if ( TAKRG_Breaker::is_tripped() ) : ?>
     505                                <div class="notice notice-warning inline">
     506                                        <p><strong><?php esc_html_e( 'The safety breaker switched the plugin to "tag only".', 'takeed-refusal-guard' ); ?></strong>
     507                                                <?php esc_html_e( 'More than half of the checkout attempts in an hour were restricted. Check the activity log below, then turn the protection back on.', 'takeed-refusal-guard' ); ?></p>
     508                                        <form method="post" action="<?php echo esc_url( $post_url ); ?>">
     509                                                <input type="hidden" name="action" value="takrg_breaker_reset" />
     510                                                <?php wp_nonce_field( 'takrg_breaker_reset' ); ?>
     511                                                <p><button type="submit" class="button"><?php esc_html_e( 'Turn protection back on', 'takeed-refusal-guard' ); ?></button></p>
     512                                        </form>
     513                                </div>
     514                        <?php endif; ?>
     515                        <?php if ( 'live' !== $s['mode'] ) : ?>
     516                                <div class="notice notice-info inline"><p><strong><?php esc_html_e( 'Test mode is on.', 'takeed-refusal-guard' ); ?></strong>
     517                                        <?php esc_html_e( 'Nothing is hidden or refused: orders are only tagged, and the activity log below shows what the plugin would have done. When the log looks right, switch to Live.', 'takeed-refusal-guard' ); ?></p></div>
     518                        <?php endif; ?>
     519
    393520                        <form method="post" action="options.php">
    394521                                <?php settings_fields( 'takrg_settings_group' ); ?>
    395522                                <table class="form-table" role="presentation">
     523                                        <tr>
     524                                                <th scope="row"><?php esc_html_e( 'Mode', 'takeed-refusal-guard' ); ?></th>
     525                                                <td>
     526                                                        <fieldset>
     527                                                                <label><input type="radio" name="takrg_settings[mode]" value="test" <?php checked( $s['mode'], 'test' ); ?> /> <strong><?php esc_html_e( 'Test mode (default)', 'takeed-refusal-guard' ); ?></strong></label>
     528                                                                <p class="description"><?php esc_html_e( 'Only tags orders and writes what it would have done to the activity log.', 'takeed-refusal-guard' ); ?></p>
     529                                                                <label><input type="radio" name="takrg_settings[mode]" value="live" <?php checked( $s['mode'], 'live' ); ?> /> <strong><?php esc_html_e( 'Live', 'takeed-refusal-guard' ); ?></strong></label>
     530                                                                <p class="description"><?php esc_html_e( 'Applies the action below. A safety breaker returns to "tag only" if more than 50% of the checkout attempts in an hour (at least 5) are restricted.', 'takeed-refusal-guard' ); ?></p>
     531                                                        </fieldset>
     532                                                </td>
     533                                        </tr>
    396534                                        <tr>
    397535                                                <th scope="row"><label for="takrg_threshold"><?php esc_html_e( 'Refusals before acting', 'takeed-refusal-guard' ); ?></label></th>
    … …  
    431569                                                </td>
    432570                                        </tr>
     571                                        <tr>
     572                                                <th scope="row"><label for="takrg_retention"><?php esc_html_e( 'Forget refusals after (months)', 'takeed-refusal-guard' ); ?></label></th>
     573                                                <td>
     574                                                        <input type="number" min="0" max="120" id="takrg_retention" name="takrg_settings[retention]" value="<?php echo esc_attr( (string) $s['retention'] ); ?>" class="small-text" />
     575                                                        <p class="description"><?php esc_html_e( '0 keeps them until you delete them. Older records and log entries are removed once a day.', 'takeed-refusal-guard' ); ?></p>
     576                                                </td>
     577                                        </tr>
    433578                                </table>
    434579                                <?php submit_button(); ?>
    … …  
    462607                                        <button type="submit" class="button"><?php esc_html_e( 'Remove all records of this number or e-mail', 'takeed-refusal-guard' ); ?></button>
    463608                                </p>
     609                        </form>
     610
     611                        <h2><?php esc_html_e( 'Allow-list and block-list', 'takeed-refusal-guard' ); ?></h2>
     612                        <p class="description"><?php esc_html_e( 'Allow: never act on this customer, whatever the refusals. Block: always treat this customer as having reached the threshold. Use an e-mail, a phone number, or a pattern with * such as *@example.com or +21620*.', 'takeed-refusal-guard' ); ?></p>
     613                        <form method="post" action="<?php echo esc_url( $post_url ); ?>">
     614                                <input type="hidden" name="action" value="takrg_rule_add" />
     615                                <?php wp_nonce_field( 'takrg_rule_add' ); ?>
     616                                <p>
     617                                        <select name="takrg_type" aria-label="<?php esc_attr_e( 'List', 'takeed-refusal-guard' ); ?>">
     618                                                <option value="allow"><?php esc_html_e( 'Allow', 'takeed-refusal-guard' ); ?></option>
     619                                                <option value="block"><?php esc_html_e( 'Block', 'takeed-refusal-guard' ); ?></option>
     620                                        </select>
     621                                        <input type="text" name="takrg_value" class="regular-text" dir="ltr" aria-label="<?php esc_attr_e( 'Value', 'takeed-refusal-guard' ); ?>" />
     622                                        <select name="takrg_country" aria-label="<?php esc_attr_e( 'Country', 'takeed-refusal-guard' ); ?>"><?php self::country_options( (string) $s['default_country'] ); ?></select>
     623                                        <button type="submit" class="button"><?php esc_html_e( 'Add rule', 'takeed-refusal-guard' ); ?></button>
     624                                </p>
     625                        </form>
     626                        <?php $rules = TAKRG_Rules::all( 100 ); ?>
     627                        <?php if ( $rules ) : ?>
     628                                <table class="widefat striped">
     629                                        <thead><tr>
     630                                                <th><?php esc_html_e( 'List', 'takeed-refusal-guard' ); ?></th>
     631                                                <th><?php esc_html_e( 'Value', 'takeed-refusal-guard' ); ?></th>
     632                                                <th><?php esc_html_e( 'Date (UTC)', 'takeed-refusal-guard' ); ?></th>
     633                                                <th></th>
     634                                        </tr></thead>
     635                                        <tbody>
     636                                        <?php foreach ( $rules as $r ) : ?>
     637                                                <tr>
     638                                                        <td><?php echo 'block' === $r['type'] ? esc_html__( 'Block', 'takeed-refusal-guard' ) : esc_html__( 'Allow', 'takeed-refusal-guard' ); ?></td>
     639                                                        <td dir="ltr"><?php echo esc_html( 'phone' === $r['kind'] ? '+' . $r['value'] : $r['value'] ); ?></td>
     640                                                        <td><?php echo esc_html( $r['created_at'] ); ?></td>
     641                                                        <td>
     642                                                                <form method="post" action="<?php echo esc_url( $post_url ); ?>">
     643                                                                        <input type="hidden" name="action" value="takrg_rule_delete" />
     644                                                                        <input type="hidden" name="takrg_id" value="<?php echo esc_attr( (string) $r['id'] ); ?>" />
     645                                                                        <?php wp_nonce_field( 'takrg_rule_delete' ); ?>
     646                                                                        <button type="submit" class="button-link button-link-delete"><?php esc_html_e( 'Delete', 'takeed-refusal-guard' ); ?></button>
     647                                                                </form>
     648                                                        </td>
     649                                                </tr>
     650                                        <?php endforeach; ?>
     651                                        </tbody>
     652                                </table>
     653                        <?php endif; ?>
     654
     655                        <h2><?php esc_html_e( 'Count refusals from existing orders', 'takeed-refusal-guard' ); ?></h2>
     656                        <form method="post" action="<?php echo esc_url( $post_url ); ?>">
     657                                <input type="hidden" name="action" value="takrg_scan" />
     658                                <input type="hidden" name="takrg_page" value="<?php echo esc_attr( (string) $scan_page ); ?>" />
     659                                <?php wp_nonce_field( 'takrg_scan' ); ?>
     660                                <p>
     661                                        <button type="submit" class="button"><?php echo $scan_page > 1 ? esc_html__( 'Continue scan', 'takeed-refusal-guard' ) : esc_html__( 'Scan existing orders', 'takeed-refusal-guard' ); ?></button>
     662                                </p>
     663                                <p class="description"><?php esc_html_e( 'Adds a record for every order that is already in a counted status. Orders that already have a record are skipped, so it is safe to repeat.', 'takeed-refusal-guard' ); ?></p>
    464664                        </form>
    465665
    … …  
    533733                        }
    534734                        ?>
     735
     736                        <h2><?php esc_html_e( 'Activity log', 'takeed-refusal-guard' ); ?></h2>
     737                        <p class="description"><?php esc_html_e( 'The last events. Customers are masked. In test mode, "Would apply" is what Live mode would have done.', 'takeed-refusal-guard' ); ?></p>
     738                        <table class="widefat striped">
     739                                <thead><tr>
     740                                        <th><?php esc_html_e( 'Date (UTC)', 'takeed-refusal-guard' ); ?></th>
     741                                        <th><?php esc_html_e( 'Event', 'takeed-refusal-guard' ); ?></th>
     742                                        <th><?php esc_html_e( 'Action', 'takeed-refusal-guard' ); ?></th>
     743                                        <th><?php esc_html_e( 'Customer', 'takeed-refusal-guard' ); ?></th>
     744                                        <th><?php esc_html_e( 'Refusals', 'takeed-refusal-guard' ); ?></th>
     745                                        <th><?php esc_html_e( 'Order', 'takeed-refusal-guard' ); ?></th>
     746                                        <th><?php esc_html_e( 'Details', 'takeed-refusal-guard' ); ?></th>
     747                                </tr></thead>
     748                                <tbody>
     749                                <?php $events = TAKRG_Log::all( 50 ); ?>
     750                                <?php if ( ! $events ) : ?>
     751                                        <tr><td colspan="7"><?php esc_html_e( 'Nothing yet.', 'takeed-refusal-guard' ); ?></td></tr>
     752                                <?php endif; ?>
     753                                <?php foreach ( $events as $e ) : ?>
     754                                        <tr>
     755                                                <td><?php echo esc_html( $e['created_at'] ); ?></td>
     756                                                <td><?php echo esc_html( self::event_label( $e['event'] ) ); ?></td>
     757                                                <td><?php echo esc_html( $e['action'] ); ?></td>
     758                                                <td dir="ltr"><?php echo esc_html( $e['who'] ); ?></td>
     759                                                <td><?php echo esc_html( (string) $e['refusals'] ); ?></td>
     760                                                <td><?php echo $e['order_id'] ? esc_html( '#' . $e['order_id'] ) : '&ndash;'; ?></td>
     761                                                <td><?php echo esc_html( $e['detail'] ); ?></td>
     762                                        </tr>
     763                                <?php endforeach; ?>
     764                                </tbody>
     765                        </table>
    535766                </div>
    536767                <?php
    537768        }
     769
     770        /**
     771         * Readable name of a log event.
     772         *
     773         * @param string $event Event key.
     774         * @return string
     775         */
     776        private static function event_label( $event ) {
     777                $labels = array(
     778                        'tagged'      => __( 'Order tagged', 'takeed-refusal-guard' ),
     779                        'would_apply' => __( 'Would apply (test mode)', 'takeed-refusal-guard' ),
     780                        'applied'     => __( 'Applied', 'takeed-refusal-guard' ),
     781                        'breaker'     => __( 'Safety breaker', 'takeed-refusal-guard' ),
     782                        'error'       => __( 'Error (order allowed)', 'takeed-refusal-guard' ),
     783                );
     784                return isset( $labels[ $event ] ) ? $labels[ $event ] : $event;
     785        }
    538786}
  • takeed-refusal-guard/trunk/includes/class-takrg-checkout.php

    r3806545 r3807599  
    2929                add_action( 'woocommerce_after_checkout_validation', array( __CLASS__, 'validate_classic' ), 10, 2 );
    3030                add_action( 'woocommerce_store_api_checkout_update_order_from_request', array( __CLASS__, 'validate_store_api' ), 10, 2 );
     31                add_filter( 'rest_request_before_callbacks', array( __CLASS__, 'record_store_api_attempt' ), 10, 3 );
    3132                add_action( 'woocommerce_review_order_before_payment', array( __CLASS__, 'render_notice' ) );
    3233                add_action( 'wp_enqueue_scripts', array( __CLASS__, 'refresh_script' ), 20 );
    … …  
    4445
    4546        /**
    46          * Refusal count for raw (not yet normalised) checkout values, and the settings that apply.
     47         * Judges a customer given as typed at the checkout: refusal count, allow-list, block rules, threshold.
     48         *
     49         * @param string $phone   Phone as typed.
     50         * @param string $email   E-mail as typed.
     51         * @param string $country Billing country.
     52         * @return array count, risky, allowed, key (opaque customer key), who (masked).
     53         */
     54        public static function assess( $phone, $email, $country = '' ) {
     55                $np  = TAKRG_Phone::normalize( $phone, TAKRG_Recorder::country_for( $country ) );
     56                $ne  = TAKRG_Phone::normalize_email( $email );
     57                $key = $np . '|' . $ne;
     58                if ( isset( self::$counts[ $key ] ) ) {
     59                        return self::$counts[ $key ];
     60                }
     61                $allowed = ( '' !== $np || '' !== $ne ) && TAKRG_Rules::matches( TAKRG_Rules::ALLOW, $np, $ne );
     62                $count   = TAKRG_Store::count( $np, $ne );
     63                if ( ! $allowed && ( '' !== $np || '' !== $ne ) && TAKRG_Rules::matches( TAKRG_Rules::BLOCK, $np, $ne ) ) {
     64                        $count = max( $count, (int) TAKRG_Settings::get( 'threshold' ) );
     65                }
     66                $risky                = ! $allowed && self::is_risky( $count, $phone, $email );
     67                self::$counts[ $key ] = array(
     68                        'count'   => $count,
     69                        'risky'   => $risky,
     70                        'allowed' => $allowed,
     71                        'key'     => substr( hash( 'sha256', $key . wp_salt( 'auth' ) ), 0, 12 ),
     72                        'who'     => TAKRG_Log::mask( $np, $ne ),
     73                );
     74                return self::$counts[ $key ];
     75        }
     76
     77        /**
     78         * Refusal count for raw (not yet normalised) checkout values.
    4779         *
    4880         * @param string $phone   Phone as typed.
    … …  
    5284         */
    5385        public static function count_for( $phone, $email, $country = '' ) {
    54                 $phone = TAKRG_Phone::normalize( $phone, TAKRG_Recorder::country_for( $country ) );
    55                 $email = TAKRG_Phone::normalize_email( $email );
    56                 $key   = $phone . '|' . $email;
    57                 if ( ! isset( self::$counts[ $key ] ) ) {
    58                         self::$counts[ $key ] = TAKRG_Store::count( $phone, $email );
    59                 }
    60                 return self::$counts[ $key ];
     86                return self::assess( $phone, $email, $country )['count'];
    6187        }
    6288
    … …  
    7298                $risky = $count >= (int) TAKRG_Settings::get( 'threshold' ) && $count > 0;
    7399                return (bool) apply_filters( 'takrg_is_risky', $risky, $count, $phone, $email );
     100        }
     101
     102        /**
     103         * Runs a check. Any exception means "allow": a failure of this plugin must never stop a sale.
     104         *
     105         * @param callable $check    The check.
     106         * @param mixed    $fallback What to return when the check fails.
     107         * @return mixed
     108         */
     109        private static function guard( $check, $fallback ) {
     110                try {
     111                        return $check();
     112                } catch ( \Throwable $e ) {
     113                        TAKRG_Log::add(
     114                                'error',
     115                                array(
     116                                        'detail' => get_class( $e ) . ': ' . $e->getMessage(),
     117                                )
     118                        );
     119                        return $fallback;
     120                }
    74121        }
    75122
    … …  
    126173        private static function request_risk() {
    127174                list( $phone, $email, $country ) = self::request_identity();
    128                 $count                           = self::count_for( $phone, $email, $country );
    129                 return array( self::is_risky( $count, $phone, $email ), $count );
     175                $a                               = self::assess( $phone, $email, $country );
     176                return array( $a['risky'], $a['count'] );
    130177        }
    131178
    … …  
    138185         */
    139186        public static function filter_gateways( $gateways ) {
    140                 if ( ! is_array( $gateways ) || ! isset( $gateways[ self::COD ] ) || 'hide' !== TAKRG_Settings::get( 'action' ) ) {
     187                if ( ! is_array( $gateways ) || ! isset( $gateways[ self::COD ] ) ) {
    141188                        return $gateways;
    142189                }
    143                 if ( is_admin() && ! wp_doing_ajax() ) {
    144                         return $gateways;
    145                 }
    146                 list( $risky ) = self::request_risk();
    147                 if ( $risky ) {
    148                         unset( $gateways[ self::COD ] );
    149                 }
    150                 return $gateways;
     190                return self::guard(
     191                        function () use ( $gateways ) {
     192                                if ( 'hide' !== TAKRG_Settings::effective_action() || ( is_admin() && ! wp_doing_ajax() ) ) {
     193                                        return $gateways;
     194                                }
     195                                list( $risky ) = self::request_risk();
     196                                if ( $risky ) {
     197                                        unset( $gateways[ self::COD ] );
     198                                }
     199                                return $gateways;
     200                        },
     201                        $gateways
     202                );
    151203        }
    152204
    … …  
    161213
    162214        /**
    163          * Whether this shop's action restricts cash on delivery.
    164          *
    165          * @return bool
    166          */
    167         private static function restricts() {
    168                 return in_array( TAKRG_Settings::get( 'action' ), array( 'hide', 'notice' ), true );
     215         * Decides one checkout attempt: should cash on delivery be refused for this customer? Also feeds the safety
     216         * breaker and the activity log. Never throws.
     217         *
     218         * @param string $phone   Phone as typed.
     219         * @param string $email   E-mail as typed.
     220         * @param string $country Billing country.
     221         * @param string $method  Chosen payment method.
     222         * @param bool   $record  Whether this attempt still has to be counted by the safety breaker.
     223         * @return bool True when the plugin must refuse cash on delivery.
     224         */
     225        private static function refuse_cod( $phone, $email, $country, $method, $record = true ) {
     226                return (bool) self::guard(
     227                        function () use ( $phone, $email, $country, $method, $record ) {
     228                                $intended = (string) TAKRG_Settings::get( 'action' );
     229                                $live     = 'live' === TAKRG_Settings::get( 'mode' ) && ! TAKRG_Breaker::is_tripped();
     230                                $a        = self::assess( $phone, $email, $country );
     231                                $acts     = $a['risky'] && in_array( $intended, array( 'hide', 'notice' ), true );
     232                                if ( $record && 'live' === TAKRG_Settings::get( 'mode' ) ) {
     233                                        TAKRG_Breaker::record( $a['key'], $acts );
     234                                }
     235                                if ( ! $acts ) {
     236                                        return false;
     237                                }
     238                                if ( self::COD !== $method ) {
     239                                        return false;
     240                                }
     241                                TAKRG_Log::add(
     242                                        $live ? 'applied' : 'would_apply',
     243                                        array(
     244                                                'action'   => $intended,
     245                                                'who'      => $a['who'],
     246                                                'refusals' => $a['count'],
     247                                        )
     248                                );
     249                                return $live;
     250                        },
     251                        false
     252                );
    169253        }
    170254
    … …  
    176260         */
    177261        public static function validate_classic( $data, $errors ) {
    178                 if ( ! self::restricts() || ! is_array( $data ) || ! isset( $data['payment_method'] ) || self::COD !== $data['payment_method'] ) {
     262                if ( ! is_array( $data ) ) {
    179263                        return;
    180264                }
    181                 $phone   = isset( $data['billing_phone'] ) ? (string) $data['billing_phone'] : '';
    182                 $email   = isset( $data['billing_email'] ) ? (string) $data['billing_email'] : '';
    183                 $country = isset( $data['billing_country'] ) ? (string) $data['billing_country'] : '';
    184                 $count   = self::count_for( $phone, $email, $country );
    185                 if ( self::is_risky( $count, $phone, $email ) ) {
     265                $method = isset( $data['payment_method'] ) ? (string) $data['payment_method'] : '';
     266                if ( self::refuse_cod( isset( $data['billing_phone'] ) ? (string) $data['billing_phone'] : '', isset( $data['billing_email'] ) ? (string) $data['billing_email'] : '', isset( $data['billing_country'] ) ? (string) $data['billing_country'] : '', $method ) ) {
    186267                        $errors->add( 'takrg_cod_unavailable', self::message() );
    187268                }
     269        }
     270
     271        /**
     272         * Block checkout: counts the attempt for the safety breaker as soon as the Store API receives it, before
     273         * WooCommerce itself may refuse the payment method (action "hide").
     274         *
     275         * @param mixed           $response Response so far.
     276         * @param array           $handler  Route handler.
     277         * @param WP_REST_Request $request  Request.
     278         * @return mixed The response, unchanged.
     279         */
     280        public static function record_store_api_attempt( $response, $handler, $request ) {
     281                unset( $handler );
     282                if ( $request instanceof WP_REST_Request && 'POST' === $request->get_method() && 1 === preg_match( '#^/wc/store/v\d+/checkout$#', $request->get_route() ) ) {
     283                        self::guard(
     284                                function () use ( $request ) {
     285                                        $b = $request->get_param( 'billing_address' );
     286                                        $b = is_array( $b ) ? $b : array();
     287                                        $a = self::assess( isset( $b['phone'] ) ? (string) $b['phone'] : '', isset( $b['email'] ) ? (string) $b['email'] : '', isset( $b['country'] ) ? (string) $b['country'] : '' );
     288                                        if ( 'live' === TAKRG_Settings::get( 'mode' ) ) {
     289                                                TAKRG_Breaker::record( $a['key'], $a['risky'] && in_array( TAKRG_Settings::get( 'action' ), array( 'hide', 'notice' ), true ) );
     290                                        }
     291                                },
     292                                null
     293                        );
     294                }
     295                return $response;
    188296        }
    189297
    … …  
    196304         */
    197305        public static function validate_store_api( $order, $request ) {
    198                 if ( ! self::restricts() || self::COD !== (string) $request['payment_method'] ) {
    199                         return;
    200                 }
    201                 $phone   = (string) $order->get_billing_phone();
    202                 $email   = (string) $order->get_billing_email();
    203                 $country = (string) $order->get_billing_country();
    204                 $count   = self::count_for( $phone, $email, $country );
    205                 if ( self::is_risky( $count, $phone, $email ) && class_exists( '\Automattic\WooCommerce\StoreApi\Exceptions\RouteException' ) ) {
     306                $refuse = self::guard(
     307                        function () use ( $order, $request ) {
     308                                return self::refuse_cod( (string) $order->get_billing_phone(), (string) $order->get_billing_email(), (string) $order->get_billing_country(), (string) $request['payment_method'], false );
     309                        },
     310                        false
     311                );
     312                if ( $refuse && class_exists( '\Automattic\WooCommerce\StoreApi\Exceptions\RouteException' ) ) {
    206313                        throw new \Automattic\WooCommerce\StoreApi\Exceptions\RouteException( 'takrg_cod_unavailable', esc_html( self::message() ), 400 );
    207314                }
    … …  
    214321         */
    215322        public static function refresh_script() {
    216                 if ( 'tag' === TAKRG_Settings::get( 'action' ) || ! function_exists( 'is_checkout' ) || ! is_checkout() ) {
     323                if ( 'tag' === TAKRG_Settings::effective_action() || ! function_exists( 'is_checkout' ) || ! is_checkout() ) {
    217324                        return;
    218325                }
    … …  
    227334        private static function notice_html() {
    228335                $inner = '';
    229                 if ( 'notice' === TAKRG_Settings::get( 'action' ) ) {
     336                if ( 'notice' === TAKRG_Settings::effective_action() ) {
    230337                        list( $risky ) = self::request_risk();
    231338                        if ( $risky ) {
    … …  
    241348         */
    242349        public static function render_notice() {
    243                 if ( 'notice' === TAKRG_Settings::get( 'action' ) ) {
    244                         echo wp_kses_post( self::notice_html() );
     350                if ( 'notice' === TAKRG_Settings::effective_action() ) {
     351                        echo wp_kses_post( self::guard( array( __CLASS__, 'notice_html' ), '' ) );
    245352                }
    246353        }
    … …  
    253360         */
    254361        public static function notice_fragment( $fragments ) {
    255                 if ( 'notice' === TAKRG_Settings::get( 'action' ) && is_array( $fragments ) ) {
    256                         $fragments['.takrg-notice-slot'] = wp_kses_post( self::notice_html() );
     362                if ( 'notice' === TAKRG_Settings::effective_action() && is_array( $fragments ) ) {
     363                        $html = self::guard( array( __CLASS__, 'notice_html' ), '' );
     364                        if ( '' !== $html ) {
     365                                $fragments['.takrg-notice-slot'] = wp_kses_post( $html );
     366                        }
    257367                }
    258368                return $fragments;
    … …  
    277387         */
    278388        public static function tag_order( $order ) {
    279                 if ( ! $order || $order->get_meta( '_takrg_risk' ) ) {
    280                         return;
    281                 }
    282                 list( $phone, $email ) = TAKRG_Recorder::identity( $order );
    283                 $count                 = TAKRG_Store::count( $phone, $email );
    284                 if ( ! self::is_risky( $count, $phone, $email ) ) {
    285                         return;
    286                 }
    287                 $order->update_meta_data( '_takrg_risk', $count );
    288                 /* translators: %d: number of refused cash-on-delivery orders. */
    289                 $order->add_order_note( sprintf( _n( 'COD risk: this customer (phone or e-mail) refused %d earlier order.', 'COD risk: this customer (phone or e-mail) refused %d earlier orders.', $count, 'takeed-refusal-guard' ), $count ) );
    290                 $order->save();
    291                 do_action( 'takrg_order_tagged', $order, $count );
     389                self::guard(
     390                        function () use ( $order ) {
     391                                if ( ! $order || $order->get_meta( '_takrg_risk' ) ) {
     392                                        return;
     393                                }
     394                                $a = self::assess( $order->get_billing_phone(), $order->get_billing_email(), $order->get_billing_country() );
     395                                if ( ! $a['risky'] ) {
     396                                        return;
     397                                }
     398                                $count = $a['count'];
     399                                $order->update_meta_data( '_takrg_risk', $count );
     400                                /* translators: %d: number of refused cash-on-delivery orders. */
     401                                $order->add_order_note( sprintf( _n( 'COD risk: this customer (phone or e-mail) refused %d earlier order.', 'COD risk: this customer (phone or e-mail) refused %d earlier orders.', $count, 'takeed-refusal-guard' ), $count ) );
     402                                $order->save();
     403                                TAKRG_Log::add(
     404                                        'tagged',
     405                                        array(
     406                                                'action'   => 'tag',
     407                                                'who'      => $a['who'],
     408                                                'refusals' => $count,
     409                                                'order_id' => $order->get_id(),
     410                                        )
     411                                );
     412                                do_action( 'takrg_order_tagged', $order, $count );
     413                        },
     414                        null
     415                );
    292416        }
    293417}
  • takeed-refusal-guard/trunk/includes/class-takrg-plugin.php

    r3806545 r3807599  
    1313final class TAKRG_Plugin {
    1414
     15        const CRON = 'takrg_daily_cleanup';
     16
    1517        /**
    16          * Activation: create the table.
     18         * Activation: create the tables and schedule the daily cleanup.
    1719         */
    1820        public static function activate() {
    1921                TAKRG_Store::install();
     22                self::schedule();
     23        }
     24
     25        /**
     26         * Deactivation: stop the daily cleanup.
     27         */
     28        public static function deactivate() {
     29                wp_clear_scheduled_hook( self::CRON );
     30        }
     31
     32        /**
     33         * Schedules the daily cleanup (retention) once.
     34         */
     35        public static function schedule() {
     36                if ( ! wp_next_scheduled( self::CRON ) ) {
     37                        wp_schedule_event( time() + HOUR_IN_SECONDS, 'daily', self::CRON );
     38                }
     39        }
     40
     41        /**
     42         * Daily cleanup: records older than the retention the administrator chose.
     43         */
     44        public static function cleanup() {
     45                TAKRG_Store::purge_older_than( (int) TAKRG_Settings::get( 'retention' ) );
     46        }
     47
     48        /**
     49         * Update from an older version. Shops that already use 1.0.x keep the behaviour they chose (live); only a
     50         * fresh installation starts in test mode.
     51         */
     52        public static function upgrade() {
     53                $from = (string) get_option( TAKRG_Store::DB_VERSION_OPTION, '' );
     54                TAKRG_Store::install();
     55                if ( '' !== $from && version_compare( $from, '2', '<' ) ) {
     56                        $saved = get_option( TAKRG_Settings::OPTION, null );
     57                        if ( is_array( $saved ) && ! isset( $saved['mode'] ) ) {
     58                                $saved['mode'] = 'live';
     59                                update_option( TAKRG_Settings::OPTION, $saved );
     60                        }
     61                }
    2062        }
    2163
    … …  
    2870                }
    2971                if ( get_option( TAKRG_Store::DB_VERSION_OPTION ) !== TAKRG_Store::DB_VERSION ) {
    30                         TAKRG_Store::install();
     72                        self::upgrade();
    3173                }
     74                self::schedule();
     75                add_action( self::CRON, array( __CLASS__, 'cleanup' ) );
    3276                TAKRG_Recorder::init();
    3377                TAKRG_Checkout::init();
  • takeed-refusal-guard/trunk/includes/class-takrg-privacy.php

    r3806545 r3807599  
    109109                        );
    110110                }
     111                if ( 1 === $page && $email ) { // The person's own allow-list / block-list entries.
     112                        foreach ( TAKRG_Rules::for_person( $email, self::phones_of( $email ) ) as $rule ) {
     113                                $export[] = array(
     114                                        'group_id'          => 'takrg-rules',
     115                                        'group_label'       => __( 'COD allow-list and block-list entries', 'takeed-refusal-guard' ),
     116                                        'group_description' => __( 'Entries added by the shop administrator.', 'takeed-refusal-guard' ),
     117                                        'item_id'           => 'takrg-rule-' . $rule['id'],
     118                                        'data'              => array(
     119                                                array(
     120                                                        'name'  => __( 'List', 'takeed-refusal-guard' ),
     121                                                        'value' => $rule['type'],
     122                                                ),
     123                                                array(
     124                                                        'name'  => __( 'Value', 'takeed-refusal-guard' ),
     125                                                        'value' => $rule['value'],
     126                                                ),
     127                                                array(
     128                                                        'name'  => __( 'Date (UTC)', 'takeed-refusal-guard' ),
     129                                                        'value' => $rule['created_at'],
     130                                                ),
     131                                        ),
     132                                );
     133                        }
     134                }
    111135                return array(
    112136                        'data' => $export,
    … …  
    132156                        }
    133157                        $removed += TAKRG_Store::delete_by_identity( '', $email );
     158                        $removed += TAKRG_Rules::delete_exact( $email, $phones );
    134159                        TAKRG_Checkout::reset_cache();
    135160                }
    … …  
    152177                        'Takeed Refusal Guard for WooCommerce',
    153178                        wp_kses_post(
    154                                 '<p class="privacy-policy-tutorial">' . __( 'Takeed Refusal Guard stores, in your own database, the phone number (digits only), the e-mail address, the order number and the date of each order that was refused at delivery. Nothing is sent to the plugin author or to any third party.', 'takeed-refusal-guard' ) . '</p>' .
     179                                '<p class="privacy-policy-tutorial">' . __( 'Takeed Refusal Guard stores, in your own database, the phone number (digits only), the e-mail address, the order number and the date of each order that was refused at delivery, the entries you add to its allow-list and block-list, and an activity log in which customers appear masked. Nothing is sent to the plugin author or to any third party.', 'takeed-refusal-guard' ) . '</p>' .
    155180                                '<p><strong class="privacy-policy-tutorial">' . __( 'Suggested text:', 'takeed-refusal-guard' ) . '</strong> ' . __( 'If you refuse a cash-on-delivery parcel, we keep your phone number and e-mail address together with the order number so that we can offer other payment methods for your next orders. You can ask us to erase this record.', 'takeed-refusal-guard' ) . '</p>'
    156181                        )
  • takeed-refusal-guard/trunk/includes/class-takrg-recorder.php

    r3806545 r3807599  
    2727                add_filter( 'handle_bulk_actions-woocommerce_page_wc-orders', array( __CLASS__, 'handle_bulk' ), 10, 3 );
    2828                add_action( 'takrg_signal', array( __CLASS__, 'on_signal' ), 10, 4 );
     29                add_filter( 'woocommerce_order_actions', array( __CLASS__, 'order_actions' ) );
     30                add_action( 'woocommerce_order_action_takrg_mark_refused', array( __CLASS__, 'action_mark_refused' ) );
     31                add_action( 'woocommerce_order_action_takrg_clear_refusal', array( __CLASS__, 'action_clear_refusal' ) );
    2932        }
    3033
    … …  
    9194
    9295        /**
     96         * Entries of the "Order actions" box on the order screen (legacy and HPOS).
     97         *
     98         * @param array $actions Order actions.
     99         * @return array
     100         */
     101        public static function order_actions( $actions ) {
     102                $actions['takrg_mark_refused']  = __( 'Mark as refused at delivery', 'takeed-refusal-guard' );
     103                $actions['takrg_clear_refusal'] = __( 'Clear the refusal record of this order', 'takeed-refusal-guard' );
     104                return $actions;
     105        }
     106
     107        /**
     108         * Order action: set the refused status.
     109         *
     110         * @param WC_Order $order Order.
     111         */
     112        public static function action_mark_refused( $order ) {
     113                if ( $order && current_user_can( TAKRG_Admin::CAP ) ) {
     114                        $order->update_status( self::STATUS, __( 'Marked as refused at delivery.', 'takeed-refusal-guard' ) );
     115                }
     116        }
     117
     118        /**
     119         * Order action: forget this order's refusal (it was a mistake).
     120         *
     121         * @param WC_Order $order Order.
     122         */
     123        public static function action_clear_refusal( $order ) {
     124                if ( $order && current_user_can( TAKRG_Admin::CAP ) ) {
     125                        TAKRG_Store::remove_for_order( $order->get_id() );
     126                        TAKRG_Checkout::reset_cache();
     127                        $order->add_order_note( __( 'Refusal record cleared.', 'takeed-refusal-guard' ) );
     128                }
     129        }
     130
     131        /**
    93132         * Country used to read a number typed without a country code: the order's own billing country when we
    94133         * support it, else the configured default.
  • takeed-refusal-guard/trunk/includes/class-takrg-settings.php

    r3806545 r3807599  
    2323        public static function defaults() {
    2424                return array(
     25                        'mode'            => 'test',
    2526                        'threshold'       => 1,
    2627                        'action'          => 'tag',
    2728                        'statuses'        => array( 'takeed-refused' ),
    2829                        'default_country' => self::guess_country(),
     30                        'retention'       => 0,
    2931                );
     32        }
     33
     34        /**
     35         * The action that is really applied now. Test mode and a tripped safety breaker both mean "tag only".
     36         *
     37         * @return string tag | hide | notice.
     38         */
     39        public static function effective_action() {
     40                if ( 'live' !== self::get( 'mode' ) || TAKRG_Breaker::is_tripped() ) {
     41                        return 'tag';
     42                }
     43                $action = self::get( 'action' );
     44                return in_array( $action, self::ACTIONS, true ) ? $action : 'tag';
    3045        }
    3146
    … …  
    93108                $out      = $defaults;
    94109
     110                $mode        = isset( $input['mode'] ) ? sanitize_key( $input['mode'] ) : '';
     111                $out['mode'] = in_array( $mode, array( 'test', 'live' ), true ) ? $mode : 'test';
     112
     113                $out['retention'] = isset( $input['retention'] ) ? min( 120, absint( $input['retention'] ) ) : 0;
     114
    95115                $out['threshold'] = isset( $input['threshold'] ) ? max( 1, min( 100, absint( $input['threshold'] ) ) ) : $defaults['threshold'];
    96116
  • takeed-refusal-guard/trunk/includes/class-takrg-store.php

    r3806545 r3807599  
    1515
    1616        const DB_VERSION_OPTION = 'takrg_db_version';
    17         const DB_VERSION        = '1';
     17        const DB_VERSION        = '2';
    1818
    1919        /**
    … …  
    4949) {$charset};"
    5050                );
     51                TAKRG_Rules::install();
     52                TAKRG_Log::install();
    5153                update_option( self::DB_VERSION_OPTION, self::DB_VERSION );
     54        }
     55
     56        /**
     57         * Deletes records older than a number of months (retention). 0 keeps everything.
     58         *
     59         * @param int $months Months to keep.
     60         */
     61        public static function purge_older_than( $months ) {
     62                global $wpdb;
     63                $months = absint( $months );
     64                if ( $months < 1 ) {
     65                        return;
     66                }
     67                $before = gmdate( 'Y-m-d H:i:s', time() - $months * 30 * DAY_IN_SECONDS );
     68                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Our own table.
     69                $wpdb->query( $wpdb->prepare( 'DELETE FROM %i WHERE created_at < %s', self::table(), $before ) );
     70                TAKRG_Log::purge_before( $before );
    5271        }
    5372
  • takeed-refusal-guard/trunk/languages/takeed-refusal-guard.pot

    r3806545 r3807599  
    1010"X-Domain: takeed-refusal-guard\n"
    1111
    12 #: includes/class-takrg-admin.php:52 includes/class-takrg-admin.php:388
     12#: includes/class-takrg-admin.php:57 includes/class-takrg-admin.php:499
    1313msgid "Refusal Guard"
    1414msgstr ""
    1515
    16 #: includes/class-takrg-admin.php:81 includes/class-takrg-admin.php:85
     16#: includes/class-takrg-admin.php:86 includes/class-takrg-admin.php:90
    1717msgid "COD risk"
    1818msgstr ""
    1919
    20 #: includes/class-takrg-admin.php:128
     20#: includes/class-takrg-admin.php:133
    2121msgid "No refusals"
    2222msgstr ""
    2323
    24 #: includes/class-takrg-admin.php:139 includes/class-takrg-admin.php:369
     24#: includes/class-takrg-admin.php:144 includes/class-takrg-admin.php:478
    2525msgid "You are not allowed to do this."
    2626msgstr ""
    2727
    28 #: includes/class-takrg-admin.php:326
     28#: includes/class-takrg-admin.php:407
     29msgid "Takeed Refusal Guard switched itself to \"tag only\"."
     30msgstr ""
     31
     32#: includes/class-takrg-admin.php:408
     33msgid "More than half of the recent checkout attempts were restricted, so the plugin stopped restricting Cash on Delivery to protect your sales."
     34msgstr ""
     35
     36#: includes/class-takrg-admin.php:409
     37msgid "Review and turn it back on"
     38msgstr ""
     39
     40#: includes/class-takrg-admin.php:423
    2941msgid "%d record added."
    3042msgid_plural "%d records added."
    … …  
    3244msgstr[1] ""
    3345
    34 #: includes/class-takrg-admin.php:329
     46#: includes/class-takrg-admin.php:426
    3547msgid "%d record removed."
    3648msgid_plural "%d records removed."
    … …  
    3850msgstr[1] ""
    3951
    40 #: includes/class-takrg-admin.php:332
     52#: includes/class-takrg-admin.php:429
    4153msgid "%d record imported."
    4254msgid_plural "%d records imported."
    … …  
    4456msgstr[1] ""
    4557
    46 #: includes/class-takrg-admin.php:334
     58#: includes/class-takrg-admin.php:431
     59msgid "Rule added."
     60msgstr ""
     61
     62#: includes/class-takrg-admin.php:433
     63msgid "Enter an e-mail address, a phone number, or a pattern such as *@example.com or +21620* (not already in the list)."
     64msgstr ""
     65
     66#: includes/class-takrg-admin.php:435
     67msgid "Protection turned back on."
     68msgstr ""
     69
     70#: includes/class-takrg-admin.php:438
     71msgid "Scan finished: %d record added."
     72msgid_plural "Scan finished: %d records added."
     73msgstr[0] ""
     74msgstr[1] ""
     75
     76#: includes/class-takrg-admin.php:441
     77msgid "%d record added. More orders remain: press \"Continue scan\"."
     78msgid_plural "%d records added. More orders remain: press \"Continue scan\"."
     79msgstr[0] ""
     80msgstr[1] ""
     81
     82#: includes/class-takrg-admin.php:443
    4783msgid "Enter a valid phone number or e-mail address."
    4884msgstr ""
    4985
    50 #: includes/class-takrg-admin.php:336
     86#: includes/class-takrg-admin.php:445
    5187msgid "Choose a .csv file of 1 MB or less."
    5288msgstr ""
    5389
    54 #: includes/class-takrg-admin.php:348
     90#: includes/class-takrg-admin.php:457
    5591msgid "Tunisia (+216)"
    5692msgstr ""
    5793
    58 #: includes/class-takrg-admin.php:349
     94#: includes/class-takrg-admin.php:458
    5995msgid "Morocco (+212)"
    6096msgstr ""
    6197
    62 #: includes/class-takrg-admin.php:350
     98#: includes/class-takrg-admin.php:459
    6399msgid "Algeria (+213)"
    64100msgstr ""
    65101
    66 #: includes/class-takrg-admin.php:351
     102#: includes/class-takrg-admin.php:460
    67103msgid "Egypt (+20)"
    68104msgstr ""
    69105
    70 #: includes/class-takrg-admin.php:352
     106#: includes/class-takrg-admin.php:461
    71107msgid "Saudi Arabia (+966)"
    72108msgstr ""
    73109
    74 #: includes/class-takrg-admin.php:353
     110#: includes/class-takrg-admin.php:462
    75111msgid "United Arab Emirates (+971)"
    76112msgstr ""
    77113
    78 #: includes/class-takrg-admin.php:354
     114#: includes/class-takrg-admin.php:463
    79115msgid "Kuwait (+965)"
    80116msgstr ""
    81117
    82 #: includes/class-takrg-admin.php:355
     118#: includes/class-takrg-admin.php:464
    83119msgid "Qatar (+974)"
    84120msgstr ""
    85121
    86 #: includes/class-takrg-admin.php:356
     122#: includes/class-takrg-admin.php:465
    87123msgid "Oman (+968)"
    88124msgstr ""
    89125
    90 #: includes/class-takrg-admin.php:357
     126#: includes/class-takrg-admin.php:466
    91127msgid "Bahrain (+973)"
    92128msgstr ""
    93129
    94 #: includes/class-takrg-admin.php:382
     130#: includes/class-takrg-admin.php:493
    95131msgid "Tag only (default)"
    96132msgstr ""
    97133
    98 #: includes/class-takrg-admin.php:382
     134#: includes/class-takrg-admin.php:493
    99135msgid "Adds an order note and the meta \"_takrg_risk\". Nothing is blocked."
    100136msgstr ""
    101137
    102 #: includes/class-takrg-admin.php:383
     138#: includes/class-takrg-admin.php:494
    103139msgid "Hide Cash on Delivery"
    104140msgstr ""
    105141
    106 #: includes/class-takrg-admin.php:383
     142#: includes/class-takrg-admin.php:494
    107143msgid "Cash on Delivery is not offered to this customer; other payment methods stay available."
    108144msgstr ""
    109145
    110 #: includes/class-takrg-admin.php:384
     146#: includes/class-takrg-admin.php:495
    111147msgid "Show a notice"
    112148msgstr ""
    113149
    114 #: includes/class-takrg-admin.php:384
     150#: includes/class-takrg-admin.php:495
    115151msgid "Shows a neutral message asking the customer to choose another payment method, and refuses Cash on Delivery on submit."
    116152msgstr ""
    117153
    118 #: includes/class-takrg-admin.php:397
     154#: includes/class-takrg-admin.php:506
     155msgid "The safety breaker switched the plugin to \"tag only\"."
     156msgstr ""
     157
     158#: includes/class-takrg-admin.php:507
     159msgid "More than half of the checkout attempts in an hour were restricted. Check the activity log below, then turn the protection back on."
     160msgstr ""
     161
     162#: includes/class-takrg-admin.php:511
     163msgid "Turn protection back on"
     164msgstr ""
     165
     166#: includes/class-takrg-admin.php:516
     167msgid "Test mode is on."
     168msgstr ""
     169
     170#: includes/class-takrg-admin.php:517
     171msgid "Nothing is hidden or refused: orders are only tagged, and the activity log below shows what the plugin would have done. When the log looks right, switch to Live."
     172msgstr ""
     173
     174#: includes/class-takrg-admin.php:524
     175msgid "Mode"
     176msgstr ""
     177
     178#: includes/class-takrg-admin.php:527
     179msgid "Test mode (default)"
     180msgstr ""
     181
     182#: includes/class-takrg-admin.php:528
     183msgid "Only tags orders and writes what it would have done to the activity log."
     184msgstr ""
     185
     186#: includes/class-takrg-admin.php:529
     187msgid "Live"
     188msgstr ""
     189
     190#: includes/class-takrg-admin.php:530
     191msgid "Applies the action below. A safety breaker returns to \"tag only\" if more than 50% of the checkout attempts in an hour (at least 5) are restricted."
     192msgstr ""
     193
     194#: includes/class-takrg-admin.php:535
    119195msgid "Refusals before acting"
    120196msgstr ""
    121197
    122 #: includes/class-takrg-admin.php:400
     198#: includes/class-takrg-admin.php:538
    123199msgid "A customer (same phone number or same e-mail) with at least this many refusals is treated as a risk."
    124200msgstr ""
    125201
    126 #: includes/class-takrg-admin.php:404
     202#: includes/class-takrg-admin.php:542
    127203msgid "Action at checkout"
    128204msgstr ""
    129205
    130 #: includes/class-takrg-admin.php:415
     206#: includes/class-takrg-admin.php:553
    131207msgid "Statuses that count as a refusal"
    132208msgstr ""
    133209
    134 #: includes/class-takrg-admin.php:423
     210#: includes/class-takrg-admin.php:561
    135211msgid "Default: only \"Refused at delivery\". Be careful with statuses such as Cancelled: customers cancel for many reasons."
    136212msgstr ""
    137213
    138 #: includes/class-takrg-admin.php:427
     214#: includes/class-takrg-admin.php:565
    139215msgid "Default country"
    140216msgstr ""
    141217
    142 #: includes/class-takrg-admin.php:430
     218#: includes/class-takrg-admin.php:568
    143219msgid "Used to read phone numbers typed without a country code."
    144220msgstr ""
    145221
    146 #: includes/class-takrg-admin.php:438
     222#: includes/class-takrg-admin.php:572
     223msgid "Forget refusals after (months)"
     224msgstr ""
     225
     226#: includes/class-takrg-admin.php:575
     227msgid "0 keeps them until you delete them. Older records and log entries are removed once a day."
     228msgstr ""
     229
     230#: includes/class-takrg-admin.php:583
    147231msgid "Add or remove a number"
    148232msgstr ""
    149233
    150 #: includes/class-takrg-admin.php:443 includes/class-takrg-admin.php:457 includes/class-takrg-admin.php:490 includes/class-takrg-privacy.php:93
     234#: includes/class-takrg-admin.php:588 includes/class-takrg-admin.php:602 includes/class-takrg-admin.php:690 includes/class-takrg-privacy.php:93
    151235msgid "Phone"
    152236msgstr ""
    153237
    154 #: includes/class-takrg-admin.php:445 includes/class-takrg-admin.php:459
     238#: includes/class-takrg-admin.php:590 includes/class-takrg-admin.php:604 includes/class-takrg-admin.php:622
    155239msgid "Country"
    156240msgstr ""
    157241
    158 #: includes/class-takrg-admin.php:446 includes/class-takrg-admin.php:460 includes/class-takrg-admin.php:491 includes/class-takrg-privacy.php:97
     242#: includes/class-takrg-admin.php:591 includes/class-takrg-admin.php:605 includes/class-takrg-admin.php:691 includes/class-takrg-privacy.php:97
    159243msgid "E-mail"
    160244msgstr ""
    161245
    162 #: includes/class-takrg-admin.php:448
     246#: includes/class-takrg-admin.php:593 includes/class-takrg-admin.php:744
    163247msgid "Refusals"
    164248msgstr ""
    165249
    166 #: includes/class-takrg-admin.php:450
     250#: includes/class-takrg-admin.php:595
    167251msgid "Add"
    168252msgstr ""
    169253
    170 #: includes/class-takrg-admin.php:462
     254#: includes/class-takrg-admin.php:607
    171255msgid "Remove all records of this number or e-mail"
    172256msgstr ""
    173257
    174 #: includes/class-takrg-admin.php:466
     258#: includes/class-takrg-admin.php:611
     259msgid "Allow-list and block-list"
     260msgstr ""
     261
     262#: includes/class-takrg-admin.php:612
     263msgid "Allow: never act on this customer, whatever the refusals. Block: always treat this customer as having reached the threshold. Use an e-mail, a phone number, or a pattern with * such as *@example.com or +21620*."
     264msgstr ""
     265
     266#: includes/class-takrg-admin.php:617 includes/class-takrg-admin.php:630 includes/class-takrg-privacy.php:120
     267msgid "List"
     268msgstr ""
     269
     270#: includes/class-takrg-admin.php:618 includes/class-takrg-admin.php:638
     271msgid "Allow"
     272msgstr ""
     273
     274#: includes/class-takrg-admin.php:619 includes/class-takrg-admin.php:638
     275msgid "Block"
     276msgstr ""
     277
     278#: includes/class-takrg-admin.php:621 includes/class-takrg-admin.php:631 includes/class-takrg-privacy.php:124
     279msgid "Value"
     280msgstr ""
     281
     282#: includes/class-takrg-admin.php:623
     283msgid "Add rule"
     284msgstr ""
     285
     286#: includes/class-takrg-admin.php:632 includes/class-takrg-admin.php:694 includes/class-takrg-admin.php:740 includes/class-takrg-privacy.php:105 includes/class-takrg-privacy.php:128
     287msgid "Date (UTC)"
     288msgstr ""
     289
     290#: includes/class-takrg-admin.php:646 includes/class-takrg-admin.php:713
     291msgid "Delete"
     292msgstr ""
     293
     294#: includes/class-takrg-admin.php:655
     295msgid "Count refusals from existing orders"
     296msgstr ""
     297
     298#: includes/class-takrg-admin.php:661
     299msgid "Continue scan"
     300msgstr ""
     301
     302#: includes/class-takrg-admin.php:661
     303msgid "Scan existing orders"
     304msgstr ""
     305
     306#: includes/class-takrg-admin.php:663
     307msgid "Adds a record for every order that is already in a counted status. Orders that already have a record are skipped, so it is safe to repeat."
     308msgstr ""
     309
     310#: includes/class-takrg-admin.php:666
    175311msgid "Import and export"
    176312msgstr ""
    177313
    178 #: includes/class-takrg-admin.php:472
     314#: includes/class-takrg-admin.php:672
    179315msgid "Import CSV"
    180316msgstr ""
    181317
    182 #: includes/class-takrg-admin.php:474
     318#: includes/class-takrg-admin.php:674
    183319msgid "One row per refusal: phone,email (a header row is optional). Numbers without a country code use the default country."
    184320msgstr ""
    185321
    186 #: includes/class-takrg-admin.php:479
     322#: includes/class-takrg-admin.php:679
    187323msgid "Export CSV"
    188324msgstr ""
    189325
    190 #: includes/class-takrg-admin.php:485
     326#: includes/class-takrg-admin.php:685
    191327msgid "Stored refusals (%d)"
    192328msgstr ""
    193329
    194 #: includes/class-takrg-admin.php:492 includes/class-takrg-privacy.php:101
     330#: includes/class-takrg-admin.php:692 includes/class-takrg-admin.php:745 includes/class-takrg-privacy.php:101
    195331msgid "Order"
    196332msgstr ""
    197333
    198 #: includes/class-takrg-admin.php:493
     334#: includes/class-takrg-admin.php:693
    199335msgid "Source"
    200336msgstr ""
    201337
    202 #: includes/class-takrg-admin.php:494 includes/class-takrg-privacy.php:105
    203 msgid "Date (UTC)"
    204 msgstr ""
    205 
    206 #: includes/class-takrg-admin.php:499
     338#: includes/class-takrg-admin.php:699
    207339msgid "No refusals recorded yet."
    208340msgstr ""
    209341
    210 #: includes/class-takrg-admin.php:513
    211 msgid "Delete"
    212 msgstr ""
    213 
    214 #: includes/class-takrg-checkout.php:159
     342#: includes/class-takrg-admin.php:736
     343msgid "Activity log"
     344msgstr ""
     345
     346#: includes/class-takrg-admin.php:737
     347msgid "The last events. Customers are masked. In test mode, \"Would apply\" is what Live mode would have done."
     348msgstr ""
     349
     350#: includes/class-takrg-admin.php:741
     351msgid "Event"
     352msgstr ""
     353
     354#: includes/class-takrg-admin.php:742
     355msgid "Action"
     356msgstr ""
     357
     358#: includes/class-takrg-admin.php:743
     359msgid "Customer"
     360msgstr ""
     361
     362#: includes/class-takrg-admin.php:746
     363msgid "Details"
     364msgstr ""
     365
     366#: includes/class-takrg-admin.php:751
     367msgid "Nothing yet."
     368msgstr ""
     369
     370#: includes/class-takrg-admin.php:778
     371msgid "Order tagged"
     372msgstr ""
     373
     374#: includes/class-takrg-admin.php:779
     375msgid "Would apply (test mode)"
     376msgstr ""
     377
     378#: includes/class-takrg-admin.php:780
     379msgid "Applied"
     380msgstr ""
     381
     382#: includes/class-takrg-admin.php:781
     383msgid "Safety breaker"
     384msgstr ""
     385
     386#: includes/class-takrg-admin.php:782
     387msgid "Error (order allowed)"
     388msgstr ""
     389
     390#: includes/class-takrg-breaker.php:158
     391msgid "Takeed Refusal Guard switched itself to \"tag only\""
     392msgstr ""
     393
     394#: includes/class-takrg-breaker.php:161
     395msgid "%1$d of the last %2$d checkout attempts were restricted, which is more than half. To protect your sales the plugin now only tags orders. Review the activity log under WooCommerce > Refusal Guard, then turn the protection back on there."
     396msgstr ""
     397
     398#: includes/class-takrg-checkout.php:211
    215399msgid "Cash on delivery is not available for this order. Please choose another payment method."
    216400msgstr ""
    217401
    218 #: includes/class-takrg-checkout.php:289
     402#: includes/class-takrg-checkout.php:401
    219403msgid "COD risk: this customer (phone or e-mail) refused %d earlier order."
    220404msgid_plural "COD risk: this customer (phone or e-mail) refused %d earlier orders."
    … …  
    230414msgstr ""
    231415
    232 #: includes/class-takrg-privacy.php:154
    233 msgid "Takeed Refusal Guard stores, in your own database, the phone number (digits only), the e-mail address, the order number and the date of each order that was refused at delivery. Nothing is sent to the plugin author or to any third party."
    234 msgstr ""
    235 
    236 #: includes/class-takrg-privacy.php:155
     416#: includes/class-takrg-privacy.php:115
     417msgid "COD allow-list and block-list entries"
     418msgstr ""
     419
     420#: includes/class-takrg-privacy.php:116
     421msgid "Entries added by the shop administrator."
     422msgstr ""
     423
     424#: includes/class-takrg-privacy.php:179
     425msgid "Takeed Refusal Guard stores, in your own database, the phone number (digits only), the e-mail address, the order number and the date of each order that was refused at delivery, the entries you add to its allow-list and block-list, and an activity log in which customers appear masked. Nothing is sent to the plugin author or to any third party."
     426msgstr ""
     427
     428#: includes/class-takrg-privacy.php:180
    237429msgid "Suggested text:"
    238430msgstr ""
    239431
    240 #: includes/class-takrg-privacy.php:155
     432#: includes/class-takrg-privacy.php:180
    241433msgid "If you refuse a cash-on-delivery parcel, we keep your phone number and e-mail address together with the order number so that we can offer other payment methods for your next orders. You can ask us to erase this record."
    242434msgstr ""
    243435
    244 #: includes/class-takrg-recorder.php:38 includes/class-takrg-recorder.php:56
     436#: includes/class-takrg-recorder.php:41 includes/class-takrg-recorder.php:59
    245437msgctxt "Order status"
    246438msgid "Refused at delivery"
    247439msgstr ""
    248440
    249 #: includes/class-takrg-recorder.php:44
     441#: includes/class-takrg-recorder.php:47
    250442msgid "Refused at delivery <span class=\"count\">(%s)</span>"
    251443msgid_plural "Refused at delivery <span class=\"count\">(%s)</span>"
    … …  
    253445msgstr[1] ""
    254446
    255 #: includes/class-takrg-recorder.php:67
     447#: includes/class-takrg-recorder.php:70
    256448msgid "Change status to refused at delivery"
    257449msgstr ""
    258450
    259 #: includes/class-takrg-recorder.php:86
     451#: includes/class-takrg-recorder.php:89 includes/class-takrg-recorder.php:114
    260452msgid "Marked as refused at delivery."
    261453msgstr ""
    262454
    263 #: includes/class-takrg-recorder.php:130
     455#: includes/class-takrg-recorder.php:102
     456msgid "Mark as refused at delivery"
     457msgstr ""
     458
     459#: includes/class-takrg-recorder.php:103
     460msgid "Clear the refusal record of this order"
     461msgstr ""
     462
     463#: includes/class-takrg-recorder.php:127
     464msgid "Refusal record cleared."
     465msgstr ""
     466
     467#: includes/class-takrg-recorder.php:169
    264468msgid "Refusal recorded by Takeed Refusal Guard."
    265469msgstr ""
  • takeed-refusal-guard/trunk/readme.txt

    r3807459 r3807599  
    88WC requires at least: 7.1
    99WC tested up to: 11.3
    10 Stable tag: 1.0.0
     10Stable tag: 1.1.0
    1111License: GPLv2 or later
    1212License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    2727   * **Show a neutral notice** asking the customer to choose another payment method.
    2828
     29**Safe by design (new in 1.1)**
     30
     31* **Test mode is the default on a new installation.** Orders are only tagged, and an activity log shows what the plugin would have done. Switch to Live when the log looks right.
     32* **Safety breaker.** If more than 50% of the checkout attempts in an hour are restricted (and there are at least 5 attempts), the plugin returns to "tag only" by itself and tells the administrator. It stays there until you turn it back on.
     33* **Fail-open.** If anything goes wrong while the plugin checks a customer, the order goes through.
     34* **Allow-list.** Customers you trust are never touched, whatever their refusals.
     35
    2936**What makes it different**
    3037
    … …  
    3845
    3946* A **COD risk** column in the orders list (legacy and HPOS screens) showing the refusal count of the customer.
     47* **Block-list and patterns**: add an e-mail, a phone number or a pattern such as `*@example.com` or `+21620*`.
     48* **Order actions** on the order screen: mark as refused, or clear a refusal that was a mistake.
     49* **Count refusals from existing orders** with one click, and **forget old refusals** automatically after a number of months you choose.
     50* **Activity log** of the last 500 events, with customers masked.
    4051* Settings under **WooCommerce > Refusal Guard**: threshold, action, counted statuses, default country, add or remove numbers by hand, CSV import and export.
    4152* WordPress personal data exporter and eraser for the stored records.
    … …  
    8899There is no hard dependency between this plugin and any other Takeed plugin.
    89100
     101= What is the safety breaker? =
     102
     103A circuit breaker against mistakes. If more than half of the checkout attempts of the last hour were restricted (with at least 5 attempts, and one customer counted once), something is wrong, for example a rule that is too wide. The plugin then only tags orders, shows a notice in the admin and sends the administrator an e-mail (through your own mail setup). The restriction comes back only when you press "Turn protection back on". The attempt that trips the breaker is still restricted; from the next checkout on, Cash on Delivery is available again.
     104
     105= What happens if the plugin fails during checkout? =
     106
     107The order goes through. Any error while checking a customer lets the order continue, and the error is written to the activity log.
     108
     109= I update from 1.0. Will my shop change? =
     110
     111No. Sites that already used 1.0 keep the action they chose and stay in Live mode. Only new installations start in Test mode.
     112
    90113= Does it send data anywhere? =
    91114
    … …  
    105128* The records are included in the WordPress personal data export (Tools > Export Personal Data) and removed by the erasure tool (Tools > Erase Personal Data), matched by e-mail address and by the phone numbers tied to it.
    106129* A suggested paragraph is added to your privacy policy page (Settings > Privacy).
    107 * Deleting the plugin removes its table and its options.
     130* The activity log shows customers masked (the first and last digits of a phone number; the first letter and the domain of an e-mail address). Allow-list and block-list entries are included in the export and the erasure when they are exact matches of the person.
     131* With "Forget refusals after (months)" you choose how long records are kept; the default keeps them until you delete them.
     132* Deleting the plugin removes its tables (refusals, rules, log) and its options.
    108133
    109134== Changelog ==
     135
     136= 1.1.0 =
     137* New installations start in Test mode: orders are tagged and an activity log shows what the plugin would have done.
     138* Safety breaker: more than 50% of the checkout attempts in an hour (at least 5) returns the plugin to "tag only" and notifies the administrator.
     139* Fail-open: any error while checking a customer lets the order through.
     140* Allow-list, block-list and wildcard patterns (e-mail and phone prefix).
     141* Order screen actions: mark as refused, clear a refusal. Bulk action unchanged.
     142* Count refusals from existing orders. Optional retention in months. Activity log with masked customers.
     143* Privacy exporter and eraser include allow-list and block-list entries.
     144* Sites updating from 1.0 keep their action and stay in Live mode.
    110145
    111146= 1.0.0 =
    … …  
    114149== Upgrade Notice ==
    115150
     151= 1.1.0 =
     152Adds Test mode (default for new installations), a safety breaker, an allow-list and an activity log. Existing sites keep their current behaviour.
     153
    116154= 1.0.0 =
    117155First release.
  • takeed-refusal-guard/trunk/takeed-refusal-guard.php

    r3806545 r3807599  
    33 * Plugin Name:       Takeed Refusal Guard for WooCommerce
    44 * Description:       Remembers customers who refused a cash-on-delivery parcel and flags, or limits, cash on delivery on their next order. Built-in phone formats for Tunisia, Morocco, Algeria, Egypt and the Gulf.
    5  * Version:           1.0.0
     5 * Version:           1.1.0
    66 * Requires at least: 6.2
    77 * Requires PHP:      7.4
    … …  
    2121defined( 'ABSPATH' ) || exit;
    2222
    23 define( 'TAKRG_VERSION', '1.0.0' );
     23define( 'TAKRG_VERSION', '1.1.0' );
    2424define( 'TAKRG_FILE', __FILE__ );
    2525define( 'TAKRG_DIR', plugin_dir_path( __FILE__ ) );
    … …  
    2727require_once TAKRG_DIR . 'includes/class-takrg-phone.php';
    2828require_once TAKRG_DIR . 'includes/class-takrg-settings.php';
     29require_once TAKRG_DIR . 'includes/class-takrg-rules.php';
     30require_once TAKRG_DIR . 'includes/class-takrg-log.php';
     31require_once TAKRG_DIR . 'includes/class-takrg-breaker.php';
    2932require_once TAKRG_DIR . 'includes/class-takrg-store.php';
    3033require_once TAKRG_DIR . 'includes/class-takrg-recorder.php';
    … …  
    4750
    4851register_activation_hook( __FILE__, array( 'TAKRG_Plugin', 'activate' ) );
     52register_deactivation_hook( __FILE__, array( 'TAKRG_Plugin', 'deactivate' ) );
    4953
    5054add_action( 'plugins_loaded', array( 'TAKRG_Plugin', 'boot' ) );
  • takeed-refusal-guard/trunk/uninstall.php

    r3806545 r3807599  
    1515        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange -- Uninstall removes our own table.
    1616        $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $wpdb->prefix . 'takrg_refusals' ) );
     17        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange -- Uninstall removes our own table.
     18        $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $wpdb->prefix . 'takrg_rules' ) );
     19        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange -- Uninstall removes our own table.
     20        $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $wpdb->prefix . 'takrg_log' ) );
    1721        delete_option( 'takrg_settings' );
    1822        delete_option( 'takrg_db_version' );
     23        delete_option( 'takrg_breaker' );
     24        wp_clear_scheduled_hook( 'takrg_daily_cleanup' );
    1925}
    2026
Note: See TracChangeset for help on using the changeset viewer.