Version Description
-
April 05, 2018 =
- Enhancement
- Merged custom-permalinks-main.php with custom-permalinks.php
- Added uninstall.php
- Bugs
- Added feed redirect of default permalink
- Provide proper feed of custom permalink
Download this release
Release Info
Developer | sasiddiqui |
Plugin | Custom Permalinks |
Version | 1.2.18 |
Comparing to | |
See all releases |
Code changes from version 1.2.17 to 1.2.18
- admin/class-custom-permalinks-about.php +145 -141
- admin/class-custom-permalinks-admin.php +551 -505
- changelog.txt +19 -19
- custom-permalinks-main.php +0 -49
- custom-permalinks.php +81 -6
- frontend/class-custom-permalinks-form.php +398 -378
- frontend/class-custom-permalinks-frontend.php +499 -438
- languages/index.php +3 -3
- readme.txt +22 -13
- uninstall.php +19 -0
admin/class-custom-permalinks-about.php
CHANGED
@@ -3,145 +3,149 @@
|
|
3 |
* @package CustomPermalinks\Admin
|
4 |
*/
|
5 |
|
6 |
-
class Custom_Permalinks_About {
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
|
|
|
|
|
|
|
|
147 |
}
|
3 |
* @package CustomPermalinks\Admin
|
4 |
*/
|
5 |
|
6 |
+
final class Custom_Permalinks_About {
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Class constructor.
|
10 |
+
*/
|
11 |
+
public function __construct() {
|
12 |
+
$this->more_plugins();
|
13 |
+
}
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Print HTML for Custom Permalinks ABout Page
|
17 |
+
*
|
18 |
+
* @access private
|
19 |
+
* @since 1.2.11
|
20 |
+
* @return void
|
21 |
+
*/
|
22 |
+
private function more_plugins() {
|
23 |
+
$plugin_url = plugins_url( '/admin', CUSTOM_PERMALINKS_FILE );
|
24 |
+
$img_src = $plugin_url . '/images';
|
25 |
+
wp_enqueue_style( 'style', $plugin_url . '/css/about-plugins.min.css' );
|
26 |
+
$plugin_name = __( 'Custom Permalinks', 'custom-permalinks' );
|
27 |
+
$button_text = __( 'Check it out', 'custom-permalinks' );
|
28 |
+
$five_star = '<span class="star">
|
29 |
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 53.867 53.867" width="15" height="15">
|
30 |
+
<polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798
|
31 |
+
10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/>
|
32 |
+
</svg>
|
33 |
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 53.867 53.867" width="15" height="15">
|
34 |
+
<polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798
|
35 |
+
10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/>
|
36 |
+
</svg>
|
37 |
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 53.867 53.867" width="15" height="15">
|
38 |
+
<polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798
|
39 |
+
10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/>
|
40 |
+
</svg>
|
41 |
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 53.867 53.867" width="15" height="15">
|
42 |
+
<polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798
|
43 |
+
10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/>
|
44 |
+
</svg>
|
45 |
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 53.867 53.867" width="15" height="15">
|
46 |
+
<polygon points="26.934,1.318 35.256,18.182 53.867,20.887 40.4,34.013 43.579,52.549 26.934,43.798
|
47 |
+
10.288,52.549 13.467,34.013 0,20.887 18.611,18.182 "/>
|
48 |
+
</svg>
|
49 |
+
</span>';
|
50 |
+
?>
|
51 |
+
|
52 |
+
<div class="wrap">
|
53 |
+
<div class="float">
|
54 |
+
<h1><?php echo $plugin_name . ' v' . CUSTOM_PERMALINKS_PLUGIN_VERSION; ?></h1>
|
55 |
+
<div class="tagline">
|
56 |
+
<p><?php _e('Thank you for choosing Custom Permalinks! We hope that your experience with our plugin for updating permalinks is quick and easy. We are trying to make it more feasible for you and provide capabilities in it.', 'custom-permalinks' ); ?></p>
|
57 |
+
<p><?php printf( __( 'To support future development and help to make it even better just leaving us a <a href="%s" title="Custom Permalinks Rating" target="_blank">%s</a> rating with a nice message to me :)', 'custom-permalinks' ), 'https://wordpress.org/support/plugin/custom-permalinks/reviews/?rate=5#new-post', $five_star ); ?></p>
|
58 |
+
</div>
|
59 |
+
</div>
|
60 |
+
|
61 |
+
<div class="float">
|
62 |
+
<object type="image/svg+xml" data="<?php echo $img_src;?>/custom-permalinks.svg" width="128" height="128"></object>
|
63 |
+
</div>
|
64 |
+
|
65 |
+
<div class="product">
|
66 |
+
<h2><?php _e( 'More from Sami Ahmed Siddiqui', 'custom-permalinks' ); ?></h2>
|
67 |
+
<span><?php _e('Our List of Plugins provides the services which helps you to manage your site URLs(Permalinks), Prevent your site from XSS Attacks, Brute force attacks, increase your site visitors by adding Structured JSON Markup and so on.', 'custom-permalinks' ); ?></span>
|
68 |
+
<div class="box recommended">
|
69 |
+
<div class="img">
|
70 |
+
<img src= "<?php echo $img_src; ?>/prevent-xss-vulnerability.png" style="transform:scale(1.5)" />
|
71 |
+
</div>
|
72 |
+
|
73 |
+
<h3><?php _e( 'Prevent XSS Vulnerability', 'custom-permalinks' ); ?></h3>
|
74 |
+
<p><?php _e( 'Secure your site from the <strong>XSS Attacks</strong> so, your users won\'t lose any kind of information or not redirected to any other site by visiting to your site with the <strong>malicious code</strong> in the URL or so. In this way, users can open your site URLs without any hesitation.', 'custom-permalinks' ); ?></p>
|
75 |
+
<a href="https://wordpress.org/plugins/prevent-xss-vulnerability/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
|
76 |
+
</div>
|
77 |
+
|
78 |
+
<div class="box">
|
79 |
+
<div class="img">
|
80 |
+
<img src= "<?php echo $img_src; ?>/permalinks-customizer.svg" />
|
81 |
+
</div>
|
82 |
+
|
83 |
+
<h3><?php _e( 'Permalinks Customizer', 'custom-permalinks' ); ?></h3>
|
84 |
+
<p><?php _e( 'Allows you to either define different Permalink Structure or define same Permalink Structure for default and Custom PostTypes, Taxonomies. Plugin automatically creates the user-friendly URLs as per your defined structured that can be edited from the single post/page.', 'custom-permalinks' ); ?></p>
|
85 |
+
<a href="https://wordpress.org/plugins/permalinks-customizer/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
|
86 |
+
</div>
|
87 |
+
|
88 |
+
<div class="box recommended">
|
89 |
+
<div class="img">
|
90 |
+
<img src= "<?php echo $img_src; ?>/http-auth.svg" />
|
91 |
+
</div>
|
92 |
+
|
93 |
+
<h3><?php _e( 'Http Auth', 'schema-for-article' ); ?></h3>
|
94 |
+
<p><?php _e( 'Allows you apply <strong>HTTP Auth</strong> on your site. You can apply Http Authentication all over the site or only the admin pages. It helps to stop cralwing on your site while on development or persist the <strong>Brute Attacks</strong> by locking the Admin Pages.', 'schema-for-article' ); ?></p>
|
95 |
+
<a href="https://wordpress.org/plugins/http-auth/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
|
96 |
+
</div>
|
97 |
+
|
98 |
+
<div class="box">
|
99 |
+
<div class="img">
|
100 |
+
<img src= "<?php echo $img_src; ?>/schema-for-article.svg" />
|
101 |
+
</div>
|
102 |
+
|
103 |
+
<h3><?php _e( 'SCHEMA for Article', 'schema-for-article' ); ?></h3>
|
104 |
+
<p><?php _e( 'Simply the easiest solution to add valid schema.org as a JSON script in the head of blog posts or articles. You can choose the schema either to show with the type of Article or NewsArticle from the settings page.', 'schema-for-article' ); ?></p>
|
105 |
+
<a href="https://wordpress.org/plugins/schema-for-article/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
|
106 |
+
</div>
|
107 |
+
|
108 |
+
<div class="box">
|
109 |
+
<div class="img">
|
110 |
+
<img src= "<?php echo $img_src; ?>/make-paths-relative.svg" />
|
111 |
+
</div>
|
112 |
+
|
113 |
+
<h3><?php _e( 'Make Paths Relative', 'custom-permalinks' ); ?></h3>
|
114 |
+
<p><?php _e( 'Convert the paths(URLs) to relative instead of absolute. You can make <strong>Post</strong>, <strong>Category</strong>, <strong>Archive</strong>, <strong>Image</strong> URLs and <strong>Script</strong> and <strong>Style</strong> src as per your requirement. You can choose which you want to be relative from the settings Page.', 'custom-permalinks' ); ?></p>
|
115 |
+
<a href="https://wordpress.org/plugins/make-paths-relative/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
|
116 |
+
</div>
|
117 |
+
|
118 |
+
<div class="box">
|
119 |
+
<div class="img">
|
120 |
+
<img src= "<?php echo $img_src; ?>/json-structuring-markup.svg" />
|
121 |
+
</div>
|
122 |
+
|
123 |
+
<h3><?php _e( 'JSON Structuring Markup', 'custom-permalinks' ); ?></h3>
|
124 |
+
<p><?php _e( 'Simply the easiest solution to add valid schema.org as a JSON script in the head of posts and pages. It provides you multiple <strong>SCHEMA</strong> types like Article, News Article, Organization and Website Schema.', 'custom-permalinks' ); ?></p>
|
125 |
+
<a href="https://wordpress.org/plugins/json-structuring-markup/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
|
126 |
+
</div>
|
127 |
+
|
128 |
+
<div class="box">
|
129 |
+
<div class="img">
|
130 |
+
<img src= "<?php echo $img_src; ?>/remove-links-and-scripts.svg" />
|
131 |
+
</div>
|
132 |
+
|
133 |
+
<h3><?php _e( 'Remove Links and Scripts', 'custom-permalinks' ); ?></h3>
|
134 |
+
<p><?php _e( 'It removes some meta data from the wordpress header so, your header keeps clean of useless information like <strong>shortlink</strong>, <strong>rsd_link</strong>, <strong>wlwmanifest_link</strong>, <strong>emoji_scripts</strong>, <strong>wp_embed</strong>, <strong>wp_json</strong>, <strong>emoji_styles</strong>, <strong>generator</strong> and so on.', 'custom-permalinks' ); ?></p>
|
135 |
+
<a href="https://wordpress.org/plugins/remove-links-and-scripts/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
|
136 |
+
</div>
|
137 |
+
|
138 |
+
<div class="box">
|
139 |
+
<div class="img">
|
140 |
+
<img src= "<?php echo $img_src; ?>/media-post-permalink.png" style="transform:scale(1.5)" />
|
141 |
+
</div>
|
142 |
+
|
143 |
+
<h3><?php _e( 'Media Post Permalink', 'custom-permalinks' ); ?></h3>
|
144 |
+
<p><?php _e( 'On uploading any image, let\'s say services.png, WordPress creates the <strong>attachment post</strong> with the permalink of <strong>/services/</strong> and doesn\'t allow you to use that permalink to point your page. In this case, we comes up with this great solution.', 'custom-permalinks' ); ?></p>
|
145 |
+
<a href="https://wordpress.org/plugins/media-post-permalink/" class="checkout-button" target="_blank"><?php echo $button_text; ?></a>
|
146 |
+
</div>
|
147 |
+
</div>
|
148 |
+
</div>
|
149 |
+
<?php
|
150 |
+
}
|
151 |
}
|
admin/class-custom-permalinks-admin.php
CHANGED
@@ -3,509 +3,555 @@
|
|
3 |
* @package CustomPermalinks\Admin
|
4 |
*/
|
5 |
|
6 |
-
class Custom_Permalinks_Admin {
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
511 |
}
|
3 |
* @package CustomPermalinks\Admin
|
4 |
*/
|
5 |
|
6 |
+
final class Custom_Permalinks_Admin {
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Initializes WordPress hooks
|
10 |
+
*/
|
11 |
+
function __construct() {
|
12 |
+
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
|
13 |
+
add_filter( 'plugin_action_links_' . CUSTOM_PERMALINKS_BASENAME,
|
14 |
+
array( $this, 'settings_link' )
|
15 |
+
);
|
16 |
+
}
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Added Pages in Menu for Settings
|
20 |
+
*
|
21 |
+
* @access public
|
22 |
+
* @since 1.2
|
23 |
+
* @return void
|
24 |
+
*/
|
25 |
+
public function admin_menu() {
|
26 |
+
add_menu_page( 'Custom Permalinks', 'Custom Permalinks', 'administrator',
|
27 |
+
'cp-post-permalinks', array( $this,'posttype_permalinks' ),
|
28 |
+
'dashicons-admin-links'
|
29 |
+
);
|
30 |
+
add_submenu_page( 'cp-post-permalinks', 'PostTypes Permalinks',
|
31 |
+
'PostTypes Permalinks', 'administrator', 'cp-post-permalinks',
|
32 |
+
array( $this, 'posttype_permalinks' )
|
33 |
+
);
|
34 |
+
add_submenu_page( 'cp-post-permalinks', 'Category Permalinks',
|
35 |
+
'Category Permalinks', 'administrator', 'cp-category-permalinks',
|
36 |
+
array( $this, 'category_permalinks' )
|
37 |
+
);
|
38 |
+
add_submenu_page( 'cp-post-permalinks', 'About Custom Permalinks',
|
39 |
+
'About CP', 'administrator', 'cp-about-plugins',
|
40 |
+
array( $this, 'about_plugin' )
|
41 |
+
);
|
42 |
+
}
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Shows all the Permalinks created by using this Plugin with Pager and
|
46 |
+
* Search Functionality of Posts/Pages.
|
47 |
+
*
|
48 |
+
* @access public
|
49 |
+
* @since 1.2
|
50 |
+
* @return void
|
51 |
+
*/
|
52 |
+
public function posttype_permalinks() {
|
53 |
+
global $wpdb;
|
54 |
+
$filter_options = '';
|
55 |
+
$filter_permalink = '';
|
56 |
+
$search_permalink = '';
|
57 |
+
$html = '';
|
58 |
+
$error = '';
|
59 |
+
|
60 |
+
// Handle Bulk Operations
|
61 |
+
if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'delete' )
|
62 |
+
|| ( isset( $_POST['action2'] ) && $_POST['action2'] == 'delete' )
|
63 |
+
&& isset( $_POST['permalink'] ) && ! empty( $_POST['permalink'] ) ) {
|
64 |
+
$post_ids = implode( ',', $_POST['permalink'] );
|
65 |
+
if ( preg_match( '/^\d+(?:,\d+)*$/', $post_ids ) ) {
|
66 |
+
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE post_id IN ($post_ids) AND meta_key = 'custom_permalink'" );
|
67 |
+
} else {
|
68 |
+
$error = '<div id="message" class="error">
|
69 |
+
<p>' . __( 'There is some error to proceed your request. Please retry with your request or contact to the plugin author.', 'custom-permalinks' ) . '</p>
|
70 |
+
</div>';
|
71 |
+
}
|
72 |
+
}
|
73 |
+
$html .= '<div class="wrap">
|
74 |
+
<h1 class="wp-heading-inline">' . __( 'PostTypes Permalinks', 'custom-permalinks' ) . '</h1>';
|
75 |
+
$html .= $error;
|
76 |
+
|
77 |
+
$search_value = '';
|
78 |
+
if ( isset( $_GET['s'] ) && ! empty( $_GET['s'] ) ) {
|
79 |
+
$filter_permalink = 'AND pm.meta_value LIKE "%' . $_GET['s'] . '%"';
|
80 |
+
$search_permalink = '&s=' . $_GET['s'] . '';
|
81 |
+
$search_value = ltrim( htmlspecialchars( $_GET['s'] ), '/' );
|
82 |
+
$html .= '<span class="subtitle">Search results for "' . $search_value . '"</span>';
|
83 |
+
}
|
84 |
+
$page_limit = 'LIMIT 0, 20';
|
85 |
+
if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] )
|
86 |
+
&& $_GET['paged'] > 1 ) {
|
87 |
+
$pager = 20 * ( $_GET['paged'] - 1 );
|
88 |
+
$page_limit = 'LIMIT ' . $pager . ', 20';
|
89 |
+
}
|
90 |
+
$sorting_by = 'ORDER By p.ID DESC';
|
91 |
+
$order_by = 'asc';
|
92 |
+
$order_by_class = 'desc';
|
93 |
+
if ( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'title' ) {
|
94 |
+
$filter_options .= '<input type="hidden" name="orderby" value="title" />';
|
95 |
+
if ( isset( $_GET['order'] ) && $_GET['order'] == 'desc' ) {
|
96 |
+
$sorting_by = 'ORDER By p.post_title DESC';
|
97 |
+
$order_by = 'asc';
|
98 |
+
$order_by_class = 'desc';
|
99 |
+
$filter_options .= '<input type="hidden" name="order" value="desc" />';
|
100 |
+
} else {
|
101 |
+
$sorting_by = 'ORDER By p.post_title';
|
102 |
+
$order_by = 'desc';
|
103 |
+
$order_by_class = 'asc';
|
104 |
+
$filter_options .= '<input type="hidden" name="order" value="asc" />';
|
105 |
+
}
|
106 |
+
}
|
107 |
+
$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 . "";
|
108 |
+
$count_posts = $wpdb->get_row( $count_query );
|
109 |
+
|
110 |
+
$html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="get">';
|
111 |
+
$html .= '<p class="search-box">';
|
112 |
+
$html .= '<input type="hidden" name="page" value="cp-post-permalinks" />';
|
113 |
+
$html .= $filter_options;
|
114 |
+
$html .= '<label class="screen-reader-text" for="custom-permalink-search-input">Search Custom Permalink:</label>';
|
115 |
+
$html .= '<input type="search" id="custom-permalink-search-input" name="s" value="' . $search_value . '">';
|
116 |
+
$html .= '<input type="submit" id="search-submit" class="button" value="Search Permalink"></p>';
|
117 |
+
$html .= '</form>';
|
118 |
+
$html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="post">';
|
119 |
+
$html .= '<div class="tablenav top">';
|
120 |
+
$html .= '<div class="alignleft actions bulkactions">
|
121 |
+
<label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label>
|
122 |
+
<select name="action" id="bulk-action-selector-top">
|
123 |
+
<option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
|
124 |
+
<option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
|
125 |
+
</select>
|
126 |
+
<input type="submit" id="doaction" class="button action" value="Apply">
|
127 |
+
</div>';
|
128 |
+
|
129 |
+
$posts = 0;
|
130 |
+
if ( isset( $count_posts->total_permalinks )
|
131 |
+
&& $count_posts->total_permalinks > 0 ) {
|
132 |
+
|
133 |
+
$html .= '<h2 class="screen-reader-text">Custom Permalink navigation</h2>';
|
134 |
+
|
135 |
+
$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 . "";
|
136 |
+
$posts = $wpdb->get_results( $query );
|
137 |
+
|
138 |
+
$pagination_html = '';
|
139 |
+
$total_pages = ceil( $count_posts->total_permalinks / 20 );
|
140 |
+
if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] )
|
141 |
+
&& $_GET['paged'] > 0 ) {
|
142 |
+
$pagination_html = $this->cp_pager(
|
143 |
+
$count_posts->total_permalinks, $_GET['paged'], $total_pages
|
144 |
+
);
|
145 |
+
if ( $_GET['paged'] > $total_pages ) {
|
146 |
+
$redirect_uri = explode(
|
147 |
+
'&paged=' . $_GET['paged'] . '', $_SERVER['REQUEST_URI']
|
148 |
+
);
|
149 |
+
header( 'Location: ' . $redirect_uri[0], 301 );
|
150 |
+
exit();
|
151 |
+
}
|
152 |
+
} elseif ( ! isset( $_GET['paged'] ) ) {
|
153 |
+
$pagination_html = $this->cp_pager(
|
154 |
+
$count_posts->total_permalinks, 1, $total_pages
|
155 |
+
);
|
156 |
+
}
|
157 |
+
|
158 |
+
$html .= $pagination_html;
|
159 |
+
}
|
160 |
+
$table_navigation = $this->tablenav_posts(
|
161 |
+
$order_by_class, $order_by, $search_permalink
|
162 |
+
);
|
163 |
+
|
164 |
+
$html .= '</div>';
|
165 |
+
$html .= '<table class="wp-list-table widefat fixed striped posts">
|
166 |
+
<thead>' . $table_navigation . '</thead>
|
167 |
+
<tbody>';
|
168 |
+
if ( $posts != 0 && ! empty( $posts ) ) {
|
169 |
+
foreach ( $posts as $post ) {
|
170 |
+
$html .= '<tr valign="top">';
|
171 |
+
$html .= '<th scope="row" class="check-column">
|
172 |
+
<input type="checkbox" name="permalink[]" value="' . $post->ID . '" />
|
173 |
+
</th>';
|
174 |
+
$html .= '<td><strong>
|
175 |
+
<a class="row-title" href="post.php?action=edit&post=' . $post->ID . '">' . $post->post_title . '</a>
|
176 |
+
</strong></td>';
|
177 |
+
$html .= '<td>' . ucwords( $post->post_type ) . '</td>';
|
178 |
+
$html .= '<td>
|
179 |
+
<a href="/' . $post->meta_value . '" target="_blank" title="' . __( "Visit " . $post->post_title, "custom-permalinks" ) . '">/' . urldecode( $post->meta_value ) . '</a>
|
180 |
+
</td>';
|
181 |
+
$html .= '</tr>';
|
182 |
+
}
|
183 |
+
} else {
|
184 |
+
$html .= '<tr class="no-items">
|
185 |
+
<td class="colspanchange" colspan="10">No permalinks found.</td>
|
186 |
+
</tr>';
|
187 |
+
}
|
188 |
+
$html .= '</tbody>
|
189 |
+
<tfoot>' . $table_navigation . '</tfoot>
|
190 |
+
</table>';
|
191 |
+
|
192 |
+
$html .= '<div class="tablenav bottom">
|
193 |
+
<div class="alignleft actions bulkactions">
|
194 |
+
<label for="bulk-action-selector-bottom" class="screen-reader-text">Select bulk action</label>
|
195 |
+
<select name="action2" id="bulk-action-selector-bottom">
|
196 |
+
<option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
|
197 |
+
<option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
|
198 |
+
</select>
|
199 |
+
<input type="submit" id="doaction2" class="button action" value="Apply">
|
200 |
+
</div>
|
201 |
+
' . $pagination_html . '
|
202 |
+
</div>';
|
203 |
+
$html .= '</form></div>';
|
204 |
+
echo $html;
|
205 |
+
|
206 |
+
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
|
207 |
+
}
|
208 |
+
|
209 |
+
/**
|
210 |
+
* Return the Navigation row HTML same as Default Posts page for PostTypes
|
211 |
+
*
|
212 |
+
* @access private
|
213 |
+
* @since 1.2
|
214 |
+
* @return string
|
215 |
+
*/
|
216 |
+
private function tablenav_posts( $order_by_class, $order_by, $search_permalink ) {
|
217 |
+
$nav = '<tr>
|
218 |
+
<td id="cb" class="manage-column column-cb check-column">
|
219 |
+
<label class="screen-reader-text" for="cb-select-all-1">Select All</label>
|
220 |
+
<input id="cb-select-all-1" type="checkbox">
|
221 |
+
</td>
|
222 |
+
<th scope="col" id="title" class="manage-column column-title column-primary sortable ' . $order_by_class . '">
|
223 |
+
<a href="/wp-admin/admin.php?page=cp-post-permalinks&orderby=title&order=' . $order_by . $search_permalink . '"><span>' . __( "Title", "custom-permalinks" ) . '</span><span class="sorting-indicator"></span></a>
|
224 |
+
</th>
|
225 |
+
<th scope="col">' . __( "Type", "custom-permalinks" ) . '</th>
|
226 |
+
<th scope="col">' . __( "Permalink", "custom-permalinks" ) . '</th>
|
227 |
+
</tr>';
|
228 |
+
return $nav;
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Shows all the Permalinks created by using this Plugin with Pager and
|
233 |
+
* Search Functionality of Category/Tags
|
234 |
+
*
|
235 |
+
* @access public
|
236 |
+
* @since 1.2
|
237 |
+
* @return void
|
238 |
+
*/
|
239 |
+
public function category_permalinks() {
|
240 |
+
|
241 |
+
$search_permalink = '';
|
242 |
+
$html = '';
|
243 |
+
|
244 |
+
// Handle Bulk Operations
|
245 |
+
if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'delete' )
|
246 |
+
|| ( isset( $_POST['action2'] ) && $_POST['action2'] == 'delete' )
|
247 |
+
&& isset( $_POST['permalink'] ) && ! empty( $_POST['permalink'] ) ) {
|
248 |
+
$remove_perm = $_POST['permalink'];
|
249 |
+
$data = get_option( 'custom_permalink_table' );
|
250 |
+
if ( isset( $data ) && is_array( $data ) ) {
|
251 |
+
$i = 0;
|
252 |
+
foreach ( $data as $link => $info ) {
|
253 |
+
if ( in_array( $info['id'], $remove_perm ) ) {
|
254 |
+
unset( $data[$link] );
|
255 |
+
unset( $remove_perm[$i] );
|
256 |
+
if ( ! is_array( $remove_perm ) || empty( $remove_perm ) )
|
257 |
+
break;
|
258 |
+
}
|
259 |
+
$i++;
|
260 |
+
}
|
261 |
+
}
|
262 |
+
update_option( 'custom_permalink_table', $data );
|
263 |
+
}
|
264 |
+
$html .= '<div class="wrap">
|
265 |
+
<h1 class="wp-heading-inline">' . __( 'Category/Tags Permalinks', 'custom-permalinks' ) . '</h1>';
|
266 |
+
|
267 |
+
$search_value = '';
|
268 |
+
if ( isset( $_GET['s'] ) && ! empty( $_GET['s'] ) ) {
|
269 |
+
$search_permalink = '&s=' . $_GET['s'] . '';
|
270 |
+
$search_value = ltrim( htmlspecialchars( $_GET['s'] ), '/' );
|
271 |
+
$html .= '<span class="subtitle">Search results for "' . $search_value . '"</span>';
|
272 |
+
}
|
273 |
+
$pager_offset = '0';
|
274 |
+
$page_limit = 20;
|
275 |
+
if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] ) && $_GET['paged'] > 1 ) {
|
276 |
+
$pager_offset = 20 * ( $_GET['paged'] - 1 );
|
277 |
+
$page_limit = $pager_offset + 20;
|
278 |
+
}
|
279 |
+
$html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="get">';
|
280 |
+
$html .= '<p class="search-box">';
|
281 |
+
$html .= '<input type="hidden" name="page" value="cp-category-permalinks" />';
|
282 |
+
$html .= '<label class="screen-reader-text" for="custom-permalink-search-input">Search Custom Permalink:</label>';
|
283 |
+
$html .= '<input type="search" id="custom-permalink-search-input" name="s" value="' . $search_value . '">';
|
284 |
+
$html .= '<input type="submit" id="search-submit" class="button" value="Search Permalink"></p>';
|
285 |
+
$html .= '</form>';
|
286 |
+
$html .= '<form action="' . $_SERVER["REQUEST_URI"] . '" method="post">';
|
287 |
+
$html .= '<div class="tablenav top">';
|
288 |
+
$html .= '<div class="alignleft actions bulkactions">
|
289 |
+
<label for="bulk-action-selector-top" class="screen-reader-text">Select bulk action</label>
|
290 |
+
<select name="action" id="bulk-action-selector-top">
|
291 |
+
<option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
|
292 |
+
<option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
|
293 |
+
</select>
|
294 |
+
<input type="submit" id="doaction" class="button action" value="Apply">
|
295 |
+
</div>';
|
296 |
+
|
297 |
+
$posts = 0;
|
298 |
+
$table = get_option( 'custom_permalink_table' );
|
299 |
+
$count_tags = count( $table );
|
300 |
+
$pagination_html = '';
|
301 |
+
if ( isset( $table ) && is_array( $table ) && $count_tags > 0 ) {
|
302 |
+
|
303 |
+
$filtered = array();
|
304 |
+
if ( $search_value != '' ) {
|
305 |
+
foreach ( $table as $key => $value ) {
|
306 |
+
if ( preg_match( '/' . $search_value . '/', $key) ) {
|
307 |
+
$filtered[$key] = $value;
|
308 |
+
}
|
309 |
+
}
|
310 |
+
$table = $filtered;
|
311 |
+
$count_tags = count( $table );
|
312 |
+
}
|
313 |
+
|
314 |
+
$html .= '<h2 class="screen-reader-text">Custom Permalink navigation</h2>';
|
315 |
+
|
316 |
+
$total_pages = ceil( $count_tags / 20 );
|
317 |
+
if ( isset( $_GET['paged'] ) && is_numeric( $_GET['paged'] )
|
318 |
+
&& $_GET['paged'] > 0 ) {
|
319 |
+
$pagination_html = $this->cp_pager(
|
320 |
+
$count_tags, $_GET['paged'], $total_pages
|
321 |
+
);
|
322 |
+
if ( $_GET['paged'] > $total_pages ) {
|
323 |
+
$redirect_uri = explode(
|
324 |
+
'&paged=' . $_GET['paged'] . '', $_SERVER['REQUEST_URI']
|
325 |
+
);
|
326 |
+
header( 'Location: ' . $redirect_uri[0], 301 );
|
327 |
+
exit();
|
328 |
+
}
|
329 |
+
} elseif ( ! isset( $_GET['paged'] ) ) {
|
330 |
+
$pagination_html = $this->cp_pager( $count_tags, 1, $total_pages );
|
331 |
+
}
|
332 |
+
|
333 |
+
$html .= $pagination_html;
|
334 |
+
}
|
335 |
+
$table_navigation = $this->tablenav_category( $search_permalink );
|
336 |
+
|
337 |
+
$html .= '</div>';
|
338 |
+
$html .= '<table class="wp-list-table widefat fixed striped posts">
|
339 |
+
<thead>' . $table_navigation . '</thead>
|
340 |
+
<tbody>';
|
341 |
+
|
342 |
+
if ( $table && is_array( $table ) && $count_tags > 0 ) {
|
343 |
+
uasort( $table, array( 'Custom_Permalinks_Admin', 'sort_array' ) );
|
344 |
+
$i = -1;
|
345 |
+
foreach ( $table as $permalink => $info ) {
|
346 |
+
$i++;
|
347 |
+
if ( $i < $pager_offset )
|
348 |
+
continue;
|
349 |
+
|
350 |
+
if ( $i >= $page_limit )
|
351 |
+
break;
|
352 |
+
|
353 |
+
$type = $info['kind'] == 'tag' ? 'post_tag' : 'category';
|
354 |
+
$term = get_term( $info['id'], $type );
|
355 |
+
$html .= '<tr valign="top">';
|
356 |
+
$html .= '<th scope="row" class="check-column">
|
357 |
+
<input type="checkbox" name="permalink[]" value="' . $info['id'] . '" />
|
358 |
+
</th>';
|
359 |
+
$html .= '<td><strong>
|
360 |
+
<a class="row-title" href="edit-tags.php?action=edit&taxonomy=' . $type . '&tag_ID=' . $info['id'] . ' ">' . $term->name . '</a>
|
361 |
+
</strong></td>';
|
362 |
+
$html .= '<td>' . ucwords( $info['kind'] ) . '</td>';
|
363 |
+
$html .= '<td>
|
364 |
+
<a href="/' . $permalink . '" target="_blank" title="' . __( "Visit " . $term->name, "custom-permalinks" ) . '">/' . $permalink . '</a>
|
365 |
+
</td>';
|
366 |
+
$html .= '</tr>';
|
367 |
+
}
|
368 |
+
} else {
|
369 |
+
$html .= '<tr class="no-items">
|
370 |
+
<td class="colspanchange" colspan="10">No permalinks found.</td>
|
371 |
+
</tr>';
|
372 |
+
}
|
373 |
+
$html .= '</tbody>
|
374 |
+
<tfoot>' . $table_navigation . '</tfoot>
|
375 |
+
</table>';
|
376 |
+
|
377 |
+
$html .= '<div class="tablenav bottom">
|
378 |
+
<div class="alignleft actions bulkactions">
|
379 |
+
<label for="bulk-action-selector-bottom" class="screen-reader-text">Select bulk action</label>
|
380 |
+
<select name="action2" id="bulk-action-selector-bottom">
|
381 |
+
<option value="-1">' . __( "Bulk Actions", "custom-permalinks" ) . '</option>
|
382 |
+
<option value="delete">' . __( "Delete Permalinks", "custom-permalinks" ) . '</option>
|
383 |
+
</select>
|
384 |
+
<input type="submit" id="doaction2" class="button action" value="Apply">
|
385 |
+
</div>
|
386 |
+
' . $pagination_html . '
|
387 |
+
</div>';
|
388 |
+
$html .= '</form></div>';
|
389 |
+
echo $html;
|
390 |
+
|
391 |
+
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
|
392 |
+
}
|
393 |
+
|
394 |
+
/**
|
395 |
+
* Sort the terms array in desc order using term id
|
396 |
+
*
|
397 |
+
* @access private
|
398 |
+
* @since 1.2
|
399 |
+
* @return integer
|
400 |
+
*/
|
401 |
+
private function sort_array( $a, $b ) {
|
402 |
+
return $b['id'] - $a['id'];
|
403 |
+
}
|
404 |
+
|
405 |
+
/**
|
406 |
+
* Return the Navigation row HTML same as Default Posts page for Category
|
407 |
+
*
|
408 |
+
* @access private
|
409 |
+
* @since 1.2
|
410 |
+
* @return string
|
411 |
+
*/
|
412 |
+
private function tablenav_category( $search_permalink ) {
|
413 |
+
$nav = '<tr>
|
414 |
+
<td id="cb" class="manage-column column-cb check-column">
|
415 |
+
<label class="screen-reader-text" for="cb-select-all-1">Select All</label>
|
416 |
+
<input id="cb-select-all-1" type="checkbox">
|
417 |
+
</td>
|
418 |
+
<th scope="col" id="title" class="manage-column column-title column-primary">' . __( "Title", "custom-permalinks" ) . '</th>
|
419 |
+
<th scope="col">' . __( "Type", "custom-permalinks" ) . '</th>
|
420 |
+
<th scope="col">' . __( "Permalink", "custom-permalinks" ) . '</th>
|
421 |
+
</tr>';
|
422 |
+
return $nav;
|
423 |
+
}
|
424 |
+
|
425 |
+
/**
|
426 |
+
* Return the Pager HTML
|
427 |
+
*
|
428 |
+
* @access private
|
429 |
+
* @since 1.2
|
430 |
+
* @return string
|
431 |
+
*/
|
432 |
+
private function cp_pager( $total_permalinks, $current_pager_value = 1, $total_pager = 0 ) {
|
433 |
+
|
434 |
+
if ( $total_pager == 0 ) return;
|
435 |
+
|
436 |
+
if ( $total_pager == 1 ) {
|
437 |
+
$pagination_html = '<div class="tablenav-pages one-page">
|
438 |
+
<span class="displaying-num">' . $total_permalinks . ' items</span>
|
439 |
+
</div>';
|
440 |
+
return $pagination_html;
|
441 |
+
}
|
442 |
+
|
443 |
+
$remove_pager_uri = explode(
|
444 |
+
'&paged=' . $current_pager_value . '', $_SERVER['REQUEST_URI']
|
445 |
+
);
|
446 |
+
$pagination_html = '<div class="tablenav-pages">
|
447 |
+
<span class="displaying-num">' . $total_permalinks . ' items</span>
|
448 |
+
<span class="pagination-links">';
|
449 |
+
|
450 |
+
if ( $current_pager_value == 1 ) {
|
451 |
+
$pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">« </span>
|
452 |
+
<span class="tablenav-pages-navspan" aria-hidden="true">‹ </span>';
|
453 |
+
} else {
|
454 |
+
$prev_page = $current_pager_value - 1;
|
455 |
+
if ( $prev_page == 1 ) {
|
456 |
+
$pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">«</span>';
|
457 |
+
} else {
|
458 |
+
$pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=1" title="First page" class="first-page">
|
459 |
+
<span class="screen-reader-text">First page</span>
|
460 |
+
<span aria-hidden="true">«</span>
|
461 |
+
</a> ';
|
462 |
+
}
|
463 |
+
$pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=' . $prev_page . '" title="Previous page" class="prev-page">
|
464 |
+
<span class="screen-reader-text">Previous page</span>
|
465 |
+
<span aria-hidden="true">‹</span>
|
466 |
+
</a> ';
|
467 |
+
}
|
468 |
+
|
469 |
+
$pagination_html .= '<span class="paging-input">
|
470 |
+
<label for="current-page-selector" class="screen-reader-text">Current Page</label>
|
471 |
+
<input class="current-page" id="current-page-selector" type="text" name="paged" value="' . $current_pager_value . '" size="1" aria-describedby="table-paging" />
|
472 |
+
<span class="tablenav-paging-text"> of <span class="total-pages">' . $total_pager . ' </span> </span>
|
473 |
+
</span>';
|
474 |
+
|
475 |
+
if ( $current_pager_value == $total_pager ) {
|
476 |
+
$pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">› </span>
|
477 |
+
<span class="tablenav-pages-navspan" aria-hidden="true">» </span>';
|
478 |
+
} else {
|
479 |
+
$next_page = $current_pager_value + 1;
|
480 |
+
$pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=' . $next_page . '" title="Next page" class="next-page">
|
481 |
+
<span class="screen-reader-text">Next page</span>
|
482 |
+
<span aria-hidden="true">›</span>
|
483 |
+
</a> ';
|
484 |
+
if ( $total_pager == $next_page) {
|
485 |
+
$pagination_html .= '<span class="tablenav-pages-navspan" aria-hidden="true">»</span>';
|
486 |
+
} else {
|
487 |
+
$pagination_html .= ' <a href="' . $remove_pager_uri[0] . '&paged=' . $total_pager . '" title="Last page" class="last-page">
|
488 |
+
<span class="screen-reader-text">Last page</span>
|
489 |
+
<span aria-hidden="true">»</span>
|
490 |
+
</a> ';
|
491 |
+
}
|
492 |
+
}
|
493 |
+
$pagination_html .= '</span></div>';
|
494 |
+
|
495 |
+
return $pagination_html;
|
496 |
+
}
|
497 |
+
|
498 |
+
/**
|
499 |
+
* Add About Plugins Page
|
500 |
+
*
|
501 |
+
* @access public
|
502 |
+
* @since 1.2.11
|
503 |
+
* @return void
|
504 |
+
*/
|
505 |
+
public function about_plugin() {
|
506 |
+
require_once(
|
507 |
+
CUSTOM_PERMALINKS_PATH . 'admin/class-custom-permalinks-about.php'
|
508 |
+
);
|
509 |
+
new Custom_Permalinks_About();
|
510 |
+
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1 );
|
511 |
+
}
|
512 |
+
|
513 |
+
/**
|
514 |
+
* Add Plugin Support and Follow Message in the footer of Admin Pages
|
515 |
+
*
|
516 |
+
* @access public
|
517 |
+
* @since 1.2.11
|
518 |
+
* @return string
|
519 |
+
*/
|
520 |
+
public function admin_footer_text() {
|
521 |
+
$footer_text = sprintf(
|
522 |
+
__( 'Custom Permalinks version %s by <a href="%s" title="Sami Ahmed Siddiqui Company Website" target="_blank">Sami Ahmed Siddiqui</a> - <a href="%s" title="Support forums" target="_blank">Support forums</a> - Follow on Twitter: <a href="%s" title="Follow Sami Ahmed Siddiqui on Twitter" target="_blank">Sami Ahmed Siddiqui</a>', 'custom-permalinks' ),
|
523 |
+
CUSTOM_PERMALINKS_PLUGIN_VERSION, 'https://www.yasglobal.com/',
|
524 |
+
'https://wordpress.org/support/plugin/custom-permalinks',
|
525 |
+
'https://twitter.com/samisiddiqui91'
|
526 |
+
);
|
527 |
+
return $footer_text;
|
528 |
+
}
|
529 |
+
|
530 |
+
/**
|
531 |
+
* Add About and Premium Settings Page Link on the Plugin Page
|
532 |
+
* under the Plugin Name.
|
533 |
+
*
|
534 |
+
* @access public
|
535 |
+
* @since 1.2.11
|
536 |
+
* @return array
|
537 |
+
*/
|
538 |
+
public function settings_link( $links ) {
|
539 |
+
$about = sprintf(
|
540 |
+
__( '<a href="%s" title="About">About</a>', 'custom-permalinks' ),
|
541 |
+
'admin.php?page=cp-about-plugins'
|
542 |
+
);
|
543 |
+
$premium_support = sprintf(
|
544 |
+
__( '<a href="%s" title="Premium Support" target="_blank">Premium Support</a>', 'custom-permalinks' ),
|
545 |
+
'https://www.custompermalinks.com/#pricing-section'
|
546 |
+
);
|
547 |
+
$contact = sprintf(
|
548 |
+
__( '<a href="%s" title="Contact" target="_blank">Contact</a>', 'custom-permalinks' ),
|
549 |
+
'https://www.custompermalinks.com/contact-us/'
|
550 |
+
);
|
551 |
+
array_unshift( $links, $contact );
|
552 |
+
array_unshift( $links, $premium_support );
|
553 |
+
array_unshift( $links, $about );
|
554 |
+
|
555 |
+
return $links;
|
556 |
+
}
|
557 |
}
|
changelog.txt
CHANGED
@@ -2,27 +2,27 @@
|
|
2 |
|
3 |
This file contains only old changelog. See readme.txt for newer versions.
|
4 |
|
5 |
-
= 1.2.5 =
|
6 |
|
7 |
* Fixed Category/Tag Update Issue + Typo on Admin Page
|
8 |
|
9 |
-
= 1.2.4 =
|
10 |
|
11 |
* Fixed Slug issue with Yoast SEO
|
12 |
|
13 |
-
= 1.2.3 =
|
14 |
|
15 |
* Fixed PHP Notice on Edit Post Page
|
16 |
|
17 |
-
= 1.2.2 =
|
18 |
|
19 |
* Fixed Typo of Class Object for term on Admin Page
|
20 |
|
21 |
-
= 1.2.1 =
|
22 |
|
23 |
* Fixed Class Typo
|
24 |
|
25 |
-
= 1.2 =
|
26 |
|
27 |
* Enhancements
|
28 |
* Added Filter to Exclude/Ignore URL to be processed
|
@@ -32,7 +32,7 @@ This file contains only old changelog. See readme.txt for newer versions.
|
|
32 |
* Bugs
|
33 |
* Fixed Vulnerability Issues
|
34 |
|
35 |
-
= 1.1 =
|
36 |
|
37 |
* Enhancements
|
38 |
* Added PostTypes Permalinks Page
|
@@ -49,51 +49,51 @@ This file contains only old changelog. See readme.txt for newer versions.
|
|
49 |
* 404 Issues
|
50 |
* Child pages bug
|
51 |
|
52 |
-
= 1.0.2 =
|
53 |
|
54 |
* Fixed Notice and some URL Issues
|
55 |
|
56 |
-
= 1.0.1 =
|
57 |
|
58 |
* Fixed issue with AMP Pages
|
59 |
|
60 |
-
= 1.0 =
|
61 |
|
62 |
* Updated Query on the `custom_permalinks_request` Function
|
63 |
|
64 |
-
= 0.9.3 =
|
65 |
|
66 |
* Fixed PolyLang Conflicts
|
67 |
|
68 |
-
= 0.9.2 =
|
69 |
|
70 |
* Fixed WPML Conflicts
|
71 |
|
72 |
-
= 0.9.1 =
|
73 |
|
74 |
* Fixed issues of Filters and Actions (Replaces 'edit_files' with 10)
|
75 |
|
76 |
-
= 0.9 =
|
77 |
|
78 |
* Resolved the conflict with PolyLang Plugin
|
79 |
|
80 |
-
= 0.8 =
|
81 |
|
82 |
* Fixed (Draft preview issue for custom post types + some PHP Warnings)
|
83 |
|
84 |
-
= 0.7.28 =
|
85 |
|
86 |
* Fixed draft preview issue(posts + pages)
|
87 |
|
88 |
-
= 0.7.27 =
|
89 |
|
90 |
* Fixed Loop Redirecting issue
|
91 |
|
92 |
-
= 0.7.26 =
|
93 |
|
94 |
* Fixed PHP Notice issue
|
95 |
|
96 |
-
= 0.7.25 =
|
97 |
|
98 |
* Fixed draft preview issue
|
99 |
|
2 |
|
3 |
This file contains only old changelog. See readme.txt for newer versions.
|
4 |
|
5 |
+
= 1.2.5 - Oct 17, 2017 =
|
6 |
|
7 |
* Fixed Category/Tag Update Issue + Typo on Admin Page
|
8 |
|
9 |
+
= 1.2.4 - Oct 07, 2017 =
|
10 |
|
11 |
* Fixed Slug issue with Yoast SEO
|
12 |
|
13 |
+
= 1.2.3 - Sept 27, 2017 =
|
14 |
|
15 |
* Fixed PHP Notice on Edit Post Page
|
16 |
|
17 |
+
= 1.2.2 - Sept 26, 2017 =
|
18 |
|
19 |
* Fixed Typo of Class Object for term on Admin Page
|
20 |
|
21 |
+
= 1.2.1 - Sept 25, 2017 =
|
22 |
|
23 |
* Fixed Class Typo
|
24 |
|
25 |
+
= 1.2 - Sept 25, 2017 =
|
26 |
|
27 |
* Enhancements
|
28 |
* Added Filter to Exclude/Ignore URL to be processed
|
32 |
* Bugs
|
33 |
* Fixed Vulnerability Issues
|
34 |
|
35 |
+
= 1.1 - Sept 25, 2017 =
|
36 |
|
37 |
* Enhancements
|
38 |
* Added PostTypes Permalinks Page
|
49 |
* 404 Issues
|
50 |
* Child pages bug
|
51 |
|
52 |
+
= 1.0.2 - Aug 15, 2017 =
|
53 |
|
54 |
* Fixed Notice and some URL Issues
|
55 |
|
56 |
+
= 1.0.1 - Aug 12, 2017 =
|
57 |
|
58 |
* Fixed issue with AMP Pages
|
59 |
|
60 |
+
= 1.0 - Aug 11, 2017 =
|
61 |
|
62 |
* Updated Query on the `custom_permalinks_request` Function
|
63 |
|
64 |
+
= 0.9.3 - July 21, 2017 =
|
65 |
|
66 |
* Fixed PolyLang Conflicts
|
67 |
|
68 |
+
= 0.9.2 - July 16, 2017 =
|
69 |
|
70 |
* Fixed WPML Conflicts
|
71 |
|
72 |
+
= 0.9.1 - July 16, 2017 =
|
73 |
|
74 |
* Fixed issues of Filters and Actions (Replaces 'edit_files' with 10)
|
75 |
|
76 |
+
= 0.9 - July 16, 2017 =
|
77 |
|
78 |
* Resolved the conflict with PolyLang Plugin
|
79 |
|
80 |
+
= 0.8 - Aug 19, 2016 =
|
81 |
|
82 |
* Fixed (Draft preview issue for custom post types + some PHP Warnings)
|
83 |
|
84 |
+
= 0.7.28 - July 28, 2016 =
|
85 |
|
86 |
* Fixed draft preview issue(posts + pages)
|
87 |
|
88 |
+
= 0.7.27 - July 21, 2016 =
|
89 |
|
90 |
* Fixed Loop Redirecting issue
|
91 |
|
92 |
+
= 0.7.26 - July 20, 2016 =
|
93 |
|
94 |
* Fixed PHP Notice issue
|
95 |
|
96 |
+
= 0.7.25 - June 06, 2016 =
|
97 |
|
98 |
* Fixed draft preview issue
|
99 |
|
custom-permalinks-main.php
DELETED
@@ -1,49 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* @package CustomPermalinks\Main
|
4 |
-
*/
|
5 |
-
|
6 |
-
// Make sure we don't expose any info if called directly
|
7 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
8 |
-
echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
|
9 |
-
exit;
|
10 |
-
}
|
11 |
-
|
12 |
-
if ( ! function_exists( 'add_action' ) || ! function_exists( 'add_filter' ) ) {
|
13 |
-
header( 'Status: 403 Forbidden' );
|
14 |
-
header( 'HTTP/1.1 403 Forbidden' );
|
15 |
-
exit();
|
16 |
-
}
|
17 |
-
|
18 |
-
define( 'CUSTOM_PERMALINKS_PLUGIN_VERSION', '1.2.17' );
|
19 |
-
|
20 |
-
if ( ! defined( 'CUSTOM_PERMALINKS_PATH' ) ) {
|
21 |
-
define( 'CUSTOM_PERMALINKS_PATH', plugin_dir_path( CUSTOM_PERMALINKS_FILE ) );
|
22 |
-
}
|
23 |
-
|
24 |
-
if ( ! defined( 'CUSTOM_PERMALINKS_BASENAME' ) ) {
|
25 |
-
define( 'CUSTOM_PERMALINKS_BASENAME', plugin_basename( CUSTOM_PERMALINKS_FILE ) );
|
26 |
-
}
|
27 |
-
|
28 |
-
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php' );
|
29 |
-
$custom_permalinks_frontend = new Custom_Permalinks_Frontend();
|
30 |
-
$custom_permalinks_frontend->init();
|
31 |
-
|
32 |
-
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-form.php' );
|
33 |
-
$custom_permalinks_form = new Custom_Permalinks_Form();
|
34 |
-
$custom_permalinks_form->init();
|
35 |
-
|
36 |
-
if ( is_admin() ) {
|
37 |
-
require_once( CUSTOM_PERMALINKS_PATH . 'admin/class-custom-permalinks-admin.php' );
|
38 |
-
new Custom_Permalinks_Admin();
|
39 |
-
}
|
40 |
-
|
41 |
-
/**
|
42 |
-
* Add textdomain hook for translation
|
43 |
-
*/
|
44 |
-
function custom_permalinks_translation_capability() {
|
45 |
-
load_plugin_textdomain( 'custom-permalinks', FALSE,
|
46 |
-
basename( dirname( CUSTOM_PERMALINKS_FILE ) ) . '/languages/'
|
47 |
-
);
|
48 |
-
}
|
49 |
-
add_action( 'plugins_loaded', 'custom_permalinks_translation_capability' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
custom-permalinks.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Custom Permalinks
|
4 |
* Plugin URI: https://wordpress.org/plugins/custom-permalinks/
|
5 |
* Description: Set custom permalinks on a per-post basis
|
6 |
-
* Version: 1.2.
|
7 |
* Author: Sami Ahmed Siddiqui
|
8 |
* Author URI: https://www.custompermalinks.com/
|
9 |
* Donate link: https://www.paypal.me/yasglobal
|
@@ -35,12 +35,87 @@
|
|
35 |
|
36 |
// Make sure we don't expose any info if called directly
|
37 |
if ( ! defined( 'ABSPATH' ) ) {
|
38 |
-
|
39 |
-
|
40 |
}
|
41 |
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
}
|
45 |
|
46 |
-
|
3 |
* Plugin Name: Custom Permalinks
|
4 |
* Plugin URI: https://wordpress.org/plugins/custom-permalinks/
|
5 |
* Description: Set custom permalinks on a per-post basis
|
6 |
+
* Version: 1.2.18
|
7 |
* Author: Sami Ahmed Siddiqui
|
8 |
* Author URI: https://www.custompermalinks.com/
|
9 |
* Donate link: https://www.paypal.me/yasglobal
|
35 |
|
36 |
// Make sure we don't expose any info if called directly
|
37 |
if ( ! defined( 'ABSPATH' ) ) {
|
38 |
+
echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
|
39 |
+
exit;
|
40 |
}
|
41 |
|
42 |
+
final class Custom_Permalinks {
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Class constructor.
|
46 |
+
*/
|
47 |
+
public function __construct() {
|
48 |
+
$this->setup_constants();
|
49 |
+
$this->includes();
|
50 |
+
|
51 |
+
add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Setup plugin constants
|
56 |
+
*
|
57 |
+
* @access private
|
58 |
+
* @since 1.2.18
|
59 |
+
* @return void
|
60 |
+
*/
|
61 |
+
private function setup_constants() {
|
62 |
+
if ( ! defined( 'CUSTOM_PERMALINKS_FILE' ) ) {
|
63 |
+
define( 'CUSTOM_PERMALINKS_FILE', __FILE__ );
|
64 |
+
}
|
65 |
+
|
66 |
+
if ( ! defined( 'CUSTOM_PERMALINKS_PLUGIN_VERSION' ) ) {
|
67 |
+
define( 'CUSTOM_PERMALINKS_PLUGIN_VERSION', '1.2.18' );
|
68 |
+
}
|
69 |
+
|
70 |
+
if ( ! defined( 'CUSTOM_PERMALINKS_PATH' ) ) {
|
71 |
+
define( 'CUSTOM_PERMALINKS_PATH', plugin_dir_path( CUSTOM_PERMALINKS_FILE ) );
|
72 |
+
}
|
73 |
+
|
74 |
+
if ( ! defined( 'CUSTOM_PERMALINKS_BASENAME' ) ) {
|
75 |
+
define( 'CUSTOM_PERMALINKS_BASENAME', plugin_basename( CUSTOM_PERMALINKS_FILE ) );
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Include required files
|
81 |
+
*
|
82 |
+
* @access private
|
83 |
+
* @since 1.2.18
|
84 |
+
* @return void
|
85 |
+
*/
|
86 |
+
private function includes() {
|
87 |
+
require_once(
|
88 |
+
CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-frontend.php'
|
89 |
+
);
|
90 |
+
$cp_frontend = new Custom_Permalinks_Frontend();
|
91 |
+
$cp_frontend->init();
|
92 |
+
|
93 |
+
require_once(
|
94 |
+
CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-form.php'
|
95 |
+
);
|
96 |
+
$cp_form = new Custom_Permalinks_Form();
|
97 |
+
$cp_form->init();
|
98 |
+
|
99 |
+
if ( is_admin() ) {
|
100 |
+
require_once(
|
101 |
+
CUSTOM_PERMALINKS_PATH . 'admin/class-custom-permalinks-admin.php'
|
102 |
+
);
|
103 |
+
new Custom_Permalinks_Admin();
|
104 |
+
}
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Loads the plugin language files
|
109 |
+
*
|
110 |
+
* @access public
|
111 |
+
* @since 1.2.18
|
112 |
+
* @return void
|
113 |
+
*/
|
114 |
+
public function load_textdomain() {
|
115 |
+
load_plugin_textdomain( 'custom-permalinks', FALSE,
|
116 |
+
basename( dirname( CUSTOM_PERMALINKS_FILE ) ) . '/languages/'
|
117 |
+
);
|
118 |
+
}
|
119 |
}
|
120 |
|
121 |
+
new Custom_Permalinks();
|
frontend/class-custom-permalinks-form.php
CHANGED
@@ -3,382 +3,402 @@
|
|
3 |
* @package CustomPermalinks\Frontend\Form
|
4 |
*/
|
5 |
|
6 |
-
class Custom_Permalinks_Form {
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
384 |
}
|
3 |
* @package CustomPermalinks\Frontend\Form
|
4 |
*/
|
5 |
|
6 |
+
final class Custom_Permalinks_Form {
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Initialize WordPress Hooks
|
10 |
+
*
|
11 |
+
* @access public
|
12 |
+
* @since 1.2
|
13 |
+
* @return void
|
14 |
+
*/
|
15 |
+
public function init() {
|
16 |
+
|
17 |
+
add_filter( 'get_sample_permalink_html',
|
18 |
+
array( $this, 'custom_permalinks_get_sample_permalink_html' ), 10, 4
|
19 |
+
);
|
20 |
+
|
21 |
+
add_action( 'save_post',
|
22 |
+
array( $this, 'custom_permalinks_save_post' ), 10, 3
|
23 |
+
);
|
24 |
+
add_action( 'delete_post',
|
25 |
+
array( $this, 'custom_permalinks_delete_permalink' ), 10
|
26 |
+
);
|
27 |
+
|
28 |
+
add_action( 'edit_tag_form',
|
29 |
+
array( $this, 'custom_permalinks_term_options' )
|
30 |
+
);
|
31 |
+
add_action( 'add_tag_form',
|
32 |
+
array( $this, 'custom_permalinks_term_options' )
|
33 |
+
);
|
34 |
+
add_action( 'edit_category_form',
|
35 |
+
array( $this, 'custom_permalinks_term_options' )
|
36 |
+
);
|
37 |
+
|
38 |
+
add_action( 'edited_post_tag',
|
39 |
+
array( $this, 'custom_permalinks_save_tag' )
|
40 |
+
);
|
41 |
+
add_action( 'edited_category',
|
42 |
+
array( $this, 'custom_permalinks_save_category' )
|
43 |
+
);
|
44 |
+
add_action( 'create_post_tag',
|
45 |
+
array( $this, 'custom_permalinks_save_tag' )
|
46 |
+
);
|
47 |
+
add_action( 'create_category',
|
48 |
+
array( $this, 'custom_permalinks_save_category' )
|
49 |
+
);
|
50 |
+
add_action( 'delete_post_tag',
|
51 |
+
array( $this, 'custom_permalinks_delete_term' )
|
52 |
+
);
|
53 |
+
add_action( 'delete_post_category',
|
54 |
+
array( $this, 'custom_permalinks_delete_term' )
|
55 |
+
);
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Save per-post options
|
60 |
+
*
|
61 |
+
* @access public
|
62 |
+
* @return void
|
63 |
+
*/
|
64 |
+
public function custom_permalinks_save_post( $id ) {
|
65 |
+
if ( ! isset( $_REQUEST['custom_permalinks_edit'] ) ) {
|
66 |
+
return;
|
67 |
+
}
|
68 |
+
|
69 |
+
delete_post_meta( $id, 'custom_permalink' );
|
70 |
+
|
71 |
+
$cp_frontend = new Custom_Permalinks_Frontend();
|
72 |
+
$original_link = $cp_frontend->custom_permalinks_original_post_link( $id );
|
73 |
+
$permalink_structure = get_option( 'permalink_structure' );
|
74 |
+
|
75 |
+
if ( $_REQUEST['custom_permalink'] && $_REQUEST['custom_permalink'] != $original_link ) {
|
76 |
+
add_post_meta( $id, 'custom_permalink',
|
77 |
+
str_replace( '%2F', '/',
|
78 |
+
urlencode( ltrim( stripcslashes( $_REQUEST['custom_permalink'] ), "/" ) )
|
79 |
+
)
|
80 |
+
);
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Delete Post Permalink
|
86 |
+
*
|
87 |
+
* @access public
|
88 |
+
* @return void
|
89 |
+
*/
|
90 |
+
public function custom_permalinks_delete_permalink( $id ) {
|
91 |
+
global $wpdb;
|
92 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = 'custom_permalink' AND post_id = %d", $id ) );
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Per-post/page options (Wordpress > 2.9)
|
97 |
+
*
|
98 |
+
* @access public
|
99 |
+
* @return string
|
100 |
+
*/
|
101 |
+
public function custom_permalinks_get_sample_permalink_html( $html, $id, $new_title, $new_slug ) {
|
102 |
+
$permalink = get_post_meta( $id, 'custom_permalink', true );
|
103 |
+
$post = get_post( $id );
|
104 |
+
|
105 |
+
if ( 'attachment' == $post->post_type || $post->ID == get_option( 'page_on_front' ) ) {
|
106 |
+
return $html;
|
107 |
+
}
|
108 |
+
|
109 |
+
$exclude_post_types = $post->post_type;
|
110 |
+
$excluded = apply_filters( 'custom_permalinks_exclude_post_type', $exclude_post_types );
|
111 |
+
if ( '__true' === $excluded ) {
|
112 |
+
return $html;
|
113 |
+
}
|
114 |
+
|
115 |
+
ob_start();
|
116 |
+
|
117 |
+
$cp_frontend = new Custom_Permalinks_Frontend();
|
118 |
+
if ( 'page' == $post->post_type ) {
|
119 |
+
$original_page_url = $cp_frontend->custom_permalinks_original_page_link( $id );
|
120 |
+
$this->custom_permalinks_get_form( $permalink, $original_page_url, false, $post->post_name );
|
121 |
+
} else {
|
122 |
+
$original_post_url = $cp_frontend->custom_permalinks_original_post_link( $id );
|
123 |
+
$this->custom_permalinks_get_form( $permalink, $original_post_url, false, $post->post_name );
|
124 |
+
}
|
125 |
+
|
126 |
+
$content = ob_get_contents();
|
127 |
+
ob_end_clean();
|
128 |
+
|
129 |
+
if ( 'publish' == $post->post_status ) {
|
130 |
+
$view_post = 'page' == $post->post_type ? __( 'View Page', 'custom-permalinks' ) : __( 'View Post', 'custom-permalinks' );
|
131 |
+
}
|
132 |
+
|
133 |
+
if ( preg_match( "@view-post-btn.*?href='([^']+)'@s", $html, $matches ) ) {
|
134 |
+
$permalink = $matches[1];
|
135 |
+
} else {
|
136 |
+
list( $permalink, $post_name ) = get_sample_permalink( $post->ID, $new_title, $new_slug );
|
137 |
+
if ( false !== strpos( $permalink, '%postname%' )
|
138 |
+
|| false !== strpos( $permalink, '%pagename%' ) ) {
|
139 |
+
$permalink = str_replace( array( '%pagename%','%postname%' ), $post_name, $permalink );
|
140 |
+
}
|
141 |
+
}
|
142 |
+
|
143 |
+
return '<strong>' . __( 'Permalink:', 'custom-permalinks' ) . "</strong>\n" . $content .
|
144 |
+
( isset( $view_post ) ? "<span id='view-post-btn'><a href='$permalink' class='button button-small' target='_blank'>$view_post</a></span>\n" : "" );
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* Per-post options (Wordpress < 2.9)
|
149 |
+
*
|
150 |
+
* @access public
|
151 |
+
* @return void
|
152 |
+
*/
|
153 |
+
public function custom_permalinks_post_options() {
|
154 |
+
global $post;
|
155 |
+
$post_id = $post;
|
156 |
+
if ( is_object( $post_id ) ) {
|
157 |
+
$post_id = $post_id->ID;
|
158 |
+
}
|
159 |
+
|
160 |
+
$permalink = get_post_meta( $post_id, 'custom_permalink', true );
|
161 |
+
?>
|
162 |
+
<div class="postbox closed">
|
163 |
+
<h3><?php _e( 'Custom Permalink', 'custom-permalinks' ) ?></h3>
|
164 |
+
<div class="inside">
|
165 |
+
<?php
|
166 |
+
$cp_frontend = new Custom_Permalinks_Frontend();
|
167 |
+
$cp_frontend->custom_permalinks_get_form( $permalink, $cp_frontend->custom_permalinks_original_post_link( $post_id ) );
|
168 |
+
?>
|
169 |
+
</div>
|
170 |
+
</div>
|
171 |
+
<?php
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Per-page options (Wordpress < 2.9)
|
176 |
+
*
|
177 |
+
* @access public
|
178 |
+
* @return void
|
179 |
+
*/
|
180 |
+
public function custom_permalinks_page_options() {
|
181 |
+
global $post;
|
182 |
+
$post_id = $post;
|
183 |
+
if (is_object( $post_id ) ) {
|
184 |
+
$post_id = $post_id->ID;
|
185 |
+
}
|
186 |
+
|
187 |
+
$permalink = get_post_meta( $post_id, 'custom_permalink', true );
|
188 |
+
?>
|
189 |
+
<div class="postbox closed">
|
190 |
+
<h3><?php _e( 'Custom Permalink', 'custom-permalinks' ); ?></h3>
|
191 |
+
<div class="inside">
|
192 |
+
<?php
|
193 |
+
$cp_frontend = new Custom_Permalinks_Frontend();
|
194 |
+
$page_permalink = $cp_frontend->custom_permalinks_original_page_link( $post_id );
|
195 |
+
$this->custom_permalinks_get_form( $permalink, $page_permalink );
|
196 |
+
?>
|
197 |
+
</div>
|
198 |
+
</div>
|
199 |
+
<?php
|
200 |
+
}
|
201 |
+
|
202 |
+
/**
|
203 |
+
* Per-category/tag options
|
204 |
+
*
|
205 |
+
* @access public
|
206 |
+
* @return void
|
207 |
+
*/
|
208 |
+
public function custom_permalinks_term_options( $object ) {
|
209 |
+
if ( is_object( $object ) && isset( $object->term_id ) ) {
|
210 |
+
$cp_frontend = new Custom_Permalinks_Frontend();
|
211 |
+
$permalink = $cp_frontend->custom_permalinks_permalink_for_term( $object->term_id );
|
212 |
+
|
213 |
+
if ( $object->term_id ) {
|
214 |
+
if ( $object->taxonomy == 'post_tag' ) {
|
215 |
+
$originalPermalink = $cp_frontend->custom_permalinks_original_tag_link( $object->term_id );
|
216 |
+
} else {
|
217 |
+
$originalPermalink = $cp_frontend->custom_permalinks_original_category_link( $object->term_id );
|
218 |
+
}
|
219 |
+
}
|
220 |
+
|
221 |
+
$this->custom_permalinks_get_form( $permalink, $originalPermalink );
|
222 |
+
} else {
|
223 |
+
$this->custom_permalinks_get_form( '' );
|
224 |
+
}
|
225 |
+
|
226 |
+
// Move the save button to above this form
|
227 |
+
wp_enqueue_script( 'jquery' );
|
228 |
+
?>
|
229 |
+
<script type="text/javascript">
|
230 |
+
jQuery(document).ready(function() {
|
231 |
+
var button = jQuery('#custom_permalink_form').parent().find('.submit');
|
232 |
+
button.remove().insertAfter(jQuery('#custom_permalink_form'));
|
233 |
+
});
|
234 |
+
</script>
|
235 |
+
<?php
|
236 |
+
}
|
237 |
+
|
238 |
+
/**
|
239 |
+
* Helper function to render form
|
240 |
+
*
|
241 |
+
* @access private
|
242 |
+
* @return void
|
243 |
+
*/
|
244 |
+
private function custom_permalinks_get_form( $permalink, $original = '', $renderContainers = true, $postname = '' ) {
|
245 |
+
?>
|
246 |
+
<input value="true" type="hidden" name="custom_permalinks_edit" />
|
247 |
+
<input value="<?php echo home_url(); ?>" type="hidden" name="custom_permalinks_home_url" id="custom_permalinks_home_url" />
|
248 |
+
<input value="<?php echo htmlspecialchars( urldecode( $permalink ) ); ?>" type="hidden" name="custom_permalink" id="custom_permalink" />
|
249 |
+
|
250 |
+
<?php
|
251 |
+
if ( $renderContainers ) :
|
252 |
+
?>
|
253 |
+
<table class="form-table" id="custom_permalink_form">
|
254 |
+
<tr>
|
255 |
+
<th scope="row"><?php _e( 'Custom Permalink', 'custom-permalinks' ); ?></th>
|
256 |
+
<td>
|
257 |
+
<?php
|
258 |
+
endif;
|
259 |
+
if ( $permalink == '' ) {
|
260 |
+
$original = $this->custom_permalinks_check_conflicts( $original );
|
261 |
+
}
|
262 |
+
$post_slug = htmlspecialchars( $permalink ? urldecode( $permalink ) : urldecode( $original ) );
|
263 |
+
$original_encoded_url = htmlspecialchars( urldecode( $original ) );
|
264 |
+
wp_enqueue_script( 'custom-permalinks-form', plugins_url( '/js/script-form.min.js', __FILE__ ), array(), false, true );
|
265 |
+
$postname_html = '';
|
266 |
+
if ( isset( $postname ) && $postname != '' ) {
|
267 |
+
$postname_html = '<input type="hidden" id="new-post-slug" class="text" value="' . $postname . '" />';
|
268 |
+
}
|
269 |
+
|
270 |
+
echo home_url() . '/<span id="editable-post-name" title="Click to edit this part of the permalink">' . $postname_html;
|
271 |
+
|
272 |
+
?>
|
273 |
+
<input type="text" id="custom-permalinks-post-slug" class="text" value="<?php echo $post_slug; ?>"
|
274 |
+
style="width: 250px; <?php if ( !$permalink ) echo 'color: #ddd'; ?>"
|
275 |
+
onfocus="if ( this.style.color = '#ddd' ) { this.style.color = '#000'; }"
|
276 |
+
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'; }" />
|
277 |
+
</span>
|
278 |
+
|
279 |
+
<?php if ( $renderContainers ) : ?>
|
280 |
+
<br />
|
281 |
+
<small><?php _e( 'Leave blank to disable', 'custom-permalinks' ); ?></small>
|
282 |
+
</td>
|
283 |
+
</tr>
|
284 |
+
</table>
|
285 |
+
<?php
|
286 |
+
endif;
|
287 |
+
}
|
288 |
+
|
289 |
+
/**
|
290 |
+
* Save per-tag options
|
291 |
+
*
|
292 |
+
* @access public
|
293 |
+
* @return void
|
294 |
+
*/
|
295 |
+
public function custom_permalinks_save_tag( $id ) {
|
296 |
+
if ( ! isset( $_REQUEST['custom_permalinks_edit'] )
|
297 |
+
|| isset( $_REQUEST['post_ID'] ) ) {
|
298 |
+
return;
|
299 |
+
}
|
300 |
+
$new_permalink = ltrim( stripcslashes( $_REQUEST['custom_permalink'] ), '/' );
|
301 |
+
|
302 |
+
$cp_frontend = new Custom_Permalinks_Frontend();
|
303 |
+
if ( $new_permalink == $cp_frontend->custom_permalinks_original_tag_link( $id ) ) {
|
304 |
+
return;
|
305 |
+
}
|
306 |
+
|
307 |
+
$term = get_term( $id, 'post_tag' );
|
308 |
+
$this->custom_permalinks_save_term( $term, str_replace( '%2F', '/', urlencode( $new_permalink ) ) );
|
309 |
+
}
|
310 |
+
|
311 |
+
/**
|
312 |
+
* Save per-category options
|
313 |
+
*
|
314 |
+
* @access public
|
315 |
+
* @return void
|
316 |
+
*/
|
317 |
+
public function custom_permalinks_save_category( $id ) {
|
318 |
+
if ( ! isset( $_REQUEST['custom_permalinks_edit'] )
|
319 |
+
|| isset( $_REQUEST['post_ID'] ) ) {
|
320 |
+
return;
|
321 |
+
}
|
322 |
+
$new_permalink = ltrim( stripcslashes( $_REQUEST['custom_permalink'] ), '/' );
|
323 |
+
|
324 |
+
$cp_frontend = new Custom_Permalinks_Frontend();
|
325 |
+
if ( $new_permalink == $cp_frontend->custom_permalinks_original_category_link( $id ) ) {
|
326 |
+
return;
|
327 |
+
}
|
328 |
+
|
329 |
+
$term = get_term( $id, 'category' );
|
330 |
+
$this->custom_permalinks_save_term(
|
331 |
+
$term, str_replace( '%2F', '/', urlencode( $new_permalink ) )
|
332 |
+
);
|
333 |
+
}
|
334 |
+
|
335 |
+
/**
|
336 |
+
* Save term (common to tags and categories)
|
337 |
+
*
|
338 |
+
* @access public
|
339 |
+
* @return void
|
340 |
+
*/
|
341 |
+
public function custom_permalinks_save_term( $term, $permalink ) {
|
342 |
+
|
343 |
+
$this->custom_permalinks_delete_term( $term->term_id );
|
344 |
+
$table = get_option( 'custom_permalink_table' );
|
345 |
+
if ( $permalink ) {
|
346 |
+
$table[$permalink] = array(
|
347 |
+
'id' => $term->term_id,
|
348 |
+
'kind' => ( $term->taxonomy == 'category' ? 'category' : 'tag' ),
|
349 |
+
'slug' => $term->slug
|
350 |
+
);
|
351 |
+
}
|
352 |
+
|
353 |
+
update_option( 'custom_permalink_table', $table );
|
354 |
+
}
|
355 |
+
|
356 |
+
/**
|
357 |
+
* Delete term
|
358 |
+
*
|
359 |
+
* @access public
|
360 |
+
* @return void
|
361 |
+
*/
|
362 |
+
public function custom_permalinks_delete_term( $id ) {
|
363 |
+
$table = get_option( 'custom_permalink_table' );
|
364 |
+
if ( $table ) {
|
365 |
+
foreach ( $table as $link => $info ) {
|
366 |
+
if ( $info['id'] == $id ) {
|
367 |
+
unset( $table[$link] );
|
368 |
+
break;
|
369 |
+
}
|
370 |
+
}
|
371 |
+
}
|
372 |
+
update_option( 'custom_permalink_table', $table );
|
373 |
+
}
|
374 |
+
|
375 |
+
/**
|
376 |
+
* Check Conflicts and resolve it (e.g: Polylang)
|
377 |
+
*
|
378 |
+
* @access public
|
379 |
+
* @since 1.2
|
380 |
+
* @return string
|
381 |
+
*/
|
382 |
+
public function custom_permalinks_check_conflicts( $requested_url = '' ) {
|
383 |
+
if ( '' == $requested_url ) {
|
384 |
+
return;
|
385 |
+
}
|
386 |
+
|
387 |
+
// Check if the Polylang Plugin is installed so, make changes in the URL
|
388 |
+
if ( defined( 'POLYLANG_VERSION' ) ) {
|
389 |
+
$polylang_config = get_option( 'polylang' );
|
390 |
+
if ( $polylang_config['force_lang'] == 1 ) {
|
391 |
+
|
392 |
+
if ( false !== strpos( $requested_url, 'language/' ) ) {
|
393 |
+
$requested_url = str_replace( 'language/', '', $requested_url );
|
394 |
+
}
|
395 |
+
|
396 |
+
$remove_lang = ltrim( strstr( $requested_url, '/' ), '/' );
|
397 |
+
if ( '' != $remove_lang ) {
|
398 |
+
return $remove_lang;
|
399 |
+
}
|
400 |
+
}
|
401 |
+
}
|
402 |
+
return $requested_url;
|
403 |
+
}
|
404 |
}
|
frontend/class-custom-permalinks-frontend.php
CHANGED
@@ -3,15 +3,19 @@
|
|
3 |
* @package CustomPermalinks\Frontend
|
4 |
*/
|
5 |
|
6 |
-
class Custom_Permalinks_Frontend {
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
public function init() {
|
12 |
-
add_filter( 'request', array( $this, '
|
13 |
|
14 |
-
add_action( 'template_redirect', array( $this, '
|
15 |
|
16 |
add_filter( 'post_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
|
17 |
add_filter( 'post_type_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
|
@@ -23,10 +27,13 @@ class Custom_Permalinks_Frontend {
|
|
23 |
add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
|
24 |
}
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
30 |
global $wpdb;
|
31 |
global $_CPRegisteredURL;
|
32 |
|
@@ -63,442 +70,496 @@ class Custom_Permalinks_Frontend {
|
|
63 |
}
|
64 |
$request_noslash = preg_replace( '@/+@','/', trim( $request, '/' ) );
|
65 |
|
66 |
-
|
67 |
if ( false !== strpos( $request_noslash, '/page/' ) ) {
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
$sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status " .
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
|
92 |
$posts = $wpdb->get_results( $sql );
|
93 |
|
94 |
if ( ! $posts ) {
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
}
|
112 |
-
|
113 |
-
if ( $posts ) {
|
114 |
-
// A post matches our request
|
115 |
-
// Preserve this url for later if it's the same as the permalink (no extra stuff)
|
116 |
-
if ( $request_noslash == trim( $posts[0]->meta_value, '/' ) ) {
|
117 |
-
$_CPRegisteredURL = $request;
|
118 |
-
}
|
119 |
-
|
120 |
-
if ( $posts[0]->post_status == 'draft' ) {
|
121 |
-
if ( $posts[0]->post_type == 'page' ) {
|
122 |
-
$original_url = '?page_id=' . $posts[0]->ID;
|
123 |
-
} else {
|
124 |
-
$original_url = '?post_type=' . $posts[0]->post_type . '&p=' . $posts[0]->ID;
|
125 |
-
}
|
126 |
-
} else {
|
127 |
-
$post_meta = trim( strtolower( $posts[0]->meta_value ), '/' );
|
128 |
-
if ( $posts[0]->post_type == 'page' ) {
|
129 |
-
$get_original_url = $this->custom_permalinks_original_page_link( $posts[0]->ID );
|
130 |
-
$original_url = preg_replace( '@/+@', '/',
|
131 |
-
str_replace( $post_meta, $get_original_url, strtolower( $request_noslash ) )
|
132 |
-
);
|
133 |
-
} else {
|
134 |
-
$get_original_url = $this->custom_permalinks_original_post_link( $posts[0]->ID );
|
135 |
-
$original_url = preg_replace( '@/+@', '/',
|
136 |
-
str_replace( $post_meta, $get_original_url, strtolower( $request_noslash ) )
|
137 |
-
);
|
138 |
-
}
|
139 |
-
if ( $remove_pager !== '' ) {
|
140 |
-
$original_url = $original_url . $remove_pager;
|
141 |
-
}
|
142 |
-
}
|
143 |
-
}
|
144 |
-
|
145 |
-
if ( $original_url === NULL ) {
|
146 |
-
// See if any terms have a matching permalink
|
147 |
-
$table = get_option( 'custom_permalink_table' );
|
148 |
-
if ( ! $table ) {
|
149 |
-
return $query;
|
150 |
-
}
|
151 |
-
|
152 |
-
foreach ( array_keys( $table ) as $permalink ) {
|
153 |
-
if ( $permalink == substr( $request_noslash, 0, strlen( $permalink ) )
|
154 |
-
|| $permalink == substr( $request_noslash . '/', 0, strlen( $permalink ) ) ) {
|
155 |
-
$term = $table[$permalink];
|
156 |
-
|
157 |
-
// Preserve this url for later if it's the same as the permalink (no extra stuff)
|
158 |
-
if ( $request_noslash == trim( $permalink, '/' ) ) {
|
159 |
-
$_CPRegisteredURL = $request;
|
160 |
-
}
|
161 |
-
|
162 |
-
if ( $term['kind'] == 'category' ) {
|
163 |
-
$category_link = $this->custom_permalinks_original_category_link( $term['id'] );
|
164 |
-
} else {
|
165 |
-
$category_link = $this->custom_permalinks_original_tag_link( $term['id'] );
|
166 |
-
}
|
167 |
-
|
168 |
-
$original_url = str_replace(
|
169 |
-
trim( $permalink, '/' ), $category_link, trim( $request, '/' )
|
170 |
-
);
|
171 |
-
}
|
172 |
-
}
|
173 |
-
}
|
174 |
-
|
175 |
-
if ( $original_url !== NULL ) {
|
176 |
-
$original_url = str_replace( '//', '/', $original_url );
|
177 |
-
|
178 |
-
if ( ( $pos = strpos( $_SERVER['REQUEST_URI'], '?' ) ) !== false ) {
|
179 |
-
$query_vars = substr( $_SERVER['REQUEST_URI'], $pos + 1);
|
180 |
-
$original_url .= ( strpos( $original_url, '?' ) === false ? '?' : '&' ) . $query_vars;
|
181 |
-
}
|
182 |
-
|
183 |
-
// Now we have the original URL, run this back through WP->parse_request, in order to
|
184 |
-
// parse parameters properly. We set $_SERVER variables to fool the function.
|
185 |
-
$old_request_uri = $_SERVER['REQUEST_URI'];
|
186 |
-
$old_query_string = '';
|
187 |
-
if ( isset( $_SERVER['QUERY_STRING'] ) ) {
|
188 |
-
$old_query_string = $_SERVER['QUERY_STRING'];
|
189 |
-
}
|
190 |
-
$_SERVER['REQUEST_URI'] = '/' . ltrim( $original_url, '/' );
|
191 |
-
$path_info = apply_filters( 'custom_permalinks_path_info', '__false' );
|
192 |
-
if ( '__false' !== $path_info ) {
|
193 |
-
$_SERVER['PATH_INFO'] = '/' . ltrim( $original_url, '/' );
|
194 |
-
}
|
195 |
-
$_SERVER['QUERY_STRING'] = ( ( $pos = strpos( $original_url, '?' ) ) !== false ? substr( $original_url, $pos + 1 ) : '' );
|
196 |
-
parse_str( $_SERVER['QUERY_STRING'], $query_array );
|
197 |
-
$old_values = array();
|
198 |
-
if ( is_array( $query_array ) ) {
|
199 |
-
foreach ( $query_array as $key => $value ) {
|
200 |
-
$old_values[$key] = $_REQUEST[$key];
|
201 |
-
$_REQUEST[$key] = $_GET[$key] = $value;
|
202 |
-
}
|
203 |
-
}
|
204 |
-
|
205 |
-
// Re-run the filter, now with original environment in place
|
206 |
-
remove_filter( 'request', array( $this, 'custom_permalinks_request' ), 10, 1 );
|
207 |
-
global $wp;
|
208 |
-
$wp->parse_request();
|
209 |
-
$query = $wp->query_vars;
|
210 |
-
add_filter( 'request', array( $this, 'custom_permalinks_request' ), 10, 1 );
|
211 |
-
|
212 |
-
// Restore values
|
213 |
-
$_SERVER['REQUEST_URI'] = $old_request_uri;
|
214 |
-
$_SERVER['QUERY_STRING'] = $old_query_string;
|
215 |
-
foreach ( $old_values as $key => $value ) {
|
216 |
-
$_REQUEST[$key] = $value;
|
217 |
-
}
|
218 |
-
}
|
219 |
-
|
220 |
-
return $query;
|
221 |
-
}
|
222 |
-
|
223 |
-
/**
|
224 |
-
* Action to redirect to the custom permalink
|
225 |
-
*/
|
226 |
-
public function custom_permalinks_redirect() {
|
227 |
-
global $wpdb;
|
228 |
-
|
229 |
-
$custom_permalink = '';
|
230 |
-
$original_permalink = '';
|
231 |
-
|
232 |
-
// Get request URI, strip parameters
|
233 |
-
$url = parse_url( get_bloginfo( 'url' ) );
|
234 |
-
$url = isset( $url['path'] ) ? $url['path'] : '';
|
235 |
-
$request = ltrim( substr( $_SERVER['REQUEST_URI'], strlen( $url ) ), '/' );
|
236 |
-
$pos = strpos( $request, '?' );
|
237 |
-
if ( $pos ) {
|
238 |
-
$request = substr( $request, 0, $pos );
|
239 |
-
}
|
240 |
-
|
241 |
-
if ( defined( 'POLYLANG_VERSION' ) ) {
|
242 |
-
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-form.php' );
|
243 |
-
$cp_form = new Custom_Permalinks_Form();
|
244 |
-
$request = $cp_form->custom_permalinks_check_conflicts( $request );
|
245 |
}
|
246 |
-
$request_noslash = preg_replace( '@/+@','/', trim( $request, '/' ) );
|
247 |
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
|
|
|
|
|
|
|
|
256 |
}
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
|
|
|
|
|
|
|
|
|
|
264 |
}
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
504 |
}
|
3 |
* @package CustomPermalinks\Frontend
|
4 |
*/
|
5 |
|
6 |
+
final class Custom_Permalinks_Frontend {
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Initialize WordPress Hooks
|
10 |
+
*
|
11 |
+
* @access public
|
12 |
+
* @since 1.2
|
13 |
+
* @return void
|
14 |
+
*/
|
15 |
public function init() {
|
16 |
+
add_filter( 'request', array( $this, 'parse_request' ), 10, 1 );
|
17 |
|
18 |
+
add_action( 'template_redirect', array( $this, 'make_redirect' ), 5 );
|
19 |
|
20 |
add_filter( 'post_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
|
21 |
add_filter( 'post_type_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
|
27 |
add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
|
28 |
}
|
29 |
|
30 |
+
/**
|
31 |
+
* Filter to rewrite the query if we have a matching post
|
32 |
+
*
|
33 |
+
* @access public
|
34 |
+
* @return void
|
35 |
+
*/
|
36 |
+
public function parse_request( $query ) {
|
37 |
global $wpdb;
|
38 |
global $_CPRegisteredURL;
|
39 |
|
70 |
}
|
71 |
$request_noslash = preg_replace( '@/+@','/', trim( $request, '/' ) );
|
72 |
|
73 |
+
$remove_pager = '';
|
74 |
if ( false !== strpos( $request_noslash, '/page/' ) ) {
|
75 |
+
$check_pager = explode( '/', $request_noslash );
|
76 |
+
$get_pager_no = count( $check_pager ) - 1;
|
77 |
+
if ( is_numeric( $check_pager[$get_pager_no] ) ) {
|
78 |
+
$remove_pager = '/page/' . $check_pager[$get_pager_no];
|
79 |
+
$request_noslash = str_replace( $remove_pager, '', $request_noslash );
|
80 |
+
}
|
81 |
+
}
|
82 |
+
|
83 |
+
if ( false !== strpos( $request_noslash, '/comment-page-' ) ) {
|
84 |
+
$check_pager = explode( '/comment-page-', $request_noslash );
|
85 |
+
$get_pager_no = count( $check_pager ) - 1;
|
86 |
+
if ( is_numeric( $check_pager[$get_pager_no] ) ) {
|
87 |
+
$remove_pager = '/comment-page-' . $check_pager[$get_pager_no];
|
88 |
+
$request_noslash = str_replace( $remove_pager, '', $request_noslash );
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
$post_feed = 0;
|
93 |
+
if ( false !== strpos( $request_noslash, '/feed' ) ) {
|
94 |
+
$request_noslash = str_replace( '/feed', '', $request_noslash );
|
95 |
+
$post_feed = 1;
|
96 |
+
}
|
97 |
|
98 |
$sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status " .
|
99 |
+
" FROM $wpdb->posts AS p INNER JOIN $wpdb->postmeta AS pm ON (pm.post_id = p.ID) " .
|
100 |
+
" WHERE pm.meta_key = 'custom_permalink' " .
|
101 |
+
" AND (pm.meta_value = '%s' OR pm.meta_value = '%s') " .
|
102 |
+
" AND p.post_status != 'trash' AND p.post_type != 'nav_menu_item' " .
|
103 |
+
" ORDER BY FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
|
104 |
+
" FIELD(post_type,'post','page') LIMIT 1", $request_noslash, $request_noslash . "/" );
|
105 |
|
106 |
$posts = $wpdb->get_results( $sql );
|
107 |
|
108 |
if ( ! $posts ) {
|
109 |
+
$def_query = apply_filters( 'custom_permalinks_like_query', '__false' );
|
110 |
+
if ( defined( 'POLYLANG_VERSION' ) || defined( 'AMP__VERSION' )
|
111 |
+
|| defined( 'TASTY_RECIPES_PLUGIN_VERSION' ) || '__false' !== $def_query ) {
|
112 |
+
$sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status FROM $wpdb->posts AS p " .
|
113 |
+
" LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE " .
|
114 |
+
" meta_key = 'custom_permalink' AND meta_value != '' AND " .
|
115 |
+
" ( LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) OR " .
|
116 |
+
" LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) ) " .
|
117 |
+
" AND post_status != 'trash' AND post_type != 'nav_menu_item'" .
|
118 |
+
" ORDER BY LENGTH(meta_value) DESC, " .
|
119 |
+
" FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
|
120 |
+
" FIELD(post_type,'post','page'), p.ID ASC LIMIT 1",
|
121 |
+
$request_noslash, $request_noslash . "/" );
|
122 |
+
|
123 |
+
$posts = $wpdb->get_results( $sql );
|
124 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
}
|
|
|
126 |
|
127 |
+
if ( $posts ) {
|
128 |
+
// A post matches our request
|
129 |
+
// Preserve this url for later if it's the same as the permalink (no extra stuff)
|
130 |
+
if ( $request_noslash == trim( $posts[0]->meta_value, '/' ) ) {
|
131 |
+
$_CPRegisteredURL = $request;
|
132 |
+
}
|
133 |
+
|
134 |
+
if ( 'draft' == $posts[0]->post_status ) {
|
135 |
+
if ( 'page' == $posts[0]->post_type ) {
|
136 |
+
$original_url = '?page_id=' . $posts[0]->ID;
|
137 |
+
} else {
|
138 |
+
$original_url = '?post_type=' . $posts[0]->post_type . '&p=' . $posts[0]->ID;
|
139 |
}
|
140 |
+
} else {
|
141 |
+
$post_meta = trim( strtolower( $posts[0]->meta_value ), '/' );
|
142 |
+
if ( $posts[0]->post_type == 'page' ) {
|
143 |
+
$get_original_url = $this->custom_permalinks_original_page_link( $posts[0]->ID );
|
144 |
+
$original_url = preg_replace( '@/+@', '/',
|
145 |
+
str_replace( $post_meta, $get_original_url, strtolower( $request_noslash ) )
|
146 |
+
);
|
147 |
+
} else {
|
148 |
+
$get_original_url = $this->custom_permalinks_original_post_link( $posts[0]->ID );
|
149 |
+
$original_url = preg_replace( '@/+@', '/',
|
150 |
+
str_replace( $post_meta, $get_original_url, strtolower( $request_noslash ) )
|
151 |
+
);
|
152 |
}
|
153 |
+
if ( 1 == $post_feed ) {
|
154 |
+
$original_url = $original_url . '/feed';
|
155 |
+
}
|
156 |
+
if ( '' !== $remove_pager ) {
|
157 |
+
$original_url = $original_url . $remove_pager;
|
158 |
+
}
|
159 |
+
}
|
160 |
+
}
|
161 |
+
|
162 |
+
if ( NULL === $original_url ) {
|
163 |
+
// See if any terms have a matching permalink
|
164 |
+
$table = get_option( 'custom_permalink_table' );
|
165 |
+
if ( ! $table ) {
|
166 |
+
return $query;
|
167 |
+
}
|
168 |
+
|
169 |
+
foreach ( array_keys( $table ) as $permalink ) {
|
170 |
+
if ( $permalink == substr( $request_noslash, 0, strlen( $permalink ) )
|
171 |
+
|| $permalink == substr( $request_noslash . '/', 0, strlen( $permalink ) ) ) {
|
172 |
+
$term = $table[$permalink];
|
173 |
+
|
174 |
+
// Preserve this url for later if it's the same as the permalink (no extra stuff)
|
175 |
+
if ( $request_noslash == trim( $permalink, '/' ) ) {
|
176 |
+
$_CPRegisteredURL = $request;
|
177 |
+
}
|
178 |
+
|
179 |
+
if ( 'category' == $term['kind'] ) {
|
180 |
+
$category_link = $this->custom_permalinks_original_category_link( $term['id'] );
|
181 |
+
} else {
|
182 |
+
$category_link = $this->custom_permalinks_original_tag_link( $term['id'] );
|
183 |
+
}
|
184 |
+
|
185 |
+
$original_url = str_replace(
|
186 |
+
trim( $permalink, '/' ), $category_link, trim( $request, '/' )
|
187 |
+
);
|
188 |
+
}
|
189 |
+
}
|
190 |
+
}
|
191 |
+
|
192 |
+
if ( NULL !== $original_url ) {
|
193 |
+
$original_url = str_replace( '//', '/', $original_url );
|
194 |
+
|
195 |
+
$pos = strpos( $_SERVER['REQUEST_URI'], '?' );
|
196 |
+
if ( false !== $pos ) {
|
197 |
+
$query_vars = substr( $_SERVER['REQUEST_URI'], $pos + 1 );
|
198 |
+
$original_url .= ( strpos( $original_url, '?' ) === false ? '?' : '&' ) . $query_vars;
|
199 |
+
}
|
200 |
+
|
201 |
+
// Now we have the original URL, run this back through WP->parse_request, in order to
|
202 |
+
// parse parameters properly. We set $_SERVER variables to fool the function.
|
203 |
+
$old_request_uri = $_SERVER['REQUEST_URI'];
|
204 |
+
$old_query_string = '';
|
205 |
+
if ( isset( $_SERVER['QUERY_STRING'] ) ) {
|
206 |
+
$old_query_string = $_SERVER['QUERY_STRING'];
|
207 |
+
}
|
208 |
+
$_SERVER['REQUEST_URI'] = '/' . ltrim( $original_url, '/' );
|
209 |
+
$path_info = apply_filters( 'custom_permalinks_path_info', '__false' );
|
210 |
+
if ( '__false' !== $path_info ) {
|
211 |
+
$_SERVER['PATH_INFO'] = '/' . ltrim( $original_url, '/' );
|
212 |
+
}
|
213 |
+
|
214 |
+
$_SERVER['QUERY_STRING'] = '';
|
215 |
+
$pos = strpos( $original_url, '?' );
|
216 |
+
if ( false !== $pos ) {
|
217 |
+
$_SERVER['QUERY_STRING'] = substr( $original_url, $pos + 1 );
|
218 |
+
}
|
219 |
+
|
220 |
+
parse_str( $_SERVER['QUERY_STRING'], $query_array );
|
221 |
+
$old_values = array();
|
222 |
+
if ( is_array( $query_array ) ) {
|
223 |
+
foreach ( $query_array as $key => $value ) {
|
224 |
+
$old_values[$key] = $_REQUEST[$key];
|
225 |
+
$_REQUEST[$key] = $_GET[$key] = $value;
|
226 |
+
}
|
227 |
+
}
|
228 |
+
|
229 |
+
// Re-run the filter, now with original environment in place
|
230 |
+
remove_filter( 'request', array( $this, 'parse_request' ), 10, 1 );
|
231 |
+
global $wp;
|
232 |
+
$wp->parse_request();
|
233 |
+
$query = $wp->query_vars;
|
234 |
+
add_filter( 'request', array( $this, 'parse_request' ), 10, 1 );
|
235 |
+
|
236 |
+
// Restore values
|
237 |
+
$_SERVER['REQUEST_URI'] = $old_request_uri;
|
238 |
+
$_SERVER['QUERY_STRING'] = $old_query_string;
|
239 |
+
foreach ( $old_values as $key => $value ) {
|
240 |
+
$_REQUEST[$key] = $value;
|
241 |
+
}
|
242 |
+
}
|
243 |
+
|
244 |
+
return $query;
|
245 |
+
}
|
246 |
+
|
247 |
+
/**
|
248 |
+
* Action to redirect to the custom permalink
|
249 |
+
*
|
250 |
+
* @access public
|
251 |
+
* @return void
|
252 |
+
*/
|
253 |
+
public function make_redirect() {
|
254 |
+
global $wpdb;
|
255 |
+
|
256 |
+
$custom_permalink = '';
|
257 |
+
$original_permalink = '';
|
258 |
+
|
259 |
+
// Get request URI, strip parameters
|
260 |
+
$url = parse_url( get_bloginfo( 'url' ) );
|
261 |
+
$url = isset( $url['path'] ) ? $url['path'] : '';
|
262 |
+
$request = ltrim( substr( $_SERVER['REQUEST_URI'], strlen( $url ) ), '/' );
|
263 |
+
$pos = strpos( $request, '?' );
|
264 |
+
if ( $pos ) {
|
265 |
+
$request = substr( $request, 0, $pos );
|
266 |
+
}
|
267 |
+
|
268 |
+
if ( defined( 'POLYLANG_VERSION' ) ) {
|
269 |
+
require_once( CUSTOM_PERMALINKS_PATH . 'frontend/class-custom-permalinks-form.php' );
|
270 |
+
$cp_form = new Custom_Permalinks_Form();
|
271 |
+
$request = $cp_form->custom_permalinks_check_conflicts( $request );
|
272 |
+
}
|
273 |
+
$request_noslash = preg_replace( '@/+@','/', trim( $request, '/' ) );
|
274 |
+
|
275 |
+
$remove_pager = '';
|
276 |
+
if ( false !== strpos( $request_noslash, '/page/' ) ) {
|
277 |
+
$check_pager = explode( '/', $request_noslash );
|
278 |
+
$get_pager_no = count( $check_pager ) - 1;
|
279 |
+
if ( is_numeric( $check_pager[$get_pager_no] ) ) {
|
280 |
+
$remove_pager = '/page/' . $check_pager[$get_pager_no];
|
281 |
+
$request_noslash = str_replace( $remove_pager, '', $request_noslash );
|
282 |
+
}
|
283 |
+
}
|
284 |
+
|
285 |
+
if ( false !== strpos( $request_noslash, '/comment-page-' ) ) {
|
286 |
+
$check_pager = explode( '/comment-page-', $request_noslash );
|
287 |
+
$get_pager_no = count( $check_pager ) - 1;
|
288 |
+
if ( is_numeric( $check_pager[$get_pager_no] ) ) {
|
289 |
+
$remove_pager = '/comment-page-' . $check_pager[$get_pager_no];
|
290 |
+
$request_noslash = str_replace( $remove_pager, '', $request_noslash );
|
291 |
+
}
|
292 |
+
}
|
293 |
+
|
294 |
+
if ( false !== strpos( $request_noslash, '/feed' ) ) {
|
295 |
+
$request_noslash = str_replace( '/feed', '', $request_noslash );
|
296 |
+
}
|
297 |
+
|
298 |
+
$sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status " .
|
299 |
+
" FROM $wpdb->posts AS p INNER JOIN $wpdb->postmeta AS pm ON (pm.post_id = p.ID) " .
|
300 |
+
" WHERE pm.meta_key = 'custom_permalink' " .
|
301 |
+
" AND (pm.meta_value = '%s' OR pm.meta_value = '%s') " .
|
302 |
+
" AND p.post_status != 'trash' AND p.post_type != 'nav_menu_item' " .
|
303 |
+
" ORDER BY FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
|
304 |
+
" FIELD(post_type,'post','page') LIMIT 1", $request_noslash, $request_noslash . "/" );
|
305 |
+
|
306 |
+
$posts = $wpdb->get_results( $sql );
|
307 |
+
|
308 |
+
if ( ! $posts ) {
|
309 |
+
$def_query = apply_filters( 'custom_permalinks_like_query', '__false' );
|
310 |
+
if ( defined( 'POLYLANG_VERSION' ) || defined( 'AMP__VERSION' )
|
311 |
+
|| defined( 'TASTY_RECIPES_PLUGIN_VERSION' ) || '__false' !== $def_query ) {
|
312 |
+
$sql = $wpdb->prepare( "SELECT p.ID, pm.meta_value, p.post_type, p.post_status FROM $wpdb->posts AS p " .
|
313 |
+
" LEFT JOIN $wpdb->postmeta AS pm ON (p.ID = pm.post_id) WHERE " .
|
314 |
+
" meta_key = 'custom_permalink' AND meta_value != '' AND " .
|
315 |
+
" ( LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) OR " .
|
316 |
+
" LOWER(meta_value) = LEFT(LOWER('%s'), LENGTH(meta_value)) ) " .
|
317 |
+
" AND post_status != 'trash' AND post_type != 'nav_menu_item'" .
|
318 |
+
" ORDER BY LENGTH(meta_value) DESC, " .
|
319 |
+
" FIELD(post_status,'publish','private','draft','auto-draft','inherit')," .
|
320 |
+
" FIELD(post_type,'post','page'), p.ID ASC LIMIT 1",
|
321 |
+
$request_noslash, $request_noslash . "/" );
|
322 |
+
|
323 |
+
$posts = $wpdb->get_results( $sql );
|
324 |
+
}
|
325 |
+
}
|
326 |
+
|
327 |
+
if ( ! isset( $posts[0]->ID ) || ! isset( $posts[0]->meta_value )
|
328 |
+
|| empty( $posts[0]->meta_value ) ) {
|
329 |
+
global $wp_query;
|
330 |
+
|
331 |
+
// If the post/tag/category we're on has a custom permalink, get it and check against the request
|
332 |
+
if ( ( is_single() || is_page() ) && ! empty( $wp_query->post ) ) {
|
333 |
+
$post = $wp_query->post;
|
334 |
+
$custom_permalink = get_post_meta( $post->ID, 'custom_permalink', true );
|
335 |
+
if ( $post->post_type == 'page' ) {
|
336 |
+
$original_permalink = $this->custom_permalinks_original_page_link( $post->ID );
|
337 |
+
} else {
|
338 |
+
$original_permalink = $this->custom_permalinks_original_post_link( $post->ID );
|
339 |
+
}
|
340 |
+
} elseif ( is_tag() || is_category() ) {
|
341 |
+
$theTerm = $wp_query->get_queried_object();
|
342 |
+
$custom_permalink = $this->custom_permalinks_permalink_for_term( $theTerm->term_id );
|
343 |
+
if ( is_tag() ) {
|
344 |
+
$original_permalink = $this->custom_permalinks_original_tag_link( $theTerm->term_id );
|
345 |
+
} else {
|
346 |
+
$original_permalink = $this->custom_permalinks_original_category_link( $theTerm->term_id );
|
347 |
+
}
|
348 |
+
}
|
349 |
+
} else {
|
350 |
+
$custom_permalink = $posts[0]->meta_value;
|
351 |
+
if ( 'page' == $posts[0]->post_type ) {
|
352 |
+
$original_permalink = $this->custom_permalinks_original_page_link( $posts[0]->ID );
|
353 |
+
} else {
|
354 |
+
$original_permalink = $this->custom_permalinks_original_post_link( $posts[0]->ID );
|
355 |
+
}
|
356 |
+
}
|
357 |
+
|
358 |
+
if ( $custom_permalink
|
359 |
+
&& ( substr( $request, 0, strlen( $custom_permalink ) ) != $custom_permalink
|
360 |
+
|| $request == $custom_permalink . '/' ) ) {
|
361 |
+
|
362 |
+
// Request doesn't match permalink - redirect
|
363 |
+
$url = $custom_permalink;
|
364 |
+
|
365 |
+
if ( substr( $request, 0, strlen( $original_permalink ) ) == $original_permalink
|
366 |
+
&& trim( $request, '/' ) != trim( $original_permalink, '/' ) ) {
|
367 |
+
// This is the original link; we can use this url to derive the new one
|
368 |
+
$url = preg_replace( '@//*@', '/', str_replace( trim( $original_permalink, '/' ), trim( $custom_permalink, '/' ), $request ) );
|
369 |
+
$url = preg_replace( '@([^?]*)&@', '\1?', $url );
|
370 |
+
}
|
371 |
+
|
372 |
+
// Append any query compenent
|
373 |
+
$url .= strstr( $_SERVER['REQUEST_URI'], '?' );
|
374 |
+
|
375 |
+
wp_redirect( home_url() . '/' . $url, 301 );
|
376 |
+
exit();
|
377 |
+
}
|
378 |
+
}
|
379 |
+
|
380 |
+
/**
|
381 |
+
* Filter to replace the post permalink with the custom one
|
382 |
+
*
|
383 |
+
* @access public
|
384 |
+
* @return string
|
385 |
+
*/
|
386 |
+
public function custom_permalinks_post_link( $permalink, $post ) {
|
387 |
+
$custom_permalink = get_post_meta( $post->ID, 'custom_permalink', true );
|
388 |
+
if ( $custom_permalink ) {
|
389 |
+
$post_type = isset( $post->post_type ) ? $post->post_type : 'post';
|
390 |
+
$language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $post->ID, 'element_type' => $post_type ) );
|
391 |
+
if ( $language_code )
|
392 |
+
return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink, $language_code );
|
393 |
+
else
|
394 |
+
return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink );
|
395 |
+
}
|
396 |
+
|
397 |
+
return $permalink;
|
398 |
+
}
|
399 |
+
|
400 |
+
/**
|
401 |
+
* Filter to replace the page permalink with the custom one
|
402 |
+
*
|
403 |
+
* @access public
|
404 |
+
* @return string
|
405 |
+
*/
|
406 |
+
public function custom_permalinks_page_link( $permalink, $page ) {
|
407 |
+
$custom_permalink = get_post_meta( $page, 'custom_permalink', true );
|
408 |
+
if ( $custom_permalink ) {
|
409 |
+
$language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $page, 'element_type' => 'page' ) );
|
410 |
+
if ( $language_code )
|
411 |
+
return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink, $language_code );
|
412 |
+
else
|
413 |
+
return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink );
|
414 |
+
}
|
415 |
+
|
416 |
+
return $permalink;
|
417 |
+
}
|
418 |
+
|
419 |
+
/**
|
420 |
+
* Filter to replace the term permalink with the custom one
|
421 |
+
*
|
422 |
+
* @access public
|
423 |
+
* @return string
|
424 |
+
*/
|
425 |
+
public function custom_permalinks_term_link( $permalink, $term ) {
|
426 |
+
$table = get_option( 'custom_permalink_table' );
|
427 |
+
if ( is_object( $term ) ) {
|
428 |
+
$term = $term->term_id;
|
429 |
+
}
|
430 |
+
|
431 |
+
$custom_permalink = $this->custom_permalinks_permalink_for_term( $term );
|
432 |
+
if ( $custom_permalink ) {
|
433 |
+
$taxonomy = get_term( $term );
|
434 |
+
if ( isset( $taxonomy ) && isset( $taxonomy->term_taxonomy_id ) ) {
|
435 |
+
$term_type = 'category';
|
436 |
+
if ( isset( $taxonomy->taxonomy ) ) {
|
437 |
+
$term_type = $taxonomy->taxonomy;
|
438 |
+
}
|
439 |
+
$language_code = apply_filters( 'wpml_element_language_code', null, array( 'element_id' => $taxonomy->term_taxonomy_id, 'element_type' => $term_type ) );
|
440 |
+
return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink, $language_code );
|
441 |
+
} else {
|
442 |
+
return apply_filters( 'wpml_permalink', home_url() . '/' . $custom_permalink );
|
443 |
+
}
|
444 |
+
}
|
445 |
+
|
446 |
+
return $permalink;
|
447 |
+
}
|
448 |
+
|
449 |
+
/**
|
450 |
+
* Get original permalink for post
|
451 |
+
*
|
452 |
+
* @access public
|
453 |
+
* @return string
|
454 |
+
*/
|
455 |
+
public function custom_permalinks_original_post_link( $post_id ) {
|
456 |
+
remove_filter( 'post_link', array( $this, 'custom_permalinks_post_link' ), 10, 3 );
|
457 |
+
remove_filter( 'post_type_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
|
458 |
+
|
459 |
+
require_once ABSPATH . '/wp-admin/includes/post.php';
|
460 |
+
list( $permalink, $post_name ) = get_sample_permalink( $post_id );
|
461 |
+
$permalink = str_replace( array( '%pagename%','%postname%' ), $post_name, $permalink );
|
462 |
+
$permalink = ltrim( str_replace( home_url(), '', $permalink ), '/' );
|
463 |
+
|
464 |
+
add_filter( 'post_link', array( $this, 'custom_permalinks_post_link' ), 10, 3 );
|
465 |
+
add_filter( 'post_type_link', array( $this, 'custom_permalinks_post_link' ), 10, 2 );
|
466 |
+
|
467 |
+
return $permalink;
|
468 |
+
}
|
469 |
+
|
470 |
+
/**
|
471 |
+
* Get original permalink for page
|
472 |
+
*
|
473 |
+
* @access public
|
474 |
+
* @return string
|
475 |
+
*/
|
476 |
+
public function custom_permalinks_original_page_link( $post_id ) {
|
477 |
+
remove_filter( 'page_link', array( $this, 'custom_permalinks_page_link' ), 10, 2 );
|
478 |
+
remove_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
|
479 |
+
|
480 |
+
require_once ABSPATH . '/wp-admin/includes/post.php';
|
481 |
+
list( $permalink, $post_name ) = get_sample_permalink( $post_id );
|
482 |
+
$permalink = str_replace( array( '%pagename%','%postname%' ), $post_name, $permalink );
|
483 |
+
$permalink = ltrim( str_replace( home_url(), '', $permalink ), '/' );
|
484 |
+
|
485 |
+
add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
|
486 |
+
add_filter( 'page_link', array( $this, 'custom_permalinks_page_link' ), 10, 2 );
|
487 |
+
return $permalink;
|
488 |
+
}
|
489 |
+
|
490 |
+
/**
|
491 |
+
* Get original permalink for tag
|
492 |
+
*
|
493 |
+
* @access public
|
494 |
+
* @return string
|
495 |
+
*/
|
496 |
+
public function custom_permalinks_original_tag_link( $tag_id ) {
|
497 |
+
remove_filter( 'tag_link', array( $this, 'custom_permalinks_term_link' ), 10, 2 );
|
498 |
+
remove_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
|
499 |
+
$originalPermalink = ltrim( str_replace( home_url(), '', get_tag_link( $tag_id ) ), '/' );
|
500 |
+
add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
|
501 |
+
add_filter( 'tag_link', array( $this, 'custom_permalinks_term_link' ), 10, 2 );
|
502 |
+
return $originalPermalink;
|
503 |
+
}
|
504 |
+
|
505 |
+
/**
|
506 |
+
* Get original permalink for category
|
507 |
+
*
|
508 |
+
* @access public
|
509 |
+
* @return string
|
510 |
+
*/
|
511 |
+
public function custom_permalinks_original_category_link( $category_id ) {
|
512 |
+
remove_filter( 'category_link', array( $this, 'custom_permalinks_term_link' ), 10, 2 );
|
513 |
+
remove_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
|
514 |
+
$originalPermalink = ltrim( str_replace( home_url(), '', get_category_link( $category_id ) ), '/' );
|
515 |
+
add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
|
516 |
+
add_filter( 'category_link', array( $this, 'custom_permalinks_term_link' ), 10, 2 );
|
517 |
+
return $originalPermalink;
|
518 |
+
}
|
519 |
+
|
520 |
+
/**
|
521 |
+
* Filter to handle trailing slashes correctly
|
522 |
+
*
|
523 |
+
* @access public
|
524 |
+
* @return string
|
525 |
+
*/
|
526 |
+
public function custom_permalinks_trailingslash( $string, $type ) {
|
527 |
+
global $_CPRegisteredURL;
|
528 |
+
|
529 |
+
remove_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
|
530 |
+
$url = parse_url( get_bloginfo( 'url' ) );
|
531 |
+
$request = ltrim( isset( $url['path'] ) ? substr( $string, strlen( $url['path'] ) ) : $string, '/' );
|
532 |
+
add_filter( 'user_trailingslashit', array( $this, 'custom_permalinks_trailingslash' ), 10, 2 );
|
533 |
+
|
534 |
+
if ( ! trim( $request ) ) {
|
535 |
+
return $string;
|
536 |
+
}
|
537 |
+
|
538 |
+
if ( trim( $_CPRegisteredURL, '/' ) == trim( $request, '/' ) ) {
|
539 |
+
if ( isset( $url['path'] ) ) {
|
540 |
+
return ( $string{0} == '/' ? '/' : '' ) . trailingslashit( $url['path'] ) . $_CPRegisteredURL;
|
541 |
+
} else {
|
542 |
+
return ( $string{0} == '/' ? '/' : '' ) . $_CPRegisteredURL;
|
543 |
+
}
|
544 |
+
}
|
545 |
+
return $string;
|
546 |
+
}
|
547 |
+
|
548 |
+
/**
|
549 |
+
* Get permalink for term
|
550 |
+
*
|
551 |
+
* @access public
|
552 |
+
* @return boolean
|
553 |
+
*/
|
554 |
+
public function custom_permalinks_permalink_for_term( $id ) {
|
555 |
+
$table = get_option( 'custom_permalink_table' );
|
556 |
+
if ( $table ) {
|
557 |
+
foreach ( $table as $link => $info ) {
|
558 |
+
if ( $info['id'] == $id ) {
|
559 |
+
return $link;
|
560 |
+
}
|
561 |
+
}
|
562 |
+
}
|
563 |
+
return false;
|
564 |
+
}
|
565 |
}
|
languages/index.php
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
<?php
|
2 |
-
/**
|
3 |
-
* Silence is golden
|
4 |
*/
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Silence is golden
|
4 |
*/
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.me/yasglobal
|
|
4 |
Tags: permalink, url, link, address, custom, redirect, custom post type
|
5 |
Requires at least: 2.6
|
6 |
Tested up to: 4.9
|
7 |
-
Stable tag: 1.2.
|
8 |
License: GPLv3
|
9 |
License URI: https://www.gnu.org/licenses/gpl.html
|
10 |
|
@@ -93,21 +93,30 @@ This process defines you the steps to follow either you are installing through W
|
|
93 |
|
94 |
== Changelog ==
|
95 |
|
96 |
-
= 1.2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
* Fixed Pagination Issue on Comments
|
99 |
* Optimize Post Pager Query
|
100 |
|
101 |
-
|
102 |
-
= 1.2.16 =
|
103 |
|
104 |
* Added compatibility with Tasty Recipes Plugin
|
105 |
|
106 |
-
= 1.2.15 =
|
107 |
|
108 |
* Added filter which can be used to add PATH_INFO in $_SERVER Variable
|
109 |
|
110 |
-
= 1.2.14 =
|
111 |
|
112 |
* Enhancement
|
113 |
* Added PATH_INFO in $_SERVER Variable
|
@@ -115,19 +124,19 @@ This process defines you the steps to follow either you are installing through W
|
|
115 |
* Bugs
|
116 |
* $this variable issue on static method
|
117 |
|
118 |
-
= 1.2.12 =
|
119 |
|
120 |
* Fixed translation path and pager content issue
|
121 |
|
122 |
-
= 1.2.11 =
|
123 |
|
124 |
* Fixed pager issue
|
125 |
|
126 |
-
= 1.2.10 =
|
127 |
|
128 |
* Fixed Redirect Issue of Child Pages
|
129 |
|
130 |
-
= 1.2.9 =
|
131 |
|
132 |
* Enhancements
|
133 |
* Added Filter to enable the like query
|
@@ -136,15 +145,15 @@ This process defines you the steps to follow either you are installing through W
|
|
136 |
* Removed LIKE Query in default. It only works if the site uses PolyLang,
|
137 |
AMP Plugins or separately enabled using the provided filter.
|
138 |
|
139 |
-
= 1.2.8 =
|
140 |
|
141 |
* Add Order by in request query
|
142 |
|
143 |
-
= 1.2.7 =
|
144 |
|
145 |
* Fixed Parse Error
|
146 |
|
147 |
-
= 1.2.6 =
|
148 |
|
149 |
* Enhancements
|
150 |
* Added Filter to Exclude Post types
|
4 |
Tags: permalink, url, link, address, custom, redirect, custom post type
|
5 |
Requires at least: 2.6
|
6 |
Tested up to: 4.9
|
7 |
+
Stable tag: 1.2.18
|
8 |
License: GPLv3
|
9 |
License URI: https://www.gnu.org/licenses/gpl.html
|
10 |
|
93 |
|
94 |
== Changelog ==
|
95 |
|
96 |
+
= 1.2.18 - April 05, 2018 =
|
97 |
+
|
98 |
+
* Enhancement
|
99 |
+
* Merged custom-permalinks-main.php with custom-permalinks.php
|
100 |
+
* Added uninstall.php
|
101 |
+
|
102 |
+
* Bugs
|
103 |
+
* Added feed redirect of default permalink
|
104 |
+
* Provide proper feed of custom permalink
|
105 |
+
|
106 |
+
= 1.2.17 - Feb 13, 2018 =
|
107 |
|
108 |
* Fixed Pagination Issue on Comments
|
109 |
* Optimize Post Pager Query
|
110 |
|
111 |
+
= 1.2.16 - Feb 09, 2018 =
|
|
|
112 |
|
113 |
* Added compatibility with Tasty Recipes Plugin
|
114 |
|
115 |
+
= 1.2.15 - Feb 08, 2018 =
|
116 |
|
117 |
* Added filter which can be used to add PATH_INFO in $_SERVER Variable
|
118 |
|
119 |
+
= 1.2.14 - Feb 07, 2018 =
|
120 |
|
121 |
* Enhancement
|
122 |
* Added PATH_INFO in $_SERVER Variable
|
124 |
* Bugs
|
125 |
* $this variable issue on static method
|
126 |
|
127 |
+
= 1.2.12 - Jan 25, 2018 =
|
128 |
|
129 |
* Fixed translation path and pager content issue
|
130 |
|
131 |
+
= 1.2.11 - Jan 24, 2018 =
|
132 |
|
133 |
* Fixed pager issue
|
134 |
|
135 |
+
= 1.2.10 - Jan 17, 2018 =
|
136 |
|
137 |
* Fixed Redirect Issue of Child Pages
|
138 |
|
139 |
+
= 1.2.9 - Jan 16, 2018 =
|
140 |
|
141 |
* Enhancements
|
142 |
* Added Filter to enable the like query
|
145 |
* Removed LIKE Query in default. It only works if the site uses PolyLang,
|
146 |
AMP Plugins or separately enabled using the provided filter.
|
147 |
|
148 |
+
= 1.2.8 - Nov 03, 2017 =
|
149 |
|
150 |
* Add Order by in request query
|
151 |
|
152 |
+
= 1.2.7 - Oct 27, 2017 =
|
153 |
|
154 |
* Fixed Parse Error
|
155 |
|
156 |
+
= 1.2.6 - Oct 27, 2017 =
|
157 |
|
158 |
* Enhancements
|
159 |
* Added Filter to Exclude Post types
|
uninstall.php
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* CustomPermalinks Uninstall
|
4 |
+
*
|
5 |
+
* Deletes Option and Post Permalinks on uninstalling the Plugin.
|
6 |
+
*
|
7 |
+
* @package CustomPermalinks/Uninstaller
|
8 |
+
* @since 1.2.18
|
9 |
+
*/
|
10 |
+
|
11 |
+
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
12 |
+
exit;
|
13 |
+
}
|
14 |
+
|
15 |
+
delete_post_meta_by_key( 'custom_permalink' );
|
16 |
+
delete_option( 'custom_permalink_table' );
|
17 |
+
|
18 |
+
// Clear any cached data that has been removed
|
19 |
+
wp_cache_flush();
|