Permalink Manager Lite - Version 1.1.2

Version Description

  • Trailing slashes & Decode URIs - new settings
  • Fix for "Bulk Edit" URI reset
  • Partial code refactoring
  • Hierarchical taxonomies fix
  • New hook: "permalink_manager_filter_final_term_permalink"
  • Taxonomies & permastructures fix
Download this release

Release Info

Developer mbis
Plugin Icon 128x128 Permalink Manager Lite
Version 1.1.2
Comparing to
See all releases

Code changes from version 1.1.1 to 1.1.2

README.txt CHANGED
@@ -4,9 +4,9 @@ Donate link: https://www.paypal.me/Bismit
4
  License: GPLv3
5
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
6
  Tags: urls, permalinks, slugs, custom url, custom permalinks, uris, url, slug, permalink
7
- Requires at least: 4.5
8
  Tested up to: 4.8
9
- Stable tag: 1.1.1
10
 
11
  Most advanced yet easy-to-use permalink plugin that helps to maintain & bulk change your URLs & slugs.
12
 
@@ -21,10 +21,14 @@ Currently, the plugin allows to perform four main actions:
21
  3. It allows to bulk regenerate/reset permalinks (or native slugs). This might be especially useful if your post titles are updated and native slugs need to be recreated.
22
  4. It allows to change the default permalink bases (permastructures) for all custom post types & posts and pages.
23
  5. It allows to auto-update URIs to match the current permastructure settings after eg. post title or assigned primary category is changed.
24
- 6. (<a href="https://permalinkmanager.pro?utm_source=wordpress">Permalink Manager Pro</a> only) It allows to manually adjust permalinks (URIs) for all categories/tags/custom terms.
25
- 7. (<a href="https://permalinkmanager.pro?utm_source=wordpress">Permalink Manager Pro</a> only) It allows to remove /product-category and /product from WooCommerce permalinks.
26
- 8. (<a href="https://permalinkmanager.pro?utm_source=wordpress">Permalink Manager Pro</a> only) It allows to define custom "stop-words" list and/or use custom one (19 languages available).
27
- 9. (<a href="https://permalinkmanager.pro?utm_source=wordpress">Permalink Manager Pro</a> only) It allows to automatically insert the custom fields to the permalinks.
 
 
 
 
28
 
29
  To improve the user experience, each tool allows also to filter the permalinks by post types or post statuses.
30
 
@@ -34,11 +38,6 @@ Word "krakow" should be replaced with "gdansk" in all your permalinks.
34
 
35
  `http://example.com/krakow/hotels-in-krakow === [changed] ===> http://example.com/gdansk/hotels-in-gdansk
36
  http://example.com/krakow/restaurants-in-krakow === [changed] ===> http://example.com/gdansk/restaurants-in-gdansk
37
- http://example.com/krakow/transport-in-krakow === [changed] ===> http://example.com/gdansk/transport-in-gdansk
38
- http://example.com/blog/krakow-the-best-city-for-tourists === [changed] ===> http://example.com/blog/gdansk-the-best-city-for-tourists
39
- http://example.com/poland/cities/krakow === [changed] ===> http://example.com/poland/cities/gdansk
40
- http://example.com/poland/cities/stalowa-wola === [not changed] ===> http://example.com/cities/stalowa-wola
41
- http://example.com/poland/cities/warszawa === [not changed] ===> http://example.com/poland/cities/warszawa
42
  http://example.com/poland/cities/poznan === [not changed] ===> http://example.com/poland/cities/poznan`
43
 
44
  = All features =
@@ -54,10 +53,11 @@ http://example.com/poland/cities/poznan === [not changed] ===> http://example.co
54
  = Additional features available in Permalink Manager Pro =
55
 
56
  * Priority support
57
- * Full support for taxonomies
58
- * Full support for WooCommerce
59
- * "Stop-words" to keep your permalinks short & clean (pre-defined "stop-words" lists are available in 19 languages)
60
- * Custom fields in permalinks
 
61
 
62
  Buy <a href="https://permalinkmanager.pro?utm_source=wordpress">Permalink Manager Pro here</a>.
63
 
@@ -95,14 +95,22 @@ A. Currently there is no 100% guarantee that Permalink Manager will work correct
95
  1. "Permalink editor".
96
  2. "Find and replace" section.
97
  3. "Regenerate/Reset" section.
98
- 4. "Permastructures" section.
99
- 5. A list of updated posts.
100
- 6. Editable URI box in Post/Page/CPT edit pagees.
101
- 7. Settings section.
102
 
103
 
104
  == Changelog ==
105
 
 
 
 
 
 
 
 
 
106
  = 1.1.1 =
107
  * Typo fix
108
  * UI improvements
4
  License: GPLv3
5
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
6
  Tags: urls, permalinks, slugs, custom url, custom permalinks, uris, url, slug, permalink
7
+ Requires at least: 4.0
8
  Tested up to: 4.8
9
+ Stable tag: 1.1.2
10
 
11
  Most advanced yet easy-to-use permalink plugin that helps to maintain & bulk change your URLs & slugs.
12
 
21
  3. It allows to bulk regenerate/reset permalinks (or native slugs). This might be especially useful if your post titles are updated and native slugs need to be recreated.
22
  4. It allows to change the default permalink bases (permastructures) for all custom post types & posts and pages.
23
  5. It allows to auto-update URIs to match the current permastructure settings after eg. post title or assigned primary category is changed.
24
+ 6. It allows to control trailing slash behavior (remove or append slash to the end of permalink).
25
+
26
+ Additional features available in <a href="https://permalinkmanager.pro?utm_source=wordpress">Permalink Manager Pro</a> only.
27
+ 1. Case insensitive permalinks.
28
+ 2. Permalink editor for categories/tags/custom terms.
29
+ 3. Possibility to remove /product-category and /product from WooCommerce permalinks.
30
+ 4. "Stop-words" auto removal - custom words and/or words from predefined lists (19 languages available).
31
+ 5. Custom fields inside the permalinks (works also with Advanced Custom Fields).
32
 
33
  To improve the user experience, each tool allows also to filter the permalinks by post types or post statuses.
34
 
38
 
39
  `http://example.com/krakow/hotels-in-krakow === [changed] ===> http://example.com/gdansk/hotels-in-gdansk
40
  http://example.com/krakow/restaurants-in-krakow === [changed] ===> http://example.com/gdansk/restaurants-in-gdansk
 
 
 
 
 
41
  http://example.com/poland/cities/poznan === [not changed] ===> http://example.com/poland/cities/poznan`
42
 
43
  = All features =
53
  = Additional features available in Permalink Manager Pro =
54
 
55
  * Priority support
56
+ * Full support for taxonomies (categories, tags & custom taxonomies)
57
+ * Full support for WooCommerce (products, product tags, product categories)
58
+ * "Stop-words" to keep your permalinks short & clean (pre-defined "stop-words" lists are available in 21 languages)
59
+ * Add custom fields to the permalinks (Advanced Custom Fields compatible)
60
+ * Import permalinks from "Custom Permalinks" plugin
61
 
62
  Buy <a href="https://permalinkmanager.pro?utm_source=wordpress">Permalink Manager Pro here</a>.
63
 
95
  1. "Permalink editor".
96
  2. "Find and replace" section.
97
  3. "Regenerate/Reset" section.
98
+ 4. "Permastructures" section.
99
+ 5. A list of updated posts.
100
+ 6. Editable URI box in Post/Page/CPT edit pagees.
101
+ 7. Settings section.
102
 
103
 
104
  == Changelog ==
105
 
106
+ = 1.1.2 =
107
+ * Trailing slashes & Decode URIs - new settings
108
+ * Fix for "Bulk Edit" URI reset
109
+ * Partial code refactoring
110
+ * Hierarchical taxonomies fix
111
+ * New hook: "permalink_manager_filter_final_term_permalink"
112
+ * Taxonomies & permastructures fix
113
+
114
  = 1.1.1 =
115
  * Typo fix
116
  * UI improvements
includes/core/permalink-manager-actions.php CHANGED
@@ -25,6 +25,7 @@ class Permalink_Manager_Actions extends Permalink_Manager_Class {
25
  'permalink_manager_options' => array('function' => 'save_settings'),
26
  'permalink_manager_permastructs' => array('function' => 'save_permastructures'),
27
  'flush_sitemaps' => array('function' => 'save_permastructures'),
 
28
  );
29
  // Clear URIs & reset settings & permastructs also should be added here.
30
 
@@ -172,6 +173,18 @@ class Permalink_Manager_Actions extends Permalink_Manager_Class {
172
  }
173
  }
174
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  update_option('permalink-manager-uris', $permalink_manager_uris);
176
  $permalink_manager_before_sections_html .= Permalink_Manager_Admin_Functions::get_alert_message(__( 'URI array is cleared!', 'permalink-manager' ), 'updated');
177
  }
@@ -225,6 +238,13 @@ class Permalink_Manager_Actions extends Permalink_Manager_Class {
225
  }
226
  }
227
 
 
 
 
 
 
 
 
228
  }
229
 
230
  ?>
25
  'permalink_manager_options' => array('function' => 'save_settings'),
26
  'permalink_manager_permastructs' => array('function' => 'save_permastructures'),
27
  'flush_sitemaps' => array('function' => 'save_permastructures'),
28
+ 'import' => array('function' => 'import_custom_permalinks_uris'),
29
  );
30
  // Clear URIs & reset settings & permastructs also should be added here.
31
 
173
  }
174
  }
175
 
176
+ // Remove duplicates
177
+ $duplicates = array_count_values($permalink_manager_uris);
178
+ foreach($duplicates as $uri => $count) {
179
+ if($count > 1) {
180
+ // Keep the last instance
181
+ for($i = 1; $i < $count; $i++) {
182
+ $duplicated_id = array_search($uri, $permalink_manager_uris);
183
+ unset($permalink_manager_uris[$duplicated_id]);
184
+ }
185
+ }
186
+ }
187
+
188
  update_option('permalink-manager-uris', $permalink_manager_uris);
189
  $permalink_manager_before_sections_html .= Permalink_Manager_Admin_Functions::get_alert_message(__( 'URI array is cleared!', 'permalink-manager' ), 'updated');
190
  }
238
  }
239
  }
240
 
241
+ /**
242
+ * Import old URIs from "Custom Permalinks" (Pro)
243
+ */
244
+ function import_custom_permalinks_uris() {
245
+ Permalink_Manager_Pro_Functions::import_custom_permalinks_uris();
246
+ }
247
+
248
  }
249
 
250
  ?>
includes/core/permalink-manager-admin-functions.php CHANGED
@@ -189,7 +189,7 @@ class Permalink_Manager_Admin_Functions extends Permalink_Manager_Class {
189
  break;
190
 
191
  case 'single_checkbox' :
192
- $fields .= '<div class="checkboxes">';
193
  $checked = ($value == 1) ? "checked='checked'" : "";
194
  $checkbox_label = (isset($args['checkbox_label'])) ? $args['checkbox_label'] : '';
195
 
@@ -266,7 +266,7 @@ class Permalink_Manager_Admin_Functions extends Permalink_Manager_Class {
266
  $html .= "</div>";
267
  } else if(isset($args['container']) && $args['container'] == 'row') {
268
  $html = "<tr data-field=\"{$input_name}\" {$container_class}><th><label for='{$input_name}'>{$args['label']}</label></th>";
269
- $html .= "<td>{$fields}{$description}</td></tr>";
270
  $html .= ($append_content) ? "<tr class=\"appended-row\"><td colspan=\"2\">{$append_content}</td></tr>" : "";
271
  } else if(isset($args['container']) && $args['container'] == 'screen-options') {
272
  $html = "<fieldset data-field=\"{$input_name}\" {$container_class}><legend>{$args['label']}</legend>";
@@ -309,6 +309,7 @@ class Permalink_Manager_Admin_Functions extends Permalink_Manager_Class {
309
  // 2. Process the array with button and nonce field settings
310
  $button_text = (!empty($button['text'])) ? $button['text'] : '';
311
  $button_class = (!empty($button['class'])) ? $button['class'] : '';
 
312
  $nonce_action = (!empty($nonce['action'])) ? $nonce['action'] : '';
313
  $nonce_name = (!empty($nonce['name'])) ? $nonce['name'] : '';
314
 
@@ -368,7 +369,7 @@ class Permalink_Manager_Admin_Functions extends Permalink_Manager_Class {
368
 
369
  // End the fields' section + add button & nonce fields
370
  $html .= ($nonce_action && $nonce_name) ? wp_nonce_field($nonce_action, $nonce_name, true, true) : "";
371
- $html .= ($button_text) ? get_submit_button($button_text, $button_class, '', false) : "";
372
  $html .= '</form>';
373
  $html .= ($form_column_class) ? "</div>" : "";
374
 
@@ -511,10 +512,10 @@ class Permalink_Manager_Admin_Functions extends Permalink_Manager_Class {
511
 
512
  $main_content .= "<tr{$alternate_class}>";
513
  $main_content .= '<td class="row-title column-primary" data-colname="' . __('Title', 'permalink-manager') . '">' . $row['item_title'] . "<a target=\"_blank\" href=\"{$permalink}\"><span class=\"small\">{$permalink}</span></a>" . '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __('Show more details', 'permalink-manager') . '</span></button></td>';
514
- $main_content .= '<td data-colname="' . __('Old URI', 'permalink-manager') . '">' . $row['old_uri'] . '</td>';
515
- $main_content .= '<td data-colname="' . __('New URI', 'permalink-manager') . '">' . $row['new_uri'] . '</td>';
516
- $main_content .= (isset($row['old_slug'])) ? '<td data-colname="' . __('Old Slug', 'permalink-manager') . '">' . $row['old_slug'] . '</td>' : "";
517
- $main_content .= (isset($row['new_slug'])) ? '<td data-colname="' . __('New Slug', 'permalink-manager') . '">' . $row['new_slug'] . '</td>' : "";
518
  $main_content .= '</tr>';
519
  }
520
 
189
  break;
190
 
191
  case 'single_checkbox' :
192
+ $fields .= '<div class="single_checkbox">';
193
  $checked = ($value == 1) ? "checked='checked'" : "";
194
  $checkbox_label = (isset($args['checkbox_label'])) ? $args['checkbox_label'] : '';
195
 
266
  $html .= "</div>";
267
  } else if(isset($args['container']) && $args['container'] == 'row') {
268
  $html = "<tr data-field=\"{$input_name}\" {$container_class}><th><label for='{$input_name}'>{$args['label']}</label></th>";
269
+ $html .= "<td><fieldset>{$fields}{$description}</fieldset></td></tr>";
270
  $html .= ($append_content) ? "<tr class=\"appended-row\"><td colspan=\"2\">{$append_content}</td></tr>" : "";
271
  } else if(isset($args['container']) && $args['container'] == 'screen-options') {
272
  $html = "<fieldset data-field=\"{$input_name}\" {$container_class}><legend>{$args['label']}</legend>";
309
  // 2. Process the array with button and nonce field settings
310
  $button_text = (!empty($button['text'])) ? $button['text'] : '';
311
  $button_class = (!empty($button['class'])) ? $button['class'] : '';
312
+ $button_attributes = (!empty($button['attributes'])) ? $button['attributes'] : '';
313
  $nonce_action = (!empty($nonce['action'])) ? $nonce['action'] : '';
314
  $nonce_name = (!empty($nonce['name'])) ? $nonce['name'] : '';
315
 
369
 
370
  // End the fields' section + add button & nonce fields
371
  $html .= ($nonce_action && $nonce_name) ? wp_nonce_field($nonce_action, $nonce_name, true, true) : "";
372
+ $html .= ($button_text) ? get_submit_button($button_text, $button_class, '', false, $button_attributes) : "";
373
  $html .= '</form>';
374
  $html .= ($form_column_class) ? "</div>" : "";
375
 
512
 
513
  $main_content .= "<tr{$alternate_class}>";
514
  $main_content .= '<td class="row-title column-primary" data-colname="' . __('Title', 'permalink-manager') . '">' . $row['item_title'] . "<a target=\"_blank\" href=\"{$permalink}\"><span class=\"small\">{$permalink}</span></a>" . '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __('Show more details', 'permalink-manager') . '</span></button></td>';
515
+ $main_content .= '<td data-colname="' . __('Old URI', 'permalink-manager') . '">' . urldecode($row['old_uri']) . '</td>';
516
+ $main_content .= '<td data-colname="' . __('New URI', 'permalink-manager') . '">' . urldecode($row['new_uri']) . '</td>';
517
+ $main_content .= (isset($row['old_slug'])) ? '<td data-colname="' . __('Old Slug', 'permalink-manager') . '">' . urldecode($row['old_slug']) . '</td>' : "";
518
+ $main_content .= (isset($row['new_slug'])) ? '<td data-colname="' . __('New Slug', 'permalink-manager') . '">' . urldecode($row['new_slug']) . '</td>' : "";
519
  $main_content .= '</tr>';
520
  }
521
 
includes/core/permalink-manager-core-functions.php ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Core function
5
+ */
6
+ class Permalink_Manager_Core_Functions extends Permalink_Manager_Class {
7
+
8
+ public function __construct() {
9
+ add_action('init', array($this, 'init_hooks'), 99);
10
+ }
11
+
12
+ function init_hooks() {
13
+ // Use the URIs set in this plugin + redirect from old URIs to new URIs + adjust canonical redirect settings
14
+ add_filter( 'request', array($this, 'detect_post'), 0, 1 );
15
+
16
+ // Trailing slashes
17
+ add_filter('permalink_manager_filter_final_term_permalink', array($this, 'control_trailing_slashes'), 9);
18
+ add_filter('permalink_manager_filter_final_post_permalink', array($this, 'control_trailing_slashes'), 9);
19
+ add_filter('permalink_manager_filter_post_sample_permalink', array($this, 'control_trailing_slashes'), 9);
20
+ add_filter('redirect_canonical', array($this, 'canonical_redirect_trailing_slash'), 9, 2);
21
+
22
+ // Redirects
23
+ add_action( 'template_redirect', array($this, 'redirect_to_new_uri'), 999);
24
+ add_action( 'parse_request', array($this, 'disable_canonical_redirect'), 0, 1 );
25
+
26
+ // Case insensitive permalinks
27
+ add_action( 'parse_request', array($this, 'case_insensitive_permalinks'), 0);
28
+ }
29
+
30
+ /**
31
+ * The most important Permalink Manager function
32
+ */
33
+ function detect_post($query) {
34
+ global $wpdb, $permalink_manager_uris, $wp_filter, $permalink_manager_options;
35
+
36
+ // Check if any custom URI is used
37
+ if(!(is_array($permalink_manager_uris)) || empty($query)) return $query;
38
+
39
+ // Used in debug mode
40
+ $old_query = $query;
41
+
42
+ /**
43
+ * 1. Prepare URL and check if it is correct
44
+ */
45
+ $protocol = stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true ? 'https://' : 'http://';
46
+ $request_url = "{$protocol}{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
47
+ $home_url = trim(rtrim(get_option('home'), '/'));
48
+ $home_url = ($protocol == 'https://') ? str_replace("http://", "https://", $home_url) : str_replace("https://", "http://", $home_url); // Adjust prefix (it should be the same in both request & home_url)
49
+
50
+ if (filter_var($request_url, FILTER_VALIDATE_URL)) {
51
+ /**
52
+ * 1. Process URL & find the URI
53
+ */
54
+ // Remove .html suffix and domain name from URL and query (URLs ended with .html will work as aliases)
55
+ $request_url = trim(str_replace($home_url, "", $request_url), "/");
56
+
57
+ // Remove querystrings from URI
58
+ $request_url = strtok($request_url, '?');
59
+
60
+ // Use default REGEX to detect post
61
+ preg_match("/^(.+?)\/?(page|feed|embed|attachment|track)?(?:\/([\d+]))?\/?$/i", $request_url, $regex_parts);
62
+ $uri_parts['lang'] = false;
63
+ $uri_parts['uri'] = (!empty($regex_parts[1])) ? $regex_parts[1] : "";
64
+ $uri_parts['endpoint'] = (!empty($regex_parts[2])) ? $regex_parts[2] : "";
65
+ $uri_parts['endpoint_value'] = (!empty($regex_parts[3])) ? $regex_parts[3] : "";
66
+
67
+ // Allow to filter the results by third-parties
68
+ $uri_parts = apply_filters('permalink-manager-detect-uri', $uri_parts, $request_url);
69
+
70
+ // Stop the function if $uri_parts is empty
71
+ if(empty($uri_parts)) return $query;
72
+
73
+ // Get the URI parts from REGEX parts
74
+ $lang = $uri_parts['lang'];
75
+ $uri = $uri_parts['uri'];
76
+ $endpoint = $uri_parts['endpoint'];
77
+ $endpoint_value = $uri_parts['endpoint_value'];
78
+
79
+ // Trim slashes
80
+ $uri = trim($uri, "/");
81
+
82
+ // Decode both Request URI & URIs array
83
+ $uri = urldecode($uri);
84
+ foreach ($permalink_manager_uris as $key => $value) {
85
+ $permalink_manager_uris[$key] = urldecode($value);
86
+ }
87
+
88
+ // Ignore URLs with no URI grabbed
89
+ if(empty($uri)) return $query;
90
+
91
+ /**
92
+ * 2. Check if found URI matches any element from custom uris array
93
+ */
94
+ $item_id = array_search($uri, $permalink_manager_uris);
95
+
96
+ // Check again in case someone added .html suffix to particular post (with .html suffix)
97
+ $item_id = (empty($item_id)) ? array_search("{$uri}.html", $permalink_manager_uris) : $item_id;
98
+
99
+ // Check again in case someone used post/tax IDs instead of slugs
100
+ $deep_detect_enabled = apply_filters('permalink-manager-deep-uri-detect', false);
101
+ if($deep_detect_enabled && (empty($item_id)) && isset($old_query['page'])) {
102
+ $item_id = array_search("{$uri}/{$endpoint_value}", $permalink_manager_uris);
103
+ $endpoint_value = $endpoint = "";
104
+ }
105
+
106
+ // Allow to filter the item_id by third-parties after initial detection
107
+ $item_id = apply_filters('permalink-manager-detected-initial-id', $item_id, $uri_parts, $request_url);
108
+
109
+ // Clear the original query before it is filtered
110
+ $query = ($item_id) ? array() : $query;
111
+
112
+ /**
113
+ * 3A. Custom URI assigned to taxonomy
114
+ */
115
+ if(strpos($item_id, 'tax-') !== false) {
116
+ // Remove the "tax-" prefix
117
+ $item_id = preg_replace("/[^0-9]/", "", $item_id);
118
+
119
+ // Filter detected post ID
120
+ $item_id = apply_filters('permalink-manager-detected-term-id', intval($item_id), $uri_parts, true);
121
+
122
+ // Get the variables to filter wp_query and double-check if tax exists
123
+ $term = get_term(intval($item_id));
124
+ if(empty($term->taxonomy)) { return $query; }
125
+
126
+ // Get some term data
127
+ $query_parameter = ($term->taxonomy == 'category') ? 'category_name' : $term->taxonomy;
128
+ $term_ancestors = get_ancestors($item_id, $term->taxonomy);
129
+ $final_uri = $term->slug;
130
+
131
+ // Fix for hierarchical CPT & pages
132
+ if(empty($term_ancestors)) {
133
+ foreach ($term_ancestors as $parent) {
134
+ $parent = get_term($parent, $term->taxonomy);
135
+ if(!empty($parent->slug)) {
136
+ $final_uri = $parent->slug . '/' . $final_uri;
137
+ }
138
+ }
139
+ }
140
+
141
+ // Make the redirects more clever - see redirect_to_new_uri() method
142
+ $query['do_not_redirect'] = 1;
143
+ $query[$query_parameter] = $final_uri;
144
+ }
145
+ /**
146
+ * 3B. Custom URI assigned to post/page/cpt item
147
+ */
148
+ else if(isset($item_id) && is_numeric($item_id)) {
149
+ // Fix for revisions
150
+ $is_revision = wp_is_post_revision($item_id);
151
+ $item_id = ($is_revision) ? $is_revision : $item_id;
152
+
153
+ // Filter detected post ID
154
+ $item_id = apply_filters('permalink-manager-detected-post-id', $item_id, $uri_parts);
155
+
156
+ $post_to_load = get_post($item_id);
157
+ $final_uri = $post_to_load->post_name;
158
+ $post_type = $post_to_load->post_type;
159
+
160
+ // Fix for hierarchical CPT & pages
161
+ if(!(empty($post_to_load->ancestors))) {
162
+ foreach ($post_to_load->ancestors as $parent) {
163
+ $parent = get_post( $parent );
164
+ if($parent && $parent->post_name) {
165
+ $final_uri = $parent->post_name . '/' . $final_uri;
166
+ }
167
+ }
168
+ }
169
+
170
+ // Alter query parameters
171
+ if($post_to_load->post_type == 'page') {
172
+ $query['pagename'] = $final_uri;
173
+ } else if($post_to_load->post_type == 'post') {
174
+ $query['name'] = $final_uri;
175
+ } else if($post_to_load->post_type == 'attachment') {
176
+ $query['attachment'] = $final_uri;
177
+ } else {
178
+ $query['name'] = $final_uri;
179
+ $query['post_type'] = $post_type;
180
+ $query[$post_type] = $final_uri;
181
+ }
182
+
183
+ // Make the redirects more clever - see redirect_to_new_uri() method
184
+ $query['do_not_redirect'] = 1;
185
+ }
186
+
187
+ /**
188
+ * 2C. Endpoints
189
+ */
190
+ if($item_id && !(empty($endpoint_value))) {
191
+ $endpoint = ($endpoint) ? str_replace(array('page', 'trackback'), array('paged', 'tb'), $endpoint) : "page";
192
+ $query[$endpoint] = $endpoint_value;
193
+ }
194
+
195
+ }
196
+
197
+ // Debug mode
198
+ if(isset($_REQUEST['debug_url'])) {
199
+ $debug_info['old_query_vars'] = $old_query;
200
+ $debug_info['new_query_vars'] = $query;
201
+
202
+ $debug_txt = json_encode($debug_info);
203
+ $debug_txt = "<textarea style=\"width:100%;height:300px\">{$debug_txt}</textarea>";
204
+ wp_die($debug_txt);
205
+ }
206
+
207
+ return $query;
208
+ }
209
+
210
+ /**
211
+ * Trailing slash
212
+ */
213
+ function control_trailing_slashes($permalink) {
214
+ global $permalink_manager_options;
215
+
216
+ $trailing_slash_setting = (!empty($permalink_manager_options['general']['trailing_slashes'])) ? $permalink_manager_options['general']['trailing_slashes'] : "";
217
+
218
+ if($trailing_slash_setting == 1) {
219
+ $permalink = trailingslashit($permalink);
220
+ } else if($trailing_slash_setting > 1) {
221
+ $permalink = untrailingslashit($permalink);
222
+ }
223
+
224
+ return $permalink;
225
+ }
226
+
227
+ function canonical_redirect_trailing_slash($redirect_url, $requested_url) {
228
+ global $permalink_manager_options;
229
+
230
+ if(substr($redirect_url, 0, -1) != '/' && $permalink_manager_options['general']['trailing_slashes'] > 1) {
231
+ $redirect_url = false;
232
+ }
233
+ return $redirect_url;
234
+ }
235
+
236
+ /**
237
+ * Redirects
238
+ */
239
+ function redirect_to_new_uri() {
240
+ global $wp_query, $permalink_manager_uris, $permalink_manager_options;
241
+
242
+ // Sometimes $wp_query indicates the wrong object if requested directly
243
+ $queried_object = get_queried_object();
244
+
245
+ if(!empty($permalink_manager_options['general']['redirect']) && !empty($queried_object)) {
246
+
247
+ // Affect only posts with custom URI and old URIs
248
+ if(!empty($queried_object->ID) && isset($permalink_manager_uris[$queried_object->ID]) && empty($wp_query->query['do_not_redirect']) && empty($wp_query->query['preview'])) {
249
+ // Ignore posts with specific statuses
250
+ if(!(empty($queried_object->post_status)) && in_array($queried_object->post_status, array('draft', 'pending', 'auto-draft', 'future'))) {
251
+ return '';
252
+ }
253
+
254
+ // Get the real URL
255
+ $correct_permalink = get_permalink($queried_object->ID);
256
+ }
257
+ // Affect only terms with custom URI and old URIs
258
+ else if(!empty($queried_object->term_id) && isset($permalink_manager_uris["tax-{$queried_object->term_id}"]) && empty($wp_query->query['do_not_redirect'])) {
259
+ // Get the real URL
260
+ $correct_permalink = get_term_link($queried_object->term_id, $queried_object->taxonomy);
261
+ }
262
+
263
+ // Get the redirection mode
264
+ $redirect_mode = $permalink_manager_options['general']['redirect'];
265
+
266
+ // Ignore default URIs (or do nothing if redirects are disabled)
267
+ if(!empty($correct_permalink) && !empty($redirect_mode)) {
268
+ wp_safe_redirect($correct_permalink, $redirect_mode);
269
+ exit();
270
+ }
271
+ }
272
+ }
273
+
274
+ function disable_canonical_redirect() {
275
+ global $permalink_manager_options, $wp_filter;
276
+ if(!($permalink_manager_options['general']['canonical_redirect'])) {
277
+ remove_action('template_redirect', 'redirect_canonical');
278
+ add_filter('wpml_is_redirected', '__return_false', 99, 2);
279
+ }
280
+ }
281
+
282
+ /**
283
+ * Case insensitive permalinks
284
+ */
285
+ function case_insensitive_permalinks() {
286
+ global $permalink_manager_options, $permalink_manager_uris;
287
+
288
+ if(!empty($permalink_manager_options['general']['case_insensitive_permalinks']) && !empty($_SERVER['REQUEST_URI'])) {
289
+ $_SERVER['REQUEST_URI'] = strtolower($_SERVER['REQUEST_URI']);
290
+ $permalink_manager_uris = array_map('strtolower', $permalink_manager_uris);
291
+ }
292
+ }
293
+
294
+ }
295
+ ?>
includes/core/permalink-manager-helper-functions.php CHANGED
@@ -30,7 +30,7 @@ class Permalink_Manager_Helper_Functions extends Permalink_Manager_Class {
30
  static function get_primary_term($post_id, $taxonomy, $slug_only = true) {
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
  if(!is_wp_error($primary_term)) {
30
  static function get_primary_term($post_id, $taxonomy, $slug_only = true) {
31
  global $permalink_manager_options;
32
 
33
+ if($permalink_manager_options['general']['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
  if(!is_wp_error($primary_term)) {
includes/core/permalink-manager-third-parties.php CHANGED
@@ -10,7 +10,7 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
10
  }
11
 
12
  function init_hooks() {
13
- global $sitepress_settings;
14
 
15
  // 1. WPML
16
  if($sitepress_settings) {
@@ -43,7 +43,7 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
43
  $yoast_permalink_options = get_option('wpseo_permalinks');
44
 
45
  // Redirect attachment to parent post/page enabled
46
- if(!empty($yoast_permalink_options['redirectattachment'])) {
47
  add_filter('permalink-manager-detected-initial-id', array($this, 'yoast_detect_attachment'), 9, 3);
48
  }
49
  }
@@ -187,5 +187,37 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
187
  return $item_id;
188
  }
189
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  }
191
  ?>
10
  }
11
 
12
  function init_hooks() {
13
+ global $sitepress_settings, $permalink_manager_options;
14
 
15
  // 1. WPML
16
  if($sitepress_settings) {
43
  $yoast_permalink_options = get_option('wpseo_permalinks');
44
 
45
  // Redirect attachment to parent post/page enabled
46
+ if(!empty($yoast_permalink_options['redirectattachment']) && !empty($permalink_manager_options['general']['redirect'])) {
47
  add_filter('permalink-manager-detected-initial-id', array($this, 'yoast_detect_attachment'), 9, 3);
48
  }
49
  }
187
  return $item_id;
188
  }
189
 
190
+ /**
191
+ * 4. Custom Permalinks
192
+ */
193
+ public static function custom_permalinks_uris() {
194
+ global $wpdb;
195
+
196
+ $custom_permalinks_uris = array();
197
+
198
+ // 1. List tags/categories
199
+ $table = get_option('custom_permalink_table');
200
+ if($table && is_array($table)) {
201
+ foreach ( $table as $permalink => $info ) {
202
+ $custom_permalinks_uris[] = array(
203
+ 'id' => "tax-" . $info['id'],
204
+ 'uri' => trim($permalink, "/")
205
+ );
206
+ }
207
+ }
208
+
209
+ // 2. List posts/pages
210
+ $query = "SELECT p.ID, m.meta_value FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON (p.ID = m.post_id) WHERE m.meta_key = 'custom_permalink' AND m.meta_value != '';";
211
+ $posts = $wpdb->get_results($query);
212
+ foreach($posts as $post) {
213
+ $custom_permalinks_uris[] = array(
214
+ 'id' => $post->ID,
215
+ 'uri' => trim($post->meta_value, "/"),
216
+ );
217
+ }
218
+
219
+ return $custom_permalinks_uris;
220
+ }
221
+
222
  }
223
  ?>
includes/core/permalink-manager-uri-functions-post.php CHANGED
@@ -479,17 +479,19 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
479
 
480
  // Do not change anything if post is not saved yet (display sample permalink instead)
481
  if($autosave || empty($post->post_status)) {
482
- $sample_permalink = $default_uri;
483
  } else {
484
- //$uri = $sample_permalink = (!empty($permalink_manager_uris[$id])) ? $permalink_manager_uris[$id] : $default_uri;
485
- $uri = $sample_permalink = (!empty($permalink_manager_uris[$id])) ? $permalink_manager_uris[$id] : $native_uri;
486
  }
487
 
488
- // Decode URI
489
- $sample_permalink = urldecode($sample_permalink);
490
 
491
  // Prepare the sample & default permalink
492
- $sample_permalink = sprintf("{$home_url}{$prefix}<span class=\"editable\">%s</span>", str_replace("//", "/", trim($sample_permalink, "/")));
 
 
493
 
494
  // Append new HTML output
495
  $html .= sprintf("<span class=\"sample-permalink-span\"><a href=\"%s\">%s</a></span>&nbsp;", strip_tags($sample_permalink), $sample_permalink);
@@ -530,7 +532,7 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
530
  __("Default URI", "permalink-manager"), urldecode(esc_html($default_uri)),
531
  __("Restore to Default URI", "permalink-manager")
532
  );
533
- if(!empty($permalink_manager_options['miscellaneous']['redirect'])) {
534
  $html .= sprintf(
535
  "<p class=\"default-permalink-row columns-container\"><span><strong>%s</strong> <a href=\"%s\">%s</a></span></p>",
536
  __("Automatic redirect for native URI enabled:", "permalink-manager"),
@@ -543,6 +545,9 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
543
  $html .= "</div>";
544
  }
545
 
 
 
 
546
  return $html;
547
  }
548
 
@@ -552,6 +557,8 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
552
  function update_post_uri($post_id, $post, $update) {
553
  global $permalink_manager_uris, $permalink_manager_options, $permalink_manager_before_sections_html;
554
 
 
 
555
  // Fix for revisions
556
  $is_revision = wp_is_post_revision($post_id);
557
  $post_id = ($is_revision) ? $is_revision : $post_id;
@@ -559,7 +566,7 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
559
 
560
  // Ignore auto-drafts & removed posts
561
  //if(in_array($post->post_status, array('auto-draft', 'trash')) || empty($post->post_name) || (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)) { return; }
562
- if(in_array($post->post_status, array('auto-draft', 'trash')) || (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)) { return; }
563
 
564
  // Get auto-update URI setting (if empty use global setting)
565
  $auto_update_uri_current = (!empty($_POST["auto_update_uri"])) ? intval($_POST["auto_update_uri"]) : 0;
479
 
480
  // Do not change anything if post is not saved yet (display sample permalink instead)
481
  if($autosave || empty($post->post_status)) {
482
+ $sample_permalink_url = $default_uri;
483
  } else {
484
+ //$uri = $sample_permalink_url = (!empty($permalink_manager_uris[$id])) ? $permalink_manager_uris[$id] : $default_uri;
485
+ $uri = $sample_permalink_url = (!empty($permalink_manager_uris[$id])) ? $permalink_manager_uris[$id] : $native_uri;
486
  }
487
 
488
+ // Decode URI & allow to filter it
489
+ $sample_permalink_url = apply_filters('permalink_manager_filter_post_sample_permalink', urldecode($sample_permalink_url), $post);
490
 
491
  // Prepare the sample & default permalink
492
+ $sample_permalink = sprintf("{$home_url}{$prefix}<span class=\"editable\">%s</span>", str_replace("//", "/", $sample_permalink_url));
493
+
494
+ // Allow to filter the sample permalink URL
495
 
496
  // Append new HTML output
497
  $html .= sprintf("<span class=\"sample-permalink-span\"><a href=\"%s\">%s</a></span>&nbsp;", strip_tags($sample_permalink), $sample_permalink);
532
  __("Default URI", "permalink-manager"), urldecode(esc_html($default_uri)),
533
  __("Restore to Default URI", "permalink-manager")
534
  );
535
+ if(!empty($permalink_manager_options['general']['redirect'])) {
536
  $html .= sprintf(
537
  "<p class=\"default-permalink-row columns-container\"><span><strong>%s</strong> <a href=\"%s\">%s</a></span></p>",
538
  __("Automatic redirect for native URI enabled:", "permalink-manager"),
545
  $html .= "</div>";
546
  }
547
 
548
+ // Append hidden field with native slug
549
+ $html .= (!empty($post->post_name)) ? "<input id=\"new-post-slug\" value=\"{$post->post_name}\" autocomplete=\"off\" type=\"hidden\">" : "";
550
+
551
  return $html;
552
  }
553
 
557
  function update_post_uri($post_id, $post, $update) {
558
  global $permalink_manager_uris, $permalink_manager_options, $permalink_manager_before_sections_html;
559
 
560
+ if(!isset($_POST['custom_uri'])) { return; }
561
+
562
  // Fix for revisions
563
  $is_revision = wp_is_post_revision($post_id);
564
  $post_id = ($is_revision) ? $is_revision : $post_id;
566
 
567
  // Ignore auto-drafts & removed posts
568
  //if(in_array($post->post_status, array('auto-draft', 'trash')) || empty($post->post_name) || (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)) { return; }
569
+ if(in_array($post->post_status, array('auto-draft', 'trash')) || (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (!empty($_REQUEST['bulk_edit'])) || (!empty($_REQUEST['post_view']))) { return; }
570
 
571
  // Get auto-update URI setting (if empty use global setting)
572
  $auto_update_uri_current = (!empty($_POST["auto_update_uri"])) ? intval($_POST["auto_update_uri"]) : 0;
includes/views/permalink-manager-settings.php CHANGED
@@ -29,8 +29,9 @@ class Permalink_Manager_Settings extends Permalink_Manager_Class {
29
 
30
  $sections_and_fields = apply_filters('permalink-manager-settings-fields', array(
31
  'general' => array(
32
- 'section_name' => __('General & Interface', 'permalink-manager'),
33
  'container' => 'row',
 
34
  'fields' => array(
35
  'auto_update_uris' => array(
36
  'type' => 'single_checkbox',
@@ -38,31 +39,18 @@ class Permalink_Manager_Settings extends Permalink_Manager_Class {
38
  'input_class' => '',
39
  'description' => __('If enabled, the custom URIs will be automatically updated every time the post is saved or updated.', 'permalink-manager')
40
  ),
41
- 'force_custom_slugs' => array(
42
- 'type' => 'single_checkbox',
43
- 'label' => __('Force custom slugs', 'permalink-manager'),
44
- 'input_class' => '',
45
- 'description' => __('If enabled, the native slugs in the defult URIs will be recreated from the post title.<br />This may cause URI duplicates when the post title is used more than once.', 'permalink-manager')
46
- ),
47
  'case_insensitive_permalinks' => array(
48
  'type' => 'single_checkbox',
49
  'label' => __('Case insensitive URIs', 'permalink-manager'),
50
  'input_class' => '',
51
- 'pro' => true,
52
- 'disabled' => true,
53
  'description' => __('Make the permalinks case-insensitive.', 'permalink-manager')
54
- ),
55
- 'decode_uris' => array(
56
- 'type' => 'single_checkbox',
57
- 'label' => __('Decode URIs', 'permalink-manager'),
58
- 'input_class' => '',
59
- 'description' => __('If enabled, the permalinks with non-ASCII characters may not be recognized in older browsers versions (advanced users only).', 'permalink-manager')
60
- ),
61
  )
62
  ),
63
  'miscellaneous' => array(
64
- 'section_name' => __('Miscellaneous & SEO functions', 'permalink-manager'),
65
  'container' => 'row',
 
66
  'fields' => array(
67
  'yoast_primary_term' => array(
68
  'type' => 'single_checkbox',
@@ -84,6 +72,41 @@ class Permalink_Manager_Settings extends Permalink_Manager_Class {
84
  'description' => __('If enabled - the visitors will be redirected from native permalinks to your custom permalinks.<br /><strong>Only native permalinks (used when the plugin is disabled) will be redirected to new custom URIs</strong>.', 'permalink-manager')
85
  )
86
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  )
88
  ));
89
 
29
 
30
  $sections_and_fields = apply_filters('permalink-manager-settings-fields', array(
31
  'general' => array(
32
+ 'section_name' => __('General settings', 'permalink-manager'),
33
  'container' => 'row',
34
+ 'name' => 'general',
35
  'fields' => array(
36
  'auto_update_uris' => array(
37
  'type' => 'single_checkbox',
39
  'input_class' => '',
40
  'description' => __('If enabled, the custom URIs will be automatically updated every time the post is saved or updated.', 'permalink-manager')
41
  ),
 
 
 
 
 
 
42
  'case_insensitive_permalinks' => array(
43
  'type' => 'single_checkbox',
44
  'label' => __('Case insensitive URIs', 'permalink-manager'),
45
  'input_class' => '',
 
 
46
  'description' => __('Make the permalinks case-insensitive.', 'permalink-manager')
47
+ )
 
 
 
 
 
 
48
  )
49
  ),
50
  'miscellaneous' => array(
51
+ 'section_name' => __('SEO functions', 'permalink-manager'),
52
  'container' => 'row',
53
+ 'name' => 'general',
54
  'fields' => array(
55
  'yoast_primary_term' => array(
56
  'type' => 'single_checkbox',
72
  'description' => __('If enabled - the visitors will be redirected from native permalinks to your custom permalinks.<br /><strong>Only native permalinks (used when the plugin is disabled) will be redirected to new custom URIs</strong>.', 'permalink-manager')
73
  )
74
  )
75
+ ),
76
+ 'advanced' => array(
77
+ 'section_name' => __('Advanced settings', 'permalink-manager'),
78
+ 'container' => 'row',
79
+ 'name' => 'general',
80
+ 'fields' => array(
81
+ 'decode_uris' => array(
82
+ 'type' => 'single_checkbox',
83
+ 'label' => __('Decode URIs', 'permalink-manager'),
84
+ 'input_class' => '',
85
+ 'description' => __('If enabled, the permalinks with non-ASCII characters may not be recognized in older browsers versions (advanced users only).', 'permalink-manager')
86
+ ),
87
+ 'force_custom_slugs' => array(
88
+ 'type' => 'single_checkbox',
89
+ 'label' => __('Force custom slugs', 'permalink-manager'),
90
+ 'input_class' => '',
91
+ 'description' => __('If enabled, the native slugs in the defult URIs will be recreated from the post title.<br />This may cause URI duplicates when the post title is used more than once.', 'permalink-manager')
92
+ ),
93
+ 'trailing_slashes' => array(
94
+ 'type' => 'select',
95
+ 'label' => __('Trailing slashes', 'permalink-manager'),
96
+ 'input_class' => 'settings-select',
97
+ 'choices' => array(0 => __('Use default settings', 'permalink-manager'), 1 => __('Always add trailing slashes', 'permalink-manager'), 2 => __('Always remove trailing slashes', 'permalink-manager')),
98
+ 'description' => __('This option can be used to alter the native settings and control if trailing slash should be added or removed from the end of posts & terms permalinks.', 'permalink-manager')
99
+ ),
100
+ /*'extension_suffix' => array(
101
+ 'type' => 'select',
102
+ 'label' => __('Extension suffix', 'permalink-manager'),
103
+ 'input_class' => 'settings-select',
104
+ 'pro' => true,
105
+ 'disabled' => true,
106
+ 'choices' => array(0 => __('Do not add', 'permalink-manager'), 'html' => __('Append .html', 'permalink-manager'), 'htm' => __('Append .htm', 'permalink-manager'), 'php' => __('Append .php', 'permalink-manager')),
107
+ 'description' => __('Allows to add .html, .htm or .php extension to the end of permalink.', 'permalink-manager')
108
+ )*/
109
+ )
110
  )
111
  ));
112
 
includes/views/permalink-manager-tools.php CHANGED
@@ -25,7 +25,11 @@ class Permalink_Manager_Tools extends Permalink_Manager_Class {
25
  'stop_words' => array(
26
  'name' => __('Stop words', 'permalink-manager'),
27
  'function' => array('class' => 'Permalink_Manager_Admin_Functions', 'method' => 'pro_text')
28
- )
 
 
 
 
29
  )
30
  );
31
 
25
  'stop_words' => array(
26
  'name' => __('Stop words', 'permalink-manager'),
27
  'function' => array('class' => 'Permalink_Manager_Admin_Functions', 'method' => 'pro_text')
28
+ ),
29
+ /*'import' => array(
30
+ 'name' => __('"Custom Permalinks" import', 'permalink-manager'),
31
+ 'function' => array('class' => 'Permalink_Manager_Admin_Functions', 'method' => 'pro_text')
32
+ )*/
33
  )
34
  );
35
 
includes/views/permalink-manager-upgrade.php CHANGED
@@ -13,7 +13,7 @@ class Permalink_Manager_Upgrade extends Permalink_Manager_Class {
13
 
14
  public function add_upgrade_section($admin_sections) {
15
  $admin_sections['upgrade'] = array(
16
- 'name' => __('Upgrade to PRO', 'permalink-manager'),
17
  'function' => array('class' => 'Permalink_Manager_Upgrade', 'method' => 'output')
18
  );
19
 
@@ -21,28 +21,42 @@ class Permalink_Manager_Upgrade extends Permalink_Manager_Class {
21
  }
22
 
23
  public function output() {
24
- $output = sprintf("<h3>%s</h3>", __("Permalink Manager Pro features", "permalink-manager"));
25
- $output .= sprintf("<p class=\"lead\">%s</p>", __('Take full control of your permalinks. Easily edit terms permalinks, use custom fields inside the URLs and automatically remove "stop words" from your web addresses!', 'permalink-manager'));
 
 
26
 
27
  $output .= "<div class=\"columns-container\">";
28
  $output .= "<div class=\"column-1_3\">";
29
  $output .= sprintf("<h5>%s</h5>", __("Full Taxonomy Support", "permalink-manager"));
30
- $output .= wpautop(__("With Permalink Manager Pro you can easily alter the default taxonomies’ permastructures & edit the full permalink of all the categories, tags and custom taxonomies terms!", "permalink-manager"));
31
- $output .= wpautop(__("You can also bulk edit the taxonomies permalinks with bulk tools (“Find & replace” and “Regnerate/reset”) and remove “stop words” from their default URIs!", "permalink-manager"));
32
  $output .= "</div>";
33
  $output .= "<div class=\"column-1_3\">";
34
  $output .= sprintf("<h5>%s</h5>", __("Full WooCommerce Support", "permalink-manager"));
35
- $output .= wpautop(__("Adjust your shop, product category, single product permalinks to suit your needs!", "permalink-manager"));
36
- $output .= wpautop(__("Remove <em>product-category</em>, <em>product-tag</em> and <em>product</em> or replace them with any tailored permastructures. Set completely custom permalinks for each product &#038; product taxonomies individually.", "permalink-manager"));
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  $output .= "</div>";
38
  $output .= "<div class=\"column-1_3\">";
39
- $output .= sprintf("<h5>%s</h5>", __("Stop words & custom fields inside permalinks", "permalink-manager"));
40
- $output .= wpautop(__("Set your own list of stop words or use a predefined one available in 21 languages. All the words will be automatically removed from default URIs.", "permalink-manager"));
41
- $output .= wpautop(__("Would you like to automatically embed your custom fields value inside the permalinks? Now, it is easy - all you need to do is to insert the tag with the custom field key name to the permastructure.", "permalink-manager"));
42
  $output .= "</div>";
43
  $output .= "</div>";
44
 
45
- $output .= sprintf("<p><a class=\"button button-default margin-top\" href=\"%s\" target=\"_blank\">%s</a>&nbsp;&nbsp;<a class=\"button button-primary margin-top\" href=\"%s\" target=\"_blank\">%s</a></p>", PERMALINK_MANAGER_WEBSITE, __("More info about Permalink Manager Pro"), "https://gumroad.com/l/permalink-manager?utm_source=plugin&utm_medium=upgrade_page&utm_campaign=freemium", __("Buy Permalink Manager Pro"));
46
 
47
  return $output;
48
  }
13
 
14
  public function add_upgrade_section($admin_sections) {
15
  $admin_sections['upgrade'] = array(
16
+ 'name' => __('Extra features', 'permalink-manager'),
17
  'function' => array('class' => 'Permalink_Manager_Upgrade', 'method' => 'output')
18
  );
19
 
21
  }
22
 
23
  public function output() {
24
+ $output = sprintf("<h3>%s</h3>", __("Permalink Manager Pro extra features", "permalink-manager"));
25
+
26
+ $output .= sprintf("<p class=\"lead\">%s</p>", __('Take full control of your permalinks! Permalink Manager Pro contains a bunch of useful extra functionalities!', 'permalink-manager'));
27
+ $output .= sprintf("<p class=\"\">%s</p>", __('Not certain if Permalink Manager Pro will fix your permalink problem?<br />Contact us at <a href="mailto:contact@permalinkmanager.pro">contact@permalinkmanager.pro</a>!', 'permalink-manager'));
28
 
29
  $output .= "<div class=\"columns-container\">";
30
  $output .= "<div class=\"column-1_3\">";
31
  $output .= sprintf("<h5>%s</h5>", __("Full Taxonomy Support", "permalink-manager"));
32
+ $output .= wpautop(__("With Permalink Manager Pro you can easily alter the default taxonomies’ permastructures & edit the full permalink in all the categories, tags and custom taxonomies terms!", "permalink-manager"));
33
+ $output .= wpautop(__("You can also bulk edit the taxonomies permalinks (eg. reset the native terms slugs) with included tools - “Find & replace” or “Regnerate/reset”", "permalink-manager"));
34
  $output .= "</div>";
35
  $output .= "<div class=\"column-1_3\">";
36
  $output .= sprintf("<h5>%s</h5>", __("Full WooCommerce Support", "permalink-manager"));
37
+ $output .= wpautop(__("Adjust your shop, product category, tags or single product permalinks and set your e-commerce URLs any way you want!", "permalink-manager"));
38
+ $output .= wpautop(__("Remove <em>product-category</em>, <em>product-tag</em> and <em>product</em> or replace them with any permastructures. Furthermore, the plugin allows to set completely custom permalinks for each product &#038; product taxonomies individually.", "permalink-manager"));
39
+ $output .= "</div>";
40
+ $output .= "<div class=\"column-1_3\">";
41
+ $output .= sprintf("<h5>%s</h5>", __("Custom fields inside permalinks", "permalink-manager"));
42
+ $output .= wpautop(__("Automatically embed your custom fields values inside the permalinks, by adding the custom field tags to the permastructures.", "permalink-manager"));
43
+ $output .= wpautop(__("This functionality is also compatible with meta keys set with Advanced Custom Fields plugin.", "permalink-manager"));
44
+ $output .= "</div>";
45
+ /*$output .= "<div class=\"column-1_3\">";
46
+ $output .= sprintf("<h5>%s</h5>", __("Import permalinks from \"Custom Permalinks\"", "permalink-manager"));
47
+ $output .= wpautop(__("Additionally, Permalink Manager Pro allows to import the custom URIs defined previously with \"Custom Permalinks\" plugin. ", "permalink-manager"));
48
+ $output .= "</div>";*/
49
+ $output .= "<div class=\"column-1_3\">";
50
+ $output .= sprintf("<h5>%s</h5>", __("Remove \"stop words\" from permalinks", "permalink-manager"));
51
+ $output .= wpautop(__("Set your own list of stop words or use a predefined one available in 21 languages. If enabled, all the words will be automatically removed from the default permalinks.", "permalink-manager"));
52
  $output .= "</div>";
53
  $output .= "<div class=\"column-1_3\">";
54
+ $output .= sprintf("<h5>%s</h5>", __("First priority support", "permalink-manager"));
55
+ $output .= wpautop(__("All Permalink Manager Pro users have early to plugin updates and first priority for support tickets.", "permalink-manager"));
 
56
  $output .= "</div>";
57
  $output .= "</div>";
58
 
59
+ $output .= sprintf("<p><a class=\"button button-default margin-top\" href=\"%s\" target=\"_blank\">%s</a>&nbsp;&nbsp;<a class=\"button button-primary margin-top\" href=\"%s\" target=\"_blank\">%s</a></p>", PERMALINK_MANAGER_WEBSITE, __("More info about Permalink Manager Pro"), "https://gumroad.com/l/permalink-manager", __("Buy Permalink Manager Pro"));
60
 
61
  return $output;
62
  }
includes/views/permalink-manager-uri-editor-post.php CHANGED
@@ -76,7 +76,11 @@ class Permalink_Manager_URI_Editor_Post extends WP_List_Table {
76
  * Data inside the columns
77
  */
78
  public function column_default( $item, $column_name ) {
 
 
79
  $uri = Permalink_Manager_URI_Functions_Post::get_post_uri($item['ID'], true);
 
 
80
  $field_args_base = array('type' => 'text', 'value' => $uri, 'without_label' => true, 'input_class' => '');
81
  $permalink = get_permalink($item['ID']);
82
  $post_statuses_array = get_post_statuses();
@@ -87,13 +91,13 @@ class Permalink_Manager_URI_Editor_Post extends WP_List_Table {
87
  switch( $column_name ) {
88
  case 'item_uri':
89
  $output = Permalink_Manager_Admin_Functions::generate_option_field("uri[{$item['ID']}]", $field_args_base);
90
- $output .= "<a class=\"small post_permalink\" href=\"{$permalink}\" target=\"_blank\"><span class=\"dashicons dashicons-admin-links\"></span> {$permalink}</a>";
91
  return $output;
92
 
93
  case 'item_title':
94
  $output = $item[ 'post_title' ];
95
  $output .= '<div class="extra-info small">';
96
- $output .= sprintf("<span><strong>%s:</strong> {$item['post_name']}</span>", __("Slug", "permalink-manager"));
97
  $output .= sprintf(" | <span><strong>%s:</strong> {$post_statuses_array[$item["post_status"]]}</span>", __("Post status", "permalink-manager"));
98
  $output .= apply_filters('permalink-manager-uri-editor-extra-info', '', $column_name, get_post($item['ID']));
99
  $output .= '</div>';
76
  * Data inside the columns
77
  */
78
  public function column_default( $item, $column_name ) {
79
+ global $permalink_manager_options;
80
+
81
  $uri = Permalink_Manager_URI_Functions_Post::get_post_uri($item['ID'], true);
82
+ $uri = (!empty($permalink_manager_options['general']['decode_uris'])) ? urldecode($uri) : $uri;
83
+
84
  $field_args_base = array('type' => 'text', 'value' => $uri, 'without_label' => true, 'input_class' => '');
85
  $permalink = get_permalink($item['ID']);
86
  $post_statuses_array = get_post_statuses();
91
  switch( $column_name ) {
92
  case 'item_uri':
93
  $output = Permalink_Manager_Admin_Functions::generate_option_field("uri[{$item['ID']}]", $field_args_base);
94
+ $output .= sprintf("<a class=\"small post_permalink\" href=\"%s\" target=\"_blank\"><span class=\"dashicons dashicons-admin-links\"></span> %s</a>", $permalink, urldecode($permalink));
95
  return $output;
96
 
97
  case 'item_title':
98
  $output = $item[ 'post_title' ];
99
  $output .= '<div class="extra-info small">';
100
+ $output .= sprintf("<span><strong>%s:</strong> %s</span>", __("Slug", "permalink-manager"), urldecode($item['post_name']));
101
  $output .= sprintf(" | <span><strong>%s:</strong> {$post_statuses_array[$item["post_status"]]}</span>", __("Post status", "permalink-manager"));
102
  $output .= apply_filters('permalink-manager-uri-editor-extra-info', '', $column_name, get_post($item['ID']));
103
  $output .= '</div>';
out/permalink-manager-admin.css CHANGED
@@ -3,7 +3,7 @@
3
  */
4
  #permalink-manager #plugin-name-heading .author-link{color:#959595;font-size:60%;text-decoration:none}
5
  #permalink-manager #permalink-manager-tab-nav > a:first-child{margin-left:0}
6
- #permalink-manager #permalink-manager-tab-nav .section_upgrade{background:#555;border-color:#555;color:#fff}
7
  #permalink-manager h4{font-size:18px;margin-bottom:10px}
8
  #permalink-manager h5{font-size:15px;margin-bottom:10px}
9
  #permalink-manager .small{display:block;font-weight:400;color:#888;font-size:80%}
@@ -63,6 +63,7 @@
63
  #permalink-manager .field-description{font-size:12px}
64
  #permalink-manager .appended-row td{padding-left:0;padding-right:0}
65
  #permalink-manager #tools select{min-width:60%}
 
66
 
67
  #permalink-manager .structure-tags-list{display:block;line-height:175%}
68
  #permalink-manager .structure-tags-list code{}
@@ -75,6 +76,7 @@
75
  #permalink-manager .columns-container a{color:#aaa}
76
  #permalink-manager .columns-container .column-1_2,#permalink-manager .columns-container .column-2_4{width:50%}
77
  #permalink-manager .columns-container .column-1_3{width:33.33%}
 
78
  #permalink-manager .columns-container .column-2_3{width:66.67%}
79
  #permalink-manager .columns-container .column-1_4{width:25%}
80
  #permalink-manager .columns-container .column-3_4{width:75%}
@@ -118,7 +120,7 @@
118
  * Breakpoints
119
  */
120
  @media only screen and (min-width :992px) {
121
- #permalink-manager #permalink-manager-tab-nav .section_debug,#permalink-manager #permalink-manager-tab-nav .section_upgrade{float:right}
122
  #permalink-manager .permastruct-container{display:table;width:100%;table-layout:auto}
123
  #permalink-manager .permastruct-container > *{display:table-cell}
124
  #permalink-manager .permastruct-container > span:first-child{width:1%;white-space:nowrap}
3
  */
4
  #permalink-manager #plugin-name-heading .author-link{color:#959595;font-size:60%;text-decoration:none}
5
  #permalink-manager #permalink-manager-tab-nav > a:first-child{margin-left:0}
6
+ #permalink-manager #permalink-manager-tab-nav .section_upgrade,#permalink-manager #permalink-manager-tab-nav .section_support{background:#555;border-color:#555;color:#fff}
7
  #permalink-manager h4{font-size:18px;margin-bottom:10px}
8
  #permalink-manager h5{font-size:15px;margin-bottom:10px}
9
  #permalink-manager .small{display:block;font-weight:400;color:#888;font-size:80%}
63
  #permalink-manager .field-description{font-size:12px}
64
  #permalink-manager .appended-row td{padding-left:0;padding-right:0}
65
  #permalink-manager #tools select{min-width:60%}
66
+ #permalink-manager fieldset label{margin-bottom:0 !important}
67
 
68
  #permalink-manager .structure-tags-list{display:block;line-height:175%}
69
  #permalink-manager .structure-tags-list code{}
76
  #permalink-manager .columns-container a{color:#aaa}
77
  #permalink-manager .columns-container .column-1_2,#permalink-manager .columns-container .column-2_4{width:50%}
78
  #permalink-manager .columns-container .column-1_3{width:33.33%}
79
+ #permalink-manager .columns-container .column-1_3:nth-of-type(3n+1){clear:left}
80
  #permalink-manager .columns-container .column-2_3{width:66.67%}
81
  #permalink-manager .columns-container .column-1_4{width:25%}
82
  #permalink-manager .columns-container .column-3_4{width:75%}
120
  * Breakpoints
121
  */
122
  @media only screen and (min-width :992px) {
123
+ #permalink-manager #permalink-manager-tab-nav .section_debug,#permalink-manager #permalink-manager-tab-nav .section_upgrade,#permalink-manager #permalink-manager-tab-nav .section_support{float:right}
124
  #permalink-manager .permastruct-container{display:table;width:100%;table-layout:auto}
125
  #permalink-manager .permastruct-container > *{display:table-cell}
126
  #permalink-manager .permastruct-container > span:first-child{width:1%;white-space:nowrap}
out/permalink-manager-admin.js CHANGED
@@ -75,9 +75,9 @@ jQuery(document).ready(function() {
75
  var auto_update_status = jQuery(selected).data('auto-update');
76
 
77
  if(auto_update_status == 1) {
78
- jQuery(custom_uri_input).attr("disabled", true);
79
  } else {
80
- jQuery(custom_uri_input).removeAttr("disabled", true);
81
  }
82
  }).trigger("change");
83
 
75
  var auto_update_status = jQuery(selected).data('auto-update');
76
 
77
  if(auto_update_status == 1) {
78
+ jQuery(custom_uri_input).attr("readonly", true);
79
  } else {
80
+ jQuery(custom_uri_input).removeAttr("readonly", true);
81
  }
82
  }).trigger("change");
83
 
permalink-manager.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Permalink Manager Lite
5
  * Plugin URI: https://permalinkmanager.pro?utm_source=plugin
6
  * Description: Most advanced Permalink utility for Wordpress. It allows to bulk edit the permalinks & permastructures and regenerate/reset all the URIs in your Wordpress instance.
7
- * Version: 1.1.1
8
  * Author: Maciej Bis
9
  * Author URI: http://maciejbis.net/
10
  * License: GPL-2.0+
@@ -21,7 +21,7 @@ if (!defined('WPINC')) {
21
  // Define the directories used to load plugin files.
22
  define( 'PERMALINK_MANAGER_PLUGIN_NAME', 'Permalink Manager' );
23
  define( 'PERMALINK_MANAGER_PLUGIN_SLUG', 'permalink-manager' );
24
- define( 'PERMALINK_MANAGER_VERSION', '1.1.1' );
25
  define( 'PERMALINK_MANAGER_DIR', untrailingslashit( dirname( __FILE__ ) ) );
26
  define( 'PERMALINK_MANAGER_BASENAME', plugin_basename(__FILE__) );
27
  define( 'PERMALINK_MANAGER_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) );
@@ -58,6 +58,7 @@ class Permalink_Manager_Class {
58
  'admin-functions' => 'Permalink_Manager_Admin_Functions',
59
  'actions' => 'Permalink_Manager_Actions',
60
  'third-parties' => 'Permalink_Manager_Third_Parties',
 
61
  'pro-functions' => 'Permalink_Manager_Pro_Functions'
62
  ),
63
  'views' => array(
@@ -96,17 +97,9 @@ class Permalink_Manager_Class {
96
  // Load options
97
  add_action( 'init', array($this, 'get_options_and_globals'), 1 );
98
 
99
- // Use the URIs set in this plugin + redirect from old URIs to new URIs + adjust canonical redirect settings
100
- add_action( 'template_redirect', array($this, 'redirect_to_new_uri'), 999);
101
- add_filter( 'request', array($this, 'detect_post'), 0, 1 );
102
- add_action( 'parse_request', array($this, 'disable_canonical_redirect'), 0, 1 );
103
-
104
  // Legacy support
105
  add_action( 'init', array($this, 'legacy_support'), 2 );
106
 
107
- // Check for updates
108
- add_action( 'init', array($this, 'check_for_updates'), 999 );
109
-
110
  // Default settings & alerts
111
  add_filter( 'permalink-manager-options', array($this, 'default_settings'), 1 );
112
  add_filter( 'permalink-manager-alerts', array($this, 'default_alerts'), 1 );
@@ -154,13 +147,13 @@ class Permalink_Manager_Class {
154
  'force_custom_slugs' => 0,
155
  'auto_update_uris' => 0,
156
  'case_insensitive_permalinks' => 0,
157
- 'decode_uris' => 0
158
- ),
159
- 'miscellaneous' => array(
160
  'yoast_primary_term' => 1,
161
- 'redirect' => "302",
162
- 'canonical_redirect' => 1
163
- )
 
 
164
  ));
165
 
166
  // Apply the default settings (if empty values) in all settings sections
@@ -180,13 +173,15 @@ class Permalink_Manager_Class {
180
  */
181
  public function default_alerts($alerts) {
182
  $default_alerts = apply_filters('permalink-manager-default-alerts', array(
183
- 'july-2017' => array(
184
- 'txt' => sprintf(__("Need to change the permalinks for categories, tags, custom taxonomies or WooCommerce?<br /><strong>Buy Permalink Manager Pro <a href=\"%s\" target=\"_blank\">here</a> and save 20&#37; using \"SUMMER\" coupon code!</strong>", "permalink-manager"),
185
- PERMALINK_MANAGER_WEBSITE),
 
 
186
  'type' => 'notice-info',
187
  'show' => 'pro_hide',
188
  'plugin_only' => true,
189
- 'until' => '2017-09-01'
190
  )
191
  ));
192
 
@@ -194,240 +189,6 @@ class Permalink_Manager_Class {
194
  return $alerts + $default_alerts;
195
  }
196
 
197
- /**
198
- * Used to optimize SQL queries amount instead of rewrite rules - the essential part of this plugin
199
- */
200
- function detect_post($query) {
201
- global $wpdb, $permalink_manager_uris, $wp_filter, $permalink_manager_options;
202
-
203
- // Check if any custom URI is used
204
- if(!(is_array($permalink_manager_uris)) || empty($query)) return $query;
205
-
206
- // Used in debug mode
207
- $old_query = $query;
208
-
209
- /**
210
- * 1. Prepare URL and check if it is correct
211
- */
212
- $protocol = stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true ? 'https://' : 'http://';
213
- $request_url = "{$protocol}{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
214
- $home_url = trim(rtrim(get_option('home'), '/'));
215
- $home_url = ($protocol == 'https://') ? str_replace("http://", "https://", $home_url) : str_replace("https://", "http://", $home_url); // Adjust prefix (it should be the same in both request & home_url)
216
-
217
- if (filter_var($request_url, FILTER_VALIDATE_URL)) {
218
- /**
219
- * 1. Process URL & find the URI
220
- */
221
- // Remove .html suffix and domain name from URL and query (URLs ended with .html will work as aliases)
222
- $request_url = trim(str_replace($home_url, "", $request_url), "/");
223
-
224
- // Remove querystrings from URI
225
- $request_url = strtok($request_url, '?');
226
-
227
- // Use default REGEX to detect post
228
- preg_match("/^(.+?)\/?(page|feed|embed|attachment|track)?(?:\/([\d+]))?\/?$/i", $request_url, $regex_parts);
229
- $uri_parts['lang'] = false;
230
- $uri_parts['uri'] = (!empty($regex_parts[1])) ? $regex_parts[1] : "";
231
- $uri_parts['endpoint'] = (!empty($regex_parts[2])) ? $regex_parts[2] : "";
232
- $uri_parts['endpoint_value'] = (!empty($regex_parts[3])) ? $regex_parts[3] : "";
233
-
234
- // Allow to filter the results by third-parties
235
- $uri_parts = apply_filters('permalink-manager-detect-uri', $uri_parts, $request_url);
236
-
237
- // Stop the function if $uri_parts is empty
238
- if(empty($uri_parts)) return $query;
239
-
240
- // Get the URI parts from REGEX parts
241
- $lang = $uri_parts['lang'];
242
- $uri = $uri_parts['uri'];
243
- $endpoint = $uri_parts['endpoint'];
244
- $endpoint_value = $uri_parts['endpoint_value'];
245
-
246
- // Trim slashes
247
- $uri = trim($uri, "/");
248
-
249
- // Decode both Request URI & URIs array
250
- $uri = urldecode($uri);
251
- foreach ($permalink_manager_uris as $key => $value) {
252
- $permalink_manager_uris[$key] = urldecode($value);
253
- }
254
-
255
- // Ignore URLs with no URI grabbed
256
- if(empty($uri)) return $query;
257
-
258
- /**
259
- * 2. Check if found URI matches any element from custom uris array
260
- */
261
- $item_id = array_search($uri, $permalink_manager_uris);
262
-
263
- // Check again in case someone added .html suffix to particular post (with .html suffix)
264
- $item_id = (empty($item_id)) ? array_search("{$uri}.html", $permalink_manager_uris) : $item_id;
265
-
266
- // Check again in case someone used post/tax IDs instead of slugs
267
- $deep_detect_enabled = apply_filters('permalink-manager-deep-uri-detect', false);
268
- if($deep_detect_enabled && (empty($item_id)) && isset($old_query['page'])) {
269
- $item_id = array_search("{$uri}/{$endpoint_value}", $permalink_manager_uris);
270
- $endpoint_value = $endpoint = "";
271
- }
272
-
273
- // Allow to filter the item_id by third-parties after initial detection
274
- $item_id = apply_filters('permalink-manager-detected-initial-id', $item_id, $uri_parts, $request_url);
275
-
276
- // Clear the original query before it is filtered
277
- $query = ($item_id) ? array() : $query;
278
-
279
- /**
280
- * 3A. Custom URI assigned to taxonomy
281
- */
282
- if(strpos($item_id, 'tax-') !== false) {
283
- // Remove the "tax-" prefix
284
- $item_id = preg_replace("/[^0-9]/", "", $item_id);
285
-
286
- // Filter detected post ID
287
- $item_id = apply_filters('permalink-manager-detected-term-id', intval($item_id), $uri_parts, true);
288
-
289
- // Get the variables to filter wp_query and double-check if tax exists
290
- $term = get_term(intval($item_id));
291
- if(empty($term->taxonomy)) { return $query; }
292
-
293
- // Get some term data
294
- $query_parameter = ($term->taxonomy == 'category') ? 'category_name' : $term->taxonomy;
295
- $term_ancestors = get_ancestors($item_id, $term->taxonomy);
296
- $final_uri = $term->slug;
297
-
298
- // Fix for hierarchical CPT & pages
299
- if(empty($term_ancestors)) {
300
- foreach ($term_ancestors as $parent) {
301
- $parent = get_term($parent, $term->taxonomy);
302
- if(!empty($parent->slug)) {
303
- $final_uri = $parent->slug . '/' . $final_uri;
304
- }
305
- }
306
- }
307
-
308
- // Make the redirects more clever - see redirect_to_new_uri() method
309
- $query['do_not_redirect'] = 1;
310
- $query[$query_parameter] = $final_uri;
311
- }
312
- /**
313
- * 3B. Custom URI assigned to post/page/cpt item
314
- */
315
- else if(isset($item_id) && is_numeric($item_id)) {
316
- // Fix for revisions
317
- $is_revision = wp_is_post_revision($item_id);
318
- $item_id = ($is_revision) ? $is_revision : $item_id;
319
-
320
- // Filter detected post ID
321
- $item_id = apply_filters('permalink-manager-detected-post-id', $item_id, $uri_parts);
322
-
323
- $post_to_load = get_post($item_id);
324
- $final_uri = $post_to_load->post_name;
325
- $post_type = $post_to_load->post_type;
326
-
327
- // Fix for hierarchical CPT & pages
328
- if(!(empty($post_to_load->ancestors))) {
329
- foreach ($post_to_load->ancestors as $parent) {
330
- $parent = get_post( $parent );
331
- if($parent && $parent->post_name) {
332
- $final_uri = $parent->post_name . '/' . $final_uri;
333
- }
334
- }
335
- }
336
-
337
- // Alter query parameters
338
- if($post_to_load->post_type == 'page') {
339
- $query['pagename'] = $final_uri;
340
- } else if($post_to_load->post_type == 'post') {
341
- $query['name'] = $final_uri;
342
- } else if($post_to_load->post_type == 'attachment') {
343
- $query['attachment'] = $final_uri;
344
- } else {
345
- $query['name'] = $final_uri;
346
- $query['post_type'] = $post_type;
347
- $query[$post_type] = $final_uri;
348
- }
349
-
350
- // Make the redirects more clever - see redirect_to_new_uri() method
351
- $query['do_not_redirect'] = 1;
352
- }
353
-
354
- /**
355
- * 2C. Endpoints
356
- */
357
- if($item_id && !(empty($endpoint_value))) {
358
- $endpoint = ($endpoint) ? str_replace(array('page', 'trackback'), array('paged', 'tb'), $endpoint) : "page";
359
- $query[$endpoint] = $endpoint_value;
360
- }
361
-
362
- }
363
-
364
- // Debug mode
365
- if(isset($_REQUEST['debug_url'])) {
366
- $debug_info['old_query_vars'] = $old_query;
367
- $debug_info['new_query_vars'] = $query;
368
-
369
- $debug_txt = json_encode($debug_info);
370
- $debug_txt = "<textarea style=\"width:100%;height:300px\">{$debug_txt}</textarea>";
371
- wp_die($debug_txt);
372
- }
373
-
374
- return $query;
375
- }
376
-
377
- function redirect_to_new_uri() {
378
- global $wp_query, $permalink_manager_uris, $permalink_manager_options;
379
-
380
- // Sometimes $wp_query indicates the wrong object if requested directly
381
- $queried_object = get_queried_object();
382
-
383
- if(!empty($permalink_manager_options['miscellaneous']['redirect']) && !empty($queried_object)) {
384
-
385
- // Affect only posts with custom URI and old URIs
386
- if(!empty($queried_object->ID) && isset($permalink_manager_uris[$queried_object->ID]) && empty($wp_query->query['do_not_redirect']) && empty($wp_query->query['preview'])) {
387
- // Ignore posts with specific statuses
388
- if(!(empty($queried_object->post_status)) && in_array($queried_object->post_status, array('draft', 'pending', 'auto-draft', 'future'))) {
389
- return '';
390
- }
391
-
392
- // Get the real URL
393
- $correct_permalink = get_permalink($queried_object->ID);
394
- }
395
- // Affect only terms with custom URI and old URIs
396
- else if(!empty($queried_object->term_id) && isset($permalink_manager_uris["tax-{$queried_object->term_id}"]) && empty($wp_query->query['do_not_redirect'])) {
397
- // Get the real URL
398
- $correct_permalink = get_term_link($queried_object->term_id, $queried_object->taxonomy);
399
- }
400
-
401
- // Get the redirection mode
402
- $redirect_mode = $permalink_manager_options['miscellaneous']['redirect'];
403
-
404
- // Ignore default URIs (or do nothing if redirects are disabled)
405
- if(!empty($correct_permalink) && !empty($redirect_mode)) {
406
- wp_safe_redirect($correct_permalink, $redirect_mode);
407
- exit();
408
- }
409
- }
410
- }
411
-
412
- function disable_canonical_redirect() {
413
- global $permalink_manager_options, $wp_filter;
414
- if(!($permalink_manager_options['miscellaneous']['canonical_redirect'])) {
415
- remove_action('template_redirect', 'redirect_canonical');
416
- add_filter('wpml_is_redirected', '__return_false', 99, 2);
417
- }
418
- }
419
-
420
- function decode_uris_array($uris) {
421
- if(!is_array($uris)) { return $uris; }
422
-
423
- foreach ($uris as $key => $value) {
424
- if(preg_match('/[^\x20-\x7f]/', $value)) {
425
- $uris[$key] = implode('/', array_map('rawurlencode', explode('/', $value)));
426
- }
427
- }
428
- return $uris;
429
- }
430
-
431
  /**
432
  * Temporary hook
433
  */
@@ -442,28 +203,26 @@ class Permalink_Manager_Class {
442
  $new_options['post_types'] = $permalink_manager_permastructs;
443
  update_option('permalink-manager-permastructs', $new_options);
444
  }
445
- }
446
 
447
- /**
448
- * Update check
449
- */
450
- public function check_for_updates() {
451
- global $permalink_manager_options;
452
 
453
- if(defined('PERMALINK_MANAGER_PRO')) {
454
- // Get the licence key
455
- $license_key = (!empty($permalink_manager_options['miscellaneous']['license_key'])) ? $permalink_manager_options['miscellaneous']['license_key'] : "";
456
 
457
- // Load Plugin Update Checker by YahnisElsts
458
- require_once PERMALINK_MANAGER_DIR . '/includes/ext/plugin-update-checker/plugin-update-checker.php';
459
 
460
- $UpdateChecker = Puc_v4_Factory::buildUpdateChecker(
461
- "https://updates.permalinkmanager.pro/?action=get_metadata&slug=permalink-manager-pro&license_key={$license_key}",
462
- __FILE__,
463
- "permalink-manager-pro"
464
- );
465
 
466
- $file = PERMALINK_MANAGER_BASENAME;
 
467
  }
468
  }
469
 
4
  * Plugin Name: Permalink Manager Lite
5
  * Plugin URI: https://permalinkmanager.pro?utm_source=plugin
6
  * Description: Most advanced Permalink utility for Wordpress. It allows to bulk edit the permalinks & permastructures and regenerate/reset all the URIs in your Wordpress instance.
7
+ * Version: 1.1.2
8
  * Author: Maciej Bis
9
  * Author URI: http://maciejbis.net/
10
  * License: GPL-2.0+
21
  // Define the directories used to load plugin files.
22
  define( 'PERMALINK_MANAGER_PLUGIN_NAME', 'Permalink Manager' );
23
  define( 'PERMALINK_MANAGER_PLUGIN_SLUG', 'permalink-manager' );
24
+ define( 'PERMALINK_MANAGER_VERSION', '1.1.2' );
25
  define( 'PERMALINK_MANAGER_DIR', untrailingslashit( dirname( __FILE__ ) ) );
26
  define( 'PERMALINK_MANAGER_BASENAME', plugin_basename(__FILE__) );
27
  define( 'PERMALINK_MANAGER_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) );
58
  'admin-functions' => 'Permalink_Manager_Admin_Functions',
59
  'actions' => 'Permalink_Manager_Actions',
60
  'third-parties' => 'Permalink_Manager_Third_Parties',
61
+ 'core-functions' => 'Permalink_Manager_Core_Functions',
62
  'pro-functions' => 'Permalink_Manager_Pro_Functions'
63
  ),
64
  'views' => array(
97
  // Load options
98
  add_action( 'init', array($this, 'get_options_and_globals'), 1 );
99
 
 
 
 
 
 
100
  // Legacy support
101
  add_action( 'init', array($this, 'legacy_support'), 2 );
102
 
 
 
 
103
  // Default settings & alerts
104
  add_filter( 'permalink-manager-options', array($this, 'default_settings'), 1 );
105
  add_filter( 'permalink-manager-alerts', array($this, 'default_alerts'), 1 );
147
  'force_custom_slugs' => 0,
148
  'auto_update_uris' => 0,
149
  'case_insensitive_permalinks' => 0,
150
+ 'decode_uris' => 0,
 
 
151
  'yoast_primary_term' => 1,
152
+ 'redirect' => '302',
153
+ 'canonical_redirect' => 1,
154
+ 'trailing_slashes' => 0
155
+ ),
156
+ 'licence' => array()
157
  ));
158
 
159
  // Apply the default settings (if empty values) in all settings sections
173
  */
174
  public function default_alerts($alerts) {
175
  $default_alerts = apply_filters('permalink-manager-default-alerts', array(
176
+ 'summer-promo' => array(
177
+ 'txt' => sprintf(
178
+ __("Get access to extra features: full taxonomy and WooCommerce support, possibility to use custom fields inside the permalinks and more!<br /><strong>Buy Permalink Manager Pro <a href=\"%s\" target=\"_blank\">here</a> and save 30&#37; using \"SUMMER\" coupon code (valid until 2017-08-01)!</strong>", "permalink-manager"),
179
+ PERMALINK_MANAGER_WEBSITE
180
+ ),
181
  'type' => 'notice-info',
182
  'show' => 'pro_hide',
183
  'plugin_only' => true,
184
+ 'until' => '2017-08-01'
185
  )
186
  ));
187
 
189
  return $alerts + $default_alerts;
190
  }
191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  /**
193
  * Temporary hook
194
  */
203
  $new_options['post_types'] = $permalink_manager_permastructs;
204
  update_option('permalink-manager-permastructs', $new_options);
205
  }
 
206
 
207
+ // Adjust options structure
208
+ if(!empty($permalink_manager_options['miscellaneous'])) {
209
+ // Get the options direclty from database
210
+ $permalink_manager_unfiltered_options = get_option('permalink-manager', array('general' => array(), 'miscellaneous' => array(), 'licence'));
 
211
 
212
+ // Combine general & general
213
+ $permalink_manager_unfiltered_options['general'] = array_merge($permalink_manager_unfiltered_options['general'], $permalink_manager_unfiltered_options['miscellaneous']);
 
214
 
215
+ // Move licence key to different section
216
+ $permalink_manager_unfiltered_options['licence']['licence_key'] = (!empty($permalink_manager_unfiltered_options['miscellaneous']['license_key'])) ? $permalink_manager_unfiltered_options['miscellaneous']['license_key'] : "";
217
 
218
+ // Remove redundant keys
219
+ unset($permalink_manager_unfiltered_options['general']['license_key']);
220
+ unset($permalink_manager_unfiltered_options['miscellaneous']);
221
+ unset($permalink_manager_unfiltered_options['permalink_manager_options']);
222
+ unset($permalink_manager_unfiltered_options['_wp_http_referer']);
223
 
224
+ // Save the settings in database
225
+ update_option('permalink-manager', $permalink_manager_unfiltered_options);
226
  }
227
  }
228