Version Description
- Hook for removed posts (their URI is now automatically removed)
Download this release
Release Info
Developer | mbis |
Plugin | Permalink Manager Lite |
Version | 0.4.9 |
Comparing to | |
See all releases |
Code changes from version 0.4.8 to 0.4.9
- README.txt +4 -1
- permalink-manager.php +35 -4
README.txt
CHANGED
@@ -5,7 +5,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
|
5 |
Tags: urls, permalinks, slugs, custom url, custom permalinks, uris, url, slug, permalink
|
6 |
Requires at least: 4.0
|
7 |
Tested up to: 4.6.1
|
8 |
-
Stable tag: 0.4.
|
9 |
|
10 |
Permalink Manager allows you to control how the permalinks for custom post types are created & regenerate them.
|
11 |
|
@@ -82,6 +82,9 @@ After the plugin is installed you can access its dashboard from this page: `Tool
|
|
82 |
|
83 |
== Changelog ==
|
84 |
|
|
|
|
|
|
|
85 |
= 0.4.8 =
|
86 |
* Pagination bug - SQL formula fix (offset variable)
|
87 |
|
5 |
Tags: urls, permalinks, slugs, custom url, custom permalinks, uris, url, slug, permalink
|
6 |
Requires at least: 4.0
|
7 |
Tested up to: 4.6.1
|
8 |
+
Stable tag: 0.4.9
|
9 |
|
10 |
Permalink Manager allows you to control how the permalinks for custom post types are created & regenerate them.
|
11 |
|
82 |
|
83 |
== Changelog ==
|
84 |
|
85 |
+
= 0.4.9 =
|
86 |
+
* Hook for removed posts (their URI is now automatically removed)
|
87 |
+
|
88 |
= 0.4.8 =
|
89 |
* Pagination bug - SQL formula fix (offset variable)
|
90 |
|
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' );
|
@@ -44,6 +44,7 @@ class Permalink_Manager_Class {
|
|
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 );
|
|
|
47 |
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugins_page_links') );
|
48 |
add_filter( 'get_sample_permalink_html', array($this, 'edit_uri_box'), 10, 4 );
|
49 |
}
|
@@ -55,7 +56,7 @@ class Permalink_Manager_Class {
|
|
55 |
|
56 |
function permalink_filters() {
|
57 |
// Public functions
|
58 |
-
add_filter( 'request', array($this, 'detect_post') );
|
59 |
add_filter( '_get_page_link', array($this, 'custom_permalinks'), 999, 2);
|
60 |
add_filter( 'page_link', array($this, 'custom_permalinks'), 999, 2);
|
61 |
add_filter( 'post_link', array($this, 'custom_permalinks'), 999, 2);
|
@@ -495,11 +496,16 @@ class Permalink_Manager_Class {
|
|
495 |
// Used in debug mode
|
496 |
$old_query = $query;
|
497 |
|
498 |
-
//
|
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)) {
|
505 |
|
@@ -521,6 +527,9 @@ class Permalink_Manager_Class {
|
|
521 |
if(!(is_array($uris))) return $query;
|
522 |
$post_id = array_search($uri, $uris);
|
523 |
|
|
|
|
|
|
|
524 |
if(isset($post_id) && is_numeric($post_id)) {
|
525 |
// Check if it is revision (hotfix) and use original post ID instead of revision ID
|
526 |
$is_revision = wp_is_post_revision($post_id);
|
@@ -542,8 +551,16 @@ class Permalink_Manager_Class {
|
|
542 |
}
|
543 |
}
|
544 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
545 |
// Alter query parameters
|
546 |
if($post_to_load->post_type == 'page') {
|
|
|
547 |
$query['pagename'] = $original_page_uri;
|
548 |
} else if($post_to_load->post_type == 'post') {
|
549 |
$query['name'] = $original_page_uri;
|
@@ -672,6 +689,20 @@ class Permalink_Manager_Class {
|
|
672 |
update_option('permalink-manager-uris', $uris);
|
673 |
}
|
674 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
675 |
/**
|
676 |
* Debug helper function
|
677 |
*/
|
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.9
|
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.9' );
|
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' );
|
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 );
|
47 |
+
add_action( 'wp_trash_post', array($this, 'remove_single_uri'), 10, 3 );
|
48 |
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugins_page_links') );
|
49 |
add_filter( 'get_sample_permalink_html', array($this, 'edit_uri_box'), 10, 4 );
|
50 |
}
|
56 |
|
57 |
function permalink_filters() {
|
58 |
// Public functions
|
59 |
+
add_filter( 'request', array($this, 'detect_post'), 0, 1 );
|
60 |
add_filter( '_get_page_link', array($this, 'custom_permalinks'), 999, 2);
|
61 |
add_filter( 'page_link', array($this, 'custom_permalinks'), 999, 2);
|
62 |
add_filter( 'post_link', array($this, 'custom_permalinks'), 999, 2);
|
496 |
// Used in debug mode
|
497 |
$old_query = $query;
|
498 |
|
499 |
+
// Get URL
|
500 |
$protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https://' : 'http://';
|
501 |
// Fix for Wordpress installed in subdirectories
|
502 |
$url = str_replace(home_url(), "{$protocol}{$_SERVER['HTTP_HOST']}", "{$protocol}{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
|
503 |
|
504 |
+
// Remove .html suffix from URL and query (URLs ended with .html work as aliases)
|
505 |
+
$url = str_replace(".html", "", $url);
|
506 |
+
if(isset($query['name'])) { $query['name'] = str_replace('.html', '', $query['name']); }
|
507 |
+
if(isset($query['pagename'])) { $query['pagename'] = str_replace('.html', '', $query['pagename']); }
|
508 |
+
|
509 |
// Check if it is correct URL
|
510 |
if (filter_var($url, FILTER_VALIDATE_URL)) {
|
511 |
|
527 |
if(!(is_array($uris))) return $query;
|
528 |
$post_id = array_search($uri, $uris);
|
529 |
|
530 |
+
// Check again in case someone added .html suffix to particular post (with .html suffix)
|
531 |
+
$post_id = (empty($post_id)) ? array_search("{$uri}.html", $uris) : $post_id;
|
532 |
+
|
533 |
if(isset($post_id) && is_numeric($post_id)) {
|
534 |
// Check if it is revision (hotfix) and use original post ID instead of revision ID
|
535 |
$is_revision = wp_is_post_revision($post_id);
|
551 |
}
|
552 |
}
|
553 |
|
554 |
+
// Fix for not-pages
|
555 |
+
if($post_to_load->post_type != 'post') {
|
556 |
+
unset($query['year']);
|
557 |
+
unset($query['monthnum']);
|
558 |
+
unset($query['day']);
|
559 |
+
}
|
560 |
+
|
561 |
// Alter query parameters
|
562 |
if($post_to_load->post_type == 'page') {
|
563 |
+
unset($query['name']);
|
564 |
$query['pagename'] = $original_page_uri;
|
565 |
} else if($post_to_load->post_type == 'post') {
|
566 |
$query['name'] = $original_page_uri;
|
689 |
update_option('permalink-manager-uris', $uris);
|
690 |
}
|
691 |
|
692 |
+
/**
|
693 |
+
* Remove URI from options array after post is moved to the trash
|
694 |
+
*/
|
695 |
+
function remove_single_uri($post_id) {
|
696 |
+
$uris = $this->permalink_manager_uris;
|
697 |
+
|
698 |
+
// Check if the custom permalink is assigned to this post
|
699 |
+
if(isset($uris[$post_id])) {
|
700 |
+
unset($uris[$post_id]);
|
701 |
+
}
|
702 |
+
|
703 |
+
update_option('permalink-manager-uris', $uris);
|
704 |
+
}
|
705 |
+
|
706 |
/**
|
707 |
* Debug helper function
|
708 |
*/
|