Permalink Manager Lite - Version 2.0.4.3

Version Description

  • Hotfix for problem with custom URIs for new terms & posts
Download this release

Release Info

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

Code changes from version 2.0.3 to 2.0.4.3

README.txt CHANGED
@@ -6,7 +6,7 @@ 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: 2.0.3
10
 
11
  Most advanced yet easy-to-use permalink plugin that helps to maintain & bulk change your URLs & slugs.
12
 
@@ -97,6 +97,19 @@ A. Currently there is no 100% guarantee that Permalink Manager will work correct
97
 
98
  == Changelog ==
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  = 2.0.3 =
101
  * Custom URI editor in "Quick Edit"
102
  * "Quick/Bulk Edit" hotfix
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: 2.0.4.3
10
 
11
  Most advanced yet easy-to-use permalink plugin that helps to maintain & bulk change your URLs & slugs.
12
 
97
 
98
  == Changelog ==
99
 
100
+ = 2.0.4.3 =
101
+ * Hotfix for problem with custom URIs for new terms & posts
102
+
103
+ = 2.0.4.1 =
104
+ * Hotfix for Elementor and another visual editor plugins
105
+ * Support for endpoints parsed as $_GET parameters
106
+
107
+ = 2.0.4 =
108
+ * New settings field - "Deep detect"
109
+
110
+ = 2.0.3.1 =
111
+ * Fix for Custom Fields tag in permastructures
112
+
113
  = 2.0.3 =
114
  * Custom URI editor in "Quick Edit"
115
  * "Quick/Bulk Edit" hotfix
includes/core/permalink-manager-core-functions.php CHANGED
@@ -20,23 +20,24 @@ class Permalink_Manager_Core_Functions extends Permalink_Manager_Class {
20
 
21
  // Redirects
22
  add_filter( 'redirect_canonical', array($this, 'fix_canonical_redirect'), 9, 2);
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, $pm_item_id;
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
  /**
@@ -51,6 +52,10 @@ class Permalink_Manager_Core_Functions extends Permalink_Manager_Class {
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
 
@@ -100,8 +105,8 @@ class Permalink_Manager_Core_Functions extends Permalink_Manager_Class {
100
  $item_id = (empty($item_id)) ? array_search("{$uri}.html", $permalink_manager_uris) : $item_id;
101
 
102
  // Check again in case someone used post/tax IDs instead of slugs
103
- $deep_detect_enabled = apply_filters('permalink-manager-deep-uri-detect', false);
104
  if($deep_detect_enabled && isset($old_query['page'])) {
 
105
  $new_item_id = array_search("{$uri}/{$endpoint_value}", $permalink_manager_uris);
106
  if($new_item_id) {
107
  $item_id = $new_item_id;
@@ -196,6 +201,8 @@ class Permalink_Manager_Core_Functions extends Permalink_Manager_Class {
196
  $query['do_not_redirect'] = 1;
197
  }
198
 
 
 
199
  /**
200
  * 2C. Endpoints
201
  */
@@ -211,6 +218,22 @@ class Permalink_Manager_Core_Functions extends Permalink_Manager_Class {
211
  }
212
  }
213
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  /**
215
  * Global with detected item id
216
  */
@@ -255,8 +278,8 @@ class Permalink_Manager_Core_Functions extends Permalink_Manager_Class {
255
  function redirect_to_new_uri() {
256
  global $wp_query, $permalink_manager_uris, $permalink_manager_redirects, $permalink_manager_options, $wp;
257
 
258
- // Do not redirect on author pages
259
- if(is_author()) { return false; }
260
 
261
  // Sometimes $wp_query indicates the wrong object if requested directly
262
  $queried_object = get_queried_object();
@@ -352,6 +375,31 @@ class Permalink_Manager_Core_Functions extends Permalink_Manager_Class {
352
  }
353
  }
354
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
  /**
356
  * Detect duplicates
357
  */
20
 
21
  // Redirects
22
  add_filter( 'redirect_canonical', array($this, 'fix_canonical_redirect'), 9, 2);
23
+ add_action( 'template_redirect', array($this, 'redirect_to_new_uri'), 0);
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
+ add_action( 'template_redirect', array($this, 'fix_pagination_pages'), 0);
29
  }
30
 
31
  /**
32
  * The most important Permalink Manager function
33
  */
34
  function detect_post($query) {
35
+ global $wpdb, $wp, $permalink_manager_uris, $wp_filter, $permalink_manager_options, $pm_item_id;
36
 
37
  // Check if any custom URI is used
38
  if(!(is_array($permalink_manager_uris)) || empty($query)) return $query;
39
 
40
+ // Used in debug mode & endpoints
41
  $old_query = $query;
42
 
43
  /**
52
  /**
53
  * 1. Process URL & find the URI
54
  */
55
+
56
+ // Check if Deep Detect is enabled
57
+ $deep_detect_enabled = apply_filters('permalink-manager-deep-uri-detect', $permalink_manager_options['general']['deep_detect']);
58
+
59
  // Remove .html suffix and domain name from URL and query (URLs ended with .html will work as aliases)
60
  $request_url = trim(str_replace($home_url, "", $request_url), "/");
61
 
105
  $item_id = (empty($item_id)) ? array_search("{$uri}.html", $permalink_manager_uris) : $item_id;
106
 
107
  // Check again in case someone used post/tax IDs instead of slugs
 
108
  if($deep_detect_enabled && isset($old_query['page'])) {
109
+
110
  $new_item_id = array_search("{$uri}/{$endpoint_value}", $permalink_manager_uris);
111
  if($new_item_id) {
112
  $item_id = $new_item_id;
201
  $query['do_not_redirect'] = 1;
202
  }
203
 
204
+
205
+
206
  /**
207
  * 2C. Endpoints
208
  */
218
  }
219
  }
220
 
221
+ /**
222
+ * 2D Endpoints - check if any endpoint is set with $_GET parameter
223
+ */
224
+ if($deep_detect_enabled && !empty($_GET)) {
225
+ $get_endpoints = array_intersect($wp->public_query_vars, array_keys($_GET));
226
+
227
+ if(!empty($get_endpoints)) {
228
+ // Append query vars from $_GET parameters
229
+ foreach($get_endpoints as $endpoint) {
230
+ // Numeric endpoints
231
+ $endpoint_value = (in_array($endpoint, array('page', 'paged', 'attachment_id'))) ? filter_var($_GET[$endpoint], FILTER_SANITIZE_NUMBER_INT) : $_GET[$endpoint];
232
+ $query[$endpoint] = sanitize_text_field($endpoint_value);
233
+ }
234
+ }
235
+ }
236
+
237
  /**
238
  * Global with detected item id
239
  */
278
  function redirect_to_new_uri() {
279
  global $wp_query, $permalink_manager_uris, $permalink_manager_redirects, $permalink_manager_options, $wp;
280
 
281
+ // Do not redirect on author pages & front page
282
+ if(is_author() || is_front_page() || is_home()) { return false; }
283
 
284
  // Sometimes $wp_query indicates the wrong object if requested directly
285
  $queried_object = get_queried_object();
375
  }
376
  }
377
 
378
+ /**
379
+ * Display 404 if requested page does not exist in pagination
380
+ */
381
+ function fix_pagination_pages() {
382
+ global $wp_query;
383
+
384
+ // 1. Get the post object
385
+ $post = get_queried_object();
386
+
387
+ // 2. Check if post object is defined
388
+ if(empty($post->ID)) { return; }
389
+
390
+ // 3. Check if pagination is detected
391
+ if(empty($wp_query->query_vars['page'])) { return; }
392
+
393
+ // 4. Count post pages
394
+ $num_pages = substr_count(strtolower($post->post_content), '<!--nextpage-->') + 1;
395
+ if($wp_query->query_vars['page'] > $num_pages) {
396
+ $wp_query->set('p', null);
397
+ $wp_query->set('pagename', null);
398
+ $wp_query->set('page_id', null);
399
+ $wp_query->set_404();
400
+ }
401
+ }
402
+
403
  /**
404
  * Detect duplicates
405
  */
includes/core/permalink-manager-third-parties.php CHANGED
@@ -83,13 +83,18 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
83
  }
84
 
85
  function wpml_detect_post($uri_parts, $request_url, $endpoints) {
86
- //preg_match("/^(?:(\w{2})\/)?(.+?)(?:\/({$endpoints}))?(?:\/([\d+]))?\/?$/i", $request_url, $regex_parts);
87
- preg_match("/^(?:(\w{2})\/)?(.+?)(?:\/({$endpoints}))?(?:\/([\d]+))?\/?$/i", $request_url, $regex_parts);
 
 
 
 
88
 
89
- $uri_parts['lang'] = (!empty($regex_parts[1])) ? $regex_parts[1] : "";
90
- $uri_parts['uri'] = (!empty($regex_parts[2])) ? $regex_parts[2] : "";
91
- $uri_parts['endpoint'] = (!empty($regex_parts[3])) ? $regex_parts[3] : "";
92
- $uri_parts['endpoint_value'] = (!empty($regex_parts[4])) ? $regex_parts[4] : "";
 
93
 
94
  return $uri_parts;
95
  }
83
  }
84
 
85
  function wpml_detect_post($uri_parts, $request_url, $endpoints) {
86
+ global $sitepress_settings;
87
+
88
+ if(!empty($sitepress_settings['active_languages'])) {
89
+ $languages_list = implode("|", $sitepress_settings['active_languages']);
90
+ //preg_match("/^(?:(\w{2})\/)?(.+?)(?:\/({$endpoints}))?(?:\/([\d+]))?\/?$/i", $request_url, $regex_parts);
91
+ preg_match("/^(?:({$languages_list})\/)?(.+?)(?:\/({$endpoints}))?(?:\/([\d]+))?\/?$/i", $request_url, $regex_parts);
92
 
93
+ $uri_parts['lang'] = (!empty($regex_parts[1])) ? $regex_parts[1] : "";
94
+ $uri_parts['uri'] = (!empty($regex_parts[2])) ? $regex_parts[2] : "";
95
+ $uri_parts['endpoint'] = (!empty($regex_parts[3])) ? $regex_parts[3] : "";
96
+ $uri_parts['endpoint_value'] = (!empty($regex_parts[4])) ? $regex_parts[4] : "";
97
+ }
98
 
99
  return $uri_parts;
100
  }
includes/core/permalink-manager-uri-functions-post.php CHANGED
@@ -163,13 +163,13 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
163
  $post_type_tag = Permalink_Manager_Helper_Functions::get_post_tag($post_type);
164
 
165
  // 3A. Do the replacement (post tag is removed now to enable support for hierarchical CPT)
166
- $tags = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', '%post_id%', '%author%', $post_type_tag, '%postname%');
167
 
168
  if($dont_append_slug) {
169
- $replacements = array($date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->ID, $author, $full_slug, $full_slug);
170
  $default_uri = str_replace($tags, $replacements, "{$default_base}");
171
  } else {
172
- $replacements = array($date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->ID, $author, '', '');
173
  $default_uri = str_replace($tags, $replacements, "{$default_base}/{$full_slug}");
174
  }
175
 
@@ -587,19 +587,19 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
587
  // Hotfix
588
  if(isset($_POST['custom_uri']) || isset($_POST['permalink-manager-quick-edit'])) { return $post_id; }
589
 
590
- // Continue only if no custom URI is already assigned
591
- if(!empty($permalink_manager_uris[$post_id])) { return $post_id; }
592
-
593
  // Fix for revisions
594
  $is_revision = wp_is_post_revision($post_id);
595
  $post_id = ($is_revision) ? $is_revision : $post_id;
596
  $post = get_post($post_id);
597
 
598
- // Hotfix for menu items
599
- if($post->post_type == 'nav_menu_item') { return; }
 
 
 
600
 
601
  $native_uri = self::get_default_post_uri($post_id, true);
602
- $new_uri = self::get_default_post_uri($post_id);;
603
  $permalink_manager_uris[$post->ID] = $new_uri;
604
 
605
  update_option('permalink-manager-uris', $permalink_manager_uris);
163
  $post_type_tag = Permalink_Manager_Helper_Functions::get_post_tag($post_type);
164
 
165
  // 3A. Do the replacement (post tag is removed now to enable support for hierarchical CPT)
166
+ $tags = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', '%post_id%', '%author%', $post_type_tag, '%postname%', '%postname_flat%');
167
 
168
  if($dont_append_slug) {
169
+ $replacements = array($date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->ID, $author, $full_slug, $full_slug, $post_name);
170
  $default_uri = str_replace($tags, $replacements, "{$default_base}");
171
  } else {
172
+ $replacements = array($date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->ID, $author, '', '', '');
173
  $default_uri = str_replace($tags, $replacements, "{$default_base}/{$full_slug}");
174
  }
175
 
587
  // Hotfix
588
  if(isset($_POST['custom_uri']) || isset($_POST['permalink-manager-quick-edit'])) { return $post_id; }
589
 
 
 
 
590
  // Fix for revisions
591
  $is_revision = wp_is_post_revision($post_id);
592
  $post_id = ($is_revision) ? $is_revision : $post_id;
593
  $post = get_post($post_id);
594
 
595
+ // Continue only if no custom URI is already assigned
596
+ if(!empty($permalink_manager_uris[$post_id])) { return $post_id; }
597
+
598
+ // Hotfix for menu items & auto-drafts
599
+ if($post->post_type == 'nav_menu_item' || $post->post_status == 'auto-draft') { return $post_id; }
600
 
601
  $native_uri = self::get_default_post_uri($post_id, true);
602
+ $new_uri = self::get_default_post_uri($post_id);
603
  $permalink_manager_uris[$post->ID] = $new_uri;
604
 
605
  update_option('permalink-manager-uris', $permalink_manager_uris);
includes/views/permalink-manager-settings.php CHANGED
@@ -55,7 +55,7 @@ class Permalink_Manager_Settings extends Permalink_Manager_Class {
55
  'fields' => array(
56
  'yoast_primary_term' => array(
57
  'type' => 'single_checkbox',
58
- 'label' => __('Primay term/category support', 'permalink-manager'),
59
  'input_class' => '',
60
  'description' => __('Used to generate default permalinks in pages, posts & custom post types. Works only when "Yoast SEO" plugin is enabled.', 'permalink-manager')
61
  ),
@@ -63,7 +63,7 @@ class Permalink_Manager_Settings extends Permalink_Manager_Class {
63
  'type' => 'single_checkbox',
64
  'label' => __('Attachment redirect support', 'permalink-manager'),
65
  'input_class' => '',
66
- 'description' => __('Support for redirect attachment URLs to parent post URL. Works only when "Yoast SEO Premium" plugin is enabled.', 'permalink-manager')
67
  ),
68
  'canonical_redirect' => array(
69
  'type' => 'single_checkbox',
@@ -111,6 +111,11 @@ class Permalink_Manager_Settings extends Permalink_Manager_Class {
111
  'choices' => $content_types,
112
  'description' => __('The slugs will not be automatically apended to the end of permastructure in the default permalinks for selected post types & taxonomies.<br />Works correctly only if <strong>"Force custom slugs" is disabled!</strong>', 'permalink-manager')
113
  ),
 
 
 
 
 
114
  'decode_uris' => array(
115
  'type' => 'single_checkbox',
116
  'label' => __('Decode URIs', 'permalink-manager'),
55
  'fields' => array(
56
  'yoast_primary_term' => array(
57
  'type' => 'single_checkbox',
58
+ 'label' => __('Primary term/category support', 'permalink-manager'),
59
  'input_class' => '',
60
  'description' => __('Used to generate default permalinks in pages, posts & custom post types. Works only when "Yoast SEO" plugin is enabled.', 'permalink-manager')
61
  ),
63
  'type' => 'single_checkbox',
64
  'label' => __('Attachment redirect support', 'permalink-manager'),
65
  'input_class' => '',
66
+ 'description' => __('Redirect attachment URLs to their parent posts. Works only when "Yoast SEO Premium" plugin is enabled.', 'permalink-manager')
67
  ),
68
  'canonical_redirect' => array(
69
  'type' => 'single_checkbox',
111
  'choices' => $content_types,
112
  'description' => __('The slugs will not be automatically apended to the end of permastructure in the default permalinks for selected post types & taxonomies.<br />Works correctly only if <strong>"Force custom slugs" is disabled!</strong>', 'permalink-manager')
113
  ),
114
+ 'deep_detect' => array(
115
+ 'type' => 'single_checkbox',
116
+ 'label' => __('Enable "Deep detect"', 'permalink-manager'),
117
+ 'description' => __('Please keep it enabled if your custom URIs end with numerals, e.g. <strong>example.com/projects/20171025</strong> or if $_GET parameters should be detected as endpoints e.g. <strong>?page=1</strong>.', 'permalink-manager')
118
+ ),
119
  'decode_uris' => array(
120
  'type' => 'single_checkbox',
121
  'label' => __('Decode URIs', 'permalink-manager'),
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: 2.0.3
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', '2.0.3' );
25
  define( 'PERMALINK_MANAGER_FILE', __FILE__ );
26
  define( 'PERMALINK_MANAGER_DIR', untrailingslashit( dirname( __FILE__ ) ) );
27
  define( 'PERMALINK_MANAGER_BASENAME', plugin_basename(__FILE__) );
@@ -158,7 +158,8 @@ class Permalink_Manager_Class {
158
  'trailing_slashes' => 0,
159
  'setup_redirects' => 0,
160
  'auto_remove_duplicates' => 0,
161
- 'disable_slug_appendix' => array()
 
162
  ),
163
  'licence' => array()
164
  ));
@@ -180,15 +181,15 @@ class Permalink_Manager_Class {
180
  */
181
  public function default_alerts($alerts) {
182
  $default_alerts = apply_filters('permalink-manager-default-alerts', array(
183
- 'september' => array(
184
  'txt' => sprintf(
185
- __("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 20&#37; using \"SUMMER\" coupon code!</strong>", "permalink-manager"),
186
  PERMALINK_MANAGER_WEBSITE
187
  ),
188
  'type' => 'notice-info',
189
  'show' => 'pro_hide',
190
  'plugin_only' => true,
191
- 'until' => '2017-09-10'
192
  )
193
  ));
194
 
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: 2.0.4.3
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', '2.0.4.3' );
25
  define( 'PERMALINK_MANAGER_FILE', __FILE__ );
26
  define( 'PERMALINK_MANAGER_DIR', untrailingslashit( dirname( __FILE__ ) ) );
27
  define( 'PERMALINK_MANAGER_BASENAME', plugin_basename(__FILE__) );
158
  'trailing_slashes' => 0,
159
  'setup_redirects' => 0,
160
  'auto_remove_duplicates' => 0,
161
+ 'disable_slug_appendix' => array(),
162
+ 'deep_detect' => 1
163
  ),
164
  'licence' => array()
165
  ));
181
  */
182
  public function default_alerts($alerts) {
183
  $default_alerts = apply_filters('permalink-manager-default-alerts', array(
184
+ 'october' => array(
185
  'txt' => sprintf(
186
+ __("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 20&#37; using \"OCTOBER\" coupon code!</strong> Valid until 31.10!", "permalink-manager"),
187
  PERMALINK_MANAGER_WEBSITE
188
  ),
189
  'type' => 'notice-info',
190
  'show' => 'pro_hide',
191
  'plugin_only' => true,
192
+ 'until' => '2017-10-31'
193
  )
194
  ));
195