PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.2
JetFormBuilder — Dynamic Blocks Form Builder v3.6.2
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / onboarding / preview.php
jetformbuilder / modules / onboarding Last commit date
assets 2 weeks ago builders 1 year ago use-form 2 weeks ago module.php 1 year ago preview.php 1 year ago
preview.php
106 lines
1 <?php
2
3 namespace JFB_Modules\Onboarding;
4
5 use Jet_Form_Builder\Blocks\Module;
6 use Jet_Form_Builder\Exceptions\Repository_Exception;
7 use JFB_Components\Wp_Nonce\Wp_Nonce;
8
9 class Preview {
10
11 const NONCE_FIELD = 'jfb_preview_nonce';
12
13 private $nonce;
14
15 public function __construct() {
16 $this->nonce = new Wp_Nonce(
17 'jfb-preview-form',
18 array(
19 'name' => self::NONCE_FIELD,
20 )
21 );
22 }
23
24 public function init_hooks() {
25 add_filter(
26 'jet-form-builder/post-type/args',
27 array( $this, 'set_form_publicly_queryable' )
28 );
29 add_filter(
30 'the_content',
31 array( $this, 'render_form_preview' )
32 );
33 add_action(
34 'jet-form-builder/editor-assets/before',
35 array( $this, 'editor_assets_before' ),
36 20
37 );
38 }
39
40 public function set_form_publicly_queryable( array $args ): array {
41 if ( is_admin() ||
42 ! $this->get_nonce()->verify() ||
43 ! current_user_can( 'edit_jet_fb_form', get_the_ID() )
44 ) {
45 return $args;
46 }
47
48 $args['publicly_queryable'] = true;
49
50 return $args;
51 }
52
53 public function render_form_preview( $content ) {
54 if ( ! is_singular( 'jet-form-builder' ) ) {
55 return $content;
56 }
57
58 if ( ! did_action( 'jet-form-builder/render-preview' ) ) {
59 do_action( 'jet-form-builder/render-preview' );
60 }
61
62 $form_id = get_the_ID();
63 $latest_revision = wp_get_latest_revision_id_and_total_count();
64
65 if ( ! empty( $latest_revision['latest_id'] ) ) {
66 $form_id = (int) $latest_revision['latest_id'];
67 }
68
69 /** @var Module $blocks */
70 /** @noinspection PhpUnhandledExceptionInspection */
71 $blocks = jet_form_builder()->module( Module::class );
72
73 return $blocks->get_form_class()->render_callback_field( array( 'form_id' => $form_id ) );
74 }
75
76 /**
77 * @return void
78 * @throws Repository_Exception
79 */
80 public function editor_assets_before() {
81 /** @var \JFB_Modules\Onboarding\Module $onboarding */
82 $onboarding = jet_form_builder()->module( 'onboarding' );
83
84 wp_localize_script(
85 $onboarding->get_handle(),
86 'JFBOnboardingConfig',
87 array(
88 'previewURL' => add_query_arg(
89 array(
90 self::NONCE_FIELD => $this->get_nonce()->create(),
91 ),
92 get_permalink()
93 ),
94 )
95 );
96 }
97
98 /**
99 * @return Wp_Nonce
100 */
101 public function get_nonce(): Wp_Nonce {
102 return $this->nonce;
103 }
104
105 }
106