PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.4.0
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.4.0
2.4.1 2.4.0 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 All 68 releases
better-payment / includes / Campaign / CampaignStyles.php

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

151 lines 5.8 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\Classes\ProCompatibility;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 /**
12 * Fires the hooks through which an add-on loads campaign theme CSS.
13 *
14 * The designs of the four Pro `-v2` themes (bp-v2-water, -fooddrive, -wildlife,
15 * -climate) and the theming of Pro's widgets used to be compiled into Lite's
16 * campaign-display stylesheet, because Pro had no way to add CSS to a campaign
17 * page. They ship with Pro now (src/css/campaign-themes.scss), which loads them
18 * through the `better_payment/campaign/enqueue_styles` action and the
19 * `better_payment/campaign/preview_stylesheets` filter fired here.
20 *
21 * Without Pro, no surface loads any Pro design — not a live page, not the
22 * Campaign Builder, not a preview document. A campaign built from a Pro template
23 * keeps its theme class, and the zero-specificity `:where()` fallback tokens in
24 * the campaign-display stylesheet render it as a plain v2 page. A free install's
25 * locked Pro template cards preview as their screenshot only.
26 *
27 * The one thing left here that is Pro's is Lite's transitional copy of the Pro
28 * themes, loaded only for an active Pro that does not ship its own (see
29 * {@see self::lite_copy_applies()}).
30 *
31 * @since 2.4.0
32 */
33 final class CampaignStyles {
34
35 /**
36 * The campaign-display stylesheet every theme builds on.
37 */
38 const DISPLAY_HANDLE = 'better-payment-campaign-display-style';
39
40 // ── Transitional copy of the Pro themes ─────────────────────────────────────
41 // Transitional copy for Better Payment Pro <= 1.4.3; delete when
42 // ProCompatibility::MIN_PRO_VERSION >= 1.4.4. Pro copy:
43 // better-payment-pro/src/css/campaign-themes.scss (loaded by
44 // better-payment-pro/includes/Campaign/CampaignStyles.php). Slug:
45 // campaign_theme_styles.
46 // Deleting it means: FEATURE, LITE_COPY_HANDLE, LITE_COPY_PATH,
47 // lite_copy_applies(), lite_copy_file(), the two blocks marked "Transitional
48 // copy" below, and src/css/campaign-pro-themes.scss with its built
49 // assets/css/campaign-pro-themes.min.css.
50
51 /**
52 * Feature slug Pro declares on `better_payment/pro_provides`.
53 */
54 const FEATURE = 'campaign_theme_styles';
55
56 /**
57 * Handle of Lite's transitional copy.
58 */
59 const LITE_COPY_HANDLE = 'better-payment-campaign-pro-themes';
60
61 /**
62 * Lite's transitional copy, relative to the plugin directory.
63 */
64 const LITE_COPY_PATH = '/assets/css/campaign-pro-themes.min.css';
65
66 /**
67 * Enqueue the theme stylesheets for one campaign surface.
68 *
69 * Call it right after the campaign-display stylesheet is enqueued or registered.
70 *
71 * @param string $context 'frontend' for a live campaign page, 'builder' for the
72 * Campaign Builder admin page.
73 * @return void
74 */
75 public static function enqueue_theme_styles( string $context = 'frontend' ): void {
76 // Transitional copy — see lite_copy_applies().
77 if ( self::lite_copy_applies() && file_exists( self::lite_copy_file() ) ) {
78 wp_enqueue_style(
79 self::LITE_COPY_HANDLE,
80 BETTER_PAYMENT_ASSETS . self::LITE_COPY_PATH,
81 array( self::DISPLAY_HANDLE ),
82 (string) filemtime( self::lite_copy_file() )
83 );
84 }
85
86 /**
87 * Fires wherever a campaign's stylesheets are enqueued, so an add-on can load
88 * its own theme CSS after Lite's campaign-display stylesheet.
89 *
90 * @param string $context 'frontend' or 'builder'.
91 */
92 do_action( 'better_payment/campaign/enqueue_styles', $context );
93 }
94
95 /**
96 * Whether Lite's transitional copy of the Pro themes should load.
97 *
98 * Transitional copy for Better Payment Pro <= 1.4.3; delete when
99 * ProCompatibility::MIN_PRO_VERSION >= 1.4.4. Pro copy:
100 * better-payment-pro/src/css/campaign-themes.scss. Slug: campaign_theme_styles.
101 *
102 * True only for an active Pro that does not declare the slug, on every
103 * surface alike. A free install never loads it: the design is Pro's product.
104 * Entitlement and the Pro declaration are read live on every call.
105 *
106 * @return bool
107 */
108 public static function lite_copy_applies(): bool {
109 return ProCompatibility::lite_copy_applies( self::FEATURE );
110 }
111
112 /**
113 * Absolute path of Lite's transitional copy.
114 *
115 * Transitional copy for Better Payment Pro <= 1.4.3; delete when
116 * ProCompatibility::MIN_PRO_VERSION >= 1.4.4. Slug: campaign_theme_styles.
117 *
118 * @return string
119 */
120 private static function lite_copy_file(): string {
121 return BETTER_PAYMENT_PATH . self::LITE_COPY_PATH;
122 }
123
124 /**
125 * Stylesheet URLs a standalone preview document links after campaign-display.
126 *
127 * Preview documents (the builder canvas, the template picker's lightbox) are
128 * built as HTML strings and never run wp_head, so they cannot use enqueues.
129 *
130 * @return string[]
131 */
132 public static function preview_stylesheets(): array {
133 $urls = array();
134
135 // Transitional copy — see lite_copy_applies().
136 if ( self::lite_copy_applies() && file_exists( self::lite_copy_file() ) ) {
137 $urls[] = add_query_arg( 'ver', (string) filemtime( self::lite_copy_file() ), BETTER_PAYMENT_ASSETS . self::LITE_COPY_PATH );
138 }
139
140 /**
141 * Filter the extra stylesheets linked into a campaign preview document.
142 *
143 * @param string[] $urls Absolute stylesheet URLs.
144 */
145 $urls = apply_filters( 'better_payment/campaign/preview_stylesheets', $urls );
146
147 // A misbehaving callback can return anything; keep only strings.
148 return array_values( array_filter( (array) $urls, 'is_string' ) );
149 }
150 }
151