register(); ( new GettingStarted() )->register(); } public function menu(): void { add_menu_page( __( 'Receipts', 'action-receipts' ), __( 'Receipts', 'action-receipts' ), Installer::CAP, self::PAGE, array( $this, 'render_page' ), 'dashicons-tickets-alt', 26 ); add_submenu_page( self::PAGE, __( 'All receipts', 'action-receipts' ), __( 'All receipts', 'action-receipts' ), Installer::CAP, self::PAGE, array( $this, 'render_page' ) ); } public function assets( $hook ): void { if ( false === strpos( (string) $hook, self::PAGE ) ) { return; } wp_enqueue_style( 'actr-admin', ACTR_URL . 'assets/css/admin.css', array(), ACTR_VERSION ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only tab check. $tab = isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : ''; if ( false !== strpos( (string) $hook, SettingsPage::PAGE ) && StatusesTab::TAB === $tab ) { wp_enqueue_script( 'actr-admin-statuses', ACTR_URL . 'assets/js/admin-statuses.js', array(), ACTR_VERSION, true ); } } public function action_links( $links ) { $links[] = '' . esc_html__( 'Settings', 'action-receipts' ) . ''; return $links; } /** * Adds a "Donate" link to the plugin's row on the Plugins screen (next to "View details"). * Only there: the plugin never asks for donations anywhere else in wp-admin. * * @param string[] $links Row meta links. * @param string $file Plugin basename of the row. */ public function row_meta( $links, $file ) { if ( plugin_basename( ACTR_FILE ) === $file ) { $links[] = '' . esc_html__( 'Donate', 'action-receipts' ) . ''; } return $links; } public function render_page(): void { if ( ! current_user_can( Installer::CAP ) ) { wp_die( esc_html__( 'You do not have permission to view receipts.', 'action-receipts' ) ); } // phpcs:ignore WordPress.Security.NonceVerification.Recommended $id = isset( $_GET['receipt'] ) ? absint( $_GET['receipt'] ) : 0; if ( $id ) { $this->render_single( $id ); return; } $table = new ReceiptsListTable(); $table->prepare_items(); echo '

' . esc_html__( 'Receipts', 'action-receipts' ) . '

'; echo ' ' . esc_html__( 'Settings', 'action-receipts' ) . ''; echo '
'; if ( GettingStarted::should_show() ) { ( new GettingStarted() )->render(); } elseif ( ! Plugin::instance()->active_adapters() ) { echo '

' . esc_html__( 'Install and activate Contact Form 7 or WPForms to start creating receipts.', 'action-receipts' ) . '

'; } echo '
'; echo ''; $table->views(); $table->search_box( __( 'Search reference or email', 'action-receipts' ), 'actr-search' ); $table->display(); echo '
'; } private function render_single( int $id ): void { $receipt = ReceiptRepository::find( $id ); if ( ! $receipt ) { echo '

' . esc_html__( 'Receipt not found', 'action-receipts' ) . '

'; return; } $status = StatusPipeline::get( $receipt['status_key'] ); $statuses = StatusPipeline::all(); $snapshot = SnapshotService::decode( $receipt ); $events = EventRepository::for_receipt( $id ); $verified = SnapshotService::verify( $receipt ); $link = ReceiptService::status_url( $receipt ); $back = admin_url( 'admin.php?page=' . self::PAGE ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $notice = isset( $_GET['actr_notice'] ) ? sanitize_key( $_GET['actr_notice'] ) : ''; ?>


·

' . esc_html( $receipt['email'] ) . '' : '—'; ?>

  • event_label( $event, $statuses ) ); ?> display_name ) : ''; } ?>


self::PAGE, 'receipt' => $id, 'actr_notice' => $changed ? 'updated' : 'nochange', ), admin_url( 'admin.php' ) ) ); exit; } private function event_label( array $event, array $statuses ): string { $to = $event['to_status'] && isset( $statuses[ $event['to_status'] ] ) ? $statuses[ $event['to_status'] ]['label'] : $event['to_status']; switch ( $event['type'] ) { case EventRepository::CREATED: return __( 'Receipt created', 'action-receipts' ); case EventRepository::STATUS_CHANGED: /* translators: %s: status label */ return sprintf( __( 'Status → %s', 'action-receipts' ), $to ); case EventRepository::EMAIL_SENT: return __( 'Email sent to the visitor', 'action-receipts' ); case EventRepository::NOTE: return __( 'Note added', 'action-receipts' ); } return (string) $event['type']; } }