PluginProbe ʕ •ᴥ•ʔ
Custom Post Type Permalinks / 1.0.2
Custom Post Type Permalinks v1.0.2
1.2.0 1.3.0 1.3.1 1.4.0 1.5.1 1.5.2 1.5.4 2.0.0 2.0.1 2.0.2 2.1.1 2.1.2 2.1.3 2.2.0 3.0.0 3.0.1 3.1.0 3.1.1 3.1.3 3.1.4 3.1.5 3.2.0 3.2.1 3.2.2 3.3.0 3.3.1 3.3.4 3.3.5 3.4.0 3.4.0-rc.1 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.5.2 3.5.3 3.5.4 3.5.5 trunk 0.6 0.6.1 0.6.2 0.7 0.7.1 0.7.10 0.7.2 0.7.2.1 0.7.3 0.7.3.1 0.7.4 0.7.4.1 0.7.5 0.7.5.1 0.7.5.2 0.7.5.6 0.7.6 0.7.8 0.7.9 0.7.9.1 0.7.9.2 0.8 0.8.1 0.8.6 0.8.7 0.8.7.1 0.8.7.5 0.8.7.6 0.9 0.9.1 0.9.2.1 0.9.3.1 0.9.3.2 0.9.3.3 0.9.5 0.9.5.1 0.9.5.2 0.9.5.3 0.9.5.4 0.9.5.6 0.9.6 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0
custom-post-type-permalinks / CPTP / Util.php
custom-post-type-permalinks / CPTP Last commit date
Module 11 years ago Module.php 11 years ago Util.php 11 years ago
Util.php
121 lines
1 <?php
2
3 /**
4 *
5 * Utilty Class
6 *
7 * @package Custom_Post_Type_Permalinks
8 * @since 0.9.4
9 *
10 * */
11
12 class CPTP_Util {
13
14 private function __construct() {
15 }
16
17 public static function get_post_types() {
18 return get_post_types( array( '_builtin' => false, 'publicly_queryable' => true, 'show_ui' => true ) );
19 }
20
21 public static function get_taxonomies( $objects = false ) {
22 if ( $objects ) {
23 $output = 'objects';
24 }
25 else {
26 $output = 'names';
27 }
28 return get_taxonomies( array( 'show_ui' => true, '_builtin' => false ), $output );
29 }
30
31
32 /**
33 *
34 * Get Custom Taxonomies parents.
35 * @version 1.0
36 *
37 */
38 public static function get_taxonomy_parents( $id, $taxonomy = 'category', $link = false, $separator = '/', $nicename = false, $visited = array() ) {
39 $chain = '';
40 $parent = get_term( $id, $taxonomy );
41 if ( is_wp_error( $parent ) ) {
42 return $parent;
43 }
44
45 if ( $nicename ){
46 $name = $parent->slug;
47 }else {
48 $name = $parent->name;
49 }
50
51 if ( $parent->parent && ( $parent->parent != $parent->term_id ) && ! in_array( $parent->parent, $visited ) ) {
52 $visited[] = $parent->parent;
53 $chain .= CPTP_Util::get_taxonomy_parents( $parent->parent, $taxonomy, $link, $separator, $nicename, $visited );
54 }
55
56 if ( $link ) {
57 $chain .= '<a href="' . get_term_link( $parent->term_id, $taxonomy ) . '" title="' . esc_attr( sprintf( __( 'View all posts in %s' ), $parent->name ) ) . '">'.esc_html( $name ).'</a>' .esc_html( $separator );
58 }else {
59 $chain .= $name.$separator;
60 }
61 return $chain;
62 }
63
64 /**
65 * Get permalink structure.
66 *
67 * @since 0.9.6
68 * @param string|object $post_type post type name. / object post type object.
69 * @return string post type structure.
70 */
71 public static function get_permalink_structure( $post_type ) {
72 if ( is_string( $post_type ) ) {
73 $pt_object = get_post_type_object( $post_type );
74 }
75 else {
76 $pt_object = $post_type;
77 }
78
79
80 if ( !empty( $pt_object->cptp_permalink_structure ) ) {
81 $structure = $pt_object->cptp_permalink_structure;
82 }
83 else {
84
85 $structure = get_option( $pt_object->name.'_structure' );
86 }
87
88 return apply_filters( 'CPTP_'.$pt_object->name.'_structure', $structure );
89 }
90
91
92 /**
93 * Get permalink structure front for date archive.
94 *
95 * @since 1.0.0
96 * @param string $post_type post type name.
97 * @return string
98 */
99 public static function get_date_front( $post_type ) {
100 $structure = CPTP_Util::get_permalink_structure( $post_type );
101
102 $front = '';
103
104 preg_match_all( '/%.+?%/', $structure, $tokens );
105 $tok_index = 1;
106 foreach ( (array) $tokens[0] as $token ) {
107 if ( '%post_id%' == $token && ($tok_index <= 3) ) {
108 $front = '/date';
109 break;
110 }
111 $tok_index++;
112 }
113
114 return $front;
115
116 }
117
118
119
120 }
121