PluginProbe
Smart Grid-Layout Design for Contact Form 7 / 4.14
Smart Grid-Layout Design for Contact Form 7 v4.14
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.14, at admin/class-cf7-grid-layout-admin.php

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