Version Description
- Fixed Category/Tag Update Issue + Typo on Admin Page
Download this release
Release Info
Developer | sasiddiqui |
Plugin | Custom Permalinks |
Version | 1.2.5 |
Comparing to | |
See all releases |
Code changes from version 1.2.4 to 1.2.5
- README.md +22 -0
- admin/class-custom-permalinks-admin.php +405 -405
- admin/class-custom-permalinks-form.php +0 -334
- custom-permalinks.php +1 -1
- frontend/class-custom-permalinks-form.php +2 -2
- readme.txt +5 -1
README.md
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
@@ -1,405 +1,405 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* @package CustomPermalinks\Admin
|
4 |
-
*/
|
5 |
-
|
6 |
-
class Custom_Permalinks_Admin {
|
7 |
-
|
8 |
-
/**
|
9 |
-
* Initializes WordPress hooks
|
10 |
-
*/
|
11 |
-
function __construct() {
|
12 |
-
add_action( 'admin_menu', array( $this, 'custom_permalinks_menu' ) );
|
13 |
-
}
|
14 |
-
|
15 |
-
/**
|
16 |
-
* Added Pages in Menu for Settings
|
17 |
-
*/
|
18 |
-
public function custom_permalinks_menu() {
|
19 |
-
add_menu_page( 'PostTypes Permalinks', 'Custom Permalinks', 'administrator', 'custom-permalinks-post-permalinks', array( $this,'custom_permalinks_post_permalinks' ), 'dashicons-admin-links' );
|
20 |
-
add_submenu_page( 'custom-permalinks-post-permalinks', 'PostTypes Permalinks', 'PostTypes Permalinks', 'administrator', 'custom-permalinks-post-permalinks', array( $this, 'custom_permalinks_post_permalinks' ) );
|
21 |
-
add_submenu_page( 'custom-permalinks-post-permalinks', 'Category Permalinks', 'Category Permalinks', 'administrator', 'custom-permalinks-category-permalinks', array( $this, 'custom_permalinks_category_permalinks' ) );
|
22 |
-
}
|
23 |
-
|
24 |
-
/**
|
25 |
-
* Shows all the Permalinks created by using this Plugin with Pager and Search Functionality of Posts/Pages
|
26 |
-
*/
|
27 |
-
public function custom_permalinks_post_permalinks() {
|
28 |
-
global $wpdb;
|
29 |
-
$filter_options = '';
|
30 |
-
$filter_permalink = '';
|
31 |
-
$search_permalink = '';
|
32 |
-
$html = '';
|
33 |
-
$error = '';
|
34 |
-
|
35 |
-
// Handle Bulk Operations
|
36 |
-
if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'delete' )
|
37 |
-
|| ( isset( $_POST['action2'] ) && $_POST['action2'] == 'delete' )
|
38 |
-
&& isset( $_POST['permalink'] ) && ! empty( $_POST['permalink'] ) ) {
|
39 |
-
$post_ids = implode( ',', $_POST['permalink'] );
|
40 |
-
if ( preg_match( '/^\d+(?:,\d+)*$/', $post_ids ) ) {
|
41 |
-
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE post_id IN ($post_ids) AND meta_key = 'custom_permalink'" );
|
42 |
-
} else {
|
43 |
-
$error = '<div id="message" class="error"><p>' . __( 'There is some error to proceed your request. Please retry with your request or contact to the plugin author.', 'custom-permalinks' ) . '</p></div>';
|
44 |
-
}
|
45 |
-
}
|
46 |
-
$html .= '<div class="wrap">
|
47 |
-
<h1 class="wp-heading-inline">' . __( 'PostTypes Permalinks', 'custom-permalinks' ) . '</h1>';
|
48 |
-
$html .= $error;
|
49 |
-
|
50 |
-
$search_value = '';
|
51 |
-
if ( isset( $_GET['s'] ) && ! empty( $_GET['s'] ) ) {
|
52 |
-
$filter_permalink = 'AND pm.meta_value LIKE "%' . $_GET['s'] . '%"';
|
53 |
-
$search_permalink = '&s=' . $_GET['s'] . '';
|
54 |
-
$search_value = ltrim( htmlspecialchars( $_GET['s'] ), '/' );
|
55 |
-
$html .= '<span class="subtitle">Search results for "' . $search_value . '"</span>';
|
56 |
-
}
|
57 |
-
$page_limit = 'LIMIT 0, 20';
|
58 |
-
if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
|
59 |
-
$pager = 20 * ( $_GET['paged'] - 1 );
|
60 |
-
$page_limit = 'LIMIT ' . $pager . ', 20';
|
61 |
-
}
|
62 |
-
$sorting_by = 'ORDER By p.ID DESC';
|
63 |
-
$order_by = 'asc';
|
64 |
-
$order_by_class = 'desc';
|
65 |
-
if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'title' ) {
|
66 |
-
$filter_options .= '<input type="hidden" name="orderby" value="title" />';
|
67 |
-
if ( isset( $_GET['order'] ) && $_GET['order'] == 'desc' ) {
|
68 |
-
$sorting_by = 'ORDER By p.post_title DESC';
|
69 |
-
$order_by = 'asc';
|
70 |
-
$order_by_class = 'desc';
|
71 |
-
$filter_options .= '<input type="hidden" name="order" value="desc" />';
|
72 |
-
} else {
|
73 |
-
$sorting_by = 'ORDER By p.post_title';
|
74 |
-
$order_by = 'desc';
|
75 |
-
$order_by_class = 'asc';
|
76 |
-
$filter_options .= '<input type="hidden" name="order" value="asc" />';
|
77 |
-
}
|
78 |
-
}
|
79 |
-
$count_query = "SELECT COUNT(p.ID) AS total_permalinks FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE pm.meta_key = 'custom_permalink' AND pm.meta_value != '' " . $filter_permalink . "";
|
80 |
-
$count_posts = $wpdb->get_row( $count_query );
|
81 |
-
|
82 |
-
$html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="get">';
|
83 |
-
$html .= '<p class="search-box">';
|
84 |
-
$html .= '<input type="hidden" name="page" value="custom-permalinks-post-permalinks" />';
|
85 |
-
$html .= $filter_options;
|
86 |
-
$html .= '<label class="screen-reader-text" for="custom-permalink-search-input">Search Custom Permalink:</label>';
|
87 |
-
$html .= '<input type="search" id="custom-permalink-search-input" name="s" value="' . $search_value . '">';
|
88 |
-
$html .= '<input type="submit" id="search-submit" class="button" value="Search Permalink"></p>';
|
89 |
-
$html .= '</form>';
|
90 |
-
$html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="post">';
|
91 |
-
$html .= '<div class="tablenav top">';
|
92 |
-
$html .= '<div class="alignleft actions bulkactions">
|
93 |
-
<label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label>
|
94 |
-
<select name="action" id="bulk-action-selector-top">
|
95 |
-
<option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
|
96 |
-
<option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
|
97 |
-
</select>
|
98 |
-
<input type="submit" id="doaction" class="button action" value="Apply">
|
99 |
-
</div>';
|
100 |
-
|
101 |
-
$posts = 0;
|
102 |
-
if ( isset( $count_posts->total_permalinks ) && $count_posts->total_permalinks > 0 ) {
|
103 |
-
|
104 |
-
$html .= '<h2 class="screen-reader-text">Custom Permalink navigation</h2>';
|
105 |
-
|
106 |
-
$query = "SELECT p.ID, p.post_title, p.post_type, pm.meta_value FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE pm.meta_key = 'custom_permalink' AND pm.meta_value != '' " . $filter_permalink . " " . $sorting_by . " " . $page_limit . "";
|
107 |
-
$posts = $wpdb->get_results( $query );
|
108 |
-
|
109 |
-
$pagination_html = '';
|
110 |
-
$total_pages = ceil( $count_posts->total_permalinks / 20 );
|
111 |
-
if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 0 ) {
|
112 |
-
$pagination_html = $this->custom_permalinks_pager( $count_posts->total_permalinks, $_GET['paged'], $total_pages );
|
113 |
-
if ( $_GET['paged'] > $total_pages ) {
|
114 |
-
$redirect_uri = explode( '&paged=' . $_GET['paged'] . '', $_SERVER['REQUEST_URI'] );
|
115 |
-
header( 'Location: ' . $redirect_uri[0], 301 );
|
116 |
-
exit();
|
117 |
-
}
|
118 |
-
} elseif ( ! isset( $_GET['paged'] ) ) {
|
119 |
-
$pagination_html = $this->custom_permalinks_pager( $count_posts->total_permalinks, 1, $total_pages );
|
120 |
-
}
|
121 |
-
|
122 |
-
$html .= $pagination_html;
|
123 |
-
}
|
124 |
-
$table_navigation = $this->custom_permalink_tablenav_posts( $order_by_class, $order_by, $search_permalink );
|
125 |
-
|
126 |
-
$html .= '</div>';
|
127 |
-
$html .= '<table class="wp-list-table widefat fixed striped posts">
|
128 |
-
<thead>' . $table_navigation . '</thead>
|
129 |
-
<tbody>';
|
130 |
-
if ( $posts != 0 && ! empty( $posts ) ) {
|
131 |
-
foreach ( $posts as $post ) {
|
132 |
-
$html .= '<tr valign="top">';
|
133 |
-
$html .= '<th scope="row" class="check-column"><input type="checkbox" name="permalink[]" value="' . $post->ID . '" /></th>';
|
134 |
-
$html .= '<td><strong><a class="row-title" href="post.php?action=edit&post=' . $post->ID . '">' . $post->post_title . '</a></strong></td>';
|
135 |
-
$html .= '<td>' . ucwords( $post->post_type ) . '</td>';
|
136 |
-
$html .= '<td><a href="/' . $post->meta_value . '" target="_blank" title="' . __( "Visit " . $post->post_title, "custom-permalinks" ) . '">/' . urldecode( $post->meta_value ) . '</a></td></tr>';
|
137 |
-
}
|
138 |
-
} else {
|
139 |
-
$html .= '<tr class="no-items"><td class="colspanchange" colspan="10">No permalinks found.</td></tr>';
|
140 |
-
}
|
141 |
-
$html .= '</tbody>
|
142 |
-
<tfoot>' . $table_navigation . '</tfoot>
|
143 |
-
</table>';
|
144 |
-
|
145 |
-
$html .= '<div class="tablenav bottom">
|
146 |
-
<div class="alignleft actions bulkactions">
|
147 |
-
<label for="bulk-action-selector-bottom" class="screen-reader-text">Select bulk action</label>
|
148 |
-
<select name="action2" id="bulk-action-selector-bottom">
|
149 |
-
<option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
|
150 |
-
<option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
|
151 |
-
</select>
|
152 |
-
<input type="submit" id="doaction2" class="button action" value="Apply">
|
153 |
-
</div>
|
154 |
-
' . $pagination_html . '
|
155 |
-
</div>';
|
156 |
-
$html .= '</form>
|
157 |
-
</div>';
|
158 |
-
echo $html;
|
159 |
-
}
|
160 |
-
|
161 |
-
/**
|
162 |
-
* Return the Navigation row HTML same as Default Posts page for PostTypes
|
163 |
-
*/
|
164 |
-
private function custom_permalink_tablenav_posts( $order_by_class, $order_by, $search_permalink ) {
|
165 |
-
$nav = '<tr>
|
166 |
-
<td id="cb" class="manage-column column-cb check-column"><label class="screen-reader-text" for="cb-select-all-1">Select All</label><input id="cb-select-all-1" type="checkbox"></td>
|
167 |
-
<th scope="col" id="title" class="manage-column column-title column-primary sortable ' . $order_by_class . '"><a href="/wp-admin/admin.php?page=custom-permalinks-post-permalinks&orderby=title&order=' . $order_by . $search_permalink . '"><span>' . __( "Title", "custom-permalinks" ) . '</span><span class="sorting-indicator"></span></a></th>
|
168 |
-
<th scope="col">' . __( "Type", "custom-permalinks" ) . '</th>
|
169 |
-
<th scope="col">' . __( "Permalink", "custom-permalinks" ) . '</th>
|
170 |
-
</tr>';
|
171 |
-
return $nav;
|
172 |
-
}
|
173 |
-
|
174 |
-
/**
|
175 |
-
* Shows all the Permalinks created by using this Plugin with Pager and Search Functionality of Category/Tags
|
176 |
-
*/
|
177 |
-
public function custom_permalinks_category_permalinks() {
|
178 |
-
|
179 |
-
$search_permalink = '';
|
180 |
-
$html = '';
|
181 |
-
|
182 |
-
// Handle Bulk Operations
|
183 |
-
if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'delete' )
|
184 |
-
|| ( isset( $_POST['action2'] ) && $_POST['action2'] == 'delete' )
|
185 |
-
&& isset( $_POST['permalink'] ) && ! empty( $_POST['permalink'] ) ) {
|
186 |
-
$remove_perm = $_POST['permalink'];
|
187 |
-
$data = get_option( 'custom_permalink_table' );
|
188 |
-
if ( isset( $data ) && is_array( $data ) ) {
|
189 |
-
$i = 0;
|
190 |
-
foreach ( $data as $link => $info ) {
|
191 |
-
if ( in_array( $info['id'], $remove_perm ) ) {
|
192 |
-
unset( $data[$link] );
|
193 |
-
unset( $remove_perm[$i] );
|
194 |
-
if ( ! is_array( $remove_perm ) || empty( $remove_perm ) )
|
195 |
-
break;
|
196 |
-
}
|
197 |
-
$i++;
|
198 |
-
}
|
199 |
-
}
|
200 |
-
update_option( 'custom_permalink_table', $data );
|
201 |
-
}
|
202 |
-
$html .= '<div class="wrap">
|
203 |
-
<h1 class="wp-heading-inline">' . __( 'Category/Tags Permalinks', 'custom-permalinks' ) . '</h1>';
|
204 |
-
|
205 |
-
$search_value = '';
|
206 |
-
if ( isset( $_GET['s'] ) && ! empty( $_GET['s'] ) ) {
|
207 |
-
$search_permalink = '&s=' . $_GET['s'] . '';
|
208 |
-
$search_value = ltrim( htmlspecialchars( $_GET['s'] ), '/' );
|
209 |
-
$html .= '<span class="subtitle">Search results for "' . $search_value . '"</span>';
|
210 |
-
}
|
211 |
-
$pager_offset = '0';
|
212 |
-
$page_limit = 20;
|
213 |
-
if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
|
214 |
-
$pager_offset = 20 * ( $_GET['paged'] - 1 );
|
215 |
-
$page_limit = $pager_offset + 20;
|
216 |
-
}
|
217 |
-
$html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="get">';
|
218 |
-
$html .= '<p class="search-box">';
|
219 |
-
$html .= '<input type="hidden" name="page" value="custom-permalinks-category-permalinks" />';
|
220 |
-
$html .= '<label class="screen-reader-text" for="custom-permalink-search-input">Search Custom Permalink:</label>';
|
221 |
-
$html .= '<input type="search" id="custom-permalink-search-input" name="s" value="' . $search_value . '">';
|
222 |
-
$html .= '<input type="submit" id="search-submit" class="button" value="Search Permalink"></p>';
|
223 |
-
$html .= '</form>';
|
224 |
-
$html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="post">';
|
225 |
-
$html .= '<div class="tablenav top">';
|
226 |
-
$html .= '<div class="alignleft actions bulkactions">
|
227 |
-
<label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label>
|
228 |
-
<select name="action" id="bulk-action-selector-top">
|
229 |
-
<option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
|
230 |
-
<option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
|
231 |
-
</select>
|
232 |
-
<input type="submit" id="doaction" class="button action" value="Apply">
|
233 |
-
</div>';
|
234 |
-
|
235 |
-
$posts
|
236 |
-
$table
|
237 |
-
$count_tags
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
$
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
$total_pages = ceil( $count_tags / 20 );
|
255 |
-
if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 0) {
|
256 |
-
$pagination_html = $this->custom_permalinks_pager( $count_tags, $_GET['paged'], $total_pages);
|
257 |
-
if ( $_GET['paged'] > $total_pages ) {
|
258 |
-
$redirect_uri = explode( '&paged=' . $_GET['paged'] . '', $_SERVER['REQUEST_URI'] );
|
259 |
-
header( 'Location: ' . $redirect_uri[0], 301 );
|
260 |
-
exit();
|
261 |
-
}
|
262 |
-
} elseif ( ! isset( $_GET['paged'] ) ) {
|
263 |
-
$pagination_html = $this->custom_permalinks_pager( $count_tags, 1, $total_pages );
|
264 |
-
}
|
265 |
-
|
266 |
-
$html .= $pagination_html;
|
267 |
-
}
|
268 |
-
$table_navigation = $this->custom_permalink_tablenav_category( $search_permalink );
|
269 |
-
|
270 |
-
$html .= '</div>';
|
271 |
-
$html .= '<table class="wp-list-table widefat fixed striped posts">
|
272 |
-
<thead>' . $table_navigation . '</thead>
|
273 |
-
<tbody>';
|
274 |
-
|
275 |
-
if ( $table && is_array( $table ) && $count_tags > 0 ) {
|
276 |
-
uasort( $table, array( 'Custom_Permalinks_Admin', 'custom_permalinks_sort_array' ) );
|
277 |
-
$i = -1;
|
278 |
-
foreach ( $table as $permalink => $info ) {
|
279 |
-
$i++;
|
280 |
-
if ( $i < $pager_offset )
|
281 |
-
continue;
|
282 |
-
|
283 |
-
if ( $i >= $page_limit )
|
284 |
-
break;
|
285 |
-
|
286 |
-
$type = $info['kind'] == 'tag' ? 'post_tag' : 'category';
|
287 |
-
$term = get_term( $info['id'], $type );
|
288 |
-
$html .= '<tr valign="top">';
|
289 |
-
$html .= '<th scope="row" class="check-column"><input type="checkbox" name="permalink[]" value="' . $info['id'] . '" /></th>';
|
290 |
-
$html .= '<td><strong><a class="row-title" href="edit-tags.php?action=edit&taxonomy=' . $type . '&tag_ID=' . $info['id'] . ' ">' . $term->name . '</a></strong></td>';
|
291 |
-
$html .= '<td>' . ucwords( $info['kind'] ) . '</td>';
|
292 |
-
$html .= '<td><a href="/' . $permalink . '" target="_blank" title="' . __( "Visit " . $term->name, "custom-permalinks" ) . '">/' . $permalink . '</a></td></tr>';
|
293 |
-
}
|
294 |
-
} else {
|
295 |
-
$html .= '<tr class="no-items"><td class="colspanchange" colspan="10">No permalinks found.</td></tr>';
|
296 |
-
}
|
297 |
-
$html .= '</tbody>
|
298 |
-
<tfoot>' . $table_navigation . '</tfoot>
|
299 |
-
</table>';
|
300 |
-
|
301 |
-
$html .= '<div class="tablenav bottom">
|
302 |
-
<div class="alignleft actions bulkactions">
|
303 |
-
<label for="bulk-action-selector-bottom" class="screen-reader-text">Select bulk action</label>
|
304 |
-
<select name="action2" id="bulk-action-selector-bottom">
|
305 |
-
<option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
|
306 |
-
<option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
|
307 |
-
</select>
|
308 |
-
<input type="submit" id="doaction2" class="button action" value="Apply">
|
309 |
-
</div>
|
310 |
-
' . $pagination_html . '
|
311 |
-
</div>';
|
312 |
-
$html .= '</form>
|
313 |
-
</div>';
|
314 |
-
echo $html;
|
315 |
-
}
|
316 |
-
|
317 |
-
/**
|
318 |
-
* Sort the terms array in desc order using term id
|
319 |
-
*/
|
320 |
-
private static function custom_permalinks_sort_array( $a, $b ) {
|
321 |
-
return $b['id'] - $a['id'];
|
322 |
-
}
|
323 |
-
|
324 |
-
/**
|
325 |
-
* Return the Navigation row HTML same as Default Posts page for Category
|
326 |
-
*/
|
327 |
-
private function custom_permalink_tablenav_category( $search_permalink ) {
|
328 |
-
$nav = '<tr>
|
329 |
-
<td id="cb" class="manage-column column-cb check-column"><label class="screen-reader-text" for="cb-select-all-1">Select All</label><input id="cb-select-all-1" type="checkbox"></td>
|
330 |
-
<th scope="col" id="title" class="manage-column column-title column-primary">' . __( "Title", "custom-permalinks" ) . '</th>
|
331 |
-
<th scope="col">' . __( "Type", "custom-permalinks" ) . '</th>
|
332 |
-
<th scope="col">' . __( "Permalink", "custom-permalinks" ) . '</th>
|
333 |
-
</tr>';
|
334 |
-
return $nav;
|
335 |
-
}
|
336 |
-
|
337 |
-
/**
|
338 |
-
* Return the Pager HTML
|
339 |
-
*/
|
340 |
-
private function custom_permalinks_pager( $total_permalinks, $current_pager_value = 1, $total_pager = 0 ) {
|
341 |
-
|
342 |
-
if ( $total_pager == 0 ) return;
|
343 |
-
|
344 |
-
if ( $total_pager == 1 ) {
|
345 |
-
$pagination_html = '<div class="tablenav-pages one-page">
|
346 |
-
<span class="displaying-num">' . $total_permalinks . ' items</span>
|
347 |
-
</div>';
|
348 |
-
return $pagination_html;
|
349 |
-
}
|
350 |
-
|
351 |
-
$remove_pager_uri = explode( '&paged=' . $current_pager_value . '', $_SERVER['REQUEST_URI'] );
|
352 |
-
$pagination_html = '<div class="tablenav-pages">
|
353 |
-
<span class="displaying-num">' . $total_permalinks . ' items</span>
|
354 |
-
<span class="pagination-links">';
|
355 |
-
|
356 |
-
if ( $current_pager_value == 1 ) {
|
357 |
-
$pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">« </span>
|
358 |
-
<span class="tablenav-pages-navspan" aria-hidden="true">‹ </span>';
|
359 |
-
} else {
|
360 |
-
$prev_page = $current_pager_value - 1;
|
361 |
-
if ( $prev_page == 1 ) {
|
362 |
-
$pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">«</span>';
|
363 |
-
} else {
|
364 |
-
$pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=1" title="First page" class="first-page">
|
365 |
-
<span class="screen-reader-text">First page</span>
|
366 |
-
<span aria-hidden="true">«</span>
|
367 |
-
</a> ';
|
368 |
-
}
|
369 |
-
$pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=' . $prev_page . '" title="Previous page" class="prev-page">
|
370 |
-
<span class="screen-reader-text">Previous page</span>
|
371 |
-
<span aria-hidden="true">‹</span>
|
372 |
-
</a> ';
|
373 |
-
}
|
374 |
-
|
375 |
-
$pagination_html .= '<span class="paging-input">
|
376 |
-
<label for="current-page-selector" class="screen-reader-text">Current Page</label>
|
377 |
-
<input class="current-page" id="current-page-selector" type="text" name="paged" value="' . $current_pager_value . '" size="1" aria-describedby="table-paging" />
|
378 |
-
<span class="tablenav-paging-text"> of <span class="total-pages">' . $total_pager . ' </span> </span>
|
379 |
-
</span>';
|
380 |
-
|
381 |
-
if ( $current_pager_value == $total_pager ) {
|
382 |
-
$pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">› </span>
|
383 |
-
<span class="tablenav-pages-navspan" aria-hidden="true">» </span>';
|
384 |
-
} else {
|
385 |
-
$next_page = $current_pager_value + 1;
|
386 |
-
$pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=' . $next_page . '" title="Next page" class="next-page">
|
387 |
-
<span class="screen-reader-text">Next page</span>
|
388 |
-
<span aria-hidden="true">›</span>
|
389 |
-
</a> ';
|
390 |
-
if ( $total_pager == $next_page) {
|
391 |
-
$pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">»</span>';
|
392 |
-
} else {
|
393 |
-
$pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=' . $total_pager . '" title="Last page" class="last-page">
|
394 |
-
<span class="screen-reader-text">Last page</span>
|
395 |
-
<span aria-hidden="true">»</span>
|
396 |
-
</a> ';
|
397 |
-
}
|
398 |
-
|
399 |
-
}
|
400 |
-
$pagination_html .= '</span></div>';
|
401 |
-
|
402 |
-
return $pagination_html;
|
403 |
-
}
|
404 |
-
|
405 |
-
}
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* @package CustomPermalinks\Admin
|
4 |
+
*/
|
5 |
+
|
6 |
+
class Custom_Permalinks_Admin {
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Initializes WordPress hooks
|
10 |
+
*/
|
11 |
+
function __construct() {
|
12 |
+
add_action( 'admin_menu', array( $this, 'custom_permalinks_menu' ) );
|
13 |
+
}
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Added Pages in Menu for Settings
|
17 |
+
*/
|
18 |
+
public function custom_permalinks_menu() {
|
19 |
+
add_menu_page( 'PostTypes Permalinks', 'Custom Permalinks', 'administrator', 'custom-permalinks-post-permalinks', array( $this,'custom_permalinks_post_permalinks' ), 'dashicons-admin-links' );
|
20 |
+
add_submenu_page( 'custom-permalinks-post-permalinks', 'PostTypes Permalinks', 'PostTypes Permalinks', 'administrator', 'custom-permalinks-post-permalinks', array( $this, 'custom_permalinks_post_permalinks' ) );
|
21 |
+
add_submenu_page( 'custom-permalinks-post-permalinks', 'Category Permalinks', 'Category Permalinks', 'administrator', 'custom-permalinks-category-permalinks', array( $this, 'custom_permalinks_category_permalinks' ) );
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Shows all the Permalinks created by using this Plugin with Pager and Search Functionality of Posts/Pages
|
26 |
+
*/
|
27 |
+
public function custom_permalinks_post_permalinks() {
|
28 |
+
global $wpdb;
|
29 |
+
$filter_options = '';
|
30 |
+
$filter_permalink = '';
|
31 |
+
$search_permalink = '';
|
32 |
+
$html = '';
|
33 |
+
$error = '';
|
34 |
+
|
35 |
+
// Handle Bulk Operations
|
36 |
+
if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'delete' )
|
37 |
+
|| ( isset( $_POST['action2'] ) && $_POST['action2'] == 'delete' )
|
38 |
+
&& isset( $_POST['permalink'] ) && ! empty( $_POST['permalink'] ) ) {
|
39 |
+
$post_ids = implode( ',', $_POST['permalink'] );
|
40 |
+
if ( preg_match( '/^\d+(?:,\d+)*$/', $post_ids ) ) {
|
41 |
+
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE post_id IN ($post_ids) AND meta_key = 'custom_permalink'" );
|
42 |
+
} else {
|
43 |
+
$error = '<div id="message" class="error"><p>' . __( 'There is some error to proceed your request. Please retry with your request or contact to the plugin author.', 'custom-permalinks' ) . '</p></div>';
|
44 |
+
}
|
45 |
+
}
|
46 |
+
$html .= '<div class="wrap">
|
47 |
+
<h1 class="wp-heading-inline">' . __( 'PostTypes Permalinks', 'custom-permalinks' ) . '</h1>';
|
48 |
+
$html .= $error;
|
49 |
+
|
50 |
+
$search_value = '';
|
51 |
+
if ( isset( $_GET['s'] ) && ! empty( $_GET['s'] ) ) {
|
52 |
+
$filter_permalink = 'AND pm.meta_value LIKE "%' . $_GET['s'] . '%"';
|
53 |
+
$search_permalink = '&s=' . $_GET['s'] . '';
|
54 |
+
$search_value = ltrim( htmlspecialchars( $_GET['s'] ), '/' );
|
55 |
+
$html .= '<span class="subtitle">Search results for "' . $search_value . '"</span>';
|
56 |
+
}
|
57 |
+
$page_limit = 'LIMIT 0, 20';
|
58 |
+
if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
|
59 |
+
$pager = 20 * ( $_GET['paged'] - 1 );
|
60 |
+
$page_limit = 'LIMIT ' . $pager . ', 20';
|
61 |
+
}
|
62 |
+
$sorting_by = 'ORDER By p.ID DESC';
|
63 |
+
$order_by = 'asc';
|
64 |
+
$order_by_class = 'desc';
|
65 |
+
if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'title' ) {
|
66 |
+
$filter_options .= '<input type="hidden" name="orderby" value="title" />';
|
67 |
+
if ( isset( $_GET['order'] ) && $_GET['order'] == 'desc' ) {
|
68 |
+
$sorting_by = 'ORDER By p.post_title DESC';
|
69 |
+
$order_by = 'asc';
|
70 |
+
$order_by_class = 'desc';
|
71 |
+
$filter_options .= '<input type="hidden" name="order" value="desc" />';
|
72 |
+
} else {
|
73 |
+
$sorting_by = 'ORDER By p.post_title';
|
74 |
+
$order_by = 'desc';
|
75 |
+
$order_by_class = 'asc';
|
76 |
+
$filter_options .= '<input type="hidden" name="order" value="asc" />';
|
77 |
+
}
|
78 |
+
}
|
79 |
+
$count_query = "SELECT COUNT(p.ID) AS total_permalinks FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE pm.meta_key = 'custom_permalink' AND pm.meta_value != '' " . $filter_permalink . "";
|
80 |
+
$count_posts = $wpdb->get_row( $count_query );
|
81 |
+
|
82 |
+
$html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="get">';
|
83 |
+
$html .= '<p class="search-box">';
|
84 |
+
$html .= '<input type="hidden" name="page" value="custom-permalinks-post-permalinks" />';
|
85 |
+
$html .= $filter_options;
|
86 |
+
$html .= '<label class="screen-reader-text" for="custom-permalink-search-input">Search Custom Permalink:</label>';
|
87 |
+
$html .= '<input type="search" id="custom-permalink-search-input" name="s" value="' . $search_value . '">';
|
88 |
+
$html .= '<input type="submit" id="search-submit" class="button" value="Search Permalink"></p>';
|
89 |
+
$html .= '</form>';
|
90 |
+
$html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="post">';
|
91 |
+
$html .= '<div class="tablenav top">';
|
92 |
+
$html .= '<div class="alignleft actions bulkactions">
|
93 |
+
<label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label>
|
94 |
+
<select name="action" id="bulk-action-selector-top">
|
95 |
+
<option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
|
96 |
+
<option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
|
97 |
+
</select>
|
98 |
+
<input type="submit" id="doaction" class="button action" value="Apply">
|
99 |
+
</div>';
|
100 |
+
|
101 |
+
$posts = 0;
|
102 |
+
if ( isset( $count_posts->total_permalinks ) && $count_posts->total_permalinks > 0 ) {
|
103 |
+
|
104 |
+
$html .= '<h2 class="screen-reader-text">Custom Permalink navigation</h2>';
|
105 |
+
|
106 |
+
$query = "SELECT p.ID, p.post_title, p.post_type, pm.meta_value FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE pm.meta_key = 'custom_permalink' AND pm.meta_value != '' " . $filter_permalink . " " . $sorting_by . " " . $page_limit . "";
|
107 |
+
$posts = $wpdb->get_results( $query );
|
108 |
+
|
109 |
+
$pagination_html = '';
|
110 |
+
$total_pages = ceil( $count_posts->total_permalinks / 20 );
|
111 |
+
if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 0 ) {
|
112 |
+
$pagination_html = $this->custom_permalinks_pager( $count_posts->total_permalinks, $_GET['paged'], $total_pages );
|
113 |
+
if ( $_GET['paged'] > $total_pages ) {
|
114 |
+
$redirect_uri = explode( '&paged=' . $_GET['paged'] . '', $_SERVER['REQUEST_URI'] );
|
115 |
+
header( 'Location: ' . $redirect_uri[0], 301 );
|
116 |
+
exit();
|
117 |
+
}
|
118 |
+
} elseif ( ! isset( $_GET['paged'] ) ) {
|
119 |
+
$pagination_html = $this->custom_permalinks_pager( $count_posts->total_permalinks, 1, $total_pages );
|
120 |
+
}
|
121 |
+
|
122 |
+
$html .= $pagination_html;
|
123 |
+
}
|
124 |
+
$table_navigation = $this->custom_permalink_tablenav_posts( $order_by_class, $order_by, $search_permalink );
|
125 |
+
|
126 |
+
$html .= '</div>';
|
127 |
+
$html .= '<table class="wp-list-table widefat fixed striped posts">
|
128 |
+
<thead>' . $table_navigation . '</thead>
|
129 |
+
<tbody>';
|
130 |
+
if ( $posts != 0 && ! empty( $posts ) ) {
|
131 |
+
foreach ( $posts as $post ) {
|
132 |
+
$html .= '<tr valign="top">';
|
133 |
+
$html .= '<th scope="row" class="check-column"><input type="checkbox" name="permalink[]" value="' . $post->ID . '" /></th>';
|
134 |
+
$html .= '<td><strong><a class="row-title" href="post.php?action=edit&post=' . $post->ID . '">' . $post->post_title . '</a></strong></td>';
|
135 |
+
$html .= '<td>' . ucwords( $post->post_type ) . '</td>';
|
136 |
+
$html .= '<td><a href="/' . $post->meta_value . '" target="_blank" title="' . __( "Visit " . $post->post_title, "custom-permalinks" ) . '">/' . urldecode( $post->meta_value ) . '</a></td></tr>';
|
137 |
+
}
|
138 |
+
} else {
|
139 |
+
$html .= '<tr class="no-items"><td class="colspanchange" colspan="10">No permalinks found.</td></tr>';
|
140 |
+
}
|
141 |
+
$html .= '</tbody>
|
142 |
+
<tfoot>' . $table_navigation . '</tfoot>
|
143 |
+
</table>';
|
144 |
+
|
145 |
+
$html .= '<div class="tablenav bottom">
|
146 |
+
<div class="alignleft actions bulkactions">
|
147 |
+
<label for="bulk-action-selector-bottom" class="screen-reader-text">Select bulk action</label>
|
148 |
+
<select name="action2" id="bulk-action-selector-bottom">
|
149 |
+
<option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
|
150 |
+
<option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
|
151 |
+
</select>
|
152 |
+
<input type="submit" id="doaction2" class="button action" value="Apply">
|
153 |
+
</div>
|
154 |
+
' . $pagination_html . '
|
155 |
+
</div>';
|
156 |
+
$html .= '</form>
|
157 |
+
</div>';
|
158 |
+
echo $html;
|
159 |
+
}
|
160 |
+
|
161 |
+
/**
|
162 |
+
* Return the Navigation row HTML same as Default Posts page for PostTypes
|
163 |
+
*/
|
164 |
+
private function custom_permalink_tablenav_posts( $order_by_class, $order_by, $search_permalink ) {
|
165 |
+
$nav = '<tr>
|
166 |
+
<td id="cb" class="manage-column column-cb check-column"><label class="screen-reader-text" for="cb-select-all-1">Select All</label><input id="cb-select-all-1" type="checkbox"></td>
|
167 |
+
<th scope="col" id="title" class="manage-column column-title column-primary sortable ' . $order_by_class . '"><a href="/wp-admin/admin.php?page=custom-permalinks-post-permalinks&orderby=title&order=' . $order_by . $search_permalink . '"><span>' . __( "Title", "custom-permalinks" ) . '</span><span class="sorting-indicator"></span></a></th>
|
168 |
+
<th scope="col">' . __( "Type", "custom-permalinks" ) . '</th>
|
169 |
+
<th scope="col">' . __( "Permalink", "custom-permalinks" ) . '</th>
|
170 |
+
</tr>';
|
171 |
+
return $nav;
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Shows all the Permalinks created by using this Plugin with Pager and Search Functionality of Category/Tags
|
176 |
+
*/
|
177 |
+
public function custom_permalinks_category_permalinks() {
|
178 |
+
|
179 |
+
$search_permalink = '';
|
180 |
+
$html = '';
|
181 |
+
|
182 |
+
// Handle Bulk Operations
|
183 |
+
if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'delete' )
|
184 |
+
|| ( isset( $_POST['action2'] ) && $_POST['action2'] == 'delete' )
|
185 |
+
&& isset( $_POST['permalink'] ) && ! empty( $_POST['permalink'] ) ) {
|
186 |
+
$remove_perm = $_POST['permalink'];
|
187 |
+
$data = get_option( 'custom_permalink_table' );
|
188 |
+
if ( isset( $data ) && is_array( $data ) ) {
|
189 |
+
$i = 0;
|
190 |
+
foreach ( $data as $link => $info ) {
|
191 |
+
if ( in_array( $info['id'], $remove_perm ) ) {
|
192 |
+
unset( $data[$link] );
|
193 |
+
unset( $remove_perm[$i] );
|
194 |
+
if ( ! is_array( $remove_perm ) || empty( $remove_perm ) )
|
195 |
+
break;
|
196 |
+
}
|
197 |
+
$i++;
|
198 |
+
}
|
199 |
+
}
|
200 |
+
update_option( 'custom_permalink_table', $data );
|
201 |
+
}
|
202 |
+
$html .= '<div class="wrap">
|
203 |
+
<h1 class="wp-heading-inline">' . __( 'Category/Tags Permalinks', 'custom-permalinks' ) . '</h1>';
|
204 |
+
|
205 |
+
$search_value = '';
|
206 |
+
if ( isset( $_GET['s'] ) && ! empty( $_GET['s'] ) ) {
|
207 |
+
$search_permalink = '&s=' . $_GET['s'] . '';
|
208 |
+
$search_value = ltrim( htmlspecialchars( $_GET['s'] ), '/' );
|
209 |
+
$html .= '<span class="subtitle">Search results for "' . $search_value . '"</span>';
|
210 |
+
}
|
211 |
+
$pager_offset = '0';
|
212 |
+
$page_limit = 20;
|
213 |
+
if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
|
214 |
+
$pager_offset = 20 * ( $_GET['paged'] - 1 );
|
215 |
+
$page_limit = $pager_offset + 20;
|
216 |
+
}
|
217 |
+
$html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="get">';
|
218 |
+
$html .= '<p class="search-box">';
|
219 |
+
$html .= '<input type="hidden" name="page" value="custom-permalinks-category-permalinks" />';
|
220 |
+
$html .= '<label class="screen-reader-text" for="custom-permalink-search-input">Search Custom Permalink:</label>';
|
221 |
+
$html .= '<input type="search" id="custom-permalink-search-input" name="s" value="' . $search_value . '">';
|
222 |
+
$html .= '<input type="submit" id="search-submit" class="button" value="Search Permalink"></p>';
|
223 |
+
$html .= '</form>';
|
224 |
+
$html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="post">';
|
225 |
+
$html .= '<div class="tablenav top">';
|
226 |
+
$html .= '<div class="alignleft actions bulkactions">
|
227 |
+
<label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label>
|
228 |
+
<select name="action" id="bulk-action-selector-top">
|
229 |
+
<option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
|
230 |
+
<option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
|
231 |
+
</select>
|
232 |
+
<input type="submit" id="doaction" class="button action" value="Apply">
|
233 |
+
</div>';
|
234 |
+
|
235 |
+
$posts = 0;
|
236 |
+
$table = get_option( 'custom_permalink_table' );
|
237 |
+
$count_tags = count( $table );
|
238 |
+
$pagination_html = '';
|
239 |
+
if ( isset( $table ) && is_array( $table ) && $count_tags > 0 ) {
|
240 |
+
|
241 |
+
$filtered = array();
|
242 |
+
if ( $search_value != '' ) {
|
243 |
+
foreach ( $table as $key => $value ) {
|
244 |
+
if( preg_match( '/' . $search_value . '/', $key) ) {
|
245 |
+
$filtered[$key] = $value;
|
246 |
+
}
|
247 |
+
}
|
248 |
+
$table = $filtered;
|
249 |
+
$count_tags = count( $table );
|
250 |
+
}
|
251 |
+
|
252 |
+
$html .= '<h2 class="screen-reader-text">Custom Permalink navigation</h2>';
|
253 |
+
|
254 |
+
$total_pages = ceil( $count_tags / 20 );
|
255 |
+
if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 0 ) {
|
256 |
+
$pagination_html = $this->custom_permalinks_pager( $count_tags, $_GET['paged'], $total_pages);
|
257 |
+
if ( $_GET['paged'] > $total_pages ) {
|
258 |
+
$redirect_uri = explode( '&paged=' . $_GET['paged'] . '', $_SERVER['REQUEST_URI'] );
|
259 |
+
header( 'Location: ' . $redirect_uri[0], 301 );
|
260 |
+
exit();
|
261 |
+
}
|
262 |
+
} elseif ( ! isset( $_GET['paged'] ) ) {
|
263 |
+
$pagination_html = $this->custom_permalinks_pager( $count_tags, 1, $total_pages );
|
264 |
+
}
|
265 |
+
|
266 |
+
$html .= $pagination_html;
|
267 |
+
}
|
268 |
+
$table_navigation = $this->custom_permalink_tablenav_category( $search_permalink );
|
269 |
+
|
270 |
+
$html .= '</div>';
|
271 |
+
$html .= '<table class="wp-list-table widefat fixed striped posts">
|
272 |
+
<thead>' . $table_navigation . '</thead>
|
273 |
+
<tbody>';
|
274 |
+
|
275 |
+
if ( $table && is_array( $table ) && $count_tags > 0 ) {
|
276 |
+
uasort( $table, array( 'Custom_Permalinks_Admin', 'custom_permalinks_sort_array' ) );
|
277 |
+
$i = -1;
|
278 |
+
foreach ( $table as $permalink => $info ) {
|
279 |
+
$i++;
|
280 |
+
if ( $i < $pager_offset )
|
281 |
+
continue;
|
282 |
+
|
283 |
+
if ( $i >= $page_limit )
|
284 |
+
break;
|
285 |
+
|
286 |
+
$type = $info['kind'] == 'tag' ? 'post_tag' : 'category';
|
287 |
+
$term = get_term( $info['id'], $type );
|
288 |
+
$html .= '<tr valign="top">';
|
289 |
+
$html .= '<th scope="row" class="check-column"><input type="checkbox" name="permalink[]" value="' . $info['id'] . '" /></th>';
|
290 |
+
$html .= '<td><strong><a class="row-title" href="edit-tags.php?action=edit&taxonomy=' . $type . '&tag_ID=' . $info['id'] . ' ">' . $term->name . '</a></strong></td>';
|
291 |
+
$html .= '<td>' . ucwords( $info['kind'] ) . '</td>';
|
292 |
+
$html .= '<td><a href="/' . $permalink . '" target="_blank" title="' . __( "Visit " . $term->name, "custom-permalinks" ) . '">/' . $permalink . '</a></td></tr>';
|
293 |
+
}
|
294 |
+
} else {
|
295 |
+
$html .= '<tr class="no-items"><td class="colspanchange" colspan="10">No permalinks found.</td></tr>';
|
296 |
+
}
|
297 |
+
$html .= '</tbody>
|
298 |
+
<tfoot>' . $table_navigation . '</tfoot>
|
299 |
+
</table>';
|
300 |
+
|
301 |
+
$html .= '<div class="tablenav bottom">
|
302 |
+
<div class="alignleft actions bulkactions">
|
303 |
+
<label for="bulk-action-selector-bottom" class="screen-reader-text">Select bulk action</label>
|
304 |
+
<select name="action2" id="bulk-action-selector-bottom">
|
305 |
+
<option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
|
306 |
+
<option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
|
307 |
+
</select>
|
308 |
+
<input type="submit" id="doaction2" class="button action" value="Apply">
|
309 |
+
</div>
|
310 |
+
' . $pagination_html . '
|
311 |
+
</div>';
|
312 |
+
$html .= '</form>
|
313 |
+
</div>';
|
314 |
+
echo $html;
|
315 |
+
}
|
316 |
+
|
317 |
+
/**
|
318 |
+
* Sort the terms array in desc order using term id
|
319 |
+
*/
|
320 |
+
private static function custom_permalinks_sort_array( $a, $b ) {
|
321 |
+
return $b['id'] - $a['id'];
|
322 |
+
}
|
323 |
+
|
324 |
+
/**
|
325 |
+
* Return the Navigation row HTML same as Default Posts page for Category
|
326 |
+
*/
|
327 |
+
private function custom_permalink_tablenav_category( $search_permalink ) {
|
328 |
+
$nav = '<tr>
|
329 |
+
<td id="cb" class="manage-column column-cb check-column"><label class="screen-reader-text" for="cb-select-all-1">Select All</label><input id="cb-select-all-1" type="checkbox"></td>
|
330 |
+
<th scope="col" id="title" class="manage-column column-title column-primary">' . __( "Title", "custom-permalinks" ) . '</th>
|
331 |
+
<th scope="col">' . __( "Type", "custom-permalinks" ) . '</th>
|
332 |
+
<th scope="col">' . __( "Permalink", "custom-permalinks" ) . '</th>
|
333 |
+
</tr>';
|
334 |
+
return $nav;
|
335 |
+
}
|
336 |
+
|
337 |
+
/**
|
338 |
+
* Return the Pager HTML
|
339 |
+
*/
|
340 |
+
private function custom_permalinks_pager( $total_permalinks, $current_pager_value = 1, $total_pager = 0 ) {
|
341 |
+
|
342 |
+
if ( $total_pager == 0 ) return;
|
343 |
+
|
344 |
+
if ( $total_pager == 1 ) {
|
345 |
+
$pagination_html = '<div class="tablenav-pages one-page">
|
346 |
+
<span class="displaying-num">' . $total_permalinks . ' items</span>
|
347 |
+
</div>';
|
348 |
+
return $pagination_html;
|
349 |
+
}
|
350 |
+
|
351 |
+
$remove_pager_uri = explode( '&paged=' . $current_pager_value . '', $_SERVER['REQUEST_URI'] );
|
352 |
+
$pagination_html = '<div class="tablenav-pages">
|
353 |
+
<span class="displaying-num">' . $total_permalinks . ' items</span>
|
354 |
+
<span class="pagination-links">';
|
355 |
+
|
356 |
+
if ( $current_pager_value == 1 ) {
|
357 |
+
$pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">« </span>
|
358 |
+
<span class="tablenav-pages-navspan" aria-hidden="true">‹ </span>';
|
359 |
+
} else {
|
360 |
+
$prev_page = $current_pager_value - 1;
|
361 |
+
if ( $prev_page == 1 ) {
|
362 |
+
$pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">«</span>';
|
363 |
+
} else {
|
364 |
+
$pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=1" title="First page" class="first-page">
|
365 |
+
<span class="screen-reader-text">First page</span>
|
366 |
+
<span aria-hidden="true">«</span>
|
367 |
+
</a> ';
|
368 |
+
}
|
369 |
+
$pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=' . $prev_page . '" title="Previous page" class="prev-page">
|
370 |
+
<span class="screen-reader-text">Previous page</span>
|
371 |
+
<span aria-hidden="true">‹</span>
|
372 |
+
</a> ';
|
373 |
+
}
|
374 |
+
|
375 |
+
$pagination_html .= '<span class="paging-input">
|
376 |
+
<label for="current-page-selector" class="screen-reader-text">Current Page</label>
|
377 |
+
<input class="current-page" id="current-page-selector" type="text" name="paged" value="' . $current_pager_value . '" size="1" aria-describedby="table-paging" />
|
378 |
+
<span class="tablenav-paging-text"> of <span class="total-pages">' . $total_pager . ' </span> </span>
|
379 |
+
</span>';
|
380 |
+
|
381 |
+
if ( $current_pager_value == $total_pager ) {
|
382 |
+
$pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">› </span>
|
383 |
+
<span class="tablenav-pages-navspan" aria-hidden="true">» </span>';
|
384 |
+
} else {
|
385 |
+
$next_page = $current_pager_value + 1;
|
386 |
+
$pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=' . $next_page . '" title="Next page" class="next-page">
|
387 |
+
<span class="screen-reader-text">Next page</span>
|
388 |
+
<span aria-hidden="true">›</span>
|
389 |
+
</a> ';
|
390 |
+
if ( $total_pager == $next_page) {
|
391 |
+
$pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">»</span>';
|
392 |
+
} else {
|
393 |
+
$pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=' . $total_pager . '" title="Last page" class="last-page">
|
394 |
+
<span class="screen-reader-text">Last page</span>
|
395 |
+
<span aria-hidden="true">»</span>
|
396 |
+
</a> ';
|
397 |
+
}
|
398 |
+
|
399 |
+
}
|
400 |
+
$pagination_html .= '</span></div>';
|
401 |
+
|
402 |
+
return $pagination_html;
|
403 |
+
}
|
404 |
+
|
405 |
+
}
|
admin/class-custom-permalinks-form.php
DELETED
@@ -1,334 +0,0 @@
|
|
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 );
|
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 );
|
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 ) {
|
195 |
-
?>
|
196 |
-
<input value="true" type="hidden" name="custom_permalinks_edit" />
|
197 |
-
<input value="<?php echo htmlspecialchars( urldecode( $permalink ) ); ?>" type="hidden" name="custom_permalink" id="custom_permalink" />
|
198 |
-
|
199 |
-
<?php if ( $renderContainers ) : ?>
|
200 |
-
<table class="form-table" id="custom_permalink_form">
|
201 |
-
<tr>
|
202 |
-
<th scope="row"><?php _e( 'Custom Permalink', 'custom-permalinks' ); ?></th>
|
203 |
-
<td>
|
204 |
-
<?php endif; ?>
|
205 |
-
|
206 |
-
<?php
|
207 |
-
if ( $permalink == '' ) {
|
208 |
-
$original = $this->custom_permalinks_check_conflicts( $original );
|
209 |
-
}
|
210 |
-
?>
|
211 |
-
|
212 |
-
<?php echo home_url() ?>/
|
213 |
-
<span id="editable-post-name" title="Click to edit this part of the permalink">
|
214 |
-
<?php
|
215 |
-
$post_slug = htmlspecialchars( $permalink ? urldecode( $permalink ) : urldecode( $original ) );
|
216 |
-
$original_encoded_url = htmlspecialchars( urldecode( $original ) );
|
217 |
-
?>
|
218 |
-
<input type="text" id="new-post-slug" class="text" value="<?php echo $post_slug; ?>"
|
219 |
-
style="width: 250px; <?php if ( !$permalink ) echo 'color: #ddd'; ?>"
|
220 |
-
onfocus="if ( this.style.color = '#ddd' ) { this.style.color = '#000'; }"
|
221 |
-
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'; }" />
|
222 |
-
</span>
|
223 |
-
|
224 |
-
<?php if ( $renderContainers ) : ?>
|
225 |
-
<br />
|
226 |
-
<small><?php _e( 'Leave blank to disable', 'custom-permalinks' ); ?></small>
|
227 |
-
</td>
|
228 |
-
</tr>
|
229 |
-
</table>
|
230 |
-
<?php
|
231 |
-
endif;
|
232 |
-
}
|
233 |
-
|
234 |
-
/**
|
235 |
-
* Save per-tag options
|
236 |
-
*/
|
237 |
-
public function custom_permalinks_save_tag( $id ) {
|
238 |
-
if ( ! isset( $_REQUEST['custom_permalinks_edit'] )
|
239 |
-
|| isset( $_REQUEST['post_ID'] ) ) {
|
240 |
-
return;
|
241 |
-
}
|
242 |
-
$newPermalink = ltrim( stripcslashes( $_REQUEST['custom_permalink'] ), "/" );
|
243 |
-
|
244 |
-
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
|
245 |
-
$custom_permalinks_frontend = new Custom_Permalinks_Frontend();
|
246 |
-
if ( $newPermalink == $custom_permalinks_frontend->custom_permalinks_original_tag_link( $id ) ) {
|
247 |
-
$newPermalink = '';
|
248 |
-
}
|
249 |
-
|
250 |
-
$term = get_term( $id, 'post_tag' );
|
251 |
-
$this->custom_permalinks_save_term( $term, str_replace( '%2F', '/', urlencode( $newPermalink ) ) );
|
252 |
-
}
|
253 |
-
|
254 |
-
/**
|
255 |
-
* Save per-category options
|
256 |
-
*/
|
257 |
-
public function custom_permalinks_save_category( $id ) {
|
258 |
-
if ( ! isset( $_REQUEST['custom_permalinks_edit'] )
|
259 |
-
|| isset( $_REQUEST['post_ID'] ) ) {
|
260 |
-
return;
|
261 |
-
}
|
262 |
-
$newPermalink = ltrim( stripcslashes( $_REQUEST['custom_permalink'] ), "/" );
|
263 |
-
|
264 |
-
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
|
265 |
-
$custom_permalinks_frontend = new Custom_Permalinks_Frontend();
|
266 |
-
if ( $newPermalink == $custom_permalinks_frontend->custom_permalinks_original_category_link( $id ) ) {
|
267 |
-
$newPermalink = '';
|
268 |
-
}
|
269 |
-
|
270 |
-
$term = get_term( $id, 'category' );
|
271 |
-
$this->custom_permalinks_save_term( $term, str_replace( '%2F', '/', urlencode( $newPermalink ) ) );
|
272 |
-
}
|
273 |
-
|
274 |
-
/**
|
275 |
-
* Save term (common to tags and categories)
|
276 |
-
*/
|
277 |
-
public function custom_permalinks_save_term( $term, $permalink ) {
|
278 |
-
|
279 |
-
$this->custom_permalinks_delete_term( $term->term_id );
|
280 |
-
$table = get_option( 'custom_permalink_table' );
|
281 |
-
if ( $permalink ) {
|
282 |
-
$table[$permalink] = array(
|
283 |
-
'id' => $term->term_id,
|
284 |
-
'kind' => ( $term->taxonomy == 'category' ? 'category' : 'tag' ),
|
285 |
-
'slug' => $term->slug
|
286 |
-
);
|
287 |
-
}
|
288 |
-
|
289 |
-
update_option( 'custom_permalink_table', $table );
|
290 |
-
}
|
291 |
-
|
292 |
-
/**
|
293 |
-
* Delete term
|
294 |
-
*/
|
295 |
-
public function custom_permalinks_delete_term( $id ) {
|
296 |
-
$table = get_option( 'custom_permalink_table' );
|
297 |
-
if ( $table ) {
|
298 |
-
foreach ( $table as $link => $info ) {
|
299 |
-
if ( $info['id'] == $id ) {
|
300 |
-
unset( $table[$link] );
|
301 |
-
break;
|
302 |
-
}
|
303 |
-
}
|
304 |
-
}
|
305 |
-
update_option( 'custom_permalink_table', $table );
|
306 |
-
}
|
307 |
-
|
308 |
-
/**
|
309 |
-
* Check Conflicts and resolve it (e.g: Polylang)
|
310 |
-
*/
|
311 |
-
public function custom_permalinks_check_conflicts( $requested_url = '' ) {
|
312 |
-
if ( $requested_url == '' ) {
|
313 |
-
return;
|
314 |
-
}
|
315 |
-
|
316 |
-
// Check if the Polylang Plugin is installed so, make changes in the URL
|
317 |
-
if ( defined( 'POLYLANG_VERSION' ) ) {
|
318 |
-
$polylang_config = get_option( 'polylang' );
|
319 |
-
if ( $polylang_config['force_lang'] == 1 ) {
|
320 |
-
|
321 |
-
if ( strpos( $requested_url, 'language/' ) !== false ) {
|
322 |
-
$requested_url = str_replace( "language/", "", $requested_url );
|
323 |
-
}
|
324 |
-
|
325 |
-
$remove_lang = ltrim( strstr( $requested_url, '/' ), '/' );
|
326 |
-
if ( $remove_lang != '' ) {
|
327 |
-
return $remove_lang;
|
328 |
-
}
|
329 |
-
}
|
330 |
-
}
|
331 |
-
return $requested_url;
|
332 |
-
}
|
333 |
-
|
334 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.5
|
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
CHANGED
@@ -249,7 +249,7 @@ class Custom_Permalinks_Form {
|
|
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 |
-
|
253 |
}
|
254 |
|
255 |
$term = get_term( $id, 'post_tag' );
|
@@ -269,7 +269,7 @@ class Custom_Permalinks_Form {
|
|
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 |
-
|
273 |
}
|
274 |
|
275 |
$term = get_term( $id, 'category' );
|
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 |
+
return;
|
253 |
}
|
254 |
|
255 |
$term = get_term( $id, 'post_tag' );
|
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 |
+
return;
|
273 |
}
|
274 |
|
275 |
$term = get_term( $id, 'category' );
|
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.4 =
|
51 |
|
52 |
* Fixed Slug issue with Yoast SEO
|
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.5
|
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.5 =
|
51 |
+
|
52 |
+
* Fixed Category/Tag Update Issue + Typo on Admin Page
|
53 |
+
|
54 |
= 1.2.4 =
|
55 |
|
56 |
* Fixed Slug issue with Yoast SEO
|