PluginProbe
Smart Grid-Layout Design for Contact Form 7 / 3.3.2
Smart Grid-Layout Design for Contact Form 7 v3.3.2
4.18.0 4.17.0 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 4.0.0 4.0.1 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10 4.11 4.12 4.13 4.14 All 119 releases
cf7-grid-layout / admin / partials / cf7-dynamic-tag-display.php

cf7-dynamic-tag-display.php in Smart Grid-Layout Design for Contact Form 7 3.3.2, at admin/partials/cf7-dynamic-tag-display.php

256 lines 11.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Provide a admin area view for the plugin
5 *
6 * This file is used to markup the admin-facing aspects of the plugin.
7 *
8 * @link http://syllogic.in
9 * @since 1.5.0
10 *
11 * @package Cf7_2_Post
12 * @subpackage Cf7_2_Post/admin/partials
13 */
14 //TODO: add a check box to include or not address fields
15 ?>
16
17 <!-- This file should primarily consist of HTML with a little bit of PHP. -->
18
19 <div id="dynamic-select-tag-generator" class="control-box cf7-dynamic-select">
20 <fieldset>
21 <legend><?= __('Dynamic Select Dropdown field','cf7-grid-layout')?></legend>
22 <table class="form-table">
23 <tbody>
24 <tr>
25 <th scope="row"><label for="<?= esc_attr( $args['content'] . '-name' ); ?>"><?= esc_html( __cf7sg( 'Name' ) ); ?></label></th>
26 <td><input type="text" name="name" class="tg-name oneline" id="<?= esc_attr( $args['content'] . '-name' ); ?>" /></td>
27 </tr>
28 <tr>
29 <th scope="row"><?=__('Field type','cf7-grid-layout')?></th>
30 <td><input name="required" type="checkbox"><?=__('Required field','cf7-grid-layout')?><br /></td>
31 </tr>
32 <tr>
33 <th scope="row"><?=__('Id attribute','cf7-grid-layout')?></th>
34 <td>
35 <input name="id" class="idvalue oneline option" id="tag-generator-panel-dynamic-select-id" type="text">
36 </td>
37 </tr>
38 <tr>
39 <th scope="row"><?=__('Class attribute','cf7-grid-layout')?></th>
40 <td>
41 <input name="class" class="classvalue oneline option" id="tag-generator-panel-dynamic-select-class" type="text">
42 </td>
43 </tr>
44 <tr>
45 <th scope="row"><?=__('Dropdown style','cf7-grid-layout')?></th>
46 <td>
47 <div>
48 <label for="html-select">
49 <input name="select-style[]" id="html-select" class=" select-type " type="radio" value="select" checked="checked"/>
50 <?=__('HTML Select field','cf7-grid-layout')?>
51 </label>
52 </div>
53 <div>
54 <label for="nice-select">
55 <input id="nice-select" name="select-style[]" class=" select-type " type="radio" value="nice" />
56 <a target="_blank" href="http://hernansartorio.com/jquery-nice-select/"><?=__('jQuery Nice Select','cf7-grid-layout')?></a>
57 </label>
58 </div>
59 <div>
60 <label for="select2-select">
61 <input id="select2-select" name="select-style[]" class=" select-type " type="radio" value="select2" />
62 <a target="_blank" href="https://select2.org/getting-started/basic-usage"><?=__('jQuery Select2','cf7-grid-layout')?></a>
63 </label>
64 <label for="select2-tags">
65 <input name="select2-tags" id="select2-tags" type="checkbox" disabled value="select2tags"/>
66 <a target="_blank" href="https://select2.org/tagging"><?=__('Enable user options','cf7-grid-layout')?></a>
67 </label>
68 </div>
69 </td>
70 </tr>
71 <tr>
72 <th scope="row"><?=__('Mutliple attribute','cf7-grid-layout')?></th>
73 <td>
74 <input name="select-multiple" id="select-multiple" type="checkbox" value="multiple"/>
75 <a target="_blank" href="https://www.w3schools.com/tags/att_select_multiple.asp"><?=__('Enable multiple selection','cf7-grid-layout')?></a>
76 </td>
77 </tr>
78 </tbody>
79 </table>
80 <div id="dynamic-dropdown-sources" class="tabordion">
81 <section id="taxonomy-source">
82 <input type="radio" name="sections" id="taxonomy-tab" checked>
83 <label for="taxonomy-tab"><?=__('Taxonomy','cf7-grid-layout')?></label>
84 <article>
85 <h4><?=__('Taxonomy source','cf7-grid-layout')?></h4>
86 <select class="taxonomy-list">
87 <option value="" data-name="" ><?=__('Choose a Taxonomy','cf7-grid-layout')?></option>
88 <option class="cf7sg-new-taxonomy" value="new_taxonomy" data-name="New Category"><?=__('New Categories','cf7-grid-layout')?></option>
89 <?php
90 //get options.
91 $dropdowns = get_option('_cf7sg_dynamic_dropdown_taxonomy',array());
92 $slugs = array();
93
94 foreach($dropdowns as $all_lists){
95 foreach($all_lists as $slug => $taxonomy){
96 if(isset($slugs[$slug]) ){
97 continue;
98 }else{
99 $slugs[$slug] = $slug;
100 }
101 echo '<option selected data-name="' . $taxonomy['singular'] . '" value="'. $taxonomy['slug'] . '" class="cf7sg-taxonomy">' . $taxonomy['plural'] . '</option>';
102 }
103 }
104 //inset the default post tags and category
105 ?>
106 <option value="post_tag" data-name="Post Tag" class="system-taxonomy"><?=__('Post Tags','cf7-grid-layout')?></option>
107 <option value="category" data-name="Post Category" class="system-taxonomy"><?=__('Post Categories','cf7-grid-layout')?></option>
108 <?php
109 $system_taxonomies = get_taxonomies( array('public'=>true, '_builtin' => false), 'objects' );
110 foreach($system_taxonomies as $taxonomy){
111 if( !empty($taxonomy_slug) && $taxonomy_slug == $taxonomy->name ) continue;
112 echo '<option value="' . $taxonomy->name . '" data-name="' . $taxonomy->labels->singular_name . '" class="system-taxonomy">' . $taxonomy->labels->name . '</option>';
113 }
114 ?>
115 </select>
116 <div class="cf72post-new-taxonomy">
117 <div><strong><?=__('New Taxonomy','cf7-grid-layout')?></strong></div>
118 <label><?=__('Plural Name','cf7-grid-layout')?><br />
119 <input disabled="true" class="cf72post-new-taxonomy" type="text" name="plural_name" value=""></label>
120 <label ><?=__('Singular Name','cf7-grid-layout')?><br />
121 <input disabled="true" class="cf72post-new-taxonomy" type="text" name="singular_name" value=""></label>
122 <label><?=__('Slug','cf7-grid-layout')?><br />
123 <input disabled="true" class="cf72post-new-taxonomy" type="text" name="taxonomy_slug" value="" /></label>
124 <label class="hidden"><input class="cf72post-new-taxonomy" type="checkbox" name="is_hierarchical" /><?=__('hierarchical','cf7-grid-layout')?></label>
125 </div>
126 </article>
127 </section>
128 <section id="post-source">
129 <input type="radio" name="sections" id="post-tab">
130 <label for="post-tab"><?=__('Post','cf7-grid-layout')?></label>
131 <article class="">
132 <h4><?=__('Post source','cf7-grid-layout')?></h4>
133 <select class="post-list">
134 <option value=""><?=__('Select a post','cf7-grid-layout')?></option>
135 <?php
136 $args = array(
137 'show_ui' => true,
138 '_builtin' => false
139 );
140 $output = 'objects'; // names or objects, note names is the default
141 $operator = 'and'; // 'and' or 'or'
142
143 $post_types = get_post_types( $args, $output, $operator );
144 foreach($post_types as $type=>$post){
145 echo '<option value="'.$type.'">'.$post->labels->name.'</option>';
146 $taxonomies = get_object_taxonomies( $type, 'objects' );
147
148 $taxonomy_lists[$type] = '';
149 foreach($taxonomies as $taxonomy){
150 //skup cf7 dynamic list taxonomies.
151 if(WPCF7_ContactForm::post_type == $type && 'wpcf7_type' != $taxonomy->name) continue;
152 $taxonomy_lists[$type] .= '<optgroup label="'.$taxonomy->label.'">'.PHP_EOL;
153 $taxonomy_lists[$type] .= cf7sg_terms_to_options($taxonomy->name, $taxonomy->hierarchical,0);
154 $taxonomy_lists[$type] .= '</optgroup>'.PHP_EOL;
155 }
156 }
157 $taxonomies = get_object_taxonomies( 'post', 'objects' );
158 $taxonomy_lists['post'] = '';
159 foreach($taxonomies as $taxonomy){
160 $taxonomy_lists['post'] .= '<optgroup label="'.$taxonomy->label.'">'.PHP_EOL;
161 $taxonomy_lists['post'] .= cf7sg_terms_to_options($taxonomy->name, $taxonomy->hierarchical,0);
162 $taxonomy_lists['post'] .= '</optgroup>'.PHP_EOL;
163 }
164 $taxonomies = get_object_taxonomies( 'page', 'objects' );
165 $taxonomy_lists['page'] = '';
166 foreach($taxonomies as $taxonomy){
167 $taxonomy_lists['page'] .= '<optgroup label="'.$taxonomy->label.'">'.PHP_EOL;
168 $taxonomy_lists['page'] .= cf7sg_terms_to_options($taxonomy->name, $taxonomy->hierarchical,0);
169 $taxonomy_lists['page'] .= '</optgroup>'.PHP_EOL;
170 }
171 ?>
172 <option value="post"><?=__('Posts','cf7-grid-layout')?></option>
173 <option value="page"><?=__('Pages','cf7-grid-layout')?></option>
174 </select>
175
176 <?php foreach($taxonomy_lists as $type=>$list ):
177 if(empty($list)) continue;
178 ?>
179 <div id="<?php echo $type ?>" class="post-taxonomies hidden">
180 <select multiple class="select2">
181 <?php echo $list?>
182 </select>
183 </div>
184 <?php endforeach; ?>
185 </article>
186 </section>
187 <section id="custom-source">
188 <input type="radio" name="sections" id="custom-tab">
189 <label for="custom-tab"><?=__('Custom','cf7-grid-layout')?></label>
190 <article>
191 <h4><?=__('Custom source','cf7-grid-layout')?></h4>
192 <p class="position-relative">
193 <?= __('Hook the following filter to programmatically load the drodown options', 'cf7-grid-layout');?> <a class="helper init" data-cf72post="add_filter('cf7sg_dynamic_dropdown_custom_options', 'filter_options',10,3);
194 function filter_options($options, $field_name, $form_key){
195 if($form_key != 'my-form') return $options; //check this is the correct form.
196 if($field_name != 'custom-dropdown') return $options; //check this is the correct field.
197 $options = array();
198 //load your options programmatically, as $value=>$name pairs.
199 $options['val1']='Value 1';
200 $options['val2']='Value 2';
201 return $options;
202 }" href="javascript:void(0);">cf7sg_dynamic_dropdown_custom_options</a>
203 </p>
204 </article>
205 </section>
206 </div> <!-- end-tabs-->
207
208 </fieldset>
209 </div>
210 <div class="insert-box">
211 <input type="hidden" name="values" value="" />
212 <input type="text" name="dynamic-select" class="tag code" readonly="readonly" onfocus="this.select()" />
213
214 <div class="submitbox">
215 <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __cf7sg( 'Insert Tag' ) ); ?>" />
216 </div>
217
218 <br class="clear" />
219 </div>
220 <?php
221 /*
222 Added functionality
223 */
224 function cf7sg_terms_to_options($taxonomy, $is_hierarchical, $parent=0){
225 $args = array('hide_empty' => 0);
226 if($is_hierarchical){
227 $args['parent'] = $parent;
228 }
229 //check the WP version
230 global $wp_version;
231 if ( $wp_version >= 4.5 ) {
232 $args['taxonomy'] = $taxonomy;
233 $terms = get_terms($args); //WP>= 4.5 the get_terms does not take a taxonomy slug field
234 }else{
235 $terms = get_terms($taxonomy, $args);
236 }
237 if( is_wp_error( $terms ) ){
238 debug_msg('Taxonomy '.$taxonomy.' does not exist');
239 return '';
240 }else if( empty($terms) ){
241 return'';
242 }
243 if(0==$parent) $class = 'parent';
244 else $class = 'child';
245 $script = '';
246 foreach($terms as $term){
247 $script .='<option value="taxonomy:' . $taxonomy . ':' . $term->slug . '" >' . $term->name . '</option>' . PHP_EOL;
248 if($is_hierarchical){
249 $script .= cf7sg_terms_to_options($taxonomy, $is_hierarchical, $term->term_id);
250 }
251 }
252 return $script;
253 }
254
255 ?>
256