PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.3.1
JetFormBuilder — Dynamic Blocks Form Builder v3.3.1
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 / shortcode / module.php
jetformbuilder / modules / shortcode Last commit date
form-shortcode.php 2 years ago module.php 2 years ago shortcode.php 2 years ago
module.php
138 lines
1 <?php
2
3
4 namespace JFB_Modules\Shortcode;
5
6 use Jet_Form_Builder\Classes\Arguments\Default_Form_Arguments;
7 use Jet_Form_Builder\Classes\Arguments\Form_Arguments;
8 use Jet_Form_Builder\Exceptions\Repository_Exception;
9 use JFB_Components\Module\Base_Module_After_Install_It;
10 use JFB_Components\Module\Base_Module_It;
11 use JFB_Components\Repository\Repository_Pattern_Trait;
12
13 // If this file is called directly, abort.
14 if ( ! defined( 'WPINC' ) ) {
15 die;
16 }
17
18 /**
19 * Class Manager
20 *
21 * @package JFB_Modules\Shortcode
22 */
23 final class Module implements Base_Module_It, Base_Module_After_Install_It {
24
25 use Repository_Pattern_Trait;
26
27 public function rep_item_id() {
28 return 'shortcode';
29 }
30
31 public function on_install() {
32 $this->rep_install();
33 }
34
35 public function on_uninstall() {
36 $this->rep_clear();
37 }
38
39 public function condition(): bool {
40 return true;
41 }
42
43 public function init_hooks() {
44 $slug = \JFB_Modules\Post_Type\Module::SLUG;
45
46 // post-type related
47 add_filter(
48 "manage_{$slug}_posts_columns",
49 array( $this, 'filter_columns' )
50 );
51 add_action(
52 "manage_{$slug}_posts_custom_column",
53 array( $this, 'add_admin_column_content' ),
54 10,
55 2
56 );
57 }
58
59 public function remove_hooks() {
60 $slug = \JFB_Modules\Post_Type\Module::SLUG;
61
62 // post-type related
63 remove_filter(
64 "manage_{$slug}_posts_columns",
65 array( $this, 'filter_columns' )
66 );
67 remove_action(
68 "manage_{$slug}_posts_custom_column",
69 array( $this, 'add_admin_column_content' )
70 );
71 }
72
73 public function rep_instances(): array {
74 return array(
75 new Form_Shortcode(),
76 );
77 }
78
79 public function filter_columns( $columns ) {
80 $after = array( 'date' => $columns['date'] );
81 unset( $columns['date'] );
82
83 $columns['jfb_shortcode'] = __( 'Shortcode', 'jet-form-builder' );
84
85 return array_merge( $columns, $after );
86 }
87
88 /**
89 * @param $column
90 * @param $form_id
91 *
92 * @return void
93 * @throws Repository_Exception
94 */
95 public function add_admin_column_content( $column, $form_id ) {
96 if ( 'jfb_shortcode' !== $column ) {
97 return;
98 }
99 /** @var \JFB_Modules\Post_Type\Module $post_type */
100 $post_type = jet_form_builder()->module( 'post-type' );
101 $arguments = array_diff( $post_type->get_args( $form_id ), Form_Arguments::arguments() );
102
103 $arguments = array_merge(
104 array( 'form_id' => $form_id ),
105 Default_Form_Arguments::arguments(),
106 $arguments
107 );
108
109 printf(
110 '<input readonly type="text" onclick="this.select()" value="%s" style="%s"/>',
111 esc_attr( $this->get_shortcode( 'jet_fb_form', $arguments ) ),
112 'width: 100%'
113 );
114 }
115
116 public function get_shortcode( $type, $arguments ): string {
117 $format = '[%1$s %2$s]';
118
119 try {
120 $type = $this->rep_clone_item( $type );
121 } catch ( Repository_Exception $exception ) {
122 return '';
123 }
124
125 return sprintf( $format, $type->get_name(), $this->generate_arguments_string( $arguments ) );
126 }
127
128 private function generate_arguments_string( $arguments ): string {
129 $response = array();
130
131 foreach ( $arguments as $name => $value ) {
132 $response[] = "$name=\"$value\"";
133 }
134
135 return implode( ' ', $response );
136 }
137 }
138