PluginProbe
Smart Grid-Layout Design for Contact Form 7 / 3.2.0
Smart Grid-Layout Design for Contact Form 7 v3.2.0
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.2.0, at admin/partials/cf7-dynamic-tag-display.php

241 lines 10.8 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 <input name="select-style[]" class=" select-type " type="radio" value="select" checked="checked"/>
49 <label><?=__('HTML Select field','cf7-grid-layout')?></label>
50 </div>
51 <div>
52 <input name="select-style[]" class=" select-type " type="radio" value="nice" />
53 <label><a target="_blank" href="http://hernansartorio.com/jquery-nice-select/"><?=__('jQuery Nice Select','cf7-grid-layout')?></a></label>
54 </div>
55 <div>
56 <input name="select-style[]" class=" select-type " type="radio" value="select2" />
57 <label><a target="_blank" href="https://select2.org/getting-started/basic-usage"><?=__('jQuery Select2','cf7-grid-layout')?></a></label>
58 <input name="select2-tags" id="select2-tags" type="checkbox" disabled value="select2tags"/>
59 <label for="select2-tags"><a target="_blank" href="https://select2.org/tagging"><?=__('Enable user options','cf7-grid-layout')?></a></label>
60 </div>
61 </td>
62 </tr>
63 </tbody>
64 </table>
65 <div id="dynamic-dropdown-sources" class="tabordion">
66 <section id="taxonomy-source">
67 <input type="radio" name="sections" id="taxonomy-tab" checked>
68 <label for="taxonomy-tab"><?=__('Taxonomy','cf7-grid-layout')?></label>
69 <article>
70 <h4><?=__('Taxonomy source','cf7-grid-layout')?></h4>
71 <select class="taxonomy-list">
72 <option value="" data-name="" ><?=__('Choose a Taxonomy','cf7-grid-layout')?></option>
73 <option class="cf7sg-new-taxonomy" value="new_taxonomy" data-name="New Category"><?=__('New Categories','cf7-grid-layout')?></option>
74 <?php
75 //get options.
76 $dropdowns = get_option('_cf7sg_dynamic_dropdown_taxonomy',array());
77 $slugs = array();
78
79 foreach($dropdowns as $all_lists){
80 foreach($all_lists as $slug => $taxonomy){
81 if(isset($slugs[$slug]) ){
82 continue;
83 }else{
84 $slugs[$slug] = $slug;
85 }
86 echo '<option selected data-name="' . $taxonomy['singular'] . '" value="'. $taxonomy['slug'] . '" class="cf7sg-taxonomy">' . $taxonomy['plural'] . '</option>';
87 }
88 }
89 //inset the default post tags and category
90 ?>
91 <option value="post_tag" data-name="Post Tag" class="system-taxonomy"><?=__('Post Tags','cf7-grid-layout')?></option>
92 <option value="category" data-name="Post Category" class="system-taxonomy"><?=__('Post Categories','cf7-grid-layout')?></option>
93 <?php
94 $system_taxonomies = get_taxonomies( array('public'=>true, '_builtin' => false), 'objects' );
95 foreach($system_taxonomies as $taxonomy){
96 if( !empty($taxonomy_slug) && $taxonomy_slug == $taxonomy->name ) continue;
97 echo '<option value="' . $taxonomy->name . '" data-name="' . $taxonomy->labels->singular_name . '" class="system-taxonomy">' . $taxonomy->labels->name . '</option>';
98 }
99 ?>
100 </select>
101 <div class="cf72post-new-taxonomy">
102 <div><strong><?=__('New Taxonomy','cf7-grid-layout')?></strong></div>
103 <label><?=__('Plural Name','cf7-grid-layout')?><br />
104 <input disabled="true" class="cf72post-new-taxonomy" type="text" name="plural_name" value=""></label>
105 <label ><?=__('Singular Name','cf7-grid-layout')?><br />
106 <input disabled="true" class="cf72post-new-taxonomy" type="text" name="singular_name" value=""></label>
107 <label><?=__('Slug','cf7-grid-layout')?><br />
108 <input disabled="true" class="cf72post-new-taxonomy" type="text" name="taxonomy_slug" value="" /></label>
109 <label class="hidden"><input class="cf72post-new-taxonomy" type="checkbox" name="is_hierarchical" /><?=__('hierarchical','cf7-grid-layout')?></label>
110 </div>
111 </article>
112 </section>
113 <section id="post-source">
114 <input type="radio" name="sections" id="post-tab">
115 <label for="post-tab"><?=__('Post','cf7-grid-layout')?></label>
116 <article class="">
117 <h4><?=__('Post source','cf7-grid-layout')?></h4>
118 <select class="post-list">
119 <option value=""><?=__('Select a post','cf7-grid-layout')?></option>
120 <?php
121 $args = array(
122 'show_ui' => true,
123 '_builtin' => false
124 );
125 $output = 'objects'; // names or objects, note names is the default
126 $operator = 'and'; // 'and' or 'or'
127
128 $post_types = get_post_types( $args, $output, $operator );
129 foreach($post_types as $type=>$post){
130 echo '<option value="'.$type.'">'.$post->labels->name.'</option>';
131 $taxonomies = get_object_taxonomies( $type, 'objects' );
132
133 $taxonomy_lists[$type] = '';
134 foreach($taxonomies as $taxonomy){
135 //skup cf7 dynamic list taxonomies.
136 if(WPCF7_ContactForm::post_type == $type && 'wpcf7_type' != $taxonomy->name) continue;
137 $taxonomy_lists[$type] .= '<optgroup label="'.$taxonomy->label.'">'.PHP_EOL;
138 $taxonomy_lists[$type] .= cf7sg_terms_to_options($taxonomy->name, $taxonomy->hierarchical,0);
139 $taxonomy_lists[$type] .= '</optgroup>'.PHP_EOL;
140 }
141 }
142 $taxonomies = get_object_taxonomies( 'post', 'objects' );
143 $taxonomy_lists['post'] = '';
144 foreach($taxonomies as $taxonomy){
145 $taxonomy_lists['post'] .= '<optgroup label="'.$taxonomy->label.'">'.PHP_EOL;
146 $taxonomy_lists['post'] .= cf7sg_terms_to_options($taxonomy->name, $taxonomy->hierarchical,0);
147 $taxonomy_lists['post'] .= '</optgroup>'.PHP_EOL;
148 }
149 $taxonomies = get_object_taxonomies( 'page', 'objects' );
150 $taxonomy_lists['page'] = '';
151 foreach($taxonomies as $taxonomy){
152 $taxonomy_lists['page'] .= '<optgroup label="'.$taxonomy->label.'">'.PHP_EOL;
153 $taxonomy_lists['page'] .= cf7sg_terms_to_options($taxonomy->name, $taxonomy->hierarchical,0);
154 $taxonomy_lists['page'] .= '</optgroup>'.PHP_EOL;
155 }
156 ?>
157 <option value="post"><?=__('Posts','cf7-grid-layout')?></option>
158 <option value="page"><?=__('Pages','cf7-grid-layout')?></option>
159 </select>
160
161 <?php foreach($taxonomy_lists as $type=>$list ):
162 if(empty($list)) continue;
163 ?>
164 <div id="<?php echo $type ?>" class="post-taxonomies hidden">
165 <select multiple class="select2">
166 <?php echo $list?>
167 </select>
168 </div>
169 <?php endforeach; ?>
170 </article>
171 </section>
172 <section id="custom-source">
173 <input type="radio" name="sections" id="custom-tab">
174 <label for="custom-tab"><?=__('Custom','cf7-grid-layout')?></label>
175 <article>
176 <h4><?=__('Custom source','cf7-grid-layout')?></h4>
177 <p class="position-relative">
178 <?= __('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);
179 function filter_options($options, $field_name, $form_key){
180 if($form_key != 'my-form') return $options; //check this is the correct form.
181 if($field_name != 'custom-dropdown') return $options; //check this is the correct field.
182 $options = array();
183 //load your options programmatically, as $value=>$name pairs.
184 $options['val1']='Value 1';
185 $options['val2']='Value 2';
186 return $options;
187 }" href="javascript:void(0);">cf7sg_dynamic_dropdown_custom_options</a>
188 </p>
189 </article>
190 </section>
191 </div> <!-- end-tabs-->
192
193 </fieldset>
194 </div>
195 <div class="insert-box">
196 <input type="hidden" name="values" value="" />
197 <input type="text" name="dynamic-select" class="tag code" readonly="readonly" onfocus="this.select()" />
198
199 <div class="submitbox">
200 <input type="button" class="button button-primary insert-tag" value="<?php echo esc_attr( __cf7sg( 'Insert Tag' ) ); ?>" />
201 </div>
202
203 <br class="clear" />
204 </div>
205 <?php
206 /*
207 Added functionality
208 */
209 function cf7sg_terms_to_options($taxonomy, $is_hierarchical, $parent=0){
210 $args = array('hide_empty' => 0);
211 if($is_hierarchical){
212 $args['parent'] = $parent;
213 }
214 //check the WP version
215 global $wp_version;
216 if ( $wp_version >= 4.5 ) {
217 $args['taxonomy'] = $taxonomy;
218 $terms = get_terms($args); //WP>= 4.5 the get_terms does not take a taxonomy slug field
219 }else{
220 $terms = get_terms($taxonomy, $args);
221 }
222 if( is_wp_error( $terms ) ){
223 debug_msg('Taxonomy '.$taxonomy.' does not exist');
224 return '';
225 }else if( empty($terms) ){
226 return'';
227 }
228 if(0==$parent) $class = 'parent';
229 else $class = 'child';
230 $script = '';
231 foreach($terms as $term){
232 $script .='<option value="taxonomy:' . $taxonomy . ':' . $term->slug . '" >' . $term->name . '</option>' . PHP_EOL;
233 if($is_hierarchical){
234 $script .= cf7sg_terms_to_options($taxonomy, $is_hierarchical, $term->term_id);
235 }
236 }
237 return $script;
238 }
239
240 ?>
241