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

1,556 lines 63.7 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 1.0.0
28 * @access private
29 * @var string $plugin_name The ID of this plugin.
30 */
31 private $plugin_name;
32 /**
33 * The version of this plugin.
34 *
35 * @since 1.0.0
36 * @access private
37 * @var string $version The current version of this plugin.
38 */
39 private $version;
40 /**
41 * Initialize the class and set its properties.
42 *
43 * @since 1.0.0
44 * @param string $plugin_name The name of this plugin.
45 * @param string $version The version of this plugin.
46 */
47 public function __construct( $plugin_name, $version ) {
48 $this->plugin_name = $plugin_name;
49 $this->version = $version;
50 }
51 /**
52 * get cf7 post type set by cf7 plugin.
53 *
54 *@since 3.0.0
55 *@return string post type.
56 */
57 private function cf7_post_type(){
58 $type = 'wpcf7_post_type_notset';
59 if(class_exists('WPCF7_ContactForm') ) {
60 $type = WPCF7_ContactForm::post_type;
61 }
62 return $type;
63 }
64 /**
65 * Hack to add scripts/styles to edit page.
66 * Hooked on 'admin_enqueue_scripts'.
67 *@since 1.5.0
68 */
69 public function popular_extentions_scripts(){
70 $screen = get_current_screen();
71 if (empty($screen) || $this->cf7_post_type() != $screen->post_type){
72 return;
73 }
74 $plugin_dir = plugin_dir_url( __DIR__ );
75 switch( $screen->base ){
76 case 'post':
77 $page_hook = '';
78 if('add' == $screen->action) $page_hook = 'contact_page_wpcf7-new';
79 else $page_hook = 'toplevel_page_wpcf7';
80 //unhook this function.
81 remove_action('admin_enqueue_scripts', array($this, 'popular_extentions_scripts'),999,0);
82 do_action('admin_enqueue_scripts', $page_hook);
83 $plugin_page ='';
84 add_action('admin_enqueue_scripts', array($this, 'popular_extentions_scripts'),999,0);
85 break;
86 case 'edit': //table.
87 break;
88 }
89 }
90 /**
91 * Function to spoof the wpcf7 plugin admin scripts loading for extensions
92 * Hooked on 'admin_print_scripts' and used to fix the issue with the mailchimp ext.
93 *@since 1.5.1
94 */
95 public function print_extentions_scripts(){
96 $screen = get_current_screen();
97 if (empty($screen) || $this->cf7_post_type() != $screen->post_type){
98 return;
99 }
100 global $plugin_page;
101 $plugin_page = 'wpcf7';
102 }
103
104
105 /**
106 * Register the stylesheets for the admin area.
107 *
108 * @since 1.0.0
109 */
110 public function enqueue_styles($page) {
111
112 if( in_array($page, array('toplevel_page_wpcf7', 'contact_page_wpcf7-new')) ) return;
113
114 $screen = get_current_screen();
115 $plugin_dir = plugin_dir_url( __DIR__ );
116 if('plugins'==$screen->base){
117 /** @since 4.1.0 */
118 wp_enqueue_style('plugin-update',$plugin_dir . 'admin/css/cf7sg-plugin-update.css', array(), $this->version, 'all');
119 return;
120 }
121 if (empty($screen) || $this->cf7_post_type() != $screen->post_type){
122 return;
123 }
124 switch( $screen->base ){
125 case 'post':
126 wp_enqueue_style( "cf7-grid-post-css", $plugin_dir . 'admin/css/cf7-grid-layout-post.css', array(), $this->version, 'all' );
127 //dynamic tag
128 wp_enqueue_style('cf7sg-dynamic-tag-css', $plugin_dir . 'admin/css/cf7sg-dynamic-tag.css', array(), $this->version, 'all' );
129 //benchmark tag
130 wp_enqueue_style('cf7sg-benchmark-tag-css', $plugin_dir . 'admin/css/cf7sg-benchmark-tag.css', array(), $this->version, 'all' );
131 //codemirror
132 wp_enqueue_style( "codemirror-css", $plugin_dir . 'assets/codemirror/codemirror.css', array(), $this->version, 'all' );
133 /** @since 4.0 enable dark theme */
134 wp_enqueue_style( "codemirror-theme-light-css", $plugin_dir . 'assets/codemirror/theme/paraiso-light.css', array(), $this->version, 'all' );
135 wp_enqueue_style( "codemirror-theme-dark-css", $plugin_dir . 'assets/codemirror/theme/material-ocean.css', array(), $this->version, 'all' );
136 wp_enqueue_style( "codemirror-foldgutter-css", $plugin_dir . 'assets/codemirror/addon/fold/foldgutter.css', array(), $this->version, 'all' );
137 wp_enqueue_style( "codemirror-dialog-css", $plugin_dir . 'assets/codemirror/addon/dialog/dialog.css', array(), $this->version, 'all' );
138 wp_enqueue_style( "codemirror-matchesonscrollbar-css", $plugin_dir . 'assets/codemirror/addon/search/matchesonscrollbar.css', array(), $this->version, 'all' );
139 wp_enqueue_style( 'smart-grid-css', $plugin_dir . 'assets/css.gs/smart-grid.admin.css', array(), $this->version, 'all');
140 wp_enqueue_style('dashicons');
141 wp_enqueue_style('select2-style', $plugin_dir . 'assets/select2/css/select2.min.css', array(), $this->version, 'all' );
142 break;
143 case 'edit': //table.
144 wp_enqueue_style( $this->plugin_name, $plugin_dir . 'admin/css/cf7-grid-layout-admin.css', array(), $this->version, 'all' );
145
146 break;
147 }
148
149 }
150
151 /**
152 * Register the JavaScript for the admin area.
153 *
154 * @since 1.0.0
155 */
156 public function enqueue_scripts($page) {
157
158 $plugin_dir = plugin_dir_url( __DIR__ );
159 if( in_array($page, array('toplevel_page_wpcf7', 'contact_page_wpcf7-new')) ){
160 wp_enqueue_script( $this->plugin_name, $plugin_dir . 'admin/js/cf7-grid-layout-admin.js', array( 'jquery' ), $this->version, true );
161 return;
162 }
163 $screen = get_current_screen();
164 if('plugins'==$screen->base){
165 /** @since 4.1.0 */
166 wp_enqueue_script('cf7sg-plugin-update', $plugin_dir . 'admin/js/cf7sg-plugin-update.js', array('jquery'));
167 /* translators: message displayed when succesful update to validate new version */
168 wp_localize_script('cf7sg-plugin-update', 'cf7sg',array(
169 'msg'=> __('Validating your update...','cf7-grid-layout'),
170 'nonce'=> wp_create_nonce( 'cf7sg_udpate_plugin' ),
171 'error'=>__('Unable to validate, please reload!', 'cf7-grid-layout')
172 ));
173 return;
174 }
175 if ($this->cf7_post_type() != $screen->post_type){
176 return;
177 }
178
179 switch( $screen->base ){
180 case 'post':
181 /* register codemirror editor & addons. */
182 //codemirror script
183 wp_register_script( 'cf7-codemirror-js',
184 $plugin_dir . 'assets/codemirror/codemirror.js',
185 null, "5.32", true
186 );
187 /** @since 3.1.2 initialise codemirror after library load and parse as attribute to anonymous functtion in cf7-grid-codemirror.js */
188 wp_add_inline_script('cf7-codemirror-js',
189 'const cmInitialSettings = {
190 value:"",matchTags: {bothTags: true},autoCloseTags:true,
191 extraKeys: {"Ctrl-Space": "autocomplete", "Ctrl-/": "toggleComment", "Ctrl-J": "toMatchingTag"},
192 lineNumbers: true, styleActiveLine: true,
193 matchBrackets: true, tabSize:2, lineWrapping: true, addModeClass: true,
194 foldGutter: true, autofocus:false,
195 gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
196 }
197 const codeMirror_5_32 = CodeMirror(document.getElementById("cf7-codemirror"),cmInitialSettings);
198 const cssCodeMirror_5_32 = CodeMirror(document.getElementById("cf7-css-codemirror"),cmInitialSettings);
199 const jsCodeMirror_5_32 = CodeMirror(document.getElementById("cf7-js-codemirror"),cmInitialSettings);');
200 //matchtags.
201 wp_enqueue_script( 'codemirror-matchtag-js',
202 $plugin_dir . 'assets/codemirror/edit/matchtags.js',
203 array('cf7-codemirror-js'), $this->version, true
204 );
205 wp_enqueue_script( 'codemirror-closetag-js',
206 $plugin_dir . 'assets/codemirror/edit/closetag.js',
207 array('cf7-codemirror-js'), $this->version, true
208 );
209 //fold code
210 wp_enqueue_script( 'codemirror-foldcode-js',
211 $plugin_dir . 'assets/codemirror/addon/fold/foldcode.js',
212 array('cf7-codemirror-js'), $this->version, true
213 );
214 wp_enqueue_script( 'codemirror-foldgutter-js',
215 $plugin_dir . 'assets/codemirror/addon/fold/foldgutter.js',
216 array('cf7-codemirror-js'), $this->version, true
217 );
218 wp_enqueue_script( 'codemirror-indent-fold-js',
219 $plugin_dir . 'assets/codemirror/addon/fold/indent-fold.js',
220 array('cf7-codemirror-js'), $this->version, true
221 );
222 wp_enqueue_script( 'codemirror-xml-fold-js',
223 $plugin_dir . 'assets/codemirror/addon/fold/xml-fold.js',
224 array('cf7-codemirror-js'), $this->version, true
225 );
226 wp_enqueue_script( 'codemirror-brace-fold-js',
227 $plugin_dir . 'assets/codemirror/addon/fold/brace-fold.js',
228 array('cf7-codemirror-js'), $this->version, true
229 );
230 wp_enqueue_script( 'codemirror-comment-fold-js',
231 $plugin_dir . 'assets/codemirror/addon/fold/comment-fold.js',
232 array('cf7-codemirror-js'), $this->version, true
233 );
234 wp_enqueue_script( 'codemirror-mixed-js',
235 $plugin_dir . 'assets/codemirror/mode/htmlmixed/htmlmixed.js',
236 array('cf7-codemirror-js'), $this->version, true
237 );
238 wp_enqueue_script( 'codemirror-javascript-js',
239 $plugin_dir . 'assets/codemirror/mode/javascript/javascript.js',
240 array('cf7-codemirror-js'), $this->version, true
241 );
242 wp_enqueue_script( 'codemirror-xml-js',
243 $plugin_dir . 'assets/codemirror/mode/xml/xml.js',
244 array('cf7-codemirror-js'), $this->version, true
245 );
246 wp_enqueue_script( 'codemirror-css-js',
247 $plugin_dir . 'assets/codemirror/mode/css/css.js',
248 array('cf7-codemirror-js'), $this->version, true
249 );
250 //overlay for shortcode highligh
251 wp_enqueue_script( 'codemirror-overlay-js',
252 $plugin_dir . 'assets/codemirror/addon/mode/overlay.js',
253 array('cf7-codemirror-js'), $this->version, true
254 );
255 /**
256 * @since 1.3.0 enable search codemirror
257 */
258 //overlay for shortcode highligh
259 wp_enqueue_script( 'codemirror-search-js',
260 $plugin_dir . 'assets/codemirror/addon/search/search.js',
261 array('cf7-codemirror-js'), $this->version, true
262 );
263 wp_enqueue_script( 'codemirror-jumptoline-js',
264 $plugin_dir . 'assets/codemirror/addon/search/jump-to-line.js',
265 array('cf7-codemirror-js'), $this->version, true
266 );
267 wp_enqueue_script( 'codemirror-matchesonscrollbar-js',
268 $plugin_dir . 'assets/codemirror/addon/search/matchesonscrollbar.js',
269 array('cf7-codemirror-js'), $this->version, true
270 );
271 wp_enqueue_script( 'codemirror-searchcursor-js',
272 $plugin_dir . 'assets/codemirror/addon/search/searchcursor.js',
273 array('cf7-codemirror-js'), $this->version, true
274 );
275 wp_enqueue_script( 'codemirror-annotatescrollbar-js',
276 $plugin_dir . 'assets/codemirror/addon/scroll/annotatescrollbar.js',
277 array('cf7-codemirror-js'), $this->version, true
278 );
279 wp_enqueue_script( 'codemirror-dialog-js',
280 $plugin_dir . 'assets/codemirror/addon/dialog/dialog.js',
281 array('cf7-codemirror-js'), $this->version, true
282 );
283
284 //js beautify
285 wp_enqueue_script( 'beautify-js',
286 $plugin_dir . 'assets/beautify/beautify.js',
287 array('jquery'), $this->version, true
288 );
289 wp_enqueue_script( 'beautify-html-js',
290 $plugin_dir . 'assets/beautify/beautify-html.js',
291 array('beautify-js'), $this->version, true
292 );
293 wp_enqueue_script('jquery-select2', $plugin_dir . 'assets/select2/js/select2.min.js', array( 'jquery' ), $this->version, true );
294 /** @since 4.0 enable dark theme */
295 $cm_light = apply_filters('cf7sg_admin_editor_theme', '');
296 $user_theme = get_user_meta(get_current_user_id(),'_cf7sg_cm_theme', true);
297 if(!empty($cm_light) && file_exists(get_stylesheet_directory().'/'.$cm_light) ){
298 wp_enqueue_style( "codemirror-theme-css", get_stylesheet_directory_uri().'/'.$cm_light, array(), $this->version, 'all' );
299 $user_theme = basename($cm_light, '.css');
300 update_user_meta(get_current_user_id(),'_cf7sg_cm_theme', '');
301 }else{
302 if(empty($user_theme)){
303 $user_theme = 'paraiso-light';
304 update_user_meta(get_current_user_id(),'_cf7sg_cm_theme', 'light');
305 }else{
306 $user_theme = ('light'==$user_theme ? 'paraiso-light' : 'material-ocean');
307 }
308 }
309 $cm_js_light = apply_filters('cf7sg_admin_js_editor_theme', '');
310 $user_js_theme = get_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', true);
311 if(!empty($cm_js_light) && file_exists(get_stylesheet_directory().'/'.$cm_js_light) ){
312 wp_enqueue_style( "codemirror-js-theme-css", get_stylesheet_directory_uri().'/'.$cm_js_light, array(), $this->version, 'all' );
313 $user_js_theme = basename($cm_js_light, '.css');
314 update_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', '');
315 }else{
316 if(empty($user_js_theme)){
317 $user_js_theme = 'paraiso-light';
318 update_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', 'light');
319 }else{
320 $user_js_theme = ('light'==$user_js_theme ? 'paraiso-light' : 'material-ocean');
321 }
322 }
323 $cm_css_light = apply_filters('cf7sg_admin_css_editor_theme', '');
324 $user_css_theme = get_user_meta(get_current_user_id(),'_cf7sg_css_cm_theme', true);
325 if(!empty($cm_css_light) && file_exists(get_stylesheet_directory().'/'.$cm_css_light) ){
326 wp_enqueue_style( "codemirror-css-theme-css", get_stylesheet_directory_uri().'/'.$cm_css_light, array(), $this->version, 'all' );
327 $user_css_theme = basename($cm_css_light, '.css');
328 update_user_meta(get_current_user_id(),'_cf7sg_css_cm_theme', '');
329 }else{
330 if(empty($user_css_theme)){
331 $user_css_theme = 'paraiso-light';
332 update_user_meta(get_current_user_id(),'_cf7sg_css_cm_theme', 'light');
333 }else{
334 $user_css_theme = ('light'==$user_css_theme ? 'paraiso-light' : 'material-ocean');
335 }
336 }
337 //enqueue the cf7 scripts.
338 wpcf7_admin_enqueue_scripts( 'wpcf7' );
339 wp_enqueue_script('jquery-clibboard', $plugin_dir . 'assets/clipboard/clipboard.min.js', array('jquery'),$this->version,true);
340 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 );
341 wp_localize_script(
342 'cf7-grid-codemirror-js',
343 'cf7sgeditor',
344 array(
345 'mode' => 'shortcode',
346 'theme' => array(
347 'light'=>'paraiso-light',
348 'dark'=>'material-ocean',
349 'user'=>$user_theme
350 ),
351 'jstheme' => array(
352 'light'=>'paraiso-light',
353 'dark'=>'material-ocean',
354 'user'=>$user_js_theme
355 ),
356 'csstheme' => array(
357 'light'=>'paraiso-light',
358 'dark'=>'material-ocean',
359 'user'=>$user_css_theme
360 )
361 )
362 );
363 global $post;
364
365 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 );
366 wp_localize_script(
367 $this->plugin_name,
368 'cf7grid',
369 array(
370 'preHTML' => apply_filters('cf7sg_pre_cf7_field_html', '<div class="field"><label></label>', $post->post_name),
371 'postHTML' => apply_filters('cf7sg_post_cf7_field_html', '<p class="info-tip"></p></div>', $post->post_name),
372 'requiredHTML' => apply_filters('cf7sg_required_cf7_field_html', '<em>*</em>', $post->post_name),
373 'ui' => apply_filters('cf7sg_grid_ui', true, $post->post_name)
374 )
375 );
376 wp_enqueue_script( 'cf7sg-dynamic-tag-js', $plugin_dir . 'admin/js/cf7sg-dynamic-tag.js', array('jquery','wpcf7-admin-taggenerator' ), $this->version, true );
377 wp_enqueue_script( 'cf7-benchmark-tag-js', $plugin_dir . 'admin/js/cf7-benchmark-tag.js', array('jquery','wpcf7-admin-taggenerator' ), $this->version, true );
378 /** @since 3.2.0 */
379 wp_enqueue_script('cf7sg-mail-tag-js', $plugin_dir.'admin/js/mail-tag-helper.js', array('jquery','jquery-clibboard'));
380 wp_localize_script('cf7sg-mail-tag-js','mailTagHelper',
381 array(
382 'msg'=>__('Click to copy!','cf7-grid-layout'),
383 'filter'=> __('Filter mailTag %s', 'cf7-grid-layout')
384 )
385 );
386 /** @since 3.3.0 enqueue ui-grid helpers js */
387 wp_enqueue_script('ui-grid-helpers-js', $plugin_dir.'admin/js/ui-custom-helper.js', array('jquery'));
388 do_action('cf7sg_enqueue_admin_editor_scripts');
389 break;
390 case 'edit':
391 //wp_enqueue_script( $this->plugin_name.'-quick-edit', plugin_dir_url( __FILE__ ) . 'js/cf7-grid-layout-quick-edit.js', false, $this->version, true );
392
393 break;
394 }
395 }
396
397 /**
398 * Adds a new sub-menu to replace the 'Add New' CF7 menu
399 * Add a new sub-menu to the Contact main menu, as well as remove the current default
400 *
401 */
402 public function add_cf7_sub_menu(){
403
404 $hook = add_submenu_page(
405 'wpcf7',
406 __cf7sg( 'Edit Contact Form'),
407 __cf7sg( 'Add New'),
408 'wpcf7_edit_contact_forms',
409 'post-new.php?post_type=wpcf7_contact_form'
410 );
411 //initial cf7 object when creating new form
412 add_action( 'load-' . $hook, array($this, 'setup_cf7_object'));
413 //remove_submenu_page( $menu_slug, $submenu_slug );
414 remove_submenu_page( 'wpcf7', 'wpcf7-new' );
415 remove_meta_box('slugdiv', $this->cf7_post_type(), 'normal');
416 }
417 /**
418 * Change the submenu order
419 * @since 1.0.0
420 */
421 public function change_cf7_submenu_order( $menu_ord ) {
422 global $submenu;
423 // Enable the next line to see all menu orders
424 if(!isset($submenu['wpcf7']) ){
425 return $menu_ord;
426 }
427 if( is_network_admin() ){
428 return $menu_ord;
429 }
430 $arr = array();
431 foreach($submenu['wpcf7'] as $menu){
432 switch($menu[2]){
433 case 'post-new.php?post_type=wpcf7_contact_form':
434 //push to the front
435 array_unshift($arr, $menu);
436 break;
437 default:
438 $arr[]=$menu;
439 break;
440 }
441 }
442 $submenu['wpcf7'] = $arr;
443 return $menu_ord;
444 }
445 /**
446 * Modify the regsitered cf7 post tppe
447 * THis function enables public capability and amind UI visibility for the cf7 post type. Hooked late on `register_post_type_args`
448 * @since 1.0.0
449 * @param Array $args array of post parameters being registered
450 * @param String $post_type post type breing resgistered
451 */
452
453 public function modify_cf7_post_type_args($args, $post_type){
454 if($post_type === $this->cf7_post_type() ) {
455 // debug_msg($args, 'pre-args');
456 // $system_dropdowns = get_option('_cf7sg_dynamic_dropdown_system_taxonomy',array());
457 /** @since 2.8.3 add wpcf7_type (registered in assets/cf7-table.php) taxonomy to cf7 post type */
458 $system_taxonomy = array('wpcf7_type');
459 // if(!empty($system_dropdowns)){
460 // foreach($system_dropdowns as $id=>$list){
461 // $system_taxonomy = array_merge($system_taxonomy, $list);
462 // }
463 // }
464 if(!empty($args['taxonomies'])){
465 $system_taxonomy = array_merge($args['taxonomies'], $system_taxonomy);
466 $system_taxonomy = array_unique($system_taxonomy);
467 }
468 $args['taxonomies'] = $system_taxonomy;
469
470 $args['public'] = false;
471 $args['show_ui']= true;
472 $args['show_in_menu']= 'wpcf7';
473 $args['supports'] = array('title', 'author');
474 $args['labels']['add_new_item'] = 'Add New Form';
475 $args['labels']['edit_item'] = 'Edit Form';
476 $args['labels']['new_item'] = 'New Form';
477 $args['labels']['view_item'] = 'View Form';
478 $args['labels']['view_items'] = 'View Forms';
479 $args['labels']['search_items'] = 'Search Forms';
480 $args['labels']['not_found'] = 'No forms found.';
481 $args['labels']['not_found_in_trash'] = 'No forms found in Trash.';
482 $args['labels']['parent_item_colon'] = '';
483 $args['labels']['attributes'] = 'Form Attributes';
484 $args['labels']['insert_into_item'] = 'Insert into form';
485 $args['labels']['uploaded_to_this_item'] = 'Uploaded to this form';
486 $args['labels']['filter_items_list'] = 'Filter forms list';
487 $args['labels']['items_list_navigation'] = 'Forms list navigation';
488 $args['labels']['items_list'] = 'Forms list';
489 /** @since 2.8.1 fix missing delete_posts notices*/
490 // $args['capabilities']['delete_posts']= 'wpcf7_delete_posts';
491 /** @since 3.0.0 enable better capability management */
492 // $args['capability_type'] = 'page';
493
494 $args['map_meta_cap']=true; //allow finer capability mapping.
495 $args['capabilities']['edit_post'] = 'wpcf7_edit_contact_form';
496 $args['capabilities']['read_post'] = 'wpcf7_read_contact_form';
497 $args['capabilities']['delete_post'] = 'wpcf7_delete_contact_form';
498 $args['capabilities']['edit_posts'] = 'wpcf7_edit_contact_forms';
499 $args['capabilities']['edit_others_posts']= 'wpcf7_edit_others_contact_forms';
500 $args['capabilities']['edit_published_posts']= 'wpcf7_edit_published_contact_forms';
501 $args['capabilities']['delete_posts']= 'wpcf7_delete_contact_forms';
502 $args['capabilities']['delete_published_posts']= 'wpcf7_delete_published_contact_forms';
503 $args['capabilities']['delete_others_posts']= 'wpcf7_delete_others_contact_forms';
504 $args['capabilities']['publish_posts']= 'wpcf7_publish_contact_forms';
505 $args['capabilities']['read_private_posts']= 'wpcf7_publish_contact_forms';
506
507 // debug_msg($args);
508 }
509 return $args;
510 }
511 /**
512 * Register custom taxonomy for dynamic dropdown lists
513 * Hooked on 'init'
514 * @since 1.0.0
515 *
516 **/
517 public function register_dynamic_dropdown_taxonomy(){
518 //register the dynamic dropdown taxonomies.
519 $dropdowns = get_option('_cf7sg_dynamic_dropdown_taxonomy',array());
520 //debug_msg($dropdowns);
521 $created = array();
522 foreach($dropdowns as $post_lists){
523 foreach($post_lists as $slug=>$taxonomy){
524 if(!isset($created[$slug])){
525 if(is_array($taxonomy)){
526 $this->register_dynamic_dropdown($taxonomy);
527 $created[$slug] = $slug;
528 }
529 }
530 }
531 }
532 }
533
534 /**
535 * Function to add the metabox to the cf7 post edit screen
536 * This adds the main editor, hooked on 'add_meta_boxes'
537 * @since 1.0.0
538 */
539 public function main_editor_meta_box() {
540 //add_meta_box( string $id, string $title, callable $callback, string $screen, string $context, string $priority, array $callback_args)
541 if( post_type_exists( $this->cf7_post_type() ) ) {
542 add_meta_box( 'meta-box-main-cf7-editor',
543 __cf7sg( 'Edit Contact Form' ),
544 array($this , 'main_editor_metabox_display'),
545 $this->cf7_post_type(),
546 'normal',
547 'high'
548 );
549 }
550 }
551 /**
552 * Function called on page load when new form is created
553 * hooked to 'load-{page-hook}'
554 * @since 1.0.0
555 **/
556 public function setup_cf7_object(){
557 $args = array();
558 /**
559 * Fix locale setup for new forms using polylang.
560 * @since 2.1.4
561 */
562 if(isset($_GET['locale'])){
563 $args['locale'] = $_GET['locale'];
564 }else if(isset($_GET['new_lang'])){
565 //check for polylang
566 $locale = $_GET['new_lang'];
567 if(function_exists('pll_languages_list')){
568 $langs = pll_languages_list();
569 $locales = pll_languages_list(array('fields'=>'locale'));
570 foreach($langs as $idx => $lang){
571 if($lang == $locale){
572 $locale = $locales[$idx];
573 }
574 }
575 }
576 $args['locale'] =$locale;
577 }else $args['locale'] = get_locale();
578
579 WPCF7_ContactForm::get_template( $args);
580 }
581 /**
582 * Callback function to disolay the main editor meta box
583 * @since 1.0.0
584 */
585 public function main_editor_metabox_display($post){
586 if('auto-draft' !== $post->post_status){
587 wpcf7_contact_form($post); //set the post
588 }
589 $post_id = $post->ID;
590 $cf7_form = wpcf7_get_current_contact_form();
591
592 if ( ! $cf7_form ) {
593 $cf7_form = WPCF7_ContactForm::get_template();
594 }
595
596 // if(empty($post)){
597 // $post_id = -1;
598 // }else{
599 // $post_id = $post->ID;
600 // }
601 require_once WPCF7_PLUGIN_DIR . '/admin/includes/editor.php';
602 require_once plugin_dir_path( __FILE__ ) . 'partials/cf7-admin-editor-display.php';
603 }
604
605 /**
606 * Function to add the metabox to the cf7 post edit screen
607 * This adds the main editor, hooked on 'add_meta_boxes'
608 * @since 1.0.0
609 */
610 public function info_meta_box() {
611 //add_meta_box( string $id, string $title, callable $callback, string $screen, string $context, string $priority, array $callback_args)
612 if(post_type_exists( $this->cf7_post_type() ) ) {
613 add_meta_box( 'meta-box-cf7-info',
614 __cf7sg( 'Information' ),
615 array($this , 'info_metabox_display'),
616 $this->cf7_post_type(),
617 'side',
618 'high'
619 );
620 }
621 }
622 /**
623 * Re-introduces the wordpress 'wpcf7_admin_misc_pub_section' for plugins to add their fields for submission
624 * Hooked to 'post_submitbox_misc_actions' which fires after post dat/time parameters are printed
625 * @since 1.0.0
626 * @param WP_Post $post post object being edited/created.
627 **/
628 public function cf7_post_submit_action($post){
629 if($this->cf7_post_type() == $post->post_type){
630 do_action( 'wpcf7_admin_misc_pub_section', $post->ID );
631 }
632 }
633 /**
634 * Callback function to disolay the main editor meta box
635 * @since 1.0.0
636 */
637 public function info_metabox_display($post){
638 require_once plugin_dir_path( __FILE__ ) . 'partials/cf7-info-metabox-display.php';
639 }
640 /**
641 * Function to add the metabox to the cf7 post edit screen
642 * This adds the helper, hooked on 'add_meta_boxes'
643 * @since 1.1.0
644 */
645 public function helper_meta_box() {
646 //add_meta_box( string $id, string $title, callable $callback, string $screen, string $context, string $priority, array $callback_args).
647 if(post_type_exists( $this->cf7_post_type() ) ) {
648 add_meta_box( 'meta-box-cf7sg-helper',
649 __( 'Actions & Filters', 'cf7-grid-layout' ),
650 array($this , 'helper_metabox_display'),
651 $this->cf7_post_type(),
652 'side',
653 'low'
654 );
655 }
656 }
657 /**
658 * Callback function to disolay the helper meta box
659 * @since 1.0.0
660 */
661 public function helper_metabox_display($post){
662 require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-helper-metabox-display.php';
663 }
664 /**
665 * Display the editor panels (wpcf7 / codemirror / grid)
666 *
667 * @since 1.0.0
668 * @param string $p1 .
669 * @return string $p2 .
670 **/
671 public function grid_editor_panel($form_post){
672 require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-grid-layout-admin-display.php';
673 }
674 /**
675 * Save cf7 post using ajax
676 * Hooked to 'save_post_wpcf7_contact_form'
677 * @since 1.0.0
678 **/
679 public function save_post($post_id, $post, $update){
680 //make sure this is the edit page and not a quick-edit.
681 if( !isset($_POST['_wpcf7nonce']) ){
682 return;
683 }
684 //validate the nonce.
685 check_admin_referer( 'wpcf7-save-contact-form_' . $post_id, '_wpcf7nonce');
686
687 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){
688 return;
689 }
690
691 switch($post->post_status){
692 case 'auto-draft':
693 case 'trash':
694 return;
695 default:
696 break;
697 }
698
699 // debug_msg($_POST, 'submitted ');
700 $args = $_REQUEST;
701 $args['id'] = $post_id;
702
703 $args['title'] = isset( $_POST['post_title'] ) ? sanitize_text_field($_POST['post_title'], 'Contact Form', 'save') : null;
704 $args['locale'] = isset( $_POST['wpcf7-locale'] ) ? sanitize_text_field($_POST['wpcf7-locale']) : null;
705 $args['form'] = '';
706 $allowed_tags = wp_kses_allowed_html( 'post' ); //filtered in function below.
707 /** @since 2.10.0 alllow custom input html*/
708 $allowed_tags['input']=array( //add additional input html elements
709 'type'=>1,
710 'class'=>1,
711 'id'=>1,
712 'value'=>1,
713 'data-*'=>1,
714 );
715 $allowed_tags['script']=array('type'=>1);
716 $cf7_key = sanitize_text_field($_POST['post_name']);
717 $allowed_tags = apply_filters('cf7sg_kses_allowed_html',$allowed_tags, $cf7_key);
718 if(isset( $_POST['wpcf7-form'] )){
719 $args['form'] = wp_kses($_POST['wpcf7-form'], $allowed_tags);
720 }
721 $args['mail'] = isset( $_POST['wpcf7-mail'] ) ? wpcf7_sanitize_mail( $_POST['wpcf7-mail'] ): array();
722 $args['mail_2'] = isset( $_POST['wpcf7-mail-2'] ) ? wpcf7_sanitize_mail( $_POST['wpcf7-mail-2'] ): array();
723 $args['messages'] = isset( $_POST['wpcf7-messages'] ) ? $_POST['wpcf7-messages'] : array();
724 foreach($args['messages'] as $key=>$value){
725 $args['messages'][$key] = sanitize_text_field($value);
726 }
727 $args['additional_settings'] = isset( $_POST['wpcf7-additional-settings'] ) ? sanitize_textarea_field($_POST['wpcf7-additional-settings']) : '';
728
729 //need to unhook this function so as not to loop infinitely
730 //debug_msg($args, 'saving cf7 posts');
731 remove_action('save_post_wpcf7_contact_form', array($this, 'save_post'), 10,3);
732 $contact_form = wpcf7_save_contact_form( $args );
733 add_action('save_post_wpcf7_contact_form', array($this, 'save_post'), 10,3);
734 //flag as a grid form
735 //update_post_meta($post_id, 'cf7_grid_form', true); removed since v2.3 as not used.
736 //save sub-forms if any
737 $sub_forms = json_decode(stripslashes($_POST['cf7sg-embeded-forms']));
738 if(empty($sub_forms)) $sub_forms = array();
739 if(!is_array($sub_forms)) $sub_forms = array($sub_forms);
740 $sanitised_sub_forms = array();
741 foreach($sub_forms as $field){
742 $sanitised_sub_forms[] = sanitize_text_field($field);
743 }
744 update_post_meta($post_id, '_cf7sg_sub_forms', $sanitised_sub_forms);
745 //save form fields which are in tabs or tables.
746 $tt_fields = json_decode(stripslashes($_POST['cf7sg-table-fields']));
747 if(empty($tt_fields)) $tt_fields = array();
748 if(!is_array($tt_fields)) $tt_fields = array($tt_fields);
749 $sanitised_table_fields = array();
750 foreach($tt_fields as $table_fields){
751 if(is_object($table_fields)){ /** @since 2.4.2 track fields in each tables. */
752 $table_fields = get_object_vars($table_fields); /*convert to array*/
753 $table = array_keys($table_fields);
754 $table = sanitize_text_field($table[0]);
755 $table_fields = $table_fields[$table];
756 $sanitised_table_fields[$table]=array();
757 foreach($table_fields as $field) $sanitised_table_fields[$table][] = sanitize_text_field($field);
758 }else $sanitised_table_fields[] = sanitize_text_field($table_fields);
759 }
760 update_post_meta($post_id, '_cf7sg_grid_table_names', $sanitised_table_fields);
761 //tabs
762 $tt_fields = json_decode(stripslashes($_POST['cf7sg-tabs-fields']));
763 if(empty($tt_fields)) $tt_fields = array();
764 if(!is_array($tt_fields)) $tt_fields = array($tt_fields);
765 $sanitised_tab_fields = array();
766 foreach($tt_fields as $tab_field){
767 if(is_object($tab_field)){ /** @since 2.4.2 track fields in each tabs. */
768 $tab_field = get_object_vars($tab_field); /*convert to array*/
769 $tab = array_keys($tab_field);
770 $tab = sanitize_text_field($tab[0]);
771 $tab_field = $tab_field[$tab];
772 $sanitised_tab_fields[$tab]=array();
773 foreach($tab_field as $field) $sanitised_tab_fields[$tab][] = sanitize_text_field($field);
774 }else $sanitised_tab_fields[] = sanitize_text_field($tab_field);
775 }
776 update_post_meta($post_id, '_cf7sg_grid_tabs_names', $sanitised_tab_fields);
777 /** track toggled fields.
778 * @since 2.5*/
779 $tt_fields = json_decode(stripslashes($_POST['cf7sg-toggle-fields']));
780 if(empty($tt_fields)) $tt_fields = array();
781 if(!is_array($tt_fields)) $tt_fields = array($tt_fields);
782 $sanitised_toggled_fields = array();
783 foreach($tt_fields as $tgg_field){
784 if(is_object($tgg_field)){
785 $tgg_field = get_object_vars($tgg_field); /*convert to array*/
786 $tgg = array_keys($tgg_field);
787 $tgg = sanitize_text_field($tgg[0]);
788 $tgg_field = $tgg_field[$tgg];
789 $sanitised_toggled_fields[$tgg]=array();
790 foreach($tgg_field as $field) $sanitised_toggled_fields[$tgg][] = sanitize_text_field($field);
791 }else $sanitised_toggled_fields[] = sanitize_text_field($tgg_field);
792 }
793 update_post_meta($post_id, '_cf7sg_grid_toggled_names', $sanitised_toggled_fields);
794 /** @since 4.0.0 track tabbed toggles */
795 $ttgls = json_decode(stripslashes($_POST['cf7sg-tabbed-toggles']));
796 if(empty($ttgls)) $ttgls = array();
797 if(!is_array($ttgls)) $ttgls = array($ttgls);
798 update_post_meta($post_id, '_cf7sg_grid_tabbed_toggles', $ttgls);
799 /** @since 4.0.0 track grouped toggles */
800 $ttgls = json_decode(stripslashes($_POST['cf7sg-grouped-toggles']));
801 if(empty($ttgls)) $ttgls = array();
802 if(is_object($ttgls)) $ttgls = get_object_vars($ttgls); //convert to array.
803 else $ttgls = array();
804 update_post_meta($post_id, '_cf7sg_grid_grouped_toggles', $ttgls);
805 //flag tab & tables for more efficient front-end display.
806 $has_tabs = ( 'true' === $_POST['cf7sg-has-tabs']) ? true : false;
807 update_post_meta($post_id, '_cf7sg_has_tabs', $has_tabs);
808 $has_tables = ( 'true' === $_POST['cf7sg-has-tables']) ? true : false;
809 update_post_meta($post_id, '_cf7sg_has_tables', $has_tables);
810 $has_toggles = ( 'true' === $_POST['cf7sg-has-toggles']) ? true : false;
811 update_post_meta($post_id, '_cf7sg_has_toggles', $has_toggles);
812 /** @since 3.3.5 track toggles in tabs */
813 $toggle_in_tabs = json_decode(stripslashes($_POST['cf7sg-toggle-in-tabs']));
814 if(empty($toggle_in_tabs)) $toggle_in_tabs = array();
815 if(!is_array($toggle_in_tabs)) $toggle_in_tabs = array($toggle_in_tabs);
816 update_post_meta($post_id, '_cf7sg_grid_toggle_in_tabs', $toggle_in_tabs);
817 /**
818 * @since 1.2.3 disable cf7sg styling/js for non-cf7sg forms.
819 */
820 $is_cf7sg = ( 'true' === $_POST['is_cf7sg_form']) ? true : false;
821 update_post_meta($post_id, '_cf7sg_managed_form', $is_cf7sg);
822 update_post_meta($post_id, '_cf7sg_version', $this->version);
823 /** @since 3.0.0 track script classes for loading for js/css in front-end */
824 $classes = sanitize_text_field($_POST['cf7sg-script-classes']);
825 $classes = explode(',', trim($classes, ','));
826 // debug_msg($classes, 'script classes');
827 update_post_meta($post_id, '_cf7sg_script_classes', $classes);
828 /**
829 *@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.
830 */
831 /** @since 4.0.0 save user theme pref */
832 if(isset($_POST['cf7sg_codemirror_theme'])){
833 update_user_meta(get_current_user_id(),'_cf7sg_cm_theme', $_POST['cf7sg_codemirror_theme']);
834 }
835 if(isset($_POST['cf7sg_js_codemirror_theme'])){
836 update_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', $_POST['cf7sg_js_codemirror_theme']);
837 }
838 //save js file if used.
839 $path = get_stylesheet_directory();
840 if(!empty($_POST['cf7sg_js_file'])){
841 //check if the file name is changed.
842 if(!empty($_POST['cf7sg_prev_js_file']) && file_exists(ABSPATH. $_POST['cf7sg_prev_js_file'])){
843 if( !unlink(ABSPATH.$_POST['cf7sg_prev_js_file']) ) debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_js_file']);
844 }
845 if( !is_dir("$path/js/") ) mkdir("$path/js/");
846 file_put_contents( "$path/js/{$cf7_key}.js", stripslashes($_POST['cf7sg_js_file']) );
847 }else if( isset($_POST['cf7sg_js_file']) && file_exists("$path/js/{$cf7_key}.js") ) { //delete file.
848 if( !unlink("$path/js/{$cf7_key}.js") ) debug_msg("CF7SG ADMIN: unable to delete file $path/js/{$cf7_key}.js");
849 }
850 //save css file.
851 if(!empty($_POST['cf7sg_css_file'])){
852 //check if the file is changed.
853 if(!empty($_POST['cf7sg_prev_css_file']) && file_exists(ABSPATH.$_POST['cf7sg_prev_css_file'])){
854 if( !unlink(ABSPATH.$_POST['cf7sg_prev_css_file']) ) debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_css_file']);
855 }
856 if( !is_dir("$path/css/") ) mkdir("$path/css/");
857 file_put_contents( $path."/css/{$cf7_key}.css", stripslashes($_POST['cf7sg_css_file']));
858 }else if( isset($_POST['cf7sg_css_file']) && file_exists("$path/css/{$cf7_key}.css") ) { //delete file.
859 if( !unlink("$path/css/{$cf7_key}.css") ) debug_msg("CF7SG ADMIN: unable to delete file $path/css/{$cf7_key}.css");
860 }
861 //jstags comments.
862 if(empty($_POST['cf7sg_jstags_comments'])) update_post_meta($post->ID, '_cf7sg_disable_jstags_comments',1);
863 else update_post_meta($post->ID, '_cf7sg_disable_jstags_comments',0);
864 }
865 /**
866 * Print default js template,
867 * Hooked to 'cf7sg_default_custom_js_template'
868 *@since 4.0.0
869 *@param string $form_key form key.
870 */
871 public function print_default_js($form_key){
872 $js_file = str_replace(ABSPATH, '', get_stylesheet_directory()."/js/{$form_key}.js");
873 include_once 'partials/cf7-default-js.php';
874 }
875 /**
876 *
877 *
878 *@since 2.3.0
879 *@param string $new_form_id new form id to duplciate to.
880 *@param string $form_id form id to duplciate.
881 */
882 public function duplicate_form_properties($new_form_id, $form_id){
883 //these properties will be preceded with an '_' by the cf7 plugin before being duplicated.
884 $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');
885 $properties = apply_filters('cf7sg_duplicate_form_properties', $properties);
886 foreach($properties as $field){
887 $value = get_post_meta($form_id, $field, true);
888 if(!empty($value)) update_post_meta($new_form_id,$field, $value);
889 }
890 }
891 /**
892 * Duplicate form.
893 *
894 *@since 2.3.0
895 *@param string $param text_description
896 *@return string text_description
897 */
898 public function duplicate_cf7_form(){
899 global $pagenow;
900 if($pagenow != 'post.php') return;
901 if(isset($_GET['action']) && 'cf7copy' == $_GET['action']){
902 $action = 'wpcf7-copy-contact-form_' . $_GET['post'];
903 if( !wp_verify_nonce( $_GET['_wpnonce'], $action )){
904 die( 'Security check error: Try to reload the page and try again.' );
905 }
906 if ( $form = wpcf7_contact_form( $_GET['post'] ) ) {
907 $new_form = $form->copy();
908 $new_form->save();
909 $this->duplicate_form_properties($new_form->id(), $_GET['post']);
910 wp_safe_redirect( admin_url( '/post.php?post='.$new_form->id().'&action=edit' ));
911 exit;
912 }
913 }
914 }
915 /**
916 * Filtered allowed html tags & attributes, add data-button to div tags to ensure forms are saved properly.
917 * Hooked on 'wp_kses_allowed_html'
918 *@since 1.0.0
919 *@param array $allowed array of allowed tags and attributes.
920 *@param mixed $context context in which content is filtered.
921 *@return array allowed tags and ttribtues.
922 */
923 public function custom_kses_rules($allowed, $context){
924 if(is_array($context)){
925 return $allowed;
926 }
927 if('post'===$context){
928 $allowed['div']['data-button'] = true; //table buttons.
929 $allowed['div']['data-form'] = true; //sub-forms.
930 $allowed['div']['data-on'] = true; //toggles.
931 $allowed['div']['data-off'] = true; //toggles.
932 $allowed['div']['data-open'] = true; //accordion.
933 $allowed['div']['data-group'] = true; //accordion.
934 $allowed['div']['data-config-field'] = true; //cf7 plugin.
935 }
936 return $allowed;
937 }
938 /**
939 * Filters the default form loaded when a new CF7 form is created
940 * Hooked on 'wpcf7_default_template'
941 * @since 1.0
942 * @param string $template the html string for the form tempalte
943 * @param string $prop the template property required.
944 */
945 public function default_cf7_form($template, $prop){
946 if($prop !== 'form') return $template;
947 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-default-form.php');
948 return $template;
949 }
950 /**
951 * Ajax function to return the content of a cf7 form
952 * Hooked on 'wp_ajax_get_cf7_content'
953 * @since 1.0.0
954 * @return String cf7 form content.
955 **/
956 public function get_cf7_content(){
957 if( !isset($_POST['nonce']) ){
958 echo 'error, nonce failed, try to reload the page.';
959 wp_die();
960 }
961 if(!wp_verify_nonce($_POST['nonce'], 'wpcf7-save-contact-form_' . $_POST['id'], '_wpcf7nonce')){
962 echo 'error, nonce failed, try to reload the page.';
963 wp_die();
964 }
965 $cf7_key = sanitize_text_field($_POST['cf7_key']);
966 $sub_forms = get_posts(array(
967 'post_type' => $this->cf7_post_type(),
968 'post_name__in' => array($cf7_key)
969 ));
970 $form='';
971 if(!empty($sub_forms)){
972 $form = get_post_meta($sub_forms[0]->ID, '_form', true);
973 echo $form;
974 }else{
975 echo 'unable to find form '.$cf7_key;
976 }
977 wp_die();
978 }
979 /**
980 * Adds a [taxonomy] tag to cf7 forms
981 * Hooked on 'wpcf7_admin_init'
982 * @since 1.0.0
983 **/
984 public function cf7_shortcode_tags(){
985 if ( class_exists( 'WPCF7_TagGenerator' ) ) {
986 $tag_generator = WPCF7_TagGenerator::get_instance();
987 $tag_generator->add(
988 'dynamic_select', //tag id
989 __( 'dynamic-dropdown', 'cf7_2_post' ), //tag button label
990 array($this,'dynamic_tag_generator') //callback
991 );
992 $tag_generator->add(
993 'benchmark', //tag id
994 __( 'benchmark', 'cf7_2_post' ), //tag button label
995 array($this,'benchmark_tag_generator') //callback
996 );
997 }
998 }
999 /**
1000 * Dynamic select screen displayt.
1001 *
1002 * This function is called by cf7 plugin, and is registered with a hooked function above
1003 *
1004 * @since 1.0.0
1005 * @param WPCF7_ContactForm $contact_form the cf7 form object
1006 * @param array $args arguments for this form.
1007 */
1008 function dynamic_tag_generator( $contact_form, $args = '' ) {
1009 $args = wp_parse_args( $args, array() );
1010 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-dynamic-tag-display.php');
1011 }
1012 /**
1013 * Benchmark input screen displayt.
1014 *
1015 * This function is called by cf7 plugin, and is registered with a hooked function above
1016 *
1017 * @since 1.0.0
1018 * @param WPCF7_ContactForm $contact_form the cf7 form object
1019 * @param array $args arguments for this form.
1020 */
1021 function benchmark_tag_generator( $contact_form, $args = '' ) {
1022 $args = wp_parse_args( $args, array() );
1023 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-benchmark-tag.php');
1024 }
1025 /**
1026 * Print hiddend field on cf7 post submit box
1027 * Hooked on 'wpcf7_admin_misc_pub_section'
1028 * @since 1.0.0
1029 * @param string $post_id cf7 form post id .
1030 **/
1031 public function dynamic_select_choices($post_id){
1032 echo '<input id="cf72post-dynamic-select" type="hidden" name="cf72post_dynamic_select_taxonomies" />';
1033 }
1034 /**
1035 * CF7 Form saved from backend, check if dynamic-select are used
1036 * Hooked on 'wpcf7_save_contact_form'
1037 * @since 1.0.0
1038 * @param WPCF7_Contact_Form $cf7_form cf7 form object
1039 */
1040 public function save_factory_metas($cf7_form){
1041 $cf7_post_id = $cf7_form->id();
1042 //get the tags used in this form
1043 if( isset($_POST['cf72post_dynamic_select_taxonomies']) ){
1044 $created_taxonomies = array();
1045 $taxonomies = json_decode(str_replace('\"','"',$_POST['cf72post_dynamic_select_taxonomies']), true);
1046 if(empty($taxonomies)){
1047 $taxonomies = array();
1048 }
1049 foreach($taxonomies as $taxonomy){
1050 //sanitize fields before saving into the DB.
1051 foreach($taxonomy as $key=>$value){
1052 $key = sanitize_key($key);
1053 $taxonomy[$key] = sanitize_text_field($value);
1054 }
1055 $created_taxonomies[$taxonomy['slug']] = $taxonomy;
1056 }
1057 //debug_msg($created_taxonomies);
1058 $tags = $cf7_form->scan_form_tags(); //get your form tags
1059 $post_lists = $saved_lists = $system_list = array();
1060
1061 $dropdowns = get_option('_cf7sg_dynamic_dropdown_taxonomy',array());
1062 foreach($dropdowns as $id => $lists){
1063 $saved_lists = array_merge($saved_lists, $lists);
1064 }
1065 foreach($tags as $tag){
1066 if('dynamic_select' == $tag['basetype']){
1067 if(isset($tag['values'])){
1068 $slug='';
1069 foreach($tag['values'] as $values){
1070 if(0 == strpos($values, 'slug:') ){
1071 $slug = str_replace('slug:', '', $values);
1072 break;
1073 }
1074 }
1075 if(empty($slug)) continue; //not a taxonomy list.
1076 //is slug newly created?
1077 if(isset($created_taxonomies[$slug])){
1078 //store this taxonomy.
1079 $post_lists[$slug] = $created_taxonomies[$slug];
1080 }else if(isset($saved_lists[$slug])){
1081 //retain previously saved list if we are stil using it.
1082 $post_lists[$slug] = $saved_lists[$slug];
1083 }else{ //system taxonomy.
1084 $system_list[] = $slug;
1085 }
1086 //store the taxonomy slug in the cf7 metas.
1087 //$post_lists[$slug] = null;
1088 }
1089 }
1090 }
1091 //list of taxonomy to register.
1092 //unset the old value.
1093 unset($dropdowns[$cf7_post_id]);
1094 //unshift new value to top of array.
1095 $dropdowns = array($cf7_post_id => $post_lists) + $dropdowns ;
1096
1097 update_option('_cf7sg_dynamic_dropdown_taxonomy', $dropdowns);
1098 //list of system taxonomy to register
1099 $system_dropdowns = get_option('_cf7sg_dynamic_dropdown_system_taxonomy',array());
1100 $system_dropdowns[$cf7_post_id] = $system_list;
1101 update_option('_cf7sg_dynamic_dropdown_system_taxonomy', $system_dropdowns);
1102
1103 }
1104 }
1105
1106 /**
1107 * function to regsiter dyanmic dropdown taxonomies
1108 *
1109 * @since 1.0.0
1110 * @param Object $taxonomy_object std object with parameters $taxonomy_object->slug, $taxonomy_object->singular, $taxonomy_object->plural, $taxonomy_object->hierarchical .
1111 **/
1112 protected function register_dynamic_dropdown($taxonomy_array){
1113 $slug = $taxonomy_array['slug'];
1114 $name = $taxonomy_array['singular'];
1115 $plural = $taxonomy_array['plural'];
1116 $is_hierarchical = $taxonomy_array['hierarchical'];
1117
1118 $labels = array(
1119 'name' => $plural,
1120 'singular_name' => $name,
1121 'menu_name' => $plural,
1122 'all_items' => 'All '.$plural,
1123 'parent_item' => 'Parent '.$name,
1124 'parent_item_colon' => 'Parent '.$name.':',
1125 'new_item_name' => 'New '.$name.' Name',
1126 'add_new_item' => 'Add New '.$name,
1127 'edit_item' => 'Edit '.$name,
1128 'update_item' => 'Update '.$name,
1129 'view_item' => 'View '.$name,
1130 'separate_items_with_commas' => 'Separate '.$plural.' with commas',
1131 'add_or_remove_items' => 'Add or remove '.$plural,
1132 'choose_from_most_used' => 'Choose from the most used',
1133 'popular_items' => 'Popular '.$plural,
1134 'search_items' => 'Search '.$plural,
1135 'not_found' => 'Not Found',
1136 'no_terms' => 'No '.$plural,
1137 'items_list' => $plural.' list',
1138 'items_list_navigation' => $plural.' list navigation',
1139 );
1140 //labels can be modified post registration
1141 $args = array(
1142 'labels' => $labels,
1143 'hierarchical' => $is_hierarchical,
1144 'public' => false,
1145 'show_ui' => true,
1146 'show_admin_column' => false,
1147 'show_in_nav_menus' => false,
1148 'show_tagcloud' => false,
1149 'show_in_quick_edit' => false,
1150 'description' => 'Contact Form 7 dynamic dropdown taxonomy list',
1151 );
1152
1153 register_taxonomy( $slug, $this->cf7_post_type(), $args );
1154 }
1155 /**
1156 * Deactivate this plugin if CF7 plugin is deactivated.
1157 * Hooks on action 'admin_init'
1158 * @since 2.1
1159 */
1160 //public function deactivate_cf7_polylang( $plugin, $network_deactivating ) {
1161 public function check_plugin_dependency() {
1162 //if either the polylang for the cf7 plugin is not active anymore, deactive this extension
1163 if( !is_plugin_active("contact-form-7/wp-contact-form-7.php") ){
1164 deactivate_plugins( "cf7-grid-layout/cf7-grid-layout.php" );
1165 debug_msg("Deactivating Smart Grid");
1166
1167 $button = '<a href="'.network_admin_url('plugins.php').'">Return to Plugins</a></a>';
1168 wp_die( '<p><strong>CF7 smart Grid-layout Extension</strong> requires <strong>Contact Form 7</strong> plugin, and has therefore been deactivated!</p>'.$button );
1169
1170 return false;
1171 }
1172 return true;
1173 }
1174 /**
1175 * Add disabled button message on hover to cf7 messages.
1176 * Hooked to 'wpcf7_messages', see file contact-form-7/includes/contact-form-template.php fn messages().
1177 *@since 2.6.0
1178 *@param array $messages array of messages to filter.
1179 *@return array array of cf7 messages.
1180 */
1181 public function disabled_message($messages){
1182 $messages['submit_disabled'] = array(
1183 'description'
1184 => __( "Hover message for disabled submit/save button", 'cf7-grid-layout' ),
1185 'default'
1186 => __( "Disabled! To enable, check the acceptance field.", 'cf7-grid-layout' ),
1187 );
1188 /** @sicne 2.8.0 */
1189 $messages['max_table_rows'] = array(
1190 'description'
1191 => __( "Message displayed when max tables rows reached.", 'cf7-grid-layout' ),
1192 'default'
1193 => __( "You have reached the maximum number of rows.", 'cf7-grid-layout' ),
1194 );
1195 return $messages;
1196 }
1197 /**
1198 * Adds pretty pointers to help users.
1199 * Hooked on 'admin_enqueue_scripts'
1200 *@since 2.6.0
1201 *@param string $hook_suffix current page.
1202 */
1203 public function pretty_admin_pointers($hook_suffix){
1204 $screen = get_current_screen();
1205 if (!isset($screen) || $this->cf7_post_type() != $screen->post_type || in_array( $hook_suffix, array('post.php', 'post-new.php'), true)){
1206 return;
1207 }
1208 $enqueue_pointer = false;
1209 // Get array list of dismissed pointers for current user and convert it to array
1210 $user_id = get_current_user_id();
1211 $dismissed_pointers = explode( ',', get_user_meta( $user_id, 'dismissed_wp_pointers', true ) );
1212 $pointers = array();
1213 /**
1214 * Filter to add custom pointers for user iterface.
1215 * @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).
1216 * @return array an array of pointers, which will be checked agains the current user.
1217 */
1218 $filter_pointers = apply_filters('cf7sg_plugin_pointers-'.$screen->id, array());
1219 foreach($filter_pointers as $id=>$pointer){
1220 // Check if our pointer is not among dismissed ones
1221 if( !in_array( $id, $dismissed_pointers ) ) {
1222 $enqueue_pointer = true;
1223 $pointers[$id] = array($pointer[0], $pointer[1], $pointer[2], $pointer[3]);
1224 }
1225 }
1226 // Enqueue pointer CSS and JS files, if needed
1227 if( $enqueue_pointer ) {
1228 wp_enqueue_style( 'wp-pointer' );
1229 wp_enqueue_script( 'wp-pointer' );
1230 wp_enqueue_script('cf7sg-pointer-js', plugin_dir_url( __DIR__ ).'admin/js/cf7sg-pointers.js', array('jquery'), $this->version, true);
1231 wp_localize_script('cf7sg-pointer-js', 'cf7sg_pointers',
1232 array('pointers'=>$pointers, 'next'=>__('Next', 'cf7-grid-layout'))
1233 );
1234 // Add footer scripts using callback function
1235 //add_action( 'admin_print_footer_scripts', array($this, 'pretty_pointer_script') );
1236 }
1237 }
1238 /**
1239 * CF7 Table pointer notices.
1240 * Hooked on 'cf7sg_plugin_pointers-edit-wpcf7_contact_form'
1241 *@since 2.6.0
1242 *@param array $pointers array of pointers to suplement
1243 *@return array array of pointers element-id=>hmtl to display key value pairs.
1244 */
1245 public function edit_pointers($pointers){
1246 ob_start();
1247 include_once 'partials/pointers/cf7sg-pointer-update-forms.php';
1248 $content =ob_get_contents();
1249 $pointers['update_forms_pointer'] = array($content, 'left', 'center','');
1250 /* tutorials */
1251 ob_clean();
1252 include_once 'partials/pointers/cf7sg-pointer-tutorials.php';
1253 $content =ob_get_contents();
1254 $pointers['tutorials_pointer'] = array($content, 'left', 'center','a[href="admin.php?page=admin.php?page=cf7sg_help"]');
1255 /* shortcodes */
1256 ob_clean();
1257 include_once 'partials/pointers/cf7sg-pointer-shortcodes.php';
1258 $content = ob_get_clean();
1259 $pointers['cf7sg_shortcodes'] = array($content, 'top', 'top','');
1260 return $pointers;
1261 }
1262 /**
1263 * CF7 Edit pointer notices.
1264 * Hooked on 'cf7sg_plugin_pointers-wpcf7_contact_form'
1265 *@since 2.6.0
1266 *@param array $pointers array of pointers to suplement
1267 *@return array array of pointers element-id=>hmtl to display key value pairs.
1268 */
1269 public function post_pointers($pointers){
1270 ob_start();
1271 include_once 'partials/pointers/cf7sg-pointer-editor-full-screen.php';
1272 $content =ob_get_contents();
1273 //content / arrow [top,bottom,left,right] / box align [top,bottom,center] / css selector.
1274 $pointers['full_screen'] = array($content, 'left', 'center','#full-screen-cf7');
1275 /* shortcodes */
1276 ob_clean();
1277 include_once 'partials/pointers/cf7sg-pointer-editor-tabs.php';
1278 $content =ob_get_contents();
1279 $pointers['editor_tabs'] = array($content, 'right', 'center','#form-editor-tabs>ul>li.ui-tabs-active');
1280 /* shortcodes */
1281 ob_clean();
1282 include_once 'partials/pointers/cf7sg-pointer-editor-rows-control.php';
1283 $content = ob_get_contents();
1284 if(!empty($content)){
1285 $pointers['row_controls'] = array($content, 'right', 'center','#grid-form>.container>.row>.row-controls');
1286 ob_clean();
1287 }
1288 include_once 'partials/pointers/cf7sg-pointer-editor-column-control.php';
1289 $content = ob_get_contents();
1290 if(!empty($content)){
1291 $pointers['column_controls'] = array($content, 'left', 'center','#grid-form>.container>.row>.columns:first-child>.grid-column>span.icon-code');
1292 ob_clean();
1293 }
1294 include_once 'partials/pointers/cf7sg-pointer-tag-dynamic-dropdown.php';
1295 $content = ob_get_contents();
1296 $pointers['dynamic_dropdown'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="dynamic-dropdown"]');
1297 ob_clean();
1298 /* #optional-editors */
1299 include_once 'partials/pointers/cf7sg-pointers-editor-optional-js-css.php';
1300 $content = ob_get_contents();
1301 $pointers['js_css_editors'] = array($content, 'left', 'center','#optional-editors');
1302 ob_clean();
1303 include_once 'partials/pointers/cf7sg-pointer-tag-benchmark.php';
1304 $content = ob_get_clean();
1305 $pointers['benchmark'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="benchmark"]');
1306 return $pointers;
1307 }
1308 /**
1309 * Rest meta_caps for better fine tuning of user caps.
1310 * hooked to 'wpcf7_map_meta_cap'.
1311 *@since 3.0.0
1312 *@param array $caps key->value pairs of capabilities.
1313 *@return array key->value pairs of capabilities.
1314 */
1315 public function reset_meta_cap($caps){
1316 return array(
1317 'wpcf7_read_contact_form'=>'read_post',
1318 'wpcf7_edit_contact_form' =>'edit_post',
1319 'wpcf7_edit_contact_forms' => 'edit_posts',
1320 'wpcf7_edit_others_contact_forms'=>'edit_others_posts',
1321 'wpcf7_edit_published_contact_forms'=>'edit_published_posts',
1322 'wpcf7_delete_contact_form'=>'delete_post',
1323 'wpcf7_delete_contact_forms'=>'delete_posts',
1324 'wpcf7_delete_published_contact_forms'=>'delete_published_posts',
1325 'wpcf7_delete_others_contact_forms'=>'delete_others_posts',
1326 'wpcf7_publish_contact_forms'=>'publish_posts',
1327 'wpcf7_publish_contact_forms'=>'read_private_posts',
1328 'wpcf7_submit'=>'read', /** @since 3.2.1 to fix subscribers_only. */
1329 );
1330 }
1331 /**
1332 * CF7 plugin by default sets form post status to 'publish' regardless of user capability.
1333 * This functions rectifies this. Hooked to 'wp_insert_post_data'.
1334 *@since 3.0.0
1335 *@param array $data sanitised post data.
1336 *@return array post data.
1337 */
1338 public function pending_for_review($data){
1339 if($this->cf7_post_type() != $data['post_type']) return $data;
1340
1341 $post_type_object = get_post_type_object( $this->cf7_post_type() );
1342 //check if user can publish.
1343 if(!current_user_can($post_type_object->cap->publish_posts) && $data['post_status']=='publish'){
1344 $data['post_status']='pending';
1345 }
1346 // debug_msg('post status '.$data['post_status']);
1347 return $data;
1348 }
1349 /**
1350 * Enable all cf7 capabilites for editors.
1351 * Hooked to action 'admin_init'.
1352 *@since 3.0.0
1353 */
1354 public function enable_cf7_editor_role(){
1355 global $wp_roles;
1356 if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles();
1357 $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');
1358 $fe = $wp_roles->get_role('editor');
1359 if(!empty($fe)){ /** @since 3.0.3 in case editor role is deleted */
1360 foreach($caps as $cap) $fe->add_cap($cap);
1361 }
1362 $caps[]='wpcf7_manage_integration';
1363 $ad = $wp_roles->get_role('administrator');
1364 if(!empty($ad)){ /** @since 3.0.3 in case admin role is deleted */
1365 foreach($caps as $cap) $ad->add_cap($cap);
1366 }
1367
1368 /** @since 3.1.3 redirect cf7 plugin pages*/
1369 global $pagenow;
1370 if ( $pagenow == 'admin.php' && isset( $_GET['page'] ) ) {
1371 $url = '';
1372 switch($_GET['page']){
1373 case 'wpcf7-new':
1374 $url = "post-new.php?post_type=wpcf7_contact_form" ;
1375 break;
1376 case 'wpcf7':
1377 if(isset($_GET['post'])) $url = "post.php?post={$_GET['post']}&action=edit&classic-editor";
1378 else $url = "edit.php?post_type=wpcf7_contact_form";
1379 break;
1380 }
1381 if(!empty($url)){
1382 wp_redirect( admin_url( $url ));
1383 exit;
1384 }
1385 }
1386 }
1387 /**
1388 * Add grid helper hooks for individual tags.
1389 * Hooked to action 'cf7sg_ui_grid_helper_hooks'.
1390 *@since 3.3.0
1391 */
1392 public function print_helper_hooks(){
1393 require_once plugin_dir_path( __FILE__ ) .'partials/helpers/cf7sg-form-fields.php';
1394 }
1395 /**
1396 * Setup mailtags or toggles.
1397 *
1398 *@since 4.0.0
1399 *@param string $param text_description
1400 *@return string text_description
1401 */
1402 public function setup_cf7_mailtags($mailtags = array()){
1403 // return $mailtags;
1404 $contact_form = WPCF7_ContactForm::get_current();
1405 $fields = get_post_meta($contact_form->id(), '_cf7sg_grid_toggled_names', true);
1406 //update_post_meta($post_id, '_cf7sg_grid_tabbed_toggles', $ttgls);
1407 if(!empty($fields)){
1408 $toggles = array_keys($fields);
1409 $groups = get_post_meta($contact_form->id(), '_cf7sg_grid_grouped_toggles', true);
1410 if(!empty($groups)){
1411 foreach($groups as $group=>$grp_toggles){
1412 $toggles = array_diff($toggles, $grp_toggles);
1413 array_push($toggles, $group);
1414 }
1415 }
1416 foreach($toggles as $tgl) $mailtags[]= 'cf7sg-toggle-'.$tgl;
1417 }
1418 //add a general form tag.
1419 $mailtags[]= 'cf7sg-form-'.get_cf7form_key($contact_form->id());
1420 return $mailtags;
1421 }
1422 /**
1423 * Funciton to to initialise admin notices.
1424 * hooked on 'admin_init'
1425 *@since 4.1.0
1426 *@param boolean $init initiliase notices or not
1427 */
1428 public function init_notices(){
1429 $grid_settings = get_option('cf7sg-plugin-version', array());
1430 $warning = false;
1431 if(isset($grid_settings['update']) and CF7SG_VERSION_FORM_UPDATE==CF7_GRID_VERSION){
1432 $warning = true;
1433 }else if(isset($grid_settings['fv']) ) {
1434 if(version_compare($grid_settings['fv'], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true;
1435 }else{ //check the forms directly
1436 global $wpdb;
1437 $result = $wpdb->get_col("SELECT pm.meta_value FROM {$wpdb->postmeta} as pm
1438 INNER JOIN {$wpdb->posts} as p on p.ID = pm.post_id
1439 WHERE p.post_type = 'wpcf7_contact_form'
1440 AND pm.meta_key = '_cf7sg_version'
1441 ORDER BY pm.meta_key
1442 ");
1443 if(!empty($result) and version_compare($result[0], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true;
1444 }
1445 if($warning){
1446 $notices= array(
1447 'admin.php'=>array(),
1448 'plugins.php'=>array(),
1449 'post.php'=>array(),
1450 'edit.php'=>array(),
1451 );
1452 $nonce = wp_create_nonce( 'cf7sg_notice-'.CF7_GRID_VERSION ); //unique.
1453 $link = admin_url('edit.php?post_type=wpcf7_contact_form');
1454 /* translators: %s is the url to the forms admin table */
1455 $msg = __('You need to <strong>update</strong> your <a href="%s">forms</a>','cf7-grid-layout');
1456 $notice = array(
1457 'nonce'=>$nonce,
1458 'type'=>'notice-warning', //[notice-update|notice-error]
1459 'msg'=>sprintf($msg , $link)
1460 );
1461 $notices['plugins.php']['cf7sg']=$notice;
1462 $notices['edit.php']['post_type=wpcf7_contact_form']=$notice;
1463
1464 update_option('cf7sg-admin-notices', $notices);
1465 }
1466
1467 update_option('cf7sg-plugin-version', array(
1468 'gv'=>CF7_GRID_VERSION,
1469 'fv'=>CF7SG_VERSION_FORM_UPDATE
1470 ));
1471 }
1472 /**
1473 * Display admin notices
1474 * Hooked on 'admin_notices'
1475 *@since 4.1.0
1476 *@param string $param text_description
1477 *@return string text_description
1478 */
1479 public function admin_notices(){
1480 //check if we have any notices.
1481 global $pagenow;
1482 $notices = get_option('cf7sg-admin-notices', array());
1483 if(empty($notices)) return;
1484
1485 if(!isset($notices[$pagenow])) return;
1486
1487 // debug_msg($notices[$pagenow], $pagenow);
1488
1489 foreach($notices[$pagenow] as $key=>$notice){
1490 switch(true){
1491 case strpos($key, 'page=') !== false && isset($_GET['page']) && $_GET['page'] === str_replace('page=','',$key):
1492 case strpos($key, 'post_type=') !== false && isset($_GET['post_type']) && $_GET['post_type'] === str_replace('post_type=','',$key):
1493 case $key==='any':
1494 case $key==='cf7sg':
1495 $dismiss = $notice['nonce'].'-forever';
1496 if ( ! PAnD::is_admin_notice_active( $dismiss ) ) {
1497 unset($notices[$pagenow]);
1498 update_option('cf7sg-admin-notices', $notices);
1499 continue 2; //continue foreach loop.
1500 }
1501 ?>
1502 <div data-dismissible="<?=$dismiss?>" class="notice <?=$notice['type']?> is-dismissible"><p><?=$notice['msg']?></p></div>
1503 <?php
1504 break;
1505 }
1506 }
1507 }
1508 /**
1509 * ajax request to validate plugin update.
1510 * Hooked on 'wp_ajax_validate_cf7sg_version_update'
1511 * @since 4.1.0
1512 */
1513 public function validate_cf7sg_version_update(){
1514 if( !isset($_POST['nonce']) or !wp_verify_nonce($_POST['nonce'], 'cf7sg_udpate_plugin') ){
1515 echo 'error, nonce failed, try to reload the page.';
1516 wp_die();
1517 }
1518 $grid_settings = get_option('cf7sg-plugin-version', array());
1519 $warning = false;
1520 if(isset($grid_settings['fv']) ) {
1521 if(version_compare($grid_settings['fv'], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true;
1522 }
1523 $grid_settings['fv'] = CF7SG_VERSION_FORM_UPDATE;
1524 $grid_settings['gv'] = CF7_GRID_VERSION;
1525 $grid_settings['update'] = true;
1526 update_option('cf7sg-plugin-version', $grid_settings);
1527 $update_msg = __('Version validated, thank you!','cf7-grid-layout');
1528 if($warning){
1529 $link = admin_url('edit.php?post_type=wpcf7_contact_form');
1530 /* translators: %s link to form table */
1531 $update_msg = __('You need to <strong>update</strong> your <a href="%s">forms</a>','cf7-grid-layout');
1532 $update_msg = sprintf( $update_msg, $link);
1533 }
1534 echo $update_msg;
1535 wp_die();
1536 }
1537 /**
1538 * Check if plugin is getting updated.
1539 * Hooked to 'upgrader_post_install'.
1540 *@since 4.1.0
1541 *@param array $param text_description
1542 *@param array $extras text_description
1543 *@param array $result text_description
1544 *@return array responses for the upgrade process
1545 */
1546 public function post_plugin_upgrade($response, $extras, $result){
1547 if( ( isset($response['destination_name']) and 'cf7-grid-layout' == $response['destination_name'] )
1548 or ( isset($extras['plugin']) and 'cf7-grid-layout/cf7-grid-layout.php' == $extras['plugin'] ) ){
1549 $grid_settings = get_option('cf7sg-plugin-version', array());
1550 $grid_settings['update'] = true;
1551 update_option('cf7sg-plugin-version', $grid_settings);
1552 }
1553 return $response;
1554 }
1555 }
1556