PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 3.6.0
GiveWP – Donation Plugin and Fundraising Platform v3.6.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Onboarding / Wizard / FormPreview.php

FormPreview.php in GiveWP – Donation Plugin and Fundraising Platform 3.6.0, at src/Onboarding/Wizard/FormPreview.php

107 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Onboarding\Wizard;
4
5 defined('ABSPATH') || exit;
6
7 use Give\Helpers\EnqueueScript;
8 use Give\Onboarding\FormRepository;
9 use Give_Scripts;
10
11 /**
12 * Form Preview page class
13 *
14 * Responsible for setting up and rendering Form Preview page at wp-admin/?page=give-form-preview
15 * This URL is used as the src for an iframe which appears inside the Onboarding Wizard.
16 *
17 * @since 2.8.0
18 */
19 class FormPreview
20 {
21
22 /** @var string $slug Page slug used for displaying form preview */
23 protected $slug = 'give-form-preview';
24
25 /** @var FormRepository */
26 protected $formRepository;
27
28 public function __construct(FormRepository $formRepository)
29 {
30 $this->formRepository = $formRepository;
31 }
32
33 /**
34 * Adds Form Preview as dashboard page
35 *
36 * Register Form Preview as an admin page route
37 *
38 * @since 2.8.0
39 **/
40 public function add_page()
41 {
42 add_submenu_page('', '', '', 'manage_options', $this->slug);
43 }
44
45 /**
46 * Conditionally renders Form Preview markup
47 *
48 * If the current page query matches the form preview's slug, method renders the form preview.
49 *
50 * @since 2.8.0
51 **/
52 public function setup_form_preview()
53 {
54 if (empty($_GET['page']) || $this->slug !== $_GET['page']) { // WPCS: CSRF ok, input var ok.
55 return;
56 } else {
57 $this->render_page();
58 }
59 }
60
61 /**
62 * Renders form preview markup
63 *
64 * Uses an object buffer to display the form preview template
65 *
66 * @since 2.8.0
67 **/
68 public function render_page()
69 {
70 $this->register_scripts();
71 ob_start();
72 include_once plugin_dir_path(__FILE__) . 'templates/form-preview.php';
73 exit;
74 }
75
76 /**
77 * Registers form preview scripts/styles
78 *
79 * @since 2.8.0
80 **/
81 protected function register_scripts()
82 {
83 wp_register_style(
84 'give-styles',
85 (new Give_Scripts)->get_frontend_stylesheet_uri(),
86 [],
87 GIVE_VERSION,
88 'all'
89 );
90
91 EnqueueScript::make('give', 'assets/dist/js/give.js' )
92 ->registerTranslations()
93 ->register();
94 }
95
96 /**
97 * Returns the ID of the form used for the form preview
98 *
99 * @since 2.8.0
100 **/
101 protected function get_preview_form_id()
102 {
103 return $this->formRepository->getOrMake();
104 }
105
106 }
107