__( 'Overview', 'codwarden' ), 'settings' => __( 'Settings', 'codwarden' ), 'phones' => __( 'Phone list', 'codwarden' ), ); if ( ! class_exists( 'CWP_Plugin' ) ) { $tabs['pro'] = __( 'Pro', 'codwarden' ); } return $tabs; } /** * Page URL. * * @param string $tab Tab. * @param array $args Extra args. * @return string */ public static function url( $tab = 'overview', $args = array() ) { return add_query_arg( array_merge( array( 'page' => self::PAGE, 'tab' => $tab ), $args ), admin_url( 'admin.php' ) ); } /** * Plugins screen link. * * @param array $links Links. * @return array */ public static function action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Dashboard', 'codwarden' ) . '' ); return $links; } /** * Menu. * * @return void */ public static function menu() { $icon = 'data:image/svg+xml;base64,' . base64_encode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- menu icon. '' ); add_menu_page( __( 'CODWarden', 'codwarden' ), __( 'CODWarden', 'codwarden' ), self::CAP, self::PAGE, array( __CLASS__, 'render' ), $icon, 57 ); add_submenu_page( self::PAGE, __( 'Overview', 'codwarden' ), __( 'Overview', 'codwarden' ), self::CAP, self::PAGE, array( __CLASS__, 'render' ) ); foreach ( array_intersect( array_keys( self::tabs() ), array( 'settings', 'phones' ) ) as $tab ) { $tabs = self::tabs(); add_submenu_page( self::PAGE, $tabs[ $tab ], $tabs[ $tab ], self::CAP, 'admin.php?page=' . self::PAGE . '&tab=' . $tab ); } } /** * Highlight the open tab in the menu. * * @param string|null $file Submenu file. * @return string|null */ public static function submenu_file( $file ) { $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- menu highlight. if ( self::PAGE !== $page ) { return $file; } $tab = self::current_tab(); return 'overview' === $tab ? self::PAGE : 'admin.php?page=' . self::PAGE . '&tab=' . $tab; } /** * Styles. * * @param string $hook Hook. * @return void */ public static function assets( $hook ) { if ( false === strpos( (string) $hook, self::PAGE ) ) { return; } $file = CODWARDEN_PATH . 'assets/css/admin.css'; wp_enqueue_style( 'codwarden-admin', CODWARDEN_URL . 'assets/css/admin.css', array(), CODWARDEN_VERSION . '.' . (int) filemtime( $file ) ); } /** * Settings registration. * * @return void */ public static function register_settings() { register_setting( 'codwarden', CODWarden_Settings::OPTION, array( 'type' => 'array', 'sanitize_callback' => array( 'CODWarden_Settings', 'sanitize' ), 'default' => CODWarden_Settings::defaults(), ) ); } /** * Current tab. * * @return string */ private static function current_tab() { $tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'overview'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- tab switch. return isset( self::tabs()[ $tab ] ) ? $tab : 'overview'; } /** * Reason labels. * * @param string $reason Reason. * @return string */ public static function reason_label( $reason ) { $labels = array( 'bad_phone' => __( 'Phone number is not a real mobile number', 'codwarden' ), 'blocked_phone' => __( 'Phone is on the refuser list', 'codwarden' ), 'over_total' => __( 'Order total above the cash on delivery limit', 'codwarden' ), 'new_over_total' => __( 'New customer above the first-order limit', 'codwarden' ), 'duplicate' => __( 'Same order placed again', 'codwarden' ), 'limit_phone' => __( 'Too many orders from this phone', 'codwarden' ), 'limit_ip' => __( 'Too many orders from this address', 'codwarden' ), ); return isset( $labels[ $reason ] ) ? $labels[ $reason ] : $reason; } /** * Shield logo. * * @return void */ private static function logo() { ?>


payment_gateways()->payment_gateways() ) ) { echo '

' . esc_html__( 'The WooCommerce Cash on delivery payment method was not found. CODWarden only acts on that method.', 'codwarden' ) . '

'; } if ( 'settings' === $tab ) { self::render_settings(); } elseif ( 'phones' === $tab ) { self::render_phones(); } elseif ( 'pro' === $tab ) { self::render_pro(); } else { self::render_overview(); } ?>
payment_gateways()->payment_gateways(); $cod_on = isset( $cod['cod'] ) && 'yes' === $cod['cod']->enabled; $state = ( $on && $cod_on ) ? 'is-on' : ( $on ? 'is-learning' : 'is-off' ); $recent = CODWarden_Store::recent_stopped( 20 ); $figures = array( __( 'COD orders this week', 'codwarden' ) => CODWarden_Store::count_since( 'placed', 168 ), __( 'Stopped this week', 'codwarden' ) => CODWarden_Store::count_since( 'stopped', 168 ), __( 'Stopped today', 'codwarden' ) => CODWarden_Store::count_since( 'stopped', 24 ), __( 'Phones on refuser list', 'codwarden' ) => CODWarden_Store::blocked_count(), ); ?>

$value ) : ?>

', esc_attr( $step ), esc_attr( CODWarden_Settings::OPTION . '[' . $key . ']' ), esc_attr( CODWarden_Settings::get( $key ) ), esc_attr( $label ) ); } /** * Allowed tags for sentences with inputs. * * @return array */ private static function kses() { return array( 'input' => array( 'type' => true, 'min' => true, 'step' => true, 'name' => true, 'value' => true, 'aria-label' => true, ), ); } /** * Settings. * * @return void */ private static function render_settings() { $cur = html_entity_decode( get_woocommerce_currency_symbol(), ENT_QUOTES ); settings_errors(); ?>

array( 'success', __( 'Phone added to the refuser list.', 'codwarden' ) ), 'unblocked' => array( 'success', __( 'Phone removed from the refuser list.', 'codwarden' ) ), 'invalid' => array( 'error', __( 'That does not look like a valid mobile number for the chosen country.', 'codwarden' ) ), ); if ( isset( $msgs[ $msg ] ) ) { printf( '

%2$s

', esc_attr( $msgs[ $msg ][0] ), esc_html( $msgs[ $msg ][1] ) ); } $base = WC()->countries->get_base_country(); ?>

403 ) ); } check_admin_referer( 'codwarden_phone' ); $do = isset( $_POST['do'] ) ? sanitize_key( wp_unslash( $_POST['do'] ) ) : ''; if ( ! empty( $_POST['hash'] ) ) { $hash = preg_replace( '/[^a-f0-9]/', '', sanitize_text_field( wp_unslash( $_POST['hash'] ) ) ); $row = CODWarden_Store::phone( $hash ); if ( $row ) { CODWarden_Store::set_blocked( $hash, $row['phone_masked'], 'block' === $do ); } wp_safe_redirect( self::url( 'phones', array( 'cw_msg' => 'block' === $do ? 'blocked' : 'unblocked' ) ) ); exit; } $country = isset( $_POST['country'] ) ? strtoupper( substr( sanitize_key( wp_unslash( $_POST['country'] ) ), 0, 2 ) ) : ''; $phone = CODWarden_Phone::normalize( isset( $_POST['phone'] ) ? sanitize_text_field( wp_unslash( $_POST['phone'] ) ) : '', $country ); if ( '' === $phone ) { wp_safe_redirect( self::url( 'phones', array( 'cw_msg' => 'invalid' ) ) ); exit; } CODWarden_Store::set_blocked( CODWarden_Phone::hash( $phone ), CODWarden_Phone::mask( $phone ), true ); wp_safe_redirect( self::url( 'phones', array( 'cw_msg' => 'blocked' ) ) ); exit; } /** * Where to buy CODWarden Pro. * * @return string */ public static function pro_url() { /** * Where to buy CODWarden Pro. Empty shows "Coming soon". * * @param string $url URL. */ return (string) apply_filters( 'codwarden_pro_url', 'https://checkout.freemius.com/plugin/46397/plan/81784/' ); } /** * Pro features. * * @return array */ private static function pro_features() { return array( array( 'title' => __( 'Customer confirmation', 'codwarden' ), 'text' => __( 'Right after the order the customer gets an email with a page to confirm or cancel. No SMS service needed.', 'codwarden' ), ), array( 'title' => __( 'On hold until confirmed', 'codwarden' ), 'text' => __( 'New cash on delivery orders wait On hold, so you only pack parcels people really want.', 'codwarden' ), ), array( 'title' => __( 'Auto cancel', 'codwarden' ), 'text' => __( 'Orders nobody confirms within the hours you choose are cancelled and the stock comes back.', 'codwarden' ), ), array( 'title' => __( 'Order screen tools', 'codwarden' ), 'text' => __( 'Mark confirmed after a phone call, send the link again, or ask on WhatsApp with a ready message.', 'codwarden' ), ), array( 'title' => __( 'Report and CSV', 'codwarden' ), 'text' => __( 'A 30 day report of confirmed, cancelled and refused orders, and a CSV export for your courier.', 'codwarden' ), ), array( 'title' => __( 'Instant alerts', 'codwarden' ), 'text' => __( 'Slack, Discord, Telegram or webhook messages when a customer confirms or cancels.', 'codwarden' ), ), ); } /** * Pro plans. * * @return array */ private static function pro_plans() { return array( 1 => array( 'name' => __( 'Single store', 'codwarden' ), 'for' => __( 'For one shop', 'codwarden' ), 'price' => 49, ), 5 => array( 'name' => __( '5 stores', 'codwarden' ), 'for' => __( 'For growing brands', 'codwarden' ), 'price' => 189, ), 25 => array( 'name' => __( '25 stores', 'codwarden' ), 'for' => __( 'For agencies', 'codwarden' ), 'price' => 379, ), ); } /** * Pro tab. * * @return void */ private static function render_pro() { $buy = self::pro_url(); ?>

$plan ) : ?>