PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / trunk
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.2 2.1.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 All 66 releases
better-payment / includes / Campaign / CampaignListColumns.php

CampaignListColumns.php in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More trunk, at includes/Campaign/CampaignListColumns.php

65 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Better_Payment\Lite\Campaign;
4
5 use Better_Payment\Lite\Campaign\Support\Money;
6
7 use Better_Payment\Lite\Controller;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Adds "Stats" and "Edit in Builder" columns to the bp_campaign post list table.
15 */
16 class CampaignListColumns extends Controller {
17
18 public function add_columns( array $columns ): array {
19 // Insert stats column before the date column
20 $date = $columns['date'] ?? null;
21 unset( $columns['date'] );
22
23 $columns['campaign_stats'] = __( 'Campaign Stats', 'better-payment' );
24 $columns['campaign_builder'] = __( 'Builder', 'better-payment' );
25
26 if ( $date ) {
27 $columns['date'] = $date;
28 }
29
30 return $columns;
31 }
32
33 public function render_column( string $column, int $post_id ) {
34 if ( $column === 'campaign_stats' ) {
35 $stats = CampaignStats::get_stats( $post_id );
36 $meta = MetaBox::get_all( $post_id );
37 $goal = (float) ( $meta['bpc_goal_amount'] ?? 0 );
38 $currency = $meta['bpc_currency'] ?? 'USD';
39 $raised = $stats['total_raised'];
40 $progress = $stats['progress'];
41
42 printf(
43 '<strong>%s %s</strong> raised<br><small>%d donors &nbsp;|&nbsp; %d%%</small>',
44 esc_html( $currency ),
45 esc_html( Money::format( $raised ) ),
46 (int) $stats['donor_count'],
47 (int) $progress
48 );
49
50 if ( $goal > 0 ) {
51 printf( '<br><small>of %s %s goal</small>', esc_html( $currency ), esc_html( Money::format( $goal ) ) );
52 }
53 }
54
55 if ( $column === 'campaign_builder' ) {
56 $url = admin_url( 'admin.php?page=bp-campaign-builder&campaign_id=' . $post_id );
57 printf(
58 '<a href="%s" class="button button-small">%s</a>',
59 esc_url( $url ),
60 esc_html__( 'Open Builder', 'better-payment' )
61 );
62 }
63 }
64 }
65