PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.4.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.4.0
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.4.0, at inc/functions.inc.php

265 lines 6.8 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 foreach ($submenu as $menuName => $menuItems) {
55 if ('st_options' === $menuName) {
56 $taxopress_settings = $taxopress_taxonomies = false;
57
58 $taxopress_submenus = $submenu['st_options'];
59 foreach($taxopress_submenus as $key => $taxopress_submenu){
60 if($taxopress_submenu[2] === 'st_options'){//settings
61 $taxopress_settings = $taxopress_submenu;
62 $taxopress_settings_key= $key;
63 unset($taxopress_submenus[$key]);
64 }
65 if($taxopress_submenu[2] === 'st_taxonomies'){//taxonomies
66 $taxopress_taxonomies = $taxopress_submenu;
67 $taxopress_taxonomies_key= $key;
68 unset($taxopress_submenus[$key]);
69 }
70 }
71 if($taxopress_settings && $taxopress_taxonomies ){
72 //swicth position
73 $taxopress_submenus[$taxopress_settings_key] = $taxopress_taxonomies;
74 $taxopress_submenus[$taxopress_taxonomies_key] = $taxopress_settings;
75 }
76
77 //resort array
78 ksort($taxopress_submenus);
79
80 $submenu['st_options'] = $taxopress_submenus;
81 break;
82 }
83 }
84 }
85
86 // Init TaxoPress
87 function init_simple_tags()
88 {
89 new SimpleTags_Client();
90 new SimpleTags_Client_TagCloud();
91
92 // Admin and XML-RPC
93 if (is_admin()) {
94 require STAGS_DIR . '/inc/class.admin.php';
95 new SimpleTags_Admin();
96 }
97
98 add_action('widgets_init', 'st_register_widget');
99 }
100
101 function taxopress_admin_pages(){
102
103 $taxopress_pages = [
104 'st_mass_terms',
105 'st_auto',
106 'st_options',
107 'st_manage',
108 'st_taxonomies',
109 'st_terms_display',
110 'st_post_tags',
111 'st_related_posts',
112 'st_autolinks',
113 'st_autoterms',
114 'st_suggestterms'
115 ];
116
117 return apply_filters('taxopress_admin_pages', $taxopress_pages);
118 }
119
120 function is_taxopress_admin_page(){
121
122 $taxopress_pages = taxopress_admin_pages();
123
124 $is_taxopress_page = false;
125 if ( isset( $_GET['page'] ) && in_array( $_GET['page'], $taxopress_pages )) {
126 $is_taxopress_page = true;
127 }
128
129 return apply_filters('is_taxopress_admin_page', $is_taxopress_page);
130 }
131
132 function taxopress_starts_with( $haystack, $needle ) {
133 $length = strlen( $needle );
134 return substr( $haystack, 0, $length ) === $needle;
135 }
136
137 function taxopress_is_html($string)
138 {
139 return preg_match("/<[^<]+>/",$string,$m) != 0;
140 }
141
142
143
144 function taxopress_is_screen_main_page(){
145
146 if(isset($_GET['action']) && $_GET['action'] === 'edit'){
147 return false;
148 }
149
150 if(isset($_GET['add']) && $_GET['add'] === 'new_item'){
151 return false;
152 }
153
154 if(isset($_GET['add']) && $_GET['add'] === 'taxonomy'){
155 return false;
156 }
157
158 return true;
159 }
160
161
162
163 function taxopress_format_class($class)
164 {
165 return esc_attr(ltrim($class, '.'));
166 }
167
168 function taxopress_add_class_to_format($xformat, $class) {
169 $classes = $class;
170 $html = $xformat;
171
172 $patterns = array();
173 $replacements = array();
174
175 // matches where anchor has existing classes contained in single quotes
176 $patterns[0] = '/<a([^>]*)class=\'([^\']*)\'([^>]*)>/';
177 $replacements[0] = '<a\1class="' . $classes . ' \2"\3>';
178
179 // matches where anchor has existing classes contained in double quotes
180 $patterns[1] = '/<a([^>]*)class="([^"]*)"([^>]*)>/';
181 $replacements[1] = '<a\1class="' . $classes . ' \2"\3>';
182
183 // matches where anchor tag has no existing classes
184 $patterns[2] = '/<a(?![^>]*class)([^>]*)>/';
185 $replacements[2] = '<a\1 class="' . $classes . '">';
186
187 $html = preg_replace($patterns, $replacements, $html);
188
189 return $html;
190 }
191
192 function taxopress_change_to_strings($join){
193 if(is_array($join)){
194 $join = join(", ", $join);
195 }
196 return $join;
197 }
198
199 function taxopress_change_to_array($array){
200 if(!is_array($array)){
201 $array = preg_split("/\s*,\s*/",$array);
202 }
203 return $array;
204 }
205
206 function taxopress_html_character_and_entity($enity_code_as_key = false){
207 #Source https://dev.w3.org/html5/html-author/charref
208 $character_set = [
209 //'&amp;' => '&#38;',
210 '&lt;' => '&#60;',
211 '&gt;' => '&#62;',
212 '&nbsp;' => '&#160;',
213 '&excl;' => '&#33;',
214 '&quot;' => '&#34;',
215 '&num;' => '&#35;',
216 '&dollar;'=> '&#36;',
217 '&percnt;' => '&#37;',
218 '&apos;' => '&#39;',
219 '&lpar;' => '&#40;',
220 '&rpar;' => '&#41;',
221 '&ast; ' => '&#42;',
222 '&plus;' => '&#43;',
223 '&comma;' => '&#44;',
224 '&period;' => '&#46;',
225 '&sol;' => '&#47;',
226 '&colon;' => '&#58',
227 '&semi;' => '&#59;',
228 '&equals;' => '&#61;',
229 '&quest;' => '&#63;',
230 '&commat;' => '&#64;',
231 '&lsqb;' => '&#91;',
232 '&bsol;' => '&#92;',
233 '&rsqb;' => '&#93;',
234 '&Hat;' => '&#94;',
235 '&lowbar;' => '&#95;',
236 '&grave;' => '&#96;',
237 '&lcub;' => '&#123;',
238 '&verbar;' => '&#124;',
239 '&rcub;' => '&#125;',
240 '&iexcl;' => '&#161;',
241 '&cent;' => '&#162;',
242 '&pound;' => '&#163;',
243 '&copy;' => '&#169;',
244 '&ordf;' => '&#170;',
245 '&laquo;' => '&#171;',
246 '&reg;' => '&#174;',
247 '&deg;' => '&#176;',
248 '&plusmn;' => '&#177;',
249 '&sup2;' => '&#178;',
250 '&sup3;' => '&#179;',
251 '&acute;' => '&#180;',
252 '&sup1;' => '&#185;',
253 '&ordm;' => '&#186;',
254 '&raquo;' => '&#187;',
255 '&frac14;' => '&#188;',
256 '&frac12;' => '&#189;',
257 '&frac34;' => '&#190;'
258 ];
259
260 if($enity_code_as_key){
261 $character_set = array_flip($character_set);
262 }
263
264 return $character_set;
265 }