PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 0.5.3
Permalink Manager Lite v0.5.3
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-admin-functions.php 9 years ago permalink-manager-helper-functions.php 9 years ago permalink-manager-post-uri-functions.php 9 years ago permalink-manager-uri-actions.php 9 years ago
permalink-manager-helper-functions.php
124 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 permastruct
64 */
65 static function get_default_permastruct($post_type = 'page', $remove_post_tag = false) {
66 global $wp_rewrite;
67
68 // Get default permastruct
69 if($post_type == 'page') {
70 $permastruct = $wp_rewrite->get_page_permastruct();
71 } else if($post_type == 'post') {
72 $permastruct = get_option('permalink_structure');
73 } else {
74 $permastruct = $wp_rewrite->get_extra_permastruct($post_type);
75 }
76
77 return ($remove_post_tag) ? trim(str_replace(array("%postname%", "%pagename%", "%{$post_type}%"), "", $permastruct), "/") : $permastruct;
78 }
79
80 /**
81 * Structure Tags & Rewrite functions
82 */
83 static function get_all_structure_tags($code = true, $seperator = ', ', $hide_slug_tags = true) {
84 global $wp_rewrite;
85
86 $tags = $wp_rewrite->rewritecode;
87 $output = "";
88 $last_tag_index = count($tags);
89 $i = 1;
90
91 // Hide slug tags
92 if($hide_slug_tags) {
93 $post_types = Permalink_Manager_Helper_Functions::get_post_types_array();
94 foreach($post_types as $post_type => $post_type_name) {
95 $post_type_tag = Permalink_Manager_Helper_Functions::get_post_tag($post_type);
96 // Find key with post type tag from rewritecode
97 $key = array_search($post_type_tag, $tags);
98 if($key) { unset($tags[$key]); }
99 }
100 }
101
102 foreach($tags as $tag) {
103 $sep = ($last_tag_index == $i) ? "" : $seperator;
104 $output .= ($code) ? "<code>{$tag}</code>{$sep}" : "{$tag}{$sep}";
105 $i++;
106 }
107
108 return $output;
109 }
110
111 static function get_post_tag($post_type) {
112 // Get the post type (with fix for posts & pages)
113 if($post_type == 'page') {
114 $post_type_tag = '%pagename%';
115 } else if ($post_type == 'post') {
116 $post_type_tag = '%postname%';
117 } else {
118 $post_type_tag = "%{$post_type}%";
119 }
120 return $post_type_tag;
121 }
122
123 }
124