admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'maple_carts_admin' ), 'confirmDelete' => __( 'Are you sure you want to delete this?', 'maple-carts' ), 'saving' => __( 'Saving...', 'maple-carts' ), 'saved' => __( 'Saved!', 'maple-carts' ), ] ); // Enqueue WP editor for email templates. if ( strpos( $hook, 'maple-carts-emails' ) !== false ) { wp_enqueue_editor(); } } /** * Handle form actions. */ public function handle_actions() { // Save settings. if ( isset( $_POST['maple_carts_save_settings'] ) && check_admin_referer( 'maple_carts_settings' ) ) { $this->save_settings(); } } /** * Save settings. */ private function save_settings() { $settings = [ 'enabled' => isset( $_POST['enabled'] ) ? 'yes' : 'no', 'cart_cutoff_time' => absint( $_POST['cart_cutoff_time'] ?? 15 ), 'delete_after_days' => absint( $_POST['delete_after_days'] ?? 90 ), 'email_mode' => isset( $_POST['email_mode'] ) && 'mailjet' === $_POST['email_mode'] ? 'mailjet' : 'builtin', 'mailjet_api_key' => sanitize_text_field( wp_unslash( $_POST['mailjet_api_key'] ?? '' ) ), 'mailjet_secret_key'=> sanitize_text_field( wp_unslash( $_POST['mailjet_secret_key'] ?? '' ) ), 'from_name' => sanitize_text_field( wp_unslash( $_POST['from_name'] ?? '' ) ), 'from_email' => sanitize_email( wp_unslash( $_POST['from_email'] ?? '' ) ), 'reply_to' => sanitize_email( wp_unslash( $_POST['reply_to'] ?? '' ) ), 'notify_admin' => isset( $_POST['notify_admin'] ) ? 'yes' : 'no', 'admin_email' => sanitize_email( wp_unslash( $_POST['admin_email'] ?? '' ) ), 'require_consent' => isset( $_POST['require_consent'] ) ? 'yes' : 'no', 'consent_text' => sanitize_text_field( wp_unslash( $_POST['consent_text'] ?? '' ) ), 'show_delete_link' => isset( $_POST['show_delete_link'] ) ? 'yes' : 'no', 'gdpr_notice' => sanitize_textarea_field( wp_unslash( $_POST['gdpr_notice'] ?? '' ) ), 'exclude_roles' => isset( $_POST['exclude_roles'] ) ? array_map( 'sanitize_text_field', $_POST['exclude_roles'] ) : [], ]; update_option( 'maple_carts_settings', $settings ); add_settings_error( 'maple_carts', 'settings_saved', __( 'Settings saved.', 'maple-carts' ), 'success' ); } /** * Render dashboard page. */ public function render_dashboard() { $period = isset( $_GET['period'] ) ? sanitize_text_field( wp_unslash( $_GET['period'] ) ) : '30days'; $stats = Maple_Carts_DB::get_stats( $period ); ?>
render_carts_table( 'abandoned', __( 'Abandoned Carts', 'maple-carts' ) ); } /** * Render recovered carts page. */ public function render_recovered_carts() { $this->render_carts_table( 'recovered', __( 'Recovered Carts', 'maple-carts' ) ); } /** * Render carts table. * * @param string $status Page status. * @param string $title Page title. */ private function render_carts_table( $status, $title ) { $page = isset( $_GET['paged'] ) ? max( 1, absint( $_GET['paged'] ) ) : 1; $limit = 20; $offset = ( $page - 1 ) * $limit; $carts = Maple_Carts_DB::get_carts_by_status( $status, $limit, $offset ); $total = Maple_Carts_DB::count_carts_by_status( $status ); $pages = ceil( $total / $limit ); ?>| email ); ?> unsubscribed ) : ?> | customer_name ?: '—' ); ?> | cart_total, [ 'currency' => $cart->currency ] ); ?> | recovered_at ? $cart->recovered_at : ( $cart->abandoned_at ?: $cart->created_at ); echo esc_html( date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $date ) ) ); ?> |