Version Description
- Enhancements
- Added Filter to Exclude Post types
- Bugs
- Fixed Query Issue on parse_request
- Resolving Issues with Cornerstone
Download this release
Release Info
Developer | sasiddiqui |
Plugin | Custom Permalinks |
Version | 1.2.6 |
Comparing to | |
See all releases |
Code changes from version 1.2.5 to 1.2.6
- README.md +0 -22
- admin/class-custom-permalinks-admin.php +405 -405
- custom-permalinks-main.php +1 -1
- custom-permalinks.php +1 -1
- frontend/class-custom-permalinks-form.php +8 -1
- frontend/class-custom-permalinks-frontend.php +88 -36
- readme.txt +30 -2
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
@@ -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 = 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 |
-
}
|
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 |
+
}
|
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__ ) );
|
15 |
exit();
|
16 |
}
|
17 |
|
18 |
+
define( 'CUSTOM_PERMALINKS_PLUGIN_VERSION', '1.2.6' );
|
19 |
|
20 |
if ( ! defined( 'CUSTOM_PERMALINKS_PATH' ) ) {
|
21 |
define( 'CUSTOM_PERMALINKS_PATH', plugin_dir_path( __FILE__ ) );
|
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.6
|
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
@@ -69,7 +69,14 @@ class Custom_Permalinks_Form {
|
|
69 |
if ( $post->post_type == 'attachment' || $post->ID == get_option( 'page_on_front' ) ) {
|
70 |
return $html;
|
71 |
}
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
|
75 |
$custom_permalinks_frontend = new Custom_Permalinks_Frontend();
|
69 |
if ( $post->post_type == 'attachment' || $post->ID == get_option( 'page_on_front' ) ) {
|
70 |
return $html;
|
71 |
}
|
72 |
+
|
73 |
+
$exclude_post_types = $post->post_type;
|
74 |
+
$excluded = apply_filters( 'custom_permalinks_exclude_post_type', $exclude_post_types );
|
75 |
+
if ( '__true' === $excluded ) {
|
76 |
+
return $html;
|
77 |
+
}
|
78 |
+
|
79 |
+
ob_start();
|
80 |
|
81 |
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
|
82 |
$custom_permalinks_frontend = new Custom_Permalinks_Frontend();
|
frontend/class-custom-permalinks-frontend.php
CHANGED
@@ -39,7 +39,10 @@ class Custom_Permalinks_Frontend {
|
|
39 |
$url = parse_url( get_bloginfo( 'url' ) );
|
40 |
$url = isset( $url['path'] ) ? $url['path'] : '';
|
41 |
$request = ltrim( substr( $_SERVER['REQUEST_URI'], strlen( $url ) ), '/' );
|
42 |
-
$
|
|
|
|
|
|
|
43 |
|
44 |
if ( ! $request ) {
|
45 |
return $query;
|
@@ -58,18 +61,29 @@ class Custom_Permalinks_Frontend {
|
|
58 |
}
|
59 |
$request_noslash = preg_replace( '@/+@','/', trim( $request, '/' ) );
|
60 |
|
61 |
-
$sql = $wpdb->prepare( "SELECT
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
" meta_key = 'custom_permalink' AND meta_value != '' AND " .
|
64 |
" ( LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) OR " .
|
65 |
" LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) ) " .
|
66 |
" AND post_status != 'trash' AND post_type != 'nav_menu_item'" .
|
67 |
" ORDER BY LENGTH(meta_value) DESC, " .
|
68 |
" FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
|
69 |
-
" FIELD(post_type,'post','page'),
|
70 |
-
|
71 |
|
72 |
-
|
|
|
73 |
|
74 |
if ( $posts ) {
|
75 |
// A post matches our request
|
@@ -81,9 +95,9 @@ class Custom_Permalinks_Frontend {
|
|
81 |
|
82 |
if ( $posts[0]->post_status == 'draft' ) {
|
83 |
if ( $posts[0]->post_type == 'page' ) {
|
84 |
-
$original_url =
|
85 |
} else {
|
86 |
-
$original_url =
|
87 |
}
|
88 |
} else {
|
89 |
$post_meta = trim( strtolower( $posts[0]->meta_value ), '/' );
|
@@ -110,7 +124,7 @@ class Custom_Permalinks_Frontend {
|
|
110 |
|
111 |
foreach ( array_keys( $table ) as $permalink ) {
|
112 |
if ( $permalink == substr( $request_noslash, 0, strlen( $permalink ) )
|
113 |
-
|| $permalink == substr( $request_noslash .
|
114 |
$term = $table[$permalink];
|
115 |
|
116 |
// Preserve this url for later if it's the same as the permalink (no extra stuff)
|
@@ -172,11 +186,17 @@ class Custom_Permalinks_Frontend {
|
|
172 |
* Action to redirect to the custom permalink
|
173 |
*/
|
174 |
public function custom_permalinks_redirect() {
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
// Get request URI, strip parameters
|
176 |
$url = parse_url( get_bloginfo( 'url' ) );
|
177 |
$url = isset( $url['path'] ) ? $url['path'] : '';
|
178 |
$request = ltrim( substr( $_SERVER['REQUEST_URI'], strlen( $url ) ), '/' );
|
179 |
-
$pos = strpos( $request,
|
180 |
if ( $pos ) {
|
181 |
$request = substr( $request, 0, $pos );
|
182 |
}
|
@@ -186,34 +206,66 @@ class Custom_Permalinks_Frontend {
|
|
186 |
$custom_permalinks_form = new Custom_Permalinks_Form();
|
187 |
$request = $custom_permalinks_form->custom_permalinks_check_conflicts( $request );
|
188 |
}
|
|
|
189 |
|
190 |
-
global $wp_query;
|
191 |
|
192 |
-
$
|
193 |
-
|
|
|
|
|
|
|
|
|
|
|
194 |
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
}
|
204 |
-
}
|
205 |
-
$
|
206 |
-
|
207 |
-
|
208 |
-
$original_permalink = $this->custom_permalinks_original_tag_link( $theTerm->term_id );
|
209 |
} else {
|
210 |
-
$original_permalink = $this->
|
211 |
}
|
212 |
}
|
213 |
|
214 |
if ( $custom_permalink
|
215 |
&& ( substr( $request, 0, strlen( $custom_permalink ) ) != $custom_permalink
|
216 |
-
|| $request == $custom_permalink .
|
217 |
|
218 |
// Request doesn't match permalink - redirect
|
219 |
$url = $custom_permalink;
|
@@ -226,9 +278,9 @@ class Custom_Permalinks_Frontend {
|
|
226 |
}
|
227 |
|
228 |
// Append any query compenent
|
229 |
-
$url .= strstr( $_SERVER['REQUEST_URI'],
|
230 |
|
231 |
-
wp_redirect( home_url() .
|
232 |
exit();
|
233 |
}
|
234 |
}
|
@@ -242,9 +294,9 @@ class Custom_Permalinks_Frontend {
|
|
242 |
$post_type = isset( $post->post_type ) ? $post->post_type : 'post';
|
243 |
$language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $post->ID, 'element_type' => $post_type ) );
|
244 |
if ( $language_code )
|
245 |
-
return apply_filters( 'wpml_permalink', home_url() .
|
246 |
else
|
247 |
-
return apply_filters( 'wpml_permalink', home_url() .
|
248 |
}
|
249 |
|
250 |
return $permalink;
|
@@ -258,9 +310,9 @@ class Custom_Permalinks_Frontend {
|
|
258 |
if ( $custom_permalink ) {
|
259 |
$language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $page, 'element_type' => 'page' ) );
|
260 |
if ( $language_code )
|
261 |
-
return apply_filters( 'wpml_permalink', home_url() .
|
262 |
else
|
263 |
-
return apply_filters( 'wpml_permalink', home_url() .
|
264 |
}
|
265 |
|
266 |
return $permalink;
|
@@ -281,9 +333,9 @@ class Custom_Permalinks_Frontend {
|
|
281 |
if ( isset( $taxonomy ) && isset( $taxonomy->term_taxonomy_id ) ) {
|
282 |
$term_type = isset( $taxonomy->taxonomy ) ? $taxonomy->taxonomy : 'category';
|
283 |
$language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $taxonomy->term_taxonomy_id, 'element_type' => $term_type ) );
|
284 |
-
return apply_filters( 'wpml_permalink', home_url() .
|
285 |
} else {
|
286 |
-
return apply_filters( 'wpml_permalink', home_url() .
|
287 |
}
|
288 |
}
|
289 |
|
39 |
$url = parse_url( get_bloginfo( 'url' ) );
|
40 |
$url = isset( $url['path'] ) ? $url['path'] : '';
|
41 |
$request = ltrim( substr( $_SERVER['REQUEST_URI'], strlen( $url ) ), '/' );
|
42 |
+
$pos = strpos( $request, '?' );
|
43 |
+
if ( $pos ) {
|
44 |
+
$request = substr( $request, 0, $pos );
|
45 |
+
}
|
46 |
|
47 |
if ( ! $request ) {
|
48 |
return $query;
|
61 |
}
|
62 |
$request_noslash = preg_replace( '@/+@','/', trim( $request, '/' ) );
|
63 |
|
64 |
+
$sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status " .
|
65 |
+
" FROM $wpdb->posts AS p INNER JOIN $wpdb->postmeta AS pm ON (pm.post_id = p.ID) " .
|
66 |
+
" WHERE pm.meta_key = 'custom_permalink' " .
|
67 |
+
" AND (pm.meta_value = '%s' OR pm.meta_value = '%s') " .
|
68 |
+
" AND p.post_status != 'trash' AND p.post_type != 'nav_menu_item' " .
|
69 |
+
" LIMIT 1", $request_noslash, $request_noslash . "/" );
|
70 |
+
|
71 |
+
$posts = $wpdb->get_results( $sql );
|
72 |
+
|
73 |
+
if ( ! $posts ) {
|
74 |
+
$sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status FROM $wpdb->posts AS p " .
|
75 |
+
" LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE " .
|
76 |
" meta_key = 'custom_permalink' AND meta_value != '' AND " .
|
77 |
" ( LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) OR " .
|
78 |
" LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) ) " .
|
79 |
" AND post_status != 'trash' AND post_type != 'nav_menu_item'" .
|
80 |
" ORDER BY LENGTH(meta_value) DESC, " .
|
81 |
" FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
|
82 |
+
" FIELD(post_type,'post','page'), p.ID ASC LIMIT 1",
|
83 |
+
$request_noslash, $request_noslash . "/" );
|
84 |
|
85 |
+
$posts = $wpdb->get_results( $sql );
|
86 |
+
}
|
87 |
|
88 |
if ( $posts ) {
|
89 |
// A post matches our request
|
95 |
|
96 |
if ( $posts[0]->post_status == 'draft' ) {
|
97 |
if ( $posts[0]->post_type == 'page' ) {
|
98 |
+
$original_url = '?page_id=' . $posts[0]->ID;
|
99 |
} else {
|
100 |
+
$original_url = '?post_type=' . $posts[0]->post_type . '&p=' . $posts[0]->ID;
|
101 |
}
|
102 |
} else {
|
103 |
$post_meta = trim( strtolower( $posts[0]->meta_value ), '/' );
|
124 |
|
125 |
foreach ( array_keys( $table ) as $permalink ) {
|
126 |
if ( $permalink == substr( $request_noslash, 0, strlen( $permalink ) )
|
127 |
+
|| $permalink == substr( $request_noslash . '/', 0, strlen( $permalink ) ) ) {
|
128 |
$term = $table[$permalink];
|
129 |
|
130 |
// Preserve this url for later if it's the same as the permalink (no extra stuff)
|
186 |
* Action to redirect to the custom permalink
|
187 |
*/
|
188 |
public function custom_permalinks_redirect() {
|
189 |
+
|
190 |
+
global $wpdb;
|
191 |
+
|
192 |
+
$custom_permalink = '';
|
193 |
+
$original_permalink = '';
|
194 |
+
|
195 |
// Get request URI, strip parameters
|
196 |
$url = parse_url( get_bloginfo( 'url' ) );
|
197 |
$url = isset( $url['path'] ) ? $url['path'] : '';
|
198 |
$request = ltrim( substr( $_SERVER['REQUEST_URI'], strlen( $url ) ), '/' );
|
199 |
+
$pos = strpos( $request, '?' );
|
200 |
if ( $pos ) {
|
201 |
$request = substr( $request, 0, $pos );
|
202 |
}
|
206 |
$custom_permalinks_form = new Custom_Permalinks_Form();
|
207 |
$request = $custom_permalinks_form->custom_permalinks_check_conflicts( $request );
|
208 |
}
|
209 |
+
$request_noslash = preg_replace( '@/+@','/', trim( $request, '/' ) );
|
210 |
|
|
|
211 |
|
212 |
+
$sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status " .
|
213 |
+
" FROM $wpdb->posts AS p INNER JOIN $wpdb->postmeta AS pm ON (pm.post_id = p.ID) " .
|
214 |
+
" WHERE pm.meta_key = 'custom_permalink' " .
|
215 |
+
" AND (pm.meta_value = '%s' OR pm.meta_value = '%s') " .
|
216 |
+
" AND p.post_status != 'trash' AND p.post_type != 'nav_menu_item' " .
|
217 |
+
" LIMIT 1", $request_noslash, $request_noslash . "/" );
|
218 |
+
$posts = $wpdb->get_results( $sql );
|
219 |
|
220 |
+
if ( ! $posts ) {
|
221 |
+
$sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status FROM $wpdb->posts AS p " .
|
222 |
+
" LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE " .
|
223 |
+
" meta_key = 'custom_permalink' AND meta_value != '' AND " .
|
224 |
+
" ( LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) OR " .
|
225 |
+
" LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) ) " .
|
226 |
+
" AND post_status != 'trash' AND post_type != 'nav_menu_item'" .
|
227 |
+
" ORDER BY LENGTH(meta_value) DESC, " .
|
228 |
+
" FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
|
229 |
+
" FIELD(post_type,'post','page'), p.ID ASC LIMIT 1",
|
230 |
+
$request_noslash, $request_noslash . "/" );
|
231 |
+
|
232 |
+
$posts = $wpdb->get_results( $sql );
|
233 |
+
}
|
234 |
+
|
235 |
+
if ( ! isset( $posts[0]->ID ) || ! isset( $posts[0]->meta_value )
|
236 |
+
&& empty( ($posts[0]->meta_value)) ) {
|
237 |
+
global $wp_query;
|
238 |
+
|
239 |
+
// If the post/tag/category we're on has a custom permalink, get it and check against the request
|
240 |
+
if ( ( is_single() || is_page() ) && ! empty( $wp_query->post ) ) {
|
241 |
+
$post = $wp_query->post;
|
242 |
+
$custom_permalink = get_post_meta( $post->ID, 'custom_permalink', true );
|
243 |
+
if ( $post->post_type == 'page' ) {
|
244 |
+
$original_permalink = $this->custom_permalinks_original_page_link( $post->ID );
|
245 |
+
} else {
|
246 |
+
$original_permalink = $this->custom_permalinks_original_post_link( $post->ID );
|
247 |
+
}
|
248 |
+
} elseif ( is_tag() || is_category() ) {
|
249 |
+
$theTerm = $wp_query->get_queried_object();
|
250 |
+
$custom_permalink = $this->custom_permalinks_permalink_for_term( $theTerm->term_id );
|
251 |
+
if ( is_tag() ) {
|
252 |
+
$original_permalink = $this->custom_permalinks_original_tag_link( $theTerm->term_id );
|
253 |
+
} else {
|
254 |
+
$original_permalink = $this->custom_permalinks_original_category_link( $theTerm->term_id );
|
255 |
+
}
|
256 |
}
|
257 |
+
} else {
|
258 |
+
$custom_permalink = $posts[0]->meta_value;
|
259 |
+
if ( $posts[0]->post_type == 'page' ) {
|
260 |
+
$original_permalink = $this->custom_permalinks_original_page_link( $posts[0]->ID );
|
|
|
261 |
} else {
|
262 |
+
$original_permalink = $this->custom_permalinks_original_post_link( $posts[0]->ID );
|
263 |
}
|
264 |
}
|
265 |
|
266 |
if ( $custom_permalink
|
267 |
&& ( substr( $request, 0, strlen( $custom_permalink ) ) != $custom_permalink
|
268 |
+
|| $request == $custom_permalink . '/' ) ) {
|
269 |
|
270 |
// Request doesn't match permalink - redirect
|
271 |
$url = $custom_permalink;
|
278 |
}
|
279 |
|
280 |
// Append any query compenent
|
281 |
+
$url .= strstr( $_SERVER['REQUEST_URI'], '?' );
|
282 |
|
283 |
+
wp_redirect( home_url() . '/' . $url, 301 );
|
284 |
exit();
|
285 |
}
|
286 |
}
|
294 |
$post_type = isset( $post->post_type ) ? $post->post_type : 'post';
|
295 |
$language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $post->ID, 'element_type' => $post_type ) );
|
296 |
if ( $language_code )
|
297 |
+
return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink, $language_code );
|
298 |
else
|
299 |
+
return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink );
|
300 |
}
|
301 |
|
302 |
return $permalink;
|
310 |
if ( $custom_permalink ) {
|
311 |
$language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $page, 'element_type' => 'page' ) );
|
312 |
if ( $language_code )
|
313 |
+
return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink, $language_code );
|
314 |
else
|
315 |
+
return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink );
|
316 |
}
|
317 |
|
318 |
return $permalink;
|
333 |
if ( isset( $taxonomy ) && isset( $taxonomy->term_taxonomy_id ) ) {
|
334 |
$term_type = isset( $taxonomy->taxonomy ) ? $taxonomy->taxonomy : 'category';
|
335 |
$language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $taxonomy->term_taxonomy_id, 'element_type' => $term_type ) );
|
336 |
+
return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink, $language_code );
|
337 |
} else {
|
338 |
+
return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink );
|
339 |
}
|
340 |
}
|
341 |
|
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 |
|
@@ -26,7 +26,7 @@ within that category.
|
|
26 |
|
27 |
> 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.
|
28 |
|
29 |
-
==
|
30 |
|
31 |
If you want to exclude some Permalink to processed with the plugin so, just add the filter looks like this:
|
32 |
`
|
@@ -39,6 +39,26 @@ function check_xml_sitemap_url( $permalink ) {
|
|
39 |
add_filter( 'custom_permalinks_request_ignore', 'check_xml_sitemap_url' );
|
40 |
`
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
== Installation ==
|
43 |
|
44 |
1. Unzip the package, and upload `custom-permalinks` to the `/wp-content/plugins/` directory
|
@@ -47,6 +67,14 @@ add_filter( 'custom_permalinks_request_ignore', 'check_xml_sitemap_url' );
|
|
47 |
|
48 |
== Changelog ==
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
= 1.2.5 =
|
51 |
|
52 |
* Fixed Category/Tag Update Issue + Typo on Admin 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.6
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
|
26 |
|
27 |
> 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.
|
28 |
|
29 |
+
== Filters ==
|
30 |
|
31 |
If you want to exclude some Permalink to processed with the plugin so, just add the filter looks like this:
|
32 |
`
|
39 |
add_filter( 'custom_permalinks_request_ignore', 'check_xml_sitemap_url' );
|
40 |
`
|
41 |
|
42 |
+
If you want to exclude permalink from any post type so, use `custom_permalinks_exclude_post_type` filter.
|
43 |
+
|
44 |
+
`custom_permalinks_exclude_post_type` filter looks like this:
|
45 |
+
`
|
46 |
+
function yasglobal_exclude_post_types( $post_type ) {
|
47 |
+
if ( $post_type == 'custompost' ) {
|
48 |
+
return '__true';
|
49 |
+
}
|
50 |
+
return '__false';
|
51 |
+
}
|
52 |
+
add_filter( 'custom_permalinks_exclude_post_type', 'yasglobal_exclude_post_types');
|
53 |
+
`
|
54 |
+
Note: `custom_permalinks_exclude_post_type` doesn't work on the posts permalink which has been created previously.
|
55 |
+
|
56 |
+
== Thanks for the Support! ==
|
57 |
+
|
58 |
+
The support from the users that love Custom Permalinks is huge. You can support Custom Permalinks's future development and help to make it even better by donating or even giving a 5 star rating with a nice message to me :)
|
59 |
+
|
60 |
+
[Donate to Custom Permalinks](https://www.paypal.me/yasglobal)
|
61 |
+
|
62 |
== Installation ==
|
63 |
|
64 |
1. Unzip the package, and upload `custom-permalinks` to the `/wp-content/plugins/` directory
|
67 |
|
68 |
== Changelog ==
|
69 |
|
70 |
+
= 1.2.6 =
|
71 |
+
|
72 |
+
* Enhancements
|
73 |
+
* Added Filter to Exclude Post types
|
74 |
+
* Bugs
|
75 |
+
* Fixed Query Issue on parse_request
|
76 |
+
* Resolving Issues with Cornerstone
|
77 |
+
|
78 |
= 1.2.5 =
|
79 |
|
80 |
* Fixed Category/Tag Update Issue + Typo on Admin Page
|