Version Description
- Redirect for old URIs added.
- Debug tools added.
Download this release
Release Info
Developer | mbis |
Plugin | Permalink Manager Lite |
Version | 0.4.4 |
Comparing to | |
See all releases |
Code changes from version 0.4.3 to 0.4.4
- README.txt +5 -1
- inc/permalink-manager-actions.php +4 -5
- inc/permalink-manager-base-editor.php +2 -2
- permalink-manager.php +69 -6
README.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: mbis
|
|
3 |
Tags: urls, permalinks, slugs, custom url, custom permalinks, uris, url, slug, permalink
|
4 |
Requires at least: 4.0
|
5 |
Tested up to: 4.5.3
|
6 |
-
Stable tag: 0.4.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -82,6 +82,10 @@ After the plugin is installed you can access its dashboard from this page: `Tool
|
|
82 |
|
83 |
== Changelog ==
|
84 |
|
|
|
|
|
|
|
|
|
85 |
= 0.4.3 =
|
86 |
* Hotfix for "Screen Options" save process.
|
87 |
|
3 |
Tags: urls, permalinks, slugs, custom url, custom permalinks, uris, url, slug, permalink
|
4 |
Requires at least: 4.0
|
5 |
Tested up to: 4.5.3
|
6 |
+
Stable tag: 0.4.4
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
82 |
|
83 |
== Changelog ==
|
84 |
|
85 |
+
= 0.4.4 =
|
86 |
+
* Redirect for old URIs added.
|
87 |
+
* Debug tools added.
|
88 |
+
|
89 |
= 0.4.3 =
|
90 |
* Hotfix for "Screen Options" save process.
|
91 |
|
inc/permalink-manager-actions.php
CHANGED
@@ -209,21 +209,20 @@ class Permalink_Manager_Actions extends Permalink_Manager_Class {
|
|
209 |
static function update_permastructs() {
|
210 |
// Setup needed variables
|
211 |
$alert_type = $alert_content = $errors = $main_content = '';
|
212 |
-
$
|
213 |
$new_permastructs = array_filter($_POST['permalink-manager']['custom-permastructs']);
|
214 |
|
215 |
foreach($new_permastructs as $post_type => $new_permstruct) {
|
216 |
$default_permastruct = Permalink_Manager_Helper_Functions::get_default_permastruct($post_type, true);
|
217 |
-
$
|
218 |
-
$new_permastructs[$post_type] = trim(preg_replace('/\s+/', '', $new_permstruct), "/");
|
219 |
|
220 |
// Do not save default permastructs
|
221 |
if($default_permastruct == $new_permstruct) {
|
222 |
-
unset($
|
223 |
}
|
224 |
}
|
225 |
|
226 |
-
update_option('permalink-manager-permastructs', $
|
227 |
|
228 |
return "";
|
229 |
}
|
209 |
static function update_permastructs() {
|
210 |
// Setup needed variables
|
211 |
$alert_type = $alert_content = $errors = $main_content = '';
|
212 |
+
$permastructs = get_option('permalink-manager-permastructs', array());
|
213 |
$new_permastructs = array_filter($_POST['permalink-manager']['custom-permastructs']);
|
214 |
|
215 |
foreach($new_permastructs as $post_type => $new_permstruct) {
|
216 |
$default_permastruct = Permalink_Manager_Helper_Functions::get_default_permastruct($post_type, true);
|
217 |
+
$permastructs[$post_type] = trim(preg_replace('/\s+/', '', $new_permstruct), "/");
|
|
|
218 |
|
219 |
// Do not save default permastructs
|
220 |
if($default_permastruct == $new_permstruct) {
|
221 |
+
unset($permastructs[$post_type]);
|
222 |
}
|
223 |
}
|
224 |
|
225 |
+
update_option('permalink-manager-permastructs', $permastructs);
|
226 |
|
227 |
return "";
|
228 |
}
|
inc/permalink-manager-base-editor.php
CHANGED
@@ -126,7 +126,7 @@ class Permalink_Manager_Base_Editor extends WP_List_Table {
|
|
126 |
usort( $data, array( &$this, 'sort_data' ) );
|
127 |
|
128 |
// Pagination
|
129 |
-
$
|
130 |
|
131 |
$this->set_pagination_args( array(
|
132 |
'total_items' => $total_items,
|
@@ -134,7 +134,7 @@ class Permalink_Manager_Base_Editor extends WP_List_Table {
|
|
134 |
));
|
135 |
|
136 |
$this->_column_headers = array($columns, $hidden, $sortable);
|
137 |
-
$this->items = $
|
138 |
}
|
139 |
|
140 |
/**
|
126 |
usort( $data, array( &$this, 'sort_data' ) );
|
127 |
|
128 |
// Pagination
|
129 |
+
$sliced_data = array_slice($data, $offset, $per_page);
|
130 |
|
131 |
$this->set_pagination_args( array(
|
132 |
'total_items' => $total_items,
|
134 |
));
|
135 |
|
136 |
$this->_column_headers = array($columns, $hidden, $sortable);
|
137 |
+
$this->items = $sliced_data;
|
138 |
}
|
139 |
|
140 |
/**
|
permalink-manager.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
* Plugin Name: Permalink Manager
|
5 |
* Plugin URI: http://maciejbis.net/
|
6 |
* Description: A simple tool that allows to mass update of slugs that are used to build permalinks for Posts, Pages and Custom Post Types.
|
7 |
-
* Version: 0.4.
|
8 |
* Author: Maciej Bis
|
9 |
* Author URI: http://maciejbis.net/
|
10 |
* License: GPL-2.0+
|
@@ -20,7 +20,7 @@ if ( ! defined( 'WPINC' ) ) {
|
|
20 |
|
21 |
// Define the directories used to load plugin files.
|
22 |
define( 'PERMALINK_MANAGER_PLUGIN_NAME', 'permalink-manager' );
|
23 |
-
define( 'PERMALINK_MANAGER_VERSION', '0.4.
|
24 |
define( 'PERMALINK_MANAGER_DIR', untrailingslashit( dirname( __FILE__ ) ) );
|
25 |
define( 'PERMALINK_MANAGER_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) );
|
26 |
define( 'PERMALINK_MANAGER_WEBSITE', 'http://maciejbis.net' );
|
@@ -39,7 +39,8 @@ class Permalink_Manager_Class {
|
|
39 |
|
40 |
if( is_admin() ) {
|
41 |
add_action( 'plugins_loaded', array($this, 'localize_me') );
|
42 |
-
add_action( 'init', array($this, 'upgrade_plugin'),
|
|
|
43 |
add_action( 'wp_loaded', array($this, 'bulk_actions'), 1 );
|
44 |
add_action( 'admin_menu', array($this, 'add_menu_page') );
|
45 |
add_action( 'save_post', array($this, 'update_single_uri'), 10, 3 );
|
@@ -47,7 +48,8 @@ class Permalink_Manager_Class {
|
|
47 |
add_filter( 'get_sample_permalink_html', array($this, 'edit_uri_box'), 10, 4 );
|
48 |
}
|
49 |
|
50 |
-
add_action( 'wp_loaded', array($this, 'permalink_filters'),
|
|
|
51 |
|
52 |
}
|
53 |
|
@@ -488,9 +490,15 @@ class Permalink_Manager_Class {
|
|
488 |
*/
|
489 |
function detect_post($query) {
|
490 |
|
|
|
|
|
|
|
|
|
|
|
491 |
// GET URL
|
492 |
-
|
493 |
-
|
|
|
494 |
|
495 |
// Check if it is correct URL
|
496 |
if (filter_var($url, FILTER_VALIDATE_URL)) {
|
@@ -536,9 +544,51 @@ class Permalink_Manager_Class {
|
|
536 |
}
|
537 |
|
538 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
539 |
return $query;
|
540 |
}
|
541 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
542 |
/**
|
543 |
* Allow to edit URIs from "Edit Post" admin pages
|
544 |
*/
|
@@ -593,6 +643,19 @@ class Permalink_Manager_Class {
|
|
593 |
update_option('permalink-manager-uris', $uris);
|
594 |
}
|
595 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
596 |
/**
|
597 |
* Convert old plugin structure to the new solution (this function will be removed in 1.0 version)
|
598 |
*/
|
4 |
* Plugin Name: Permalink Manager
|
5 |
* Plugin URI: http://maciejbis.net/
|
6 |
* Description: A simple tool that allows to mass update of slugs that are used to build permalinks for Posts, Pages and Custom Post Types.
|
7 |
+
* Version: 0.4.4
|
8 |
* Author: Maciej Bis
|
9 |
* Author URI: http://maciejbis.net/
|
10 |
* License: GPL-2.0+
|
20 |
|
21 |
// Define the directories used to load plugin files.
|
22 |
define( 'PERMALINK_MANAGER_PLUGIN_NAME', 'permalink-manager' );
|
23 |
+
define( 'PERMALINK_MANAGER_VERSION', '0.4.4' );
|
24 |
define( 'PERMALINK_MANAGER_DIR', untrailingslashit( dirname( __FILE__ ) ) );
|
25 |
define( 'PERMALINK_MANAGER_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) );
|
26 |
define( 'PERMALINK_MANAGER_WEBSITE', 'http://maciejbis.net' );
|
39 |
|
40 |
if( is_admin() ) {
|
41 |
add_action( 'plugins_loaded', array($this, 'localize_me') );
|
42 |
+
add_action( 'init', array($this, 'upgrade_plugin'), 999 );
|
43 |
+
add_action( 'wp_loaded', array($this, 'debug_filters'), 999999999999 );
|
44 |
add_action( 'wp_loaded', array($this, 'bulk_actions'), 1 );
|
45 |
add_action( 'admin_menu', array($this, 'add_menu_page') );
|
46 |
add_action( 'save_post', array($this, 'update_single_uri'), 10, 3 );
|
48 |
add_filter( 'get_sample_permalink_html', array($this, 'edit_uri_box'), 10, 4 );
|
49 |
}
|
50 |
|
51 |
+
add_action( 'wp_loaded', array($this, 'permalink_filters'), 999);
|
52 |
+
add_action( 'template_redirect', array($this, 'redirect_to_new_uri'), 999);
|
53 |
|
54 |
}
|
55 |
|
490 |
*/
|
491 |
function detect_post($query) {
|
492 |
|
493 |
+
global $wpdb;
|
494 |
+
|
495 |
+
// Used in debug mode
|
496 |
+
$old_query = $query;
|
497 |
+
|
498 |
// GET URL
|
499 |
+
$protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https://' : 'http://';
|
500 |
+
// Fix for Wordpress installed in subdirectories
|
501 |
+
$url = str_replace(home_url(), "{$protocol}{$_SERVER['HTTP_HOST']}", "{$protocol}{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
|
502 |
|
503 |
// Check if it is correct URL
|
504 |
if (filter_var($url, FILTER_VALIDATE_URL)) {
|
544 |
}
|
545 |
|
546 |
}
|
547 |
+
|
548 |
+
// Debug mode
|
549 |
+
if(isset($_REQUEST['debug_url']) && $_REQUEST['debug_url'] == true) {
|
550 |
+
$debug_info['old_query_vars'] = $old_query;
|
551 |
+
$debug_info['new_query_vars'] = $query;
|
552 |
+
$debug_info['request'] = "{$protocol}{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
|
553 |
+
|
554 |
+
$debug_txt = json_encode($debug_info);
|
555 |
+
$debug_txt = "<textarea style=\"width:100%;height:300px\">{$debug_txt}</textarea>";
|
556 |
+
wp_die($debug_txt);
|
557 |
+
}
|
558 |
+
|
559 |
return $query;
|
560 |
}
|
561 |
|
562 |
+
function redirect_to_new_uri() {
|
563 |
+
global $wp;
|
564 |
+
|
565 |
+
$uris = $this->permalink_manager_uris;
|
566 |
+
$object_id = get_queried_object_id();
|
567 |
+
$uri = isset($uris[$object_id]) ? home_url('/') . $uris[$object_id] : "";
|
568 |
+
|
569 |
+
$protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https://' : 'http://';
|
570 |
+
$request_uri = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"];
|
571 |
+
|
572 |
+
// Get the option value (will be added in 0.5 with additional option panel)
|
573 |
+
$redirects_activated = 1;
|
574 |
+
|
575 |
+
// Ignore default URIs
|
576 |
+
if(!($uri)) return;
|
577 |
+
|
578 |
+
// Now get native URI & $_GET parameters
|
579 |
+
$old_default_uri = home_url('/') . Permalink_Manager_Helper_Functions::get_uri($object_id, 'native');
|
580 |
+
$correct_uri = str_replace($old_default_uri, $uri, $request_uri);
|
581 |
+
|
582 |
+
if (isset($_REQUEST['debug_redirect'])) {
|
583 |
+
wp_die("<strong>ID:</strong> {$object_id}<br /> <strong>URI:</strong> {$uri}<br/> <strong>Default URI:</strong> {$old_default_uri}<br /><strong>Correct URI:</strong> {$correct_uri}<br /><strong>Request URI</strong>{$request_uri}");
|
584 |
+
// Redirect if it is old URI
|
585 |
+
} else if(strpos($request_uri, $old_default_uri) !== false && ($redirects_activated == 1)) {
|
586 |
+
wp_redirect( $correct_uri );
|
587 |
+
exit();
|
588 |
+
}
|
589 |
+
|
590 |
+
}
|
591 |
+
|
592 |
/**
|
593 |
* Allow to edit URIs from "Edit Post" admin pages
|
594 |
*/
|
643 |
update_option('permalink-manager-uris', $uris);
|
644 |
}
|
645 |
|
646 |
+
/**
|
647 |
+
* Debug helper function
|
648 |
+
*/
|
649 |
+
function debug_filters() {
|
650 |
+
global $wp_filter;
|
651 |
+
if(isset($_REQUEST['debug_filter'])) {
|
652 |
+
$hook = $_REQUEST['debug_filter'];
|
653 |
+
$debug_txt = ($_REQUEST['debug_filter'] == "all") ? json_encode($wp_filter) : json_encode($wp_filter[$hook]);
|
654 |
+
$debug_txt = "<textarea style=\"width:100%;height:300px\">{$debug_txt}</textarea>";
|
655 |
+
wp_die($debug_txt);
|
656 |
+
}
|
657 |
+
}
|
658 |
+
|
659 |
/**
|
660 |
* Convert old plugin structure to the new solution (this function will be removed in 1.0 version)
|
661 |
*/
|