PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 2.5.1.2
Permalink Manager Lite v2.5.1.2
2.6.0 2.5.5 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-permastructures-functions.php
permalink-manager / includes / core Last commit date
permalink-manager-actions.php 1 year ago permalink-manager-admin-functions.php 1 year ago permalink-manager-core-functions.php 1 year ago permalink-manager-debug.php 1 year ago permalink-manager-gutenberg.php 1 year ago permalink-manager-helper-functions.php 1 year ago permalink-manager-permastructures-functions.php 1 year ago permalink-manager-uri-functions-post.php 1 year ago permalink-manager-uri-functions.php 1 year ago
permalink-manager-permastructures-functions.php
139 lines
1 <?php
2
3 /**
4 * Helper functions used for Permastructures (permalink formats)
5 */
6 class Permalink_Manager_Permastructure_Functions {
7
8 public function __construct() {
9 add_action( 'plugins_loaded', array( $this, 'init' ), 5 );
10 }
11
12 /**
13 * Add hooks used by plugin to filter the custom permalinks
14 */
15 function init() {
16 // Replace empty placeholder tags & remove BOM
17 add_filter( 'permalink_manager_filter_default_post_uri', array( $this, 'replace_empty_placeholder_tags' ), 10, 5 );
18 add_filter( 'permalink_manager_filter_default_term_uri', array( $this, 'replace_empty_placeholder_tags' ), 10, 5 );
19 }
20
21 /**
22 * Get the default permalink format for specific post type
23 *
24 * @param string $post_type
25 * @param bool $remove_post_tag
26 *
27 * @return string
28 */
29 static function get_default_permastruct( $post_type = 'page', $remove_post_tag = false ) {
30 global $wp_rewrite;
31
32 // Get default permastruct
33 if ( $post_type == 'page' ) {
34 $permastruct = $wp_rewrite->get_page_permastruct();
35 } else if ( $post_type == 'post' ) {
36 $permastruct = get_option( 'permalink_structure' );
37 } else {
38 $permastruct = $wp_rewrite->get_extra_permastruct( $post_type );
39 }
40
41 return ( $remove_post_tag ) ? trim( str_replace( array( "%postname%", "%pagename%", "%{$post_type}%" ), "", $permastruct ), "/" ) : $permastruct;
42 }
43
44 /**
45 * Get the post name permastructure tag for specific post type
46 *
47 * @param string $post_type
48 *
49 * @return string
50 */
51 static function get_post_tag( $post_type ) {
52 // Get the post type (with fix for posts & pages)
53 if ( $post_type == 'page' ) {
54 $post_type_tag = '%pagename%';
55 } else if ( $post_type == 'post' ) {
56 $post_type_tag = '%postname%';
57 } else {
58 $post_type_tag = "%{$post_type}%";
59 }
60
61 return $post_type_tag;
62 }
63
64 /**
65 * Check if any of slug tags is present inside Permastructure settings
66 *
67 * @param $default_uri
68 * @param $slug_tags
69 * @param $content_element
70 *
71 * @return bool|null
72 */
73 public static function is_slug_tag_present( $default_uri, $slug_tags, $content_element ) {
74 global $permalink_manager_options;
75
76 // Check if any post tag is present in custom permastructure
77 if ( ! empty( $content_element->post_type ) ) {
78 $content_type = $content_element->post_type;
79 $content_type_key = 'post_types';
80 } else if ( ! empty( $content_element->taxonomy ) ) {
81 $content_type = $content_element->taxonomy;
82 $content_type_key = 'taxonomies';
83 } else {
84 return null;
85 }
86
87 $permastructure_settings = ( ! empty( $permalink_manager_options['permastructure-settings'] ) ) ? $permalink_manager_options['permastructure-settings'] : array();
88 $do_not_append_settings = ( ! empty( $permastructure_settings['do_not_append_slug'] ) ) ? $permastructure_settings['do_not_append_slug'] : array();
89 $do_not_append_slug = ( ! empty( $do_not_append_settings[ $content_type_key ] ) && ! empty( $do_not_append_settings[ $content_type_key ][ $content_type ] ) ) ? true : false;
90 $do_not_append_slug = apply_filters( "permalink_manager_do_not_append_slug", $do_not_append_slug, $content_type, $content_element );
91
92 if ( ! $do_not_append_slug ) {
93 foreach ( $slug_tags as $tag ) {
94 if ( strpos( $default_uri, $tag ) !== false ) {
95 $do_not_append_slug = true;
96 break;
97 }
98 }
99 }
100
101 // 3F. Replace the post tags with slugs or append the slug if no post tag is defined
102 if ( ! empty( $do_not_append_slug ) ) {
103 return true;
104 } else {
105 return false;
106 }
107 }
108
109 /**
110 * Replace empty placeholder tags & remove BOM
111 *
112 * @param string $default_uri
113 * @param string $native_slug
114 * @param string $element
115 * @param string $slug
116 * @param bool $native_uri
117 *
118 * @return string
119 */
120 public static function replace_empty_placeholder_tags( $default_uri, $native_slug = "", $element = "", $slug = "", $native_uri = false ) {
121 // Remove the BOM
122 $default_uri = str_replace( array( "\xEF\xBB\xBF", "%ef%bb%bf" ), '', $default_uri );
123
124 // Encode the URI before placeholders are removed
125 $chunks = explode( '/', $default_uri );
126 foreach ( $chunks as &$chunk ) {
127 if ( ! preg_match( "/^(%.+?%)$/", $chunk ) && preg_match( '/%[A-F0-9]{2}%[A-F0-9]{2}/i', $chunk ) ) {
128 $chunk = rawurldecode( $chunk );
129 }
130 }
131 $default_uri = implode( "/", $chunks );
132
133 $empty_tag_replacement = apply_filters( 'permalink_manager_empty_tag_replacement', '', $element );
134 $default_uri = preg_replace( "/%(.+?)%/", $empty_tag_replacement, $default_uri );
135 $default_uri = str_replace( "//", "/", $default_uri );
136
137 return trim( $default_uri, "/" );
138 }
139 }