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

1,244 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(); /** @since 3.3.2 */
496
497 WPCF7_ContactForm::get_template( $args);
498 }
499 /**
500 * Callback function to disolay the main editor meta box
501 * @since 1.0.0
502 */
503 public function main_editor_metabox_display($post){
504 if('auto-draft' !== $post->post_status){
505 wpcf7_contact_form($post); //set the post
506 }
507 $post_id = $post->ID;
508 $cf7_form = wpcf7_get_current_contact_form();
509
510 if ( ! $cf7_form ) {
511 $cf7_form = WPCF7_ContactForm::get_template();
512 }
513
514 // if(empty($post)){
515 // $post_id = -1;
516 // }else{
517 // $post_id = $post->ID;
518 // }
519 require_once WPCF7_PLUGIN_DIR . '/admin/includes/editor.php';
520 require_once plugin_dir_path( __FILE__ ) . 'partials/cf7-admin-editor-display.php';
521 }
522
523 /**
524 * Function to add the metabox to the cf7 post edit screen
525 * This adds the main editor, hooked on 'add_meta_boxes'
526 * @since 1.0.0
527 */
528 public function info_meta_box() {
529 //add_meta_box( string $id, string $title, callable $callback, string $screen, string $context, string $priority, array $callback_args)
530 if(post_type_exists( $this->cf7_post_type() ) ) {
531 add_meta_box( 'meta-box-cf7-info',
532 __cf7sg( 'Information' ),
533 array($this , 'info_metabox_display'),
534 $this->cf7_post_type(),
535 'side',
536 'high'
537 );
538 }
539 }
540 /**
541 * Re-introduces the wordpress 'wpcf7_admin_misc_pub_section' for plugins to add their fields for submission
542 * Hooked to 'post_submitbox_misc_actions' which fires after post dat/time parameters are printed
543 * @since 1.0.0
544 * @param WP_Post $post post object being edited/created.
545 **/
546 public function cf7_post_submit_action($post){
547 if($this->cf7_post_type() == $post->post_type){
548 do_action( 'wpcf7_admin_misc_pub_section', $post->ID );
549 }
550 }
551 /**
552 * Callback function to disolay the main editor meta box
553 * @since 1.0.0
554 */
555 public function info_metabox_display($post){
556 require_once plugin_dir_path( __FILE__ ) . 'partials/cf7-info-metabox-display.php';
557 }
558 /**
559 * Function to add the metabox to the cf7 post edit screen
560 * This adds the helper, hooked on 'add_meta_boxes'
561 * @since 1.1.0
562 */
563 public function helper_meta_box() {
564 //add_meta_box( string $id, string $title, callable $callback, string $screen, string $context, string $priority, array $callback_args).
565 if(post_type_exists( $this->cf7_post_type() ) ) {
566 add_meta_box( 'meta-box-cf7sg-helper',
567 __( 'Actions & Filters', 'cf7-grid-layout' ),
568 array($this , 'helper_metabox_display'),
569 $this->cf7_post_type(),
570 'side',
571 'low'
572 );
573 }
574 }
575 /**
576 * Callback function to disolay the helper meta box
577 * @since 1.0.0
578 */
579 public function helper_metabox_display($post){
580 require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-helper-metabox-display.php';
581 }
582 /**
583 * Display the editor panels (wpcf7 / codemirror / grid)
584 *
585 * @since 1.0.0
586 * @param string $p1 .
587 * @return string $p2 .
588 **/
589 public function grid_editor_panel($form_post){
590 require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-grid-layout-admin-display.php';
591 }
592 /**
593 * Save cf7 post using ajax
594 * Hooked to 'save_post_wpcf7_contact_form'
595 * @since 1.0.0
596 **/
597 public function save_post($post_id, $post, $update){
598 //make sure this is the edit page and not a quick-edit.
599 if( !isset($_POST['_wpcf7nonce']) ){
600 return;
601 }
602 //validate the nonce.
603 check_admin_referer( 'wpcf7-save-contact-form_' . $post_id, '_wpcf7nonce');
604
605 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){
606 return;
607 }
608
609 switch($post->post_status){
610 case 'auto-draft':
611 case 'trash':
612 return;
613 default:
614 break;
615 }
616
617 // debug_msg($_POST, 'submitted ');
618 $args = $_REQUEST;
619 $args['id'] = $post_id;
620
621 $args['title'] = isset( $_POST['post_title'] ) ? sanitize_text_field($_POST['post_title'], 'Contact Form', 'save') : null;
622 $args['locale'] = isset( $_POST['wpcf7-locale'] ) ? sanitize_text_field($_POST['wpcf7-locale']) : null;
623 $args['form'] = '';
624 $allowed_tags = wp_kses_allowed_html( 'post' ); //filtered in function below.
625 /** @since 2.10.0 alllow custom input html*/
626 $allowed_tags['input']=array( //add additional input html elements
627 'type'=>1,
628 'class'=>1,
629 'id'=>1,
630 'value'=>1,
631 'data-*'=>1,
632 );
633 $allowed_tags['script']=array('type'=>1);
634 $allowed_tags = apply_filters('cf7sg_kses_allowed_html',$allowed_tags, $_POST['post_name']);
635 if(isset( $_POST['wpcf7-form'] )){
636 $args['form'] = wp_kses($_POST['wpcf7-form'], $allowed_tags);
637 }
638 $args['mail'] = isset( $_POST['wpcf7-mail'] ) ? wpcf7_sanitize_mail( $_POST['wpcf7-mail'] ): array();
639 $args['mail_2'] = isset( $_POST['wpcf7-mail-2'] ) ? wpcf7_sanitize_mail( $_POST['wpcf7-mail-2'] ): array();
640 $args['messages'] = isset( $_POST['wpcf7-messages'] ) ? $_POST['wpcf7-messages'] : array();
641 foreach($args['messages'] as $key=>$value){
642 $args['messages'][$key] = sanitize_text_field($value);
643 }
644 $args['additional_settings'] = isset( $_POST['wpcf7-additional-settings'] ) ? sanitize_textarea_field($_POST['wpcf7-additional-settings']) : '';
645
646 //need to unhook this function so as not to loop infinitely
647 //debug_msg($args, 'saving cf7 posts');
648 remove_action('save_post_wpcf7_contact_form', array($this, 'save_post'), 10,3);
649 $contact_form = wpcf7_save_contact_form( $args );
650 add_action('save_post_wpcf7_contact_form', array($this, 'save_post'), 10,3);
651 //flag as a grid form
652 //update_post_meta($post_id, 'cf7_grid_form', true); removed since v2.3 as not used.
653 //save sub-forms if any
654 $sub_forms = json_decode(stripslashes($_POST['cf7sg-embeded-forms']));
655 if(empty($sub_forms)) $sub_forms = array();
656 if(!is_array($sub_forms)) $sub_forms = array($sub_forms);
657 $sanitised_sub_forms = array();
658 foreach($sub_forms as $field){
659 $sanitised_sub_forms[] = sanitize_text_field($field);
660 }
661 update_post_meta($post_id, '_cf7sg_sub_forms', $sanitised_sub_forms);
662 //save form fields which are in tabs or tables.
663 $tt_fields = json_decode(stripslashes($_POST['cf7sg-table-fields']));
664 if(empty($tt_fields)) $tt_fields = array();
665 if(!is_array($tt_fields)) $tt_fields = array($tt_fields);
666 $sanitised_table_fields = array();
667 foreach($tt_fields as $table_fields){
668 if(is_object($table_fields)){ /** @since 2.4.2 track fields in each tables. */
669 $table_fields = get_object_vars($table_fields); /*convert to array*/
670 $table = array_keys($table_fields);
671 $table = sanitize_text_field($table[0]);
672 $table_fields = $table_fields[$table];
673 $sanitised_table_fields[$table]=array();
674 foreach($table_fields as $field) $sanitised_table_fields[$table][] = sanitize_text_field($field);
675 }else $sanitised_table_fields[] = sanitize_text_field($table_fields);
676 }
677 update_post_meta($post_id, '_cf7sg_grid_table_names', $sanitised_table_fields);
678 //tabs
679 $tt_fields = json_decode(stripslashes($_POST['cf7sg-tabs-fields']));
680 if(empty($tt_fields)) $tt_fields = array();
681 if(!is_array($tt_fields)) $tt_fields = array($tt_fields);
682 $sanitised_tab_fields = array();
683 foreach($tt_fields as $tab_field){
684 if(is_object($tab_field)){ /** @since 2.4.2 track fields in each tabs. */
685 $tab_field = get_object_vars($tab_field); /*convert to array*/
686 $tab = array_keys($tab_field);
687 $tab = sanitize_text_field($tab[0]);
688 $tab_field = $tab_field[$tab];
689 $sanitised_tab_fields[$tab]=array();
690 foreach($tab_field as $field) $sanitised_tab_fields[$tab][] = sanitize_text_field($field);
691 }else $sanitised_tab_fields[] = sanitize_text_field($tab_field);
692 }
693 update_post_meta($post_id, '_cf7sg_grid_tabs_names', $sanitised_tab_fields);
694 /** track toggled fields.
695 * @since 2.5*/
696 $tt_fields = json_decode(stripslashes($_POST['cf7sg-toggle-fields']));
697 if(empty($tt_fields)) $tt_fields = array();
698 if(!is_array($tt_fields)) $tt_fields = array($tt_fields);
699 $sanitised_toggled_fields = array();
700 foreach($tt_fields as $tgg_field){
701 if(is_object($tgg_field)){
702 $tgg_field = get_object_vars($tgg_field); /*convert to array*/
703 $tgg = array_keys($tgg_field);
704 $tgg = sanitize_text_field($tgg[0]);
705 $tgg_field = $tgg_field[$tgg];
706 $sanitised_toggled_fields[$tgg]=array();
707 foreach($tgg_field as $field) $sanitised_toggled_fields[$tgg][] = sanitize_text_field($field);
708 }else $sanitised_toggled_fields[] = sanitize_text_field($tgg_field);
709 }
710 update_post_meta($post_id, '_cf7sg_grid_toggled_names', $sanitised_toggled_fields);
711 //flag tab & tables for more efficient front-end display.
712 $has_tabs = ( 'true' === $_POST['cf7sg-has-tabs']) ? true : false;
713 update_post_meta($post_id, '_cf7sg_has_tabs', $has_tabs);
714 $has_tables = ( 'true' === $_POST['cf7sg-has-tables']) ? true : false;
715 update_post_meta($post_id, '_cf7sg_has_tables', $has_tables);
716 $has_toggles = ( 'true' === $_POST['cf7sg-has-toggles']) ? true : false;
717 update_post_meta($post_id, '_cf7sg_has_toggles', $has_toggles);
718 /**
719 * @since 1.2.3 disable cf7sg styling/js for non-cf7sg forms.
720 */
721 $is_cf7sg = ( 'true' === $_POST['is_cf7sg_form']) ? true : false;
722 update_post_meta($post_id, '_cf7sg_managed_form', $is_cf7sg);
723 update_post_meta($post_id, '_cf7sg_version', $this->version);
724 /** @since 3.0.0 track script classes for loading for js/css in front-end */
725 $classes = sanitize_text_field($_POST['cf7sg-script-classes']);
726 $classes = explode(',', trim($classes, ','));
727 // debug_msg($classes, 'script classes');
728 update_post_meta($post_id, '_cf7sg_script_classes', $classes);
729 /**
730 *@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.
731 */
732 }
733 /**
734 *
735 *
736 *@since 2.3.0
737 *@param string $new_form_id new form id to duplciate to.
738 *@param string $form_id form id to duplciate.
739 */
740 public function duplicate_form_properties($new_form_id, $form_id){
741 //these properties will be preceded with an '_' by the cf7 plugin before being duplicated.
742 $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');
743 $properties = apply_filters('cf7sg_duplicate_form_properties', $properties);
744 foreach($properties as $field){
745 $value = get_post_meta($form_id, $field, true);
746 if(!empty($value)) update_post_meta($new_form_id,$field, $value);
747 }
748 }
749 /**
750 * Duplicate form.
751 *
752 *@since 2.3.0
753 *@param string $param text_description
754 *@return string text_description
755 */
756 public function duplicate_cf7_form(){
757 global $pagenow;
758 if($pagenow != 'post.php') return;
759 if(isset($_GET['action']) && 'cf7copy' == $_GET['action']){
760 $action = 'wpcf7-copy-contact-form_' . $_GET['post'];
761 if( !wp_verify_nonce( $_GET['_wpnonce'], $action )){
762 die( 'Security check error: Try to reload the page and try again.' );
763 }
764 if ( $form = wpcf7_contact_form( $_GET['post'] ) ) {
765 $new_form = $form->copy();
766 $new_form->save();
767 $this->duplicate_form_properties($new_form->id(), $_GET['post']);
768 wp_safe_redirect( admin_url( '/post.php?post='.$new_form->id().'&action=edit' ));
769 exit;
770 }
771 }
772 }
773 /**
774 * Filtered allowed html tags & attributes, add data-button to div tags to ensure forms are saved properly.
775 * Hooked on 'wp_kses_allowed_html'
776 *@since 1.0.0
777 *@param array $allowed array of allowed tags and attributes.
778 *@param mixed $context context in which content is filtered.
779 *@return array allowed tags and ttribtues.
780 */
781 public function custom_kses_rules($allowed, $context){
782 if(is_array($context)){
783 return $allowed;
784 }
785 if('post'===$context){
786 $allowed['div']['data-button'] = true; //table buttons.
787 $allowed['div']['data-form'] = true; //sub-forms.
788 $allowed['div']['data-on'] = true; //toggles.
789 $allowed['div']['data-off'] = true; //toggles.
790 $allowed['div']['data-open'] = true; //accordion.
791 $allowed['div']['data-group'] = true; //accordion.
792 $allowed['div']['data-config-field'] = true; //cf7 plugin.
793 }
794 return $allowed;
795 }
796 /**
797 * Filters the default form loaded when a new CF7 form is created
798 * Hooked on 'wpcf7_default_template'
799 * @since 1.0
800 * @param string $template the html string for the form tempalte
801 * @param string $prop the template property required.
802 */
803 public function default_cf7_form($template, $prop){
804 if($prop !== 'form') return $template;
805 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-default-form.php');
806 return $template;
807 }
808 /**
809 * Ajax function to return the content of a cf7 form
810 * Hooked on 'wp_ajax_get_cf7_content'
811 * @since 1.0.0
812 * @return String cf7 form content.
813 **/
814 public function get_cf7_content(){
815 if( !isset($_POST['nonce']) ){
816 echo 'error, nonce failed, try to reload the page.';
817 wp_die();
818 }
819 if(!wp_verify_nonce($_POST['nonce'], 'wpcf7-save-contact-form_' . $_POST['id'], '_wpcf7nonce')){
820 echo 'error, nonce failed, try to reload the page.';
821 wp_die();
822 }
823 $cf7_key = sanitize_text_field($_POST['cf7_key']);
824 $sub_forms = get_posts(array(
825 'post_type' => $this->cf7_post_type(),
826 'post_name__in' => array($cf7_key)
827 ));
828 $form='';
829 if(!empty($sub_forms)){
830 $form = get_post_meta($sub_forms[0]->ID, '_form', true);
831 echo $form;
832 }else{
833 echo 'unable to find form '.$cf7_key;
834 }
835 wp_die();
836 }
837 /**
838 * Adds a [taxonomy] tag to cf7 forms
839 * Hooked on 'wpcf7_admin_init'
840 * @since 1.0.0
841 **/
842 public function cf7_shortcode_tags(){
843 if ( class_exists( 'WPCF7_TagGenerator' ) ) {
844 $tag_generator = WPCF7_TagGenerator::get_instance();
845 $tag_generator->add(
846 'dynamic_select', //tag id
847 __( 'dynamic-dropdown', 'cf7_2_post' ), //tag button label
848 array($this,'dynamic_tag_generator') //callback
849 );
850 $tag_generator->add(
851 'benchmark', //tag id
852 __( 'benchmark', 'cf7_2_post' ), //tag button label
853 array($this,'benchmark_tag_generator') //callback
854 );
855 }
856 }
857 /**
858 * Dynamic select screen displayt.
859 *
860 * This function is called by cf7 plugin, and is registered with a hooked function above
861 *
862 * @since 1.0.0
863 * @param WPCF7_ContactForm $contact_form the cf7 form object
864 * @param array $args arguments for this form.
865 */
866 function dynamic_tag_generator( $contact_form, $args = '' ) {
867 $args = wp_parse_args( $args, array() );
868 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-dynamic-tag-display.php');
869 }
870 /**
871 * Benchmark input screen displayt.
872 *
873 * This function is called by cf7 plugin, and is registered with a hooked function above
874 *
875 * @since 1.0.0
876 * @param WPCF7_ContactForm $contact_form the cf7 form object
877 * @param array $args arguments for this form.
878 */
879 function benchmark_tag_generator( $contact_form, $args = '' ) {
880 $args = wp_parse_args( $args, array() );
881 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-benchmark-tag.php');
882 }
883 /**
884 * Print hiddend field on cf7 post submit box
885 * Hooked on 'wpcf7_admin_misc_pub_section'
886 * @since 1.0.0
887 * @param string $post_id cf7 form post id .
888 **/
889 public function dynamic_select_choices($post_id){
890 echo '<input id="cf72post-dynamic-select" type="hidden" name="cf72post_dynamic_select_taxonomies" />';
891 }
892 /**
893 * CF7 Form saved from backend, check if dynamic-select are used
894 * Hooked on 'wpcf7_save_contact_form'
895 * @since 1.0.0
896 * @param WPCF7_Contact_Form $cf7_form cf7 form object
897 */
898 public function save_factory_metas($cf7_form){
899 $cf7_post_id = $cf7_form->id();
900 //get the tags used in this form
901 if( isset($_POST['cf72post_dynamic_select_taxonomies']) ){
902 $created_taxonomies = array();
903 $taxonomies = json_decode(str_replace('\"','"',$_POST['cf72post_dynamic_select_taxonomies']), true);
904 if(empty($taxonomies)){
905 $taxonomies = array();
906 }
907 foreach($taxonomies as $taxonomy){
908 //sanitize fields before saving into the DB.
909 foreach($taxonomy as $key=>$value){
910 $key = sanitize_key($key);
911 $taxonomy[$key] = sanitize_text_field($value);
912 }
913 $created_taxonomies[$taxonomy['slug']] = $taxonomy;
914 }
915 //debug_msg($created_taxonomies);
916 $tags = $cf7_form->scan_form_tags(); //get your form tags
917 $post_lists = $saved_lists = $system_list = array();
918
919 $dropdowns = get_option('_cf7sg_dynamic_dropdown_taxonomy',array());
920 foreach($dropdowns as $id => $lists){
921 $saved_lists = array_merge($saved_lists, $lists);
922 }
923 foreach($tags as $tag){
924 if('dynamic_select' == $tag['basetype']){
925 if(isset($tag['values'])){
926 $slug='';
927 foreach($tag['values'] as $values){
928 if(0 == strpos($values, 'slug:') ){
929 $slug = str_replace('slug:', '', $values);
930 break;
931 }
932 }
933 if(empty($slug)) continue; //not a taxonomy list.
934 //is slug newly created?
935 if(isset($created_taxonomies[$slug])){
936 //store this taxonomy.
937 $post_lists[$slug] = $created_taxonomies[$slug];
938 }else if(isset($saved_lists[$slug])){
939 //retain previously saved list if we are stil using it.
940 $post_lists[$slug] = $saved_lists[$slug];
941 }else{ //system taxonomy.
942 $system_list[] = $slug;
943 }
944 //store the taxonomy slug in the cf7 metas.
945 //$post_lists[$slug] = null;
946 }
947 }
948 }
949 //list of taxonomy to register.
950 //unset the old value.
951 unset($dropdowns[$cf7_post_id]);
952 //unshift new value to top of array.
953 $dropdowns = array($cf7_post_id => $post_lists) + $dropdowns ;
954
955 update_option('_cf7sg_dynamic_dropdown_taxonomy', $dropdowns);
956 //list of system taxonomy to register
957 $system_dropdowns = get_option('_cf7sg_dynamic_dropdown_system_taxonomy',array());
958 $system_dropdowns[$cf7_post_id] = $system_list;
959 update_option('_cf7sg_dynamic_dropdown_system_taxonomy', $system_dropdowns);
960
961 }
962 }
963
964 /**
965 * function to regsiter dyanmic dropdown taxonomies
966 *
967 * @since 1.0.0
968 * @param Object $taxonomy_object std object with parameters $taxonomy_object->slug, $taxonomy_object->singular, $taxonomy_object->plural, $taxonomy_object->hierarchical .
969 **/
970 protected function register_dynamic_dropdown($taxonomy_array){
971 $slug = $taxonomy_array['slug'];
972 $name = $taxonomy_array['singular'];
973 $plural = $taxonomy_array['plural'];
974 $is_hierarchical = $taxonomy_array['hierarchical'];
975
976 $labels = array(
977 'name' => $plural,
978 'singular_name' => $name,
979 'menu_name' => $plural,
980 'all_items' => 'All '.$plural,
981 'parent_item' => 'Parent '.$name,
982 'parent_item_colon' => 'Parent '.$name.':',
983 'new_item_name' => 'New '.$name.' Name',
984 'add_new_item' => 'Add New '.$name,
985 'edit_item' => 'Edit '.$name,
986 'update_item' => 'Update '.$name,
987 'view_item' => 'View '.$name,
988 'separate_items_with_commas' => 'Separate '.$plural.' with commas',
989 'add_or_remove_items' => 'Add or remove '.$plural,
990 'choose_from_most_used' => 'Choose from the most used',
991 'popular_items' => 'Popular '.$plural,
992 'search_items' => 'Search '.$plural,
993 'not_found' => 'Not Found',
994 'no_terms' => 'No '.$plural,
995 'items_list' => $plural.' list',
996 'items_list_navigation' => $plural.' list navigation',
997 );
998 //labels can be modified post registration
999 $args = array(
1000 'labels' => $labels,
1001 'hierarchical' => $is_hierarchical,
1002 'public' => false,
1003 'show_ui' => true,
1004 'show_admin_column' => false,
1005 'show_in_nav_menus' => false,
1006 'show_tagcloud' => false,
1007 'show_in_quick_edit' => false,
1008 'description' => 'Contact Form 7 dynamic dropdown taxonomy list',
1009 );
1010
1011 register_taxonomy( $slug, $this->cf7_post_type(), $args );
1012 }
1013 /**
1014 * Deactivate this plugin if CF7 plugin is deactivated.
1015 * Hooks on action 'admin_init'
1016 * @since 2.1
1017 */
1018 //public function deactivate_cf7_polylang( $plugin, $network_deactivating ) {
1019 public function check_plugin_dependency() {
1020 //if either the polylang for the cf7 plugin is not active anymore, deactive this extension
1021 if( !is_plugin_active("contact-form-7/wp-contact-form-7.php") ){
1022 deactivate_plugins( "cf7-grid-layout/cf7-grid-layout.php" );
1023 debug_msg("Deactivating Smart Grid");
1024
1025 $button = '<a href="'.network_admin_url('plugins.php').'">Return to Plugins</a></a>';
1026 wp_die( '<p><strong>CF7 smart Grid-layout Extension</strong> requires <strong>Contact Form 7</strong> plugin, and has therefore been deactivated!</p>'.$button );
1027
1028 return false;
1029 }
1030 return true;
1031 }
1032 /**
1033 * Add disabled button message on hover to cf7 messages.
1034 * Hooked to 'wpcf7_messages', see file contact-form-7/includes/contact-form-template.php fn messages().
1035 *@since 2.6.0
1036 *@param array $messages array of messages to filter.
1037 *@return array array of cf7 messages.
1038 */
1039 public function disabled_message($messages){
1040 $messages['submit_disabled'] = array(
1041 'description'
1042 => __( "Hover message for disabled submit/save button", 'cf7-grid-layout' ),
1043 'default'
1044 => __( "Disabled! To enable, check the acceptance field.", 'cf7-grid-layout' ),
1045 );
1046 /** @sicne 2.8.0 */
1047 $messages['max_table_rows'] = array(
1048 'description'
1049 => __( "Message displayed when max tables rows reached.", 'cf7-grid-layout' ),
1050 'default'
1051 => __( "You have reached the maximum number of rows.", 'cf7-grid-layout' ),
1052 );
1053 return $messages;
1054 }
1055 /**
1056 * Adds pretty pointers to help users.
1057 * Hooked on 'admin_enqueue_scripts'
1058 *@since 2.6.0
1059 *@param string $hook_suffix current page.
1060 */
1061 public function pretty_admin_pointers($hook_suffix){
1062 $screen = get_current_screen();
1063 if (!isset($screen) || $this->cf7_post_type() != $screen->post_type || in_array( $hook_suffix, array('post.php', 'post-new.php'), true)){
1064 return;
1065 }
1066 $enqueue_pointer = false;
1067 // Get array list of dismissed pointers for current user and convert it to array
1068 $user_id = get_current_user_id();
1069 $dismissed_pointers = explode( ',', get_user_meta( $user_id, 'dismissed_wp_pointers', true ) );
1070 $pointers = array();
1071 /**
1072 * Filter to add custom pointers for user iterface.
1073 * @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).
1074 * @return array an array of pointers, which will be checked agains the current user.
1075 */
1076 $filter_pointers = apply_filters('cf7sg_plugin_pointers-'.$screen->id, array());
1077 foreach($filter_pointers as $id=>$pointer){
1078 // Check if our pointer is not among dismissed ones
1079 if( !in_array( $id, $dismissed_pointers ) ) {
1080 $enqueue_pointer = true;
1081 $pointers[$id] = array($pointer[0], $pointer[1], $pointer[2], $pointer[3]);
1082 }
1083 }
1084 // Enqueue pointer CSS and JS files, if needed
1085 if( $enqueue_pointer ) {
1086 wp_enqueue_style( 'wp-pointer' );
1087 wp_enqueue_script( 'wp-pointer' );
1088 wp_enqueue_script('cf7sg-pointer-js', plugin_dir_url( __DIR__ ).'admin/js/cf7sg-pointers.js', array('jquery'), $this->version, true);
1089 wp_localize_script('cf7sg-pointer-js', 'cf7sg_pointers',
1090 array('pointers'=>$pointers, 'next'=>__('Next', 'cf7-grid-layout'))
1091 );
1092 // Add footer scripts using callback function
1093 //add_action( 'admin_print_footer_scripts', array($this, 'pretty_pointer_script') );
1094 }
1095 }
1096 /**
1097 * CF7 Table pointer notices.
1098 * Hooked on 'cf7sg_plugin_pointers-edit-wpcf7_contact_form'
1099 *@since 2.6.0
1100 *@param array $pointers array of pointers to suplement
1101 *@return array array of pointers element-id=>hmtl to display key value pairs.
1102 */
1103 public function edit_pointers($pointers){
1104 ob_start();
1105 include_once 'partials/pointers/cf7sg-pointer-update-forms.php';
1106 $content =ob_get_contents();
1107 $pointers['update_forms_pointer'] = array($content, 'left', 'center','');
1108 /* shortcodes */
1109 ob_clean();
1110 include_once 'partials/pointers/cf7sg-pointer-shortcodes.php';
1111 $content = ob_get_clean();
1112 $pointers['cf7sg_shortcodes'] = array($content, 'top', 'top','');
1113 return $pointers;
1114 }
1115 /**
1116 * CF7 Edit pointer notices.
1117 * Hooked on 'cf7sg_plugin_pointers-wpcf7_contact_form'
1118 *@since 2.6.0
1119 *@param array $pointers array of pointers to suplement
1120 *@return array array of pointers element-id=>hmtl to display key value pairs.
1121 */
1122 public function post_pointers($pointers){
1123 ob_start();
1124 include_once 'partials/pointers/cf7sg-pointer-editor-full-screen.php';
1125 $content =ob_get_contents();
1126 //content / arrow [top,bottom,left,right] / box align [top,bottom,center] / css selector.
1127 $pointers['full_screen'] = array($content, 'left', 'center','#full-screen-cf7');
1128 /* shortcodes */
1129 ob_clean();
1130 include_once 'partials/pointers/cf7sg-pointer-editor-tabs.php';
1131 $content =ob_get_contents();
1132 $pointers['editor_tabs'] = array($content, 'right', 'center','#form-editor-tabs>ul>li.ui-tabs-active');
1133 /* shortcodes */
1134 ob_clean();
1135 include_once 'partials/pointers/cf7sg-pointer-editor-rows-control.php';
1136 $content = ob_get_contents();
1137 if(!empty($content)){
1138 $pointers['row_controls'] = array($content, 'right', 'center','#grid-form>.container>.row>.row-controls');
1139 ob_clean();
1140 }
1141 include_once 'partials/pointers/cf7sg-pointer-editor-column-control.php';
1142 $content = ob_get_contents();
1143 if(!empty($content)){
1144 $pointers['column_controls'] = array($content, 'left', 'center','#grid-form>.container>.row>.columns:first-child>.grid-column>span.icon-code');
1145 ob_clean();
1146 }
1147 include_once 'partials/pointers/cf7sg-pointer-tag-dynamic-dropdown.php';
1148 $content = ob_get_contents();
1149 $pointers['dynamic_dropdown'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="dynamic-dropdown"]');
1150 ob_clean();
1151 include_once 'partials/pointers/cf7sg-pointer-tag-benchmark.php';
1152 $content = ob_get_clean();
1153 $pointers['benchmark'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="benchmark"]');
1154 return $pointers;
1155 }
1156 /**
1157 * Rest meta_caps for better fine tuning of user caps.
1158 * hooked to 'wpcf7_map_meta_cap'.
1159 *@since 3.0.0
1160 *@param array $caps key->value pairs of capabilities.
1161 *@return array key->value pairs of capabilities.
1162 */
1163 public function reset_meta_cap($caps){
1164 return array(
1165 'wpcf7_read_contact_form'=>'read_post',
1166 'wpcf7_edit_contact_form' =>'edit_post',
1167 'wpcf7_edit_contact_forms' => 'edit_posts',
1168 'wpcf7_edit_others_contact_forms'=>'edit_others_posts',
1169 'wpcf7_edit_published_contact_forms'=>'edit_published_posts',
1170 'wpcf7_delete_contact_form'=>'delete_post',
1171 'wpcf7_delete_contact_forms'=>'delete_posts',
1172 'wpcf7_delete_published_contact_forms'=>'delete_published_posts',
1173 'wpcf7_delete_others_contact_forms'=>'delete_others_posts',
1174 'wpcf7_publish_contact_forms'=>'publish_posts',
1175 'wpcf7_publish_contact_forms'=>'read_private_posts',
1176 'wpcf7_submit'=>'read', /** @since 3.2.1 to fix subscribers_only. */
1177 );
1178 }
1179 /**
1180 * CF7 plugin by default sets form post status to 'publish' regardless of user capability.
1181 * This functions rectifies this. Hooked to 'wp_insert_post_data'.
1182 *@since 3.0.0
1183 *@param array $data sanitised post data.
1184 *@return array post data.
1185 */
1186 public function pending_for_review($data){
1187 if($this->cf7_post_type() != $data['post_type']) return $data;
1188
1189 $post_type_object = get_post_type_object( $this->cf7_post_type() );
1190 //check if user can publish.
1191 if(!current_user_can($post_type_object->cap->publish_posts) && $data['post_status']=='publish'){
1192 $data['post_status']='pending';
1193 }
1194 // debug_msg('post status '.$data['post_status']);
1195 return $data;
1196 }
1197 /**
1198 * Enable all cf7 capabilites for editors.
1199 * Hooked to action 'admin_init'.
1200 *@since 3.0.0
1201 */
1202 public function enable_cf7_editor_role(){
1203 global $wp_roles;
1204 if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles();
1205 $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');
1206 $fe = $wp_roles->get_role('editor');
1207 if(!empty($fe)){ /** @since 3.0.3 in case editor role is deleted */
1208 foreach($caps as $cap) $fe->add_cap($cap);
1209 }
1210 $caps[]='wpcf7_manage_integration';
1211 $ad = $wp_roles->get_role('administrator');
1212 if(!empty($ad)){ /** @since 3.0.3 in case admin role is deleted */
1213 foreach($caps as $cap) $ad->add_cap($cap);
1214 }
1215
1216 /** @since 3.1.3 redirect cf7 plugin pages*/
1217 global $pagenow;
1218 if ( $pagenow == 'admin.php' && isset( $_GET['page'] ) ) {
1219 $url = '';
1220 switch($_GET['page']){
1221 case 'wpcf7-new':
1222 $url = "post-new.php?post_type=wpcf7_contact_form" ;
1223 break;
1224 case 'wpcf7':
1225 if(isset($_GET['post'])) $url = "post.php?post={$_GET['post']}&action=edit&classic-editor";
1226 else $url = "edit.php?post_type=wpcf7_contact_form";
1227 break;
1228 }
1229 if(!empty($url)){
1230 wp_redirect( admin_url( $url ));
1231 exit;
1232 }
1233 }
1234 }
1235 /**
1236 * Add grid helper hooks for individual tags.
1237 * Hooked to action 'cf7sg_ui_grid_helper_hooks'.
1238 *@since 3.3.0
1239 */
1240 public function print_helper_hooks(){
1241 require_once plugin_dir_path( __FILE__ ) .'partials/helpers/cf7sg-form-fields.php';
1242 }
1243 }
1244