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

1,248 lines 50.0 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 /** @since 3.3.5 track toggles in tabs */
718 $toggle_in_tabs = json_decode(stripslashes($_POST['cf7sg-toggle-in-tabs']));
719 if(empty($toggle_in_tabs)) $toggle_in_tabs = array();
720 if(!is_array($toggle_in_tabs)) $toggle_in_tabs = array($toggle_in_tabs);
721 update_post_meta($post_id, '_cf7sg_grid_toggle_in_tabs', $toggle_in_tabs);
722 /**
723 * @since 1.2.3 disable cf7sg styling/js for non-cf7sg forms.
724 */
725 $is_cf7sg = ( 'true' === $_POST['is_cf7sg_form']) ? true : false;
726 update_post_meta($post_id, '_cf7sg_managed_form', $is_cf7sg);
727 update_post_meta($post_id, '_cf7sg_version', $this->version);
728 /** @since 3.0.0 track script classes for loading for js/css in front-end */
729 $classes = sanitize_text_field($_POST['cf7sg-script-classes']);
730 $classes = explode(',', trim($classes, ','));
731 // debug_msg($classes, 'script classes');
732 update_post_meta($post_id, '_cf7sg_script_classes', $classes);
733 /**
734 *@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.
735 */
736 }
737 /**
738 *
739 *
740 *@since 2.3.0
741 *@param string $new_form_id new form id to duplciate to.
742 *@param string $form_id form id to duplciate.
743 */
744 public function duplicate_form_properties($new_form_id, $form_id){
745 //these properties will be preceded with an '_' by the cf7 plugin before being duplicated.
746 $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');
747 $properties = apply_filters('cf7sg_duplicate_form_properties', $properties);
748 foreach($properties as $field){
749 $value = get_post_meta($form_id, $field, true);
750 if(!empty($value)) update_post_meta($new_form_id,$field, $value);
751 }
752 }
753 /**
754 * Duplicate form.
755 *
756 *@since 2.3.0
757 *@param string $param text_description
758 *@return string text_description
759 */
760 public function duplicate_cf7_form(){
761 global $pagenow;
762 if($pagenow != 'post.php') return;
763 if(isset($_GET['action']) && 'cf7copy' == $_GET['action']){
764 $action = 'wpcf7-copy-contact-form_' . $_GET['post'];
765 if( !wp_verify_nonce( $_GET['_wpnonce'], $action )){
766 die( 'Security check error: Try to reload the page and try again.' );
767 }
768 if ( $form = wpcf7_contact_form( $_GET['post'] ) ) {
769 $new_form = $form->copy();
770 $new_form->save();
771 $this->duplicate_form_properties($new_form->id(), $_GET['post']);
772 wp_safe_redirect( admin_url( '/post.php?post='.$new_form->id().'&action=edit' ));
773 exit;
774 }
775 }
776 }
777 /**
778 * Filtered allowed html tags & attributes, add data-button to div tags to ensure forms are saved properly.
779 * Hooked on 'wp_kses_allowed_html'
780 *@since 1.0.0
781 *@param array $allowed array of allowed tags and attributes.
782 *@param mixed $context context in which content is filtered.
783 *@return array allowed tags and ttribtues.
784 */
785 public function custom_kses_rules($allowed, $context){
786 if(is_array($context)){
787 return $allowed;
788 }
789 if('post'===$context){
790 $allowed['div']['data-button'] = true; //table buttons.
791 $allowed['div']['data-form'] = true; //sub-forms.
792 $allowed['div']['data-on'] = true; //toggles.
793 $allowed['div']['data-off'] = true; //toggles.
794 $allowed['div']['data-open'] = true; //accordion.
795 $allowed['div']['data-group'] = true; //accordion.
796 $allowed['div']['data-config-field'] = true; //cf7 plugin.
797 }
798 return $allowed;
799 }
800 /**
801 * Filters the default form loaded when a new CF7 form is created
802 * Hooked on 'wpcf7_default_template'
803 * @since 1.0
804 * @param string $template the html string for the form tempalte
805 * @param string $prop the template property required.
806 */
807 public function default_cf7_form($template, $prop){
808 if($prop !== 'form') return $template;
809 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-default-form.php');
810 return $template;
811 }
812 /**
813 * Ajax function to return the content of a cf7 form
814 * Hooked on 'wp_ajax_get_cf7_content'
815 * @since 1.0.0
816 * @return String cf7 form content.
817 **/
818 public function get_cf7_content(){
819 if( !isset($_POST['nonce']) ){
820 echo 'error, nonce failed, try to reload the page.';
821 wp_die();
822 }
823 if(!wp_verify_nonce($_POST['nonce'], 'wpcf7-save-contact-form_' . $_POST['id'], '_wpcf7nonce')){
824 echo 'error, nonce failed, try to reload the page.';
825 wp_die();
826 }
827 $cf7_key = sanitize_text_field($_POST['cf7_key']);
828 $sub_forms = get_posts(array(
829 'post_type' => $this->cf7_post_type(),
830 'post_name__in' => array($cf7_key)
831 ));
832 $form='';
833 if(!empty($sub_forms)){
834 $form = get_post_meta($sub_forms[0]->ID, '_form', true);
835 echo $form;
836 }else{
837 echo 'unable to find form '.$cf7_key;
838 }
839 wp_die();
840 }
841 /**
842 * Adds a [taxonomy] tag to cf7 forms
843 * Hooked on 'wpcf7_admin_init'
844 * @since 1.0.0
845 **/
846 public function cf7_shortcode_tags(){
847 if ( class_exists( 'WPCF7_TagGenerator' ) ) {
848 $tag_generator = WPCF7_TagGenerator::get_instance();
849 $tag_generator->add(
850 'dynamic_select', //tag id
851 __( 'dynamic-dropdown', 'cf7_2_post' ), //tag button label
852 array($this,'dynamic_tag_generator') //callback
853 );
854 $tag_generator->add(
855 'benchmark', //tag id
856 __( 'benchmark', 'cf7_2_post' ), //tag button label
857 array($this,'benchmark_tag_generator') //callback
858 );
859 }
860 }
861 /**
862 * Dynamic select screen displayt.
863 *
864 * This function is called by cf7 plugin, and is registered with a hooked function above
865 *
866 * @since 1.0.0
867 * @param WPCF7_ContactForm $contact_form the cf7 form object
868 * @param array $args arguments for this form.
869 */
870 function dynamic_tag_generator( $contact_form, $args = '' ) {
871 $args = wp_parse_args( $args, array() );
872 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-dynamic-tag-display.php');
873 }
874 /**
875 * Benchmark input screen displayt.
876 *
877 * This function is called by cf7 plugin, and is registered with a hooked function above
878 *
879 * @since 1.0.0
880 * @param WPCF7_ContactForm $contact_form the cf7 form object
881 * @param array $args arguments for this form.
882 */
883 function benchmark_tag_generator( $contact_form, $args = '' ) {
884 $args = wp_parse_args( $args, array() );
885 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-benchmark-tag.php');
886 }
887 /**
888 * Print hiddend field on cf7 post submit box
889 * Hooked on 'wpcf7_admin_misc_pub_section'
890 * @since 1.0.0
891 * @param string $post_id cf7 form post id .
892 **/
893 public function dynamic_select_choices($post_id){
894 echo '<input id="cf72post-dynamic-select" type="hidden" name="cf72post_dynamic_select_taxonomies" />';
895 }
896 /**
897 * CF7 Form saved from backend, check if dynamic-select are used
898 * Hooked on 'wpcf7_save_contact_form'
899 * @since 1.0.0
900 * @param WPCF7_Contact_Form $cf7_form cf7 form object
901 */
902 public function save_factory_metas($cf7_form){
903 $cf7_post_id = $cf7_form->id();
904 //get the tags used in this form
905 if( isset($_POST['cf72post_dynamic_select_taxonomies']) ){
906 $created_taxonomies = array();
907 $taxonomies = json_decode(str_replace('\"','"',$_POST['cf72post_dynamic_select_taxonomies']), true);
908 if(empty($taxonomies)){
909 $taxonomies = array();
910 }
911 foreach($taxonomies as $taxonomy){
912 //sanitize fields before saving into the DB.
913 foreach($taxonomy as $key=>$value){
914 $key = sanitize_key($key);
915 $taxonomy[$key] = sanitize_text_field($value);
916 }
917 $created_taxonomies[$taxonomy['slug']] = $taxonomy;
918 }
919 //debug_msg($created_taxonomies);
920 $tags = $cf7_form->scan_form_tags(); //get your form tags
921 $post_lists = $saved_lists = $system_list = array();
922
923 $dropdowns = get_option('_cf7sg_dynamic_dropdown_taxonomy',array());
924 foreach($dropdowns as $id => $lists){
925 $saved_lists = array_merge($saved_lists, $lists);
926 }
927 foreach($tags as $tag){
928 if('dynamic_select' == $tag['basetype']){
929 if(isset($tag['values'])){
930 $slug='';
931 foreach($tag['values'] as $values){
932 if(0 == strpos($values, 'slug:') ){
933 $slug = str_replace('slug:', '', $values);
934 break;
935 }
936 }
937 if(empty($slug)) continue; //not a taxonomy list.
938 //is slug newly created?
939 if(isset($created_taxonomies[$slug])){
940 //store this taxonomy.
941 $post_lists[$slug] = $created_taxonomies[$slug];
942 }else if(isset($saved_lists[$slug])){
943 //retain previously saved list if we are stil using it.
944 $post_lists[$slug] = $saved_lists[$slug];
945 }else{ //system taxonomy.
946 $system_list[] = $slug;
947 }
948 //store the taxonomy slug in the cf7 metas.
949 //$post_lists[$slug] = null;
950 }
951 }
952 }
953 //list of taxonomy to register.
954 //unset the old value.
955 unset($dropdowns[$cf7_post_id]);
956 //unshift new value to top of array.
957 $dropdowns = array($cf7_post_id => $post_lists) + $dropdowns ;
958
959 update_option('_cf7sg_dynamic_dropdown_taxonomy', $dropdowns);
960 //list of system taxonomy to register
961 $system_dropdowns = get_option('_cf7sg_dynamic_dropdown_system_taxonomy',array());
962 $system_dropdowns[$cf7_post_id] = $system_list;
963 update_option('_cf7sg_dynamic_dropdown_system_taxonomy', $system_dropdowns);
964
965 }
966 }
967
968 /**
969 * function to regsiter dyanmic dropdown taxonomies
970 *
971 * @since 1.0.0
972 * @param Object $taxonomy_object std object with parameters $taxonomy_object->slug, $taxonomy_object->singular, $taxonomy_object->plural, $taxonomy_object->hierarchical .
973 **/
974 protected function register_dynamic_dropdown($taxonomy_array){
975 $slug = $taxonomy_array['slug'];
976 $name = $taxonomy_array['singular'];
977 $plural = $taxonomy_array['plural'];
978 $is_hierarchical = $taxonomy_array['hierarchical'];
979
980 $labels = array(
981 'name' => $plural,
982 'singular_name' => $name,
983 'menu_name' => $plural,
984 'all_items' => 'All '.$plural,
985 'parent_item' => 'Parent '.$name,
986 'parent_item_colon' => 'Parent '.$name.':',
987 'new_item_name' => 'New '.$name.' Name',
988 'add_new_item' => 'Add New '.$name,
989 'edit_item' => 'Edit '.$name,
990 'update_item' => 'Update '.$name,
991 'view_item' => 'View '.$name,
992 'separate_items_with_commas' => 'Separate '.$plural.' with commas',
993 'add_or_remove_items' => 'Add or remove '.$plural,
994 'choose_from_most_used' => 'Choose from the most used',
995 'popular_items' => 'Popular '.$plural,
996 'search_items' => 'Search '.$plural,
997 'not_found' => 'Not Found',
998 'no_terms' => 'No '.$plural,
999 'items_list' => $plural.' list',
1000 'items_list_navigation' => $plural.' list navigation',
1001 );
1002 //labels can be modified post registration
1003 $args = array(
1004 'labels' => $labels,
1005 'hierarchical' => $is_hierarchical,
1006 'public' => false,
1007 'show_ui' => true,
1008 'show_admin_column' => false,
1009 'show_in_nav_menus' => false,
1010 'show_tagcloud' => false,
1011 'show_in_quick_edit' => false,
1012 'description' => 'Contact Form 7 dynamic dropdown taxonomy list',
1013 );
1014
1015 register_taxonomy( $slug, $this->cf7_post_type(), $args );
1016 }
1017 /**
1018 * Deactivate this plugin if CF7 plugin is deactivated.
1019 * Hooks on action 'admin_init'
1020 * @since 2.1
1021 */
1022 //public function deactivate_cf7_polylang( $plugin, $network_deactivating ) {
1023 public function check_plugin_dependency() {
1024 //if either the polylang for the cf7 plugin is not active anymore, deactive this extension
1025 if( !is_plugin_active("contact-form-7/wp-contact-form-7.php") ){
1026 deactivate_plugins( "cf7-grid-layout/cf7-grid-layout.php" );
1027 debug_msg("Deactivating Smart Grid");
1028
1029 $button = '<a href="'.network_admin_url('plugins.php').'">Return to Plugins</a></a>';
1030 wp_die( '<p><strong>CF7 smart Grid-layout Extension</strong> requires <strong>Contact Form 7</strong> plugin, and has therefore been deactivated!</p>'.$button );
1031
1032 return false;
1033 }
1034 return true;
1035 }
1036 /**
1037 * Add disabled button message on hover to cf7 messages.
1038 * Hooked to 'wpcf7_messages', see file contact-form-7/includes/contact-form-template.php fn messages().
1039 *@since 2.6.0
1040 *@param array $messages array of messages to filter.
1041 *@return array array of cf7 messages.
1042 */
1043 public function disabled_message($messages){
1044 $messages['submit_disabled'] = array(
1045 'description'
1046 => __( "Hover message for disabled submit/save button", 'cf7-grid-layout' ),
1047 'default'
1048 => __( "Disabled! To enable, check the acceptance field.", 'cf7-grid-layout' ),
1049 );
1050 /** @sicne 2.8.0 */
1051 $messages['max_table_rows'] = array(
1052 'description'
1053 => __( "Message displayed when max tables rows reached.", 'cf7-grid-layout' ),
1054 'default'
1055 => __( "You have reached the maximum number of rows.", 'cf7-grid-layout' ),
1056 );
1057 return $messages;
1058 }
1059 /**
1060 * Adds pretty pointers to help users.
1061 * Hooked on 'admin_enqueue_scripts'
1062 *@since 2.6.0
1063 *@param string $hook_suffix current page.
1064 */
1065 public function pretty_admin_pointers($hook_suffix){
1066 $screen = get_current_screen();
1067 if (!isset($screen) || $this->cf7_post_type() != $screen->post_type || in_array( $hook_suffix, array('post.php', 'post-new.php'), true)){
1068 return;
1069 }
1070 $enqueue_pointer = false;
1071 // Get array list of dismissed pointers for current user and convert it to array
1072 $user_id = get_current_user_id();
1073 $dismissed_pointers = explode( ',', get_user_meta( $user_id, 'dismissed_wp_pointers', true ) );
1074 $pointers = array();
1075 /**
1076 * Filter to add custom pointers for user iterface.
1077 * @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).
1078 * @return array an array of pointers, which will be checked agains the current user.
1079 */
1080 $filter_pointers = apply_filters('cf7sg_plugin_pointers-'.$screen->id, array());
1081 foreach($filter_pointers as $id=>$pointer){
1082 // Check if our pointer is not among dismissed ones
1083 if( !in_array( $id, $dismissed_pointers ) ) {
1084 $enqueue_pointer = true;
1085 $pointers[$id] = array($pointer[0], $pointer[1], $pointer[2], $pointer[3]);
1086 }
1087 }
1088 // Enqueue pointer CSS and JS files, if needed
1089 if( $enqueue_pointer ) {
1090 wp_enqueue_style( 'wp-pointer' );
1091 wp_enqueue_script( 'wp-pointer' );
1092 wp_enqueue_script('cf7sg-pointer-js', plugin_dir_url( __DIR__ ).'admin/js/cf7sg-pointers.js', array('jquery'), $this->version, true);
1093 wp_localize_script('cf7sg-pointer-js', 'cf7sg_pointers',
1094 array('pointers'=>$pointers, 'next'=>__('Next', 'cf7-grid-layout'))
1095 );
1096 // Add footer scripts using callback function
1097 //add_action( 'admin_print_footer_scripts', array($this, 'pretty_pointer_script') );
1098 }
1099 }
1100 /**
1101 * CF7 Table pointer notices.
1102 * Hooked on 'cf7sg_plugin_pointers-edit-wpcf7_contact_form'
1103 *@since 2.6.0
1104 *@param array $pointers array of pointers to suplement
1105 *@return array array of pointers element-id=>hmtl to display key value pairs.
1106 */
1107 public function edit_pointers($pointers){
1108 ob_start();
1109 include_once 'partials/pointers/cf7sg-pointer-update-forms.php';
1110 $content =ob_get_contents();
1111 $pointers['update_forms_pointer'] = array($content, 'left', 'center','');
1112 /* shortcodes */
1113 ob_clean();
1114 include_once 'partials/pointers/cf7sg-pointer-shortcodes.php';
1115 $content = ob_get_clean();
1116 $pointers['cf7sg_shortcodes'] = array($content, 'top', 'top','');
1117 return $pointers;
1118 }
1119 /**
1120 * CF7 Edit pointer notices.
1121 * Hooked on 'cf7sg_plugin_pointers-wpcf7_contact_form'
1122 *@since 2.6.0
1123 *@param array $pointers array of pointers to suplement
1124 *@return array array of pointers element-id=>hmtl to display key value pairs.
1125 */
1126 public function post_pointers($pointers){
1127 ob_start();
1128 include_once 'partials/pointers/cf7sg-pointer-editor-full-screen.php';
1129 $content =ob_get_contents();
1130 //content / arrow [top,bottom,left,right] / box align [top,bottom,center] / css selector.
1131 $pointers['full_screen'] = array($content, 'left', 'center','#full-screen-cf7');
1132 /* shortcodes */
1133 ob_clean();
1134 include_once 'partials/pointers/cf7sg-pointer-editor-tabs.php';
1135 $content =ob_get_contents();
1136 $pointers['editor_tabs'] = array($content, 'right', 'center','#form-editor-tabs>ul>li.ui-tabs-active');
1137 /* shortcodes */
1138 ob_clean();
1139 include_once 'partials/pointers/cf7sg-pointer-editor-rows-control.php';
1140 $content = ob_get_contents();
1141 if(!empty($content)){
1142 $pointers['row_controls'] = array($content, 'right', 'center','#grid-form>.container>.row>.row-controls');
1143 ob_clean();
1144 }
1145 include_once 'partials/pointers/cf7sg-pointer-editor-column-control.php';
1146 $content = ob_get_contents();
1147 if(!empty($content)){
1148 $pointers['column_controls'] = array($content, 'left', 'center','#grid-form>.container>.row>.columns:first-child>.grid-column>span.icon-code');
1149 ob_clean();
1150 }
1151 include_once 'partials/pointers/cf7sg-pointer-tag-dynamic-dropdown.php';
1152 $content = ob_get_contents();
1153 $pointers['dynamic_dropdown'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="dynamic-dropdown"]');
1154 ob_clean();
1155 include_once 'partials/pointers/cf7sg-pointer-tag-benchmark.php';
1156 $content = ob_get_clean();
1157 $pointers['benchmark'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="benchmark"]');
1158 return $pointers;
1159 }
1160 /**
1161 * Rest meta_caps for better fine tuning of user caps.
1162 * hooked to 'wpcf7_map_meta_cap'.
1163 *@since 3.0.0
1164 *@param array $caps key->value pairs of capabilities.
1165 *@return array key->value pairs of capabilities.
1166 */
1167 public function reset_meta_cap($caps){
1168 return array(
1169 'wpcf7_read_contact_form'=>'read_post',
1170 'wpcf7_edit_contact_form' =>'edit_post',
1171 'wpcf7_edit_contact_forms' => 'edit_posts',
1172 'wpcf7_edit_others_contact_forms'=>'edit_others_posts',
1173 'wpcf7_edit_published_contact_forms'=>'edit_published_posts',
1174 'wpcf7_delete_contact_form'=>'delete_post',
1175 'wpcf7_delete_contact_forms'=>'delete_posts',
1176 'wpcf7_delete_published_contact_forms'=>'delete_published_posts',
1177 'wpcf7_delete_others_contact_forms'=>'delete_others_posts',
1178 'wpcf7_publish_contact_forms'=>'publish_posts',
1179 'wpcf7_publish_contact_forms'=>'read_private_posts',
1180 'wpcf7_submit'=>'read', /** @since 3.2.1 to fix subscribers_only. */
1181 );
1182 }
1183 /**
1184 * CF7 plugin by default sets form post status to 'publish' regardless of user capability.
1185 * This functions rectifies this. Hooked to 'wp_insert_post_data'.
1186 *@since 3.0.0
1187 *@param array $data sanitised post data.
1188 *@return array post data.
1189 */
1190 public function pending_for_review($data){
1191 if($this->cf7_post_type() != $data['post_type']) return $data;
1192
1193 $post_type_object = get_post_type_object( $this->cf7_post_type() );
1194 //check if user can publish.
1195 if(!current_user_can($post_type_object->cap->publish_posts) && $data['post_status']=='publish'){
1196 $data['post_status']='pending';
1197 }
1198 // debug_msg('post status '.$data['post_status']);
1199 return $data;
1200 }
1201 /**
1202 * Enable all cf7 capabilites for editors.
1203 * Hooked to action 'admin_init'.
1204 *@since 3.0.0
1205 */
1206 public function enable_cf7_editor_role(){
1207 global $wp_roles;
1208 if ( ! isset( $wp_roles ) ) $wp_roles = new WP_Roles();
1209 $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');
1210 $fe = $wp_roles->get_role('editor');
1211 if(!empty($fe)){ /** @since 3.0.3 in case editor role is deleted */
1212 foreach($caps as $cap) $fe->add_cap($cap);
1213 }
1214 $caps[]='wpcf7_manage_integration';
1215 $ad = $wp_roles->get_role('administrator');
1216 if(!empty($ad)){ /** @since 3.0.3 in case admin role is deleted */
1217 foreach($caps as $cap) $ad->add_cap($cap);
1218 }
1219
1220 /** @since 3.1.3 redirect cf7 plugin pages*/
1221 global $pagenow;
1222 if ( $pagenow == 'admin.php' && isset( $_GET['page'] ) ) {
1223 $url = '';
1224 switch($_GET['page']){
1225 case 'wpcf7-new':
1226 $url = "post-new.php?post_type=wpcf7_contact_form" ;
1227 break;
1228 case 'wpcf7':
1229 if(isset($_GET['post'])) $url = "post.php?post={$_GET['post']}&action=edit&classic-editor";
1230 else $url = "edit.php?post_type=wpcf7_contact_form";
1231 break;
1232 }
1233 if(!empty($url)){
1234 wp_redirect( admin_url( $url ));
1235 exit;
1236 }
1237 }
1238 }
1239 /**
1240 * Add grid helper hooks for individual tags.
1241 * Hooked to action 'cf7sg_ui_grid_helper_hooks'.
1242 *@since 3.3.0
1243 */
1244 public function print_helper_hooks(){
1245 require_once plugin_dir_path( __FILE__ ) .'partials/helpers/cf7sg-form-fields.php';
1246 }
1247 }
1248