Permalink Manager Lite - Version 1.0.1

Version Description

  • Small bugs fixed
Download this release

Release Info

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

Code changes from version 1.0.0 to 1.0.1

README.txt CHANGED
@@ -5,7 +5,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.html
5
  Tags: urls, permalinks, slugs, custom url, custom permalinks, uris, url, slug, permalink
6
  Requires at least: 4.0
7
  Tested up to: 4.7.3
8
- Stable tag: 1.0.0
9
 
10
  Most advanced yet easy-to-use permalink plugin that helps to maintain & bulk change your URLs & slugs.
11
 
@@ -76,6 +76,9 @@ After the plugin is installed you can access its dashboard from this page: `Tool
76
 
77
  == Changelog ==
78
 
 
 
 
79
  = 1.0.0 =
80
  * Further refactoring
81
  * WPML support added
5
  Tags: urls, permalinks, slugs, custom url, custom permalinks, uris, url, slug, permalink
6
  Requires at least: 4.0
7
  Tested up to: 4.7.3
8
+ Stable tag: 1.0.1
9
 
10
  Most advanced yet easy-to-use permalink plugin that helps to maintain & bulk change your URLs & slugs.
11
 
76
 
77
  == Changelog ==
78
 
79
+ = 1.0.1 =
80
+ * Small bugs fixed
81
+
82
  = 1.0.0 =
83
  * Further refactoring
84
  * WPML support added
includes/core/permalink-manager-admin-functions.php CHANGED
@@ -207,7 +207,7 @@ class Permalink_Manager_Admin_Functions extends Permalink_Manager_Class {
207
  return "<div class=\"clearfix\"></div>";
208
 
209
  case 'permastruct' :
210
- $siteurl = get_bloginfo('wpurl');
211
  $fields .= "<code>{$siteurl}/</code><input type='text' {$input_class} value='{$value}' name='{$input_name}' {$placeholder} {$readonly}/>";
212
  break;
213
 
207
  return "<div class=\"clearfix\"></div>";
208
 
209
  case 'permastruct' :
210
+ $siteurl = get_option('home');
211
  $fields .= "<code>{$siteurl}/</code><input type='text' {$input_class} value='{$value}' name='{$input_name}' {$placeholder} {$readonly}/>";
212
  break;
213
 
includes/core/permalink-manager-helper-functions.php CHANGED
@@ -163,4 +163,20 @@ class Permalink_Manager_Helper_Functions extends Permalink_Manager_Class {
163
  return (isset($term_object->taxonomy)) ? $term_object->taxonomy : '';
164
  }
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  }
163
  return (isset($term_object->taxonomy)) ? $term_object->taxonomy : '';
164
  }
165
 
166
+ /**
167
+ * Get default language (WPML & Polylang)
168
+ */
169
+ static function get_language() {
170
+ global $sitepress;
171
+ $def_lang = '';
172
+
173
+ if(function_exists('pll_default_language')) {
174
+ $def_lang = pll_default_language('slug');
175
+ } else if(is_object($sitepress)) {
176
+ $def_lang = $sitepress->get_default_language();
177
+ }
178
+
179
+ return $def_lang;
180
+ }
181
+
182
  }
includes/core/permalink-manager-uri-functions-post.php CHANGED
@@ -25,17 +25,27 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
25
  $post = (is_integer($post)) ? get_post($post) : $post;
26
  $post_type = $post->post_type;
27
 
 
 
 
 
28
  // Apend the language code as a non-editable prefix
29
  if(isset($sitepress_settings['language_negotiation_type']) && $sitepress_settings['language_negotiation_type'] == 1) {
30
  $post_lang_details = apply_filters('wpml_post_language_details', NULL, $post->ID);
31
  $language_code = (!empty($post_lang_details['language_code'])) ? "{$post_lang_details['language_code']}/" : '';
 
 
 
 
 
 
32
  } else {
33
  $language_code = "";
34
  }
35
 
36
  // Do not change permalink of frontpage
37
  if(get_option('page_on_front') == $post->ID) { return $permalink; }
38
- if(isset($permalink_manager_uris[$post->ID])) $permalink = get_bloginfo('wpurl') . "/{$language_code}{$permalink_manager_uris[$post->ID]}";
39
 
40
  return $permalink;
41
  }
@@ -75,6 +85,9 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
75
 
76
  // Load all bases & post
77
  $post = is_object($post) ? $post : get_post($post);
 
 
 
78
  $post_id = $post->ID;
79
  $post_type = $post->post_type;
80
  $post_name = $post->post_name;
@@ -368,7 +381,7 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
368
  $default_uri = self::get_default_post_uri($id);
369
  $default_uri .= (empty($post->post_name)) ? apply_filters("permalink_manager_filter_default_post_draft_slug", "/{$new_slug}", $id) : "";
370
  // Make sure that home URL ends with slash
371
- $home_url = trim(get_bloginfo('wpurl'), "/") . "/";
372
 
373
  // WPML - apend the language code as a non-editable prefix
374
  if(isset($sitepress_settings['language_negotiation_type']) && $sitepress_settings['language_negotiation_type'] == 1) {
@@ -377,6 +390,12 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
377
 
378
  // Last instance - use language paramater from &_GET array
379
  $language_code = (empty($language_code) && !empty($_GET['lang'])) ? $_GET['lang'] : $language_code;
 
 
 
 
 
 
380
  } else {
381
  $language_code = "";
382
  }
25
  $post = (is_integer($post)) ? get_post($post) : $post;
26
  $post_type = $post->post_type;
27
 
28
+ if(in_array($post->post_status, array('draft', 'pending', 'auto-draft', 'future'))) {
29
+ return trim($permalink, "/");
30
+ }
31
+
32
  // Apend the language code as a non-editable prefix
33
  if(isset($sitepress_settings['language_negotiation_type']) && $sitepress_settings['language_negotiation_type'] == 1) {
34
  $post_lang_details = apply_filters('wpml_post_language_details', NULL, $post->ID);
35
  $language_code = (!empty($post_lang_details['language_code'])) ? "{$post_lang_details['language_code']}/" : '';
36
+
37
+ // Hide language code if "Use directory for default language" option is enabled
38
+ $default_language = Permalink_Manager_Helper_Functions::get_language();
39
+ if(isset($sitepress_settings['urls']['directory_for_default_language']) && ($sitepress_settings['urls']['directory_for_default_language'] == 0) && ($default_language == $post_lang_details['language_code'])) {
40
+ $language_code = "";
41
+ }
42
  } else {
43
  $language_code = "";
44
  }
45
 
46
  // Do not change permalink of frontpage
47
  if(get_option('page_on_front') == $post->ID) { return $permalink; }
48
+ if(isset($permalink_manager_uris[$post->ID])) $permalink = get_option('home') . "/{$language_code}{$permalink_manager_uris[$post->ID]}";
49
 
50
  return $permalink;
51
  }
85
 
86
  // Load all bases & post
87
  $post = is_object($post) ? $post : get_post($post);
88
+
89
+ // Check if post ID is defined
90
+ if(empty($post->ID)) { return ''; }
91
  $post_id = $post->ID;
92
  $post_type = $post->post_type;
93
  $post_name = $post->post_name;
381
  $default_uri = self::get_default_post_uri($id);
382
  $default_uri .= (empty($post->post_name)) ? apply_filters("permalink_manager_filter_default_post_draft_slug", "/{$new_slug}", $id) : "";
383
  // Make sure that home URL ends with slash
384
+ $home_url = trim(get_option('home'), "/") . "/";
385
 
386
  // WPML - apend the language code as a non-editable prefix
387
  if(isset($sitepress_settings['language_negotiation_type']) && $sitepress_settings['language_negotiation_type'] == 1) {
390
 
391
  // Last instance - use language paramater from &_GET array
392
  $language_code = (empty($language_code) && !empty($_GET['lang'])) ? $_GET['lang'] : $language_code;
393
+
394
+ // Hide language code if "Use directory for default language" option is enabled
395
+ $default_language = Permalink_Manager_Helper_Functions::get_language();
396
+ if(isset($sitepress_settings['urls']['directory_for_default_language']) && ($sitepress_settings['urls']['directory_for_default_language'] == 0) && ($default_language == $language_code)) {
397
+ $language_code = '';
398
+ }
399
  } else {
400
  $language_code = "";
401
  }
includes/views/permalink-manager-uri-editor-post.php CHANGED
@@ -86,33 +86,33 @@ class Permalink_Manager_URI_Editor_Post extends WP_List_Table {
86
 
87
  switch( $column_name ) {
88
  case 'post_status':
89
- $post_statuses_array = get_post_statuses();
90
- return "<span title=\"{$item[$column_name]}\">{$post_statuses_array[$item[$column_name]]}</span>";
91
 
92
  case 'post_name':
93
- $output = $item[ 'post_name' ];
94
- return $output;
95
 
96
  case 'uri':
97
- $output = ($item['post_status'] != 'publish') ? '-' : Permalink_Manager_Admin_Functions::generate_option_field("uri[{$item['ID']}]", $field_args_base);
98
- $output .= "<a class=\"small post_permalink\" href=\"{$permalink}\" target=\"_blank\"><span class=\"dashicons dashicons-admin-links\"></span> {$permalink}</a>";
99
- return $output;;
100
 
101
  case 'post_title':
102
- $output = $item[ 'post_title' ];
103
- $output .= '<div class="row-actions">';
104
- $output .= '<span class="edit"><a target="_blank" href="' . home_url() . '/wp-admin/post.php?post=' . $item[ 'ID' ] . '&amp;action=edit" title="' . __('Edit', 'permalink-manager') . '">' . __('Edit', 'permalink-manager') . '</a> | </span>';
105
- $output .= '<span class="view"><a target="_blank" href="' . $permalink . '" title="' . __('View', 'permalink-manager') . ' ' . $item[ 'post_title' ] . '" rel="permalink">' . __('View', 'permalink-manager') . '</a> | </span>';
106
- $output .= '<span class="id">#' . $item[ 'ID' ] . '</span>';
107
- $output .= '</div>';
108
- return $output;
109
 
110
  case 'post_lang':
111
- $post_lang_details = apply_filters('wpml_post_language_details', NULL, $item['ID']);
112
- return (!empty($post_lang_details['native_name'])) ? $post_lang_details['native_name'] : "-";
113
 
114
  default:
115
- return $item[$column_name];
116
  }
117
  }
118
 
86
 
87
  switch( $column_name ) {
88
  case 'post_status':
89
+ $post_statuses_array = get_post_statuses();
90
+ return "<span title=\"{$item[$column_name]}\">{$post_statuses_array[$item[$column_name]]}</span>";
91
 
92
  case 'post_name':
93
+ $output = $item[ 'post_name' ];
94
+ return $output;
95
 
96
  case 'uri':
97
+ $output = Permalink_Manager_Admin_Functions::generate_option_field("uri[{$item['ID']}]", $field_args_base);
98
+ $output .= "<a class=\"small post_permalink\" href=\"{$permalink}\" target=\"_blank\"><span class=\"dashicons dashicons-admin-links\"></span> {$permalink}</a>";
99
+ return $output;;
100
 
101
  case 'post_title':
102
+ $output = $item[ 'post_title' ];
103
+ $output .= '<div class="row-actions">';
104
+ $output .= '<span class="edit"><a target="_blank" href="' . home_url() . '/wp-admin/post.php?post=' . $item[ 'ID' ] . '&amp;action=edit" title="' . __('Edit', 'permalink-manager') . '">' . __('Edit', 'permalink-manager') . '</a> | </span>';
105
+ $output .= '<span class="view"><a target="_blank" href="' . $permalink . '" title="' . __('View', 'permalink-manager') . ' ' . $item[ 'post_title' ] . '" rel="permalink">' . __('View', 'permalink-manager') . '</a> | </span>';
106
+ $output .= '<span class="id">#' . $item[ 'ID' ] . '</span>';
107
+ $output .= '</div>';
108
+ return $output;
109
 
110
  case 'post_lang':
111
+ $post_lang_details = apply_filters('wpml_post_language_details', NULL, $item['ID']);
112
+ return (!empty($post_lang_details['native_name'])) ? $post_lang_details['native_name'] : "-";
113
 
114
  default:
115
+ return $item[$column_name];
116
  }
117
  }
118
 
permalink-manager.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Permalink Manager
5
  * Plugin URI: http://maciejbis.net/
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.0.0
8
  * Author: Maciej Bis
9
  * Author URI: http://maciejbis.net/
10
  * License: GPL-2.0+
@@ -142,7 +142,7 @@ class Permalink_Manager_Class {
142
  */
143
  $protocol = stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true ? 'https://' : 'http://';
144
  $request_url = "{$protocol}{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
145
- $home_url = trim(rtrim(get_bloginfo('wpurl'), '/'));
146
  // Adjust prefix (it should be the same in both request & home_url)
147
  $home_url = ($protocol == 'https://') ? str_replace("http://", "https://", $home_url) : str_replace("https://", "http://", $home_url);
148
 
@@ -285,7 +285,13 @@ class Permalink_Manager_Class {
285
  global $wp, $wp_query, $permalink_manager_uris, $permalink_manager_options;
286
 
287
  // Affect only posts with custom URI and old URIs
288
- if(is_singular() && isset($permalink_manager_uris[$wp_query->queried_object_id]) && empty($wp_query->query['do_not_redirect'])) {
 
 
 
 
 
 
289
  $current_url = home_url(add_query_arg(array(),$wp->request));
290
  $native_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($permalink_manager_uris[$wp_query->queried_object_id], true);
291
 
4
  * Plugin Name: Permalink Manager
5
  * Plugin URI: http://maciejbis.net/
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.0.1
8
  * Author: Maciej Bis
9
  * Author URI: http://maciejbis.net/
10
  * License: GPL-2.0+
142
  */
143
  $protocol = stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true ? 'https://' : 'http://';
144
  $request_url = "{$protocol}{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
145
+ $home_url = trim(rtrim(get_bloginfo('url'), '/'));
146
  // Adjust prefix (it should be the same in both request & home_url)
147
  $home_url = ($protocol == 'https://') ? str_replace("http://", "https://", $home_url) : str_replace("https://", "http://", $home_url);
148
 
285
  global $wp, $wp_query, $permalink_manager_uris, $permalink_manager_options;
286
 
287
  // Affect only posts with custom URI and old URIs
288
+ if(is_singular() && isset($permalink_manager_uris[$wp_query->queried_object_id]) && empty($wp_query->query['do_not_redirect']) && empty($wp_query->query['preview'])) {
289
+ // Ignore posts with specific statuses
290
+ if(!(empty($wp_query->queried_object->post_status)) && in_array($wp_query->queried_object->post_status, array('draft', 'pending', 'auto-draft', 'future'))) {
291
+ return '';
292
+ }
293
+
294
+ // Get the real URL
295
  $current_url = home_url(add_query_arg(array(),$wp->request));
296
  $native_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri($permalink_manager_uris[$wp_query->queried_object_id], true);
297