init.php
7.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! function_exists( 'cf7cmlsIsMoanaActivated' ) ) {
function cf7cmlsIsMoanaActivated() {
return defined( 'CF7_VC_DIR' );
}
}
// Add Go Pro Action Link
add_filter( 'plugin_action_links_' . CF7MLS_PLUGIN_BASENAME, 'cf7mls_plugin_action_links' );
function cf7mls_plugin_action_links( $links ) {
$links[] = '<a target="_blank" href="https://1.envato.market/Multi-Step-Form" style="color: #43B854; font-weight: bold">' . __( 'Go Pro', 'cf7mls' ) . '</a>';
return $links;
}
// Add Document link
add_filter( 'plugin_row_meta', 'cf7mls_plugin_row_meta', 10, 2 );
function cf7mls_plugin_row_meta( $links, $file ) {
if ( strpos( $file, 'contact-form-7-multi-step.php' ) !== false ) {
$new_links = array(
'doc' => '<a href="https://ninjateam.org/contact-form-7-multi-step-pro-doc/" target="_blank">' . __( 'Documentation', 'cf7mls' ) . '</a>',
);
$links = array_merge( $links, $new_links );
}
return $links;
}
add_filter( 'wpcf7_editor_panels', 'cf7mls_wpcf7_editor_panels' );
function cf7mls_wpcf7_editor_panels( $panels ) {
$panels['form-panel'] = array(
'title' => __( 'Form', 'contact-form-7' ),
'callback' => 'cf7mls_wpcf7_editor_panel_form',
);
return $panels;
}
function cf7mls_wpcf7_editor_panel_form( $post ) {
$desc_link = wpcf7_link(
__( 'https://contactform7.com/editing-form-template/', 'contact-form-7' ),
__( 'Editing Form Template', 'contact-form-7' )
);
$description = __( 'You can edit the form template here. For details, see %s.', 'contact-form-7' );
$description = sprintf( esc_html( $description ), $desc_link );
?>
<h2 class="cf7mls-title-form"><?php echo esc_html( __( 'Form', 'contact-form-7' ) ); ?></h2>
<fieldset class="cf7mls-wrap-form">
<legend class="cf7mls-description-form"><?php echo $description; ?></legend>
<?php
$tag_generator = WPCF7_TagGenerator::get_instance();
$tag_generator->print_buttons();
?>
<textarea id="wpcf7-form" name="wpcf7-form" cols="100" rows="24" class="large-text code" data-config-field="form.body"><?php echo esc_textarea( $post->prop( 'form' ) ); ?></textarea>
<div id="cf7mls-app"></div>
<div id="cf7mls_PostBoxUpgradePro" style="display:none;"></div>
</fieldset>
<?php
}
// add js, css
add_action( 'admin_enqueue_scripts', 'cf7mls_admin_scripts_callback' );
function cf7mls_admin_scripts_callback( $hook_suffix ) {
$load_js_css = false;
if ( ( substr( $hook_suffix, -15 ) == '_page_wpcf7-new' ) || ( $hook_suffix == 'toplevel_page_wpcf7' ) ) {
$load_js_css = true;
}
if ( $load_js_css === true ) {
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_style( 'vue-css', CF7MLS_PLUGIN_URL . '/assets/dist/css/main.css' );
wp_register_script( 'vue-js', CF7MLS_PLUGIN_URL . '/assets/dist/js/main.js' );
wp_enqueue_script( 'vue-js' );
wp_localize_script(
'vue-js',
'cf7_mls_vue_js',
array(
'textInputStep' => __( 'Step Name', 'contact-form-7' ),
'textInputBack' => __( 'Back Button', 'contact-form-7' ),
'textInputNext' => __( 'Next Button', 'contact-form-7' ),
'textEditMoana' => __( 'Edit With Moana', 'cf7mls' ),
'cf7cmlsIsMoanaActivated' => cf7cmlsIsMoanaActivated(),
'pluginUrl' => CF7MLS_PLUGIN_URL,
)
);
wp_register_script( 'cf7mls', CF7MLS_PLUGIN_URL . '/assets/admin/js/cf7mls.js', array( 'jquery' ) );
wp_enqueue_script( 'cf7mls' );
$form_content = '';
$manager = WPCF7_FormTagsManager::get_instance();
if ( isset( $_GET['post'] ) && (int) $_GET['post'] > 0 ) {
$form = WPCF7_ContactForm::get_instance( sanitize_text_field( $_GET['post'] ) );
if ( $form ) {
$form_content = $form->prop( 'form' );
} else {
$form_content = WPCF7_ContactFormTemplate::get_default( 'form' );
}
} else {
$form_content = WPCF7_ContactFormTemplate::get_default( 'form' );
}
$scan = $manager->scan( $form_content );
$steps = array();
$numberStep = 0;
foreach ( $scan as $k => $v ) {
if ( $v->type == 'cf7mls_step' ) {
if ( count( $v->values ) == 2 ) {
$numberStep = (int) ( explode( '-', $v->name )[1] );
if ( $numberStep === 1 ) {
$steps[] = array(
'back' => '',
'next' => $v->values[0],
'title' => $v->values[1],
);
} else {
$steps[] = array(
'back' => $v->values[0],
'next' => '',
'title' => $v->values[1],
);
}
} elseif ( count( $v->values ) == 3 ) {
$steps[] = array(
'back' => $v->values[0],
'next' => $v->values[1],
'title' => $v->values[2],
);
}
}
}
wp_localize_script(
'cf7mls',
'cf7mls',
array(
'steps' => $steps,
'cf7mls_app' => null,
)
);
wp_register_style( 'cf7mls', CF7MLS_PLUGIN_URL . '/assets/admin/css/cf7mls.css' );
wp_enqueue_style( 'cf7mls' );
wp_register_style( 'cf7mls_progress_bar', CF7MLS_PLUGIN_URL . '/assets/frontend/css/progress_bar.css' );
wp_enqueue_style( 'cf7mls_progress_bar' );
}
}
/**
* Add step buttin to the wpcf7 tag generator.
*/
function cf7mls_add_tag_generator_multistep() {
if ( class_exists( 'WPCF7_TagGenerator' ) ) {
$tag = WPCF7_TagGenerator::get_instance();
$tag->add(
'cf7mls_step',
__( 'Step', 'cf7mls' ),
'cf7mls_multistep_tag_generator_callback'
);
}
}
add_action( 'admin_init', 'cf7mls_add_tag_generator_multistep', 30 );
/**
* [cf7mls_multistep_tag_generator_callback description]
*/
function cf7mls_multistep_tag_generator_callback( $contact_form, $args = '' ) {
$args = wp_parse_args( $args, array() );
?>
<div class="control-box">
<fieldset>
<legend><?php _e( 'Generate buttons for form\'s steps.', 'cf7mls' ); ?></legend>
<table class="form-table cf7mls-table">
<tbody>
<tr>
<th scope="row"><label for="tag-generator-panel-cf7mls_step-name"><?php _e( 'Name', 'cf7mls' ); ?></label></th>
<td><input type="text" id="tag-generator-panel-cf7mls_step-name" class="tg-name oneline" name="name"></td>
</tr>
<tr>
<th scope="row">
<label for="tag-generator-panel-cf7mls_step-btns-title"><?php _e( 'Back, Next Buttons Title', 'cf7mls' ); ?></label>
</th>
<td>
<textarea name="values" id="tag-generator-panel-cf7mls_step-btns-title" class="cf7mls-values"><?php echo "Back\nNext"; ?></textarea>
<br />
<label for="tag-generator-panel-cf7mls_step-back">
<span class="description"><?php _e( 'One title per line. Back Button\'s title on the first line and Next Button\'s title on the second line.<br />If this is a first step, type only one line for Next Button', 'cf7mls' ); ?></span>
</label>
</td>
</tr>
</tbody>
</table>
</fieldset>
</div>
<div class="insert-box">
<input type="text" name="cf7mls_step" class="tag code" readonly="readonly" onfocus="this.select()" />
<div class="submitbox">
<input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __( 'Insert Tag', 'cf7mls' ) ); ?>" />
</div>
<br class="clear" />
<p class="description mail-tag"><label><?php echo esc_html( __( 'This field should not be used on the Mail tab.', 'cf7mls' ) ); ?></label>
</p>
</div>
<?php
}