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

1,243 lines 49.6 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 if( in_array($page, array('toplevel_page_wpcf7', 'contact_page_wpcf7-new')) ) return;
112
113 $screen = get_current_screen();
114 if (empty($screen) || $this->cf7_post_type() != $screen->post_type){
115 return;
116 }
117 $plugin_dir = plugin_dir_url( __DIR__ );
118 switch( $screen->base ){
119 case 'post':
120 wp_enqueue_style( "cf7-grid-post-css", $plugin_dir . 'admin/css/cf7-grid-layout-post.css', array(), $this->version, 'all' );
121 //dynamic tag
122 wp_enqueue_style('cf7sg-dynamic-tag-css', $plugin_dir . 'admin/css/cf7sg-dynamic-tag.css', array(), $this->version, 'all' );
123 //benchmark tag
124 wp_enqueue_style('cf7sg-benchmark-tag-css', $plugin_dir . 'admin/css/cf7sg-benchmark-tag.css', array(), $this->version, 'all' );
125 //codemirror
126 wp_enqueue_style( "codemirror-css", $plugin_dir . 'assets/codemirror/codemirror.css', array(), $this->version, 'all' );
127 wp_enqueue_style( "codemirror-theme-css", $plugin_dir . 'assets/codemirror/theme/paraiso-light.css', array(), $this->version, 'all' );
128 wp_enqueue_style( "codemirror-foldgutter-css", $plugin_dir . 'assets/codemirror/addon/fold/foldgutter.css', array(), $this->version, 'all' );
129 wp_enqueue_style( "codemirror-dialog-css", $plugin_dir . 'assets/codemirror/addon/dialog/dialog.css', array(), $this->version, 'all' );
130 wp_enqueue_style( "codemirror-matchesonscrollbar-css", $plugin_dir . 'assets/codemirror/addon/search/matchesonscrollbar.css', array(), $this->version, 'all' );
131 wp_enqueue_style( 'smart-grid-css', $plugin_dir . 'assets/css.gs/smart-grid.admin.css', array(), $this->version, 'all');
132 wp_enqueue_style('dashicons');
133 wp_enqueue_style('select2-style', $plugin_dir . 'assets/select2/css/select2.min.css', array(), $this->version, 'all' );
134 break;
135 case 'edit': //table.
136 wp_enqueue_style( $this->plugin_name, $plugin_dir . 'admin/css/cf7-grid-layout-admin.css', array(), $this->version, 'all' );
137
138 break;
139 }
140
141 }
142
143 /**
144 * Register the JavaScript for the admin area.
145 *
146 * @since 1.0.0
147 */
148 public function enqueue_scripts($page) {
149 global $post;
150 //debug_msg($screen, $this->custom_type );
151 $plugin_dir = plugin_dir_url( __DIR__ );
152 if( in_array($page, array('toplevel_page_wpcf7', 'contact_page_wpcf7-new')) ){
153 wp_enqueue_script( $this->plugin_name, $plugin_dir . 'admin/js/cf7-grid-layout-admin.js', array( 'jquery' ), $this->version, true );
154 return;
155 }
156 $screen = get_current_screen();
157 if ($this->cf7_post_type() != $screen->post_type){
158 return;
159 }
160 switch( $screen->base ){
161 case 'post':
162 /* register codemirror editor & addons. */
163 //codemirror script
164 wp_register_script( 'cf7-codemirror-js',
165 $plugin_dir . 'assets/codemirror/codemirror.js',
166 null, "5.32", true
167 );
168 /** @since 3.1.2 initialise codemirror after library load and parse as attribute to anonymous functtion in cf7-grid-codemirror.js */
169 wp_add_inline_script('cf7-codemirror-js',
170 'var codeMirror_5_32 = CodeMirror(document.getElementById("cf7-codemirror"),
171 {
172 value: "",
173 extraKeys: {"Ctrl-Space": "autocomplete"},
174 lineNumbers: true,
175 styleActiveLine: true,
176 matchBrackets: true,
177 tabSize:2,
178 mode: "htmlmixed",
179 lineWrapping: true,
180 addModeClass: true,
181 foldGutter: true,
182 autofocus:false,
183 gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
184 });');
185 //fold code
186 wp_enqueue_script( 'codemirror-foldcode-js',
187 $plugin_dir . 'assets/codemirror/addon/fold/foldcode.js',
188 array('cf7-codemirror-js'), $this->version, true
189 );
190 wp_enqueue_script( 'codemirror-foldgutter-js',
191 $plugin_dir . 'assets/codemirror/addon/fold/foldgutter.js',
192 array('cf7-codemirror-js'), $this->version, true
193 );
194 wp_enqueue_script( 'codemirror-indent-fold-js',
195 $plugin_dir . 'assets/codemirror/addon/fold/indent-fold.js',
196 array('cf7-codemirror-js'), $this->version, true
197 );
198 wp_enqueue_script( 'codemirror-xml-fold-js',
199 $plugin_dir . 'assets/codemirror/addon/fold/xml-fold.js',
200 array('cf7-codemirror-js'), $this->version, true
201 );
202 wp_enqueue_script( 'codemirror-brace-fold-js',
203 $plugin_dir . 'assets/codemirror/addon/fold/brace-fold.js',
204 array('cf7-codemirror-js'), $this->version, true
205 );
206 wp_enqueue_script( 'codemirror-comment-fold-js',
207 $plugin_dir . 'assets/codemirror/addon/fold/comment-fold.js',
208 array('cf7-codemirror-js'), $this->version, true
209 );
210 wp_enqueue_script( 'codemirror-mixed-js',
211 $plugin_dir . 'assets/codemirror/mode/htmlmixed/htmlmixed.js',
212 array('cf7-codemirror-js'), $this->version, true
213 );
214 wp_enqueue_script( 'codemirror-javascript-js',
215 $plugin_dir . 'assets/codemirror/mode/javascript/javascript.js',
216 array('cf7-codemirror-js'), $this->version, true
217 );
218 wp_enqueue_script( 'codemirror-xml-js',
219 $plugin_dir . 'assets/codemirror/mode/xml/xml.js',
220 array('cf7-codemirror-js'), $this->version, true
221 );
222 wp_enqueue_script( 'codemirror-css-js',
223 $plugin_dir . 'assets/codemirror/mode/css/css.js',
224 array('cf7-codemirror-js'), $this->version, true
225 );
226 //overlay for shortcode highligh
227 wp_enqueue_script( 'codemirror-overlay-js',
228 $plugin_dir . 'assets/codemirror/addon/mode/overlay.js',
229 array('cf7-codemirror-js'), $this->version, true
230 );
231 /**
232 * @since 1.3.0 enable search codemirror
233 */
234 //overlay for shortcode highligh
235 wp_enqueue_script( 'codemirror-search-js',
236 $plugin_dir . 'assets/codemirror/addon/search/search.js',
237 array('cf7-codemirror-js'), $this->version, true
238 );
239 wp_enqueue_script( 'codemirror-jumptoline-js',
240 $plugin_dir . 'assets/codemirror/addon/search/jump-to-line.js',
241 array('cf7-codemirror-js'), $this->version, true
242 );
243 wp_enqueue_script( 'codemirror-matchesonscrollbar-js',
244 $plugin_dir . 'assets/codemirror/addon/search/matchesonscrollbar.js',
245 array('cf7-codemirror-js'), $this->version, true
246 );
247 wp_enqueue_script( 'codemirror-searchcursor-js',
248 $plugin_dir . 'assets/codemirror/addon/search/searchcursor.js',
249 array('cf7-codemirror-js'), $this->version, true
250 );
251 wp_enqueue_script( 'codemirror-annotatescrollbar-js',
252 $plugin_dir . 'assets/codemirror/addon/scroll/annotatescrollbar.js',
253 array('cf7-codemirror-js'), $this->version, true
254 );
255 wp_enqueue_script( 'codemirror-dialog-js',
256 $plugin_dir . 'assets/codemirror/addon/dialog/dialog.js',
257 array('cf7-codemirror-js'), $this->version, true
258 );
259
260 //js beautify
261 wp_enqueue_script( 'beautify-js',
262 $plugin_dir . 'assets/beautify/beautify.js',
263 array('jquery'), $this->version, true
264 );
265 wp_enqueue_script( 'beautify-html-js',
266 $plugin_dir . 'assets/beautify/beautify-html.js',
267 array('beautify-js'), $this->version, true
268 );
269 wp_enqueue_script('jquery-select2', $plugin_dir . 'assets/select2/js/select2.min.js', array( 'jquery' ), $this->version, true );
270
271 //enqueue the cf7 scripts.
272 wpcf7_admin_enqueue_scripts( 'wpcf7' );
273 wp_enqueue_script('jquery-clibboard', $plugin_dir . 'assets/clipboard/clipboard.min.js', array('jquery'),$this->version,true);
274 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 );
275 wp_localize_script(
276 'cf7-grid-codemirror-js',
277 'cf7sgeditor',
278 array(
279 'mode' => apply_filters('cf7sg_admin_editor_mode', 'shortcode', $post->post_name),
280 'theme' => apply_filters('cf7sg_admin_editor_theme', 'paraiso-light', $post->post_name)
281 )
282 );
283 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 );
284 wp_localize_script(
285 $this->plugin_name,
286 'cf7grid',
287 array(
288 'preHTML' => apply_filters('cf7sg_pre_cf7_field_html', '<div class="field"><label></label>', $post->post_name),
289 'postHTML' => apply_filters('cf7sg_post_cf7_field_html', '<p class="info-tip"></p></div>', $post->post_name),
290 'requiredHTML' => apply_filters('cf7sg_required_cf7_field_html', '<em>*</em>', $post->post_name),
291 'ui' => apply_filters('cf7sg_grid_ui', true, $post->post_name)
292 )
293 );
294 wp_enqueue_script( 'cf7sg-dynamic-tag-js', $plugin_dir . 'admin/js/cf7sg-dynamic-tag.js', array('jquery','wpcf7-admin-taggenerator' ), $this->version, true );
295 wp_enqueue_script( 'cf7-benchmark-tag-js', $plugin_dir . 'admin/js/cf7-benchmark-tag.js', array('jquery','wpcf7-admin-taggenerator' ), $this->version, true );
296 /** @since 3.2.0 */
297 wp_enqueue_script('cf7sg-mail-tag-js', $plugin_dir.'admin/js/mail-tag-helper.js', array('jquery','jquery-clibboard'));
298 wp_localize_script('cf7sg-mail-tag-js','mailTagHelper',
299 array(
300 'msg'=>__('Click to copy!','cf7-grid-layout'),
301 'filter'=> __('Filter mailTag %s', 'cf7-grid-layout')
302 )
303 );
304 /** @since 3.3.0enqueue ui-grid helpers js */
305 wp_enqueue_script('ui-grid-helpers-js', $plugin_dir.'admin/js/ui-custom-helper.js', array('jquery'));
306 do_action('cf7sg_enqueue_admin_editor_scripts');
307 break;
308 case 'edit':
309 //wp_enqueue_script( $this->plugin_name.'-quick-edit', plugin_dir_url( __FILE__ ) . 'js/cf7-grid-layout-quick-edit.js', false, $this->version, true );
310
311 break;
312 }
313 }
314
315 /**
316 * Adds a new sub-menu to replace the 'Add New' CF7 menu
317 * Add a new sub-menu to the Contact main menu, as well as remove the current default
318 *
319 */
320 public function add_cf7_sub_menu(){
321
322 $hook = add_submenu_page(
323 'wpcf7',
324 __cf7sg( 'Edit Contact Form'),
325 __cf7sg( 'Add New'),
326 'wpcf7_edit_contact_forms',
327 'post-new.php?post_type=wpcf7_contact_form'
328 );
329 //initial cf7 object when creating new form
330 add_action( 'load-' . $hook, array($this, 'setup_cf7_object'));
331 //remove_submenu_page( $menu_slug, $submenu_slug );
332 remove_submenu_page( 'wpcf7', 'wpcf7-new' );
333 remove_meta_box('slugdiv', $this->cf7_post_type(), 'normal');
334 }
335 /**
336 * Change the submenu order
337 * @since 1.0.0
338 */
339 public function change_cf7_submenu_order( $menu_ord ) {
340 global $submenu;
341 // Enable the next line to see all menu orders
342 if(!isset($submenu['wpcf7']) ){
343 return $menu_ord;
344 }
345 if( is_network_admin() ){
346 return $menu_ord;
347 }
348 $arr = array();
349 foreach($submenu['wpcf7'] as $menu){
350 switch($menu[2]){
351 case 'post-new.php?post_type=wpcf7_contact_form':
352 //push to the front
353 array_unshift($arr, $menu);
354 break;
355 default:
356 $arr[]=$menu;
357 break;
358 }
359 }
360 $submenu['wpcf7'] = $arr;
361 return $menu_ord;
362 }
363 /**
364 * Modify the regsitered cf7 post tppe
365 * THis function enables public capability and amind UI visibility for the cf7 post type. Hooked late on `register_post_type_args`
366 * @since 1.0.0
367 * @param Array $args array of post parameters being registered
368 * @param String $post_type post type breing resgistered
369 */
370
371 public function modify_cf7_post_type_args($args, $post_type){
372 if($post_type === $this->cf7_post_type() ) {
373 // debug_msg($args, 'pre-args');
374 // $system_dropdowns = get_option('_cf7sg_dynamic_dropdown_system_taxonomy',array());
375 /** @since 2.8.3 add wpcf7_type (registered in assets/cf7-table.php) taxonomy to cf7 post type */
376 $system_taxonomy = array('wpcf7_type');
377 // if(!empty($system_dropdowns)){
378 // foreach($system_dropdowns as $id=>$list){
379 // $system_taxonomy = array_merge($system_taxonomy, $list);
380 // }
381 // }
382 if(!empty($args['taxonomies'])){
383 $system_taxonomy = array_merge($args['taxonomies'], $system_taxonomy);
384 $system_taxonomy = array_unique($system_taxonomy);
385 }
386 $args['taxonomies'] = $system_taxonomy;
387
388 $args['public'] = false;
389 $args['show_ui']= true;
390 $args['show_in_menu']= 'wpcf7';
391 $args['supports'] = array('title', 'author');
392 $args['labels']['add_new_item'] = 'Add New Form';
393 $args['labels']['edit_item'] = 'Edit Form';
394 $args['labels']['new_item'] = 'New Form';
395 $args['labels']['view_item'] = 'View Form';
396 $args['labels']['view_items'] = 'View Forms';
397 $args['labels']['search_items'] = 'Search Forms';
398 $args['labels']['not_found'] = 'No forms found.';
399 $args['labels']['not_found_in_trash'] = 'No forms found in Trash.';
400 $args['labels']['parent_item_colon'] = '';
401 $args['labels']['attributes'] = 'Form Attributes';
402 $args['labels']['insert_into_item'] = 'Insert into form';
403 $args['labels']['uploaded_to_this_item'] = 'Uploaded to this form';
404 $args['labels']['filter_items_list'] = 'Filter forms list';
405 $args['labels']['items_list_navigation'] = 'Forms list navigation';
406 $args['labels']['items_list'] = 'Forms list';
407 /** @since 2.8.1 fix missing delete_posts notices*/
408 // $args['capabilities']['delete_posts']= 'wpcf7_delete_posts';
409 /** @since 3.0.0 enable better capability management */
410 // $args['capability_type'] = 'page';
411
412 $args['map_meta_cap']=true; //allow finer capability mapping.
413 $args['capabilities']['edit_post'] = 'wpcf7_edit_contact_form';
414 $args['capabilities']['read_post'] = 'wpcf7_read_contact_form';
415 $args['capabilities']['delete_post'] = 'wpcf7_delete_contact_form';
416 $args['capabilities']['edit_posts'] = 'wpcf7_edit_contact_forms';
417 $args['capabilities']['edit_others_posts']= 'wpcf7_edit_others_contact_forms';
418 $args['capabilities']['edit_published_posts']= 'wpcf7_edit_published_contact_forms';
419 $args['capabilities']['delete_posts']= 'wpcf7_delete_contact_forms';
420 $args['capabilities']['delete_published_posts']= 'wpcf7_delete_published_contact_forms';
421 $args['capabilities']['delete_others_posts']= 'wpcf7_delete_others_contact_forms';
422 $args['capabilities']['publish_posts']= 'wpcf7_publish_contact_forms';
423 $args['capabilities']['read_private_posts']= 'wpcf7_publish_contact_forms';
424
425 // debug_msg($args);
426 }
427 return $args;
428 }
429 /**
430 * Register custom taxonomy for dynamic dropdown lists
431 * Hooked on 'init'
432 * @since 1.0.0
433 *
434 **/
435 public function register_dynamic_dropdown_taxonomy(){
436 //register the dynamic dropdown taxonomies.
437 $dropdowns = get_option('_cf7sg_dynamic_dropdown_taxonomy',array());
438 //debug_msg($dropdowns);
439 $created = array();
440 foreach($dropdowns as $post_lists){
441 foreach($post_lists as $slug=>$taxonomy){
442 if(!isset($created[$slug])){
443 if(is_array($taxonomy)){
444 $this->register_dynamic_dropdown($taxonomy);
445 $created[$slug] = $slug;
446 }
447 }
448 }
449 }
450 }
451
452 /**
453 * Function to add the metabox to the cf7 post edit screen
454 * This adds the main editor, hooked on 'add_meta_boxes'
455 * @since 1.0.0
456 */
457 public function main_editor_meta_box() {
458 //add_meta_box( string $id, string $title, callable $callback, string $screen, string $context, string $priority, array $callback_args)
459 if( post_type_exists( $this->cf7_post_type() ) ) {
460 add_meta_box( 'meta-box-main-cf7-editor',
461 __cf7sg( 'Edit Contact Form' ),
462 array($this , 'main_editor_metabox_display'),
463 $this->cf7_post_type(),
464 'normal',
465 'high'
466 );
467 }
468 }
469 /**
470 * Function called on page load when new form is created
471 * hooked to 'load-{page-hook}'
472 * @since 1.0.0
473 **/
474 public function setup_cf7_object(){
475 $args = array();
476 /**
477 * Fix locale setup for new forms using polylang.
478 * @since 2.1.4
479 */
480 if(isset($_GET['locale'])){
481 $args['locale'] = $_GET['locale'];
482 }else if(isset($_GET['new_lang'])){
483 //check for polylang
484 $locale = $_GET['new_lang'];
485 if(function_exists('pll_languages_list')){
486 $langs = pll_languages_list();
487 $locales = pll_languages_list(array('fields'=>'locale'));
488 foreach($langs as $idx => $lang){
489 if($lang == $locale){
490 $locale = $locales[$idx];
491 }
492 }
493 }
494 $args['locale'] =$locale;
495 }else $args['locale'] = get_locale();
496 WPCF7_ContactForm::get_template( $args);
497 }
498 /**
499 * Callback function to disolay the main editor meta box
500 * @since 1.0.0
501 */
502 public function main_editor_metabox_display($post){
503 if('auto-draft' !== $post->post_status){
504 wpcf7_contact_form($post); //set the post
505 }
506 $post_id = $post->ID;
507 $cf7_form = wpcf7_get_current_contact_form();
508
509 if ( ! $cf7_form ) {
510 $cf7_form = WPCF7_ContactForm::get_template();
511 }
512
513 // if(empty($post)){
514 // $post_id = -1;
515 // }else{
516 // $post_id = $post->ID;
517 // }
518 require_once WPCF7_PLUGIN_DIR . '/admin/includes/editor.php';
519 require_once plugin_dir_path( __FILE__ ) . 'partials/cf7-admin-editor-display.php';
520 }
521
522 /**
523 * Function to add the metabox to the cf7 post edit screen
524 * This adds the main editor, hooked on 'add_meta_boxes'
525 * @since 1.0.0
526 */
527 public function info_meta_box() {
528 //add_meta_box( string $id, string $title, callable $callback, string $screen, string $context, string $priority, array $callback_args)
529 if(post_type_exists( $this->cf7_post_type() ) ) {
530 add_meta_box( 'meta-box-cf7-info',
531 __cf7sg( 'Information' ),
532 array($this , 'info_metabox_display'),
533 $this->cf7_post_type(),
534 'side',
535 'high'
536 );
537 }
538 }
539 /**
540 * Re-introduces the wordpress 'wpcf7_admin_misc_pub_section' for plugins to add their fields for submission
541 * Hooked to 'post_submitbox_misc_actions' which fires after post dat/time parameters are printed
542 * @since 1.0.0
543 * @param WP_Post $post post object being edited/created.
544 **/
545 public function cf7_post_submit_action($post){
546 if($this->cf7_post_type() == $post->post_type){
547 do_action( 'wpcf7_admin_misc_pub_section', $post->ID );
548 }
549 }
550 /**
551 * Callback function to disolay the main editor meta box
552 * @since 1.0.0
553 */
554 public function info_metabox_display($post){
555 require_once plugin_dir_path( __FILE__ ) . 'partials/cf7-info-metabox-display.php';
556 }
557 /**
558 * Function to add the metabox to the cf7 post edit screen
559 * This adds the helper, hooked on 'add_meta_boxes'
560 * @since 1.1.0
561 */
562 public function helper_meta_box() {
563 //add_meta_box( string $id, string $title, callable $callback, string $screen, string $context, string $priority, array $callback_args).
564 if(post_type_exists( $this->cf7_post_type() ) ) {
565 add_meta_box( 'meta-box-cf7sg-helper',
566 __( 'Actions & Filters', 'cf7-grid-layout' ),
567 array($this , 'helper_metabox_display'),
568 $this->cf7_post_type(),
569 'side',
570 'low'
571 );
572 }
573 }
574 /**
575 * Callback function to disolay the helper meta box
576 * @since 1.0.0
577 */
578 public function helper_metabox_display($post){
579 require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-helper-metabox-display.php';
580 }
581 /**
582 * Display the editor panels (wpcf7 / codemirror / grid)
583 *
584 * @since 1.0.0
585 * @param string $p1 .
586 * @return string $p2 .
587 **/
588 public function grid_editor_panel($form_post){
589 require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-grid-layout-admin-display.php';
590 }
591 /**
592 * Save cf7 post using ajax
593 * Hooked to 'save_post_wpcf7_contact_form'
594 * @since 1.0.0
595 **/
596 public function save_post($post_id, $post, $update){
597 //make sure this is the edit page and not a quick-edit.
598 if( !isset($_POST['_wpcf7nonce']) ){
599 return;
600 }
601 //validate the nonce.
602 check_admin_referer( 'wpcf7-save-contact-form_' . $post_id, '_wpcf7nonce');
603
604 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){
605 return;
606 }
607
608 switch($post->post_status){
609 case 'auto-draft':
610 case 'trash':
611 return;
612 default:
613 break;
614 }
615
616 // debug_msg($_POST, 'submitted ');
617 $args = $_REQUEST;
618 $args['id'] = $post_id;
619
620 $args['title'] = isset( $_POST['post_title'] ) ? sanitize_text_field($_POST['post_title'], 'Contact Form', 'save') : null;
621 $args['locale'] = isset( $_POST['wpcf7-locale'] ) ? sanitize_text_field($_POST['wpcf7-locale']) : null;
622 $args['form'] = '';
623 $allowed_tags = wp_kses_allowed_html( 'post' ); //filtered in function below.
624 /** @since 2.10.0 alllow custom input html*/
625 $allowed_tags['input']=array( //add additional input html elements
626 'type'=>1,
627 'class'=>1,
628 'id'=>1,
629 'value'=>1,
630 'data-*'=>1,
631 );
632 $allowed_tags['script']=array('type'=>1);
633 $allowed_tags = apply_filters('cf7sg_kses_allowed_html',$allowed_tags, $_POST['post_name']);
634 if(isset( $_POST['wpcf7-form'] )){
635 $args['form'] = wp_kses($_POST['wpcf7-form'], $allowed_tags);
636 }
637 $args['mail'] = isset( $_POST['wpcf7-mail'] ) ? wpcf7_sanitize_mail( $_POST['wpcf7-mail'] ): array();
638 $args['mail_2'] = isset( $_POST['wpcf7-mail-2'] ) ? wpcf7_sanitize_mail( $_POST['wpcf7-mail-2'] ): array();
639 $args['messages'] = isset( $_POST['wpcf7-messages'] ) ? $_POST['wpcf7-messages'] : array();
640 foreach($args['messages'] as $key=>$value){
641 $args['messages'][$key] = sanitize_text_field($value);
642 }
643 $args['additional_settings'] = isset( $_POST['wpcf7-additional-settings'] ) ? sanitize_textarea_field($_POST['wpcf7-additional-settings']) : '';
644
645 //need to unhook this function so as not to loop infinitely
646 //debug_msg($args, 'saving cf7 posts');
647 remove_action('save_post_wpcf7_contact_form', array($this, 'save_post'), 10,3);
648 $contact_form = wpcf7_save_contact_form( $args );
649 add_action('save_post_wpcf7_contact_form', array($this, 'save_post'), 10,3);
650 //flag as a grid form
651 //update_post_meta($post_id, 'cf7_grid_form', true); removed since v2.3 as not used.
652 //save sub-forms if any
653 $sub_forms = json_decode(stripslashes($_POST['cf7sg-embeded-forms']));
654 if(empty($sub_forms)) $sub_forms = array();
655 if(!is_array($sub_forms)) $sub_forms = array($sub_forms);
656 $sanitised_sub_forms = array();
657 foreach($sub_forms as $field){
658 $sanitised_sub_forms[] = sanitize_text_field($field);
659 }
660 update_post_meta($post_id, '_cf7sg_sub_forms', $sanitised_sub_forms);
661 //save form fields which are in tabs or tables.
662 $tt_fields = json_decode(stripslashes($_POST['cf7sg-table-fields']));
663 if(empty($tt_fields)) $tt_fields = array();
664 if(!is_array($tt_fields)) $tt_fields = array($tt_fields);
665 $sanitised_table_fields = array();
666 foreach($tt_fields as $table_fields){
667 if(is_object($table_fields)){ /** @since 2.4.2 track fields in each tables. */
668 $table_fields = get_object_vars($table_fields); /*convert to array*/
669 $table = array_keys($table_fields);
670 $table = sanitize_text_field($table[0]);
671 $table_fields = $table_fields[$table];
672 $sanitised_table_fields[$table]=array();
673 foreach($table_fields as $field) $sanitised_table_fields[$table][] = sanitize_text_field($field);
674 }else $sanitised_table_fields[] = sanitize_text_field($table_fields);
675 }
676 update_post_meta($post_id, '_cf7sg_grid_table_names', $sanitised_table_fields);
677 //tabs
678 $tt_fields = json_decode(stripslashes($_POST['cf7sg-tabs-fields']));
679 if(empty($tt_fields)) $tt_fields = array();
680 if(!is_array($tt_fields)) $tt_fields = array($tt_fields);
681 $sanitised_tab_fields = array();
682 foreach($tt_fields as $tab_field){
683 if(is_object($tab_field)){ /** @since 2.4.2 track fields in each tabs. */
684 $tab_field = get_object_vars($tab_field); /*convert to array*/
685 $tab = array_keys($tab_field);
686 $tab = sanitize_text_field($tab[0]);
687 $tab_field = $tab_field[$tab];
688 $sanitised_tab_fields[$tab]=array();
689 foreach($tab_field as $field) $sanitised_tab_fields[$tab][] = sanitize_text_field($field);
690 }else $sanitised_tab_fields[] = sanitize_text_field($tab_field);
691 }
692 update_post_meta($post_id, '_cf7sg_grid_tabs_names', $sanitised_tab_fields);
693 /** track toggled fields.
694 * @since 2.5*/
695 $tt_fields = json_decode(stripslashes($_POST['cf7sg-toggle-fields']));
696 if(empty($tt_fields)) $tt_fields = array();
697 if(!is_array($tt_fields)) $tt_fields = array($tt_fields);
698 $sanitised_toggled_fields = array();
699 foreach($tt_fields as $tgg_field){
700 if(is_object($tgg_field)){
701 $tgg_field = get_object_vars($tgg_field); /*convert to array*/
702 $tgg = array_keys($tgg_field);
703 $tgg = sanitize_text_field($tgg[0]);
704 $tgg_field = $tgg_field[$tgg];
705 $sanitised_toggled_fields[$tgg]=array();
706 foreach($tgg_field as $field) $sanitised_toggled_fields[$tgg][] = sanitize_text_field($field);
707 }else $sanitised_toggled_fields[] = sanitize_text_field($tgg_field);
708 }
709 update_post_meta($post_id, '_cf7sg_grid_toggled_names', $sanitised_toggled_fields);
710 //flag tab & tables for more efficient front-end display.
711 $has_tabs = ( 'true' === $_POST['cf7sg-has-tabs']) ? true : false;
712 update_post_meta($post_id, '_cf7sg_has_tabs', $has_tabs);
713 $has_tables = ( 'true' === $_POST['cf7sg-has-tables']) ? true : false;
714 update_post_meta($post_id, '_cf7sg_has_tables', $has_tables);
715 $has_toggles = ( 'true' === $_POST['cf7sg-has-toggles']) ? true : false;
716 update_post_meta($post_id, '_cf7sg_has_toggles', $has_toggles);
717 /**
718 * @since 1.2.3 disable cf7sg styling/js for non-cf7sg forms.
719 */
720 $is_cf7sg = ( 'true' === $_POST['is_cf7sg_form']) ? true : false;
721 update_post_meta($post_id, '_cf7sg_managed_form', $is_cf7sg);
722 update_post_meta($post_id, '_cf7sg_version', $this->version);
723 /** @since 3.0.0 track script classes for loading for js/css in front-end */
724 $classes = sanitize_text_field($_POST['cf7sg-script-classes']);
725 $classes = explode(',', trim($classes, ','));
726 // debug_msg($classes, 'script classes');
727 update_post_meta($post_id, '_cf7sg_script_classes', $classes);
728 /**
729 *@since 2.3.0 the duplicate functionality has been isntored and therefore any new meta fields added to this plugin needs to be added to the duplication properties too.
730 */
731 }
732 /**
733 *
734 *
735 *@since 2.3.0
736 *@param string $new_form_id new form id to duplciate to.
737 *@param string $form_id form id to duplciate.
738 */
739 public function duplicate_form_properties($new_form_id, $form_id){
740 //these properties will be preceded with an '_' by the cf7 plugin before being duplicated.
741 $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');
742 $properties = apply_filters('cf7sg_duplicate_form_properties', $properties);
743 foreach($properties as $field){
744 $value = get_post_meta($form_id, $field, true);
745 if(!empty($value)) update_post_meta($new_form_id,$field, $value);
746 }
747 }
748 /**
749 * Duplicate form.
750 *
751 *@since 2.3.0
752 *@param string $param text_description
753 *@return string text_description
754 */
755 public function duplicate_cf7_form(){
756 global $pagenow;
757 if($pagenow != 'post.php') return;
758 if(isset($_GET['action']) && 'cf7copy' == $_GET['action']){
759 $action = 'wpcf7-copy-contact-form_' . $_GET['post'];
760 if( !wp_verify_nonce( $_GET['_wpnonce'], $action )){
761 die( 'Security check error: Try to reload the page and try again.' );
762 }
763 if ( $form = wpcf7_contact_form( $_GET['post'] ) ) {
764 $new_form = $form->copy();
765 $new_form->save();
766 $this->duplicate_form_properties($new_form->id(), $_GET['post']);
767 wp_safe_redirect( admin_url( '/post.php?post='.$new_form->id().'&action=edit' ));
768 exit;
769 }
770 }
771 }
772 /**
773 * Filtered allowed html tags & attributes, add data-button to div tags to ensure forms are saved properly.
774 * Hooked on 'wp_kses_allowed_html'
775 *@since 1.0.0
776 *@param array $allowed array of allowed tags and attributes.
777 *@param mixed $context context in which content is filtered.
778 *@return array allowed tags and ttribtues.
779 */
780 public function custom_kses_rules($allowed, $context){
781 if(is_array($context)){
782 return $allowed;
783 }
784 if('post'===$context){
785 $allowed['div']['data-button'] = true; //table buttons.
786 $allowed['div']['data-form'] = true; //sub-forms.
787 $allowed['div']['data-on'] = true; //toggles.
788 $allowed['div']['data-off'] = true; //toggles.
789 $allowed['div']['data-open'] = true; //accordion.
790 $allowed['div']['data-group'] = true; //accordion.
791 $allowed['div']['data-config-field'] = true; //cf7 plugin.
792 }
793 return $allowed;
794 }
795 /**
796 * Filters the default form loaded when a new CF7 form is created
797 * Hooked on 'wpcf7_default_template'
798 * @since 1.0
799 * @param string $template the html string for the form tempalte
800 * @param string $prop the template property required.
801 */
802 public function default_cf7_form($template, $prop){
803 if($prop !== 'form') return $template;
804 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-default-form.php');
805 return $template;
806 }
807 /**
808 * Ajax function to return the content of a cf7 form
809 * Hooked on 'wp_ajax_get_cf7_content'
810 * @since 1.0.0
811 * @return String cf7 form content.
812 **/
813 public function get_cf7_content(){
814 if( !isset($_POST['nonce']) ){
815 echo 'error, nonce failed, try to reload the page.';
816 wp_die();
817 }
818 if(!wp_verify_nonce($_POST['nonce'], 'wpcf7-save-contact-form_' . $_POST['id'], '_wpcf7nonce')){
819 echo 'error, nonce failed, try to reload the page.';
820 wp_die();
821 }
822 $cf7_key = sanitize_text_field($_POST['cf7_key']);
823 $sub_forms = get_posts(array(
824 'post_type' => $this->cf7_post_type(),
825 'post_name__in' => array($cf7_key)
826 ));
827 $form='';
828 if(!empty($sub_forms)){
829 $form = get_post_meta($sub_forms[0]->ID, '_form', true);
830 echo $form;
831 }else{
832 echo 'unable to find form '.$cf7_key;
833 }
834 wp_die();
835 }
836 /**
837 * Adds a [taxonomy] tag to cf7 forms
838 * Hooked on 'wpcf7_admin_init'
839 * @since 1.0.0
840 **/
841 public function cf7_shortcode_tags(){
842 if ( class_exists( 'WPCF7_TagGenerator' ) ) {
843 $tag_generator = WPCF7_TagGenerator::get_instance();
844 $tag_generator->add(
845 'dynamic_select', //tag id
846 __( 'dynamic-dropdown', 'cf7_2_post' ), //tag button label
847 array($this,'dynamic_tag_generator') //callback
848 );
849 $tag_generator->add(
850 'benchmark', //tag id
851 __( 'benchmark', 'cf7_2_post' ), //tag button label
852 array($this,'benchmark_tag_generator') //callback
853 );
854 }
855 }
856 /**
857 * Dynamic select screen displayt.
858 *
859 * This function is called by cf7 plugin, and is registered with a hooked function above
860 *
861 * @since 1.0.0
862 * @param WPCF7_ContactForm $contact_form the cf7 form object
863 * @param array $args arguments for this form.
864 */
865 function dynamic_tag_generator( $contact_form, $args = '' ) {
866 $args = wp_parse_args( $args, array() );
867 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-dynamic-tag-display.php');
868 }
869 /**
870 * Benchmark input screen displayt.
871 *
872 * This function is called by cf7 plugin, and is registered with a hooked function above
873 *
874 * @since 1.0.0
875 * @param WPCF7_ContactForm $contact_form the cf7 form object
876 * @param array $args arguments for this form.
877 */
878 function benchmark_tag_generator( $contact_form, $args = '' ) {
879 $args = wp_parse_args( $args, array() );
880 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-benchmark-tag.php');
881 }
882 /**
883 * Print hiddend field on cf7 post submit box
884 * Hooked on 'wpcf7_admin_misc_pub_section'
885 * @since 1.0.0
886 * @param string $post_id cf7 form post id .
887 **/
888 public function dynamic_select_choices($post_id){
889 echo '<input id="cf72post-dynamic-select" type="hidden" name="cf72post_dynamic_select_taxonomies" />';
890 }
891 /**
892 * CF7 Form saved from backend, check if dynamic-select are used
893 * Hooked on 'wpcf7_save_contact_form'
894 * @since 1.0.0
895 * @param WPCF7_Contact_Form $cf7_form cf7 form object
896 */
897 public function save_factory_metas($cf7_form){
898 $cf7_post_id = $cf7_form->id();
899 //get the tags used in this form
900 if( isset($_POST['cf72post_dynamic_select_taxonomies']) ){
901 $created_taxonomies = array();
902 $taxonomies = json_decode(str_replace('\"','"',$_POST['cf72post_dynamic_select_taxonomies']), true);
903 if(empty($taxonomies)){
904 $taxonomies = array();
905 }
906 foreach($taxonomies as $taxonomy){
907 //sanitize fields before saving into the DB.
908 foreach($taxonomy as $key=>$value){
909 $key = sanitize_key($key);
910 $taxonomy[$key] = sanitize_text_field($value);
911 }
912 $created_taxonomies[$taxonomy['slug']] = $taxonomy;
913 }
914 //debug_msg($created_taxonomies);
915 $tags = $cf7_form->scan_form_tags(); //get your form tags
916 $post_lists = $saved_lists = $system_list = array();
917
918 $dropdowns = get_option('_cf7sg_dynamic_dropdown_taxonomy',array());
919 foreach($dropdowns as $id => $lists){
920 $saved_lists = array_merge($saved_lists, $lists);
921 }
922 foreach($tags as $tag){
923 if('dynamic_select' == $tag['basetype']){
924 if(isset($tag['values'])){
925 $slug='';
926 foreach($tag['values'] as $values){
927 if(0 == strpos($values, 'slug:') ){
928 $slug = str_replace('slug:', '', $values);
929 break;
930 }
931 }
932 if(empty($slug)) continue; //not a taxonomy list.
933 //is slug newly created?
934 if(isset($created_taxonomies[$slug])){
935 //store this taxonomy.
936 $post_lists[$slug] = $created_taxonomies[$slug];
937 }else if(isset($saved_lists[$slug])){
938 //retain previously saved list if we are stil using it.
939 $post_lists[$slug] = $saved_lists[$slug];
940 }else{ //system taxonomy.
941 $system_list[] = $slug;
942 }
943 //store the taxonomy slug in the cf7 metas.
944 //$post_lists[$slug] = null;
945 }
946 }
947 }
948 //list of taxonomy to register.
949 //unset the old value.
950 unset($dropdowns[$cf7_post_id]);
951 //unshift new value to top of array.
952 $dropdowns = array($cf7_post_id => $post_lists) + $dropdowns ;
953
954 update_option('_cf7sg_dynamic_dropdown_taxonomy', $dropdowns);
955 //list of system taxonomy to register
956 $system_dropdowns = get_option('_cf7sg_dynamic_dropdown_system_taxonomy',array());
957 $system_dropdowns[$cf7_post_id] = $system_list;
958 update_option('_cf7sg_dynamic_dropdown_system_taxonomy', $system_dropdowns);
959
960 }
961 }
962
963 /**
964 * function to regsiter dyanmic dropdown taxonomies
965 *
966 * @since 1.0.0
967 * @param Object $taxonomy_object std object with parameters $taxonomy_object->slug, $taxonomy_object->singular, $taxonomy_object->plural, $taxonomy_object->hierarchical .
968 **/
969 protected function register_dynamic_dropdown($taxonomy_array){
970 $slug = $taxonomy_array['slug'];
971 $name = $taxonomy_array['singular'];
972 $plural = $taxonomy_array['plural'];
973 $is_hierarchical = $taxonomy_array['hierarchical'];
974
975 $labels = array(
976 'name' => $plural,
977 'singular_name' => $name,
978 'menu_name' => $plural,
979 'all_items' => 'All '.$plural,
980 'parent_item' => 'Parent '.$name,
981 'parent_item_colon' => 'Parent '.$name.':',
982 'new_item_name' => 'New '.$name.' Name',
983 'add_new_item' => 'Add New '.$name,
984 'edit_item' => 'Edit '.$name,
985 'update_item' => 'Update '.$name,
986 'view_item' => 'View '.$name,
987 'separate_items_with_commas' => 'Separate '.$plural.' with commas',
988 'add_or_remove_items' => 'Add or remove '.$plural,
989 'choose_from_most_used' => 'Choose from the most used',
990 'popular_items' => 'Popular '.$plural,
991 'search_items' => 'Search '.$plural,
992 'not_found' => 'Not Found',
993 'no_terms' => 'No '.$plural,
994 'items_list' => $plural.' list',
995 'items_list_navigation' => $plural.' list navigation',
996 );
997 //labels can be modified post registration
998 $args = array(
999 'labels' => $labels,
1000 'hierarchical' => $is_hierarchical,
1001 'public' => false,
1002 'show_ui' => true,
1003 'show_admin_column' => false,
1004 'show_in_nav_menus' => false,
1005 'show_tagcloud' => false,
1006 'show_in_quick_edit' => false,
1007 'description' => 'Contact Form 7 dynamic dropdown taxonomy list',
1008 );
1009
1010 register_taxonomy( $slug, $this->cf7_post_type(), $args );
1011 }
1012 /**
1013 * Deactivate this plugin if CF7 plugin is deactivated.
1014 * Hooks on action 'admin_init'
1015 * @since 2.1
1016 */
1017 //public function deactivate_cf7_polylang( $plugin, $network_deactivating ) {
1018 public function check_plugin_dependency() {
1019 //if either the polylang for the cf7 plugin is not active anymore, deactive this extension
1020 if( !is_plugin_active("contact-form-7/wp-contact-form-7.php") ){
1021 deactivate_plugins( "cf7-grid-layout/cf7-grid-layout.php" );
1022 debug_msg("Deactivating Smart Grid");
1023
1024 $button = '<a href="'.network_admin_url('plugins.php').'">Return to Plugins</a></a>';
1025 wp_die( '<p><strong>CF7 smart Grid-layout Extension</strong> requires <strong>Contact Form 7</strong> plugin, and has therefore been deactivated!</p>'.$button );
1026
1027 return false;
1028 }
1029 return true;
1030 }
1031 /**
1032 * Add disabled button message on hover to cf7 messages.
1033 * Hooked to 'wpcf7_messages', see file contact-form-7/includes/contact-form-template.php fn messages().
1034 *@since 2.6.0
1035 *@param array $messages array of messages to filter.
1036 *@return array array of cf7 messages.
1037 */
1038 public function disabled_message($messages){
1039 $messages['submit_disabled'] = array(
1040 'description'
1041 => __( "Hover message for disabled submit/save button", 'cf7-grid-layout' ),
1042 'default'
1043 => __( "Disabled! To enable, check the acceptance field.", 'cf7-grid-layout' ),
1044 );
1045 /** @sicne 2.8.0 */
1046 $messages['max_table_rows'] = array(
1047 'description'
1048 => __( "Message displayed when max tables rows reached.", 'cf7-grid-layout' ),
1049 'default'
1050 => __( "You have reached the maximum number of rows.", 'cf7-grid-layout' ),
1051 );
1052 return $messages;
1053 }
1054 /**
1055 * Adds pretty pointers to help users.
1056 * Hooked on 'admin_enqueue_scripts'
1057 *@since 2.6.0
1058 *@param string $hook_suffix current page.
1059 */
1060 public function pretty_admin_pointers($hook_suffix){
1061 $screen = get_current_screen();
1062 if (!isset($screen) || $this->cf7_post_type() != $screen->post_type || in_array( $hook_suffix, array('post.php', 'post-new.php'), true)){
1063 return;
1064 }
1065 $enqueue_pointer = false;
1066 // Get array list of dismissed pointers for current user and convert it to array
1067 $user_id = get_current_user_id();
1068 $dismissed_pointers = explode( ',', get_user_meta( $user_id, 'dismissed_wp_pointers', true ) );
1069 $pointers = array();
1070 /**
1071 * Filter to add custom pointers for user iterface.
1072 * @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).
1073 * @return array an array of pointers, which will be checked agains the current user.
1074 */
1075 $filter_pointers = apply_filters('cf7sg_plugin_pointers-'.$screen->id, array());
1076 foreach($filter_pointers as $id=>$pointer){
1077 // Check if our pointer is not among dismissed ones
1078 if( !in_array( $id, $dismissed_pointers ) ) {
1079 $enqueue_pointer = true;
1080 $pointers[$id] = array($pointer[0], $pointer[1], $pointer[2], $pointer[3]);
1081 }
1082 }
1083 // Enqueue pointer CSS and JS files, if needed
1084 if( $enqueue_pointer ) {
1085 wp_enqueue_style( 'wp-pointer' );
1086 wp_enqueue_script( 'wp-pointer' );
1087 wp_enqueue_script('cf7sg-pointer-js', plugin_dir_url( __DIR__ ).'admin/js/cf7sg-pointers.js', array('jquery'), $this->version, true);
1088 wp_localize_script('cf7sg-pointer-js', 'cf7sg_pointers',
1089 array('pointers'=>$pointers, 'next'=>__('Next', 'cf7-grid-layout'))
1090 );
1091 // Add footer scripts using callback function
1092 //add_action( 'admin_print_footer_scripts', array($this, 'pretty_pointer_script') );
1093 }
1094 }
1095 /**
1096 * CF7 Table pointer notices.
1097 * Hooked on 'cf7sg_plugin_pointers-edit-wpcf7_contact_form'
1098 *@since 2.6.0
1099 *@param array $pointers array of pointers to suplement
1100 *@return array array of pointers element-id=>hmtl to display key value pairs.
1101 */
1102 public function edit_pointers($pointers){
1103 ob_start();
1104 include_once 'partials/pointers/cf7sg-pointer-update-forms.php';
1105 $content =ob_get_contents();
1106 $pointers['update_forms_pointer'] = array($content, 'left', 'center','');
1107 /* shortcodes */
1108 ob_clean();
1109 include_once 'partials/pointers/cf7sg-pointer-shortcodes.php';
1110 $content = ob_get_clean();
1111 $pointers['cf7sg_shortcodes'] = array($content, 'top', 'top','');
1112 return $pointers;
1113 }
1114 /**
1115 * CF7 Edit pointer notices.
1116 * Hooked on 'cf7sg_plugin_pointers-wpcf7_contact_form'
1117 *@since 2.6.0
1118 *@param array $pointers array of pointers to suplement
1119 *@return array array of pointers element-id=>hmtl to display key value pairs.
1120 */
1121 public function post_pointers($pointers){
1122 ob_start();
1123 include_once 'partials/pointers/cf7sg-pointer-editor-full-screen.php';
1124 $content =ob_get_contents();
1125 //content / arrow [top,bottom,left,right] / box align [top,bottom,center] / css selector.
1126 $pointers['full_screen'] = array($content, 'left', 'center','#full-screen-cf7');
1127 /* shortcodes */
1128 ob_clean();
1129 include_once 'partials/pointers/cf7sg-pointer-editor-tabs.php';
1130 $content =ob_get_contents();
1131 $pointers['editor_tabs'] = array($content, 'right', 'center','#form-editor-tabs>ul>li.ui-tabs-active');
1132 /* shortcodes */
1133 ob_clean();
1134 include_once 'partials/pointers/cf7sg-pointer-editor-rows-control.php';
1135 $content = ob_get_contents();
1136 if(!empty($content)){
1137 $pointers['row_controls'] = array($content, 'right', 'center','#grid-form>.container>.row>.row-controls');
1138 ob_clean();
1139 }
1140 include_once 'partials/pointers/cf7sg-pointer-editor-column-control.php';
1141 $content = ob_get_contents();
1142 if(!empty($content)){
1143 $pointers['column_controls'] = array($content, 'left', 'center','#grid-form>.container>.row>.columns:first-child>.grid-column>span.icon-code');
1144 ob_clean();
1145 }
1146 include_once 'partials/pointers/cf7sg-pointer-tag-dynamic-dropdown.php';
1147 $content = ob_get_contents();
1148 $pointers['dynamic_dropdown'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="dynamic-dropdown"]');
1149 ob_clean();
1150 include_once 'partials/pointers/cf7sg-pointer-tag-benchmark.php';
1151 $content = ob_get_clean();
1152 $pointers['benchmark'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="benchmark"]');
1153 return $pointers;
1154 }
1155 /**
1156 * Rest meta_caps for better fine tuning of user caps.
1157 * hooked to 'wpcf7_map_meta_cap'.
1158 *@since 3.0.0
1159 *@param array $caps key->value pairs of capabilities.
1160 *@return array key->value pairs of capabilities.
1161 */
1162 public function reset_meta_cap($caps){
1163 return array(
1164 'wpcf7_read_contact_form'=>'read_post',
1165 'wpcf7_edit_contact_form' =>'edit_post',
1166 'wpcf7_edit_contact_forms' => 'edit_posts',
1167 'wpcf7_edit_others_contact_forms'=>'edit_others_posts',
1168 'wpcf7_edit_published_contact_forms'=>'edit_published_posts',
1169 'wpcf7_delete_contact_form'=>'delete_post',
1170 'wpcf7_delete_contact_forms'=>'delete_posts',
1171 'wpcf7_delete_published_contact_forms'=>'delete_published_posts',
1172 'wpcf7_delete_others_contact_forms'=>'delete_others_posts',
1173 'wpcf7_publish_contact_forms'=>'publish_posts',
1174 'wpcf7_publish_contact_forms'=>'read_private_posts',
1175 'wpcf7_submit'=>'read', /** @since 3.2.1 to fix subscribers_only. */
1176 );
1177 }
1178 /**
1179 * CF7 plugin by default sets form post status to 'publish' regardless of user capability.
1180 * This functions rectifies this. Hooked to 'wp_insert_post_data'.
1181 *@since 3.0.0
1182 *@param array $data sanitised post data.
1183 *@return array post data.
1184 */
1185 public function pending_for_review($data){
1186 if($this->cf7_post_type() != $data['post_type']) return $data;
1187
1188 $post_type_object = get_post_type_object( $this->cf7_post_type() );
1189 //check if user can publish.
1190 if(!current_user_can($post_type_object->cap->publish_posts) && $data['post_status']=='publish'){
1191 $data['post_status']='pending';
1192 }
1193 // debug_msg('post status '.$data['post_status']);
1194 return $data;
1195 }
1196 /**
1197 * Enable all cf7 capabilites for editors.
1198 * Hooked to action 'admin_init'.
1199 *@since 3.0.0
1200 */
1201 public function enable_cf7_editor_role(){
1202 global $wp_roles;
1203 if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles();
1204 $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');
1205 $fe = $wp_roles->get_role('editor');
1206 if(!empty($fe)){ /** @since 3.0.3 in case editor role is deleted */
1207 foreach($caps as $cap) $fe->add_cap($cap);
1208 }
1209 $caps[]='wpcf7_manage_integration';
1210 $ad = $wp_roles->get_role('administrator');
1211 if(!empty($ad)){ /** @since 3.0.3 in case admin role is deleted */
1212 foreach($caps as $cap) $ad->add_cap($cap);
1213 }
1214
1215 /** @since 3.1.3 redirect cf7 plugin pages*/
1216 global $pagenow;
1217 if ( $pagenow == 'admin.php' && isset( $_GET['page'] ) ) {
1218 $url = '';
1219 switch($_GET['page']){
1220 case 'wpcf7-new':
1221 $url = "post-new.php?post_type=wpcf7_contact_form" ;
1222 break;
1223 case 'wpcf7':
1224 if(isset($_GET['post'])) $url = "post.php?post={$_GET['post']}&action=edit&classic-editor";
1225 else $url = "edit.php?post_type=wpcf7_contact_form";
1226 break;
1227 }
1228 if(!empty($url)){
1229 wp_redirect( admin_url( $url ));
1230 exit;
1231 }
1232 }
1233 }
1234 /**
1235 * Add grid helper hooks for individual tags.
1236 * Hooked to action 'cf7sg_ui_grid_helper_hooks'.
1237 *@since 3.3.0
1238 */
1239 public function print_helper_hooks(){
1240 require_once plugin_dir_path( __FILE__ ) .'partials/helpers/cf7sg-form-fields.php';
1241 }
1242 }
1243