PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / trunk
JetFormBuilder — Dynamic Blocks Form Builder vtrunk
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 1 month ago builders 1 year ago use-form 3 weeks ago module.php 1 year ago preview.php 4 weeks ago
preview.php
107 lines
1 <?php
2
3 namespace JFB_Modules\Onboarding;
4
5 use Jet_Form_Builder\Blocks\Block_Helper;
6 use Jet_Form_Builder\Blocks\Module;
7 use Jet_Form_Builder\Exceptions\Repository_Exception;
8 use JFB_Components\Wp_Nonce\Wp_Nonce;
9
10 class Preview {
11
12 const NONCE_FIELD = Block_Helper::PREVIEW_NONCE_FIELD;
13
14 private $nonce;
15
16 public function __construct() {
17 $this->nonce = new Wp_Nonce(
18 Block_Helper::PREVIEW_NONCE_ACTION,
19 array(
20 'name' => self::NONCE_FIELD,
21 )
22 );
23 }
24
25 public function init_hooks() {
26 add_filter(
27 'jet-form-builder/post-type/args',
28 array( $this, 'set_form_publicly_queryable' )
29 );
30 add_filter(
31 'the_content',
32 array( $this, 'render_form_preview' )
33 );
34 add_action(
35 'jet-form-builder/editor-assets/before',
36 array( $this, 'editor_assets_before' ),
37 20
38 );
39 }
40
41 public function set_form_publicly_queryable( array $args ): array {
42 if ( is_admin() ||
43 ! $this->get_nonce()->verify() ||
44 ! current_user_can( 'edit_jet_fb_form', get_the_ID() )
45 ) {
46 return $args;
47 }
48
49 $args['publicly_queryable'] = true;
50
51 return $args;
52 }
53
54 public function render_form_preview( $content ) {
55 if ( ! is_singular( 'jet-form-builder' ) ) {
56 return $content;
57 }
58
59 if ( ! did_action( 'jet-form-builder/render-preview' ) ) {
60 do_action( 'jet-form-builder/render-preview' );
61 }
62
63 $form_id = get_the_ID();
64 $latest_revision = wp_get_latest_revision_id_and_total_count();
65
66 if ( ! empty( $latest_revision['latest_id'] ) ) {
67 $form_id = (int) $latest_revision['latest_id'];
68 }
69
70 /** @var Module $blocks */
71 /** @noinspection PhpUnhandledExceptionInspection */
72 $blocks = jet_form_builder()->module( Module::class );
73
74 return $blocks->get_form_class()->render_callback_field( array( 'form_id' => $form_id ) );
75 }
76
77 /**
78 * @return void
79 * @throws Repository_Exception
80 */
81 public function editor_assets_before() {
82 /** @var \JFB_Modules\Onboarding\Module $onboarding */
83 $onboarding = jet_form_builder()->module( 'onboarding' );
84
85 wp_localize_script(
86 $onboarding->get_handle(),
87 'JFBOnboardingConfig',
88 array(
89 'previewURL' => add_query_arg(
90 array(
91 self::NONCE_FIELD => $this->get_nonce()->create(),
92 ),
93 get_permalink()
94 ),
95 )
96 );
97 }
98
99 /**
100 * @return Wp_Nonce
101 */
102 public function get_nonce(): Wp_Nonce {
103 return $this->nonce;
104 }
105
106 }
107