PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 1.0.4
Permalink Manager Lite v1.0.4
2.5.4 2.5.3.4 2.2.18 2.2.19.2 2.2.19.3 2.2.19.3.1 2.2.2 2.2.20 2.2.20.1 2.2.20.3 2.2.4 2.2.5 2.2.6 2.2.7.2 2.2.7.3 2.2.7.5 2.2.7.6 2.2.8.4 2.2.8.5 2.2.8.6 2.2.8.7 2.2.8.9 2.2.9.1 2.2.9.2 2.2.9.2.1 2.2.9.3 2.2.9.4 2.2.9.6 2.2.9.7 2.2.9.9 2.3.0 2.3.1.1 2.4.0 2.4.1 2.4.1.2 2.4.1.3 2.4.1.4 2.4.1.5 2.4.1.6 2.4.2 2.4.2.1 2.4.3 2.4.3.1 2.4.3.2 2.4.3.3 2.4.3.4 2.4.4 2.4.4.1 2.4.4.2 2.4.4.3 2.5.0 2.5.1 2.5.1.1 2.5.1.2 2.5.1.3 2.5.1.4 2.5.2 2.5.2.1 2.5.2.2 2.5.2.3 2.5.2.4 2.5.3 2.5.3.1 2.5.3.2 2.5.3.3 trunk 0.2 0.3 0.3.1 0.3.2 0.3.3 0.3.4 0.4 0.4.1 0.4.2 0.4.3 0.4.4 0.4.6 0.4.7 0.4.8 0.4.9 0.5.3 0.5.4 1.0.0 1.0.1 1.0.4 1.1.0 1.1.1 1.1.2 1.11.6.3 2.0.0 2.0.3 2.0.4 2.0.4.3 2.0.5.1 2.0.5.2 2.0.5.3 2.0.5.3.1 2.0.5.4 2.0.5.4a 2.0.5.5 2.0.5.6 2.0.5.6.1 2.0.5.7 2.0.5.9a 2.0.6.2.1 2.0.6.2a 2.0.6.3 2.1.0 2.1.1 2.1.2.4 2.2.0 2.2.1.1 2.2.1.2 2.2.11 2.2.12 2.2.13.1 2.2.14 2.2.15.1 2.2.16 2.2.17
permalink-manager / includes / core / permalink-manager-helper-functions.php
permalink-manager / includes / core Last commit date
permalink-manager-actions.php 9 years ago permalink-manager-admin-functions.php 9 years ago permalink-manager-helper-functions.php 9 years ago permalink-manager-uri-functions-post.php 9 years ago
permalink-manager-helper-functions.php
183 lines
1 <?php
2
3 /**
4 * Additional functions used in classes and another subclasses
5 */
6 class Permalink_Manager_Helper_Functions extends Permalink_Manager_Class {
7
8 public function __construct() { }
9
10 /**
11 * Support for multidimensional arrays - array_map()
12 */
13 static function multidimensional_array_map($function, $input) {
14 $output = array();
15
16 if(is_array($input)) {
17 foreach ($input as $key => $val) {
18 $output[$key] = (is_array($val) ? self::multidimensional_array_map($function, $val) : $function($val));
19 }
20 } else {
21 $output = $function($input);
22 }
23
24 return $output;
25 }
26
27 /**
28 * Get primary term (by Yoast SEO)
29 */
30 static function get_primary_term($post_id, $taxonomy) {
31 global $permalink_manager_options;
32
33 if($permalink_manager_options['miscellaneous']['yoast_primary_term'] == 1 && class_exists('WPSEO_Primary_Term')) {
34 $primary_term = new WPSEO_Primary_Term($taxonomy, $post_id);
35 $primary_term = get_term($primary_term->get_primary_term());
36 return (!is_wp_error($primary_term)) ? $primary_term->slug : "";
37 } else {
38 return '';
39 }
40 }
41
42 /**
43 * Get post_types array
44 */
45 static function get_post_types_array($format = null, $cpt = null) {
46 $post_types = apply_filters('permalink-manager-post-types', get_post_types( array('public' => true), 'objects'));
47
48 $post_types_array = array();
49 if($format == 'full') {
50 foreach ( $post_types as $post_type ) {
51 $post_types_array[$post_type->name] = array('label' => $post_type->labels->name, 'name' => $post_type->name);
52 }
53 } else {
54 foreach ( $post_types as $post_type ) {
55 $post_types_array[$post_type->name] = $post_type->labels->name;
56 }
57 }
58
59 return (empty($cpt)) ? $post_types_array : $post_types_array[$cpt];
60 }
61
62 /**
63 * Get array with all taxonomies
64 */
65 static function get_taxonomies_array($format = null, $tax = null) {
66 $taxonomies = apply_filters('permalink-manager-taxonomies', get_taxonomies(array('public' => true, 'rewrite' => true), 'objects'));
67
68 $taxonomies_array = array();
69 if($format == 'full') {
70 foreach ( $taxonomies as $taxonomy ) {
71 $taxonomies_array[$taxonomy->name] = array('label' => $taxonomy->labels->name, 'name' => $taxonomy->name);
72 }
73 } else {
74 foreach ( $taxonomies as $taxonomy ) {
75 $taxonomies_array[$taxonomy->name] = $taxonomy->labels->name;
76 }
77 }
78
79 return (empty($tax)) ? $taxonomies_array : $taxonomies_array[$tax];
80 }
81
82 /**
83 * Get permastruct
84 */
85 static function get_default_permastruct($post_type = 'page', $remove_post_tag = false) {
86 global $wp_rewrite;
87
88 // Get default permastruct
89 if($post_type == 'page') {
90 $permastruct = $wp_rewrite->get_page_permastruct();
91 } else if($post_type == 'post') {
92 $permastruct = get_option('permalink_structure');
93 } else {
94 $permastruct = $wp_rewrite->get_extra_permastruct($post_type);
95 }
96
97 return ($remove_post_tag) ? trim(str_replace(array("%postname%", "%pagename%", "%{$post_type}%"), "", $permastruct), "/") : $permastruct;
98 }
99
100 /**
101 * Remove post tag from permastructure
102 */
103 static function remove_post_tag($permastruct) {
104 $post_types = self::get_post_types_array('full');
105
106 // Get all post tags
107 $post_tags = array("%postname%", "%pagename%");
108 foreach($post_types as $post_type) {
109 $post_tags[] = "%{$post_type['name']}%";
110 }
111
112 $permastruct = str_replace($post_tags, "", $permastruct);
113 return trim($permastruct, "/");
114 }
115
116 /**
117 * Structure Tags & Rewrite functions
118 */
119 static function get_all_structure_tags($code = true, $seperator = ', ', $hide_slug_tags = true) {
120 global $wp_rewrite;
121
122 $tags = $wp_rewrite->rewritecode;
123
124 // Hide slug tags
125 if($hide_slug_tags) {
126 $post_types = Permalink_Manager_Helper_Functions::get_post_types_array();
127 foreach($post_types as $post_type => $post_type_name) {
128 $post_type_tag = Permalink_Manager_Helper_Functions::get_post_tag($post_type);
129 // Find key with post type tag from rewritecode
130 $key = array_search($post_type_tag, $tags);
131 if($key) { unset($tags[$key]); }
132 }
133 }
134
135 foreach($tags as &$tag) {
136 $tag = ($code) ? "<code>{$tag}</code>" : "{$tag}";
137 }
138 $output = implode($seperator, $tags);
139
140 return "<span class=\"structure-tags-list\">{$output}</span>";
141 }
142
143 /**
144 * Get endpoint used to mark the postname or its equivalent for custom post types and pages in permastructures
145 */
146 static function get_post_tag($post_type) {
147 // Get the post type (with fix for posts & pages)
148 if($post_type == 'page') {
149 $post_type_tag = '%pagename%';
150 } else if ($post_type == 'post') {
151 $post_type_tag = '%postname%';
152 } else {
153 $post_type_tag = "%{$post_type}%";
154 }
155 return $post_type_tag;
156 }
157
158 /**
159 * Find taxonomy name using "term_id"
160 */
161 static function get_tax_name($term, $term_by = 'id') {
162 $term_object = get_term_by($term_by, $term);
163 return (isset($term_object->taxonomy)) ? $term_object->taxonomy : '';
164 }
165
166 /**
167 * Get default language (WPML & Polylang)
168 */
169 static function get_language() {
170 global $sitepress;
171 $def_lang = '';
172
173 if(function_exists('pll_default_language')) {
174 $def_lang = pll_default_language('slug');
175 } else if(is_object($sitepress)) {
176 $def_lang = $sitepress->get_default_language();
177 }
178
179 return $def_lang;
180 }
181
182 }
183