PluginProbe
Smart Grid-Layout Design for Contact Form 7 / 4.12
Smart Grid-Layout Design for Contact Form 7 v4.12
4.18.0 4.17.0 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 4.0.0 4.0.1 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10 4.11 4.12 4.13 4.14 All 119 releases
cf7-grid-layout / admin / class-cf7-grid-layout-admin.php

class-cf7-grid-layout-admin.php in Smart Grid-Layout Design for Contact Form 7 4.12, at admin/class-cf7-grid-layout-admin.php

1,984 lines 83.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The admin-specific functionality of the plugin.
5 *
6 * @link http://syllogic.in
7 * @since 1.0.0
8 *
9 * @package Cf7_Grid_Layout
10 * @subpackage Cf7_Grid_Layout/admin
11 */
12
13 /**
14 * The admin-specific functionality of the plugin.
15 *
16 * Defines the plugin name, version, and two examples hooks for how to
17 * enqueue the admin-specific stylesheet and JavaScript.
18 *
19 * @package Cf7_Grid_Layout
20 * @subpackage Cf7_Grid_Layout/admin
21 * @author Aurovrata V. <vrata@syllogic.in>
22 */
23 class Cf7_Grid_Layout_Admin {
24 /**
25 * The ID of this plugin.
26 *
27 * @since 4.2.1
28 * @access private
29 * @var string $plugin_name The ID of this plugin.
30 */
31 private static $admin_notice_pages = array(
32 'admin.php'=>array('cf7sg_help'=>'page'),
33 'edit.php'=>array('wpcf7_contact_form'=>'post_type'),
34 'post.php'=> 'wpcf7_contact_form',
35 'edit-tags.php'=>array('wpcf7_contact_form'=>'post_type'),
36 'index.php'=>'',//dashboard ,
37 'plugins.php'=>'',
38 //'options-general.php'=>'page=',
39 );
40 /**
41 * The ID of this plugin.
42 *
43 * @since 1.0.0
44 * @access private
45 * @var string $plugin_name The ID of this plugin.
46 */
47 private $plugin_name;
48
49 /**
50 * The ID of this plugin.
51 *
52 * @since 4.6.0
53 * @access public
54 * @var Constant CF7SG_OPTION Options key.
55 */
56 const CF7SG_OPTION = 'cf7sg-plugin-version';
57
58 /**
59 * The version of this plugin.
60 *
61 * @since 1.0.0
62 * @access private
63 * @var string $version The current version of this plugin.
64 */
65 private $version;
66 /**
67 * Initialize the class and set its properties.
68 *
69 * @since 1.0.0
70 * @param string $plugin_name The name of this plugin.
71 * @param string $version The version of this plugin.
72 */
73 public function __construct( $plugin_name, $version ) {
74 $this->plugin_name = $plugin_name;
75 $this->version = $version;
76 }
77 /**
78 * get cf7 post type set by cf7 plugin.
79 *
80 *@since 3.0.0
81 *@return string post type.
82 */
83 private function cf7_post_type(){
84 $type = 'wpcf7_post_type_notset';
85 if(class_exists('WPCF7_ContactForm') ) {
86 $type = WPCF7_ContactForm::post_type;
87 }
88 return $type;
89 }
90 /**
91 * Hack to add scripts/styles to edit page.
92 * Hooked on 'admin_enqueue_scripts'.
93 *@since 1.5.0
94 */
95 public function popular_extentions_scripts(){
96 $screen = get_current_screen();
97 if (empty($screen) || $this->cf7_post_type() != $screen->post_type){
98 return;
99 }
100 $plugin_dir = plugin_dir_url( __DIR__ );
101
102 switch( $screen->base ){
103 case 'post':
104 $page_hook = '';
105 if('add' == $screen->action) $page_hook = 'contact_page_wpcf7-new';
106 else $page_hook = 'toplevel_page_wpcf7';
107 //unhook this function.
108 remove_action('admin_enqueue_scripts', array($this, 'popular_extentions_scripts'),999,0);
109 do_action('admin_enqueue_scripts', $page_hook);
110 $plugin_page ='';
111 add_action('admin_enqueue_scripts', array($this, 'popular_extentions_scripts'),999,0);
112 break;
113 case 'edit': //table.
114 break;
115 }
116 }
117 /**
118 * Function to spoof the wpcf7 plugin admin scripts loading for extensions
119 * Hooked on 'admin_print_scripts' and used to fix the issue with the mailchimp ext.
120 *@since 1.5.1
121 */
122 public function print_extentions_scripts(){
123 $screen = get_current_screen();
124 if (empty($screen) || $this->cf7_post_type() != $screen->post_type){
125 return;
126 }
127 global $plugin_page;
128 $plugin_page = 'wpcf7';
129 }
130
131
132 /**
133 * Register the stylesheets for the admin area.
134 *
135 * @since 1.0.0
136 */
137 public function enqueue_styles($page) {
138
139 if( in_array($page, array('toplevel_page_wpcf7', 'contact_page_wpcf7-new')) ) return;
140
141 $screen = get_current_screen();
142 $plugin_dir = plugin_dir_url( __DIR__ );
143 if('plugins'==$screen->base){
144 /** @since 4.1.0 */
145 wp_enqueue_style('plugin-update',$plugin_dir . 'admin/css/cf7sg-plugin-update.css', array(), $this->version, 'all');
146 return;
147 }
148 if (empty($screen) || $this->cf7_post_type() != $screen->post_type){
149 return;
150 }
151 switch( $screen->base ){
152 case 'post':
153 wp_enqueue_style( "cf7-grid-post-css", $plugin_dir . 'admin/css/cf7-grid-layout-post.css', array(), $this->version, 'all' );
154 //dynamic tag
155 wp_enqueue_style('cf7sg-dynamic-tag-css', $plugin_dir . 'admin/css/cf7sg-dynamic-tag.css', array(), $this->version, 'all' );
156 //benchmark tag
157 wp_enqueue_style('cf7sg-benchmark-tag-css', $plugin_dir . 'admin/css/cf7sg-benchmark-tag.css', array(), $this->version, 'all' );
158 //codemirror
159 wp_enqueue_style( "codemirror-css", $plugin_dir . 'assets/codemirror/codemirror.css', array(), $this->version, 'all' );
160 /** @since 4.0 enable dark theme */
161 wp_enqueue_style( "codemirror-theme-light-css", $plugin_dir . 'assets/codemirror/theme/paraiso-light.css', array(), $this->version, 'all' );
162 wp_enqueue_style( "codemirror-theme-dark-css", $plugin_dir . 'assets/codemirror/theme/material-ocean.css', array(), $this->version, 'all' );
163 wp_enqueue_style( "codemirror-foldgutter-css", $plugin_dir . 'assets/codemirror/addon/fold/foldgutter.css', array(), $this->version, 'all' );
164 wp_enqueue_style( "codemirror-dialog-css", $plugin_dir . 'assets/codemirror/addon/dialog/dialog.css', array(), $this->version, 'all' );
165 wp_enqueue_style( "codemirror-matchesonscrollbar-css", $plugin_dir . 'assets/codemirror/addon/search/matchesonscrollbar.css', array(), $this->version, 'all' );
166 wp_enqueue_style( 'smart-grid-css', $plugin_dir . 'assets/css.gs/smart-grid.admin.css', array(), $this->version, 'all');
167 wp_enqueue_style('dashicons');
168 wp_enqueue_style('select2-style', $plugin_dir . 'assets/select2/css/select2.min.css', array(), $this->version, 'all' );
169 /** @since 4.4.0 Enabled user style enqueue */
170 do_action('cf7sg_enqueue_admin_editor_styles');
171 break;
172 case 'edit': //table.
173 wp_enqueue_style( $this->plugin_name, $plugin_dir . 'admin/css/cf7-grid-layout-admin.css', array(), $this->version, 'all' );
174 /** @since 4.4.0 Enabled user style enqueue */
175 do_action('cf7sg_enqueue_admin_table_styles');
176 break;
177 }
178
179 }
180
181 /**
182 * Register the JavaScript for the admin area.
183 *
184 * @since 1.0.0
185 */
186 public function enqueue_scripts($page) {
187
188 $plugin_dir = plugin_dir_url( __DIR__ );
189 if( in_array($page, array('toplevel_page_wpcf7', 'contact_page_wpcf7-new')) ){
190 wp_enqueue_script( $this->plugin_name, $plugin_dir . 'admin/js/cf7-grid-layout-admin.js', array( 'jquery' ), $this->version, true );
191 return;
192 }
193 $screen = get_current_screen();
194 if('plugins'==$screen->base){
195 /** @since 4.1.0 */
196 wp_enqueue_script('cf7sg-plugin-update', $plugin_dir . 'admin/js/cf7sg-plugin-update.js', array('jquery'));
197 /* translators: message displayed when succesful update to validate new version */
198 wp_localize_script('cf7sg-plugin-update', 'cf7sg',array(
199 'msg'=> __('Validating your update...','cf7-grid-layout'),
200 'nonce'=> wp_create_nonce( 'cf7sg_udpate_plugin' ),
201 'error'=>__('Unable to validate, please reload!', 'cf7-grid-layout')
202 ));
203 return;
204 }
205 if ($this->cf7_post_type() != $screen->post_type){
206 return;
207 }
208
209 switch( $screen->base ){
210 case 'post':
211 global $post;
212 /* register codemirror editor & addons. */
213 //codemirror script
214 wp_register_script( 'cf7-codemirror-js',
215 $plugin_dir . 'assets/codemirror/codemirror.js',
216 null, "5.32", true
217 );
218 /** @since 3.1.2 initialise codemirror after library load and parse as attribute to anonymous functtion in cf7-grid-codemirror.js */
219 wp_add_inline_script('cf7-codemirror-js',
220 'const cmInitialSettings = {
221 value:"",autoCloseTags:true,
222 extraKeys: {"Ctrl-Space": "autocomplete", "Ctrl-/": "toggleComment", "Ctrl-J": "toMatchingTag"},
223 lineNumbers: true, styleActiveLine: true,
224 matchBrackets: true, tabSize:2, lineWrapping: true, addModeClass: true,
225 foldGutter: true, autofocus:false,
226 gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
227 }
228 const codeMirror_5_32 = CodeMirror(document.getElementById("cf7-codemirror"),cmInitialSettings);
229 const cssCodeMirror_5_32 = CodeMirror(document.getElementById("cf7-css-codemirror"),cmInitialSettings);
230 const jsCodeMirror_5_32 = CodeMirror(document.getElementById("cf7-js-codemirror"),cmInitialSettings);');
231 //matchtags.
232 wp_enqueue_script( 'codemirror-closetag-js',
233 $plugin_dir . 'assets/codemirror/addon/edit/closetag.js',
234 array('cf7-codemirror-js'), $this->version, true
235 );
236 //fold code
237 wp_enqueue_script( 'codemirror-foldcode-js',
238 $plugin_dir . 'assets/codemirror/addon/fold/foldcode.js',
239 array('cf7-codemirror-js'), $this->version, true
240 );
241 wp_enqueue_script( 'codemirror-foldgutter-js',
242 $plugin_dir . 'assets/codemirror/addon/fold/foldgutter.js',
243 array('cf7-codemirror-js'), $this->version, true
244 );
245 wp_enqueue_script( 'codemirror-indent-fold-js',
246 $plugin_dir . 'assets/codemirror/addon/fold/indent-fold.js',
247 array('cf7-codemirror-js'), $this->version, true
248 );
249 wp_enqueue_script( 'codemirror-xml-fold-js',
250 $plugin_dir . 'assets/codemirror/addon/fold/xml-fold.js',
251 array('cf7-codemirror-js'), $this->version, true
252 );
253 wp_enqueue_script( 'codemirror-matchtag-js',
254 $plugin_dir . 'assets/codemirror/addon/edit/matchtags.js',
255 array('cf7-codemirror-js','codemirror-xml-fold-js'), $this->version, true
256 );
257 wp_enqueue_script( 'codemirror-brace-fold-js',
258 $plugin_dir . 'assets/codemirror/addon/fold/brace-fold.js',
259 array('cf7-codemirror-js'), $this->version, true
260 );
261 wp_enqueue_script( 'codemirror-comment-fold-js',
262 $plugin_dir . 'assets/codemirror/addon/fold/comment-fold.js',
263 array('cf7-codemirror-js'), $this->version, true
264 );
265 wp_enqueue_script( 'codemirror-mixed-js',
266 $plugin_dir . 'assets/codemirror/mode/htmlmixed/htmlmixed.js',
267 array('cf7-codemirror-js'), $this->version, true
268 );
269 wp_enqueue_script( 'codemirror-javascript-js',
270 $plugin_dir . 'assets/codemirror/mode/javascript/javascript.js',
271 array('cf7-codemirror-js'), $this->version, true
272 );
273 wp_enqueue_script( 'codemirror-xml-js',
274 $plugin_dir . 'assets/codemirror/mode/xml/xml.js',
275 array('cf7-codemirror-js'), $this->version, true
276 );
277 wp_enqueue_script( 'codemirror-css-js',
278 $plugin_dir . 'assets/codemirror/mode/css/css.js',
279 array('cf7-codemirror-js'), $this->version, true
280 );
281 //overlay for shortcode highligh
282 wp_enqueue_script( 'codemirror-overlay-js',
283 $plugin_dir . 'assets/codemirror/addon/mode/overlay.js',
284 array('cf7-codemirror-js'), $this->version, true
285 );
286 /**
287 * @since 1.3.0 enable search codemirror
288 */
289 //overlay for shortcode highligh
290 wp_enqueue_script( 'codemirror-search-js',
291 $plugin_dir . 'assets/codemirror/addon/search/search.js',
292 array('cf7-codemirror-js'), $this->version, true
293 );
294 wp_enqueue_script( 'codemirror-jumptoline-js',
295 $plugin_dir . 'assets/codemirror/addon/search/jump-to-line.js',
296 array('cf7-codemirror-js'), $this->version, true
297 );
298 wp_enqueue_script( 'codemirror-matchesonscrollbar-js',
299 $plugin_dir . 'assets/codemirror/addon/search/matchesonscrollbar.js',
300 array('cf7-codemirror-js'), $this->version, true
301 );
302 wp_enqueue_script( 'codemirror-searchcursor-js',
303 $plugin_dir . 'assets/codemirror/addon/search/searchcursor.js',
304 array('cf7-codemirror-js'), $this->version, true
305 );
306 wp_enqueue_script( 'codemirror-annotatescrollbar-js',
307 $plugin_dir . 'assets/codemirror/addon/scroll/annotatescrollbar.js',
308 array('cf7-codemirror-js'), $this->version, true
309 );
310 wp_enqueue_script( 'codemirror-dialog-js',
311 $plugin_dir . 'assets/codemirror/addon/dialog/dialog.js',
312 array('cf7-codemirror-js'), $this->version, true
313 );
314
315 //js beautify
316 wp_enqueue_script( 'beautify-js',
317 $plugin_dir . 'assets/beautify/beautify.js',
318 array('jquery'), $this->version, true
319 );
320 wp_enqueue_script( 'beautify-html-js',
321 $plugin_dir . 'assets/beautify/beautify-html.js',
322 array('beautify-js'), $this->version, true
323 );
324 wp_enqueue_script('jquery-select2', $plugin_dir . 'assets/select2/js/select2.min.js', array( 'jquery' ), $this->version, true );
325 /** @since 4.0 enable dark theme */
326 $cm_light = apply_filters('cf7sg_admin_editor_theme', '');
327 $user_theme = get_user_meta(get_current_user_id(),'_cf7sg_cm_theme', true);
328 if(!empty($cm_light) && file_exists(get_stylesheet_directory().'/'.$cm_light) ){
329 wp_enqueue_style( "codemirror-theme-css", get_stylesheet_directory_uri().'/'.$cm_light, array(), $this->version, 'all' );
330 $user_theme = basename($cm_light, '.css');
331 update_user_meta(get_current_user_id(),'_cf7sg_cm_theme', '');
332 }else{
333 if(empty($user_theme)){
334 $user_theme = 'paraiso-light';
335 update_user_meta(get_current_user_id(),'_cf7sg_cm_theme', 'light');
336 }else{
337 $user_theme = ('light'==$user_theme ? 'paraiso-light' : 'material-ocean');
338 }
339 }
340 $cm_js_light = apply_filters('cf7sg_admin_js_editor_theme', '');
341 $user_js_theme = get_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', true);
342 if(!empty($cm_js_light) && file_exists(get_stylesheet_directory().'/'.$cm_js_light) ){
343 wp_enqueue_style( "codemirror-js-theme-css", get_stylesheet_directory_uri().'/'.$cm_js_light, array(), $this->version, 'all' );
344 $user_js_theme = basename($cm_js_light, '.css');
345 update_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', '');
346 }else{
347 if(empty($user_js_theme)){
348 $user_js_theme = 'paraiso-light';
349 update_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', 'light');
350 }else{
351 $user_js_theme = ('light'==$user_js_theme ? 'paraiso-light' : 'material-ocean');
352 }
353 }
354 $cm_css_light = apply_filters('cf7sg_admin_css_editor_theme', '');
355 $user_css_theme = get_user_meta(get_current_user_id(),'_cf7sg_css_cm_theme', true);
356 if(!empty($cm_css_light) && file_exists(get_stylesheet_directory().'/'.$cm_css_light) ){
357 wp_enqueue_style( "codemirror-css-theme-css", get_stylesheet_directory_uri().'/'.$cm_css_light, array(), $this->version, 'all' );
358 $user_css_theme = basename($cm_css_light, '.css');
359 update_user_meta(get_current_user_id(),'_cf7sg_css_cm_theme', '');
360 }else{
361 if(empty($user_css_theme)){
362 $user_css_theme = 'paraiso-light';
363 update_user_meta(get_current_user_id(),'_cf7sg_css_cm_theme', 'light');
364 }else{
365 $user_css_theme = ('light'==$user_css_theme ? 'paraiso-light' : 'material-ocean');
366 }
367 }
368 //enqueue the cf7 scripts.
369 /** @since 4.11.5 force loading of current form for cf7 plugin error handling */
370 if('auto-draft'!=$post->post_status) WPCF7_ContactForm::get_instance($post);
371 wpcf7_admin_enqueue_scripts( 'wpcf7' );
372 wp_enqueue_script('jquery-clibboard', $plugin_dir . 'assets/clipboard/clipboard.min.js', array('jquery'),$this->version,true);
373 wp_enqueue_script( 'cf7-grid-codemirror-js', $plugin_dir . 'admin/js/cf7-grid-codemirror.js', array( 'jquery', 'jquery-ui-tabs', 'cf7-codemirror-js' ), $this->version, true );
374 wp_localize_script(
375 'cf7-grid-codemirror-js',
376 'cf7sgeditor',
377 array(
378 'mode' => 'shortcode',
379 'theme' => array(
380 'light'=>'paraiso-light',
381 'dark'=>'material-ocean',
382 'user'=>$user_theme
383 ),
384 'jstheme' => array(
385 'light'=>'paraiso-light',
386 'dark'=>'material-ocean',
387 'user'=>$user_js_theme
388 ),
389 'csstheme' => array(
390 'light'=>'paraiso-light',
391 'dark'=>'material-ocean',
392 'user'=>$user_css_theme
393 ),
394 'jserror'=>__('There is a <strong>Javascript error on the page</strong> which prevents the editor from loading properly.', 'cf7-grid-layout'),
395 'fixhtmlform'=>__('The editor failed to load. You may recover your form by copying it into a new form editor, do you wish to continue?', 'cf7-grid-layout'),
396 )
397 );
398 global $post;
399
400 wp_enqueue_script( $this->plugin_name, $plugin_dir . 'admin/js/cf7-grid-layout-admin.js', array('cf7-grid-codemirror-js', 'jquery-ui-sortable' ), $this->version, true );
401 /** @since 4.11.0 abstract out dynamic lists */
402 do_action('cf7sg_register_dynamic_lists');
403 $lists = cf7sg_get_dynamic_lists();
404 wp_localize_script(
405 $this->plugin_name,
406 'cf7grid',
407 array(
408 'preHTML' => apply_filters('cf7sg_pre_cf7_field_html', '<div class="field"><label></label>', $post->post_name),
409 'postHTML' => apply_filters('cf7sg_post_cf7_field_html', '<p class="info-tip"></p></div>', $post->post_name),
410 'requiredHTML' => apply_filters('cf7sg_required_cf7_field_html', '<em>*</em>', $post->post_name),
411 'ui' => apply_filters('cf7sg_grid_ui', true, $post->post_name),
412 'dynamicTags' => array_keys($lists)
413 )
414 );
415 wp_enqueue_script( 'cf7sg-dynamic-tag-js', $plugin_dir . 'admin/js/cf7sg-dynamic-tag.js', array('jquery','wpcf7-admin-taggenerator' ), $this->version, true );
416 wp_enqueue_script( 'cf7sg-dynamic-checkbox-js', $plugin_dir . 'admin/js/cf7sg-dynamic-checkbox.js', array('jquery','wpcf7-admin-taggenerator' ), $this->version, true );
417 wp_enqueue_script( 'cf7sg-dynamic-select-js', $plugin_dir . 'admin/js/cf7sg-dynamic-select.js', array('jquery','wpcf7-admin-taggenerator' ), $this->version, true );
418 wp_enqueue_script( 'cf7-benchmark-tag-js', $plugin_dir . 'admin/js/cf7-benchmark-tag.js', array('jquery','wpcf7-admin-taggenerator' ), $this->version, true );
419 /** @since 3.2.0 */
420 wp_enqueue_script('cf7sg-mail-tag-js', $plugin_dir.'admin/js/mail-tag-helper.js', array('jquery','jquery-clibboard'));
421 wp_localize_script('cf7sg-mail-tag-js','mailTagHelper',
422 array(
423 'msg'=>__('Click to copy!','cf7-grid-layout'),
424 'filter'=> __('Filter mailTag %s', 'cf7-grid-layout')
425 )
426 );
427 /** @since 3.3.0 enqueue ui-grid helpers js */
428 wp_enqueue_script('ui-grid-helpers-js', $plugin_dir.'admin/js/ui-custom-helper.js', array('jquery'));
429 do_action('cf7sg_enqueue_admin_editor_scripts');
430
431 break;
432 case 'edit':
433 //wp_enqueue_script( $this->plugin_name.'-quick-edit', plugin_dir_url( __FILE__ ) . 'js/cf7-grid-layout-quick-edit.js', false, $this->version, true );
434 /** @since 4.4.0 Enabled user script enqueue */
435 do_action('cf7sg_enqueue_admin_table_scripts');
436 break;
437 }
438 }
439
440 /**
441 * Adds a new sub-menu to replace the 'Add New' CF7 menu
442 * Add a new sub-menu to the Contact main menu, as well as remove the current default
443 *
444 */
445 public function add_cf7_sub_menu(){
446
447 $hook = add_submenu_page(
448 'wpcf7',
449 __cf7sg( 'Edit Contact Form'),
450 __cf7sg( 'Add New'),
451 'wpcf7_edit_contact_forms',
452 'post-new.php?post_type=wpcf7_contact_form'
453 );
454 //initial cf7 object when creating new form
455 //add_action( 'load-' . $hook, array($this, 'setup_cf7_object'));
456 //remove_submenu_page( $menu_slug, $submenu_slug );
457 remove_submenu_page( 'wpcf7', 'wpcf7-new' );
458 remove_meta_box('slugdiv', $this->cf7_post_type(), 'normal');
459 }
460 /**
461 * Change the submenu order
462 * @since 1.0.0
463 */
464 public function change_cf7_submenu_order( $menu_ord ) {
465 global $submenu;
466 // Enable the next line to see all menu orders
467 if(!isset($submenu['wpcf7']) ){
468 return $menu_ord;
469 }
470 if( is_network_admin() ){
471 return $menu_ord;
472 }
473 $arr = array();
474 foreach($submenu['wpcf7'] as $menu){
475 switch($menu[2]){
476 case 'post-new.php?post_type=wpcf7_contact_form':
477 //push to the front
478 array_unshift($arr, $menu);
479 break;
480 default:
481 $arr[]=$menu;
482 break;
483 }
484 }
485 $submenu['wpcf7'] = $arr;
486 return $menu_ord;
487 }
488 /**
489 * Modify the regsitered cf7 post tppe
490 * THis function enables public capability and amind UI visibility for the cf7 post type. Hooked late on `register_post_type_args`
491 * @since 1.0.0
492 * @param Array $args array of post parameters being registered
493 * @param String $post_type post type breing resgistered
494 */
495
496 public function modify_cf7_post_type_args($args, $post_type){
497 if($post_type === $this->cf7_post_type() ) {
498 // debug_msg($args, 'pre-args');
499 // $system_dropdowns = get_option('_cf7sg_dynamic_dropdown_system_taxonomy',array());
500 /** @since 2.8.3 add wpcf7_type (registered in assets/cf7-table.php) taxonomy to cf7 post type */
501 $system_taxonomy = array('wpcf7_type');
502 // if(!empty($system_dropdowns)){
503 // foreach($system_dropdowns as $id=>$list){
504 // $system_taxonomy = array_merge($system_taxonomy, $list);
505 // }
506 // }
507 if(!empty($args['taxonomies'])){
508 $system_taxonomy = array_merge($args['taxonomies'], $system_taxonomy);
509 $system_taxonomy = array_unique($system_taxonomy);
510 }
511 $args['taxonomies'] = $system_taxonomy;
512
513 $args['public'] = false;
514 $args['show_ui']= true;
515 $args['show_in_menu']= 'wpcf7';
516 $args['supports'] = array('title', 'author');
517 $args['labels']['add_new_item'] = 'Add New Form';
518 $args['labels']['edit_item'] = 'Edit Form';
519 $args['labels']['new_item'] = 'New Form';
520 $args['labels']['view_item'] = 'View Form';
521 $args['labels']['view_items'] = 'View Forms';
522 $args['labels']['search_items'] = 'Search Forms';
523 $args['labels']['not_found'] = 'No forms found.';
524 $args['labels']['not_found_in_trash'] = 'No forms found in Trash.';
525 $args['labels']['parent_item_colon'] = '';
526 $args['labels']['attributes'] = 'Form Attributes';
527 $args['labels']['insert_into_item'] = 'Insert into form';
528 $args['labels']['uploaded_to_this_item'] = 'Uploaded to this form';
529 $args['labels']['filter_items_list'] = 'Filter forms list';
530 $args['labels']['items_list_navigation'] = 'Forms list navigation';
531 $args['labels']['items_list'] = 'Forms list';
532 /** @since 2.8.1 fix missing delete_posts notices*/
533 // $args['capabilities']['delete_posts']= 'wpcf7_delete_posts';
534 /** @since 3.0.0 enable better capability management */
535 // $args['capability_type'] = 'page';
536
537 $args['map_meta_cap']=true; //allow finer capability mapping.
538 $args['capabilities']['edit_post'] = 'wpcf7_edit_contact_form';
539 $args['capabilities']['read_post'] = 'wpcf7_read_contact_form';
540 $args['capabilities']['delete_post'] = 'wpcf7_delete_contact_form';
541 $args['capabilities']['edit_posts'] = 'wpcf7_edit_contact_forms';
542 $args['capabilities']['edit_others_posts']= 'wpcf7_edit_others_contact_forms';
543 $args['capabilities']['edit_published_posts']= 'wpcf7_edit_published_contact_forms';
544 $args['capabilities']['delete_posts']= 'wpcf7_delete_contact_forms';
545 $args['capabilities']['delete_published_posts']= 'wpcf7_delete_published_contact_forms';
546 $args['capabilities']['delete_others_posts']= 'wpcf7_delete_others_contact_forms';
547 $args['capabilities']['publish_posts']= 'wpcf7_publish_contact_forms';
548 $args['capabilities']['read_private_posts']= 'wpcf7_publish_contact_forms';
549
550 // debug_msg($args);
551 }
552 return $args;
553 }
554 /**
555 * Register custom taxonomy for dynamic dropdown lists
556 * Hooked on 'init'
557 * @since 1.0.0
558 *
559 **/
560 public function register_dynamic_dropdown_taxonomy(){
561 //register the dynamic dropdown taxonomies.
562 $dropdowns = get_option('_cf7sg_dynamic_dropdown_taxonomy',array());
563 $created = array();
564 foreach($dropdowns as $post_id=>$post_lists){
565 foreach($post_lists as $slug=>$taxonomy){
566 if(!isset($created[$slug])){
567 if(is_array($taxonomy)){
568 $this->register_dynamic_dropdown($taxonomy);
569 $created[$slug] = $slug;
570 }
571 }
572 }
573 }
574 /** @since 5.0 register dynamic_select list */
575 do_action('cf7sg_register_dynamic_lists');
576 // debug_msg('created dynamic select ');
577 }
578 /**
579 * function to regsiter dyanmic dropdown taxonomies
580 *
581 * @since 1.0.0
582 * @param Object $taxonomy_object std object with parameters $taxonomy_object->slug, $taxonomy_object->singular, $taxonomy_object->plural, $taxonomy_object->hierarchical .
583 **/
584 protected function register_dynamic_dropdown($taxonomy_array){
585 $slug = $taxonomy_array['slug'];
586 $name = $taxonomy_array['singular'];
587 $plural = $taxonomy_array['plural'];
588 $is_hierarchical = $taxonomy_array['hierarchical'];
589
590 $labels = array(
591 'name' => $plural,
592 'singular_name' => $name,
593 'menu_name' => $plural,
594 'all_items' => 'All '.$plural,
595 'parent_item' => 'Parent '.$name,
596 'parent_item_colon' => 'Parent '.$name.':',
597 'new_item_name' => 'New '.$name.' Name',
598 'add_new_item' => 'Add New '.$name,
599 'edit_item' => 'Edit '.$name,
600 'update_item' => 'Update '.$name,
601 'view_item' => 'View '.$name,
602 'separate_items_with_commas' => 'Separate '.$plural.' with commas',
603 'add_or_remove_items' => 'Add or remove '.$plural,
604 'choose_from_most_used' => 'Choose from the most used',
605 'popular_items' => 'Popular '.$plural,
606 'search_items' => 'Search '.$plural,
607 'not_found' => 'Not Found',
608 'no_terms' => 'No '.$plural,
609 'items_list' => $plural.' list',
610 'items_list_navigation' => $plural.' list navigation',
611 );
612 //labels can be modified post registration
613 $args = array(
614 'labels' => $labels,
615 'hierarchical' => $is_hierarchical,
616 'public' => false,
617 'show_ui' => true,
618 'show_admin_column' => false,
619 'show_in_nav_menus' => false,
620 'show_tagcloud' => false,
621 'show_in_quick_edit' => false,
622 'description' => 'Contact Form 7 dynamic dropdown taxonomy list',
623 );
624
625 register_taxonomy( $slug, $this->cf7_post_type(), $args );
626 }
627 /**
628 * CF7 Form saved from backend, check if dynamic lists are used
629 * Hooked on 'wpcf7_save_contact_form'
630 * @since 1.0.0
631 * @param WPCF7_Contact_Form $cf7_form cf7 form object
632 */
633 public function save_factory_metas($cf7_form){
634 $cf7_post_id = $cf7_form->id();
635 //get the tags used in this form
636 $tags = $cf7_form->scan_form_tags(); //get your form tags
637 $dynamic_lists = cf7sg_get_dynamic_lists();
638 $dynamic_tags = array_keys($dynamic_lists);
639 $dynamic_fields = array();
640 $form_classes = array();
641 foreach($tags as $tag){
642 if(in_array($tag->basetype, $dynamic_tags)){
643 $dynamic_fields[$tag->basetype]=$tag;
644 $form_classes = array_merge($form_classes, $dynamic_lists[$tag->basetype]->get_form_classes($tag, $cf7_post_id));
645 }
646 }
647 if(!empty($form_classes)){
648 $classes = get_post_meta($cf7_post_id, '_cf7sg_script_classes', true);
649 if(empty($classes)){
650 $classes = array();
651 }
652 $form_classes = array_diff(array_unique($form_classes), $classes); //any new classes?
653 if(!empty($form_classes)) {
654 update_post_meta($cf7_post_id, '_cf7sg_script_classes', array_merge($classes, $form_classes));
655 }
656 }
657 //check for newly created taxonomy lists.
658 if( isset($_POST['cf72post_dynamic_select_taxonomies']) ){
659 $created_taxonomies = array();
660 $taxonomies = json_decode(str_replace('\"','"',$_POST['cf72post_dynamic_select_taxonomies']), true);
661 if(empty($taxonomies)){
662 $taxonomies = array();
663 }
664 foreach($taxonomies as $taxonomy){
665 //sanitize fields before saving into the DB.
666 foreach($taxonomy as $key=>$value){
667 $key = sanitize_key($key);
668 $taxonomy[$key] = sanitize_text_field($value);
669 }
670 $created_taxonomies[$taxonomy['slug']] = $taxonomy;
671 }
672 // debug_msg($created_taxonomies, 'created ');
673 $post_lists = $saved_lists = $system_list = array();
674
675 $dropdowns = get_option('_cf7sg_dynamic_dropdown_taxonomy',array());
676 foreach($dropdowns as $id => $lists){
677 $saved_lists = array_merge($saved_lists, $lists);
678 }
679 // debug_msg($dynamic_fields, 'dynamic ');
680 foreach($dynamic_fields as $tag){
681 if(isset($tag['values'])){
682 $slug='';
683 foreach($tag['values'] as $values){
684 if(0 == strpos($values, 'slug:') ){
685 $slug = str_replace('slug:', '', $values);
686 break;
687 }
688 }
689 if(empty($slug)) continue; //not a taxonomy list.
690 //is slug newly created?
691 if(isset($created_taxonomies[$slug])){
692 //store this taxonomy.
693 $post_lists[$slug] = $created_taxonomies[$slug];
694 }else if(isset($saved_lists[$slug])){
695 //retain previously saved list if we are stil using it.
696 $post_lists[$slug] = $saved_lists[$slug];
697 }else{ //system taxonomy.
698 $system_list[] = $slug;
699 }
700 //store the taxonomy slug in the cf7 metas.
701 //$post_lists[$slug] = null;
702 }
703 }
704 // debug_msg($post_lists,' post lists ');
705 //list of taxonomy to register.
706 //unset the old value.
707 if(isset($dropdowns[$cf7_post_id])) unset($dropdowns[$cf7_post_id]);
708 //unshift new value to top of array.
709 $dropdowns[$cf7_post_id] = $post_lists;
710 update_option('_cf7sg_dynamic_dropdown_taxonomy', $dropdowns);
711 //list of system taxonomy to register
712 $system_dropdowns = get_option('_cf7sg_dynamic_dropdown_system_taxonomy',array());
713 $system_dropdowns[$cf7_post_id] = $system_list;
714 update_option('_cf7sg_dynamic_dropdown_system_taxonomy', $system_dropdowns);
715 }
716 }
717 /**
718 * Print hiddend field on cf7 post submit box
719 * Hooked on 'wpcf7_admin_misc_pub_section'
720 * @since 1.0.0
721 * @param string $post_id cf7 form post id .
722 **/
723 public function dynamic_select_choices($post_id){
724 echo '<input id="cf72post-dynamic-select" type="hidden" name="cf72post_dynamic_select_taxonomies" />';
725 }
726
727 /**
728 * Hide the cf7 form editor page author metabox by default.
729 * hooked to 'hidden_meta_boxes'.
730 *@since 4.6.0
731 *@param Array $hidden array of hidden metabox ids.
732 *@param WP_Screen $screen current amdin page screen object.
733 *@param Boolean $use_defaults wether default settings used.
734 *@return Array array of hidden metabox ids.
735 */
736 public function hide_author_metabox($hidden, $screen, $use_defaults){
737 if( 'wpcf7_contact_form' != $screen->id ) return $hidden;
738
739 if(in_array('authordiv', $hidden)) return $hidden;
740
741 if($use_defaults) $hidden[] = 'authordiv';
742 else {
743 $gs = get_option(self::CF7SG_OPTION, array());
744
745 if(!isset($gs['hide_author'])){
746 $gs['hide_author']=true; //flag it.
747 $uo = get_user_option('metaboxhidden_wpcf7_contact_form');
748 if(false === $uo) $uo = array();
749 $uo = array_unique( array_merge( $uo + array( 'authordiv' ) ) );
750 $hidden = array_unique( array_merge( $hidden + array( 'authordiv' ) ) );
751 update_option(self::CF7SG_OPTION,$gs);
752 update_user_option( get_current_user_id(), 'metaboxhidden_wpcf7_contact_form', $uo);
753 }
754 }
755 return $hidden;
756 }
757 /**
758 * Function to add the metabox to the cf7 post edit screen
759 * This adds the main editor, hooked on 'add_meta_boxes'
760 * @since 1.0.0
761 */
762 public function edit_page_metabox() {
763 //add_meta_box( string $id, string $title, callable $callback, string $screen, string $context, string $priority, array $callback_args)
764 if( post_type_exists( $this->cf7_post_type() ) ) {
765 add_meta_box( 'meta-box-main-cf7-editor',
766 __cf7sg( 'Edit Contact Form' ),
767 array($this , 'main_editor_metabox_display'),
768 $this->cf7_post_type(),
769 'normal',
770 'high'
771 );
772 add_meta_box( 'meta-box-cf7-info',
773 __cf7sg( 'Information' ),
774 array($this , 'info_metabox_display'),
775 $this->cf7_post_type(),
776 'side',
777 'high'
778 );
779 /** @since 1.1.0 add helper metabox */
780 add_meta_box( 'meta-box-cf7sg-helper',
781 __( 'Actions & Filters', 'cf7-grid-layout' ),
782 array($this , 'helper_metabox_display'),
783 $this->cf7_post_type(),
784 'side',
785 'default'
786 );
787 /** @since 4.6.0 enable page redirect */
788 add_meta_box(
789 'cf7sg-redirect', // Unique ID
790 'Redirect on Submission', // Box title
791 array($this, 'display_rediect_metabox'), // Content callback, must be of type callable
792 $this->cf7_post_type() // Post type
793 );
794 }
795 }
796 /**
797 * Callback function to disolay the main editor meta box
798 * @since 1.0.0
799 */
800 public function main_editor_metabox_display($post){
801 $post_id = $post->ID;
802 if('auto-draft' !== $post->post_status){
803 wpcf7_contact_form($post); //set the post
804 }
805 $cf7_form = wpcf7_get_current_contact_form();
806 if ( ! $cf7_form ) {
807 $args = apply_filters('cf7sg_new_cf7_form_template_arguments', array());
808 $cf7_form = WPCF7_ContactForm::get_template($args);
809 }
810 require_once WPCF7_PLUGIN_DIR . '/admin/includes/editor.php';
811 require_once plugin_dir_path( __FILE__ ) . 'partials/cf7-admin-editor-display.php';
812 }
813
814 /**
815 * Re-introduces the wordpress 'wpcf7_admin_misc_pub_section' for plugins to add their fields for submission
816 * Hooked to 'post_submitbox_misc_actions' which fires after post dat/time parameters are printed
817 * @since 1.0.0
818 * @param WP_Post $post post object being edited/created.
819 **/
820 public function cf7_post_submit_action($post){
821 if($this->cf7_post_type() == $post->post_type){
822 do_action( 'wpcf7_admin_misc_pub_section', $post->ID );
823 }
824 }
825 /**
826 * Callback function to disolay the main editor meta box
827 * @since 1.0.0
828 */
829 public function info_metabox_display($post){
830 require_once plugin_dir_path( __FILE__ ) . 'partials/cf7-info-metabox-display.php';
831 }
832 /**
833 * Callback function to disolay the helper meta box
834 * @since 1.0.0
835 */
836 public function helper_metabox_display($post){
837 require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-helper-metabox-display.php';
838 }
839 /**
840 * Display the editor panels (wpcf7 / codemirror / grid)
841 *
842 * @since 1.0.0
843 * @param WPCF7_Contact_Form $form_post .
844 **/
845 public function grid_editor_panel($form_post){
846 require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-grid-layout-admin-display.php';
847 }
848 /**
849 *
850 *
851 *@since 4.6.0
852 *@param string $param text_description
853 *@return string text_description
854 */
855 public function display_rediect_metabox($post){
856 require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-redirect-metabox-display.php';
857 }
858 /**
859 * Clean up post meta, delete sgcf7 corresponding view post.
860 * Hooked to action 'before_delete_post'.
861 *@since 4.3.0
862 *@param int $post_id post ID.
863 *@param WP_Post post object.
864 */
865 public function delete_post($post_id){
866 if(get_post_type($post_id) != WPCF7_ContactForm::post_type) return;
867 //remove viewing post.
868 $preview_id = get_post_meta($post_id, '_cf7sg_form_page',true);
869 if(!empty($preview_id)) wp_delete_post($preview_id);
870 /** @since 4.12.5 delete custom css/js files */
871 $p = get_post($post_id);
872 $path = get_stylesheet_directory();
873 if(realpath("$path/js/{$p->post_name}.js")) unlink( "$path/js/{$p->post_name}.js" );
874 if(realpath("$path/css/{$p->post_name}.css")) unlink( "$path/css/{$p->post_name}.css" );
875 }
876 /**
877 * Bookeeping on trashed posts.
878 * hooked to 'trashed_post'
879 *@since 4.12.5
880 *@param String $post_id
881 */
882 public function form_trashed($post_id){
883 if(get_post_type($post_id) != WPCF7_ContactForm::post_type) return;
884 $p = get_post($post_id);
885 $prev = get_post_meta($post_id, '_wp_desired_post_slug', true);
886 $path = get_stylesheet_directory();
887 if(realpath("$path/js/{$prev}.js")){ //rename file
888 rename( "$path/js/{$prev}.js" , "$path/js/{$p->post_name}.js" );
889 }
890 if(realpath("$path/css/{$prev}.css")){
891 rename( "$path/css/{$prev}.css" , "$path/css/{$p->post_name}.css" );
892 }
893 }
894 /**
895 * Bookeeping on trashed posts.
896 * hooked to 'trashed_post'
897 *@since 4.12.5
898 *@param String $post_id
899 */
900 public function form_untrashed($post_id){
901 if(get_post_type($post_id) != WPCF7_ContactForm::post_type) return;
902 $p = get_post($post_id);
903
904 $path = get_stylesheet_directory();
905 if(realpath("$path/js/{$p->post_name}__trashed.js")){ //rename file
906 rename( "$path/js/{$p->post_name}__trashed.js" , "$path/js/{$p->post_name}.js" );
907 }
908 if(realpath("$path/css/{$p->post_name}__trashed.css")){
909 rename( "$path/css/{$p->post_name}__trashed.css" , "$path/css/{$p->post_name}.css" );
910 }
911 }
912 /**
913 * Save cf7 post using ajax
914 * Hooked to 'save_post_wpcf7_contact_form'
915 * @since 1.0.0
916 **/
917 public function save_post($post_id, $post, $update){
918 //make sure this is the edit page and not a quick-edit.
919 if( !isset($_POST['_wpcf7nonce']) ){
920 return;
921 }
922 //validate the nonce.
923 check_admin_referer( 'wpcf7-save-contact-form_' . $post_id, '_wpcf7nonce');
924
925 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){
926 return;
927 }
928
929 switch($post->post_status){
930 case 'auto-draft':
931 case 'trash':
932 return;
933 default:
934 break;
935 }
936
937 // debug_msg($_POST, 'submitted ');
938 $args = $_REQUEST;
939 $args['id'] = $post_id;
940
941 $args['title'] = isset( $_POST['post_title'] ) ? sanitize_text_field($_POST['post_title'], 'Contact Form', 'save') : null;
942 $args['locale'] = isset( $_POST['wpcf7-locale'] ) ? sanitize_text_field($_POST['wpcf7-locale']) : null;
943 $args['form'] = '';
944 $allowed_tags = wp_kses_allowed_html( 'post' ); //filtered in function below.
945 /** @since 4.8.1 alllow custom input html*/
946 $allowed_tags['input']=array( //add additional input html elements
947 'type'=>1,'name'=>1,'placeholder'=>1,'value'=>1,'maxlength'=>1,'minlength'=>1, //input fields.
948 'spellcheck'=>1,'size'=>1,'readonly'=>1,'pattern'=>1,'list'=>1, //input fields.
949 'class'=>1,
950 'id'=>1,
951 'data-*'=>1,
952 );
953 $allowed_tags['script']=array('type'=>1);
954 $cf7_key = $post->post_name;
955 $allowed_tags = apply_filters('cf7sg_kses_allowed_html',$allowed_tags, $cf7_key);
956 if(isset( $_POST['wpcf7-form'] )){
957 $args['form'] = wp_kses($_POST['wpcf7-form'], $allowed_tags);
958 }
959 $args['mail'] = isset( $_POST['wpcf7-mail'] ) ? wpcf7_sanitize_mail( $_POST['wpcf7-mail'] ): array();
960 $args['mail_2'] = isset( $_POST['wpcf7-mail-2'] ) ? wpcf7_sanitize_mail( $_POST['wpcf7-mail-2'] ): array();
961 $args['messages'] = isset( $_POST['wpcf7-messages'] ) ? $_POST['wpcf7-messages'] : array();
962 foreach($args['messages'] as $key=>$value){
963 $args['messages'][$key] = sanitize_text_field($value);
964 }
965 $args['additional_settings'] = isset( $_POST['wpcf7-additional-settings'] ) ? sanitize_textarea_field($_POST['wpcf7-additional-settings']) : '';
966
967
968 //save sub-forms if any
969 $sub_forms = json_decode(stripslashes($_POST['cf7sg-embeded-forms']));
970 if(empty($sub_forms)) $sub_forms = array();
971 if(!is_array($sub_forms)) $sub_forms = array($sub_forms);
972 $sanitised_sub_forms = array();
973 foreach($sub_forms as $field){
974 $sanitised_sub_forms[] = sanitize_text_field($field);
975 }
976 update_post_meta($post_id, '_cf7sg_sub_forms', $sanitised_sub_forms);
977 //save form fields which are in tabs or tables.
978 $tt_fields = json_decode(stripslashes($_POST['cf7sg-table-fields']));
979 if(empty($tt_fields)) $tt_fields = array();
980 if(!is_array($tt_fields)) $tt_fields = array($tt_fields);
981 $sanitised_table_fields = array();
982 foreach($tt_fields as $table_fields){
983 if(is_object($table_fields)){ /** @since 2.4.2 track fields in each tables. */
984 $table_fields = get_object_vars($table_fields); /*convert to array*/
985 $table = array_keys($table_fields);
986 $table = sanitize_text_field($table[0]);
987 $table_fields = $table_fields[$table];
988 $sanitised_table_fields[$table]=array();
989 foreach($table_fields as $field) $sanitised_table_fields[$table][] = sanitize_text_field($field);
990 }else $sanitised_table_fields[] = sanitize_text_field($table_fields);
991 }
992 update_post_meta($post_id, '_cf7sg_grid_table_names', $sanitised_table_fields);
993 //tabs
994 $tt_fields = json_decode(stripslashes($_POST['cf7sg-tabs-fields']));
995 if(empty($tt_fields)) $tt_fields = array();
996 if(!is_array($tt_fields)) $tt_fields = array($tt_fields);
997 $sanitised_tab_fields = array();
998 foreach($tt_fields as $tab_field){
999 if(is_object($tab_field)){ /** @since 2.4.2 track fields in each tabs. */
1000 $tab_field = get_object_vars($tab_field); /*convert to array*/
1001 $tab = array_keys($tab_field);
1002 $tab = sanitize_text_field($tab[0]);
1003 $tab_field = $tab_field[$tab];
1004 $sanitised_tab_fields[$tab]=array();
1005 foreach($tab_field as $field) $sanitised_tab_fields[$tab][] = sanitize_text_field($field);
1006 }else $sanitised_tab_fields[] = sanitize_text_field($tab_field);
1007 }
1008 update_post_meta($post_id, '_cf7sg_grid_tabs_names', $sanitised_tab_fields);
1009 /** track toggled fields.
1010 * @since 2.5*/
1011 $tt_fields = json_decode(stripslashes($_POST['cf7sg-toggle-fields']));
1012 if(empty($tt_fields)) $tt_fields = array();
1013 if(!is_array($tt_fields)) $tt_fields = array($tt_fields);
1014 $sanitised_toggled_fields = array();
1015 foreach($tt_fields as $tgg_field){
1016 if(is_object($tgg_field)){
1017 $tgg_field = get_object_vars($tgg_field); /*convert to array*/
1018 $tgg = array_keys($tgg_field);
1019 $tgg = sanitize_text_field($tgg[0]);
1020 $tgg_field = $tgg_field[$tgg];
1021 $sanitised_toggled_fields[$tgg]=array();
1022 foreach($tgg_field as $field) $sanitised_toggled_fields[$tgg][] = sanitize_text_field($field);
1023 }else $sanitised_toggled_fields[] = sanitize_text_field($tgg_field);
1024 }
1025 update_post_meta($post_id, '_cf7sg_grid_toggled_names', $sanitised_toggled_fields);
1026 /** @since 4.0.0 track tabbed toggles */
1027 $ttgls = json_decode(stripslashes($_POST['cf7sg-tabbed-toggles']));
1028 if(empty($ttgls)) $ttgls = array();
1029 if(!is_array($ttgls)) $ttgls = array($ttgls);
1030 update_post_meta($post_id, '_cf7sg_grid_tabbed_toggles', $ttgls);
1031 /** @since 4.0.0 track grouped toggles */
1032 $ttgls = json_decode(stripslashes($_POST['cf7sg-grouped-toggles']));
1033 if(empty($ttgls)) $ttgls = array();
1034 if(is_object($ttgls)) $ttgls = get_object_vars($ttgls); //convert to array.
1035 else $ttgls = array();
1036 update_post_meta($post_id, '_cf7sg_grid_grouped_toggles', $ttgls);
1037 //flag tab & tables for more efficient front-end display.
1038 $has_tabs = ( 'true' === $_POST['cf7sg-has-tabs']) ? true : false;
1039 update_post_meta($post_id, '_cf7sg_has_tabs', $has_tabs);
1040 $has_tables = ( 'true' === $_POST['cf7sg-has-tables']) ? true : false;
1041 update_post_meta($post_id, '_cf7sg_has_tables', $has_tables);
1042 $has_toggles = ( 'true' === $_POST['cf7sg-has-toggles']) ? true : false;
1043 update_post_meta($post_id, '_cf7sg_has_toggles', $has_toggles);
1044
1045 /**
1046 * @since 1.2.3 disable cf7sg styling/js for non-cf7sg forms.
1047 */
1048 $is_cf7sg = ( 'true' === $_POST['is_cf7sg_form']) ? true : false;
1049 update_post_meta($post_id, '_cf7sg_managed_form', $is_cf7sg);
1050 update_post_meta($post_id, '_cf7sg_version', $this->version);
1051 /** @since 3.0.0 track script classes for loading for js/css in front-end */
1052 $classes = sanitize_text_field($_POST['cf7sg-script-classes']);
1053 $classes = explode(',', trim($classes, ','));
1054 // debug_msg($classes, 'script classes');
1055 update_post_meta($post_id, '_cf7sg_script_classes', $classes);
1056 /**
1057 *@since 2.3.0 the duplicate functionality has been instored and therefore any new meta fields added to this plugin needs to be added to the duplication properties too.
1058 */
1059 /** @since 4.0.0 save user theme pref */
1060 if(isset($_POST['cf7sg_codemirror_theme'])){
1061 update_user_meta(get_current_user_id(),'_cf7sg_cm_theme', $_POST['cf7sg_codemirror_theme']);
1062 }
1063 if(isset($_POST['cf7sg_js_codemirror_theme'])){
1064 update_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', $_POST['cf7sg_js_codemirror_theme']);
1065 }
1066 //save js file if used.
1067 $path = get_stylesheet_directory();
1068 if(!empty($_POST['cf7sg_js_file']) || !empty($_POST['cf7sg_prev_js_file'])){
1069 //check if the file name is changed.
1070 if(!empty($_POST['cf7sg_prev_js_file']) && ($fp = realpath(ABSPATH. $_POST['cf7sg_prev_js_file'])) !== false ){
1071 $path_match = preg_match('/^'.preg_quote("$path/js/",'/').'[^\s!?.\/#*]+\.js$'.'/', $fp);
1072 if($path_match && !unlink($fp) ){
1073 debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_js_file']);
1074 }
1075 }
1076 if( !is_dir("$path/js/") ) mkdir("$path/js/");
1077 file_put_contents( "$path/js/{$cf7_key}.js", stripslashes($_POST['cf7sg_js_file']) );
1078 }else if( isset($_POST['cf7sg_js_file']) && file_exists("$path/js/{$cf7_key}.js") ) { //delete file.
1079 if( !unlink("$path/js/{$cf7_key}.js") ) debug_msg("CF7SG ADMIN: unable to delete file $path/js/{$cf7_key}.js");
1080 }
1081 //save css file.
1082 if(!empty($_POST['cf7sg_css_file']) || !empty($_POST['cf7sg_prev_css_file'])){
1083 //check if the file is changed.
1084 if(!empty($_POST['cf7sg_prev_css_file']) && ($fp = realpath(ABSPATH.$_POST['cf7sg_prev_css_file'])) !==false ){
1085 $path_match = preg_match('/^'.preg_quote("$path/css/",'/').'[^\s!?.\/#*]+\.css$'.'/', $fp);
1086 if($path_match && !unlink($fp) ){
1087 debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_css_file']);
1088 }
1089 }
1090 if( !is_dir("$path/css/") ) mkdir("$path/css/");
1091 file_put_contents( $path."/css/{$cf7_key}.css", stripslashes($_POST['cf7sg_css_file']));
1092 }else if( isset($_POST['cf7sg_css_file']) && file_exists("$path/css/{$cf7_key}.css") ) { //delete file.
1093 if( !unlink("$path/css/{$cf7_key}.css") ) debug_msg("CF7SG ADMIN: unable to delete file $path/css/{$cf7_key}.css");
1094 }
1095 //jstags comments.
1096 if(empty($_POST['cf7sg_jstags_comments'])) update_post_meta($post->ID, '_cf7sg_disable_jstags_comments',1);
1097 else update_post_meta($post->ID, '_cf7sg_disable_jstags_comments',0);
1098 /** @since 4.3.0 create/update a preview form post for this form */
1099 $preview_id = get_post_meta($post->ID, '_cf7sg_form_page',true);
1100 $content = '[cf7form cf7key="'.$cf7_key.'"';
1101 $content .= isset($_POST['post_lang_choice']) ? ' lang="'.$_POST['post_lang_choice'].'"]':']';
1102 $prev_page = array(
1103 'post_title'=>sanitize_text_field($_POST['post_title']),
1104 'post_content'=>$content,
1105 'post_status'=>'draft',
1106 'post_type'=>'cf7sg_page',
1107 // 'post_name' => sanitize_title( $title ),
1108 );
1109 /** @since 4.6.0 redirect on submit */
1110 if(isset($_POST['cf7sg_page_redirect'])){
1111 $redirect_to = absint($_POST['cf7sg_page_redirect']);
1112 update_post_meta($post->ID, '_cf7sg_page_redirect',$redirect_to);
1113 if(isset($_POST['cache_cf7sg_submit']) and isset($_POST['cf7sg_cached_time']) and isset($_POST['cf7sg_cached_unit'])){
1114 $cache = floatval( $_POST['cf7sg_cached_time']);
1115 if($cache>0){
1116 $cache=array($cache, absint($_POST['cf7sg_cached_unit']));
1117 update_post_meta($post->ID, '_cf7sg_cache_redirect_data',$cache);
1118 }
1119 }else delete_post_meta($post->ID, '_cf7sg_cache_redirect_data');
1120 }
1121 if(empty($cf7_key)) $prev_page['post_content'] = '[contact-form-7 id="'.$post->ID.'"]';
1122 if( !empty($preview_id) ){
1123 $prev_page['ID'] = $preview_id;
1124 }
1125 $preview_id = wp_insert_post($prev_page, true);
1126 if(!is_wp_error($preview_id)){
1127 update_post_meta($post->ID, '_cf7sg_form_page',$preview_id);
1128 }
1129 //save wpcf7 form
1130 //need to unhook this function so as not to loop infinitely
1131 //debug_msg($args, 'saving cf7 posts');
1132 remove_action('save_post_wpcf7_contact_form', array($this, 'save_post'), 10,3);
1133 // debug_msg($args['form'],'form ');
1134 /** @since 4.11.5 filter wp_kses ffrmo cf7 plugin v5.5 */
1135 add_filter('wpcf7_kses_allowed_html', function($cf7_tags, $context) use ($allowed_tags){
1136 if('form'==$context) return array_merge($cf7_tags, $allowed_tags);
1137 return $cf7_tags;
1138 },1001,2);
1139 $contact_form = wpcf7_save_contact_form( $args );
1140 /** @since 4.11.5 cf7 plugin validate form */
1141 if(function_exists('wpcf7_validate_configuration') &&
1142 method_exists('WPCF7_ConfigValidator','validate') &&
1143 method_exists('WPCF7_ConfigValidator','save') ){
1144 if ( $contact_form and wpcf7_validate_configuration() ) {
1145 $config_validator = new WPCF7_ConfigValidator( $contact_form );
1146 $config_validator->validate();
1147 $config_validator->save();
1148 }
1149 }
1150 add_action('save_post_wpcf7_contact_form', array($this, 'save_post'), 10,3);
1151
1152 /** @since 4.9.2 fire form saving action so as to prevent double save_post hook calls on other plugins */
1153 do_action('cf7sg_save_post',$post_id, $post, $update);
1154 }
1155 /**
1156 * Print default js template,
1157 * Hooked to 'cf7sg_default_custom_js_template'
1158 *@since 4.0.0
1159 *@param string $form_key form key.
1160 */
1161 public function print_default_js($form_key){
1162 $js_file = str_replace(ABSPATH, '', get_stylesheet_directory()."/js/{$form_key}.js");
1163 include_once 'partials/cf7-default-js.php';
1164 }
1165 /**
1166 *
1167 *
1168 *@since 2.3.0
1169 *@param string $new_form_id new form id to duplciate to.
1170 *@param string $form_id form id to duplciate.
1171 */
1172 public function duplicate_form_properties($new_form_id, $form_id){
1173 //these properties will be preceded with an '_' by the cf7 plugin before being duplicated.
1174 $properties = array('_cf7sg_sub_forms', '_cf7sg_grid_table_names', '_cf7sg_grid_tabs_names', '_cf7sg_has_tabs', '_cf7sg_has_tables', '_cf7sg_managed_form','_cf7sg_script_classes', '_cf7sg_version', '_cf7sg_grid_toggled_names', '_cf7sg_grid_tabbed_toggles', '_cf7sg_grid_grouped_toggles', '_cf7sg_has_toggles', '_cf7sg_disable_jstags_comments', '_cf7sg_page_redirect', '_cf7sg_cache_redirect_data');
1175 $properties = apply_filters('cf7sg_duplicate_form_properties', $properties);
1176 foreach($properties as $field){
1177 $value = get_post_meta($form_id, $field, true);
1178 if(!empty($value)) update_post_meta($new_form_id,$field, $value);
1179 }
1180 }
1181 /**
1182 * Duplicate form.
1183 *
1184 *@since 2.3.0
1185 *@return string text_description
1186 */
1187 public function duplicate_cf7_form(){
1188 global $pagenow;
1189 if($pagenow != 'post.php') return;
1190 if(isset($_GET['action']) && 'cf7copy' == $_GET['action']){
1191 $action = 'wpcf7-copy-contact-form_' . $_GET['post'];
1192 if( !wp_verify_nonce( $_GET['_wpnonce'], $action )){
1193 die( 'Security check error: Try to reload the page and try again.' );
1194 }
1195 if ( $form = wpcf7_contact_form( $_GET['post'] ) ) {
1196 $new_form = $form->copy();
1197 $new_form->save();
1198 $this->duplicate_form_properties($new_form->id(), $_GET['post']);
1199 /** @since 4.11 duplicate js/css files */
1200 $new_key = get_cf7form_key($new_form->id());
1201 $key = get_cf7form_key($form->id());
1202 $path = get_stylesheet_directory();
1203 $js_file = "$path/js/{$key}.js";
1204 if( file_exists($js_file) ){
1205 copy($js_file, "$path/js/{$new_key}.js");
1206 }
1207 $css_file = "$path/css/{$key}.css";
1208 if( file_exists($css_file) ){
1209 copy($css_file, "$path/css/{$new_key}.css");
1210 }
1211 wp_safe_redirect( admin_url( '/post.php?post='.$new_form->id().'&action=edit' ));
1212 exit;
1213 }
1214 }
1215 }
1216 /**
1217 * Filtered allowed html tags & attributes, add data-button to div tags to ensure forms are saved properly.
1218 * Hooked on 'wp_kses_allowed_html'
1219 *@since 1.0.0
1220 *@param array $allowed array of allowed tags and attributes.
1221 *@param mixed $context context in which content is filtered.
1222 *@return array allowed tags and ttribtues.
1223 */
1224 public function custom_kses_rules($allowed, $context){
1225 if(is_array($context)){
1226 return $allowed;
1227 }
1228 if('post'===$context){
1229 $allowed['div']['data-button'] = true; //table buttons.
1230 $allowed['div']['data-form'] = true; //sub-forms.
1231 $allowed['div']['data-on'] = true; //toggles.
1232 $allowed['div']['data-off'] = true; //toggles.
1233 $allowed['div']['data-open'] = true; //accordion.
1234 $allowed['div']['data-group'] = true; //accordion.
1235 $allowed['div']['data-config-field'] = true; //cf7 plugin.
1236 }
1237 return $allowed;
1238 }
1239 /**
1240 * Filters the default form loaded when a new CF7 form is created
1241 * Hooked on 'wpcf7_default_template'
1242 * @since 1.0
1243 * @param string $template the html string for the form tempalte
1244 * @param string $prop the template property required.
1245 */
1246 public function default_cf7_form($template, $prop){
1247 if($prop !== 'form') return $template;
1248 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-default-form.php');
1249 return $template;
1250 }
1251 /**
1252 * Ajax function to return the content of a cf7 form
1253 * Hooked on 'wp_ajax_get_cf7_content'
1254 * @since 1.0.0
1255 * @return String cf7 form content.
1256 **/
1257 public function get_cf7_content(){
1258 if( !isset($_POST['nonce']) ){
1259 echo 'error, nonce failed, try to reload the page.';
1260 wp_die();
1261 }
1262 if(!wp_verify_nonce($_POST['nonce'], 'wpcf7-save-contact-form_' . $_POST['id'], '_wpcf7nonce')){
1263 echo 'error, nonce failed, try to reload the page.';
1264 wp_die();
1265 }
1266 $cf7_key = sanitize_text_field($_POST['cf7_key']);
1267 $sub_forms = get_posts(array(
1268 'post_type' => $this->cf7_post_type(),
1269 'post_name__in' => array($cf7_key)
1270 ));
1271 $form='';
1272 if(!empty($sub_forms)){
1273 $form = get_post_meta($sub_forms[0]->ID, '_form', true);
1274 echo $form;
1275 }else{
1276 echo 'unable to find form '.$cf7_key;
1277 }
1278 wp_die();
1279 }
1280 /**
1281 * Adds a [taxonomy] tag to cf7 forms
1282 * Hooked on 'wpcf7_admin_init'
1283 * @since 1.0.0
1284 **/
1285 public function cf7_shortcode_tags(){
1286 if ( class_exists( 'WPCF7_TagGenerator' ) ) {
1287 /** @since 4.10.0 enable extension of dynamic lists */
1288 $tag_generator = WPCF7_TagGenerator::get_instance();
1289 $tag_generator->add(
1290 'benchmark', //tag id
1291 __( 'benchmark', 'cf7_2_post' ), //tag button label
1292 array($this,'benchmark_tag_generator') //callback
1293 );
1294 }
1295 /** @since 4.10.0 abstract out dynamic lists */
1296 do_action('cf7sg_register_dynamic_lists');
1297 $lists = cf7sg_get_dynamic_lists();
1298 foreach($lists as $l) $l->register_cf7_tag();
1299 }
1300
1301 /**
1302 * Benchmark input screen displayt.
1303 *
1304 * This function is called by cf7 plugin, and is registered with a hooked function above
1305 *
1306 * @since 1.0.0
1307 * @param WPCF7_ContactForm $contact_form the cf7 form object
1308 * @param array $args arguments for this form.
1309 */
1310 function benchmark_tag_generator( $contact_form, $args = '' ) {
1311 $args = wp_parse_args( $args, array() );
1312 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-benchmark-tag.php');
1313 }
1314 /**
1315 * Print the dynamic list tag generator form.
1316 * Hooked on 'cf7sg_display_dynamic_list_tag_manager'.
1317 * allows other plugins to customise the tag manager for their own dynamic field.
1318 *@since 4.11.0
1319 *@param String $tag_id dynamic list tag id.
1320 *@param CF7SG_Dynamic_list $dlo dynamic list object.
1321 *@param WPCF7_Contact_Form $form cf7 form object.
1322 *@param Array $args cf7 form shortcode attributes
1323 */
1324 public function print_dynamic_list_generator($tag_id, $dlo, $form, $args){
1325 include plugin_dir_path( __FILE__ ) . 'partials/cf7-dynamic-tag-display.php';
1326 }
1327 /**
1328 * Add custom imagegrid hook to taxonomy source.
1329 * Hooked to 'cf7sg_dynamic_tag_manager_taxonomy_source'
1330 *@since 4.11.0
1331 *@param String $tag_id dynamic list tag id.
1332 */
1333 public function add_taxonomy_imagegrid_hook($tag_id){
1334 if('dynamic_checkbox' != $tag_id) return;
1335 ?>
1336 <p class="imagegrid-filter display-none filter-hook">
1337 <strong><?=__('Filter imagegrid image sources','cf7-grid-layout')?></strong><br />
1338 <?php echo sprintf(__('Copy the following <a class="%s" href="javascript:void(0);">filter</a> to your <em>functions.php</em> file.', 'cf7-grid-layout'), 'cf7sg_filter_taxonomy_images');?>
1339 </p>
1340 <?php
1341 }
1342 /**
1343 * Function to get classes to be added to the form wrapper.
1344 * these classes will be passed in the resource enqueue action, allowing for specific js/css resources
1345 * to be queued up and loaded on the page where the form is being displayed.
1346 * hooked to 'cf7sg_save_dynamic_list_form_classes'
1347 * @param Array array of classes to be added to the form wrapper.
1348 * @param WPCF7_FormTag cf7 tag object for the form field.
1349 * @param int $form_id cf7 fomr post ID..
1350 * @return Array an array of classes to be added to the form to which this tag belonggs to.
1351 */
1352 public function save_dynamic_list_form_classes($form_classes, $tag, $form_id){
1353 /* Bookeeping, set up tagged select2 fields to filter newly added options in case Post My CF7 Form plugin is running */
1354 $class = $tag->get_class_option('');
1355 switch($tag->basetype){
1356 case 'dynamic_select':
1357 if(strpos($class, 'select2')){
1358 $form_classes[] = 'has-select2';
1359 //track this field if user sets custom options.
1360 if(strpos($class, 'tags')){
1361 $tagged_fields = get_post_meta($form_id, '_cf7sg_select2_tagged_fields', true);
1362 if(empty($tagged_fields)){
1363 $tagged_fields = array();
1364 }
1365 if( !isset($tagged_fields[$tag->name]) ){
1366 $tagged_fields[$tag->name] = $source;
1367 update_post_meta($form_id, '_cf7sg_select2_tagged_fields',$tagged_fields);
1368 }
1369 }
1370 }
1371 if(false != strpos($class, 'nice-select') || false !=strpos($class, 'ui-select')){
1372 $form_classes[] = 'has-nice-select';
1373 }
1374 break;
1375 case 'dynamic_checkbox':
1376 switch(true){
1377 case strpos($class, 'hybriddd'):
1378 case strpos($class, 'imagehdd'):
1379 case strpos($class, 'imagegrid'):
1380 case strpos($class, 'treeview'):
1381 $form_classes[] = 'has-hybriddd';
1382 break;
1383 }
1384 break;
1385 }
1386 return $form_classes;
1387 }
1388 /**
1389 * Deactivate this plugin if CF7 plugin is deactivated.
1390 * Hooks on action 'admin_init'
1391 * @since 2.1
1392 */
1393 //public function deactivate_cf7_polylang( $plugin, $network_deactivating ) {
1394 public function check_plugin_dependency() {
1395 //if either the polylang for the cf7 plugin is not active anymore, deactive this extension
1396 if( !is_plugin_active("contact-form-7/wp-contact-form-7.php") ){
1397 deactivate_plugins( "cf7-grid-layout/cf7-grid-layout.php" );
1398 debug_msg("Deactivating Smart Grid");
1399
1400 $button = '<a href="'.network_admin_url('plugins.php').'">Return to Plugins</a></a>';
1401 wp_die( '<p><strong>CF7 smart Grid-layout Extension</strong> requires <strong>Contact Form 7</strong> plugin, and has therefore been deactivated!</p>'.$button );
1402
1403 return false;
1404 }
1405 return true;
1406 }
1407 /**
1408 * Add disabled button message on hover to cf7 messages.
1409 * Hooked to 'wpcf7_messages', see file contact-form-7/includes/contact-form-template.php fn messages().
1410 *@since 2.6.0
1411 *@param array $messages array of messages to filter.
1412 *@return array array of cf7 messages.
1413 */
1414 public function disabled_message($messages){
1415 $messages['submit_disabled'] = array(
1416 'description'
1417 => __( "Hover message for disabled submit/save button", 'cf7-grid-layout' ),
1418 'default'
1419 => __( "Disabled! To enable, check the acceptance field.", 'cf7-grid-layout' ),
1420 );
1421 /** @sicne 2.8.0 */
1422 $messages['max_table_rows'] = array(
1423 'description'
1424 => __( "Message displayed when max tables rows reached.", 'cf7-grid-layout' ),
1425 'default'
1426 => __( "You have reached the maximum number of rows.", 'cf7-grid-layout' ),
1427 );
1428 return $messages;
1429 }
1430 /**
1431 * Adds pretty pointers to help users.
1432 * Hooked on 'admin_enqueue_scripts'
1433 *@since 2.6.0
1434 *@param string $hook_suffix current page.
1435 */
1436 public function pretty_admin_pointers($hook_suffix){
1437 $screen = get_current_screen();
1438 if (!isset($screen) || $this->cf7_post_type() != $screen->post_type || in_array( $hook_suffix, array('post.php', 'post-new.php'), true)){
1439 return;
1440 }
1441 $enqueue_pointer = false;
1442 // Get array list of dismissed pointers for current user and convert it to array
1443 $user_id = get_current_user_id();
1444 $dismissed_pointers = explode( ',', get_user_meta( $user_id, 'dismissed_wp_pointers', true ) );
1445 $pointers = array();
1446 $helpers = array();
1447 /**
1448 * Filter to add custom pointers for user iterface.
1449 * @var array $pointers an array of $pointer_id=>array($content, $arrow, $valign) key/value pairs to filter. The key is the pointer id to identify which ones the user has dismissed. The value is an array with the message $content, the position of the $arrow (left|right|top|bottom), the vertical alignment ($valign) of the box (center|top|bottom).
1450 * @return array an array of pointers, which will be checked agains the current user.
1451 */
1452 $filter_pointers = apply_filters('cf7sg_plugin_pointers-'.$screen->id, array(),$dismissed_pointers);
1453 foreach($filter_pointers as $id=>$pointer){
1454 $enqueue_pointer = true;
1455 if(is_array($pointer)){
1456 $pointers[$id] = array($pointer[0], $pointer[1], $pointer[2], $pointer[3]);
1457 }else $helpers[$id] = $pointer;
1458 }
1459 // Enqueue pointer CSS and JS files, if needed
1460 if( $enqueue_pointer ) {
1461 wp_enqueue_style( 'wp-pointer' );
1462 wp_enqueue_script( 'wp-pointer' );
1463 wp_enqueue_script('cf7sg-pointer-js', plugin_dir_url( __DIR__ ).'admin/js/cf7sg-pointers.js', array('jquery'), $this->version, true);
1464 wp_localize_script('cf7sg-pointer-js', 'cf7sg_pointers',
1465 array(
1466 'pointers'=>$pointers,
1467 'helpers'=>$helpers,
1468 'next'=>__('Next', 'cf7-grid-layout')
1469 )
1470 );
1471 // Add footer scripts using callback function
1472
1473 }
1474 }
1475
1476 /**
1477 * CF7 Table pointer notices.
1478 * Hooked on 'cf7sg_plugin_pointers-edit-wpcf7_contact_form'
1479 *@since 2.6.0
1480 *@param Array $pointers array of pointers to suplement
1481 *@param Array $dismissed array of dismissed pointer ids.
1482 *@return Array array of pointers element-id=>hmtl to display key value pairs.
1483 */
1484 public function edit_pointers($pointers, $dismissed){
1485 ob_start();
1486 /* update forms */
1487 if( !in_array( 'update_forms_pointer', $dismissed ) ) {
1488 include_once 'partials/pointers/cf7sg-pointer-update-forms.php';
1489 $content =ob_get_contents();
1490 $pointers['update_forms_pointer'] = array($content, 'left', 'center','');
1491 ob_clean();
1492 }
1493 /* tutorials */
1494 if( !in_array( 'tutorials_pointer', $dismissed ) ) {
1495 include_once 'partials/pointers/cf7sg-pointer-tutorials.php';
1496 $content =ob_get_contents();
1497 $pointers['tutorials_pointer'] = array($content, 'left', 'center','a[href="admin.php?page=cf7sg_help"]');
1498 ob_clean();
1499 }else if( !in_array( 'new_tutorials_pointer', $dismissed ) ) { /* new tutorials */
1500 include_once 'partials/pointers/cf7sg-pointer-tutorial-advance.php';
1501 $content =ob_get_contents();
1502 $pointers['new_tutorials_pointer'] = array($content, 'left', 'center','a[href="admin.php?page=cf7sg_help"]');
1503 ob_clean();
1504 }
1505 /* shortcodes */
1506 if( !in_array( 'cf7sg_shortcodes', $dismissed ) ) {
1507 include_once 'partials/pointers/cf7sg-pointer-shortcodes.php';
1508 $content = ob_get_contents();
1509 $pointers['cf7sg_shortcodes'] = array($content, 'top', 'top','');
1510 ob_clean();
1511 }
1512 ob_end_clean();
1513 return $pointers;
1514 }
1515 /**
1516 * CF7 Edit pointer notices.
1517 * Hooked on 'cf7sg_plugin_pointers-wpcf7_contact_form'
1518 *@since 2.6.0
1519 *@param Array $pointers array of pointers to suplement
1520 *@param Array $dismissed array of dismissed pointer ids.
1521 *@return Array array of pointers element-id=>hmtl to display key value pairs.
1522 */
1523 public function post_pointers($pointers, $dismissed){
1524 ob_start();
1525 /* full screen button */
1526 if( !in_array( 'full_screen', $dismissed ) ) {
1527 include_once 'partials/pointers/cf7sg-pointer-editor-full-screen.php';
1528 $content =ob_get_contents();
1529 //content / arrow [top,bottom,left,right] / box align [top,bottom,center] / css selector.
1530 $pointers['full_screen'] = array($content, 'left', 'center','#full-screen-cf7');
1531 ob_clean();
1532 }
1533 /* editor_tabs */
1534 if( !in_array( 'editor_tabs', $dismissed ) ) {
1535 include_once 'partials/pointers/cf7sg-pointer-editor-tabs.php';
1536 $content =ob_get_contents();
1537 $pointers['editor_tabs'] = array($content, 'right', 'center','#form-editor-tabs>ul>li.ui-tabs-active');
1538 ob_clean();
1539 }
1540 /* row_controls */
1541 if( !in_array( 'row_controls', $dismissed ) ) {
1542 include_once 'partials/pointers/cf7sg-pointer-editor-rows-control.php';
1543 $content = ob_get_contents();
1544 $pointers['row_controls'] = array($content, 'right', 'center','#grid-form>.container>.row>.row-controls');
1545 ob_clean();
1546 }
1547 /* preview form */
1548 if( !in_array( 'preview_form', $dismissed ) ) {
1549 include_once 'partials/pointers/cf7sg-pointer-editor-preview-form.php';
1550 $content = ob_get_contents();
1551 $pointers['preview_form'] = array($content, 'right', 'center','#preview-form-link');
1552 ob_clean();
1553 }
1554 /* column controls */
1555 if( !in_array( 'column_controls', $dismissed ) ) {
1556 include_once 'partials/pointers/cf7sg-pointer-editor-column-control.php';
1557 $content = ob_get_contents();
1558 $pointers['column_controls'] = array($content, 'left', 'center','#grid-form > .container:first-child > .row > .columns:first-child > .grid-column > span.icon-code');
1559 ob_clean();
1560 }
1561 /*dynamic-dropdown pointer*/
1562 if( !in_array( 'dynamic_dropdown', $dismissed ) ) {
1563 include_once 'partials/pointers/cf7sg-pointer-tag-dynamic-dropdown.php';
1564 $content = ob_get_contents();
1565 $pointers['dynamic_dropdown'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="dynamic-dropdown"]');
1566 ob_clean();
1567 }
1568 /*dynamic-checkbox pointer*/
1569 if( !in_array( 'dynamic_checkbox', $dismissed ) ) {
1570 include_once 'partials/pointers/cf7sg-pointer-tag-dynamic-checkbox.php';
1571 $content = ob_get_contents();
1572 $pointers['dynamic_checkbox'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="dynamic-checkbox"]');
1573 ob_clean();
1574 }
1575 /* #optional-editors */
1576 if( !in_array( 'js_css_editors', $dismissed ) ) {
1577 include_once 'partials/pointers/cf7sg-pointers-editor-optional-js-css.php';
1578 $content = ob_get_contents();
1579 $pointers['js_css_editors'] = array($content, 'left', 'center','#optional-editors');
1580 ob_clean();
1581 }
1582 /*benchmark pointer*/
1583 if( !in_array( 'benchmark', $dismissed ) ) {
1584 include_once 'partials/pointers/cf7sg-pointer-tag-benchmark.php';
1585 $content = ob_get_contents();
1586 $pointers['benchmark'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="benchmark"]');
1587 ob_clean();
1588 }
1589 /*UI tags pointer include always*/
1590 include_once 'partials/pointers/cf7sg-pointer-tag-ui-editor-tags.php';
1591 $content = ob_get_contents();
1592 $pointers['ui_editor_tags'] = $content; //controlled within js script
1593 ob_end_clean();
1594 return $pointers;
1595 }
1596 /**
1597 * Rest meta_caps for better fine tuning of user caps.
1598 * hooked to 'wpcf7_map_meta_cap'.
1599 *@since 3.0.0
1600 *@param array $caps key->value pairs of capabilities.
1601 *@return array key->value pairs of capabilities.
1602 */
1603 public function reset_meta_cap($caps){
1604 return array(
1605 'wpcf7_read_contact_form'=>'read_post',
1606 'wpcf7_edit_contact_form' =>'edit_post',
1607 'wpcf7_edit_contact_forms' => 'edit_posts',
1608 'wpcf7_edit_others_contact_forms'=>'edit_others_posts',
1609 'wpcf7_edit_published_contact_forms'=>'edit_published_posts',
1610 'wpcf7_delete_contact_form'=>'delete_post',
1611 'wpcf7_delete_contact_forms'=>'delete_posts',
1612 'wpcf7_delete_published_contact_forms'=>'delete_published_posts',
1613 'wpcf7_delete_others_contact_forms'=>'delete_others_posts',
1614 'wpcf7_publish_contact_forms'=>'publish_posts',
1615 'wpcf7_publish_contact_forms'=>'read_private_posts',
1616 'wpcf7_submit'=>'read', /** @since 3.2.1 to fix subscribers_only. */
1617 );
1618 }
1619 /**
1620 * CF7 plugin by default sets form post status to 'publish' regardless of user capability.
1621 * This functions rectifies this. Hooked to 'wp_insert_post_data'.
1622 *@since 3.0.0
1623 *@param array $data sanitised post data.
1624 *@return array post data.
1625 */
1626 public function pending_for_review($data, $post){
1627 if($this->cf7_post_type() != $data['post_type']) return $data;
1628
1629 $post_type_object = get_post_type_object( $this->cf7_post_type() );
1630 //check if user can publish.
1631 if(isset($post['ID']) && !current_user_can($post_type_object->cap->publish_posts, $post['ID']) && $data['post_status']=='publish'){
1632 $data['post_status']='pending';
1633 }
1634 // debug_msg('post status '.$data['post_status']);
1635 return $data;
1636 }
1637 /**
1638 * Enable all cf7 capabilites for editors.
1639 * Hooked to action 'admin_init'.
1640 *@since 3.0.0
1641 */
1642 public function enable_cf7_editor_role(){
1643 global $wp_roles;
1644 if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles();
1645 $caps=array('wpcf7_edit_contact_forms','wpcf7_edit_others_contact_forms','wpcf7_edit_published_contact_forms','wpcf7_read_contact_forms','wpcf7_publish_contact_forms','wpcf7_delete_contact_forms','wpcf7_delete_published_contact_forms','wpcf7_delete_others_contact_forms');
1646 $fe = $wp_roles->get_role('editor');
1647 if(!empty($fe)){ /** @since 3.0.3 in case editor role is deleted */
1648 foreach($caps as $cap) $fe->add_cap($cap);
1649 }
1650 $caps[]='wpcf7_manage_integration';
1651 $ad = $wp_roles->get_role('administrator');
1652 if(!empty($ad)){ /** @since 3.0.3 in case admin role is deleted */
1653 foreach($caps as $cap) $ad->add_cap($cap);
1654 }
1655
1656 /** @since 3.1.3 redirect cf7 plugin pages*/
1657 global $pagenow;
1658 // debug_msg("page: $pagenow");
1659 if ( $pagenow == 'admin.php' && isset( $_GET['page'] ) ) {
1660 $url = '';
1661 switch($_GET['page']){
1662 case 'wpcf7-new':
1663 $url = "post-new.php?post_type=wpcf7_contact_form" ;
1664 break;
1665 case 'wpcf7':
1666 if(isset($_GET['post'])) $url = "post.php?post={$_GET['post']}&action=edit&classic-editor";
1667 else $url = "edit.php?post_type=wpcf7_contact_form";
1668 break;
1669 }
1670 if(!empty($url)){
1671 wp_redirect( admin_url( $url ));
1672 exit;
1673 }
1674 }else if( $pagenow == 'edit.php' && isset( $_GET['post_type']) && $this->cf7_post_type()==$_GET['post_type'] ){ /** @since 4.11.5 buld validate */
1675 if(isset($_POST['action']) && 'validate'==$_POST['action'] && function_exists('wpcf7_load_bulk_validate_page')){
1676 wpcf7_load_bulk_validate_page('wpcf7','validate');
1677 }
1678 }
1679 }
1680 /**
1681 * Add grid helper hooks for individual tags.
1682 * Hooked to action 'cf7sg_ui_grid_helper_hooks'.
1683 *@since 3.3.0
1684 */
1685 public function print_helper_hooks(){
1686 require_once plugin_dir_path( __FILE__ ) .'partials/helpers/cf7sg-form-fields.php';
1687 }
1688 /**
1689 * Setup mailtags or toggles.
1690 * Hooked to 'wpcf7_collect_mail_tags'
1691 *@since 4.0.0
1692 *@param string $param text_description
1693 *@return string text_description
1694 */
1695 public function setup_cf7_mailtags($mailtags){
1696 // debug_msg($mailtags, 'mail tags ');
1697 // return $mailtags;
1698 $contact_form = WPCF7_ContactForm::get_current();
1699 $fields = get_post_meta($contact_form->id(), '_cf7sg_grid_toggled_names', true);
1700 //update_post_meta($post_id, '_cf7sg_grid_tabbed_toggles', $ttgls);
1701 if(!empty($fields)){
1702 $toggles = array_keys($fields);
1703 $groups = get_post_meta($contact_form->id(), '_cf7sg_grid_grouped_toggles', true);
1704 if(!empty($groups)){
1705 foreach($groups as $group=>$grp_toggles){
1706 $toggles = array_diff($toggles, $grp_toggles);
1707 array_push($toggles, $group);
1708 }
1709 }
1710 foreach($toggles as $tgl) $mailtags[]= 'cf7sg-toggle-'.$tgl;
1711 }
1712 //add a general form tag.
1713 $mailtags[]= 'cf7sg-form-'.get_cf7form_key($contact_form->id());
1714 return $mailtags;
1715 }
1716 /**
1717 * Funciton to to initialise admin notices.
1718 * hooked on 'admin_init'
1719 *@since 4.1.0
1720 */
1721 public function init_notices(){
1722 global $pagenow;
1723 switch($pagenow){
1724 case 'edit.php':
1725 case 'post.php':
1726 case 'plugins.php':
1727 break;
1728 default:
1729 return;
1730 }
1731 $grid_settings = get_option( self::CF7SG_OPTION, array());
1732 //if plugin settings exists and this is not an update, then no need to run.
1733 $notices = array();
1734 if( !empty($grid_settings) and isset($grid_settings['update']) ){
1735 $warning = false;
1736
1737 if(isset($grid_settings['update']) and CF7SG_VERSION_FORM_UPDATE==CF7_GRID_VERSION){
1738 $warning = true;
1739 }else if(isset($grid_settings['fv']) ) {
1740 if(version_compare($grid_settings['fv'], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true;
1741 }else{ //check the forms directly
1742 global $wpdb;
1743 $post_type = $this->cf7_post_type();
1744 $result = $wpdb->get_col("SELECT pm.meta_value FROM {$wpdb->postmeta} as pm
1745 INNER JOIN {$wpdb->posts} as p on p.ID = pm.post_id INNER JOIN {$wpdb->postmeta} as pmf on pmf.post_id = pm.post_id
1746 WHERE pmf.meta_key = '_cf7sg_managed_form'
1747 AND pmf.meta_value = 1
1748 AND p.post_type = '{$post_type}'
1749 AND pm.meta_key = '_cf7sg_version'
1750 ");
1751 if(!empty($result) and version_compare($result[0], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true;
1752 }
1753
1754 if($warning){
1755 $link = admin_url('edit.php?post_type=wpcf7_contact_form');
1756 /* translators: %s is the url to the forms admin table */
1757 $msg = __('You need to <strong>update</strong> your <a href="%s">forms</a>','cf7-grid-layout');
1758 $notices['cf7sg_notice-'.CF7_GRID_VERSION] = array(
1759 'type'=>'notice-warning', //[notice-update|notice-error]
1760 'msg'=>sprintf($msg , $link),
1761 'pages'=>array('plugins.php','edit.php')
1762 );
1763 }
1764 /** @since 4.2.0 new sliders tutorial */
1765 if( isset($grid_settings['update']) ){
1766 $notices['cf7sg_sliders_tutorial'] = array(
1767 'type'=>'notice-update', //[notice-update|notice-error]
1768 /* translators: %s is the link to the tuorial page*/
1769 'msg'=>sprintf( __('There is a new tutorial for <a href="%s">multistep slider forms</a>','cf7-grid-layout'), admin_url('admin.php?page=cf7sg_help')),
1770 'html'=>'<div class="inline-top"><iframe width="230" height="130" src="https://www.youtube.com/embed/WiweQRhOr0g" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div><div class="inline-top"><strong>Learn how to create multi-step multi-slide CF7 forms using a slider construct functionality of the Smart Grid-layout extension plugin.</strong></div>',
1771 'pages'=>array('plugins.php','edit.php')
1772 );
1773 $notices['cf7sg_modular_tutorial'] = array(
1774 'type'=>'notice-update', //[notice-update|notice-error]
1775 /* translators: %s is the link to the tuorial page*/
1776 'msg'=>sprintf( __('There is a new tutorial for <a href="%s">modular form construct</a>','cf7-grid-layout'), admin_url('admin.php?page=cf7sg_help')),
1777 'html'=>'<div class="inline-top"><iframe width="230" height="130" src="https://www.youtube.com/embed/vPc3M5Emro4" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div><div class="inline-top"><strong>Learn how to use modular form construct functionality allowing complex forms to be assembled from other child forms.</strong></div>',
1778 'pages'=>array('plugins.php','edit.php')
1779 );
1780 }
1781 update_option(self::CF7SG_OPTION, array(
1782 'gv'=>CF7_GRID_VERSION,
1783 'fv'=>CF7SG_VERSION_FORM_UPDATE
1784 ));
1785 }
1786 /** @since 4.11.5 add admin notices for bulk cf7 validation */
1787 //check if cf7 found issues:
1788
1789 if(method_exists('WPCF7','get_option')){
1790 $result = WPCF7::get_option( 'bulk_validate' );
1791 if(!empty($result)){
1792 $has_errors = ( isset($result['count_invalid']) and $result['count_invalid']>0);
1793 $is_old = (defined('WPCF7_ConfigValidator::last_important_update') &&
1794 isset($result['version']) &&
1795 version_compare( $result['version'], WPCF7_ConfigValidator::last_important_update, '<'));
1796 if( $is_old or $has_errors){
1797 ob_start();
1798 wpcf7_admin_bulk_validate_page();
1799 $html = ob_get_contents();
1800 ob_end_clean();
1801 $msg = '';
1802 if($is_old){
1803 $msg = __('CF7 plugin udpate requires you to revalidate your forms.','cf7-grid-layout');
1804 }else if($has_errors){
1805 $msg = sprintf( /* translators : %s is number of forms */
1806 __('You have %s form(s) with errors flagged below, fix those before attempting to revalidate your forms','cf7-grid-layout'),
1807 $result['count_invalid']
1808 );
1809 }
1810 $notices['cf7sg_notice-cf7_validate'] = array(
1811 'type'=>'notice-error',
1812 'msg' => $msg,
1813 'html'=>$html,
1814 'pages'=>array('edit.php')
1815 );
1816 }
1817 }
1818 }
1819 if(!empty($notices)) update_option('cf7sg-admin-notices', $notices);
1820 }
1821 /**
1822 * Display admin notices
1823 * Hooked on 'admin_notices'
1824 *@since 4.1.0
1825 */
1826 public function admin_notices(){
1827 //check if we have any notices.
1828 global $pagenow;
1829 $notices = get_option('cf7sg-admin-notices', array());
1830
1831 if(empty($notices)) return;
1832
1833 if(!isset(self::$admin_notice_pages[$pagenow])) return;
1834
1835 $notify=false;
1836 $rule = self::$admin_notice_pages[$pagenow];
1837 if($pagenow=='post.php'){
1838 $screen = get_current_screen();
1839 if($this->cf7_post_type() == $screen->post_type) $notify=true;
1840 }else if( !empty($rule) and is_array($rule) ){
1841 foreach($rule as $key=>$type){
1842 if( isset($_GET[$type]) and $_GET[$type]==$key ) $notify=true;
1843 }
1844 }else $notify = true; //default.
1845
1846 if(!$notify) return; //rules don't match;
1847
1848 //do we have any notices to display?
1849 foreach($notices as $id=>$notice){
1850 if( isset($notice['pages']) and !in_array($pagenow, $notice['pages'])) continue;
1851 $time = isset($notice['time']) ? $notice['time']: 'forever';
1852 $dismiss = "$id-$time";
1853 if ( ! PAnD::is_admin_notice_active( $dismiss ) ) {
1854 unset($notices[$id]);
1855 update_option('cf7sg-admin-notices', $notices);
1856 continue ; //continue foreach loop.
1857 }
1858 if(!isset($notice['html'])) $notice['html'] = '';
1859 ?>
1860 <style>.notice .inline-top{display: inline-block;vertical-align: top;margin-right: 10px;max-width: 300px;}</style>
1861 <div data-dismissible="<?=$dismiss?>" class="notice <?=$notice['type']?> is-dismissible cf7sg-notice">
1862 <?= empty($notice['msg'])?'':'<p>'.$notice['msg'].'</p>'?>
1863 <?=$notice['html']?>
1864 </div>
1865 <?php
1866 /** @since 4.7.1 dismiss notices once displayed */
1867 unset($notices[$id]);
1868 update_option('cf7sg-admin-notices', $notices);
1869 }
1870 }
1871 /**
1872 * ajax request to validate plugin update.
1873 * Hooked on 'wp_ajax_validate_cf7sg_version_update'
1874 * @since 4.1.0
1875 */
1876 public function validate_cf7sg_version_update(){
1877 if( !isset($_POST['nonce']) or !wp_verify_nonce($_POST['nonce'], 'cf7sg_udpate_plugin') ){
1878 echo 'error, nonce failed, try to reload the page.';
1879 wp_die();
1880 }
1881 $grid_settings = get_option(self::CF7SG_OPTION, array());
1882 $warning = false;
1883 if(isset($grid_settings['fv']) ) {
1884 if(version_compare($grid_settings['fv'], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true;
1885 }
1886 $grid_settings['fv'] = CF7SG_VERSION_FORM_UPDATE;
1887 $grid_settings['gv'] = CF7_GRID_VERSION;
1888 $grid_settings['update'] = true;
1889 update_option(self::CF7SG_OPTION, $grid_settings);
1890 $update_msg = __('Version validated, thank you!','cf7-grid-layout');
1891 if($warning){
1892 $link = admin_url('edit.php?post_type=wpcf7_contact_form');
1893 /* translators: %s link to form table */
1894 $update_msg = __('You need to <strong>update</strong> your <a href="%s">forms</a>','cf7-grid-layout');
1895 $update_msg = sprintf( $update_msg, $link);
1896 }
1897 echo $update_msg;
1898 wp_die();
1899 }
1900
1901 /**
1902 * Check if plugin is getting updated.
1903 * Hooked to 'upgrader_post_install'.
1904 *@since 4.1.0
1905 *@param array $param text_description
1906 *@param array $extras text_description
1907 *@param array $result text_description
1908 *@return array responses for the upgrade process
1909 */
1910 public function post_plugin_upgrade($response, $extras, $result){
1911 if( ( isset($response['destination_name']) and 'cf7-grid-layout' == $response['destination_name'] )
1912 or ( isset($extras['plugin']) and 'cf7-grid-layout/cf7-grid-layout.php' == $extras['plugin'] ) ){
1913 $grid_settings = get_option(self::CF7SG_OPTION, array());
1914 $grid_settings['update'] = true;
1915 update_option(self::CF7SG_OPTION, $grid_settings);
1916 }
1917 return $response;
1918 }
1919 /**
1920 * Preview form post type creation.
1921 * hooked on action 'init'.
1922 *@since 4.3.0
1923 *@param string $param text_description
1924 *@return string text_description
1925 */
1926 // Register Custom Post Type
1927 function register_form_preview_posttype() {
1928
1929 $labels = array(
1930 'name' => _x( 'CF7 Forms', 'Post Type General Name', 'cf7-grid-layout' ),
1931 'singular_name' => _x( 'CF7 Form', 'Post Type Singular Name', 'cf7-grid-layout' ),
1932 'menu_name' => __( 'CF7 Forms', 'cf7-grid-layout' ),
1933 'name_admin_bar' => __( 'CF7 Form', 'cf7-grid-layout' ),
1934 'parent_item_colon' => __( 'Parent Item:', 'cf7-grid-layout' ),
1935 'all_items' => __( 'All Form Pages', 'cf7-grid-layout' ),
1936 'add_new_item' => __( 'Add New Form Page', 'cf7-grid-layout' ),
1937 'add_new' => __( 'Add New', 'cf7-grid-layout' ),
1938 'new_item' => __( 'New Form Page', 'cf7-grid-layout' ),
1939 'edit_item' => __( 'Edit Form Page', 'cf7-grid-layout' ),
1940 'update_item' => __( 'Update Form Page', 'cf7-grid-layout' ),
1941 'view_item' => __( 'View Form Page', 'cf7-grid-layout' ),
1942 'view_items' => __( 'View Form Pages', 'cf7-grid-layout' ),
1943 'search_items' => __( 'Search Form Page', 'cf7-grid-layout' ),
1944 'not_found' => __( 'Not found', 'cf7-grid-layout' ),
1945 'not_found_in_trash' => __( 'Not found in Trash', 'cf7-grid-layout' ),
1946 );
1947 $rewrite = array(
1948 'slug' => 'sgform',
1949 'with_front' => true,
1950 'pages' => true,
1951 'feeds' => false,
1952 );
1953 $args = array(
1954 'label' => __( 'CF7 Form', 'cf7-grid-layout' ),
1955 'description' => __( 'Preview/View CF7 forms on the front-end', 'cf7-grid-layout' ),
1956 'labels' => $labels,
1957 'public' => true,
1958 'show_ui' => false,
1959 'show_in_menu' => false,
1960 'show_in_admin_bar' => false,
1961 'show_in_nav_menus' => false,
1962 'can_export' => false,
1963 'has_archive' => false,
1964 'exclude_from_search' => true,
1965 'publicly_queryable' => true,
1966 // 'query_var' => 'sgcf7',
1967 'rewrite' => $rewrite,
1968 );
1969 register_post_type( 'cf7sg_page', $args );
1970
1971 }
1972 /**
1973 * Load translation files for the CF7 Polylang extension.
1974 * Hoooked to ''
1975 *@since 4.4.0
1976 *@param string $param text_description
1977 *@return string text_description
1978 */
1979 public function load_translation_files($trans){
1980 $trans[$this->plugin_name]=CF7SG_TRANSLATED_VERSION;
1981 return $trans;
1982 }
1983 }
1984