PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.6.2
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.6.2
3.53.0 3.52.0 3.51.0 3.50.0 3.45.0 3.38.0 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.40.0 3.40.1 3.41.0 3.42.0 3.43.0 3.44.0 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 All 177 releases
simple-tags / inc / functions.inc.php

functions.inc.php in Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms 3.6.2, at inc/functions.inc.php

280 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * trim and remove empty element
4 *
5 * @param string $element
6 *
7 * @return string
8 */
9 function _delete_empty_element( $element ) {
10 $element = stripslashes( $element );
11 $element = trim( $element );
12 if ( ! empty( $element ) ) {
13 return $element;
14 }
15
16 return false;
17 }
18
19 /**
20 * Test if page have tags or not...
21 *
22 * @return boolean
23 * @author WebFactory Ltd
24 */
25 function is_page_have_tags() {
26 $taxonomies = get_object_taxonomies( 'page' );
27
28 return in_array( 'post_tag', $taxonomies, true );
29 }
30
31 /**
32 * Register widget on WP
33 */
34 function st_register_widget() {
35 register_widget( 'SimpleTags_Widget' );
36 if ( 1 === (int) SimpleTags_Plugin::get_option_value( 'active_terms_display' )){
37 register_widget( 'SimpleTags_Shortcode_Widget' );
38 }
39 if ( 1 === (int) SimpleTags_Plugin::get_option_value( 'active_post_tags' )){
40 register_widget( 'SimpleTags_PostTags_Widget' );
41 }
42 if ( 1 === (int) SimpleTags_Plugin::get_option_value( 'active_related_posts_new' )){
43 register_widget( 'SimpleTags_RelatedPosts_Widget' );
44 }
45 }
46
47 /**
48 * Change menu item order
49 */
50 add_action('custom_menu_order', 'taxopress_re_order_menu');
51 function taxopress_re_order_menu() {
52 global $submenu;
53 $newSubmenu = [];
54
55 //we only want to do this if taxonomy is active
56 $active_taxonomies = isset($_POST['updateoptions']) &&
57 (
58 !isset($_POST['active_taxonomies']) ||
59 (isset($_POST['active_taxonomies']) && (int)$_POST['active_taxonomies'] === 0)
60 ) ? 0 : 1;
61 if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_taxonomies' ) || (isset($_POST['active_taxonomies']) && (int)$_POST['active_taxonomies'] === 1)) && $active_taxonomies === 1 ) {
62 foreach ($submenu as $menuName => $menuItems) {
63 if ('st_options' === $menuName) {
64 $taxopress_settings = $taxopress_taxonomies = false;
65
66 $taxopress_submenus = $submenu['st_options'];
67 foreach($taxopress_submenus as $key => $taxopress_submenu){
68 if($taxopress_submenu[2] === 'st_options'){//settings
69 $taxopress_settings = $taxopress_submenu;
70 $taxopress_settings_key= $key;
71 unset($taxopress_submenus[$key]);
72 }
73 if($taxopress_submenu[2] === 'st_taxonomies'){//taxonomies
74 $taxopress_taxonomies = $taxopress_submenu;
75 $taxopress_taxonomies_key= $key;
76 unset($taxopress_submenus[$key]);
77 }
78 }
79 if($taxopress_settings && $taxopress_taxonomies ){
80 //swicth position
81 $taxopress_submenus[$taxopress_settings_key] = $taxopress_taxonomies;
82 $taxopress_submenus[$taxopress_taxonomies_key] = $taxopress_settings;
83 }
84
85 //resort array
86 ksort($taxopress_submenus);
87
88 $submenu['st_options'] = $taxopress_submenus;
89 break;
90 }
91 }
92 }
93 }
94
95 // Init TaxoPress
96 function init_simple_tags()
97 {
98 new SimpleTags_Client();
99 new SimpleTags_Client_TagCloud();
100
101 // Admin and XML-RPC
102 if (is_admin()) {
103 require STAGS_DIR . '/inc/class.admin.php';
104 new SimpleTags_Admin();
105 }
106
107 add_action('widgets_init', 'st_register_widget');
108 }
109
110 function taxopress_admin_pages(){
111
112 $taxopress_pages = [
113 'st_mass_terms',
114 'st_auto',
115 'st_options',
116 'st_manage',
117 'st_taxonomies',
118 'st_terms_display',
119 'st_post_tags',
120 'st_related_posts',
121 'st_autolinks',
122 'st_autoterms',
123 'st_suggestterms',
124 'st_terms'
125 ];
126
127 return apply_filters('taxopress_admin_pages', $taxopress_pages);
128 }
129
130 function is_taxopress_admin_page(){
131
132 $taxopress_pages = taxopress_admin_pages();
133
134 $is_taxopress_page = false;
135 if ( isset( $_GET['page'] ) && in_array( $_GET['page'], $taxopress_pages )) {
136 $is_taxopress_page = true;
137 }
138
139 return apply_filters('is_taxopress_admin_page', $is_taxopress_page);
140 }
141
142 function taxopress_starts_with( $haystack, $needle ) {
143 $length = strlen( $needle );
144 return substr( $haystack, 0, $length ) === $needle;
145 }
146
147 function taxopress_is_html($string)
148 {
149 return preg_match("/<[^<]+>/",$string,$m) != 0;
150 }
151
152
153
154 function taxopress_is_screen_main_page(){
155
156 if(isset($_GET['action']) && $_GET['action'] === 'edit'){
157 return false;
158 }
159
160 if(isset($_GET['add']) && $_GET['add'] === 'new_item'){
161 return false;
162 }
163
164 if(isset($_GET['add']) && $_GET['add'] === 'taxonomy'){
165 return false;
166 }
167
168 return true;
169 }
170
171
172
173 function taxopress_format_class($class)
174 {
175 return esc_attr(ltrim($class, '.'));
176 }
177
178 function taxopress_add_class_to_format($xformat, $class) {
179 $classes = $class;
180 $html = $xformat;
181
182 $patterns = array();
183 $replacements = array();
184
185 // matches where anchor has existing classes contained in single quotes
186 $patterns[0] = '/<a([^>]*)class=\'([^\']*)\'([^>]*)>/';
187 $replacements[0] = '<a\1class="' . $classes . ' \2"\3>';
188
189 // matches where anchor has existing classes contained in double quotes
190 $patterns[1] = '/<a([^>]*)class="([^"]*)"([^>]*)>/';
191 $replacements[1] = '<a\1class="' . $classes . ' \2"\3>';
192
193 // matches where anchor tag has no existing classes
194 $patterns[2] = '/<a(?![^>]*class)([^>]*)>/';
195 $replacements[2] = '<a\1 class="' . $classes . '">';
196
197 $html = preg_replace($patterns, $replacements, $html);
198
199 return $html;
200 }
201
202 function taxopress_change_to_strings($join){
203 if(is_array($join)){
204 $join = join(", ", $join);
205 }
206 return $join;
207 }
208
209 function taxopress_change_to_array($array){
210 if(!is_array($array)){
211 $array = preg_split("/\s*,\s*/",$array);
212 }
213 return $array;
214 }
215
216 function taxopress_html_character_and_entity($enity_code_as_key = false){
217 #Source https://dev.w3.org/html5/html-author/charref
218 $character_set = [
219 //'&amp;' => '&#38;',
220 '&lt;' => '&#60;',
221 '&gt;' => '&#62;',
222 '&nbsp;' => '&#160;',
223 '&excl;' => '&#33;',
224 '&quot;' => '&#34;',
225 '&num;' => '&#35;',
226 '&dollar;'=> '&#36;',
227 '&percnt;' => '&#37;',
228 '&apos;' => '&#39;',
229 '&lpar;' => '&#40;',
230 '&rpar;' => '&#41;',
231 '&ast; ' => '&#42;',
232 '&plus;' => '&#43;',
233 '&comma;' => '&#44;',
234 '&period;' => '&#46;',
235 '&sol;' => '&#47;',
236 '&colon;' => '&#58',
237 '&semi;' => '&#59;',
238 '&equals;' => '&#61;',
239 '&quest;' => '&#63;',
240 '&commat;' => '&#64;',
241 '&lsqb;' => '&#91;',
242 '&bsol;' => '&#92;',
243 '&rsqb;' => '&#93;',
244 '&Hat;' => '&#94;',
245 '&lowbar;' => '&#95;',
246 '&grave;' => '&#96;',
247 '&lcub;' => '&#123;',
248 '&verbar;' => '&#124;',
249 '&rcub;' => '&#125;',
250 '&iexcl;' => '&#161;',
251 '&cent;' => '&#162;',
252 '&pound;' => '&#163;',
253 '&copy;' => '&#169;',
254 '&ordf;' => '&#170;',
255 '&laquo;' => '&#171;',
256 '&reg;' => '&#174;',
257 '&deg;' => '&#176;',
258 '&plusmn;' => '&#177;',
259 '&sup2;' => '&#178;',
260 '&sup3;' => '&#179;',
261 '&acute;' => '&#180;',
262 '&sup1;' => '&#185;',
263 '&ordm;' => '&#186;',
264 '&raquo;' => '&#187;',
265 '&frac14;' => '&#188;',
266 '&frac12;' => '&#189;',
267 '&frac34;' => '&#190;',
268 '&rarr;' => '&#8594;',
269 '&larr;' => '&#8592;',
270 '&uarr;' => '&#8593;',
271 '&darr;' => '&#8595;',
272 '&trade;' => '&#8482;',
273 ];
274
275 if($enity_code_as_key){
276 $character_set = array_flip($character_set);
277 }
278
279 return $character_set;
280 }