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 +202 -261 4.104.5 View file →
@@ -44,19 +44,9 @@
44 44 * @access private
45 45 * @var string $plugin_name The ID of this plugin.
46 46 */
47 47 private $plugin_name;
48 -
49 48 /**
50 - * The ID of this plugin.
51 - *
52 - * @since 4.6.0
53 - * @access public
54 - * @var Constant CF7SG_OPTION Options key.
55 - */
56 - const CF7SG_OPTION = 'cf7sg-plugin-version';
57 -
58 - /**
59 49 * The version of this plugin.
60 50 *
61 51 * @since 1.0.0
62 52 * @access private
@@ -97,9 +87,8 @@
97 87 if (empty($screen) || $this->cf7_post_type() != $screen->post_type){
98 88 return;
99 89 }
100 90 $plugin_dir = plugin_dir_url( __DIR__ );
101 -
102 91 switch( $screen->base ){
103 92 case 'post':
104 93 $page_hook = '';
105 94 if('add' == $screen->action) $page_hook = 'contact_page_wpcf7-new';
@@ -228,9 +217,9 @@
228 217 const cssCodeMirror_5_32 = CodeMirror(document.getElementById("cf7-css-codemirror"),cmInitialSettings);
229 218 const jsCodeMirror_5_32 = CodeMirror(document.getElementById("cf7-js-codemirror"),cmInitialSettings);');
230 219 //matchtags.
231 220 wp_enqueue_script( 'codemirror-closetag-js',
232 - $plugin_dir . 'assets/codemirror/addon/edit/closetag.js',
221 + $plugin_dir . 'assets/codemirror/edit/closetag.js',
233 222 array('cf7-codemirror-js'), $this->version, true
234 223 );
235 224 //fold code
236 225 wp_enqueue_script( 'codemirror-foldcode-js',
@@ -561,196 +550,16 @@
561 550 }
562 551 }
563 552 }
564 553 }
565 - /** @since 5.0 register dynamic_select list */
566 - do_action('cf7sg_register_dynamic_lists');
567 - // debug_msg('created dynamic select ');
568 554 }
569 - /**
570 - * function to regsiter dyanmic dropdown taxonomies
571 - *
572 - * @since 1.0.0
573 - * @param Object $taxonomy_object std object with parameters $taxonomy_object->slug, $taxonomy_object->singular, $taxonomy_object->plural, $taxonomy_object->hierarchical .
574 - **/
575 - protected function register_dynamic_dropdown($taxonomy_array){
576 - $slug = $taxonomy_array['slug'];
577 - $name = $taxonomy_array['singular'];
578 - $plural = $taxonomy_array['plural'];
579 - $is_hierarchical = $taxonomy_array['hierarchical'];
580 555
581 - $labels = array(
582 - 'name' => $plural,
583 - 'singular_name' => $name,
584 - 'menu_name' => $plural,
585 - 'all_items' => 'All '.$plural,
586 - 'parent_item' => 'Parent '.$name,
587 - 'parent_item_colon' => 'Parent '.$name.':',
588 - 'new_item_name' => 'New '.$name.' Name',
589 - 'add_new_item' => 'Add New '.$name,
590 - 'edit_item' => 'Edit '.$name,
591 - 'update_item' => 'Update '.$name,
592 - 'view_item' => 'View '.$name,
593 - 'separate_items_with_commas' => 'Separate '.$plural.' with commas',
594 - 'add_or_remove_items' => 'Add or remove '.$plural,
595 - 'choose_from_most_used' => 'Choose from the most used',
596 - 'popular_items' => 'Popular '.$plural,
597 - 'search_items' => 'Search '.$plural,
598 - 'not_found' => 'Not Found',
599 - 'no_terms' => 'No '.$plural,
600 - 'items_list' => $plural.' list',
601 - 'items_list_navigation' => $plural.' list navigation',
602 - );
603 - //labels can be modified post registration
604 - $args = array(
605 - 'labels' => $labels,
606 - 'hierarchical' => $is_hierarchical,
607 - 'public' => false,
608 - 'show_ui' => true,
609 - 'show_admin_column' => false,
610 - 'show_in_nav_menus' => false,
611 - 'show_tagcloud' => false,
612 - 'show_in_quick_edit' => false,
613 - 'description' => 'Contact Form 7 dynamic dropdown taxonomy list',
614 - );
615 -
616 - register_taxonomy( $slug, $this->cf7_post_type(), $args );
617 - }
618 556 /**
619 - * CF7 Form saved from backend, check if dynamic-select are used
620 - * Hooked on 'wpcf7_save_contact_form'
621 - * @since 1.0.0
622 - * @param WPCF7_Contact_Form $cf7_form cf7 form object
623 - */
624 - public function save_factory_metas($cf7_form){
625 - $cf7_post_id = $cf7_form->id();
626 - //get the tags used in this form
627 - $tags = $cf7_form->scan_form_tags(); //get your form tags
628 - $dynamic_lists = cf7sg_get_dynamic_lists();
629 - $dynamic_tags = array_keys($dynamic_lists);
630 - $dynamic_fields = array();
631 - $form_classes = array();
632 - foreach($tags as $tag){
633 - if(in_array($tag['basetype'],$dynamic_tags)){
634 - $dynamic_fields[$tag['basetype']]=$tag;
635 - $form_classes = array_merge($form_classes, $dynamic_lists[$tag['basetype']]->get_form_classes($tag, $cf7_post_id));
636 - }
637 - }
638 - if(!empty($form_classes)){
639 - $classes = get_post_meta($cf7_post_id, '_cf7sg_script_classes', true);
640 - if(empty($classes)){
641 - $classes = array();
642 - }
643 - $form_classes = array_diff(array_unique($form_classes), $classes); //any new classes?
644 - if(!empty($form_classes)) {
645 - update_post_meta($cf7_post_id, '_cf7sg_script_classes', array_merge( $form_classes, $classes));
646 - }
647 - }
648 - //check for newly created taxonomy lists.
649 - if( isset($_POST['cf72post_dynamic_select_taxonomies']) ){
650 - $created_taxonomies = array();
651 - $taxonomies = json_decode(str_replace('\"','"',$_POST['cf72post_dynamic_select_taxonomies']), true);
652 - if(empty($taxonomies)){
653 - $taxonomies = array();
654 - }
655 - foreach($taxonomies as $taxonomy){
656 - //sanitize fields before saving into the DB.
657 - foreach($taxonomy as $key=>$value){
658 - $key = sanitize_key($key);
659 - $taxonomy[$key] = sanitize_text_field($value);
660 - }
661 - $created_taxonomies[$taxonomy['slug']] = $taxonomy;
662 - }
663 - //debug_msg($created_taxonomies);
664 - $post_lists = $saved_lists = $system_list = array();
665 -
666 - $dropdowns = get_option('_cf7sg_dynamic_dropdown_taxonomy',array());
667 - foreach($dropdowns as $id => $lists){
668 - $saved_lists = array_merge($saved_lists, $lists);
669 - }
670 - foreach($dynamic_fields as $tag){
671 - if(isset($tag['values'])){
672 - $slug='';
673 - foreach($tag['values'] as $values){
674 - if(0 == strpos($values, 'slug:') ){
675 - $slug = str_replace('slug:', '', $values);
676 - break;
677 - }
678 - }
679 - if(empty($slug)) continue; //not a taxonomy list.
680 - //is slug newly created?
681 - if(isset($created_taxonomies[$slug])){
682 - //store this taxonomy.
683 - $post_lists[$slug] = $created_taxonomies[$slug];
684 - }else if(isset($saved_lists[$slug])){
685 - //retain previously saved list if we are stil using it.
686 - $post_lists[$slug] = $saved_lists[$slug];
687 - }else{ //system taxonomy.
688 - $system_list[] = $slug;
689 - }
690 - //store the taxonomy slug in the cf7 metas.
691 - //$post_lists[$slug] = null;
692 - }
693 - }
694 - //list of taxonomy to register.
695 - //unset the old value.
696 - unset($dropdowns[$cf7_post_id]);
697 - //unshift new value to top of array.
698 - $dropdowns = array($cf7_post_id => $post_lists) + $dropdowns ;
699 -
700 - update_option('_cf7sg_dynamic_dropdown_taxonomy', $dropdowns);
701 - //list of system taxonomy to register
702 - $system_dropdowns = get_option('_cf7sg_dynamic_dropdown_system_taxonomy',array());
703 - $system_dropdowns[$cf7_post_id] = $system_list;
704 - update_option('_cf7sg_dynamic_dropdown_system_taxonomy', $system_dropdowns);
705 - }
706 - }
707 - /**
708 - * Print hiddend field on cf7 post submit box
709 - * Hooked on 'wpcf7_admin_misc_pub_section'
710 - * @since 1.0.0
711 - * @param string $post_id cf7 form post id .
712 - **/
713 - public function dynamic_select_choices($post_id){
714 - echo '<input id="cf72post-dynamic-select" type="hidden" name="cf72post_dynamic_select_taxonomies" />';
715 - }
716 -
717 - /**
718 - * Hide the cf7 form editor page author metabox by default.
719 - * hooked to 'hidden_meta_boxes'.
720 - *@since 4.6.0
721 - *@param Array $hidden array of hidden metabox ids.
722 - *@param WP_Screen $screen current amdin page screen object.
723 - *@param Boolean $use_defaults wether default settings used.
724 - *@return Array array of hidden metabox ids.
725 - */
726 - public function hide_author_metabox($hidden, $screen, $use_defaults){
727 - if( 'wpcf7_contact_form' != $screen->id ) return $hidden;
728 -
729 - if(in_array('authordiv', $hidden)) return $hidden;
730 -
731 - if($use_defaults) $hidden[] = 'authordiv';
732 - else {
733 - $gs = get_option(self::CF7SG_OPTION, array());
734 -
735 - if(!isset($gs['hide_author'])){
736 - $gs['hide_author']=true; //flag it.
737 - $uo = get_user_option('metaboxhidden_wpcf7_contact_form');
738 - if(false === $uo) $uo = array();
739 - $uo = array_unique( array_merge( $uo + array( 'authordiv' ) ) );
740 - $hidden = array_unique( array_merge( $hidden + array( 'authordiv' ) ) );
741 - update_option(self::CF7SG_OPTION,$gs);
742 - update_user_option( get_current_user_id(), 'metaboxhidden_wpcf7_contact_form', $uo);
743 - }
744 - }
745 - return $hidden;
746 - }
747 - /**
748 557 * Function to add the metabox to the cf7 post edit screen
749 558 * This adds the main editor, hooked on 'add_meta_boxes'
750 559 * @since 1.0.0
751 560 */
752 - public function edit_page_metabox() {
561 + public function main_editor_meta_box() {
753 562 //add_meta_box( string $id, string $title, callable $callback, string $screen, string $context, string $priority, array $callback_args)
754 563 if( post_type_exists( $this->cf7_post_type() ) ) {
755 564 add_meta_box( 'meta-box-main-cf7-editor',
756 565 __cf7sg( 'Edit Contact Form' ),
@@ -758,32 +567,11 @@
758 567 $this->cf7_post_type(),
759 568 'normal',
760 569 'high'
761 570 );
762 - add_meta_box( 'meta-box-cf7-info',
763 - __cf7sg( 'Information' ),
764 - array($this , 'info_metabox_display'),
765 - $this->cf7_post_type(),
766 - 'side',
767 - 'high'
768 - );
769 - /** @since 1.1.0 add helper metabox */
770 - add_meta_box( 'meta-box-cf7sg-helper',
771 - __( 'Actions & Filters', 'cf7-grid-layout' ),
772 - array($this , 'helper_metabox_display'),
773 - $this->cf7_post_type(),
774 - 'side',
775 - 'default'
776 - );
777 - /** @since 4.6.0 enable page redirect */
778 - add_meta_box(
779 - 'cf7sg-redirect', // Unique ID
780 - 'Redirect on Submission', // Box title
781 - array($this, 'display_rediect_metabox'), // Content callback, must be of type callable
782 - $this->cf7_post_type() // Post type
783 - );
784 571 }
785 572 }
573 +
786 574 /**
787 575 * Callback function to disolay the main editor meta box
788 576 * @since 1.0.0
789 577 */
@@ -796,13 +584,36 @@
796 584 if ( ! $cf7_form ) {
797 585 $args = apply_filters('cf7sg_new_cf7_form_template_arguments', array());
798 586 $cf7_form = WPCF7_ContactForm::get_template($args);
799 587 }
588 +
589 + // if(empty($post)){
590 + // $post_id = -1;
591 + // }else{
592 + // $post_id = $post->ID;
593 + // }
800 594 require_once WPCF7_PLUGIN_DIR . '/admin/includes/editor.php';
801 595 require_once plugin_dir_path( __FILE__ ) . 'partials/cf7-admin-editor-display.php';
802 596 }
803 597
804 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 + /**
805 616 * Re-introduces the wordpress 'wpcf7_admin_misc_pub_section' for plugins to add their fields for submission
806 617 * Hooked to 'post_submitbox_misc_actions' which fires after post dat/time parameters are printed
807 618 * @since 1.0.0
808 619 * @param WP_Post $post post object being edited/created.
@@ -819,8 +630,25 @@
819 630 public function info_metabox_display($post){
820 631 require_once plugin_dir_path( __FILE__ ) . 'partials/cf7-info-metabox-display.php';
821 632 }
822 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 + /**
823 651 * Callback function to disolay the helper meta box
824 652 * @since 1.0.0
825 653 */
826 654 public function helper_metabox_display($post){
@@ -836,18 +664,8 @@
836 664 public function grid_editor_panel($form_post){
837 665 require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-grid-layout-admin-display.php';
838 666 }
839 667 /**
840 - *
841 - *
842 - *@since 4.6.0
843 - *@param string $param text_description
844 - *@return string text_description
845 - */
846 - public function display_rediect_metabox($post){
847 - require_once plugin_dir_path( __FILE__ ) . '/partials/cf7-redirect-metabox-display.php';
848 - }
849 - /**
850 668 * Clean up post meta, delete sgcf7 corresponding view post.
851 669 * Hooked to action 'before_delete_post'.
852 670 *@since 4.3.0
853 671 *@param int $post_id post ID.
@@ -891,14 +709,14 @@
891 709 $args['title'] = isset( $_POST['post_title'] ) ? sanitize_text_field($_POST['post_title'], 'Contact Form', 'save') : null;
892 710 $args['locale'] = isset( $_POST['wpcf7-locale'] ) ? sanitize_text_field($_POST['wpcf7-locale']) : null;
893 711 $args['form'] = '';
894 712 $allowed_tags = wp_kses_allowed_html( 'post' ); //filtered in function below.
895 - /** @since 4.8.1 alllow custom input html*/
713 + /** @since 2.10.0 alllow custom input html*/
896 714 $allowed_tags['input']=array( //add additional input html elements
897 - 'type'=>1,'name'=>1,'placeholder'=>1,'value'=>1,'maxlength'=>1,'minlength'=>1, //input fields.
898 - 'spellcheck'=>1,'size'=>1,'readonly'=>1,'pattern'=>1,'list'=>1, //input fields.
715 + 'type'=>1,
899 716 'class'=>1,
900 717 'id'=>1,
718 + 'value'=>1,
901 719 'data-*'=>1,
902 720 );
903 721 $allowed_tags['script']=array('type'=>1);
904 722 $cf7_key = $post->post_name;
@@ -916,9 +734,8 @@
916 734
917 735 //need to unhook this function so as not to loop infinitely
918 736 //debug_msg($args, 'saving cf7 posts');
919 737 remove_action('save_post_wpcf7_contact_form', array($this, 'save_post'), 10,3);
920 - // debug_msg($args['form'],'form ');
921 738 $contact_form = wpcf7_save_contact_form( $args );
922 739 add_action('save_post_wpcf7_contact_form', array($this, 'save_post'), 10,3);
923 740 //flag as a grid form
924 741 //update_post_meta($post_id, 'cf7_grid_form', true); removed since v2.3 as not used.
@@ -1060,20 +877,8 @@
1060 877 'post_status'=>'draft',
1061 878 'post_type'=>'cf7sg_page',
1062 879 // 'post_name' => sanitize_title( $title ),
1063 880 );
1064 - /** @since 4.6.0 redirect on submit */
1065 - if(isset($_POST['cf7sg_page_redirect'])){
1066 - $redirect_to = absint($_POST['cf7sg_page_redirect']);
1067 - update_post_meta($post->ID, '_cf7sg_page_redirect',$redirect_to);
1068 - if(isset($_POST['cache_cf7sg_submit']) and isset($_POST['cf7sg_cached_time']) and isset($_POST['cf7sg_cached_unit'])){
1069 - $cache = floatval( $_POST['cf7sg_cached_time']);
1070 - if($cache>0){
1071 - $cache=array($cache, absint($_POST['cf7sg_cached_unit']));
1072 - update_post_meta($post->ID, '_cf7sg_cache_redirect_data',$cache);
1073 - }
1074 - }else delete_post_meta($post->ID, '_cf7sg_cache_redirect_data');
1075 - }
1076 881 if(empty($cf7_key)) $prev_page['post_content'] = '[contact-form-7 id="'.$post->ID.'"]';
1077 882 if( !empty($preview_id) ){
1078 883 $prev_page['ID'] = $preview_id;
1079 884 }
@@ -1080,10 +885,8 @@
1080 885 $preview_id = wp_insert_post($prev_page, true);
1081 886 if(!is_wp_error($preview_id)){
1082 887 update_post_meta($post->ID, '_cf7sg_form_page',$preview_id);
1083 888 }
1084 - /** @since 4.9.2 fire form saving action so as to prevent double save_post hook calls on other plugins */
1085 - do_action('cf7sg_save_post',$post_id, $post, $update);
1086 889 }
1087 890 /**
1088 891 * Print default js template,
1089 892 * Hooked to 'cf7sg_default_custom_js_template'
@@ -1204,22 +1007,35 @@
1204 1007 * @since 1.0.0
1205 1008 **/
1206 1009 public function cf7_shortcode_tags(){
1207 1010 if ( class_exists( 'WPCF7_TagGenerator' ) ) {
1208 - /** @since 4.10.0 enable extension of dynamic lists */
1209 1011 $tag_generator = WPCF7_TagGenerator::get_instance();
1210 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(
1211 1018 'benchmark', //tag id
1212 1019 __( 'benchmark', 'cf7_2_post' ), //tag button label
1213 1020 array($this,'benchmark_tag_generator') //callback
1214 1021 );
1215 1022 }
1216 - /** @since 4.10.0 abstract out dynamic lists */
1217 - $lists = cf7sg_get_dynamic_lists();
1218 - foreach($lists as $l) $l->register_cf7_tag();
1219 1023 }
1220 -
1221 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 + /**
1222 1038 * Benchmark input screen displayt.
1223 1039 *
1224 1040 * This function is called by cf7 plugin, and is registered with a hooked function above
1225 1041 *
@@ -1230,10 +1046,139 @@
1230 1046 function benchmark_tag_generator( $contact_form, $args = '' ) {
1231 1047 $args = wp_parse_args( $args, array() );
1232 1048 include( plugin_dir_path( __FILE__ ) . '/partials/cf7-benchmark-tag.php');
1233 1049 }
1050 + /**
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" />';
1058 + }
1059 + /**
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
1064 + */
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();
1234 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 + }
1099 + }
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;
1110 + }
1111 + //store the taxonomy slug in the cf7 metas.
1112 + //$post_lists[$slug] = null;
1113 + }
1114 + }
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 +
1128 + }
1129 + }
1130 +
1235 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 + /**
1236 1181 * Deactivate this plugin if CF7 plugin is deactivated.
1237 1182 * Hooks on action 'admin_init'
1238 1183 * @since 2.1
1239 1184 */
@@ -1380,9 +1325,9 @@
1380 1325 }
1381 1326 include_once 'partials/pointers/cf7sg-pointer-editor-column-control.php';
1382 1327 $content = ob_get_contents();
1383 1328 if(!empty($content)){
1384 - $pointers['column_controls'] = array($content, 'left', 'center','#grid-form > .container:first-child > .row > .columns:first-child > .grid-column > span.icon-code');
1329 + $pointers['column_controls'] = array($content, 'left', 'center','#grid-form>.container>.row>.columns:first-child>.grid-column>span.icon-code');
1385 1330 ob_clean();
1386 1331 }
1387 1332 include_once 'partials/pointers/cf7sg-pointer-tag-dynamic-dropdown.php';
1388 1333 $content = ob_get_contents();
@@ -1427,14 +1372,14 @@
1427 1372 *@since 3.0.0
1428 1373 *@param array $data sanitised post data.
1429 1374 *@return array post data.
1430 1375 */
1431 - public function pending_for_review($data, $post){
1376 + public function pending_for_review($data){
1432 1377 if($this->cf7_post_type() != $data['post_type']) return $data;
1433 1378
1434 1379 $post_type_object = get_post_type_object( $this->cf7_post_type() );
1435 1380 //check if user can publish.
1436 - 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'){
1437 1382 $data['post_status']='pending';
1438 1383 }
1439 1384 // debug_msg('post status '.$data['post_status']);
1440 1385 return $data;
@@ -1517,9 +1462,9 @@
1517 1462 * hooked on 'admin_init'
1518 1463 *@since 4.1.0
1519 1464 */
1520 1465 public function init_notices(){
1521 - $grid_settings = get_option( self::CF7SG_OPTION, array());
1466 + $grid_settings = get_option( 'cf7sg-plugin-version', array());
1522 1467 //if plugin settings exists and this is not an update, then no need to run.
1523 1468 if( !empty($grid_settings) and !isset($grid_settings['update']) ) return;
1524 1469
1525 1470 $warning = false;
@@ -1569,9 +1514,9 @@
1569 1514 );
1570 1515 }
1571 1516 if(!empty($notices)) update_option('cf7sg-admin-notices', $notices);
1572 1517
1573 - update_option(self::CF7SG_OPTION, array(
1518 + update_option('cf7sg-plugin-version', array(
1574 1519 'gv'=>CF7_GRID_VERSION,
1575 1520 'fv'=>CF7SG_VERSION_FORM_UPDATE
1576 1521 ));
1577 1522 }
@@ -1583,9 +1528,8 @@
1583 1528 public function admin_notices(){
1584 1529 //check if we have any notices.
1585 1530 global $pagenow;
1586 1531 $notices = get_option('cf7sg-admin-notices', array());
1587 -
1588 1532 if(empty($notices)) return;
1589 1533
1590 1534 if(!isset(self::$admin_notice_pages[$pagenow])) return;
1591 1535
@@ -1617,11 +1561,8 @@
1617 1561 ?>
1618 1562 <style>.notice .inline-top{display: inline-block;vertical-align: top;margin-right: 10px;max-width: 300px;}</style>
1619 1563 <div data-dismissible="<?=$dismiss?>" class="notice <?=$notice['type']?> is-dismissible"><p><?=$notice['msg']?></p><?=$notice['html']?></div>
1620 1564 <?php
1621 - /** @since 4.7.1 dismiss notices once displayed */
1622 - unset($notices[$id]);
1623 - update_option('cf7sg-admin-notices', $notices);
1624 1565 }
1625 1566 }
1626 1567 /**
1627 1568 * ajax request to validate plugin update.
@@ -1632,9 +1573,9 @@
1632 1573 if( !isset($_POST['nonce']) or !wp_verify_nonce($_POST['nonce'], 'cf7sg_udpate_plugin') ){
1633 1574 echo 'error, nonce failed, try to reload the page.';
1634 1575 wp_die();
1635 1576 }
1636 - $grid_settings = get_option(self::CF7SG_OPTION, array());
1577 + $grid_settings = get_option('cf7sg-plugin-version', array());
1637 1578 $warning = false;
1638 1579 if(isset($grid_settings['fv']) ) {
1639 1580 if(version_compare($grid_settings['fv'], CF7SG_VERSION_FORM_UPDATE, '<') ) $warning = true;
1640 1581 }
@@ -1640,9 +1581,9 @@
1640 1581 }
1641 1582 $grid_settings['fv'] = CF7SG_VERSION_FORM_UPDATE;
1642 1583 $grid_settings['gv'] = CF7_GRID_VERSION;
1643 1584 $grid_settings['update'] = true;
1644 - update_option(self::CF7SG_OPTION, $grid_settings);
1585 + update_option('cf7sg-plugin-version', $grid_settings);
1645 1586 $update_msg = __('Version validated, thank you!','cf7-grid-layout');
1646 1587 if($warning){
1647 1588 $link = admin_url('edit.php?post_type=wpcf7_contact_form');
1648 1589 /* translators: %s link to form table */
@@ -1663,11 +1604,11 @@
1663 1604 */
1664 1605 public function post_plugin_upgrade($response, $extras, $result){
1665 1606 if( ( isset($response['destination_name']) and 'cf7-grid-layout' == $response['destination_name'] )
1666 1607 or ( isset($extras['plugin']) and 'cf7-grid-layout/cf7-grid-layout.php' == $extras['plugin'] ) ){
1667 - $grid_settings = get_option(self::CF7SG_OPTION, array());
1608 + $grid_settings = get_option('cf7sg-plugin-version', array());
1668 1609 $grid_settings['update'] = true;
1669 - update_option(self::CF7SG_OPTION, $grid_settings);
1610 + update_option('cf7sg-plugin-version', $grid_settings);
1670 1611 }
1671 1612 return $response;
1672 1613 }
1673 1614 /**