PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.3.0
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.3.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 1.0.5 1.0.6 All 66 releases
better-payment / includes / Campaign / Shortcode.php

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

67 lines 1.9 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\Controller;
6 use Better_Payment\Lite\Campaign\Services\RendererService;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * [bp_campaign id="42"] shortcode — renders a campaign on the frontend.
14 * Rendering is delegated to RendererService, which supports both the
15 * column-based layout schema and the legacy flat-array format.
16 */
17 class Shortcode extends Controller {
18
19 public function register() {
20 add_shortcode( 'bp_campaign', [ $this, 'render' ] );
21 }
22
23 public function render( $atts ): string {
24 $atts = shortcode_atts( [ 'id' => 0 ], $atts, 'bp_campaign' );
25
26 $campaign_id = absint( $atts['id'] );
27 if ( ! $campaign_id ) {
28 return '';
29 }
30
31 $post = get_post( $campaign_id );
32 if ( ! $post || $post->post_type !== 'bp_campaign' || $post->post_status !== 'publish' ) {
33 return '';
34 }
35
36 $this->enqueue_frontend_styles();
37 $this->enqueue_frontend_scripts();
38
39 return RendererService::render_campaign( $campaign_id );
40 }
41
42 private function enqueue_frontend_scripts(): void {
43 if ( wp_script_is( 'fundraising-campaign-script', 'enqueued' ) ) {
44 return;
45 }
46 wp_enqueue_script( 'fundraising-campaign-script' );
47 }
48
49 private function enqueue_frontend_styles(): void {
50 $handle = 'better-payment-campaign-display-style';
51 $css_file = BETTER_PAYMENT_PATH . '/assets/blocks/campaign-display/style.min.css';
52
53 if ( ! wp_style_is( $handle, 'registered' ) && file_exists( $css_file ) ) {
54 wp_register_style(
55 $handle,
56 BETTER_PAYMENT_ASSETS . '/blocks/campaign-display/style.min.css',
57 [],
58 filemtime( $css_file )
59 );
60 }
61
62 if ( ! wp_style_is( $handle, 'enqueued' ) ) {
63 wp_enqueue_style( $handle );
64 }
65 }
66 }
67