PluginProbe
Smart Grid-Layout Design for Contact Form 7 / 4.5
Smart Grid-Layout Design for Contact Form 7 v4.5
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
← All changes | admin/class-cf7-grid-layout-admin.php +347 -669 4.144.5 View file →
@@ -36,9 +36,8 @@
36 36 'index.php'=>'',//dashboard ,
37 37 'plugins.php'=>'',
38 38 //'options-general.php'=>'page=',
39 39 );
40 - public const METAKEYS = array('_cf7sg_sub_forms', '_cf7sg_grid_table_names', '_cf7sg_grid_tabs_names', '_cf7sg_has_tabs', '_cf7sg_has_tables', '_cf7sg_managed_form','_cf7sg_script_classes', '_cf7sg_version', '_cf7sg_grid_toggled_names', '_cf7sg_grid_tabbed_toggles', '_cf7sg_grid_grouped_toggles', '_cf7sg_has_toggles', '_cf7sg_disable_jstags_comments', '_cf7sg_page_redirect', '_cf7sg_cache_redirect_data','_cf7sg_form_page');
41 40 /**
42 41 * The ID of this plugin.
43 42 *
44 43 * @since 1.0.0
@@ -45,19 +44,9 @@
45 44 * @access private
46 45 * @var string $plugin_name The ID of this plugin.
47 46 */
48 47 private $plugin_name;
49 -
50 48 /**
51 - * The ID of this plugin.
52 - *
53 - * @since 4.6.0
54 - * @access public
55 - * @var Constant CF7SG_OPTION Options key.
56 - */
57 - const CF7SG_OPTION = 'cf7sg-plugin-version';
58 -
59 - /**
60 49 * The version of this plugin.
61 50 *
62 51 * @since 1.0.0
63 52 * @access private
@@ -98,9 +87,8 @@
98 87 if (empty($screen) || $this->cf7_post_type() != $screen->post_type){
99 88 return;
100 89 }
101 90 $plugin_dir = plugin_dir_url( __DIR__ );
102 -
103 91 switch( $screen->base ){
104 92 case 'post':
105 93 $page_hook = '';
106 94 if('add' == $screen->action) $page_hook = 'contact_page_wpcf7-new';
@@ -135,19 +123,18 @@
135 123 *
136 124 * @since 1.0.0
137 125 */
138 126 public function enqueue_styles($page) {
139 - if('plugins.php'==$page){
140 - /** @since 4.1.0 */
141 - wp_enqueue_style('plugin-update', plugin_dir_url( __DIR__ ) . 'admin/css/cf7sg-plugin-update.css', array(), $this->version, 'all');
142 - return;
143 - }
144 127
145 128 if( in_array($page, array('toplevel_page_wpcf7', 'contact_page_wpcf7-new')) ) return;
146 -
129 +
147 130 $screen = get_current_screen();
148 131 $plugin_dir = plugin_dir_url( __DIR__ );
149 -
132 + if('plugins'==$screen->base){
133 + /** @since 4.1.0 */
134 + wp_enqueue_style('plugin-update',$plugin_dir . 'admin/css/cf7sg-plugin-update.css', array(), $this->version, 'all');
135 + return;
136 + }
150 137 if (empty($screen) || $this->cf7_post_type() != $screen->post_type){
151 138 return;
152 139 }
153 140 switch( $screen->base ){
@@ -191,9 +178,10 @@
191 178 if( in_array($page, array('toplevel_page_wpcf7', 'contact_page_wpcf7-new')) ){
192 179 wp_enqueue_script( $this->plugin_name, $plugin_dir . 'admin/js/cf7-grid-layout-admin.js', array( 'jquery' ), $this->version, true );
193 180 return;
194 181 }
195 - if('plugins.php'==$page){
182 + $screen = get_current_screen();
183 + if('plugins'==$screen->base){
196 184 /** @since 4.1.0 */
197 185 wp_enqueue_script('cf7sg-plugin-update', $plugin_dir . 'admin/js/cf7sg-plugin-update.js', array('jquery'));
198 186 /* translators: message displayed when succesful update to validate new version */
199 187 wp_localize_script('cf7sg-plugin-update', 'cf7sg',array(
@@ -202,9 +190,8 @@
202 190 'error'=>__('Unable to validate, please reload!', 'cf7-grid-layout')
203 191 ));
204 192 return;
205 193 }
206 - $screen = get_current_screen();
207 194 if ($this->cf7_post_type() != $screen->post_type){
208 195 return;
209 196 }
210 197
@@ -209,9 +196,8 @@
209 196 }
210 197
211 198 switch( $screen->base ){
212 199 case 'post':
213 - global $post;
214 200 /* register codemirror editor & addons. */
215 201 //codemirror script
216 202 wp_register_script( 'cf7-codemirror-js',
217 203 $plugin_dir . 'assets/codemirror/codemirror.js',
@@ -231,9 +217,9 @@
231 217 const cssCodeMirror_5_32 = CodeMirror(document.getElementById("cf7-css-codemirror"),cmInitialSettings);
232 218 const jsCodeMirror_5_32 = CodeMirror(document.getElementById("cf7-js-codemirror"),cmInitialSettings);');
233 219 //matchtags.
234 220 wp_enqueue_script( 'codemirror-closetag-js',
235 - $plugin_dir . 'assets/codemirror/addon/edit/closetag.js',
221 + $plugin_dir . 'assets/codemirror/edit/closetag.js',
236 222 array('cf7-codemirror-js'), $this->version, true
237 223 );
238 224 //fold code
239 225 wp_enqueue_script( 'codemirror-foldcode-js',
@@ -367,10 +353,8 @@
367 353 $user_css_theme = ('light'==$user_css_theme ? 'paraiso-light' : 'material-ocean');
368 354 }
369 355 }
370 356 //enqueue the cf7 scripts.
371 - /** @since 4.11.5 force loading of current form for cf7 plugin error handling */
372 - if('auto-draft'!=$post->post_status) WPCF7_ContactForm::get_instance($post);
373 357 wpcf7_admin_enqueue_scripts( 'wpcf7' );
374 358 wp_enqueue_script('jquery-clibboard', $plugin_dir . 'assets/clipboard/clipboard.min.js', array('jquery'),$this->version,true);
375 359 wp_enqueue_script( 'cf7-grid-codemirror-js', $plugin_dir . 'admin/js/cf7-grid-codemirror.js', array( 'jquery', 'jquery-ui-tabs', 'cf7-codemirror-js' ), $this->version, true );
376 360 wp_localize_script(
@@ -399,25 +383,19 @@
399 383 );
400 384 global $post;
401 385
402 386 wp_enqueue_script( $this->plugin_name, $plugin_dir . 'admin/js/cf7-grid-layout-admin.js', array('cf7-grid-codemirror-js', 'jquery-ui-sortable' ), $this->version, true );
403 - /** @since 4.11.0 abstract out dynamic lists */
404 - do_action('cf7sg_register_dynamic_lists');
405 - $lists = cf7sg_get_dynamic_lists();
406 387 wp_localize_script(
407 388 $this->plugin_name,
408 389 'cf7grid',
409 390 array(
410 - 'preHTML' => apply_filters('cf7sg_pre_cf7_field_html', '<div class="field"><label for=""></label>', $post->post_name),
391 + 'preHTML' => apply_filters('cf7sg_pre_cf7_field_html', '<div class="field"><label></label>', $post->post_name),
411 392 'postHTML' => apply_filters('cf7sg_post_cf7_field_html', '<p class="info-tip"></p></div>', $post->post_name),
412 393 'requiredHTML' => apply_filters('cf7sg_required_cf7_field_html', '<em>*</em>', $post->post_name),
413 - 'ui' => apply_filters('cf7sg_grid_ui', true, $post->post_name),
414 - 'dynamicTags' => array_keys($lists)
394 + 'ui' => apply_filters('cf7sg_grid_ui', true, $post->post_name)
415 395 )
416 396 );
417 397 wp_enqueue_script( 'cf7sg-dynamic-tag-js', $plugin_dir . 'admin/js/cf7sg-dynamic-tag.js', array('jquery','wpcf7-admin-taggenerator' ), $this->version, true );
418 - wp_enqueue_script( 'cf7sg-dynamic-checkbox-js', $plugin_dir . 'admin/js/cf7sg-dynamic-checkbox.js', array('jquery','wpcf7-admin-taggenerator' ), $this->version, true );
419 - wp_enqueue_script( 'cf7sg-dynamic-select-js', $plugin_dir . 'admin/js/cf7sg-dynamic-select.js', array('jquery','wpcf7-admin-taggenerator' ), $this->version, true );
420 398 wp_enqueue_script( 'cf7-benchmark-tag-js', $plugin_dir . 'admin/js/cf7-benchmark-tag.js', array('jquery','wpcf7-admin-taggenerator' ), $this->version, true );
421 399 /** @since 3.2.0 */
422 400 wp_enqueue_script('cf7sg-mail-tag-js', $plugin_dir.'admin/js/mail-tag-helper.js', array('jquery','jquery-clibboard'));
423 401 wp_localize_script('cf7sg-mail-tag-js','mailTagHelper',
@@ -428,9 +406,8 @@
428 406 );
429 407 /** @since 3.3.0 enqueue ui-grid helpers js */
430 408 wp_enqueue_script('ui-grid-helpers-js', $plugin_dir.'admin/js/ui-custom-helper.js', array('jquery'));
431 409 do_action('cf7sg_enqueue_admin_editor_scripts');
432 -
433 410 break;
434 411 case 'edit':
435 412 //wp_enqueue_script( $this->plugin_name.'-quick-edit', plugin_dir_url( __FILE__ ) . 'js/cf7-grid-layout-quick-edit.js', false, $this->version, true );
436 413 /** @since 4.4.0 Enabled user script enqueue */
@@ -487,26 +464,8 @@
487 464 $submenu['wpcf7'] = $arr;
488 465 return $menu_ord;
489 466 }
490 467 /**
491 - * Register plugin.php styling page to warn users on major update.
492 - * hooked on 'after_plugin_row_cf7-grid-layout/cf7-grid-layout.php'
493 - * @param String $plugin_file the plugin file
494 - * @param Array $plugin_data array of plugin attributes
495 - * @param String $status status of plugin update.
496 - * @since 4.14.1
497 - */
498 - public function enable_warning_on_plugin_update($plugin_file, $plugin_data, $status){
499 - //verify that the current version is below the major udpate, and the new version is above or the same as the major udpate
500 - if(!empty($plugin_data['new_version']) &&
501 - version_compare($this->version, CF7SG_MAJOR_UPDATE_VERSION, '<=') &&
502 - version_compare(CF7SG_MAJOR_UPDATE_VERSION, $plugin_data['new_version'], '<=' )){
503 - /* translator: 1. version number */
504 - $msg = sprintf( __('WARNING: Read v%1$s update details!', 'cf7-grid-layout'),CF7SG_MAJOR_UPDATE_VERSION);
505 - printf('<style>#cf7-grid-layout-update{--rpwc2-update-msg:"%1$s";}#cf7-grid-layout-update .update-link::after {display:ruby;}</style>',$msg);
506 - }
507 - }
508 - /**
509 468 * Modify the regsitered cf7 post tppe
510 469 * THis function enables public capability and amind UI visibility for the cf7 post type. Hooked late on `register_post_type_args`
511 470 * @since 1.0.0
512 471 * @param Array $args array of post parameters being registered
@@ -579,10 +538,11 @@
579 538 **/
580 539 public function register_dynamic_dropdown_taxonomy(){
581 540 //register the dynamic dropdown taxonomies.
582 541 $dropdowns = get_option('_cf7sg_dynamic_dropdown_taxonomy',array());
542 + //debug_msg($dropdowns);
583 543 $created = array();
584 - foreach($dropdowns as $post_id=>$post_lists){
544 + foreach($dropdowns as $post_lists){
585 545 foreach($post_lists as $slug=>$taxonomy){
586 546 if(!isset($created[$slug])){
587 547 if(is_array($taxonomy)){
588 548 $this->register_dynamic_dropdown($taxonomy);
@@ -590,197 +550,16 @@
590 550 }
591 551 }
592 552 }
593 553 }
594 - /** @since 5.0 register dynamic_select list */
595 - do_action('cf7sg_register_dynamic_lists');
596 - // debug_msg('created dynamic select ');
597 554 }
598 - /**
599 - * function to regsiter dyanmic dropdown taxonomies
600 - *
601 - * @since 1.0.0
602 - * @param Object $taxonomy_object std object with parameters $taxonomy_object->slug, $taxonomy_object->singular, $taxonomy_object->plural, $taxonomy_object->hierarchical .
603 - **/
604 - protected function register_dynamic_dropdown($taxonomy_array){
605 - $slug = $taxonomy_array['slug'];
606 - $name = $taxonomy_array['singular'];
607 - $plural = $taxonomy_array['plural'];
608 - $is_hierarchical = $taxonomy_array['hierarchical'];
609 555
610 - $labels = array(
611 - 'name' => $plural,
612 - 'singular_name' => $name,
613 - 'menu_name' => $plural,
614 - 'all_items' => 'All '.$plural,
615 - 'parent_item' => 'Parent '.$name,
616 - 'parent_item_colon' => 'Parent '.$name.':',
617 - 'new_item_name' => 'New '.$name.' Name',
618 - 'add_new_item' => 'Add New '.$name,
619 - 'edit_item' => 'Edit '.$name,
620 - 'update_item' => 'Update '.$name,
621 - 'view_item' => 'View '.$name,
622 - 'separate_items_with_commas' => 'Separate '.$plural.' with commas',
623 - 'add_or_remove_items' => 'Add or remove '.$plural,
624 - 'choose_from_most_used' => 'Choose from the most used',
625 - 'popular_items' => 'Popular '.$plural,
626 - 'search_items' => 'Search '.$plural,
627 - 'not_found' => 'Not Found',
628 - 'no_terms' => 'No '.$plural,
629 - 'items_list' => $plural.' list',
630 - 'items_list_navigation' => $plural.' list navigation',
631 - );
632 - //labels can be modified post registration
633 - $args = array(
634 - 'labels' => $labels,
635 - 'hierarchical' => $is_hierarchical,
636 - 'public' => false,
637 - 'show_ui' => true,
638 - 'show_admin_column' => false,
639 - 'show_in_nav_menus' => false,
640 - 'show_tagcloud' => false,
641 - 'show_in_quick_edit' => false,
642 - 'description' => 'Contact Form 7 dynamic dropdown taxonomy list',
643 - );
644 -
645 - register_taxonomy( $slug, $this->cf7_post_type(), $args );
646 - }
647 556 /**
648 - * CF7 Form saved from backend, check if dynamic lists are used
649 - * Hooked on 'wpcf7_save_contact_form'
650 - * @since 1.0.0
651 - * @param WPCF7_Contact_Form $cf7_form cf7 form object
652 - */
653 - public function save_factory_metas($cf7_form){
654 - $cf7_post_id = $cf7_form->id();
655 - //get the tags used in this form
656 - $tags = $cf7_form->scan_form_tags(); //get your form tags
657 - $dynamic_lists = cf7sg_get_dynamic_lists();
658 - $dynamic_tags = array_keys($dynamic_lists);
659 - $dynamic_fields = array();
660 - $form_classes = array();
661 - foreach($tags as $tag){
662 - if(in_array($tag->basetype, $dynamic_tags)){
663 - $dynamic_fields[$tag->basetype]=$tag;
664 - $form_classes = array_merge($form_classes, $dynamic_lists[$tag->basetype]->get_form_classes($tag, $cf7_post_id));
665 - }
666 - }
667 - if(!empty($form_classes)){
668 - $classes = get_post_meta($cf7_post_id, '_cf7sg_script_classes', true);
669 - if(empty($classes)){
670 - $classes = array();
671 - }
672 - $form_classes = array_diff(array_unique($form_classes), $classes); //any new classes?
673 - if(!empty($form_classes)) {
674 - update_post_meta($cf7_post_id, '_cf7sg_script_classes', array_merge($classes, $form_classes));
675 - }
676 - }
677 - //check for newly created taxonomy lists.
678 - if( isset($_POST['cf72post_dynamic_select_taxonomies']) ){
679 - $created_taxonomies = array();
680 - $taxonomies = json_decode(str_replace('\"','"',$_POST['cf72post_dynamic_select_taxonomies']), true);
681 - if(empty($taxonomies)){
682 - $taxonomies = array();
683 - }
684 - foreach($taxonomies as $taxonomy){
685 - //sanitize fields before saving into the DB.
686 - foreach($taxonomy as $key=>$value){
687 - $key = sanitize_key($key);
688 - $taxonomy[$key] = sanitize_text_field($value);
689 - }
690 - $created_taxonomies[$taxonomy['slug']] = $taxonomy;
691 - }
692 - // debug_msg($created_taxonomies, 'created ');
693 - $post_lists = $saved_lists = $system_list = array();
694 -
695 - $dropdowns = get_option('_cf7sg_dynamic_dropdown_taxonomy',array());
696 - foreach($dropdowns as $id => $lists){
697 - $saved_lists = array_merge($saved_lists, $lists);
698 - }
699 - // debug_msg($dynamic_fields, 'dynamic ');
700 - foreach($dynamic_fields as $tag){
701 - if(isset($tag['values'])){
702 - $slug='';
703 - foreach($tag['values'] as $values){
704 - if(0 == strpos($values, 'slug:') ){
705 - $slug = str_replace('slug:', '', $values);
706 - break;
707 - }
708 - }
709 - if(empty($slug)) continue; //not a taxonomy list.
710 - //is slug newly created?
711 - if(isset($created_taxonomies[$slug])){
712 - //store this taxonomy.
713 - $post_lists[$slug] = $created_taxonomies[$slug];
714 - }else if(isset($saved_lists[$slug])){
715 - //retain previously saved list if we are stil using it.
716 - $post_lists[$slug] = $saved_lists[$slug];
717 - }else{ //system taxonomy.
718 - $system_list[] = $slug;
719 - }
720 - //store the taxonomy slug in the cf7 metas.
721 - //$post_lists[$slug] = null;
722 - }
723 - }
724 - // debug_msg($post_lists,' post lists ');
725 - //list of taxonomy to register.
726 - //unset the old value.
727 - if(isset($dropdowns[$cf7_post_id])) unset($dropdowns[$cf7_post_id]);
728 - //unshift new value to top of array.
729 - $dropdowns[$cf7_post_id] = $post_lists;
730 - update_option('_cf7sg_dynamic_dropdown_taxonomy', $dropdowns);
731 - //list of system taxonomy to register
732 - $system_dropdowns = get_option('_cf7sg_dynamic_dropdown_system_taxonomy',array());
733 - $system_dropdowns[$cf7_post_id] = $system_list;
734 - update_option('_cf7sg_dynamic_dropdown_system_taxonomy', $system_dropdowns);
735 - }
736 - }
737 - /**
738 - * Print hiddend field on cf7 post submit box
739 - * Hooked on 'wpcf7_admin_misc_pub_section'
740 - * @since 1.0.0
741 - * @param string $post_id cf7 form post id .
742 - **/
743 - public function dynamic_select_choices($post_id){
744 - echo '<input id="cf72post-dynamic-select" type="hidden" name="cf72post_dynamic_select_taxonomies" />';
745 - }
746 -
747 - /**
748 - * Hide the cf7 form editor page author metabox by default.
749 - * hooked to 'hidden_meta_boxes'.
750 - *@since 4.6.0
751 - *@param Array $hidden array of hidden metabox ids.
752 - *@param WP_Screen $screen current amdin page screen object.
753 - *@param Boolean $use_defaults wether default settings used.
754 - *@return Array array of hidden metabox ids.
755 - */
756 - public function hide_author_metabox($hidden, $screen, $use_defaults){
757 - if( 'wpcf7_contact_form' != $screen->id ) return $hidden;
758 -
759 - if(in_array('authordiv', $hidden)) return $hidden;
760 -
761 - if($use_defaults) $hidden[] = 'authordiv';
762 - else {
763 - $gs = get_option(self::CF7SG_OPTION, array());
764 -
765 - if(!isset($gs['hide_author'])){
766 - $gs['hide_author']=true; //flag it.
767 - $uo = get_user_option('metaboxhidden_wpcf7_contact_form');
768 - if(false === $uo) $uo = array();
769 - $uo = array_unique( array_merge( $uo + array( 'authordiv' ) ) );
770 - $hidden = array_unique( array_merge( $hidden + array( 'authordiv' ) ) );
771 - update_option(self::CF7SG_OPTION,$gs);
772 - update_user_option( get_current_user_id(), 'metaboxhidden_wpcf7_contact_form', $uo);
773 - }
774 - }
775 - return $hidden;
776 - }
777 - /**
778 557 * Function to add the metabox to the cf7 post edit screen
779 558 * This adds the main editor, hooked on 'add_meta_boxes'
780 559 * @since 1.0.0
781 560 */
782 - public function edit_page_metabox() {
561 + public function main_editor_meta_box() {
783 562 //add_meta_box( string $id, string $title, callable $callback, string $screen, string $context, string $priority, array $callback_args)
784 563 if( post_type_exists( $this->cf7_post_type() ) ) {
785 564 add_meta_box( 'meta-box-main-cf7-editor',
786 565 __cf7sg( 'Edit Contact Form' ),
@@ -788,51 +567,53 @@
788 567 $this->cf7_post_type(),
789 568 'normal',
790 569 'high'
791 570 );
792 - add_meta_box( 'meta-box-cf7-info',
793 - __cf7sg( 'Information' ),
794 - array($this , 'info_metabox_display'),
795 - $this->cf7_post_type(),
796 - 'side',
797 - 'high'
798 - );
799 - /** @since 1.1.0 add helper metabox */
800 - add_meta_box( 'meta-box-cf7sg-helper',
801 - __( 'Actions & Filters', 'cf7-grid-layout' ),
802 - array($this , 'helper_metabox_display'),
803 - $this->cf7_post_type(),
804 - 'side',
805 - 'default'
806 - );
807 - /** @since 4.6.0 enable page redirect */
808 - add_meta_box(
809 - 'cf7sg-redirect', // Unique ID
810 - 'Redirect on Submission', // Box title
811 - array($this, 'display_rediect_metabox'), // Content callback, must be of type callable
812 - $this->cf7_post_type() // Post type
813 - );
814 571 }
815 572 }
573 +
816 574 /**
817 575 * Callback function to disolay the main editor meta box
818 576 * @since 1.0.0
819 577 */
820 578 public function main_editor_metabox_display($post){
821 - $post_id = $post->ID;
822 579 if('auto-draft' !== $post->post_status){
823 580 wpcf7_contact_form($post); //set the post
824 581 }
582 + $post_id = $post->ID;
825 583 $cf7_form = wpcf7_get_current_contact_form();
826 584 if ( ! $cf7_form ) {
827 585 $args = apply_filters('cf7sg_new_cf7_form_template_arguments', array());
828 586 $cf7_form = WPCF7_ContactForm::get_template($args);
829 587 }
588 +
589 + // if(empty($post)){
590 + // $post_id = -1;
591 + // }else{
592 + // $post_id = $post->ID;
593 + // }
830 594 require_once WPCF7_PLUGIN_DIR . '/admin/includes/editor.php';
831 595 require_once plugin_dir_path( __FILE__ ) . 'partials/cf7-admin-editor-display.php';
832 596 }
833 597
834 598 /**
599 + * Function to add the metabox to the cf7 post edit screen
600 + * This adds the main editor, hooked on 'add_meta_boxes'
601 + * @since 1.0.0
602 + */
603 + public function info_meta_box() {
604 + //add_meta_box( string $id, string $title, callable $callback, string $screen, string $context, string $priority, array $callback_args)
605 + if(post_type_exists( $this->cf7_post_type() ) ) {
606 + add_meta_box( 'meta-box-cf7-info',
607 + __cf7sg( 'Information' ),
608 + array($this , 'info_metabox_display'),
609 + $this->cf7_post_type(),
610 + 'side',
611 + 'high'
612 + );
613 + }
614 + }
615 + /**
835 616 * Re-introduces the wordpress 'wpcf7_admin_misc_pub_section' for plugins to add their fields for submission
836 617 * Hooked to 'post_submitbox_misc_actions' which fires after post dat/time parameters are printed
837 618 * @since 1.0.0
838 619 * @param WP_Post $post post object being edited/created.
@@ -849,8 +630,25 @@
849 630 public function info_metabox_display($post){
850 631 require_once plugin_dir_path( __FILE__ ) . 'partials/cf7-info-metabox-display.php';
851 632 }
852 633 /**
634 + * Function to add the metabox to the cf7 post edit screen
635 + * This adds the helper, hooked on 'add_meta_boxes'
636 + * @since 1.1.0
637 + */
638 + public function helper_meta_box() {
639 + //add_meta_box( string $id, string $title, callable $callback, string $screen, string $context, string $priority, array $callback_args).
640 + if(post_type_exists( $this->cf7_post_type() ) ) {
641 + add_meta_box( 'meta-box-cf7sg-helper',
642 + __( 'Actions & Filters', 'cf7-grid-layout' ),
643 + array($this , 'helper_metabox_display'),
644 + $this->cf7_post_type(),
645 + 'side',
646 + 'low'
647 + );
648 + }
649 + }
650 + /**
853 651 * Callback function to disolay the helper meta box
854 652 * @since 1.0.0
855 653 */
856 654 public function helper_metabox_display($post){
@@ -859,24 +657,15 @@
859 657 /**
860 658 * Display the editor panels (wpcf7 / codemirror / grid)
861 659 *
862 660 * @since 1.0.0
863 - * @param WPCF7_Contact_Form $form_post .
661 + * @param string $p1 .
662 + * @return string $p2 .
864 663 **/
865 664 public function grid_editor_panel($form_post){
866 665 require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-grid-layout-admin-display.php';
867 666 }
868 667 /**
869 - *
870 - *
871 - *@since 4.6.0
872 - *@param string $param text_description
873 - *@return string text_description
874 - */
875 - public function display_rediect_metabox($post){
876 - require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-redirect-metabox-display.php';
877 - }
878 - /**
879 668 * Clean up post meta, delete sgcf7 corresponding view post.
880 669 * Hooked to action 'before_delete_post'.
881 670 *@since 4.3.0
882 671 *@param int $post_id post ID.
@@ -883,54 +672,13 @@
883 672 *@param WP_Post post object.
884 673 */
885 674 public function delete_post($post_id){
886 675 if(get_post_type($post_id) != WPCF7_ContactForm::post_type) return;
887 - //remove viewing post.
676 + //remove viwing post.
888 677 $preview_id = get_post_meta($post_id, '_cf7sg_form_page',true);
889 678 if(!empty($preview_id)) wp_delete_post($preview_id);
890 - /** @since 4.12.5 delete custom css/js files */
891 - $p = get_post($post_id);
892 - $path = get_stylesheet_directory();
893 - if(realpath("$path/js/{$p->post_name}.js")) unlink( "$path/js/{$p->post_name}.js" );
894 - if(realpath("$path/css/{$p->post_name}.css")) unlink( "$path/css/{$p->post_name}.css" );
895 679 }
896 680 /**
897 - * Bookeeping on trashed posts.
898 - * hooked to 'trashed_post'
899 - *@since 4.12.5
900 - *@param String $post_id
901 - */
902 - public function form_trashed($post_id){
903 - if(get_post_type($post_id) != WPCF7_ContactForm::post_type) return;
904 - $p = get_post($post_id);
905 - $prev = get_post_meta($post_id, '_wp_desired_post_slug', true);
906 - $path = get_stylesheet_directory();
907 - if(realpath("$path/js/{$prev}.js")){ //rename file
908 - rename( "$path/js/{$prev}.js" , "$path/js/{$p->post_name}.js" );
909 - }
910 - if(realpath("$path/css/{$prev}.css")){
911 - rename( "$path/css/{$prev}.css" , "$path/css/{$p->post_name}.css" );
912 - }
913 - }
914 - /**
915 - * Bookeeping on trashed posts.
916 - * hooked to 'trashed_post'
917 - *@since 4.12.5
918 - *@param String $post_id
919 - */
920 - public function form_untrashed($post_id){
921 - if(get_post_type($post_id) != WPCF7_ContactForm::post_type) return;
922 - $p = get_post($post_id);
923 -
924 - $path = get_stylesheet_directory();
925 - if(realpath("$path/js/{$p->post_name}__trashed.js")){ //rename file
926 - rename( "$path/js/{$p->post_name}__trashed.js" , "$path/js/{$p->post_name}.js" );
927 - }
928 - if(realpath("$path/css/{$p->post_name}__trashed.css")){
929 - rename( "$path/css/{$p->post_name}__trashed.css" , "$path/css/{$p->post_name}.css" );
930 - }
931 - }
932 - /**
933 681 * Save cf7 post using ajax
934 682 * Hooked to 'save_post_wpcf7_contact_form'
935 683 * @since 1.0.0
936 684 **/
@@ -961,14 +709,14 @@
961 709 $args['title'] = isset( $_POST['post_title'] ) ? sanitize_text_field($_POST['post_title'], 'Contact Form', 'save') : null;
962 710 $args['locale'] = isset( $_POST['wpcf7-locale'] ) ? sanitize_text_field($_POST['wpcf7-locale']) : null;
963 711 $args['form'] = '';
964 712 $allowed_tags = wp_kses_allowed_html( 'post' ); //filtered in function below.
965 - /** @since 4.8.1 alllow custom input html*/
713 + /** @since 2.10.0 alllow custom input html*/
966 714 $allowed_tags['input']=array( //add additional input html elements
967 - 'type'=>1,'name'=>1,'placeholder'=>1,'value'=>1,'maxlength'=>1,'minlength'=>1, //input fields.
968 - 'spellcheck'=>1,'size'=>1,'readonly'=>1,'pattern'=>1,'list'=>1, //input fields.
715 + 'type'=>1,
969 716 'class'=>1,
970 717 'id'=>1,
718 + 'value'=>1,
971 719 'data-*'=>1,
972 720 );
973 721 $allowed_tags['script']=array('type'=>1);
974 722 $cf7_key = $post->post_name;
@@ -983,9 +731,15 @@
983 731 $args['messages'][$key] = sanitize_text_field($value);
984 732 }
985 733 $args['additional_settings'] = isset( $_POST['wpcf7-additional-settings'] ) ? sanitize_textarea_field($_POST['wpcf7-additional-settings']) : '';
986 734
987 -
735 + //need to unhook this function so as not to loop infinitely
736 + //debug_msg($args, 'saving cf7 posts');
737 + remove_action('save_post_wpcf7_contact_form', array($this, 'save_post'), 10,3);
738 + $contact_form = wpcf7_save_contact_form( $args );
739 + add_action('save_post_wpcf7_contact_form', array($this, 'save_post'), 10,3);
740 + //flag as a grid form
741 + //update_post_meta($post_id, 'cf7_grid_form', true); removed since v2.3 as not used.
988 742 //save sub-forms if any
989 743 $sub_forms = json_decode(stripslashes($_POST['cf7sg-embeded-forms']));
990 744 if(empty($sub_forms)) $sub_forms = array();
991 745 if(!is_array($sub_forms)) $sub_forms = array($sub_forms);
@@ -1060,9 +814,13 @@
1060 814 $has_tables = ( 'true' === $_POST['cf7sg-has-tables']) ? true : false;
1061 815 update_post_meta($post_id, '_cf7sg_has_tables', $has_tables);
1062 816 $has_toggles = ( 'true' === $_POST['cf7sg-has-toggles']) ? true : false;
1063 817 update_post_meta($post_id, '_cf7sg_has_toggles', $has_toggles);
1064 -
818 + /** @since 3.3.5 track toggles in tabs */
819 + // $toggle_in_tabs = json_decode(stripslashes($_POST['cf7sg-toggle-in-tabs']));
820 + // if(empty($toggle_in_tabs)) $toggle_in_tabs = array();
821 + // if(!is_array($toggle_in_tabs)) $toggle_in_tabs = array($toggle_in_tabs);
822 + // update_post_meta($post_id, '_cf7sg_grid_toggle_in_tabs', $toggle_in_tabs);
1065 823 /**
1066 824 * @since 1.2.3 disable cf7sg styling/js for non-cf7sg forms.
1067 825 */
1068 826 $is_cf7sg = ( 'true' === $_POST['is_cf7sg_form']) ? true : false;
@@ -1084,15 +842,12 @@
1084 842 update_user_meta(get_current_user_id(),'_cf7sg_js_cm_theme', $_POST['cf7sg_js_codemirror_theme']);
1085 843 }
1086 844 //save js file if used.
1087 845 $path = get_stylesheet_directory();
1088 - if(!empty($_POST['cf7sg_js_file']) || !empty($_POST['cf7sg_prev_js_file'])){
846 + if(!empty($_POST['cf7sg_js_file'])){
1089 847 //check if the file name is changed.
1090 - if(!empty($_POST['cf7sg_prev_js_file']) && ($fp = realpath(ABSPATH. $_POST['cf7sg_prev_js_file'])) !== false ){
1091 - $path_match = preg_match('/^'.preg_quote("$path/js/",'/').'[^\s!?.\/#*]+\.js$'.'/', $fp);
1092 - if($path_match && !unlink($fp) ){
1093 - debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_js_file']);
1094 - }
848 + if(!empty($_POST['cf7sg_prev_js_file']) && file_exists(ABSPATH. $_POST['cf7sg_prev_js_file'])){
849 + if( !unlink(ABSPATH.$_POST['cf7sg_prev_js_file']) ) debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_js_file']);
1095 850 }
1096 851 if( !is_dir("$path/js/") ) mkdir("$path/js/");
1097 852 file_put_contents( "$path/js/{$cf7_key}.js", stripslashes($_POST['cf7sg_js_file']) );
1098 853 }else if( isset($_POST['cf7sg_js_file']) && file_exists("$path/js/{$cf7_key}.js") ) { //delete file.
@@ -1098,15 +853,12 @@
1098 853 }else if( isset($_POST['cf7sg_js_file']) && file_exists("$path/js/{$cf7_key}.js") ) { //delete file.
1099 854 if( !unlink("$path/js/{$cf7_key}.js") ) debug_msg("CF7SG ADMIN: unable to delete file $path/js/{$cf7_key}.js");
1100 855 }
1101 856 //save css file.
1102 - if(!empty($_POST['cf7sg_css_file']) || !empty($_POST['cf7sg_prev_css_file'])){
857 + if(!empty($_POST['cf7sg_css_file'])){
1103 858 //check if the file is changed.
1104 - if(!empty($_POST['cf7sg_prev_css_file']) && ($fp = realpath(ABSPATH.$_POST['cf7sg_prev_css_file'])) !==false ){
1105 - $path_match = preg_match('/^'.preg_quote("$path/css/",'/').'[^\s!?.\/#*]+\.css$'.'/', $fp);
1106 - if($path_match && !unlink($fp) ){
1107 - debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_css_file']);
1108 - }
859 + if(!empty($_POST['cf7sg_prev_css_file']) && file_exists(ABSPATH.$_POST['cf7sg_prev_css_file'])){
860 + if( !unlink(ABSPATH.$_POST['cf7sg_prev_css_file']) ) debug_msg('CF7SG ADMIN: unable to delete file '.$_POST['cf7sg_prev_css_file']);
1109 861 }
1110 862 if( !is_dir("$path/css/") ) mkdir("$path/css/");
1111 863 file_put_contents( $path."/css/{$cf7_key}.css", stripslashes($_POST['cf7sg_css_file']));
1112 864 }else if( isset($_POST['cf7sg_css_file']) && file_exists("$path/css/{$cf7_key}.css") ) { //delete file.
@@ -1125,20 +877,8 @@
1125 877 'post_status'=>'draft',
1126 878 'post_type'=>'cf7sg_page',
1127 879 // 'post_name' => sanitize_title( $title ),
1128 880 );
1129 - /** @since 4.6.0 redirect on submit */
1130 - if(isset($_POST['cf7sg_page_redirect'])){
1131 - $redirect_to = absint($_POST['cf7sg_page_redirect']);
1132 - update_post_meta($post->ID, '_cf7sg_page_redirect',$redirect_to);
1133 - if(isset($_POST['cache_cf7sg_submit']) and isset($_POST['cf7sg_cached_time']) and isset($_POST['cf7sg_cached_unit'])){
1134 - $cache = floatval( $_POST['cf7sg_cached_time']);
1135 - if($cache>0){
1136 - $cache=array($cache, absint($_POST['cf7sg_cached_unit']));
1137 - update_post_meta($post->ID, '_cf7sg_cache_redirect_data',$cache);
1138 - }
1139 - }else delete_post_meta($post->ID, '_cf7sg_cache_redirect_data');
1140 - }
1141 881 if(empty($cf7_key)) $prev_page['post_content'] = '[contact-form-7 id="'.$post->ID.'"]';
1142 882 if( !empty($preview_id) ){
1143 883 $prev_page['ID'] = $preview_id;
1144 884 }
@@ -1145,33 +885,8 @@
1145 885 $preview_id = wp_insert_post($prev_page, true);
1146 886 if(!is_wp_error($preview_id)){
1147 887 update_post_meta($post->ID, '_cf7sg_form_page',$preview_id);
1148 888 }
1149 - //save wpcf7 form
1150 - //need to unhook this function so as not to loop infinitely
1151 - //debug_msg($args, 'saving cf7 posts');
1152 - remove_action('save_post_wpcf7_contact_form', array($this, 'save_post'), 10,3);
1153 - // debug_msg($args['form'],'form ');
1154 - /** @since 4.11.5 filter wp_kses ffrmo cf7 plugin v5.5 */
1155 - add_filter('wpcf7_kses_allowed_html', function($cf7_tags, $context) use ($allowed_tags){
1156 - if('form'==$context) return array_merge($cf7_tags, $allowed_tags);
1157 - return $cf7_tags;
1158 - },1001,2);
1159 - $contact_form = wpcf7_save_contact_form( $args );
1160 - /** @since 4.11.5 cf7 plugin validate form */
1161 - if(function_exists('wpcf7_validate_configuration') &&
1162 - method_exists('WPCF7_ConfigValidator','validate') &&
1163 - method_exists('WPCF7_ConfigValidator','save') ){
1164 - if ( $contact_form and wpcf7_validate_configuration() ) {
1165 - $config_validator = new WPCF7_ConfigValidator( $contact_form );
1166 - $config_validator->validate();
1167 - $config_validator->save();
1168 - }
1169 - }
1170 - add_action('save_post_wpcf7_contact_form', array($this, 'save_post'), 10,3);
1171 -
1172 - /** @since 4.9.2 fire form saving action so as to prevent double save_post hook calls on other plugins */
1173 - do_action('cf7sg_save_post',$post_id, $post, $update);
1174 889 }
1175 890 /**
1176 891 * Print default js template,
1177 892 * Hooked to 'cf7sg_default_custom_js_template'
@@ -1182,15 +897,18 @@
1182 897 $js_file = str_replace(ABSPATH, '', get_stylesheet_directory()."/js/{$form_key}.js");
1183 898 include_once 'partials/cf7-default-js.php';
1184 899 }
1185 900 /**
1186 - * Called by duplicate_cf7_form.
901 + *
902 + *
1187 903 *@since 2.3.0
1188 904 *@param string $new_form_id new form id to duplciate to.
1189 905 *@param string $form_id form id to duplciate.
1190 906 */
1191 - public function duplicate_form_properties($form_id, $new_form_id){
1192 - $properties = apply_filters('cf7sg_duplicate_form_properties', Cf7_Grid_Layout_Admin::METAKEYS);
907 + public function duplicate_form_properties($new_form_id, $form_id){
908 + //these properties will be preceded with an '_' by the cf7 plugin before being duplicated.
909 + $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');
910 + $properties = apply_filters('cf7sg_duplicate_form_properties', $properties);
1193 911 foreach($properties as $field){
1194 912 $value = get_post_meta($form_id, $field, true);
1195 913 if(!empty($value)) update_post_meta($new_form_id,$field, $value);
1196 914 }
@@ -1196,10 +914,11 @@
1196 914 }
1197 915 }
1198 916 /**
1199 917 * Duplicate form.
1200 - * Hooked to 'admin_init', looks out for URL action parameter set to cf7copy.
918 + *
1201 919 *@since 2.3.0
920 + *@param string $param text_description
1202 921 *@return string text_description
1203 922 */
1204 923 public function duplicate_cf7_form(){
1205 924 global $pagenow;
@@ -1211,21 +930,9 @@
1211 930 }
1212 931 if ( $form = wpcf7_contact_form( $_GET['post'] ) ) {
1213 932 $new_form = $form->copy();
1214 933 $new_form->save();
1215 - self::duplicate_form_properties($_GET['post'],$new_form->id());
1216 - /** @since 4.11 duplicate js/css files */
1217 - $new_key = get_cf7form_key($new_form->id());
1218 - $key = get_cf7form_key($form->id());
1219 - $path = get_stylesheet_directory();
1220 - $js_file = "$path/js/{$key}.js";
1221 - if( file_exists($js_file) ){
1222 - copy($js_file, "$path/js/{$new_key}.js");
1223 - }
1224 - $css_file = "$path/css/{$key}.css";
1225 - if( file_exists($css_file) ){
1226 - copy($css_file, "$path/css/{$new_key}.css");
1227 - }
934 + $this->duplicate_form_properties($new_form->id(), $_GET['post']);
1228 935 wp_safe_redirect( admin_url( '/post.php?post='.$new_form->id().'&action=edit' ));
1229 936 exit;
1230 937 }
1231 938 }
@@ -1300,23 +1007,35 @@
1300 1007 * @since 1.0.0
1301 1008 **/
1302 1009 public function cf7_shortcode_tags(){
1303 1010 if ( class_exists( 'WPCF7_TagGenerator' ) ) {
1304 - /** @since 4.10.0 enable extension of dynamic lists */
1305 1011 $tag_generator = WPCF7_TagGenerator::get_instance();
1306 1012 $tag_generator->add(
1013 + 'dynamic_select', //tag id
1014 + __( 'dynamic-dropdown', 'cf7_2_post' ), //tag button label
1015 + array($this,'dynamic_tag_generator') //callback
1016 + );
1017 + $tag_generator->add(
1307 1018 'benchmark', //tag id
1308 1019 __( 'benchmark', 'cf7_2_post' ), //tag button label
1309 1020 array($this,'benchmark_tag_generator') //callback
1310 1021 );
1311 1022 }
1312 - /** @since 4.10.0 abstract out dynamic lists */
1313 - do_action('cf7sg_register_dynamic_lists');
1314 - $lists = cf7sg_get_dynamic_lists();
1315 - foreach($lists as $l) $l->register_cf7_tag();
1316 1023 }
1317 -
1318 1024 /**
1025 + * Dynamic select screen displayt.
1026 + *
1027 + * This function is called by cf7 plugin, and is registered with a hooked function above
1028 + *
1029 + * @since 1.0.0
1030 + * @param WPCF7_ContactForm $contact_form the cf7 form object
1031 + * @param array $args arguments for this form.
1032 + */
1033 + function dynamic_tag_generator( $contact_form, $args = '' ) {
1034 + $args = wp_parse_args( $args, array() );
1035 + include( plugin_dir_path( __FILE__ ) . '/partials/cf7-dynamic-tag-display.php');
1036 + }
1037 + /**
1319 1038 * Benchmark input screen displayt.
1320 1039 *
1321 1040 * This function is called by cf7 plugin, and is registered with a hooked function above
1322 1041 *
@@ -1328,82 +1047,138 @@
1328 1047 $args = wp_parse_args( $args, array() );
1329 1048 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-benchmark-tag.php');
1330 1049 }
1331 1050 /**
1332 - * Print the dynamic list tag generator form.
1333 - * Hooked on 'cf7sg_display_dynamic_list_tag_manager'.
1334 - * allows other plugins to customise the tag manager for their own dynamic field.
1335 - *@since 4.11.0
1336 - *@param String $tag_id dynamic list tag id.
1337 - *@param CF7SG_Dynamic_list $dlo dynamic list object.
1338 - *@param WPCF7_Contact_Form $form cf7 form object.
1339 - *@param Array $args cf7 form shortcode attributes
1340 - */
1341 - public function print_dynamic_list_generator($tag_id, $dlo, $form, $args){
1342 - include plugin_dir_path( __FILE__ ) . 'partials/cf7-dynamic-tag-display.php';
1051 + * Print hiddend field on cf7 post submit box
1052 + * Hooked on 'wpcf7_admin_misc_pub_section'
1053 + * @since 1.0.0
1054 + * @param string $post_id cf7 form post id .
1055 + **/
1056 + public function dynamic_select_choices($post_id){
1057 + echo '<input id="cf72post-dynamic-select" type="hidden" name="cf72post_dynamic_select_taxonomies" />';
1343 1058 }
1344 1059 /**
1345 - * Add custom imagegrid hook to taxonomy source.
1346 - * Hooked to 'cf7sg_dynamic_tag_manager_taxonomy_source'
1347 - *@since 4.11.0
1348 - *@param String $tag_id dynamic list tag id.
1060 + * CF7 Form saved from backend, check if dynamic-select are used
1061 + * Hooked on 'wpcf7_save_contact_form'
1062 + * @since 1.0.0
1063 + * @param WPCF7_Contact_Form $cf7_form cf7 form object
1349 1064 */
1350 - public function add_taxonomy_imagegrid_hook($tag_id){
1351 - if('dynamic_checkbox' != $tag_id) return;
1352 - ?>
1353 - <p class="imagegrid-filter display-none filter-hook">
1354 - <strong><?=__('Filter imagegrid image sources','cf7-grid-layout')?></strong><br />
1355 - <?php echo sprintf(__('Copy the following <a class="%s" href="javascript:void(0);">filter</a> to your <em>functions.php</em> file.', 'cf7-grid-layout'), 'cf7sg_filter_taxonomy_images');?>
1356 - </p>
1357 - <?php
1358 - }
1359 - /**
1360 - * Function to get classes to be added to the form wrapper.
1361 - * these classes will be passed in the resource enqueue action, allowing for specific js/css resources
1362 - * to be queued up and loaded on the page where the form is being displayed.
1363 - * hooked to 'cf7sg_save_dynamic_list_form_classes'
1364 - * @param Array array of classes to be added to the form wrapper.
1365 - * @param WPCF7_FormTag cf7 tag object for the form field.
1366 - * @param int $form_id cf7 fomr post ID..
1367 - * @return Array an array of classes to be added to the form to which this tag belonggs to.
1368 - */
1369 - public function save_dynamic_list_form_classes($form_classes, $tag, $form_id){
1370 - /* Bookeeping, set up tagged select2 fields to filter newly added options in case Post My CF7 Form plugin is running */
1371 - $class = $tag->get_class_option('');
1372 - switch($tag->basetype){
1373 - case 'dynamic_select':
1374 - if(strpos($class, 'select2')){
1375 - $form_classes[] = 'has-select2';
1376 - //track this field if user sets custom options.
1377 - if(strpos($class, 'tags')){
1378 - $tagged_fields = get_post_meta($form_id, '_cf7sg_select2_tagged_fields', true);
1379 - if(empty($tagged_fields)){
1380 - $tagged_fields = array();
1065 + public function save_factory_metas($cf7_form){
1066 + $cf7_post_id = $cf7_form->id();
1067 + //get the tags used in this form
1068 + if( isset($_POST['cf72post_dynamic_select_taxonomies']) ){
1069 + $created_taxonomies = array();
1070 + $taxonomies = json_decode(str_replace('\"','"',$_POST['cf72post_dynamic_select_taxonomies']), true);
1071 + if(empty($taxonomies)){
1072 + $taxonomies = array();
1073 + }
1074 + foreach($taxonomies as $taxonomy){
1075 + //sanitize fields before saving into the DB.
1076 + foreach($taxonomy as $key=>$value){
1077 + $key = sanitize_key($key);
1078 + $taxonomy[$key] = sanitize_text_field($value);
1079 + }
1080 + $created_taxonomies[$taxonomy['slug']] = $taxonomy;
1081 + }
1082 + //debug_msg($created_taxonomies);
1083 + $tags = $cf7_form->scan_form_tags(); //get your form tags
1084 + $post_lists = $saved_lists = $system_list = array();
1085 +
1086 + $dropdowns = get_option('_cf7sg_dynamic_dropdown_taxonomy',array());
1087 + foreach($dropdowns as $id => $lists){
1088 + $saved_lists = array_merge($saved_lists, $lists);
1089 + }
1090 + foreach($tags as $tag){
1091 + if('dynamic_select' == $tag['basetype']){
1092 + if(isset($tag['values'])){
1093 + $slug='';
1094 + foreach($tag['values'] as $values){
1095 + if(0 == strpos($values, 'slug:') ){
1096 + $slug = str_replace('slug:', '', $values);
1097 + break;
1098 + }
1381 1099 }
1382 - if( !isset($tagged_fields[$tag->name]) ){
1383 - $tagged_fields[$tag->name] = $source;
1384 - update_post_meta($form_id, '_cf7sg_select2_tagged_fields',$tagged_fields);
1100 + if(empty($slug)) continue; //not a taxonomy list.
1101 + //is slug newly created?
1102 + if(isset($created_taxonomies[$slug])){
1103 + //store this taxonomy.
1104 + $post_lists[$slug] = $created_taxonomies[$slug];
1105 + }else if(isset($saved_lists[$slug])){
1106 + //retain previously saved list if we are stil using it.
1107 + $post_lists[$slug] = $saved_lists[$slug];
1108 + }else{ //system taxonomy.
1109 + $system_list[] = $slug;
1385 1110 }
1111 + //store the taxonomy slug in the cf7 metas.
1112 + //$post_lists[$slug] = null;
1386 1113 }
1387 1114 }
1388 - if(false != strpos($class, 'nice-select') || false !=strpos($class, 'ui-select')){
1389 - $form_classes[] = 'has-nice-select';
1390 - }
1391 - break;
1392 - case 'dynamic_checkbox':
1393 - switch(true){
1394 - case strpos($class, 'hybriddd'):
1395 - case strpos($class, 'imagehdd'):
1396 - case strpos($class, 'imagegrid'):
1397 - case strpos($class, 'treeview'):
1398 - $form_classes[] = 'has-hybriddd';
1399 - break;
1400 - }
1401 - break;
1115 + }
1116 + //list of taxonomy to register.
1117 + //unset the old value.
1118 + unset($dropdowns[$cf7_post_id]);
1119 + //unshift new value to top of array.
1120 + $dropdowns = array($cf7_post_id => $post_lists) + $dropdowns ;
1121 +
1122 + update_option('_cf7sg_dynamic_dropdown_taxonomy', $dropdowns);
1123 + //list of system taxonomy to register
1124 + $system_dropdowns = get_option('_cf7sg_dynamic_dropdown_system_taxonomy',array());
1125 + $system_dropdowns[$cf7_post_id] = $system_list;
1126 + update_option('_cf7sg_dynamic_dropdown_system_taxonomy', $system_dropdowns);
1127 +
1402 1128 }
1403 - return $form_classes;
1404 1129 }
1130 +
1405 1131 /**
1132 + * function to regsiter dyanmic dropdown taxonomies
1133 + *
1134 + * @since 1.0.0
1135 + * @param Object $taxonomy_object std object with parameters $taxonomy_object->slug, $taxonomy_object->singular, $taxonomy_object->plural, $taxonomy_object->hierarchical .
1136 + **/
1137 + protected function register_dynamic_dropdown($taxonomy_array){
1138 + $slug = $taxonomy_array['slug'];
1139 + $name = $taxonomy_array['singular'];
1140 + $plural = $taxonomy_array['plural'];
1141 + $is_hierarchical = $taxonomy_array['hierarchical'];
1142 +
1143 + $labels = array(
1144 + 'name' => $plural,
1145 + 'singular_name' => $name,
1146 + 'menu_name' => $plural,
1147 + 'all_items' => 'All '.$plural,
1148 + 'parent_item' => 'Parent '.$name,
1149 + 'parent_item_colon' => 'Parent '.$name.':',
1150 + 'new_item_name' => 'New '.$name.' Name',
1151 + 'add_new_item' => 'Add New '.$name,
1152 + 'edit_item' => 'Edit '.$name,
1153 + 'update_item' => 'Update '.$name,
1154 + 'view_item' => 'View '.$name,
1155 + 'separate_items_with_commas' => 'Separate '.$plural.' with commas',
1156 + 'add_or_remove_items' => 'Add or remove '.$plural,
1157 + 'choose_from_most_used' => 'Choose from the most used',
1158 + 'popular_items' => 'Popular '.$plural,
1159 + 'search_items' => 'Search '.$plural,
1160 + 'not_found' => 'Not Found',
1161 + 'no_terms' => 'No '.$plural,
1162 + 'items_list' => $plural.' list',
1163 + 'items_list_navigation' => $plural.' list navigation',
1164 + );
1165 + //labels can be modified post registration
1166 + $args = array(
1167 + 'labels' => $labels,
1168 + 'hierarchical' => $is_hierarchical,
1169 + 'public' => false,
1170 + 'show_ui' => true,
1171 + 'show_admin_column' => false,
1172 + 'show_in_nav_menus' => false,
1173 + 'show_tagcloud' => false,
1174 + 'show_in_quick_edit' => false,
1175 + 'description' => 'Contact Form 7 dynamic dropdown taxonomy list',
1176 + );
1177 +
1178 + register_taxonomy( $slug, $this->cf7_post_type(), $args );
1179 + }
1180 + /**
1406 1181 * Deactivate this plugin if CF7 plugin is deactivated.
1407 1182 * Hooks on action 'admin_init'
1408 1183 * @since 2.1
1409 1184 */
@@ -1459,20 +1234,20 @@
1459 1234 // Get array list of dismissed pointers for current user and convert it to array
1460 1235 $user_id = get_current_user_id();
1461 1236 $dismissed_pointers = explode( ',', get_user_meta( $user_id, 'dismissed_wp_pointers', true ) );
1462 1237 $pointers = array();
1463 - $helpers = array();
1464 1238 /**
1465 1239 * Filter to add custom pointers for user iterface.
1466 1240 * @var array $pointers an array of $pointer_id=>array($content, $arrow, $valign) key/value pairs to filter. The key is the pointer id to identify which ones the user has dismissed. The value is an array with the message $content, the position of the $arrow (left|right|top|bottom), the vertical alignment ($valign) of the box (center|top|bottom).
1467 1241 * @return array an array of pointers, which will be checked agains the current user.
1468 1242 */
1469 - $filter_pointers = apply_filters('cf7sg_plugin_pointers-'.$screen->id, array(),$dismissed_pointers);
1243 + $filter_pointers = apply_filters('cf7sg_plugin_pointers-'.$screen->id, array());
1470 1244 foreach($filter_pointers as $id=>$pointer){
1471 - $enqueue_pointer = true;
1472 - if(is_array($pointer)){
1245 + // Check if our pointer is not among dismissed ones
1246 + if( !in_array( $id, $dismissed_pointers ) ) {
1247 + $enqueue_pointer = true;
1473 1248 $pointers[$id] = array($pointer[0], $pointer[1], $pointer[2], $pointer[3]);
1474 - }else $helpers[$id] = $pointer;
1249 + }
1475 1250 }
1476 1251 // Enqueue pointer CSS and JS files, if needed
1477 1252 if( $enqueue_pointer ) {
1478 1253 wp_enqueue_style( 'wp-pointer' );
@@ -1478,56 +1253,41 @@
1478 1253 wp_enqueue_style( 'wp-pointer' );
1479 1254 wp_enqueue_script( 'wp-pointer' );
1480 1255 wp_enqueue_script('cf7sg-pointer-js', plugin_dir_url( __DIR__ ).'admin/js/cf7sg-pointers.js', array('jquery'), $this->version, true);
1481 1256 wp_localize_script('cf7sg-pointer-js', 'cf7sg_pointers',
1482 - array(
1483 - 'pointers'=>$pointers,
1484 - 'helpers'=>$helpers,
1485 - 'next'=>__('Next', 'cf7-grid-layout')
1486 - )
1257 + array('pointers'=>$pointers, 'next'=>__('Next', 'cf7-grid-layout'))
1487 1258 );
1488 1259 // Add footer scripts using callback function
1489 -
1260 + //add_action( 'admin_print_footer_scripts', array($this, 'pretty_pointer_script') );
1490 1261 }
1491 1262 }
1492 -
1493 1263 /**
1494 1264 * CF7 Table pointer notices.
1495 1265 * Hooked on 'cf7sg_plugin_pointers-edit-wpcf7_contact_form'
1496 1266 *@since 2.6.0
1497 - *@param Array $pointers array of pointers to suplement
1498 - *@param Array $dismissed array of dismissed pointer ids.
1499 - *@return Array array of pointers element-id=>hmtl to display key value pairs.
1267 + *@param array $pointers array of pointers to suplement
1268 + *@return array array of pointers element-id=>hmtl to display key value pairs.
1500 1269 */
1501 - public function edit_pointers($pointers, $dismissed){
1270 + public function edit_pointers($pointers){
1502 1271 ob_start();
1503 - /* update forms */
1504 - if( !in_array( 'update_forms_pointer', $dismissed ) ) {
1505 - include_once 'partials/pointers/cf7sg-pointer-update-forms.php';
1506 - $content =ob_get_contents();
1507 - $pointers['update_forms_pointer'] = array($content, 'left', 'center','');
1508 - ob_clean();
1509 - }
1272 + include_once 'partials/pointers/cf7sg-pointer-update-forms.php';
1273 + $content =ob_get_contents();
1274 + $pointers['update_forms_pointer'] = array($content, 'left', 'center','');
1510 1275 /* tutorials */
1511 - if( !in_array( 'tutorials_pointer', $dismissed ) ) {
1512 - include_once 'partials/pointers/cf7sg-pointer-tutorials.php';
1513 - $content =ob_get_contents();
1514 - $pointers['tutorials_pointer'] = array($content, 'left', 'center','a[href="admin.php?page=cf7sg_help"]');
1515 - ob_clean();
1516 - }else if( !in_array( 'new_tutorials_pointer', $dismissed ) ) { /* new tutorials */
1517 - include_once 'partials/pointers/cf7sg-pointer-tutorial-advance.php';
1518 - $content =ob_get_contents();
1519 - $pointers['new_tutorials_pointer'] = array($content, 'left', 'center','a[href="admin.php?page=cf7sg_help"]');
1520 - ob_clean();
1521 - }
1276 + ob_clean();
1277 + include_once 'partials/pointers/cf7sg-pointer-tutorials.php';
1278 + $content =ob_get_contents();
1279 + $pointers['tutorials_pointer'] = array($content, 'left', 'center','a[href="admin.php?page=cf7sg_help"]');
1280 + /* new tutorials */
1281 + ob_clean();
1282 + include_once 'partials/pointers/cf7sg-pointer-tutorial-advance.php';
1283 + $content =ob_get_contents();
1284 + $pointers['new_tutorials_pointer'] = array($content, 'left', 'center','a[href="admin.php?page=cf7sg_help"]');
1522 1285 /* shortcodes */
1523 - if( !in_array( 'cf7sg_shortcodes', $dismissed ) ) {
1524 - include_once 'partials/pointers/cf7sg-pointer-shortcodes.php';
1525 - $content = ob_get_contents();
1526 - $pointers['cf7sg_shortcodes'] = array($content, 'top', 'top','');
1527 - ob_clean();
1528 - }
1529 - ob_end_clean();
1286 + ob_clean();
1287 + include_once 'partials/pointers/cf7sg-pointer-shortcodes.php';
1288 + $content = ob_get_clean();
1289 + $pointers['cf7sg_shortcodes'] = array($content, 'top', 'top','');
1530 1290 return $pointers;
1531 1291 }
1532 1292 /**
1533 1293 * CF7 Edit pointer notices.
@@ -1532,83 +1292,56 @@
1532 1292 /**
1533 1293 * CF7 Edit pointer notices.
1534 1294 * Hooked on 'cf7sg_plugin_pointers-wpcf7_contact_form'
1535 1295 *@since 2.6.0
1536 - *@param Array $pointers array of pointers to suplement
1537 - *@param Array $dismissed array of dismissed pointer ids.
1538 - *@return Array array of pointers element-id=>hmtl to display key value pairs.
1296 + *@param array $pointers array of pointers to suplement
1297 + *@return array array of pointers element-id=>hmtl to display key value pairs.
1539 1298 */
1540 - public function post_pointers($pointers, $dismissed){
1299 + public function post_pointers($pointers){
1541 1300 ob_start();
1542 - /* full screen button */
1543 - if( !in_array( 'full_screen', $dismissed ) ) {
1544 - include_once 'partials/pointers/cf7sg-pointer-editor-full-screen.php';
1545 - $content =ob_get_contents();
1546 - //content / arrow [top,bottom,left,right] / box align [top,bottom,center] / css selector.
1547 - $pointers['full_screen'] = array($content, 'left', 'center','#full-screen-cf7');
1548 - ob_clean();
1549 - }
1550 - /* editor_tabs */
1551 - if( !in_array( 'editor_tabs', $dismissed ) ) {
1552 - include_once 'partials/pointers/cf7sg-pointer-editor-tabs.php';
1553 - $content =ob_get_contents();
1554 - $pointers['editor_tabs'] = array($content, 'right', 'center','#form-editor-tabs>ul>li.ui-tabs-active');
1555 - ob_clean();
1556 - }
1557 - /* row_controls */
1558 - if( !in_array( 'row_controls', $dismissed ) ) {
1559 - include_once 'partials/pointers/cf7sg-pointer-editor-rows-control.php';
1560 - $content = ob_get_contents();
1301 + include_once 'partials/pointers/cf7sg-pointer-editor-full-screen.php';
1302 + $content =ob_get_contents();
1303 + //content / arrow [top,bottom,left,right] / box align [top,bottom,center] / css selector.
1304 + $pointers['full_screen'] = array($content, 'left', 'center','#full-screen-cf7');
1305 + /* shortcodes */
1306 + ob_clean();
1307 + include_once 'partials/pointers/cf7sg-pointer-editor-tabs.php';
1308 + $content =ob_get_contents();
1309 + $pointers['editor_tabs'] = array($content, 'right', 'center','#form-editor-tabs>ul>li.ui-tabs-active');
1310 + /* shortcodes */
1311 + ob_clean();
1312 + include_once 'partials/pointers/cf7sg-pointer-editor-rows-control.php';
1313 + $content = ob_get_contents();
1314 + if(!empty($content)){
1561 1315 $pointers['row_controls'] = array($content, 'right', 'center','#grid-form>.container>.row>.row-controls');
1562 1316 ob_clean();
1563 1317 }
1564 1318 /* preview form */
1565 - if( !in_array( 'preview_form', $dismissed ) ) {
1566 - include_once 'partials/pointers/cf7sg-pointer-editor-preview-form.php';
1567 - $content = ob_get_contents();
1319 + ob_clean();
1320 + include_once 'partials/pointers/cf7sg-pointer-editor-preview-form.php';
1321 + $content = ob_get_contents();
1322 + if(!empty($content)){
1568 1323 $pointers['preview_form'] = array($content, 'right', 'center','#preview-form-link');
1569 1324 ob_clean();
1570 1325 }
1571 - /* column controls */
1572 - if( !in_array( 'column_controls', $dismissed ) ) {
1573 - include_once 'partials/pointers/cf7sg-pointer-editor-column-control.php';
1574 - $content = ob_get_contents();
1575 - $pointers['column_controls'] = array($content, 'left', 'center','#grid-form > .container:first-child > .row > .columns:first-child > .grid-column > span.icon-code');
1326 + include_once 'partials/pointers/cf7sg-pointer-editor-column-control.php';
1327 + $content = ob_get_contents();
1328 + if(!empty($content)){
1329 + $pointers['column_controls'] = array($content, 'left', 'center','#grid-form>.container>.row>.columns:first-child>.grid-column>span.icon-code');
1576 1330 ob_clean();
1577 1331 }
1578 - /*dynamic-dropdown pointer*/
1579 - if( !in_array( 'dynamic_dropdown', $dismissed ) ) {
1580 - include_once 'partials/pointers/cf7sg-pointer-tag-dynamic-dropdown.php';
1581 - $content = ob_get_contents();
1582 - $pointers['dynamic_dropdown'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="dynamic-dropdown"]');
1583 - ob_clean();
1584 - }
1585 - /*dynamic-checkbox pointer*/
1586 - if( !in_array( 'dynamic_checkbox', $dismissed ) ) {
1587 - include_once 'partials/pointers/cf7sg-pointer-tag-dynamic-checkbox.php';
1588 - $content = ob_get_contents();
1589 - $pointers['dynamic_checkbox'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="dynamic-checkbox"]');
1590 - ob_clean();
1591 - }
1332 + include_once 'partials/pointers/cf7sg-pointer-tag-dynamic-dropdown.php';
1333 + $content = ob_get_contents();
1334 + $pointers['dynamic_dropdown'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="dynamic-dropdown"]');
1335 + ob_clean();
1592 1336 /* #optional-editors */
1593 - if( !in_array( 'js_css_editors', $dismissed ) ) {
1594 - include_once 'partials/pointers/cf7sg-pointers-editor-optional-js-css.php';
1595 - $content = ob_get_contents();
1596 - $pointers['js_css_editors'] = array($content, 'left', 'center','#optional-editors');
1597 - ob_clean();
1598 - }
1599 - /*benchmark pointer*/
1600 - if( !in_array( 'benchmark', $dismissed ) ) {
1601 - include_once 'partials/pointers/cf7sg-pointer-tag-benchmark.php';
1602 - $content = ob_get_contents();
1603 - $pointers['benchmark'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="benchmark"]');
1604 - ob_clean();
1605 - }
1606 - /*UI tags pointer include always*/
1607 - include_once 'partials/pointers/cf7sg-pointer-tag-ui-editor-tags.php';
1337 + include_once 'partials/pointers/cf7sg-pointers-editor-optional-js-css.php';
1608 1338 $content = ob_get_contents();
1609 - $pointers['ui_editor_tags'] = $content; //controlled within js script
1610 - ob_end_clean();
1339 + $pointers['js_css_editors'] = array($content, 'left', 'center','#optional-editors');
1340 + ob_clean();
1341 + include_once 'partials/pointers/cf7sg-pointer-tag-benchmark.php';
1342 + $content = ob_get_clean();
1343 + $pointers['benchmark'] = array($content, 'left', 'center','#top-tags>#tag-generator-list > a[title*="benchmark"]');
1611 1344 return $pointers;
1612 1345 }
1613 1346 /**
1614 1347 * Rest meta_caps for better fine tuning of user caps.
@@ -1639,14 +1372,14 @@
1639 1372 *@since 3.0.0
1640 1373 *@param array $data sanitised post data.
1641 1374 *@return array post data.
1642 1375 */
1643 - public function pending_for_review($data, $post){
1376 + public function pending_for_review($data){
1644 1377 if($this->cf7_post_type() != $data['post_type']) return $data;
1645 1378
1646 1379 $post_type_object = get_post_type_object( $this->cf7_post_type() );
1647 1380 //check if user can publish.
1648 - if(isset($post['ID']) && !current_user_can($post_type_object->cap->publish_posts, $post['ID']) && $data['post_status']=='publish'){
1381 + if(!current_user_can($post_type_object->cap->publish_posts) && $data['post_status']=='publish'){
1649 1382 $data['post_status']='pending';
1650 1383 }
1651 1384 // debug_msg('post status '.$data['post_status']);
1652 1385 return $data;
@@ -1671,9 +1404,8 @@
1671 1404 }
1672 1405
1673 1406 /** @since 3.1.3 redirect cf7 plugin pages*/
1674 1407 global $pagenow;
1675 - // debug_msg("page: $pagenow");
1676 1408 if ( $pagenow == 'admin.php' && isset( $_GET['page'] ) ) {
1677 1409 $url = '';
1678 1410 switch($_GET['page']){
1679 1411 case 'wpcf7-new':
@@ -1687,12 +1419,8 @@
1687 1419 if(!empty($url)){
1688 1420 wp_redirect( admin_url( $url ));
1689 1421 exit;
1690 1422 }
1691 - }else if( $pagenow == 'edit.php' && isset( $_GET['post_type']) && $this->cf7_post_type()==$_GET['post_type'] ){ /** @since 4.11.5 buld validate */
1692 - if(isset($_POST['action']) && 'validate'==$_POST['action'] && function_exists('wpcf7_load_bulk_validate_page')){
1693 - wpcf7_load_bulk_validate_page('wpcf7','validate');
1694 - }
1695 1423 }
1696 1424 }
1697 1425 /**
1698 1426 * Add grid helper hooks for individual tags.
@@ -1703,15 +1431,14 @@
1703 1431 require_once plugin_dir_path( __FILE__ ) .'partials/helpers/cf7sg-form-fields.php';
1704 1432 }
1705 1433 /**
1706 1434 * Setup mailtags or toggles.
1707 - * Hooked to 'wpcf7_collect_mail_tags'
1435 + *
1708 1436 *@since 4.0.0
1709 1437 *@param string $param text_description
1710 1438 *@return string text_description
1711 1439 */
1712 - public function setup_cf7_mailtags($mailtags){
1713 - // debug_msg($mailtags, 'mail tags ');
1440 + public function setup_cf7_mailtags($mailtags = array()){
1714 1441 // return $mailtags;
1715 1442 $contact_form = WPCF7_ContactForm::get_current();
1716 1443 $fields = get_post_meta($contact_form->id(), '_cf7sg_grid_toggled_names', true);
1717 1444 //update_post_meta($post_id, '_cf7sg_grid_tabbed_toggles', $ttgls);
@@ -1735,106 +1462,64 @@
1735 1462 * hooked on 'admin_init'
1736 1463 *@since 4.1.0
1737 1464 */
1738 1465 public function init_notices(){
1739 - global $pagenow;
1740 - switch($pagenow){
1741 - case 'edit.php':
1742 - case 'post.php':
1743 - case 'plugins.php':
1744 - break;
1745 - default:
1746 - return;
1747 - }
1748 - $grid_settings = get_option( self::CF7SG_OPTION, array());
1466 + $grid_settings = get_option( 'cf7sg-plugin-version', array());
1749 1467 //if plugin settings exists and this is not an update, then no need to run.
1468 + if( !empty($grid_settings) and !isset($grid_settings['update']) ) return;
1469 +
1470 + $warning = false;
1750 1471 $notices = array();
1751 - if( !empty($grid_settings) and isset($grid_settings['update']) ){
1752 - $warning = false;
1753 1472
1754 - if(isset($grid_settings['update']) and CF7SG_VERSION_FORM_UPDATE==CF7_GRID_VERSION){
1755 - $warning = true;
1756 - }else if(isset($grid_settings['fv']) ) {
1757 - if(version_compare($grid_settings['fv'], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true;
1758 - }else{ //check the forms directly
1759 - global $wpdb;
1760 - $post_type = $this->cf7_post_type();
1761 - $result = $wpdb->get_col("SELECT pm.meta_value FROM {$wpdb->postmeta} as pm
1762 - INNER JOIN {$wpdb->posts} as p on p.ID = pm.post_id INNER JOIN {$wpdb->postmeta} as pmf on pmf.post_id = pm.post_id
1763 - WHERE pmf.meta_key = '_cf7sg_managed_form'
1764 - AND pmf.meta_value = 1
1765 - AND p.post_type = '{$post_type}'
1766 - AND pm.meta_key = '_cf7sg_version'
1767 - ");
1768 - if(!empty($result) and version_compare($result[0], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true;
1769 - }
1473 + if(isset($grid_settings['update']) and CF7SG_VERSION_FORM_UPDATE==CF7_GRID_VERSION){
1474 + $warning = true;
1475 + }else if(isset($grid_settings['fv']) ) {
1476 + if(version_compare($grid_settings['fv'], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true;
1477 + }else{ //check the forms directly
1478 + global $wpdb;
1479 + $post_type = $this->cf7_post_type();
1480 + $result = $wpdb->get_col("SELECT pm.meta_value FROM {$wpdb->postmeta} as pm
1481 + INNER JOIN {$wpdb->posts} as p on p.ID = pm.post_id
1482 + WHERE p.post_type = '{$post_type}'
1483 + AND pm.meta_key = '_cf7sg_version'
1484 + ORDER BY pm.meta_key
1485 + ");
1486 + if(!empty($result) and version_compare($result[0], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true;
1487 + }
1770 1488
1771 - if($warning){
1772 - $link = admin_url('edit.php?post_type=wpcf7_contact_form');
1773 - /* translators: %s is the url to the forms admin table */
1774 - $msg = __('You need to <strong>update</strong> your <a href="%s">forms</a>','cf7-grid-layout');
1775 - $notices['cf7sg_notice-'.CF7_GRID_VERSION] = array(
1776 - 'type'=>'notice-warning', //[notice-update|notice-error]
1777 - 'msg'=>sprintf($msg , $link),
1778 - 'pages'=>array('plugins.php','edit.php')
1779 - );
1780 - }
1781 - /** @since 4.2.0 new sliders tutorial */
1782 - if( isset($grid_settings['update']) ){
1783 - $notices['cf7sg_sliders_tutorial'] = array(
1784 - 'type'=>'notice-update', //[notice-update|notice-error]
1785 - /* translators: %s is the link to the tuorial page*/
1786 - 'msg'=>sprintf( __('There is a new tutorial for <a href="%s">multistep slider forms</a>','cf7-grid-layout'), admin_url('admin.php?page=cf7sg_help')),
1787 - 'html'=>'<div class="inline-top"><iframe width="230" height="130" src="https://www.youtube.com/embed/WiweQRhOr0g" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div><div class="inline-top"><strong>Learn how to create multi-step multi-slide CF7 forms using a slider construct functionality of the Smart Grid-layout extension plugin.</strong></div>',
1788 - 'pages'=>array('plugins.php','edit.php')
1789 - );
1790 - $notices['cf7sg_modular_tutorial'] = array(
1791 - 'type'=>'notice-update', //[notice-update|notice-error]
1792 - /* translators: %s is the link to the tuorial page*/
1793 - 'msg'=>sprintf( __('There is a new tutorial for <a href="%s">modular form construct</a>','cf7-grid-layout'), admin_url('admin.php?page=cf7sg_help')),
1794 - 'html'=>'<div class="inline-top"><iframe width="230" height="130" src="https://www.youtube.com/embed/vPc3M5Emro4" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div><div class="inline-top"><strong>Learn how to use modular form construct functionality allowing complex forms to be assembled from other child forms.</strong></div>',
1795 - 'pages'=>array('plugins.php','edit.php')
1796 - );
1797 - }
1798 - update_option(self::CF7SG_OPTION, array(
1799 - 'gv'=>CF7_GRID_VERSION,
1800 - 'fv'=>CF7SG_VERSION_FORM_UPDATE
1801 - ));
1489 + if($warning){
1490 + $link = admin_url('edit.php?post_type=wpcf7_contact_form');
1491 + /* translators: %s is the url to the forms admin table */
1492 + $msg = __('You need to <strong>update</strong> your <a href="%s">forms</a>','cf7-grid-layout');
1493 + $notices['cf7sg_notice-'.CF7_GRID_VERSION] = array(
1494 + 'type'=>'notice-warning', //[notice-update|notice-error]
1495 + 'msg'=>sprintf($msg , $link),
1496 + 'pages'=>array('plugins.php','edit.php')
1497 + );
1802 1498 }
1803 - /** @since 4.11.5 add admin notices for bulk cf7 validation */
1804 - //check if cf7 found issues:
1805 -
1806 - if(method_exists('WPCF7','get_option')){
1807 - $result = WPCF7::get_option( 'bulk_validate' );
1808 - if(!empty($result)){
1809 - $has_errors = ( isset($result['count_invalid']) and $result['count_invalid']>0);
1810 - $is_old = (defined('WPCF7_ConfigValidator::last_important_update') &&
1811 - isset($result['version']) &&
1812 - version_compare( $result['version'], WPCF7_ConfigValidator::last_important_update, '<'));
1813 - if( $is_old or $has_errors){
1814 - ob_start();
1815 - wpcf7_admin_bulk_validate_page();
1816 - $html = ob_get_contents();
1817 - ob_end_clean();
1818 - $msg = '';
1819 - if($is_old){
1820 - $msg = __('CF7 plugin udpate requires you to revalidate your forms.','cf7-grid-layout');
1821 - }else if($has_errors){
1822 - $msg = sprintf( /* translators : %s is number of forms */
1823 - __('You have %s form(s) with errors flagged below, fix those before attempting to revalidate your forms','cf7-grid-layout'),
1824 - $result['count_invalid']
1825 - );
1826 - }
1827 - $notices['cf7sg_notice-cf7_validate'] = array(
1828 - 'type'=>'notice-error',
1829 - 'msg' => $msg,
1830 - 'html'=>$html,
1831 - 'pages'=>array('edit.php')
1832 - );
1833 - }
1834 - }
1499 + /** @since 4.2.0 new sliders tutorial */
1500 + if( isset($grid_settings['update']) ){
1501 + $notices['cf7sg_sliders_tutorial'] = array(
1502 + 'type'=>'notice-update', //[notice-update|notice-error]
1503 + /* translators: %s is the link to the tuorial page*/
1504 + 'msg'=>sprintf( __('There is a new tutorial for <a href="%s">multistep slider forms</a>','cf7-grid-layout'), admin_url('admin.php?page=cf7sg_help')),
1505 + 'html'=>'<div class="inline-top"><iframe width="230" height="130" src="https://www.youtube.com/embed/WiweQRhOr0g" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div><div class="inline-top"><strong>Learn how to create multi-step multi-slide CF7 forms using a slider construct functionality of the Smart Grid-layout extension plugin.</strong></div>',
1506 + 'pages'=>array('plugins.php','edit.php')
1507 + );
1508 + $notices['cf7sg_modular_tutorial'] = array(
1509 + 'type'=>'notice-update', //[notice-update|notice-error]
1510 + /* translators: %s is the link to the tuorial page*/
1511 + 'msg'=>sprintf( __('There is a new tutorial for <a href="%s">modular form construct</a>','cf7-grid-layout'), admin_url('admin.php?page=cf7sg_help')),
1512 + 'html'=>'<div class="inline-top"><iframe width="230" height="130" src="https://www.youtube.com/embed/vPc3M5Emro4" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div><div class="inline-top"><strong>Learn how to use modular form construct functionality allowing complex forms to be assembled from other child forms.</strong></div>',
1513 + 'pages'=>array('plugins.php','edit.php')
1514 + );
1835 1515 }
1836 1516 if(!empty($notices)) update_option('cf7sg-admin-notices', $notices);
1517 +
1518 + update_option('cf7sg-plugin-version', array(
1519 + 'gv'=>CF7_GRID_VERSION,
1520 + 'fv'=>CF7SG_VERSION_FORM_UPDATE
1521 + ));
1837 1522 }
1838 1523 /**
1839 1524 * Display admin notices
1840 1525 * Hooked on 'admin_notices'
@@ -1843,9 +1528,8 @@
1843 1528 public function admin_notices(){
1844 1529 //check if we have any notices.
1845 1530 global $pagenow;
1846 1531 $notices = get_option('cf7sg-admin-notices', array());
1847 -
1848 1532 if(empty($notices)) return;
1849 1533
1850 1534 if(!isset(self::$admin_notice_pages[$pagenow])) return;
1851 1535
@@ -1850,8 +1534,9 @@
1850 1534 if(!isset(self::$admin_notice_pages[$pagenow])) return;
1851 1535
1852 1536 $notify=false;
1853 1537 $rule = self::$admin_notice_pages[$pagenow];
1538 + // debug_msg($rule, 'notice rules ');
1854 1539 if($pagenow=='post.php'){
1855 1540 $screen = get_current_screen();
1856 1541 if($this->cf7_post_type() == $screen->post_type) $notify=true;
1857 1542 }else if( !empty($rule) and is_array($rule) ){
@@ -1874,16 +1559,10 @@
1874 1559 }
1875 1560 if(!isset($notice['html'])) $notice['html'] = '';
1876 1561 ?>
1877 1562 <style>.notice .inline-top{display: inline-block;vertical-align: top;margin-right: 10px;max-width: 300px;}</style>
1878 - <div data-dismissible="<?=$dismiss?>" class="notice <?=$notice['type']?> is-dismissible cf7sg-notice">
1879 - <?= empty($notice['msg'])?'':'<p>'.$notice['msg'].'</p>'?>
1880 - <?=$notice['html']?>
1881 - </div>
1563 + <div data-dismissible="<?=$dismiss?>" class="notice <?=$notice['type']?> is-dismissible"><p><?=$notice['msg']?></p><?=$notice['html']?></div>
1882 1564 <?php
1883 - /** @since 4.7.1 dismiss notices once displayed */
1884 - unset($notices[$id]);
1885 - update_option('cf7sg-admin-notices', $notices);
1886 1565 }
1887 1566 }
1888 1567 /**
1889 1568 * ajax request to validate plugin update.
@@ -1894,9 +1573,9 @@
1894 1573 if( !isset($_POST['nonce']) or !wp_verify_nonce($_POST['nonce'], 'cf7sg_udpate_plugin') ){
1895 1574 echo 'error, nonce failed, try to reload the page.';
1896 1575 wp_die();
1897 1576 }
1898 - $grid_settings = get_option(self::CF7SG_OPTION, array());
1577 + $grid_settings = get_option('cf7sg-plugin-version', array());
1899 1578 $warning = false;
1900 1579 if(isset($grid_settings['fv']) ) {
1901 1580 if(version_compare($grid_settings['fv'], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true;
1902 1581 }
@@ -1902,9 +1581,9 @@
1902 1581 }
1903 1582 $grid_settings['fv'] = CF7SG_VERSION_FORM_UPDATE;
1904 1583 $grid_settings['gv'] = CF7_GRID_VERSION;
1905 1584 $grid_settings['update'] = true;
1906 - update_option(self::CF7SG_OPTION, $grid_settings);
1585 + update_option('cf7sg-plugin-version', $grid_settings);
1907 1586 $update_msg = __('Version validated, thank you!','cf7-grid-layout');
1908 1587 if($warning){
1909 1588 $link = admin_url('edit.php?post_type=wpcf7_contact_form');
1910 1589 /* translators: %s link to form table */
@@ -1913,9 +1592,8 @@
1913 1592 }
1914 1593 echo $update_msg;
1915 1594 wp_die();
1916 1595 }
1917 -
1918 1596 /**
1919 1597 * Check if plugin is getting updated.
1920 1598 * Hooked to 'upgrader_post_install'.
1921 1599 *@since 4.1.0
@@ -1926,11 +1604,11 @@
1926 1604 */
1927 1605 public function post_plugin_upgrade($response, $extras, $result){
1928 1606 if( ( isset($response['destination_name']) and 'cf7-grid-layout' == $response['destination_name'] )
1929 1607 or ( isset($extras['plugin']) and 'cf7-grid-layout/cf7-grid-layout.php' == $extras['plugin'] ) ){
1930 - $grid_settings = get_option(self::CF7SG_OPTION, array());
1608 + $grid_settings = get_option('cf7sg-plugin-version', array());
1931 1609 $grid_settings['update'] = true;
1932 - update_option(self::CF7SG_OPTION, $grid_settings);
1610 + update_option('cf7sg-plugin-version', $grid_settings);
1933 1611 }
1934 1612 return $response;
1935 1613 }
1936 1614 /**