Version Description
- Fixed Slug issue with Yoast SEO
Download this release
Release Info
Developer | sasiddiqui |
Plugin | Custom Permalinks |
Version | 1.2.4 |
Comparing to | |
See all releases |
Code changes from version 1.2.3 to 1.2.4
- README.md +0 -22
- admin/class-custom-permalinks-admin.php +1 -0
- custom-permalinks-main.php +2 -2
- custom-permalinks.php +1 -1
- frontend/class-custom-permalinks-form.php +339 -0
- frontend/class-custom-permalinks-frontend.php +2 -2
- frontend/js/script-form.js +51 -0
- frontend/js/script-form.min.js +1 -0
- languages/index.php +4 -0
- readme.txt +5 -1
README.md
DELETED
@@ -1,22 +0,0 @@
|
|
1 |
-
# Custom Permalinks
|
2 |
-
|
3 |
-
## Description
|
4 |
-
|
5 |
-
Lay out your site the way *you* want it. Set the URL of any post, page, tag or category to anything you want.
|
6 |
-
Old permalinks will redirect properly to the new address. Custom Permalinks gives you ultimate control
|
7 |
-
over your site structure.
|
8 |
-
|
9 |
-
Be warned: *This plugin is not a replacement for WordPress's built-in permalink system*. Check your WordPress
|
10 |
-
administration's "Permalinks" settings page first, to make sure that this doesn't already meet your needs.
|
11 |
-
|
12 |
-
This plugin is only useful for assigning custom permalinks for *individual* posts, pages, tags or categories.
|
13 |
-
It will not apply whole permalink structures, or automatically apply a category's custom permalink to the posts
|
14 |
-
within that category.
|
15 |
-
|
16 |
-
> If anyone wants the different Structure Tags for their Post types or use symbols in the URLs So, use the [Permalinks Customizer](https://wordpress.org/plugins/permalinks-customizer/) which is a fork of this plugin and contains the enhancement of this plugin.
|
17 |
-
|
18 |
-
## Installation
|
19 |
-
|
20 |
-
1. Unzip the package, and upload `custom-permalinks` to the `/wp-content/plugins/` directory
|
21 |
-
2. Activate the plugin through the 'Plugins' menu in WordPress
|
22 |
-
3. Edit any post, page, tag or category to set a custom permalink.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
admin/class-custom-permalinks-admin.php
CHANGED
@@ -27,6 +27,7 @@ class Custom_Permalinks_Admin {
|
|
27 |
public function custom_permalinks_post_permalinks() {
|
28 |
global $wpdb;
|
29 |
$filter_options = '';
|
|
|
30 |
$search_permalink = '';
|
31 |
$html = '';
|
32 |
$error = '';
|
27 |
public function custom_permalinks_post_permalinks() {
|
28 |
global $wpdb;
|
29 |
$filter_options = '';
|
30 |
+
$filter_permalink = '';
|
31 |
$search_permalink = '';
|
32 |
$html = '';
|
33 |
$error = '';
|
custom-permalinks-main.php
CHANGED
@@ -15,7 +15,7 @@ if ( ! function_exists( "add_action" ) || ! function_exists( "add_filter" ) ) {
|
|
15 |
exit();
|
16 |
}
|
17 |
|
18 |
-
define( 'CUSTOM_PERMALINKS_PLUGIN_VERSION', '1.2.
|
19 |
|
20 |
if ( ! defined( 'CUSTOM_PERMALINKS_PATH' ) ) {
|
21 |
define( 'CUSTOM_PERMALINKS_PATH', plugin_dir_path( __FILE__ ) );
|
@@ -25,7 +25,7 @@ require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-fronten
|
|
25 |
$custom_permalinks_frontend = new Custom_Permalinks_Frontend();
|
26 |
$custom_permalinks_frontend->init();
|
27 |
|
28 |
-
require_once( CUSTOM_PERMALINKS_PATH . '
|
29 |
$custom_permalinks_form = new Custom_Permalinks_Form();
|
30 |
$custom_permalinks_form->init();
|
31 |
|
15 |
exit();
|
16 |
}
|
17 |
|
18 |
+
define( 'CUSTOM_PERMALINKS_PLUGIN_VERSION', '1.2.4' );
|
19 |
|
20 |
if ( ! defined( 'CUSTOM_PERMALINKS_PATH' ) ) {
|
21 |
define( 'CUSTOM_PERMALINKS_PATH', plugin_dir_path( __FILE__ ) );
|
25 |
$custom_permalinks_frontend = new Custom_Permalinks_Frontend();
|
26 |
$custom_permalinks_frontend->init();
|
27 |
|
28 |
+
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-form.php' );
|
29 |
$custom_permalinks_form = new Custom_Permalinks_Form();
|
30 |
$custom_permalinks_form->init();
|
31 |
|
custom-permalinks.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
* Plugin Name: Custom Permalinks
|
5 |
* Plugin URI: https://wordpress.org/plugins/custom-permalinks/
|
6 |
* Description: Set custom permalinks on a per-post basis
|
7 |
-
* Version: 1.2.
|
8 |
* Author: Sami Ahmed Siddiqui
|
9 |
* Author URI: https://www.yasglobal.com/web-design-development/wordpress/custom-permalinks/
|
10 |
* Donate link: https://www.paypal.me/yasglobal
|
4 |
* Plugin Name: Custom Permalinks
|
5 |
* Plugin URI: https://wordpress.org/plugins/custom-permalinks/
|
6 |
* Description: Set custom permalinks on a per-post basis
|
7 |
+
* Version: 1.2.4
|
8 |
* Author: Sami Ahmed Siddiqui
|
9 |
* Author URI: https://www.yasglobal.com/web-design-development/wordpress/custom-permalinks/
|
10 |
* Donate link: https://www.paypal.me/yasglobal
|
frontend/class-custom-permalinks-form.php
ADDED
@@ -0,0 +1,339 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package CustomPermalinks\Admin\Form
|
4 |
+
*/
|
5 |
+
|
6 |
+
class Custom_Permalinks_Form {
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Initialize WordPress Hooks
|
10 |
+
*/
|
11 |
+
public function init() {
|
12 |
+
|
13 |
+
add_filter( 'get_sample_permalink_html', array( $this, 'custom_permalinks_get_sample_permalink_html' ), 10, 4 );
|
14 |
+
|
15 |
+
add_action( 'save_post', array( $this, 'custom_permalinks_save_post' ), 10, 3 );
|
16 |
+
add_action( 'delete_post', array( $this, 'custom_permalinks_delete_permalink' ), 10 );
|
17 |
+
|
18 |
+
add_action( 'edit_tag_form', array( $this, 'custom_permalinks_term_options' ) );
|
19 |
+
add_action( 'add_tag_form', array( $this, 'custom_permalinks_term_options' ) );
|
20 |
+
add_action( 'edit_category_form', array( $this, 'custom_permalinks_term_options' ) );
|
21 |
+
|
22 |
+
add_action( 'edited_post_tag', array( $this, 'custom_permalinks_save_tag' ) );
|
23 |
+
add_action( 'edited_category', array( $this, 'custom_permalinks_save_category' ) );
|
24 |
+
add_action( 'create_post_tag', array( $this, 'custom_permalinks_save_tag' ) );
|
25 |
+
add_action( 'create_category', array( $this, 'custom_permalinks_save_category' ) );
|
26 |
+
add_action( 'delete_post_tag', array( $this, 'custom_permalinks_delete_term' ) );
|
27 |
+
add_action( 'delete_post_category', array( $this, 'custom_permalinks_delete_term' ) );
|
28 |
+
}
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Save per-post options
|
32 |
+
*/
|
33 |
+
public function custom_permalinks_save_post( $id ) {
|
34 |
+
if ( ! isset( $_REQUEST['custom_permalinks_edit'] ) ) {
|
35 |
+
return;
|
36 |
+
}
|
37 |
+
|
38 |
+
delete_post_meta( $id, 'custom_permalink' );
|
39 |
+
|
40 |
+
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
|
41 |
+
$custom_permalinks_frontend = new Custom_Permalinks_Frontend();
|
42 |
+
$original_link = $custom_permalinks_frontend->custom_permalinks_original_post_link( $id );
|
43 |
+
$permalink_structure = get_option( 'permalink_structure' );
|
44 |
+
|
45 |
+
if ( $_REQUEST['custom_permalink'] && $_REQUEST['custom_permalink'] != $original_link ) {
|
46 |
+
add_post_meta( $id, 'custom_permalink',
|
47 |
+
str_replace( '%2F', '/',
|
48 |
+
urlencode( ltrim( stripcslashes( $_REQUEST['custom_permalink'] ), "/" ) )
|
49 |
+
)
|
50 |
+
);
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Delete post
|
56 |
+
*/
|
57 |
+
public function custom_permalinks_delete_permalink( $id ) {
|
58 |
+
global $wpdb;
|
59 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = 'custom_permalink' AND post_id = %d", $id ) );
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Per-post/page options (Wordpress > 2.9)
|
64 |
+
*/
|
65 |
+
public function custom_permalinks_get_sample_permalink_html( $html, $id, $new_title, $new_slug ) {
|
66 |
+
$permalink = get_post_meta( $id, 'custom_permalink', true );
|
67 |
+
$post = get_post( $id );
|
68 |
+
|
69 |
+
if ( $post->post_type == 'attachment' || $post->ID == get_option( 'page_on_front' ) ) {
|
70 |
+
return $html;
|
71 |
+
}
|
72 |
+
ob_start();
|
73 |
+
|
74 |
+
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
|
75 |
+
$custom_permalinks_frontend = new Custom_Permalinks_Frontend();
|
76 |
+
if ( $post->post_type == "page" ) {
|
77 |
+
$original_page_url = $custom_permalinks_frontend->custom_permalinks_original_page_link( $id );
|
78 |
+
$this->custom_permalinks_get_form( $permalink, $original_page_url, false, $post->post_name );
|
79 |
+
} else {
|
80 |
+
$original_post_url = $custom_permalinks_frontend->custom_permalinks_original_post_link( $id );
|
81 |
+
$this->custom_permalinks_get_form( $permalink, $original_post_url, false, $post->post_name );
|
82 |
+
}
|
83 |
+
|
84 |
+
$content = ob_get_contents();
|
85 |
+
ob_end_clean();
|
86 |
+
|
87 |
+
if ( 'publish' == $post->post_status ) {
|
88 |
+
$view_post = 'page' == $post->post_type ? __( 'View Page', 'custom-permalinks' ) : __( 'View Post', 'custom-permalinks' );
|
89 |
+
}
|
90 |
+
|
91 |
+
if ( preg_match( "@view-post-btn.*?href='([^']+)'@s", $html, $matches ) ) {
|
92 |
+
$permalink = $matches[1];
|
93 |
+
} else {
|
94 |
+
list( $permalink, $post_name ) = get_sample_permalink( $post->ID, $new_title, $new_slug );
|
95 |
+
if ( false !== strpos( $permalink, '%postname%' )
|
96 |
+
|| false !== strpos( $permalink, '%pagename%' ) ) {
|
97 |
+
$permalink = str_replace( array( '%pagename%','%postname%' ), $post_name, $permalink );
|
98 |
+
}
|
99 |
+
}
|
100 |
+
|
101 |
+
return '<strong>' . __( 'Permalink:', 'custom-permalinks' ) . "</strong>\n" . $content .
|
102 |
+
( isset( $view_post ) ? "<span id='view-post-btn'><a href='$permalink' class='button button-small' target='_blank'>$view_post</a></span>\n" : "" );
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Per-post options (Wordpress < 2.9)
|
107 |
+
*/
|
108 |
+
public function custom_permalinks_post_options() {
|
109 |
+
global $post;
|
110 |
+
$post_id = $post;
|
111 |
+
if ( is_object( $post_id ) ) {
|
112 |
+
$post_id = $post_id->ID;
|
113 |
+
}
|
114 |
+
|
115 |
+
$permalink = get_post_meta( $post_id, 'custom_permalink', true );
|
116 |
+
?>
|
117 |
+
<div class="postbox closed">
|
118 |
+
<h3><?php _e( 'Custom Permalink', 'custom-permalinks' ) ?></h3>
|
119 |
+
<div class="inside">
|
120 |
+
<?php
|
121 |
+
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
|
122 |
+
$custom_permalinks_frontend = new Custom_Permalinks_Frontend();
|
123 |
+
$custom_permalinks_frontend->custom_permalinks_get_form( $permalink, $custom_permalinks_frontend->custom_permalinks_original_post_link( $post_id ) );
|
124 |
+
?>
|
125 |
+
</div>
|
126 |
+
</div>
|
127 |
+
<?php
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Per-page options (Wordpress < 2.9)
|
132 |
+
*/
|
133 |
+
public function custom_permalinks_page_options() {
|
134 |
+
global $post;
|
135 |
+
$post_id = $post;
|
136 |
+
if (is_object( $post_id ) ) {
|
137 |
+
$post_id = $post_id->ID;
|
138 |
+
}
|
139 |
+
|
140 |
+
$permalink = get_post_meta( $post_id, 'custom_permalink', true );
|
141 |
+
|
142 |
+
?>
|
143 |
+
<div class="postbox closed">
|
144 |
+
<h3><?php _e( 'Custom Permalink', 'custom-permalinks' ); ?></h3>
|
145 |
+
<div class="inside">
|
146 |
+
<?php
|
147 |
+
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
|
148 |
+
$custom_permalinks_frontend = new Custom_Permalinks_Frontend();
|
149 |
+
$page_permalink = $custom_permalinks_frontend->custom_permalinks_original_page_link( $post_id );
|
150 |
+
$this->custom_permalinks_get_form( $permalink, $page_permalink );
|
151 |
+
?>
|
152 |
+
</div>
|
153 |
+
</div>
|
154 |
+
<?php
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Per-category/tag options
|
159 |
+
*/
|
160 |
+
public function custom_permalinks_term_options( $object ) {
|
161 |
+
if ( is_object( $object ) && isset( $object->term_id ) ) {
|
162 |
+
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
|
163 |
+
$custom_permalinks_frontend = new Custom_Permalinks_Frontend();
|
164 |
+
$permalink = $custom_permalinks_frontend->custom_permalinks_permalink_for_term( $object->term_id );
|
165 |
+
|
166 |
+
if ( $object->term_id ) {
|
167 |
+
if ( $object->taxonomy == 'post_tag' ) {
|
168 |
+
$originalPermalink = $custom_permalinks_frontend->custom_permalinks_original_tag_link( $object->term_id );
|
169 |
+
} else {
|
170 |
+
$originalPermalink = $custom_permalinks_frontend->custom_permalinks_original_category_link( $object->term_id );
|
171 |
+
}
|
172 |
+
}
|
173 |
+
|
174 |
+
$this->custom_permalinks_get_form( $permalink, $originalPermalink );
|
175 |
+
} else {
|
176 |
+
$this->custom_permalinks_get_form( '' );
|
177 |
+
}
|
178 |
+
|
179 |
+
// Move the save button to above this form
|
180 |
+
wp_enqueue_script( 'jquery' );
|
181 |
+
?>
|
182 |
+
<script type="text/javascript">
|
183 |
+
jQuery(document).ready(function() {
|
184 |
+
var button = jQuery('#custom_permalink_form').parent().find('.submit');
|
185 |
+
button.remove().insertAfter(jQuery('#custom_permalink_form'));
|
186 |
+
});
|
187 |
+
</script>
|
188 |
+
<?php
|
189 |
+
}
|
190 |
+
|
191 |
+
/**
|
192 |
+
* Helper function to render form
|
193 |
+
*/
|
194 |
+
private function custom_permalinks_get_form( $permalink, $original = "", $renderContainers = true, $postname = "" ) {
|
195 |
+
?>
|
196 |
+
<input value="true" type="hidden" name="custom_permalinks_edit" />
|
197 |
+
<input value="<?php echo home_url(); ?>" type="hidden" name="custom_permalinks_home_url" id="custom_permalinks_home_url" />
|
198 |
+
<input value="<?php echo htmlspecialchars( urldecode( $permalink ) ); ?>" type="hidden" name="custom_permalink" id="custom_permalink" />
|
199 |
+
|
200 |
+
<?php
|
201 |
+
if ( $renderContainers ) :
|
202 |
+
?>
|
203 |
+
<table class="form-table" id="custom_permalink_form">
|
204 |
+
<tr>
|
205 |
+
<th scope="row"><?php _e( 'Custom Permalink', 'custom-permalinks' ); ?></th>
|
206 |
+
<td>
|
207 |
+
<?php
|
208 |
+
endif;
|
209 |
+
if ( $permalink == '' ) {
|
210 |
+
$original = $this->custom_permalinks_check_conflicts( $original );
|
211 |
+
}
|
212 |
+
$post_slug = htmlspecialchars( $permalink ? urldecode( $permalink ) : urldecode( $original ) );
|
213 |
+
$original_encoded_url = htmlspecialchars( urldecode( $original ) );
|
214 |
+
wp_enqueue_script( 'custom-permalinks-form', plugins_url( '/js/script-form.min.js', __FILE__ ), array(), false, true );
|
215 |
+
$postname_html = '';
|
216 |
+
if ( isset( $postname ) && $postname != "" ) {
|
217 |
+
$postname_html = '<input type="hidden" id="new-post-slug" class="text" value="' . $postname . '" />';
|
218 |
+
}
|
219 |
+
|
220 |
+
echo home_url() . '/<span id="editable-post-name" title="Click to edit this part of the permalink">' . $postname_html;
|
221 |
+
|
222 |
+
?>
|
223 |
+
<input type="text" id="custom-permalinks-post-slug" class="text" value="<?php echo $post_slug; ?>"
|
224 |
+
style="width: 250px; <?php if ( !$permalink ) echo 'color: #ddd'; ?>"
|
225 |
+
onfocus="if ( this.style.color = '#ddd' ) { this.style.color = '#000'; }"
|
226 |
+
onblur="document.getElementById('custom_permalink').value = this.value; if ( this.value == '' || this.value == '<?php echo $original_encoded_url; ?>' ) { this.value = '<?php echo $original_encoded_url; ?>'; this.style.color = '#ddd'; }" />
|
227 |
+
</span>
|
228 |
+
|
229 |
+
<?php if ( $renderContainers ) : ?>
|
230 |
+
<br />
|
231 |
+
<small><?php _e( 'Leave blank to disable', 'custom-permalinks' ); ?></small>
|
232 |
+
</td>
|
233 |
+
</tr>
|
234 |
+
</table>
|
235 |
+
<?php
|
236 |
+
endif;
|
237 |
+
}
|
238 |
+
|
239 |
+
/**
|
240 |
+
* Save per-tag options
|
241 |
+
*/
|
242 |
+
public function custom_permalinks_save_tag( $id ) {
|
243 |
+
if ( ! isset( $_REQUEST['custom_permalinks_edit'] )
|
244 |
+
|| isset( $_REQUEST['post_ID'] ) ) {
|
245 |
+
return;
|
246 |
+
}
|
247 |
+
$newPermalink = ltrim( stripcslashes( $_REQUEST['custom_permalink'] ), "/" );
|
248 |
+
|
249 |
+
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
|
250 |
+
$custom_permalinks_frontend = new Custom_Permalinks_Frontend();
|
251 |
+
if ( $newPermalink == $custom_permalinks_frontend->custom_permalinks_original_tag_link( $id ) ) {
|
252 |
+
$newPermalink = '';
|
253 |
+
}
|
254 |
+
|
255 |
+
$term = get_term( $id, 'post_tag' );
|
256 |
+
$this->custom_permalinks_save_term( $term, str_replace( '%2F', '/', urlencode( $newPermalink ) ) );
|
257 |
+
}
|
258 |
+
|
259 |
+
/**
|
260 |
+
* Save per-category options
|
261 |
+
*/
|
262 |
+
public function custom_permalinks_save_category( $id ) {
|
263 |
+
if ( ! isset( $_REQUEST['custom_permalinks_edit'] )
|
264 |
+
|| isset( $_REQUEST['post_ID'] ) ) {
|
265 |
+
return;
|
266 |
+
}
|
267 |
+
$newPermalink = ltrim( stripcslashes( $_REQUEST['custom_permalink'] ), "/" );
|
268 |
+
|
269 |
+
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
|
270 |
+
$custom_permalinks_frontend = new Custom_Permalinks_Frontend();
|
271 |
+
if ( $newPermalink == $custom_permalinks_frontend->custom_permalinks_original_category_link( $id ) ) {
|
272 |
+
$newPermalink = '';
|
273 |
+
}
|
274 |
+
|
275 |
+
$term = get_term( $id, 'category' );
|
276 |
+
$this->custom_permalinks_save_term( $term, str_replace( '%2F', '/', urlencode( $newPermalink ) ) );
|
277 |
+
}
|
278 |
+
|
279 |
+
/**
|
280 |
+
* Save term (common to tags and categories)
|
281 |
+
*/
|
282 |
+
public function custom_permalinks_save_term( $term, $permalink ) {
|
283 |
+
|
284 |
+
$this->custom_permalinks_delete_term( $term->term_id );
|
285 |
+
$table = get_option( 'custom_permalink_table' );
|
286 |
+
if ( $permalink ) {
|
287 |
+
$table[$permalink] = array(
|
288 |
+
'id' => $term->term_id,
|
289 |
+
'kind' => ( $term->taxonomy == 'category' ? 'category' : 'tag' ),
|
290 |
+
'slug' => $term->slug
|
291 |
+
);
|
292 |
+
}
|
293 |
+
|
294 |
+
update_option( 'custom_permalink_table', $table );
|
295 |
+
}
|
296 |
+
|
297 |
+
/**
|
298 |
+
* Delete term
|
299 |
+
*/
|
300 |
+
public function custom_permalinks_delete_term( $id ) {
|
301 |
+
$table = get_option( 'custom_permalink_table' );
|
302 |
+
if ( $table ) {
|
303 |
+
foreach ( $table as $link => $info ) {
|
304 |
+
if ( $info['id'] == $id ) {
|
305 |
+
unset( $table[$link] );
|
306 |
+
break;
|
307 |
+
}
|
308 |
+
}
|
309 |
+
}
|
310 |
+
update_option( 'custom_permalink_table', $table );
|
311 |
+
}
|
312 |
+
|
313 |
+
/**
|
314 |
+
* Check Conflicts and resolve it (e.g: Polylang)
|
315 |
+
*/
|
316 |
+
public function custom_permalinks_check_conflicts( $requested_url = '' ) {
|
317 |
+
if ( $requested_url == '' ) {
|
318 |
+
return;
|
319 |
+
}
|
320 |
+
|
321 |
+
// Check if the Polylang Plugin is installed so, make changes in the URL
|
322 |
+
if ( defined( 'POLYLANG_VERSION' ) ) {
|
323 |
+
$polylang_config = get_option( 'polylang' );
|
324 |
+
if ( $polylang_config['force_lang'] == 1 ) {
|
325 |
+
|
326 |
+
if ( strpos( $requested_url, 'language/' ) !== false ) {
|
327 |
+
$requested_url = str_replace( "language/", "", $requested_url );
|
328 |
+
}
|
329 |
+
|
330 |
+
$remove_lang = ltrim( strstr( $requested_url, '/' ), '/' );
|
331 |
+
if ( $remove_lang != '' ) {
|
332 |
+
return $remove_lang;
|
333 |
+
}
|
334 |
+
}
|
335 |
+
}
|
336 |
+
return $requested_url;
|
337 |
+
}
|
338 |
+
|
339 |
+
}
|
frontend/class-custom-permalinks-frontend.php
CHANGED
@@ -52,7 +52,7 @@ class Custom_Permalinks_Frontend {
|
|
52 |
}
|
53 |
|
54 |
if ( defined( 'POLYLANG_VERSION' ) ) {
|
55 |
-
require_once( CUSTOM_PERMALINKS_PATH . '
|
56 |
$custom_permalinks_form = new Custom_Permalinks_Form();
|
57 |
$request = $custom_permalinks_form->custom_permalinks_check_conflicts( $request );
|
58 |
}
|
@@ -182,7 +182,7 @@ class Custom_Permalinks_Frontend {
|
|
182 |
}
|
183 |
|
184 |
if ( defined( 'POLYLANG_VERSION' ) ) {
|
185 |
-
require_once( CUSTOM_PERMALINKS_PATH . '
|
186 |
$custom_permalinks_form = new Custom_Permalinks_Form();
|
187 |
$request = $custom_permalinks_form->custom_permalinks_check_conflicts( $request );
|
188 |
}
|
52 |
}
|
53 |
|
54 |
if ( defined( 'POLYLANG_VERSION' ) ) {
|
55 |
+
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-form.php' );
|
56 |
$custom_permalinks_form = new Custom_Permalinks_Form();
|
57 |
$request = $custom_permalinks_form->custom_permalinks_check_conflicts( $request );
|
58 |
}
|
182 |
}
|
183 |
|
184 |
if ( defined( 'POLYLANG_VERSION' ) ) {
|
185 |
+
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-form.php' );
|
186 |
$custom_permalinks_form = new Custom_Permalinks_Form();
|
187 |
$request = $custom_permalinks_form->custom_permalinks_check_conflicts( $request );
|
188 |
}
|
frontend/js/script-form.js
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var getHomeURL = document.getElementById( 'custom_permalinks_home_url' ),
|
2 |
+
getPermalink = document.getElementById( 'custom_permalink' ),
|
3 |
+
checkYoastSEO = document.getElementById( 'wpseo_meta' );
|
4 |
+
|
5 |
+
function changeSEOLinkOnBlur () {
|
6 |
+
var snippetCiteBase = document.getElementById( 'snippet_citeBase' );
|
7 |
+
if ( snippetCiteBase && getHomeURL && getHomeURL.value != "" && getPermalink && getPermalink.value ) {
|
8 |
+
var i = 0;
|
9 |
+
var urlChanged = setInterval( function() {
|
10 |
+
i++;
|
11 |
+
snippetCiteBase.innerHTML = getHomeURL.value + '/' + getPermalink.value;
|
12 |
+
if (i === 5) {
|
13 |
+
clearInterval(urlChanged);
|
14 |
+
}
|
15 |
+
}, 1000);
|
16 |
+
}
|
17 |
+
}
|
18 |
+
|
19 |
+
function changeSEOLink () {
|
20 |
+
var snippetCiteBase = document.getElementById( 'snippet_citeBase' );
|
21 |
+
if ( snippetCiteBase && getHomeURL && getHomeURL.value != "" && getPermalink && getPermalink.value ) {
|
22 |
+
var i = 0;
|
23 |
+
var urlChanged = setInterval( function() {
|
24 |
+
i++;
|
25 |
+
snippetCiteBase.innerHTML = getHomeURL.value + '/' + getPermalink.value;
|
26 |
+
if (i === 5) {
|
27 |
+
clearInterval(urlChanged);
|
28 |
+
}
|
29 |
+
}, 1000);
|
30 |
+
var snippetEditorTitle = document.getElementById( 'snippet-editor-title' ),
|
31 |
+
snippetEditorSlug = document.getElementById( 'snippet-editor-slug' ),
|
32 |
+
snippetEditorDesc = document.getElementById( 'snippet-editor-meta-description' ),
|
33 |
+
snippetCite = document.getElementById( 'snippet_cite' );
|
34 |
+
if ( snippetEditorTitle ) {
|
35 |
+
snippetEditorTitle.addEventListener("blur", changeSEOLinkOnBlur, false);
|
36 |
+
}
|
37 |
+
if ( snippetEditorSlug ) {
|
38 |
+
snippetEditorSlug.addEventListener("blur", changeSEOLinkOnBlur, false);
|
39 |
+
}
|
40 |
+
if ( snippetEditorDesc ) {
|
41 |
+
snippetEditorDesc.addEventListener("blur", changeSEOLinkOnBlur, false);
|
42 |
+
}
|
43 |
+
if ( snippetCite ) {
|
44 |
+
snippetCite.style.display = 'none';
|
45 |
+
}
|
46 |
+
}
|
47 |
+
}
|
48 |
+
|
49 |
+
if ( checkYoastSEO ) {
|
50 |
+
window.addEventListener("load", changeSEOLink, false);
|
51 |
+
}
|
frontend/js/script-form.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
function changeSEOLinkOnBlur(){var e=document.getElementById("snippet_citeBase");if(e&&getHomeURL&&""!=getHomeURL.value&&getPermalink&&getPermalink.value)var t=0,n=setInterval(function(){t++,e.innerHTML=getHomeURL.value+"/"+getPermalink.value,5===t&&clearInterval(n)},1e3)}function changeSEOLink(){var e=document.getElementById("snippet_citeBase");if(e&&getHomeURL&&""!=getHomeURL.value&&getPermalink&&getPermalink.value){var t=0,n=setInterval(function(){t++,e.innerHTML=getHomeURL.value+"/"+getPermalink.value,5===t&&clearInterval(n)},1e3),a=document.getElementById("snippet-editor-title"),l=document.getElementById("snippet-editor-slug"),i=document.getElementById("snippet-editor-meta-description"),m=document.getElementById("snippet_cite");a&&a.addEventListener("blur",changeSEOLinkOnBlur,!1),l&&l.addEventListener("blur",changeSEOLinkOnBlur,!1),i&&i.addEventListener("blur",changeSEOLinkOnBlur,!1),m&&(m.style.display="none")}}var getHomeURL=document.getElementById("custom_permalinks_home_url"),getPermalink=document.getElementById("custom_permalink"),checkYoastSEO=document.getElementById("wpseo_meta");checkYoastSEO&&window.addEventListener("load",changeSEOLink,!1);
|
languages/index.php
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Silence is golden
|
4 |
+
*/
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Donate link: https://www.paypal.me/yasglobal
|
|
5 |
Tags: permalink, url, link, address, custom, redirect, custom post type
|
6 |
Requires at least: 2.6
|
7 |
Tested up to: 4.8
|
8 |
-
Stable tag: 1.2.
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
@@ -47,6 +47,10 @@ add_filter( 'custom_permalinks_request_ignore', 'check_xml_sitemap_url' );
|
|
47 |
|
48 |
== Changelog ==
|
49 |
|
|
|
|
|
|
|
|
|
50 |
= 1.2.3 =
|
51 |
|
52 |
* Fixed PHP Notice on Edit Post Page
|
5 |
Tags: permalink, url, link, address, custom, redirect, custom post type
|
6 |
Requires at least: 2.6
|
7 |
Tested up to: 4.8
|
8 |
+
Stable tag: 1.2.4
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
47 |
|
48 |
== Changelog ==
|
49 |
|
50 |
+
= 1.2.4 =
|
51 |
+
|
52 |
+
* Fixed Slug issue with Yoast SEO
|
53 |
+
|
54 |
= 1.2.3 =
|
55 |
|
56 |
* Fixed PHP Notice on Edit Post Page
|