Version Description
- Typo fix
- UI improvements
- Fix for canonical redirects in WPML
Download this release
Release Info
Developer | mbis |
Plugin | Permalink Manager Lite |
Version | 1.1.1 |
Comparing to | |
See all releases |
Code changes from version 1.1.0 to 1.1.1
- README.txt +11 -6
- includes/core/permalink-manager-actions.php +42 -34
- includes/core/permalink-manager-admin-functions.php +25 -12
- includes/core/permalink-manager-helper-functions.php +12 -4
- includes/core/permalink-manager-third-parties.php +83 -44
- includes/core/permalink-manager-uri-functions-post.php +75 -30
- includes/views/permalink-manager-permastructs.php +22 -8
- includes/views/permalink-manager-settings.php +18 -4
- includes/views/permalink-manager-upgrade.php +50 -0
- includes/views/permalink-manager-uri-editor-post.php +18 -21
- out/permalink-manager-admin.css +21 -8
- out/permalink-manager-admin.js +3 -4
- permalink-manager.php +95 -40
README.txt
CHANGED
@@ -1,18 +1,16 @@
|
|
1 |
-
=== Permalink Manager ===
|
2 |
Contributors: mbis
|
3 |
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.
|
8 |
Tested up to: 4.8
|
9 |
-
Stable tag: 1.1.
|
10 |
|
11 |
Most advanced yet easy-to-use permalink plugin that helps to maintain & bulk change your URLs & slugs.
|
12 |
|
13 |
-
== Description ==
|
14 |
-
|
15 |
-
<strong>Follow <a href="https://www.facebook.com/permalinkmanager/" target="_blank">Permalink Manager</a> on Facebook for news & updates!</strong>
|
16 |
|
17 |
A really intuitive and easy-to-use plugin that helps to manage the permalinks for all your posts, pages and other custom post types items.
|
18 |
|
@@ -26,6 +24,7 @@ Currently, the plugin allows to perform four main actions:
|
|
26 |
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.
|
27 |
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.
|
28 |
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).
|
|
|
29 |
|
30 |
To improve the user experience, each tool allows also to filter the permalinks by post types or post statuses.
|
31 |
|
@@ -58,6 +57,7 @@ http://example.com/poland/cities/poznan === [not changed] ===> http://example.co
|
|
58 |
* Full support for taxonomies
|
59 |
* Full support for WooCommerce
|
60 |
* "Stop-words" to keep your permalinks short & clean (pre-defined "stop-words" lists are available in 19 languages)
|
|
|
61 |
|
62 |
Buy <a href="https://permalinkmanager.pro?utm_source=wordpress">Permalink Manager Pro here</a>.
|
63 |
|
@@ -103,6 +103,11 @@ A. Currently there is no 100% guarantee that Permalink Manager will work correct
|
|
103 |
|
104 |
== Changelog ==
|
105 |
|
|
|
|
|
|
|
|
|
|
|
106 |
= 1.1.0 =
|
107 |
* Partial code refactoring
|
108 |
* "Auto-update" feature
|
1 |
+
=== Permalink Manager Lite ===
|
2 |
Contributors: mbis
|
3 |
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 |
|
13 |
+
== Description ==
|
|
|
|
|
14 |
|
15 |
A really intuitive and easy-to-use plugin that helps to manage the permalinks for all your posts, pages and other custom post types items.
|
16 |
|
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 |
|
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 |
|
103 |
|
104 |
== Changelog ==
|
105 |
|
106 |
+
= 1.1.1 =
|
107 |
+
* Typo fix
|
108 |
+
* UI improvements
|
109 |
+
* Fix for canonical redirects in WPML
|
110 |
+
|
111 |
= 1.1.0 =
|
112 |
* Partial code refactoring
|
113 |
* "Auto-update" feature
|
includes/core/permalink-manager-actions.php
CHANGED
@@ -6,10 +6,7 @@ class Permalink_Manager_Actions extends Permalink_Manager_Class {
|
|
6 |
|
7 |
public function __construct() {
|
8 |
add_action( 'admin_init', array($this, 'trigger_action'), 999 );
|
9 |
-
add_action( 'admin_init', array($this, '
|
10 |
-
|
11 |
-
// Screen Options
|
12 |
-
add_action( 'admin_init', array($this, 'save_screen_options'), 999 );
|
13 |
}
|
14 |
|
15 |
/**
|
@@ -18,13 +15,8 @@ class Permalink_Manager_Actions extends Permalink_Manager_Class {
|
|
18 |
public function trigger_action() {
|
19 |
global $permalink_manager_before_sections_html, $permalink_manager_after_sections_html;
|
20 |
|
21 |
-
// 1. Check if the form was submitted
|
22 |
-
if(
|
23 |
-
$this->flush_sitemaps();
|
24 |
-
$permalink_manager_before_sections_html .= Permalink_Manager_Admin_Functions::get_alert_message(__( 'Sitemap was updated!', 'permalink-manager' ), 'updated');
|
25 |
-
|
26 |
-
return;
|
27 |
-
} else if(empty($_POST)) { return; }
|
28 |
|
29 |
$actions_map = array(
|
30 |
'uri_editor' => array('function' => 'update_all_permalinks', 'display_uri_table' => true),
|
@@ -99,16 +91,27 @@ class Permalink_Manager_Actions extends Permalink_Manager_Class {
|
|
99 |
$permalink_manager_before_sections_html .= Permalink_Manager_Admin_Functions::get_alert_message(__( 'The settings are saved!', 'permalink-manager' ), 'updated');
|
100 |
}
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
/**
|
103 |
* Save "Screen Options"
|
104 |
*/
|
105 |
public static function save_screen_options() {
|
106 |
-
|
107 |
-
check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' );
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
}
|
112 |
}
|
113 |
|
114 |
/**
|
@@ -133,18 +136,19 @@ class Permalink_Manager_Actions extends Permalink_Manager_Class {
|
|
133 |
$permastruct = trim($permastruct, "/");
|
134 |
|
135 |
// Do not store default permastructures
|
136 |
-
$default_permastruct = ($group_name == 'post_types') ? Permalink_Manager_Helper_Functions::get_default_permastruct($element, true) : "";
|
137 |
-
if($permastruct == $default_permastruct) { unset($group[$element]); }
|
138 |
}
|
139 |
// Do not store empty permastructures
|
140 |
-
$new_options[$group_name] = array_filter($group);
|
141 |
} else {
|
142 |
unset($new_options[$group_name]);
|
143 |
}
|
144 |
}
|
145 |
|
146 |
// Override the global with settings
|
147 |
-
$permalink_manager_permastructs = $new_options =
|
|
|
148 |
|
149 |
// Save the settings in database
|
150 |
update_option('permalink-manager-permastructs', $new_options);
|
@@ -153,22 +157,23 @@ class Permalink_Manager_Actions extends Permalink_Manager_Class {
|
|
153 |
/**
|
154 |
* Remove URI from options array after post is moved to the trash
|
155 |
*/
|
156 |
-
function clear_uris(
|
157 |
-
global $permalink_manager_uris;
|
158 |
-
|
159 |
-
if(
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
}
|
168 |
}
|
169 |
-
|
170 |
-
update_option('permalink-manager-uris', $permalink_manager_uris);
|
171 |
}
|
|
|
|
|
|
|
172 |
}
|
173 |
|
174 |
/**
|
@@ -211,9 +216,12 @@ class Permalink_Manager_Actions extends Permalink_Manager_Class {
|
|
211 |
* Clear sitemaps cache
|
212 |
*/
|
213 |
function flush_sitemaps($types = array()) {
|
214 |
-
|
|
|
215 |
if(class_exists('WPSEO_Sitemaps_Cache')) {
|
216 |
$sitemaps = WPSEO_Sitemaps_Cache::clear($types);
|
|
|
|
|
217 |
}
|
218 |
}
|
219 |
|
6 |
|
7 |
public function __construct() {
|
8 |
add_action( 'admin_init', array($this, 'trigger_action'), 999 );
|
9 |
+
add_action( 'admin_init', array($this, 'extra_actions') );
|
|
|
|
|
|
|
10 |
}
|
11 |
|
12 |
/**
|
15 |
public function trigger_action() {
|
16 |
global $permalink_manager_before_sections_html, $permalink_manager_after_sections_html;
|
17 |
|
18 |
+
// 1. Check if the form was submitted
|
19 |
+
if(empty($_POST)) { return; }
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
$actions_map = array(
|
22 |
'uri_editor' => array('function' => 'update_all_permalinks', 'display_uri_table' => true),
|
91 |
$permalink_manager_before_sections_html .= Permalink_Manager_Admin_Functions::get_alert_message(__( 'The settings are saved!', 'permalink-manager' ), 'updated');
|
92 |
}
|
93 |
|
94 |
+
/**
|
95 |
+
* Additional actions
|
96 |
+
*/
|
97 |
+
public static function extra_actions() {
|
98 |
+
if(isset($_GET['flush_sitemaps'])) {
|
99 |
+
self::flush_sitemaps();
|
100 |
+
} else if(isset($_GET['clear-permalink-manager-uris'])) {
|
101 |
+
self::clear_uris();
|
102 |
+
} else if(!empty($_POST['screen-options-apply'])) {
|
103 |
+
self::save_screen_options();
|
104 |
+
}
|
105 |
+
}
|
106 |
+
|
107 |
/**
|
108 |
* Save "Screen Options"
|
109 |
*/
|
110 |
public static function save_screen_options() {
|
111 |
+
check_admin_referer( 'screen-options-nonce', 'screenoptionnonce' );
|
|
|
112 |
|
113 |
+
// The values will be sanitized inside the function
|
114 |
+
self::save_settings('screen-options', $_POST['screen-options']);
|
|
|
115 |
}
|
116 |
|
117 |
/**
|
136 |
$permastruct = trim($permastruct, "/");
|
137 |
|
138 |
// Do not store default permastructures
|
139 |
+
// $default_permastruct = ($group_name == 'post_types') ? Permalink_Manager_Helper_Functions::get_default_permastruct($element, true) : "";
|
140 |
+
// if($permastruct == $default_permastruct) { unset($group[$element]); }
|
141 |
}
|
142 |
// Do not store empty permastructures
|
143 |
+
// $new_options[$group_name] = array_filter($group);
|
144 |
} else {
|
145 |
unset($new_options[$group_name]);
|
146 |
}
|
147 |
}
|
148 |
|
149 |
// Override the global with settings
|
150 |
+
// $permalink_manager_permastructs = $new_options = $new_options;
|
151 |
+
$permalink_manager_permastructs = $new_options;
|
152 |
|
153 |
// Save the settings in database
|
154 |
update_option('permalink-manager-permastructs', $new_options);
|
157 |
/**
|
158 |
* Remove URI from options array after post is moved to the trash
|
159 |
*/
|
160 |
+
public static function clear_uris() {
|
161 |
+
global $permalink_manager_uris, $permalink_manager_before_sections_html;
|
162 |
+
|
163 |
+
if(empty($permalink_manager_uris)) { return; }
|
164 |
+
|
165 |
+
foreach($permalink_manager_uris as $post_id => $uri) {
|
166 |
+
// Loop only through post URIs
|
167 |
+
if(is_numeric($post_id)) {
|
168 |
+
$post_status = get_post_status($post_id);
|
169 |
+
if(in_array($post_status, array('auto-draft', 'trash', ''))) {
|
170 |
+
unset($permalink_manager_uris[$post_id]);
|
171 |
}
|
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 |
}
|
178 |
|
179 |
/**
|
216 |
* Clear sitemaps cache
|
217 |
*/
|
218 |
function flush_sitemaps($types = array()) {
|
219 |
+
global $permalink_manager_before_sections_html;
|
220 |
+
|
221 |
if(class_exists('WPSEO_Sitemaps_Cache')) {
|
222 |
$sitemaps = WPSEO_Sitemaps_Cache::clear($types);
|
223 |
+
|
224 |
+
$permalink_manager_before_sections_html .= Permalink_Manager_Admin_Functions::get_alert_message(__( 'Sitemaps were updated!', 'permalink-manager' ), 'updated');
|
225 |
}
|
226 |
}
|
227 |
|
includes/core/permalink-manager-admin-functions.php
CHANGED
@@ -112,7 +112,7 @@ class Permalink_Manager_Admin_Functions extends Permalink_Manager_Class {
|
|
112 |
*/
|
113 |
public function plugins_page_links($links) {
|
114 |
$links[] = sprintf('<a href="%s">%s</a>', $this->get_admin_url(), __( 'URI Editor', 'permalink-manager' ));
|
115 |
-
if(!defined('PERMALINK_MANAGER_PRO')
|
116 |
$links[] = sprintf('<a href="%s" target="_blank">%s</a>', PERMALINK_MANAGER_WEBSITE, __( 'Buy Permalink Manager Pro', 'permalink-manager' ));
|
117 |
}
|
118 |
return $links;
|
@@ -211,17 +211,17 @@ class Permalink_Manager_Admin_Functions extends Permalink_Manager_Class {
|
|
211 |
break;
|
212 |
|
213 |
case 'select' :
|
214 |
-
$fields .= '<
|
215 |
$fields .= "<select name='{$input_name}' {$input_atts}>";
|
216 |
foreach($args['choices'] as $choice_value => $choice) {
|
217 |
$label = (is_array($choice)) ? $choice['label'] : $choice;
|
218 |
$atts = ($choice_value == $value) ? "selected='selected'" : "";
|
219 |
$atts .= (!empty($choice['atts'])) ? " {$choice['atts']}" : "";
|
220 |
|
221 |
-
$fields .= "<option value='{$choice_value}' {$atts}
|
222 |
}
|
223 |
$fields .= '</select>';
|
224 |
-
$fields .= '</
|
225 |
break;
|
226 |
|
227 |
case 'number' :
|
@@ -249,7 +249,7 @@ class Permalink_Manager_Admin_Functions extends Permalink_Manager_Class {
|
|
249 |
|
250 |
case 'permastruct' :
|
251 |
$siteurl = get_option('home');
|
252 |
-
$fields .= "<code>{$siteurl}/</code><input type='text' {$input_atts} value='{$value}' name='{$input_name}'
|
253 |
break;
|
254 |
|
255 |
default :
|
@@ -386,11 +386,8 @@ class Permalink_Manager_Admin_Functions extends Permalink_Manager_Class {
|
|
386 |
|
387 |
$html = "<div id=\"permalink-manager\" class=\"wrap\">";
|
388 |
|
389 |
-
// Display alerts [moved to display_plugin_notices() function] and another content if needed and the plugin header
|
390 |
-
// $html .= $permalink_manager_before_sections_html;
|
391 |
-
$buy_link = (!defined('PERMALINK_MANAGER_PRO')) ? sprintf("<a href=\"%s\" target=\"_blank\" class=\"page-title-action\">%s</a>", PERMALINK_MANAGER_WEBSITE, __("Buy Permalink Manager Pro", "permalink-manager")) : "";
|
392 |
$donate_link = sprintf("<a href=\"%s\" target=\"_blank\" class=\"page-title-action\">%s</a>", PERMALINK_MANAGER_DONATE, __("Donate", "permalink-manager"));
|
393 |
-
$html .= sprintf("<h2 id=\"plugin-name-heading\">%s <a href=\"http://maciejbis.net\" class=\"author-link\" target=\"_blank\">%s</a> %s
|
394 |
|
395 |
// Display the tab navigation
|
396 |
$html .= "<div id=\"permalink-manager-tab-nav\" class=\"nav-tab-wrapper\">";
|
@@ -454,7 +451,12 @@ class Permalink_Manager_Admin_Functions extends Permalink_Manager_Class {
|
|
454 |
/**
|
455 |
* Display error/info message
|
456 |
*/
|
457 |
-
public static function get_alert_message($alert_content, $alert_type, $dismissable = true, $id = false) {
|
|
|
|
|
|
|
|
|
|
|
458 |
$class = ($dismissable) ? "is-dismissible" : "";
|
459 |
$alert_id = ($id) ? " data-alert_id=\"{$id}\"" : "";
|
460 |
|
@@ -529,12 +531,23 @@ class Permalink_Manager_Admin_Functions extends Permalink_Manager_Class {
|
|
529 |
* Display global notices (throughout wp-admin dashboard)
|
530 |
*/
|
531 |
function display_global_notices() {
|
532 |
-
global $permalink_manager_alerts;
|
533 |
|
534 |
$html = "";
|
535 |
if(!empty($permalink_manager_alerts) && is_array($permalink_manager_alerts)) {
|
536 |
foreach($permalink_manager_alerts as $alert_id => $alert) {
|
537 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
538 |
}
|
539 |
}
|
540 |
|
112 |
*/
|
113 |
public function plugins_page_links($links) {
|
114 |
$links[] = sprintf('<a href="%s">%s</a>', $this->get_admin_url(), __( 'URI Editor', 'permalink-manager' ));
|
115 |
+
if(!defined('PERMALINK_MANAGER_PRO')) {
|
116 |
$links[] = sprintf('<a href="%s" target="_blank">%s</a>', PERMALINK_MANAGER_WEBSITE, __( 'Buy Permalink Manager Pro', 'permalink-manager' ));
|
117 |
}
|
118 |
return $links;
|
211 |
break;
|
212 |
|
213 |
case 'select' :
|
214 |
+
$fields .= '<span class="select">';
|
215 |
$fields .= "<select name='{$input_name}' {$input_atts}>";
|
216 |
foreach($args['choices'] as $choice_value => $choice) {
|
217 |
$label = (is_array($choice)) ? $choice['label'] : $choice;
|
218 |
$atts = ($choice_value == $value) ? "selected='selected'" : "";
|
219 |
$atts .= (!empty($choice['atts'])) ? " {$choice['atts']}" : "";
|
220 |
|
221 |
+
$fields .= "<option value='{$choice_value}' {$atts}>{$label}</option>";
|
222 |
}
|
223 |
$fields .= '</select>';
|
224 |
+
$fields .= '</span>';
|
225 |
break;
|
226 |
|
227 |
case 'number' :
|
249 |
|
250 |
case 'permastruct' :
|
251 |
$siteurl = get_option('home');
|
252 |
+
$fields .= "<div class=\"permastruct-container\"><span><code>{$siteurl}/</code></span><span><input type='text' {$input_atts} value='{$value}' name='{$input_name}'/></span></div>";
|
253 |
break;
|
254 |
|
255 |
default :
|
386 |
|
387 |
$html = "<div id=\"permalink-manager\" class=\"wrap\">";
|
388 |
|
|
|
|
|
|
|
389 |
$donate_link = sprintf("<a href=\"%s\" target=\"_blank\" class=\"page-title-action\">%s</a>", PERMALINK_MANAGER_DONATE, __("Donate", "permalink-manager"));
|
390 |
+
$html .= sprintf("<h2 id=\"plugin-name-heading\">%s <a href=\"http://maciejbis.net\" class=\"author-link\" target=\"_blank\">%s</a> %s</h2>", PERMALINK_MANAGER_PLUGIN_NAME, __("by Maciej Bis", "permalink-manager"), $donate_link);
|
391 |
|
392 |
// Display the tab navigation
|
393 |
$html .= "<div id=\"permalink-manager-tab-nav\" class=\"nav-tab-wrapper\">";
|
451 |
/**
|
452 |
* Display error/info message
|
453 |
*/
|
454 |
+
public static function get_alert_message($alert_content = "", $alert_type = "", $dismissable = true, $id = false) {
|
455 |
+
// Ignore empty messages (just in case)
|
456 |
+
if(empty($alert_content) || empty($alert_type)) {
|
457 |
+
return "";
|
458 |
+
}
|
459 |
+
|
460 |
$class = ($dismissable) ? "is-dismissible" : "";
|
461 |
$alert_id = ($id) ? " data-alert_id=\"{$id}\"" : "";
|
462 |
|
531 |
* Display global notices (throughout wp-admin dashboard)
|
532 |
*/
|
533 |
function display_global_notices() {
|
534 |
+
global $permalink_manager_alerts, $active_section;
|
535 |
|
536 |
$html = "";
|
537 |
if(!empty($permalink_manager_alerts) && is_array($permalink_manager_alerts)) {
|
538 |
foreach($permalink_manager_alerts as $alert_id => $alert) {
|
539 |
+
if(!empty($alert['show'])) {
|
540 |
+
// Hide notice in Permalink Manager Pro
|
541 |
+
if(defined('PERMALINK_MANAGER_PRO') && $alert['show'] == 'pro_hide') { continue; }
|
542 |
+
|
543 |
+
// Display the notice only on the plugin pages
|
544 |
+
if(empty($active_section) && !empty($alert['plugin_only'])) { continue; }
|
545 |
+
|
546 |
+
// Check if the notice did not expire
|
547 |
+
if(isset($alert['until']) && (time() > strtotime($alert['until']))) { continue; }
|
548 |
+
|
549 |
+
$html .= self::get_alert_message($alert['txt'], $alert['type'], true, $alert_id);
|
550 |
+
}
|
551 |
}
|
552 |
}
|
553 |
|
includes/core/permalink-manager-helper-functions.php
CHANGED
@@ -27,16 +27,17 @@ class Permalink_Manager_Helper_Functions extends Permalink_Manager_Class {
|
|
27 |
/**
|
28 |
* Get primary term (by Yoast SEO)
|
29 |
*/
|
30 |
-
static function get_primary_term($post_id, $taxonomy) {
|
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 |
-
|
37 |
-
|
38 |
-
|
39 |
}
|
|
|
40 |
}
|
41 |
|
42 |
/**
|
@@ -198,4 +199,11 @@ class Permalink_Manager_Helper_Functions extends Permalink_Manager_Class {
|
|
198 |
return $data;
|
199 |
}
|
200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
}
|
27 |
/**
|
28 |
* Get primary term (by Yoast SEO)
|
29 |
*/
|
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)) {
|
37 |
+
return ($slug_only) ? $primary_term->slug : $primary_term;
|
38 |
+
}
|
39 |
}
|
40 |
+
return '';
|
41 |
}
|
42 |
|
43 |
/**
|
199 |
return $data;
|
200 |
}
|
201 |
|
202 |
+
/**
|
203 |
+
* Encode URI and keep slashes
|
204 |
+
*/
|
205 |
+
static function encode_uri($uri) {
|
206 |
+
return str_replace("%2F", "/", urlencode($uri));
|
207 |
+
}
|
208 |
+
|
209 |
}
|
includes/core/permalink-manager-third-parties.php
CHANGED
@@ -6,41 +6,64 @@
|
|
6 |
class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
|
7 |
|
8 |
public function __construct() {
|
9 |
-
add_action('init', array($this, '
|
10 |
-
add_action('init', array($this, 'amp_hooks'), 99);
|
11 |
}
|
12 |
|
13 |
-
|
14 |
-
* 1. WPML filters
|
15 |
-
*/
|
16 |
-
function wpml_hooks() {
|
17 |
global $sitepress_settings;
|
18 |
|
19 |
-
//
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
//
|
24 |
-
|
25 |
-
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
add_filter('permalink-manager-term-permalink-prefix', array($this, 'wpml_element_lang_prefix'), 9, 3);
|
32 |
}
|
33 |
}
|
34 |
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
if(
|
39 |
-
$
|
40 |
-
|
41 |
-
$wpml_item_id = apply_filters('wpml_object_id', $item_id);
|
42 |
-
$item_id = (is_numeric($wpml_item_id)) ? $wpml_item_id : $item_id;
|
43 |
-
}
|
44 |
}
|
45 |
|
46 |
return $item_id;
|
@@ -81,7 +104,7 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
|
|
81 |
|
82 |
// Hide language code if "Use directory for default language" option is enabled
|
83 |
$default_language = Permalink_Manager_Helper_Functions::get_language();
|
84 |
-
if(isset($sitepress_settings['urls']['directory_for_default_language']) && ($sitepress_settings['urls']['directory_for_default_language'] == 0) && ($default_language == $lang_details->language_code)) {
|
85 |
$prefix = "";
|
86 |
}
|
87 |
}
|
@@ -98,32 +121,32 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
|
|
98 |
}
|
99 |
|
100 |
function wpml_lang_column_content_uri_editor($output, $column, $item) {
|
101 |
-
if($
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
$lang_details = apply_filters('wpml_element_language_details', NULL, array('element_id' => $term->term_id, 'element_type' => $term->taxonomy));
|
108 |
-
}
|
109 |
-
|
110 |
-
return (!empty($lang_details->language_code)) ? $lang_details->language_code : "-";
|
111 |
}
|
112 |
|
|
|
|
|
113 |
return $output;
|
114 |
}
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
// Detect AMP endpoint
|
122 |
-
add_filter('permalink-manager-detect-uri', array($this, 'detect_amp'), 10, 2);
|
123 |
-
add_filter('request', array($this, 'enable_amp'), 10, 1);
|
124 |
}
|
|
|
|
|
125 |
}
|
126 |
|
|
|
|
|
|
|
127 |
function detect_amp($uri_parts, $request_url) {
|
128 |
global $amp_enabled;
|
129 |
$amp_query_var = AMP_QUERY_VAR;
|
@@ -148,5 +171,21 @@ class Permalink_Manager_Third_Parties extends Permalink_Manager_Class {
|
|
148 |
return $query;
|
149 |
}
|
150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
}
|
152 |
?>
|
6 |
class Permalink_Manager_Third_Parties 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 |
global $sitepress_settings;
|
14 |
|
15 |
+
// 1. WPML
|
16 |
+
if($sitepress_settings) {
|
17 |
+
// Detect Post/Term function
|
18 |
+
add_filter('permalink-manager-detected-post-id', array($this, 'wpml_language_mismatch_fix'), 9, 3);
|
19 |
+
add_filter('permalink-manager-detected-term-id', array($this, 'wpml_language_mismatch_fix'), 9, 3);
|
20 |
+
|
21 |
+
// URI Editor
|
22 |
+
add_filter('permalink-manager-uri-editor-extra-info', array($this, 'wpml_lang_column_content_uri_editor'), 9, 3);
|
23 |
+
|
24 |
+
// Split the current URL into subparts (check if WPML is active)
|
25 |
+
if(isset($sitepress_settings['language_negotiation_type']) && $sitepress_settings['language_negotiation_type'] == 1) {
|
26 |
+
add_filter('permalink-manager-detect-uri', array($this, 'wpml_detect_post'), 9, 2);
|
27 |
+
add_filter('permalink-manager-post-permalink-prefix', array($this, 'wpml_element_lang_prefix'), 9, 3);
|
28 |
+
add_filter('permalink-manager-term-permalink-prefix', array($this, 'wpml_element_lang_prefix'), 9, 3);
|
29 |
+
} else if(isset($sitepress_settings['language_negotiation_type']) && $sitepress_settings['language_negotiation_type'] == 3) {
|
30 |
+
add_filter('permalink-manager-detect-uri', array($this, 'wpml_ignore_lang_query_parameter'), 9);
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
// 2. AMP
|
35 |
+
if(defined('AMP_QUERY_VAR')) {
|
36 |
+
// Detect AMP endpoint
|
37 |
+
add_filter('permalink-manager-detect-uri', array($this, 'detect_amp'), 10, 2);
|
38 |
+
add_filter('request', array($this, 'enable_amp'), 10, 1);
|
39 |
+
}
|
40 |
|
41 |
+
// 3. Yoast SEO
|
42 |
+
if(class_exists('WPSEO_Options')) {
|
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 |
}
|
50 |
}
|
51 |
|
52 |
+
/**
|
53 |
+
* 1. WPML filters
|
54 |
+
*/
|
55 |
+
function wpml_language_mismatch_fix($item_id, $uri_parts, $is_term = false) {
|
56 |
+
if($is_term) {
|
57 |
+
$current_term = get_term($item_id);
|
58 |
+
$element_type = (!empty($current_term) && !is_wp_error($current_term)) ? $current_term->taxonomy : "";
|
59 |
+
} else {
|
60 |
+
$element_type = get_post_type($item_id);
|
61 |
+
}
|
62 |
+
$language_code = apply_filters('wpml_element_language_code', null, array('element_id' => $item_id, 'element_type' => $element_type));
|
63 |
|
64 |
+
if(!empty($uri_parts['lang']) && ($uri_parts['lang'] != $language_code)) {
|
65 |
+
$wpml_item_id = apply_filters('wpml_object_id', $item_id);
|
66 |
+
$item_id = (is_numeric($wpml_item_id)) ? $wpml_item_id : $item_id;
|
|
|
|
|
|
|
67 |
}
|
68 |
|
69 |
return $item_id;
|
104 |
|
105 |
// Hide language code if "Use directory for default language" option is enabled
|
106 |
$default_language = Permalink_Manager_Helper_Functions::get_language();
|
107 |
+
if(isset($sitepress_settings['urls']['directory_for_default_language']) && isset($lang_details->language_code) && ($sitepress_settings['urls']['directory_for_default_language'] == 0) && ($default_language == $lang_details->language_code)) {
|
108 |
$prefix = "";
|
109 |
}
|
110 |
}
|
121 |
}
|
122 |
|
123 |
function wpml_lang_column_content_uri_editor($output, $column, $item) {
|
124 |
+
if(isset($item->post_type)) {
|
125 |
+
$post = (is_integer($item)) ? get_post($item) : $item;
|
126 |
+
$lang_details = apply_filters('wpml_element_language_details', NULL, array('element_id' => $post->ID, 'element_type' => $post->post_type));
|
127 |
+
} else {
|
128 |
+
$term = (is_integer($item)) ? get_term(intval($item)) : $item;
|
129 |
+
$lang_details = apply_filters('wpml_element_language_details', NULL, array('element_id' => $term->term_id, 'element_type' => $term->taxonomy));
|
|
|
|
|
|
|
|
|
130 |
}
|
131 |
|
132 |
+
$output .= (!empty($lang_details->language_code)) ? sprintf(" | <span><strong>%s:</strong> %s</span>", __("Language"), $lang_details->language_code) : "";
|
133 |
+
|
134 |
return $output;
|
135 |
}
|
136 |
|
137 |
+
function wpml_ignore_lang_query_parameter($uri_parts) {
|
138 |
+
global $permalink_manager_uris;
|
139 |
+
|
140 |
+
foreach($permalink_manager_uris as &$uri) {
|
141 |
+
$uri = trim(strtok($uri, '?'), "/");
|
|
|
|
|
|
|
142 |
}
|
143 |
+
|
144 |
+
return $uri_parts;
|
145 |
}
|
146 |
|
147 |
+
/**
|
148 |
+
* 2. AMP hooks
|
149 |
+
*/
|
150 |
function detect_amp($uri_parts, $request_url) {
|
151 |
global $amp_enabled;
|
152 |
$amp_query_var = AMP_QUERY_VAR;
|
171 |
return $query;
|
172 |
}
|
173 |
|
174 |
+
/**
|
175 |
+
* 3. Yoast SEO
|
176 |
+
*/
|
177 |
+
function yoast_detect_attachment($item_id, $uri_parts, $request_url) {
|
178 |
+
global $wpdb;
|
179 |
+
|
180 |
+
if(empty($item_id) && !empty($uri_parts['uri'])) {
|
181 |
+
$attachment_slug = basename($uri_parts['uri']);
|
182 |
+
$attachment = $wpdb->get_row( $wpdb->prepare( "SELECT ID, post_name FROM {$wpdb->posts} WHERE post_type = %s AND post_name = %s", "attachment", $attachment_slug ), ARRAY_A );
|
183 |
+
|
184 |
+
$item_id = (!empty($attachment['ID'])) ? $attachment['ID'] : $item_id;
|
185 |
+
}
|
186 |
+
|
187 |
+
return $item_id;
|
188 |
+
}
|
189 |
+
|
190 |
}
|
191 |
?>
|
includes/core/permalink-manager-uri-functions-post.php
CHANGED
@@ -12,9 +12,11 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
|
|
12 |
add_filter( 'page_link', array($this, 'custom_post_permalinks'), 999, 2);
|
13 |
add_filter( 'post_link', array($this, 'custom_post_permalinks'), 999, 2);
|
14 |
add_filter( 'post_type_link', array($this, 'custom_post_permalinks'), 999, 2);
|
|
|
15 |
|
16 |
add_filter( 'permalink-manager-uris', array($this, 'exclude_homepage'), 999, 2);
|
17 |
add_action( 'save_post', array($this, 'update_post_uri'), 999, 3 );
|
|
|
18 |
add_action( 'wp_trash_post', array($this, 'remove_post_uri'), 10, 3 );
|
19 |
|
20 |
add_filter( 'permalink_manager_filter_default_post_slug', array($this, 'force_custom_slugs'), 5, 3 );
|
@@ -24,7 +26,7 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
|
|
24 |
* Change permalinks for posts, pages & custom post types
|
25 |
*/
|
26 |
function custom_post_permalinks($permalink, $post) {
|
27 |
-
global $wp_rewrite, $permalink_manager_uris;
|
28 |
|
29 |
$post = (is_integer($post)) ? get_post($post) : $post;
|
30 |
$post_type = $post->post_type;
|
@@ -38,13 +40,24 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
|
|
38 |
return trim($permalink, "/");
|
39 |
}
|
40 |
|
41 |
-
// 2.
|
42 |
-
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
if(isset($permalink_manager_uris[$post->ID])) { $permalink = get_option('home') . "/{$prefix}{$permalink_manager_uris[$post->ID]}"; }
|
46 |
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
$permalink = apply_filters('permalink_manager_filter_final_post_permalink', user_trailingslashit($permalink), $post);
|
49 |
|
50 |
return $permalink;
|
@@ -97,7 +110,7 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
|
|
97 |
if($native_uri) {
|
98 |
$permastruct = $default_permastruct;
|
99 |
} else {
|
100 |
-
$permastruct = (
|
101 |
}
|
102 |
|
103 |
$default_base = (!empty($permastruct)) ? trim($permastruct, '/') : "";
|
@@ -128,17 +141,37 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
|
|
128 |
|
129 |
if($taxonomies) {
|
130 |
foreach($taxonomies as $taxonomy) {
|
131 |
-
//
|
132 |
-
$
|
133 |
|
134 |
-
//
|
135 |
-
if(empty($
|
136 |
$terms = wp_get_object_terms($post->ID, $taxonomy);
|
137 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
}
|
139 |
|
140 |
-
// Do the replacement
|
141 |
-
$default_uri = (!empty($replacement)) ? str_replace("%{$taxonomy}%", $replacement, $default_uri) : $default_uri;
|
142 |
}
|
143 |
}
|
144 |
|
@@ -249,9 +282,9 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
|
|
249 |
}
|
250 |
|
251 |
// Do not store default values
|
252 |
-
if(isset($permalink_manager_uris[$row['ID']]) && ($new_uri == $native_uri)) {
|
253 |
-
|
254 |
-
}
|
255 |
}
|
256 |
|
257 |
// Filter array before saving
|
@@ -344,9 +377,9 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
|
|
344 |
}
|
345 |
|
346 |
// Do not store default values
|
347 |
-
if(isset($permalink_manager_uris[$row['ID']]) && ($new_uri == $native_uri)) {
|
348 |
-
|
349 |
-
}
|
350 |
}
|
351 |
|
352 |
// Filter array before saving
|
@@ -405,9 +438,9 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
|
|
405 |
}
|
406 |
|
407 |
// Do not store native URIs
|
408 |
-
if($new_uri == $native_uri) {
|
409 |
-
|
410 |
-
}
|
411 |
|
412 |
}
|
413 |
|
@@ -452,6 +485,9 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
|
|
452 |
$uri = $sample_permalink = (!empty($permalink_manager_uris[$id])) ? $permalink_manager_uris[$id] : $native_uri;
|
453 |
}
|
454 |
|
|
|
|
|
|
|
455 |
// Prepare the sample & default permalink
|
456 |
$sample_permalink = sprintf("{$home_url}{$prefix}<span class=\"editable\">%s</span>", str_replace("//", "/", trim($sample_permalink, "/")));
|
457 |
|
@@ -482,7 +518,7 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
|
|
482 |
$html .= sprintf("<p><label for=\"custom_uri\" class=\"strong\">%s %s</label><span>%s</span></p>",
|
483 |
__("Current URI", "permalink-manager"),
|
484 |
Permalink_Manager_Admin_Functions::help_tooltip(__("The custom URI can be edited only if 'Auto-update the URI' feature is not enabled.", "permalink-manager")),
|
485 |
-
Permalink_Manager_Admin_Functions::generate_option_field("custom_uri", array("extra_atts" => "data-default
|
486 |
);
|
487 |
$html .= sprintf("<p><label for=\"auto_auri\" class=\"strong\">%s %s</label><span>%s</span></p>",
|
488 |
__("Auto-update the URI", "permalink-manager"),
|
@@ -490,10 +526,18 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
|
|
490 |
Permalink_Manager_Admin_Functions::generate_option_field("auto_update_uri", array("type" => "select", "input_class" => "widefat auto_update", "value" => $auto_update_val, "choices" => $auto_update_choices))
|
491 |
);
|
492 |
$html .= sprintf(
|
493 |
-
"<p class=\"default-permalink-row columns-container\"><span class=\"column-3_4\"><strong>%s:</strong> %s</span><span class=\"column-1_4\"><a href=\"#\"
|
494 |
-
__("Default URI", "permalink-manager"), esc_html($default_uri),
|
495 |
__("Restore to Default URI", "permalink-manager")
|
496 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
497 |
$html .= "</div>";
|
498 |
|
499 |
$html .= "</div>";
|
@@ -529,11 +573,12 @@ class Permalink_Manager_URI_Functions_Post extends Permalink_Manager_Class {
|
|
529 |
$new_uri = (empty($_POST['custom_uri']) || $auto_update_uri == 1) ? $default_uri : trim($_POST['custom_uri'], "/");
|
530 |
|
531 |
// Do not store default values
|
532 |
-
if(isset($permalink_manager_uris[$post->ID]) && ($new_uri == $native_uri)) {
|
533 |
-
|
534 |
-
}
|
|
|
535 |
// Save only changed URIs
|
536 |
-
|
537 |
$permalink_manager_uris[$post->ID] = $new_uri;
|
538 |
}
|
539 |
|
12 |
add_filter( 'page_link', array($this, 'custom_post_permalinks'), 999, 2);
|
13 |
add_filter( 'post_link', array($this, 'custom_post_permalinks'), 999, 2);
|
14 |
add_filter( 'post_type_link', array($this, 'custom_post_permalinks'), 999, 2);
|
15 |
+
add_filter( 'attachment_link', array($this, 'custom_post_permalinks'), 999, 2);
|
16 |
|
17 |
add_filter( 'permalink-manager-uris', array($this, 'exclude_homepage'), 999, 2);
|
18 |
add_action( 'save_post', array($this, 'update_post_uri'), 999, 3 );
|
19 |
+
add_action( 'edit_attachment', array($this, 'update_post_uri'), 999, 1 );
|
20 |
add_action( 'wp_trash_post', array($this, 'remove_post_uri'), 10, 3 );
|
21 |
|
22 |
add_filter( 'permalink_manager_filter_default_post_slug', array($this, 'force_custom_slugs'), 5, 3 );
|
26 |
* Change permalinks for posts, pages & custom post types
|
27 |
*/
|
28 |
function custom_post_permalinks($permalink, $post) {
|
29 |
+
global $wp_rewrite, $permalink_manager_uris, $permalink_manager_options;
|
30 |
|
31 |
$post = (is_integer($post)) ? get_post($post) : $post;
|
32 |
$post_type = $post->post_type;
|
40 |
return trim($permalink, "/");
|
41 |
}
|
42 |
|
43 |
+
// 2. Filter only the posts with custom permalink assigned
|
44 |
+
if(isset($permalink_manager_uris[$post->ID])) {
|
45 |
+
// Apend the language code as a non-editable prefix (can be used also for another prefixes)
|
46 |
+
$prefix = apply_filters('permalink-manager-post-permalink-prefix', '', $post);
|
47 |
|
48 |
+
$permalink = get_option('home');
|
|
|
49 |
|
50 |
+
// Encode URI?
|
51 |
+
if(!empty($permalink_manager_options['general']['decode_uris'])) {
|
52 |
+
$permalink .= urldecode("/{$prefix}{$permalink_manager_uris[$post->ID]}");
|
53 |
+
} else {
|
54 |
+
$permalink .= Permalink_Manager_Helper_Functions::encode_uri("/{$prefix}{$permalink_manager_uris[$post->ID]}");
|
55 |
+
}
|
56 |
+
} else if(!empty($permalink_manager_options['general']['decode_uris'])) {
|
57 |
+
$permalink = urldecode($permalink);
|
58 |
+
}
|
59 |
+
|
60 |
+
// 3. Additional filter
|
61 |
$permalink = apply_filters('permalink_manager_filter_final_post_permalink', user_trailingslashit($permalink), $post);
|
62 |
|
63 |
return $permalink;
|
110 |
if($native_uri) {
|
111 |
$permastruct = $default_permastruct;
|
112 |
} else {
|
113 |
+
$permastruct = (isset($permalink_manager_permastructs['post_types'][$post_type])) ? $permalink_manager_permastructs['post_types'][$post_type] : $default_permastruct;
|
114 |
}
|
115 |
|
116 |
$default_base = (!empty($permastruct)) ? trim($permastruct, '/') : "";
|
141 |
|
142 |
if($taxonomies) {
|
143 |
foreach($taxonomies as $taxonomy) {
|
144 |
+
// 1. Try to use Yoast SEO Primary Term
|
145 |
+
$replacement_term = Permalink_Manager_Helper_Functions::get_primary_term($post->ID, $taxonomy, false);
|
146 |
|
147 |
+
// 2. Get the first assigned term to this taxonomy
|
148 |
+
if(empty($replacement_term)) {
|
149 |
$terms = wp_get_object_terms($post->ID, $taxonomy);
|
150 |
+
$replacement_term = (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) ? $terms[0] : "";
|
151 |
+
}
|
152 |
+
|
153 |
+
// 3A. Hierarhcical taxonomy base
|
154 |
+
if(!empty($replacement_term->term_id) && strpos($default_uri, "%{$taxonomy}_flat%") === false && is_taxonomy_hierarchical($taxonomy)) {
|
155 |
+
$ancestors = get_ancestors( $replacement_term->term_id, $taxonomy, 'taxonomy' );
|
156 |
+
$hierarchical_slugs = array();
|
157 |
+
|
158 |
+
foreach ( (array) $ancestors as $ancestor ) {
|
159 |
+
$ancestor_term = get_term($ancestor, $taxonomy);
|
160 |
+
$hierarchical_slugs[] = $ancestor_term->slug;
|
161 |
+
}
|
162 |
+
$hierarchical_slugs = array_reverse($hierarchical_slugs);
|
163 |
+
$replacement = implode('/', $hierarchical_slugs);
|
164 |
+
|
165 |
+
// Append the term slug now
|
166 |
+
$replacement = "{$replacement}/{$replacement_term->slug}";
|
167 |
+
}
|
168 |
+
// 3B. Flat taxonomy base
|
169 |
+
else if(!empty($replacement_term->slug)) {
|
170 |
+
$replacement = $replacement_term->slug;
|
171 |
}
|
172 |
|
173 |
+
// 4. Do the replacement
|
174 |
+
$default_uri = (!empty($replacement)) ? str_replace(array("%{$taxonomy}%", "%{$taxonomy}_flat%"), $replacement, $default_uri) : $default_uri;
|
175 |
}
|
176 |
}
|
177 |
|
282 |
}
|
283 |
|
284 |
// Do not store default values
|
285 |
+
// if(isset($permalink_manager_uris[$row['ID']]) && ($new_uri == $native_uri)) {
|
286 |
+
// unset($permalink_manager_uris[$row['ID']]);
|
287 |
+
// }
|
288 |
}
|
289 |
|
290 |
// Filter array before saving
|
377 |
}
|
378 |
|
379 |
// Do not store default values
|
380 |
+
// if(isset($permalink_manager_uris[$row['ID']]) && ($new_uri == $native_uri)) {
|
381 |
+
// unset($permalink_manager_uris[$row['ID']]);
|
382 |
+
// }
|
383 |
}
|
384 |
|
385 |
// Filter array before saving
|
438 |
}
|
439 |
|
440 |
// Do not store native URIs
|
441 |
+
// if($new_uri == $native_uri) {
|
442 |
+
// unset($old_uris[$id]);
|
443 |
+
// }
|
444 |
|
445 |
}
|
446 |
|
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 |
|
518 |
$html .= sprintf("<p><label for=\"custom_uri\" class=\"strong\">%s %s</label><span>%s</span></p>",
|
519 |
__("Current URI", "permalink-manager"),
|
520 |
Permalink_Manager_Admin_Functions::help_tooltip(__("The custom URI can be edited only if 'Auto-update the URI' feature is not enabled.", "permalink-manager")),
|
521 |
+
Permalink_Manager_Admin_Functions::generate_option_field("custom_uri", array("extra_atts" => "data-default=\"{$default_uri}\"", "input_class" => "widefat custom_uri", "value" => urldecode($uri)))
|
522 |
);
|
523 |
$html .= sprintf("<p><label for=\"auto_auri\" class=\"strong\">%s %s</label><span>%s</span></p>",
|
524 |
__("Auto-update the URI", "permalink-manager"),
|
526 |
Permalink_Manager_Admin_Functions::generate_option_field("auto_update_uri", array("type" => "select", "input_class" => "widefat auto_update", "value" => $auto_update_val, "choices" => $auto_update_choices))
|
527 |
);
|
528 |
$html .= sprintf(
|
529 |
+
"<p class=\"default-permalink-row columns-container\"><span class=\"column-3_4\"><strong>%s:</strong> %s</span><span class=\"column-1_4\"><a href=\"#\" class=\"restore-default\"><span class=\"dashicons dashicons-image-rotate\"></span> %s</a></span></p>",
|
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"),
|
537 |
+
"{$home_url}{$prefix}{$native_uri}",
|
538 |
+
urldecode($native_uri)
|
539 |
+
);
|
540 |
+
}
|
541 |
$html .= "</div>";
|
542 |
|
543 |
$html .= "</div>";
|
573 |
$new_uri = (empty($_POST['custom_uri']) || $auto_update_uri == 1) ? $default_uri : trim($_POST['custom_uri'], "/");
|
574 |
|
575 |
// Do not store default values
|
576 |
+
// if(isset($permalink_manager_uris[$post->ID]) && ($new_uri == $native_uri)) {
|
577 |
+
// unset($permalink_manager_uris[$post->ID]);
|
578 |
+
// } else
|
579 |
+
|
580 |
// Save only changed URIs
|
581 |
+
if($new_uri != $old_uri) {
|
582 |
$permalink_manager_uris[$post->ID] = $new_uri;
|
583 |
}
|
584 |
|
includes/views/permalink-manager-permastructs.php
CHANGED
@@ -26,9 +26,11 @@ class Permalink_Manager_Permastructs extends Permalink_Manager_Class {
|
|
26 |
$woocommerce_icon = "<i class=\"woocommerce-icon woocommerce-cart\"></i>";
|
27 |
|
28 |
// 1. Get notes
|
29 |
-
$post_types_notes = wpautop(sprintf(__('All
|
30 |
$post_types_notes .= Permalink_Manager_Helper_Functions::get_all_structure_tags();
|
31 |
-
$post_types_notes .= wpautop(sprintf(__('Please note that some of them can be used only for particular post types
|
|
|
|
|
32 |
|
33 |
// 2. Get fields
|
34 |
$fields = array(
|
@@ -65,7 +67,9 @@ class Permalink_Manager_Permastructs extends Permalink_Manager_Class {
|
|
65 |
$fields["post_types"]["fields"][$post_type['name']] = array(
|
66 |
'label' => $post_type['label'],
|
67 |
'container' => 'row',
|
68 |
-
'input_class' => '',
|
|
|
|
|
69 |
'value' => $current_permastruct,
|
70 |
'placeholder' => $default_permastruct,
|
71 |
'type' => 'permastruct'
|
@@ -75,18 +79,28 @@ class Permalink_Manager_Permastructs extends Permalink_Manager_Class {
|
|
75 |
return apply_filters('permalink-manager-permastructs-fields', $fields);
|
76 |
}
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
/**
|
79 |
* Get the array with settings and render the HTML output
|
80 |
*/
|
81 |
public function output() {
|
82 |
global $permalink_manager_permastructs;
|
83 |
|
84 |
-
$
|
85 |
-
$
|
86 |
-
$
|
87 |
-
$output .= Permalink_Manager_Admin_Functions::get_the_form(self::get_fields(), '', array('text' => __( 'Save permastructures', 'permalink-manager' ), 'class' => 'primary margin-top'), '', array('action' => 'permalink-manager', 'name' => 'permalink_manager_permastructs'));
|
88 |
|
89 |
-
return $
|
90 |
}
|
91 |
|
92 |
}
|
26 |
$woocommerce_icon = "<i class=\"woocommerce-icon woocommerce-cart\"></i>";
|
27 |
|
28 |
// 1. Get notes
|
29 |
+
$post_types_notes = wpautop(sprintf(__('All allowed <a href="%s" target="_blank">structure tags</a> are listed below.', 'permalink-manager'), "https://codex.wordpress.org/Using_Permalinks#Structure_Tags"));
|
30 |
$post_types_notes .= Permalink_Manager_Helper_Functions::get_all_structure_tags();
|
31 |
+
$post_types_notes .= wpautop(sprintf(__('Please note that some of them can be used only for particular post types permastructures.', 'permalink-manager'), "https://codex.wordpress.org/Using_Permalinks#Structure_Tags"));
|
32 |
+
$post_types_notes .= __('<h5>Custom fields inside permastructures <small>(Permalink Manager Pro only)</small></h5>', 'permalink-manager');
|
33 |
+
$post_types_notes .= wpautop(__('To use the custom fields inside the permalink, please use following tag <code>%__custom_field_key%</code> and replace "<em>custom_field_key</em>" with the full name of your custom field key.', 'permalink-manager'));
|
34 |
|
35 |
// 2. Get fields
|
36 |
$fields = array(
|
67 |
$fields["post_types"]["fields"][$post_type['name']] = array(
|
68 |
'label' => $post_type['label'],
|
69 |
'container' => 'row',
|
70 |
+
'input_class' => 'permastruct-field',
|
71 |
+
'after_description' => self::restore_default_row($default_permastruct),
|
72 |
+
'extra_atts' => "data-default=\"{$default_permastruct}\"",
|
73 |
'value' => $current_permastruct,
|
74 |
'placeholder' => $default_permastruct,
|
75 |
'type' => 'permastruct'
|
79 |
return apply_filters('permalink-manager-permastructs-fields', $fields);
|
80 |
}
|
81 |
|
82 |
+
/**
|
83 |
+
* Restore default permastructure row
|
84 |
+
*/
|
85 |
+
public static function restore_default_row($default_permastruct) {
|
86 |
+
return sprintf(
|
87 |
+
"<p class=\"default-permastruct-row columns-container\"><span class=\"column-2_4\"><strong>%s:</strong> %s</span><span class=\"column-2_4\"><a href=\"#\" class=\"restore-default\"><span class=\"dashicons dashicons-image-rotate\"></span> %s</a></span></p>",
|
88 |
+
__("Default permastructure", "permalink-manager"), esc_html($default_permastruct),
|
89 |
+
__("Restore to Default Permastructure", "permalink-manager")
|
90 |
+
);
|
91 |
+
}
|
92 |
+
|
93 |
/**
|
94 |
* Get the array with settings and render the HTML output
|
95 |
*/
|
96 |
public function output() {
|
97 |
global $permalink_manager_permastructs;
|
98 |
|
99 |
+
$sidebar = '<h3>' . __('Important notices', 'permalink-manager') . '</h3>';
|
100 |
+
$sidebar .= wpautop(__('This tool <strong>automatically appends the slug to the end of permastructure</strong>, so there is no need to use them within the fields. To prevent the overlapping URLs problem please keep the permastructures unique.'));
|
101 |
+
$sidebar .= sprintf(wpautop(__('The current permastructures settings will be applied <strong>only to the new posts & terms</strong>. To apply the <strong>new permastructures to old posts & terms</strong>, please use "Regenerate/reset" tool available <a href="%s">here</a>.', 'bis')), admin_url('tools.php?page=permalink-manager§ion=tools&subsection=regenerate_slugs'));
|
|
|
102 |
|
103 |
+
return Permalink_Manager_Admin_Functions::get_the_form(self::get_fields(), '', array('text' => __( 'Save permastructures', 'permalink-manager' ), 'class' => 'primary margin-top'), $sidebar, array('action' => 'permalink-manager', 'name' => 'permalink_manager_permastructs'));
|
104 |
}
|
105 |
|
106 |
}
|
includes/views/permalink-manager-settings.php
CHANGED
@@ -36,14 +36,28 @@ class Permalink_Manager_Settings extends Permalink_Manager_Class {
|
|
36 |
'type' => 'single_checkbox',
|
37 |
'label' => __('Auto-update URIs', 'permalink-manager'),
|
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 |
)
|
48 |
),
|
49 |
'miscellaneous' => array(
|
@@ -67,7 +81,7 @@ class Permalink_Manager_Settings extends Permalink_Manager_Class {
|
|
67 |
'label' => __('Redirect', 'permalink-manager'),
|
68 |
'input_class' => 'settings-select',
|
69 |
'choices' => array(0 => __('Disable', 'permalink-manager'), "301" => __('Enable "301 redirect"', 'permalink-manager'), "302" => __('Enable "302 redirect"', 'permalink-manager')),
|
70 |
-
'description' => __('If enabled - the visitors will be redirected from native permalinks to your custom permalinks
|
71 |
)
|
72 |
)
|
73 |
)
|
36 |
'type' => 'single_checkbox',
|
37 |
'label' => __('Auto-update URIs', 'permalink-manager'),
|
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(
|
81 |
'label' => __('Redirect', 'permalink-manager'),
|
82 |
'input_class' => 'settings-select',
|
83 |
'choices' => array(0 => __('Disable', 'permalink-manager'), "301" => __('Enable "301 redirect"', 'permalink-manager'), "302" => __('Enable "302 redirect"', 'permalink-manager')),
|
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 |
)
|
includes/views/permalink-manager-upgrade.php
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Display the page where the slugs could be regenerated or replaced
|
5 |
+
*/
|
6 |
+
class Permalink_Manager_Upgrade extends Permalink_Manager_Class {
|
7 |
+
|
8 |
+
public function __construct() {
|
9 |
+
if(!defined('PERMALINK_MANAGER_PRO')) {
|
10 |
+
add_filter( 'permalink-manager-sections', array($this, 'add_upgrade_section'), 1 );
|
11 |
+
}
|
12 |
+
}
|
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 |
+
|
20 |
+
return $admin_sections;
|
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 & 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> <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 |
+
}
|
49 |
+
|
50 |
+
}
|
includes/views/permalink-manager-uri-editor-post.php
CHANGED
@@ -42,17 +42,17 @@ class Permalink_Manager_URI_Editor_Post extends WP_List_Table {
|
|
42 |
return $output;
|
43 |
}
|
44 |
|
|
|
|
|
|
|
|
|
45 |
/**
|
46 |
* Override the parent columns method. Defines the columns to use in your listing table
|
47 |
*/
|
48 |
public function get_columns() {
|
49 |
return apply_filters('permalink-manager-uri-editor-columns', array(
|
50 |
-
|
51 |
-
'
|
52 |
-
'post_name' => __('Post name (native slug)', 'permalink-manager'),
|
53 |
-
//'post_date_gmt' => __('Date', 'permalink-manager'),
|
54 |
-
'uri' => __('Full URI & Permalink', 'permalink-manager'),
|
55 |
-
'post_status' => __('Post status', 'permalink-manager'),
|
56 |
));
|
57 |
}
|
58 |
|
@@ -60,7 +60,7 @@ class Permalink_Manager_URI_Editor_Post extends WP_List_Table {
|
|
60 |
* Hidden columns
|
61 |
*/
|
62 |
public function get_hidden_columns() {
|
63 |
-
return array(
|
64 |
}
|
65 |
|
66 |
/**
|
@@ -68,9 +68,7 @@ class Permalink_Manager_URI_Editor_Post extends WP_List_Table {
|
|
68 |
*/
|
69 |
public function get_sortable_columns() {
|
70 |
return array(
|
71 |
-
'
|
72 |
-
'post_name' => array('post_name', false),
|
73 |
-
'post_status' => array('post_status', false),
|
74 |
);
|
75 |
}
|
76 |
|
@@ -81,28 +79,27 @@ class Permalink_Manager_URI_Editor_Post extends WP_List_Table {
|
|
81 |
$uri = Permalink_Manager_URI_Functions_Post::get_post_uri($item['ID'], true);
|
82 |
$field_args_base = array('type' => 'text', 'value' => $uri, 'without_label' => true, 'input_class' => '');
|
83 |
$permalink = get_permalink($item['ID']);
|
|
|
84 |
|
85 |
$output = apply_filters('permalink-manager-uri-editor-column-content', '', $column_name, get_post($item['ID']));
|
86 |
if(!empty($output)) { return $output; }
|
87 |
|
88 |
switch( $column_name ) {
|
89 |
-
case '
|
90 |
-
$post_statuses_array = get_post_statuses();
|
91 |
-
return "<span title=\"{$item[$column_name]}\">{$post_statuses_array[$item[$column_name]]}</span>";
|
92 |
-
|
93 |
-
case 'post_name':
|
94 |
-
$output = $item[ 'post_name' ];
|
95 |
-
return $output;
|
96 |
-
|
97 |
-
case 'uri':
|
98 |
$output = Permalink_Manager_Admin_Functions::generate_option_field("uri[{$item['ID']}]", $field_args_base);
|
99 |
$output .= "<a class=\"small post_permalink\" href=\"{$permalink}\" target=\"_blank\"><span class=\"dashicons dashicons-admin-links\"></span> {$permalink}</a>";
|
100 |
return $output;
|
101 |
|
102 |
-
case '
|
103 |
$output = $item[ 'post_title' ];
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
$output .= '<div class="row-actions">';
|
105 |
-
$output .=
|
106 |
$output .= '<span class="view"><a target="_blank" href="' . $permalink . '" title="' . __('View', 'permalink-manager') . ' ' . $item[ 'post_title' ] . '" rel="permalink">' . __('View', 'permalink-manager') . '</a> | </span>';
|
107 |
$output .= '<span class="id">#' . $item[ 'ID' ] . '</span>';
|
108 |
$output .= '</div>';
|
42 |
return $output;
|
43 |
}
|
44 |
|
45 |
+
function get_table_classes() {
|
46 |
+
return array( 'widefat', 'striped', $this->_args['plural'] );
|
47 |
+
}
|
48 |
+
|
49 |
/**
|
50 |
* Override the parent columns method. Defines the columns to use in your listing table
|
51 |
*/
|
52 |
public function get_columns() {
|
53 |
return apply_filters('permalink-manager-uri-editor-columns', array(
|
54 |
+
'item_title' => __('Post title', 'permalink-manager'),
|
55 |
+
'item_uri' => __('Full URI & Permalink', 'permalink-manager')
|
|
|
|
|
|
|
|
|
56 |
));
|
57 |
}
|
58 |
|
60 |
* Hidden columns
|
61 |
*/
|
62 |
public function get_hidden_columns() {
|
63 |
+
return array();
|
64 |
}
|
65 |
|
66 |
/**
|
68 |
*/
|
69 |
public function get_sortable_columns() {
|
70 |
return array(
|
71 |
+
'item_title' => array('post_title', false)
|
|
|
|
|
72 |
);
|
73 |
}
|
74 |
|
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();
|
83 |
|
84 |
$output = apply_filters('permalink-manager-uri-editor-column-content', '', $column_name, get_post($item['ID']));
|
85 |
if(!empty($output)) { return $output; }
|
86 |
|
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>';
|
100 |
+
|
101 |
$output .= '<div class="row-actions">';
|
102 |
+
$output .= sprintf("<span class=\"edit\"><a href=\"%s/wp-admin/post.php?post={$item['ID']}&action=edit\" title=\"%s\">%s</a> | </span>", home_url(), __('Edit', 'permalink-manager'), __('Edit', 'permalink-manager'));
|
103 |
$output .= '<span class="view"><a target="_blank" href="' . $permalink . '" title="' . __('View', 'permalink-manager') . ' ' . $item[ 'post_title' ] . '" rel="permalink">' . __('View', 'permalink-manager') . '</a> | </span>';
|
104 |
$output .= '<span class="id">#' . $item[ 'ID' ] . '</span>';
|
105 |
$output .= '</div>';
|
out/permalink-manager-admin.css
CHANGED
@@ -3,16 +3,16 @@
|
|
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 h4{font-size:18px;margin-bottom:10px}
|
7 |
#permalink-manager h5{font-size:15px;margin-bottom:10px}
|
8 |
-
#permalink-manager .structure-tags-list{display:block;line-height:175%}
|
9 |
-
#permalink-manager .structure-tags-list code{}
|
10 |
#permalink-manager .small{display:block;font-weight:400;color:#888;font-size:80%}
|
11 |
#permalink-manager .settings-select{min-width:200px}
|
12 |
#permalink-manager .fixed-table{max-width:100%;table-layout:fixed}
|
13 |
#permalink-manager .margin-top{margin-top:15px}
|
14 |
#permalink-manager .help_tooltip{text-decoration:none;color:#959595}
|
15 |
#permalink-manager .small-select{height:24px;line-height:22px;padding:0 8px 1px;font-size:11px}
|
|
|
16 |
|
17 |
#permalink-manager .woocommerce-icon:before{font-family:"WooCommerce";font-style:normal}
|
18 |
#permalink-manager .woocommerce-cart:before{content:"\e01d"}
|
@@ -27,12 +27,12 @@
|
|
27 |
#permalink-manager .tablenav.top{margin-top:0}
|
28 |
#permalink-manager .tablenav .actions{padding:0;overflow:visible}
|
29 |
#permalink-manager .tablenav #months-filter{margin-left:10px}
|
30 |
-
#permalink-manager .column-post_type,#permalink-manager .column-post_status,#permalink-manager .column-count,#permalink-manager .column-post_lang{width:13%}
|
31 |
-
#permalink-manager .column-count,#permalink-manager .column-post_lang,#permalink-manager th#count{text-align:center}
|
32 |
#permalink-manager th#count a{display:inline-block}
|
33 |
-
#permalink-manager .post_name input{max-width:100%}
|
34 |
#permalink-manager .post_permalink a,.post_permalink .dashicons{font-size:13px;color:#aaa;line-height:1.5em;height:auto;width:auto}
|
35 |
#permalink-manager .post_permalink{margin-top:5px;display:block}
|
|
|
|
|
|
|
36 |
|
37 |
#permalink-manager .info{box-shadow:0 1px 1px 0 rgba(0,0,0,.1);display:block;overflow:hidden;clear:both;font-weight:bold;border-left:4px solid #dc3232;}
|
38 |
#permalink-manager .alert,#permalink-manager .info{line-height:19px;padding:11px 15px;margin:15px 0}
|
@@ -64,11 +64,15 @@
|
|
64 |
#permalink-manager .appended-row td{padding-left:0;padding-right:0}
|
65 |
#permalink-manager #tools select{min-width:60%}
|
66 |
|
|
|
|
|
|
|
67 |
/**
|
68 |
* Columns
|
69 |
*/
|
70 |
#permalink-manager .columns-container{overflow:hidden;margin-left:-15px;margin-right:-15px;clear:both;display:block}
|
71 |
#permalink-manager .columns-container > *{float:left;padding-left:15px;padding-right:15px;box-sizing:border-box;-webkit-box-sizing:border-box;overflow:hidden;display:block}
|
|
|
72 |
#permalink-manager .columns-container .column-1_2,#permalink-manager .columns-container .column-2_4{width:50%}
|
73 |
#permalink-manager .columns-container .column-1_3{width:33.33%}
|
74 |
#permalink-manager .columns-container .column-2_3{width:66.67%}
|
@@ -85,13 +89,15 @@
|
|
85 |
#permalink-manager.permalink-manager-edit-uri-box .inside{padding:0 10px 10px 10px}
|
86 |
#permalink-manager.permalink-manager-edit-uri-box .strong{display:block;font-weight:bold;margin-bottom:5px}
|
87 |
#permalink-manager.permalink-manager-edit-uri-box .toggle-indicator:before{content:"\f142";display:inline-block;font:400 20px/1 dashicons}
|
88 |
-
#permalink-manager.permalink-manager-edit-uri-box .default-permalink-row{color:#aaa;font-size:90%;border-top:1px solid #eee;padding-top:10px}
|
89 |
-
#permalink-manager.permalink-manager-edit-uri-box #restore-default-uri{display:block;text-align:center;width:100%;border-radius:0;color:#959595;text-decoration:none}
|
90 |
#permalink-manager.permalink-manager-edit-uri-box .columns-container{margin-left:-10px;margin-right:-10px}
|
91 |
#permalink-manager.permalink-manager-edit-uri-box .columns-container > *{padding-left:10px;padding-right:10px}
|
92 |
#permalink-manager.permalink-manager-edit-uri-box .close-button{float:right;width:36px;height:36px;padding:0;cursor:pointer;display:block}
|
93 |
#permalink-manager.permalink-manager-edit-uri-box .close-icon{margin-top:4px;-webkit-border-radius:50%;border-radius:50%;text-indent:-1px;color:#72777c;line-height:36px;display:block;text-align:center}
|
94 |
#permalink-manager.permalink-manager-edit-uri-box .close-icon:before{content:"\f158";display:inline-block;font:400 20px/1 dashicons;speak:none;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-decoration:none!important}
|
|
|
|
|
|
|
|
|
95 |
|
96 |
/**
|
97 |
* Tippy.js custom theme
|
@@ -112,7 +118,14 @@
|
|
112 |
* Breakpoints
|
113 |
*/
|
114 |
@media only screen and (min-width :992px) {
|
115 |
-
#permalink-manager #permalink-manager-tab-nav .section_debug{float:right}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
}
|
117 |
@media only screen and (max-width :782px) {
|
118 |
#permalink-manager .columns-container .column-1_2,#permalink-manager .columns-container .column-1_3,#permalink-manager .columns-container .column-2_3{width:100%}
|
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%}
|
10 |
#permalink-manager .settings-select{min-width:200px}
|
11 |
#permalink-manager .fixed-table{max-width:100%;table-layout:fixed}
|
12 |
#permalink-manager .margin-top{margin-top:15px}
|
13 |
#permalink-manager .help_tooltip{text-decoration:none;color:#959595}
|
14 |
#permalink-manager .small-select{height:24px;line-height:22px;padding:0 8px 1px;font-size:11px}
|
15 |
+
#permalink-manager .lead{font-size:125%}
|
16 |
|
17 |
#permalink-manager .woocommerce-icon:before{font-family:"WooCommerce";font-style:normal}
|
18 |
#permalink-manager .woocommerce-cart:before{content:"\e01d"}
|
27 |
#permalink-manager .tablenav.top{margin-top:0}
|
28 |
#permalink-manager .tablenav .actions{padding:0;overflow:visible}
|
29 |
#permalink-manager .tablenav #months-filter{margin-left:10px}
|
|
|
|
|
30 |
#permalink-manager th#count a{display:inline-block}
|
|
|
31 |
#permalink-manager .post_permalink a,.post_permalink .dashicons{font-size:13px;color:#aaa;line-height:1.5em;height:auto;width:auto}
|
32 |
#permalink-manager .post_permalink{margin-top:5px;display:block}
|
33 |
+
#permalink-manager .column-count,#permalink-manager .column-post_lang{width:1%}
|
34 |
+
#permalink-manager .column-count,#permalink-manager .column-post_lang,#permalink-manager th#count{text-align:right}
|
35 |
+
#permalink-manager .extra-info span{white-space:nowrap}
|
36 |
|
37 |
#permalink-manager .info{box-shadow:0 1px 1px 0 rgba(0,0,0,.1);display:block;overflow:hidden;clear:both;font-weight:bold;border-left:4px solid #dc3232;}
|
38 |
#permalink-manager .alert,#permalink-manager .info{line-height:19px;padding:11px 15px;margin:15px 0}
|
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{}
|
69 |
+
|
70 |
/**
|
71 |
* Columns
|
72 |
*/
|
73 |
#permalink-manager .columns-container{overflow:hidden;margin-left:-15px;margin-right:-15px;clear:both;display:block}
|
74 |
#permalink-manager .columns-container > *{float:left;padding-left:15px;padding-right:15px;box-sizing:border-box;-webkit-box-sizing:border-box;overflow:hidden;display:block}
|
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%}
|
89 |
#permalink-manager.permalink-manager-edit-uri-box .inside{padding:0 10px 10px 10px}
|
90 |
#permalink-manager.permalink-manager-edit-uri-box .strong{display:block;font-weight:bold;margin-bottom:5px}
|
91 |
#permalink-manager.permalink-manager-edit-uri-box .toggle-indicator:before{content:"\f142";display:inline-block;font:400 20px/1 dashicons}
|
|
|
|
|
92 |
#permalink-manager.permalink-manager-edit-uri-box .columns-container{margin-left:-10px;margin-right:-10px}
|
93 |
#permalink-manager.permalink-manager-edit-uri-box .columns-container > *{padding-left:10px;padding-right:10px}
|
94 |
#permalink-manager.permalink-manager-edit-uri-box .close-button{float:right;width:36px;height:36px;padding:0;cursor:pointer;display:block}
|
95 |
#permalink-manager.permalink-manager-edit-uri-box .close-icon{margin-top:4px;-webkit-border-radius:50%;border-radius:50%;text-indent:-1px;color:#72777c;line-height:36px;display:block;text-align:center}
|
96 |
#permalink-manager.permalink-manager-edit-uri-box .close-icon:before{content:"\f158";display:inline-block;font:400 20px/1 dashicons;speak:none;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;text-decoration:none!important}
|
97 |
+
#permalink-manager .default-permalink-row{border-top:1px solid #eee;padding-top:10px}
|
98 |
+
#permalink-manager .default-permalink-row,#permalink-manager .default-permastruct-row{color:#aaa;font-size:90%}
|
99 |
+
#permalink-manager .restore-default{display:inline-block;text-align:right;width:100%;border-radius:0;color:#959595;text-decoration:none}
|
100 |
+
#permalink-manager .widefat{width:100% !important}
|
101 |
|
102 |
/**
|
103 |
* Tippy.js custom theme
|
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}
|
125 |
+
#permalink-manager .permastruct-field{width:100%}
|
126 |
+
|
127 |
+
#permalink-manager .column-item_uri{width:600px;max-width:100%}
|
128 |
+
#permalink-manager .column-item_uri input{width:100%}
|
129 |
}
|
130 |
@media only screen and (max-width :782px) {
|
131 |
#permalink-manager .columns-container .column-1_2,#permalink-manager .columns-container .column-1_3,#permalink-manager .columns-container .column-2_3{width:100%}
|
out/permalink-manager-admin.js
CHANGED
@@ -84,10 +84,9 @@ jQuery(document).ready(function() {
|
|
84 |
/**
|
85 |
* Restore "Default URI"
|
86 |
*/
|
87 |
-
jQuery('
|
88 |
-
jQuery('input[data-default
|
89 |
-
|
90 |
-
});
|
91 |
return false;
|
92 |
});
|
93 |
|
84 |
/**
|
85 |
* Restore "Default URI"
|
86 |
*/
|
87 |
+
jQuery('.restore-default').on('click', function() {
|
88 |
+
var input = jQuery(this).parents('.field-container, .permalink-manager-edit-uri-box').find('input[data-default]');
|
89 |
+
jQuery(input).val(jQuery(input).data('default')).trigger('keyup');
|
|
|
90 |
return false;
|
91 |
});
|
92 |
|
permalink-manager.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
<?php
|
2 |
|
3 |
/**
|
4 |
-
* Plugin Name: Permalink Manager
|
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.
|
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.
|
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__ ) ) );
|
@@ -67,6 +67,7 @@ class Permalink_Manager_Class {
|
|
67 |
'settings' => 'Permalink_Manager_Settings',
|
68 |
'debug' => 'Permalink_Manager_Debug',
|
69 |
'pro-addons' => 'Permalink_Manager_Pro_Addons',
|
|
|
70 |
'uri-editor-tax' => false,
|
71 |
'uri-editor-post' => false
|
72 |
)
|
@@ -96,15 +97,15 @@ class Permalink_Manager_Class {
|
|
96 |
add_action( 'init', array($this, 'get_options_and_globals'), 1 );
|
97 |
|
98 |
// Use the URIs set in this plugin + redirect from old URIs to new URIs + adjust canonical redirect settings
|
99 |
-
add_action( 'wp', array($this, 'disable_canonical_redirect'), 0, 1 );
|
100 |
add_action( 'template_redirect', array($this, 'redirect_to_new_uri'), 999);
|
101 |
add_filter( 'request', array($this, 'detect_post'), 0, 1 );
|
|
|
102 |
|
103 |
// Legacy support
|
104 |
add_action( 'init', array($this, 'legacy_support'), 2 );
|
105 |
|
106 |
// Check for updates
|
107 |
-
|
108 |
|
109 |
// Default settings & alerts
|
110 |
add_filter( 'permalink-manager-options', array($this, 'default_settings'), 1 );
|
@@ -152,16 +153,26 @@ class Permalink_Manager_Class {
|
|
152 |
'general' => array(
|
153 |
'force_custom_slugs' => 0,
|
154 |
'auto_update_uris' => 0,
|
|
|
|
|
155 |
),
|
156 |
'miscellaneous' => array(
|
157 |
'yoast_primary_term' => 1,
|
158 |
'redirect' => "302",
|
159 |
-
'canonical_redirect' => 1
|
160 |
)
|
161 |
));
|
162 |
|
163 |
// Apply the default settings (if empty values) in all settings sections
|
164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
}
|
166 |
|
167 |
/**
|
@@ -169,7 +180,14 @@ class Permalink_Manager_Class {
|
|
169 |
*/
|
170 |
public function default_alerts($alerts) {
|
171 |
$default_alerts = apply_filters('permalink-manager-default-alerts', array(
|
172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
));
|
174 |
|
175 |
// Apply the default settings (if empty values) in all settings sections
|
@@ -180,10 +198,10 @@ class Permalink_Manager_Class {
|
|
180 |
* Used to optimize SQL queries amount instead of rewrite rules - the essential part of this plugin
|
181 |
*/
|
182 |
function detect_post($query) {
|
183 |
-
global $wpdb, $permalink_manager_uris, $wp_filter;
|
184 |
|
185 |
// Check if any custom URI is used
|
186 |
-
if(!(is_array($permalink_manager_uris))) return $query;
|
187 |
|
188 |
// Used in debug mode
|
189 |
$old_query = $query;
|
@@ -228,6 +246,12 @@ class Permalink_Manager_Class {
|
|
228 |
// Trim slashes
|
229 |
$uri = trim($uri, "/");
|
230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
// Ignore URLs with no URI grabbed
|
232 |
if(empty($uri)) return $query;
|
233 |
|
@@ -246,6 +270,9 @@ class Permalink_Manager_Class {
|
|
246 |
$endpoint_value = $endpoint = "";
|
247 |
}
|
248 |
|
|
|
|
|
|
|
249 |
// Clear the original query before it is filtered
|
250 |
$query = ($item_id) ? array() : $query;
|
251 |
|
@@ -257,10 +284,10 @@ class Permalink_Manager_Class {
|
|
257 |
$item_id = preg_replace("/[^0-9]/", "", $item_id);
|
258 |
|
259 |
// Filter detected post ID
|
260 |
-
$item_id = apply_filters('permalink-manager-detected-term-id', $item_id, $uri_parts);
|
261 |
|
262 |
// Get the variables to filter wp_query and double-check if tax exists
|
263 |
-
$term = get_term($item_id);
|
264 |
if(empty($term->taxonomy)) { return $query; }
|
265 |
|
266 |
// Get some term data
|
@@ -278,7 +305,8 @@ class Permalink_Manager_Class {
|
|
278 |
}
|
279 |
}
|
280 |
|
281 |
-
//
|
|
|
282 |
$query[$query_parameter] = $final_uri;
|
283 |
}
|
284 |
/**
|
@@ -311,6 +339,8 @@ class Permalink_Manager_Class {
|
|
311 |
$query['pagename'] = $final_uri;
|
312 |
} else if($post_to_load->post_type == 'post') {
|
313 |
$query['name'] = $final_uri;
|
|
|
|
|
314 |
} else {
|
315 |
$query['name'] = $final_uri;
|
316 |
$query['post_type'] = $post_type;
|
@@ -345,34 +375,57 @@ class Permalink_Manager_Class {
|
|
345 |
}
|
346 |
|
347 |
function redirect_to_new_uri() {
|
348 |
-
global $
|
349 |
|
350 |
-
//
|
351 |
-
|
352 |
-
// Ignore posts with specific statuses
|
353 |
-
if(!(empty($wp_query->queried_object->post_status)) && in_array($wp_query->queried_object->post_status, array('draft', 'pending', 'auto-draft', 'future'))) {
|
354 |
-
return '';
|
355 |
-
}
|
356 |
|
357 |
-
|
358 |
-
$correct_permalink = get_permalink($wp_query->queried_object_id);
|
359 |
-
}
|
360 |
|
361 |
-
|
362 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
363 |
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
|
|
|
|
|
|
|
|
368 |
}
|
369 |
}
|
370 |
|
371 |
function disable_canonical_redirect() {
|
372 |
-
global $permalink_manager_options;
|
373 |
if(!($permalink_manager_options['miscellaneous']['canonical_redirect'])) {
|
374 |
remove_action('template_redirect', 'redirect_canonical');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
375 |
}
|
|
|
376 |
}
|
377 |
|
378 |
/**
|
@@ -397,19 +450,21 @@ class Permalink_Manager_Class {
|
|
397 |
public function check_for_updates() {
|
398 |
global $permalink_manager_options;
|
399 |
|
400 |
-
|
401 |
-
|
|
|
402 |
|
403 |
-
|
404 |
-
|
405 |
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
|
412 |
-
|
|
|
413 |
}
|
414 |
|
415 |
}
|
1 |
<?php
|
2 |
|
3 |
/**
|
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 |
// 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__ ) ) );
|
67 |
'settings' => 'Permalink_Manager_Settings',
|
68 |
'debug' => 'Permalink_Manager_Debug',
|
69 |
'pro-addons' => 'Permalink_Manager_Pro_Addons',
|
70 |
+
'upgrade' => 'Permalink_Manager_Upgrade',
|
71 |
'uri-editor-tax' => false,
|
72 |
'uri-editor-post' => false
|
73 |
)
|
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 );
|
153 |
'general' => array(
|
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
|
167 |
+
foreach($default_settings as $group_name => $fields) {
|
168 |
+
foreach($fields as $field_name => $field) {
|
169 |
+
if(!isset($settings[$group_name][$field_name])) {
|
170 |
+
$settings[$group_name][$field_name] = $field;
|
171 |
+
}
|
172 |
+
}
|
173 |
+
}
|
174 |
+
|
175 |
+
return $settings;
|
176 |
}
|
177 |
|
178 |
/**
|
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% 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 |
|
193 |
// Apply the default settings (if empty values) in all settings sections
|
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;
|
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 |
|
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 |
|
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
|
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 |
/**
|
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;
|
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 |
/**
|
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 |
|
470 |
}
|