Headline
CVE-2022-4410: Changeset 2833667 for permalink-manager – WordPress Plugin Repository
The Permalink Manager Lite plugin for WordPress is vulnerable to Stored Cross-Site Scripting in versions up to, and including 2.2.20.3 due to improper output escaping on post/page/media titles. This makes it possible for attackers to inject arbitrary web scripts on the permalink-manager page if another plugin or theme is installed on the site that allows lower privileged users with unfiltered_html the ability to modify post/page titles with malicious web scripts.
permalink-manager/trunk/README.txt
r2818536
r2833667
7
7
Requires at least: 4.4.0
8
8
Requires PHP: 5.4
9
Tested up to: 6.1.1
10
Stable tag: 2.2.20.3
9
Tested up to: 6.2.0
10
Stable tag: 2.3.0
11
11
12
12
Permalink Manager lets you customize the complete URL addresses of your posts, pages, custom post types, terms, and WooCommerce links with ease without touching any core files.
…
…
34
34
\= Additional features available in Permalink Manager Pro =
35
35
36
The free version covers all of the necessary functions, while the premium version adds a few handy functionalities that can improve the process of adjusting WordPress permalinks.
36
The free version covers all the necessary functions, while the premium version adds a few handy functionalities that can improve the process of adjusting WordPress permalinks.
37
37
38
38
Click here for additional information and to purchase <a href="https://permalinkmanager.pro?utm\_source=wordpress">Permalink Manager Pro</a>.
…
…
71
71
72
72
\= Will the old permalink automatically redirect the new ones?
73
Yes, Permalink Manager will automatically redirect the native permalinks (used when the plugin is disabled or before it was activated) to the actual, custom permalinks.
73
Yes, Permalink Manager will automatically redirect the native permalinks (used when the plugin is disabled, or before it was activated) to the actual, custom permalinks.
74
74
75
75
\= Does this plugin support Buddypress?
76
Currently there is no 100% guarantee that Permalink Manager will work correctly with Buddypress.
76
Currently, there is no 100% guarantee that Permalink Manager will work correctly with Buddypress.
77
77
78
78
\= Can I remove the plugin after the permalinks are updated? =
79
79
Yes, if you used Permalink Manager only to regenerate the slugs (native post names). Please note that if you use custom permalinks (that differ from the native ones), they will no longer be used after the plugin is disabled.
80
80
81
It is because Permalink Manager overwrites one of the core Wordpress functionalities to bypass the rewrite rules ("regular expressions" to detect the posts/pages/taxonomies/etc. and another parameters from the URL) by using the array of custom permalinks (you can check them in "Debug" tab) that are used only by the plugin.
81
It is because Permalink Manager overwrites one of the core WordPress functionalities to bypass the rewrite rules ("regular expressions" to detect the posts/pages/taxonomies/etc. and another parameters from the URL) by using the array of custom permalinks (you can check them in "Debug" tab) that are used only by the plugin.
82
82
83
83
\== Screenshots ==
…
…
93
93
94
94
\== Changelog ==
95
96
\= 2.3.0 (December 14, 2022) =
97
\* Dev - For improved readability, the plugin's code has been reformatted and more comments have been added to match WordPress PHP Coding Standards
98
\* Dev - To simplify the codebase, redundant functions and variables were removed
99
\* Fix - The post/term titles in Bulk URI Editor are protected from XSS (Cross-site scripting) attacks by sanitizing the displayed titles
100
\* Fix - Improved compatibility with Groundhogg plugin
101
\* Fix - Improved compatibility with BasePress plugin
102
\* Fix - Minor improvements for WPML compatibility
103
\* Fix - The bug that caused the message "You are not allowed to remove Permalink Manager data!" to show up randomly in the admin dashboard has been fixed
104
105
\= 2.2.20.4 (November 23, 2022) =
106
\* Fix - The "URI Editor" for individual term pages is now called later to ensure that all custom taxonomies are registered
107
\* Dev - The "nonce" field has been renamed for clarity
108
\* Dev - New filter added - 'permalink\_manager\_get\_language\_code'
95
109
96
110
\= 2.2.20.2/2.2.20.3 (November 15, 2022) =
…
…
239
253
\= 2.2.8.8/2.2.8.9 =
240
254
\* Fix - Hotfix for 'redirect\_canonical' function (causing a redirect loop)
241
\* Fix - The custom canonical permalink set with Yoast SEO is now no longer overwriten
255
\* Fix - The custom canonical permalink set with Yoast SEO is now no longer overwritten
242
256
\* Fix - The custom permalinks are no longer saved if the post/term has no title
243
257
\* Fix - Hotfix for Gutenberg related JS errors
…
…
449
463
\* Dev - Better support for non-ASCII characters in URIs
450
464
\* Fix - Minor fix for hierarchical post types
451
\* Fix Fix for coupon URL redirect
465
\* Fix \- Coupon URL redirect
452
466
\* Enhancement - New filter - "permalink-manager-force-hyphens"
453
467
…
…
455
469
\* Enhancement - Discount URLs for WooCommerce - now the shop clients can use coupons' custom URIs to easily apply the discount to the cart
456
470
\* Enhancement - Extra AJAX check for duplicated URIs in "Edit URI" box
457
\* Enhancement - Wordpress CronJobs for "Automatically remove duplicates" functionality
471
\* Enhancement - WordPress CronJobs for "Automatically remove duplicates" functionality
458
472
\* Dev - Extra improvements in "save\_post/update\_term" hooks
459
473
\* Fix - Terms permalinks added via "Edit post" page
…
…
470
484
\* Fix - Hotfix for redirects - redirect chain no longer occurs (WPML)
471
485
\* Fix - Hotfix for ACF custom fields in terms
472
\* Fix - "Trailling slashes" mode setting added, also the trailing slashes are removed from permalinks containing GET parameters or anchors (often used by 3rd party plugins)
486
\* Fix - "Trailing slashes" mode setting added, also the trailing slashes are removed from permalinks containing GET parameters or anchors (often used by 3rd party plugins)
473
487
474
488
\= 2.0.5.2.2 =
…
…
539
553
\* Fix - Hotfix for custom field tags
540
554
\* Fix - Hotfix for Jetpack
541
\* Enhancement - Suuport for WP All Import
555
\* Enhancement - Support for WP All Import
542
556
\* Enhancement - Support for Custom Permalinks
543
557
permalink-manager/trunk/includes/core/permalink-manager-actions.php
r2818533
r2833667
1
1
<?php
2
2
3
/\*\*
3
\* Additional hooks for "Permalink Manager Pro"
4
\*/
5
class Permalink\_Manager\_Actions extends Permalink\_Manager\_Class {
4
\* Additional hooks for "Permalink Manager Pro"
5
\*/
6
class Permalink\_Manager\_Actions {
6
7
7
8
public function \_\_construct() {
8
add\_action('admin\_init', array($this, 'trigger\_action'), 9);
9
add\_action('admin\_init', array($this, 'extra\_actions'));
9
add\_action( 'admin\_init', array( $this, 'trigger\_action' ), 9 );
10
add\_action( 'admin\_init', array( $this, 'extra\_actions' ) );
10
11
11
12
// Ajax-based functions
12
if(is\_admin()) {
13
add\_action('wp\_ajax\_pm\_bulk\_tools', array($this, 'ajax\_bulk\_tools'));
14
add\_action('wp\_ajax\_pm\_save\_permalink', array($this, 'ajax\_save\_permalink'));
15
add\_action('wp\_ajax\_pm\_detect\_duplicates', array($this, 'ajax\_detect\_duplicates'));
16
add\_action('wp\_ajax\_pm\_dismissed\_notice\_handler', array($this, 'ajax\_hide\_global\_notice'));
17
}
18
19
add\_action('clean\_permalinks\_event', array($this, 'clean\_permalinks\_hook'));
20
add\_action('init', array($this, 'clean\_permalinks\_cronjob'));
21
}
22
23
/\*\*
24
\* Actions
25
\*/
13
if ( is\_admin() ) {
14
add\_action( 'wp\_ajax\_pm\_bulk\_tools', array( $this, 'ajax\_bulk\_tools' ) );
15
add\_action( 'wp\_ajax\_pm\_save\_permalink', array( $this, 'ajax\_save\_permalink' ) );
16
add\_action( 'wp\_ajax\_pm\_detect\_duplicates', array( $this, 'ajax\_detect\_duplicates' ) );
17
add\_action( 'wp\_ajax\_pm\_dismissed\_notice\_handler', array( $this, 'ajax\_hide\_global\_notice' ) );
18
}
19
20
add\_action( 'clean\_permalinks\_event', array( $this, 'clean\_permalinks\_hook' ) );
21
add\_action( 'init', array( $this, 'clean\_permalinks\_cronjob' ) );
22
}
23
24
/\*\*
25
\* Route the requests to functions that save datasets with associated callbacks
26
\*/
26
27
public function trigger\_action() {
27
28
global $permalink\_manager\_after\_sections\_html;
28
29
29
30
// 1. Check if the form was submitted
30
if(empty($\_POST)) {
31
if ( empty( $\_POST ) ) {
31
32
return;
32
33
}
33
34
34
35
// 2. Do nothing if search query is not empty
35
if(isset($\_REQUEST\['search-submit'\]) || isset($\_REQUEST\['months-filter-button'\])) {
36
if ( isset( $\_REQUEST\['search-submit'\] ) || isset( $\_REQUEST\['months-filter-button'\] ) ) {
36
37
return;
37
38
}
38
39
39
40
$actions\_map = array(
40
'uri\_editor' \=> array('function' => 'update\_all\_permalinks', 'display\_uri\_table' => true),
41
'permalink\_manager\_options' \=> array('function' => 'save\_settings'),
42
'permalink\_manager\_permastructs' => array('function' => 'save\_permastructures'),
43
'import' \=> array('function' => 'import\_custom\_permalinks\_uris'),
41
'uri\_editor' => array( 'function' => 'update\_all\_permalinks', 'display\_uri\_table' => true ),
42
'permalink\_manager\_options' => array( 'function' => 'save\_settings' ),
43
'permalink\_manager\_permastructs' => array( 'function' => 'save\_permastructures' ),
44
'import' => array( 'function' => 'import\_custom\_permalinks\_uris' ),
44
45
);
45
46
46
47
// 3. Find the action
47
foreach($actions\_map as $action => $map) {
48
if(isset($\_POST\[$action\]) && wp\_verify\_nonce($\_POST\[$action\], 'permalink-manager')) {
48
foreach ( $actions\_map as $action => $map ) {
49
if ( isset( $\_POST\[ $action \] ) && wp\_verify\_nonce( $\_POST\[ $action \], 'permalink-manager' ) ) {
49
50
// Execute the function
50
$output = call\_user\_func(array($this, $map\['function'\]));
51
$output = call\_user\_func( array( $this, $map\['function'\] ) );
51
52
52
53
// Get list of updated URIs
53
if(!empty($map\['display\_uri\_table'\])) {
54
$updated\_slugs\_count = (isset($output\['updated\_count'\]) && $output\['updated\_count'\] > 0) ? $output\['updated\_count'\] : false;
55
$updated\_slugs\_array = ($updated\_slugs\_count) ? $output\['updated'\] : '';
54
if ( ! empty( $map\['display\_uri\_table'\] ) ) {
55
$updated\_slugs\_count = ( isset( $output\['updated\_count'\] ) && $output\['updated\_count'\] > 0 ) ? $output\['updated\_count'\] : false;
56
$updated\_slugs\_array = ( $updated\_slugs\_count ) ? $output\['updated'\] : '';
56
57
}
57
58
…
…
62
63
63
64
// 4. Display the slugs table (and append the globals)
64
if(isset($updated\_slugs\_count)) {
65
$permalink\_manager\_after\_sections\_html .= Permalink\_Manager\_Admin\_Functions::display\_updated\_slugs($updated\_slugs\_array);
66
}
67
}
68
69
/\*\*
70
\* Save settings
71
\*/
72
public static function save\_settings($field = false, $value = false, $display\_alert = true) {
73
global $permalink\_manager\_options, $permalink\_manager\_before\_sections\_html;
74
75
// Info: The settings array is used also by "Screen Options"
76
$new\_options = $permalink\_manager\_options;
77
//$new\_options = array();
78
79
// Save only selected field/sections
80
if($field && $value) {
81
$new\_options\[$field\] = $value;
82
} else {
83
$post\_fields = $\_POST;
84
85
foreach($post\_fields as $option\_name => $option\_value) {
86
$new\_options\[$option\_name\] = $option\_value;
87
}
88
}
89
90
// Allow only white-listed option groups
91
foreach($new\_options as $group => $group\_options) {
92
if(!in\_array($group, array('licence', 'screen-options', 'general', 'permastructure-settings', 'stop-words'))) {
93
unset($new\_options\[$group\]);
94
}
95
}
96
97
// Sanitize & override the global with new settings
98
$new\_options = Permalink\_Manager\_Helper\_Functions::sanitize\_array($new\_options);
99
$permalink\_manager\_options = $new\_options = array\_filter($new\_options);
100
101
// Save the settings in database
102
update\_option('permalink-manager', $new\_options);
103
104
// Display the message
105
$permalink\_manager\_before\_sections\_html .= ($display\_alert) ? Permalink\_Manager\_Admin\_Functions::get\_alert\_message(\_\_( 'The settings are saved!', 'permalink-manager' ), 'updated') : "";
106
}
107
108
/\*\*
109
\* Trigger bulk tools via AJAX
110
\*/
111
function ajax\_bulk\_tools() {
112
global $sitepress, $wp\_filter, $wpdb;
113
114
// Define variables
115
$return = array('alert' => Permalink\_Manager\_Admin\_Functions::get\_alert\_message(\_\_( '<strong>No slugs</strong> were updated!', 'permalink-manager' ), 'error updated\_slugs'));
116
117
// Get the name of the function
118
if(isset($\_POST\['regenerate'\]) && wp\_verify\_nonce($\_POST\['regenerate'\], 'permalink-manager')) {
119
$function\_name = 'regenerate\_all\_permalinks';
120
$uniq\_id = $\_POST\['pm\_session\_id'\];
121
} else if(isset($\_POST\['find\_and\_replace'\]) && wp\_verify\_nonce($\_POST\['find\_and\_replace'\], 'permalink-manager') && !empty($\_POST\['old\_string'\]) && !empty($\_POST\['new\_string'\])) {
122
$function\_name = 'find\_and\_replace';
123
$uniq\_id = $\_POST\['pm\_session\_id'\];
124
}
125
126
// Get content type & post statuses
127
if(!empty($\_POST\['content\_type'\]) && $\_POST\['content\_type'\] == 'taxonomies') {
128
$content\_type = 'taxonomies';
129
130
if(empty($\_POST\['taxonomies'\])) {
131
$error = true;
132
$return = array('alert' => Permalink\_Manager\_Admin\_Functions::get\_alert\_message(\_\_( '<strong>No taxonomy</strong> selected!', 'permalink-manager' ), 'error updated\_slugs'));
133
}
134
} else {
135
$content\_type = 'post\_types';
136
137
// Check if any post type was selected
138
if(empty($\_POST\['post\_types'\])) {
139
$error = true;
140
$return = array('alert' => Permalink\_Manager\_Admin\_Functions::get\_alert\_message(\_\_( '<strong>No post type</strong> selected!', 'permalink-manager' ), 'error updated\_slugs'));
141
}
142
143
// Check post status
144
if(empty($\_POST\['post\_statuses'\])) {
145
$error = true;
146
$return = array('alert' => Permalink\_Manager\_Admin\_Functions::get\_alert\_message(\_\_( '<strong>No post status</strong> selected!', 'permalink-manager' ), 'error updated\_slugs'));
147
}
148
}
149
150
// Check if both strings are set for "Find and replace" tool
151
if(!empty($function\_name) && !empty($content\_type) && empty($error)) {
152
153
// Hotfix for WPML (start)
154
if($sitepress) {
155
remove\_filter('get\_terms\_args', array($sitepress, 'get\_terms\_args\_filter'), 10);
156
remove\_filter('get\_term', array($sitepress, 'get\_term\_adjust\_id'), 1);
157
remove\_filter('terms\_clauses', array($sitepress, 'terms\_clauses'), 10);
158
remove\_filter('get\_pages', array($sitepress, 'get\_pages\_adjust\_ids'), 1);
159
}
160
161
// Get the mode
162
$mode = isset($\_POST\['mode'\]) ? $\_POST\['mode'\] : 'custom\_uris';
163
164
// Get the content type
165
if($content\_type == 'taxonomies') {
166
$class\_name = 'Permalink\_Manager\_URI\_Functions\_Tax';
167
} else {
168
$class\_name = 'Permalink\_Manager\_URI\_Functions\_Post';
169
}
170
171
// Get items (try to get them from transient)
172
$items = get\_transient("pm\_{$uniq\_id}");
173
$progress = get\_transient("pm\_{$uniq\_id}\_progress");
174
175
$first\_chunk = true;
176
$chunk\_size = apply\_filters('permalink\_manager\_chunk\_size', 50);
177
178
if(empty($items)) {
179
$items = $class\_name::get\_items();
180
181
if(!empty($items)) {
182
// Set stats (to display the progress)
183
$total = count($items);
184
185
// Split items array into chunks and save them to transient
186
$items = array\_chunk($items, $chunk\_size);
187
188
set\_transient("pm\_{$uniq\_id}\_progress", 0, 300);
189
set\_transient("pm\_{$uniq\_id}", $items, 300);
190
191
// Check for MySQL errors
192
if(!empty($wpdb->last\_error)) {
193
printf('%s (%sMB)', $wpdb->last\_error, strlen(serialize($items)) / 1000000);
194
http\_response\_code(500);
195
die();
196
}
197
}
198
}
199
200
// Get homepage URL and ensure that it ends with slash
201
$home\_url = Permalink\_Manager\_Helper\_Functions::get\_permalink\_base() . "/";
202
203
// Process the variables from $\_POST object
204
$old\_string = (!empty($\_POST\['old\_string'\])) ? str\_replace($home\_url, '', esc\_sql($\_POST\['old\_string'\])) : '';
205
$new\_string = (!empty($\_POST\['old\_string'\])) ? str\_replace($home\_url, '', esc\_sql($\_POST\['new\_string'\])) : '';
206
207
// Process only one subarray
208
if(!empty($items\[0\])) {
209
$chunk = array\_shift($items);
210
set\_transient("pm\_{$uniq\_id}", $items, 300);
211
212
// Check if posts or terms should be updated
213
if($function\_name == 'find\_and\_replace') {
214
$output = $class\_name::find\_and\_replace($chunk, $mode, $old\_string, $new\_string);
215
} else {
216
$output = $class\_name::regenerate\_all\_permalinks($chunk, $mode);
217
}
218
219
if(!empty($output\['updated\_count'\])) {
220
$return = array\_merge($return, (array) Permalink\_Manager\_Admin\_Functions::display\_updated\_slugs($output\['updated'\], true, $first\_chunk));
221
$return\['updated\_count'\] = $output\['updated\_count'\];
222
}
223
224
// Send total number of processed items with a first chunk
225
if(!empty($total)) {
226
$return\['total'\] = $total;
227
}
228
229
// Check if there are any chunks left
230
if(count($items) > 0) {
231
// Update progress
232
$progress += $chunk\_size;
233
set\_transient("pm\_{$uniq\_id}\_progress", $progress, 300);
234
235
$return\['left\_chunks'\] = true;
236
$return\['progress'\] = $progress;
237
} else {
238
delete\_transient("pm\_{$uniq\_id}");
239
delete\_transient("pm\_{$uniq\_id}\_progress");
240
}
241
}
242
243
// Hotfix for WPML (end)
244
if($sitepress) {
245
add\_filter('terms\_clauses', array($sitepress, 'terms\_clauses'), 10, 4);
246
add\_filter('get\_term', array($sitepress, 'get\_term\_adjust\_id'), 1, 1);
247
add\_filter('get\_terms\_args', array($sitepress, 'get\_terms\_args\_filter'), 10, 2);
248
add\_filter('get\_pages', array($sitepress, 'get\_pages\_adjust\_ids'), 1, 2);
249
}
250
}
251
252
wp\_send\_json($return);
253
die();
254
}
255
256
/\*\*
257
\* Save permalink via AJAX
258
\*/
259
public function ajax\_save\_permalink() {
260
$element\_id = (!empty($\_POST\['permalink-manager-edit-uri-element-id'\])) ? sanitize\_text\_field($\_POST\['permalink-manager-edit-uri-element-id'\]) : '';
261
262
if(!empty($element\_id) && is\_numeric($element\_id)) {
263
Permalink\_Manager\_URI\_Functions\_Post::update\_post\_uri($element\_id);
264
265
// Reload URI Editor & clean post cache
266
clean\_post\_cache($element\_id);
267
die();
268
}
269
}
270
271
/\*\*
272
\* Update all permalinks in "Permalink Editor"
273
\*/
274
function update\_all\_permalinks() {
275
// Check if posts or terms should be updated
276
if(!empty($\_POST\['content\_type'\]) && $\_POST\['content\_type'\] == 'taxonomies') {
277
return Permalink\_Manager\_URI\_Functions\_Tax::update\_all\_permalinks();
278
} else {
279
return Permalink\_Manager\_URI\_Functions\_Post::update\_all\_permalinks();
280
}
281
}
282
283
/\*\*
284
\* Additional actions
65
if ( isset( $updated\_slugs\_count ) && isset( $updated\_slugs\_array ) ) {
66
$permalink\_manager\_after\_sections\_html .= Permalink\_Manager\_Admin\_Functions::display\_updated\_slugs( $updated\_slugs\_array );
67
}
68
}
69
70
/\*\*
71
\* Route the requests to the additional tools-related functions with the relevant callbacks
285
72
\*/
286
73
public static function extra\_actions() {
287
74
global $permalink\_manager\_before\_sections\_html;
288
75
289
if(current\_user\_can('manage\_options') && !empty($\_GET\['\_wpnonce'\])) {
76
if ( current\_user\_can( 'manage\_options' ) && ! empty( $\_GET\['permalink-manager-nonce'\] ) ) {
290
77
// Check if the nonce field is correct
291
$nonce = sanitize\_key($\_GET\['\_wpnonce'\]);
292
293
if(!wp\_verify\_nonce($nonce, 'permalink-manager')) {
294
$permalink\_manager\_before\_sections\_html = Permalink\_Manager\_Admin\_Functions::get\_alert\_message(\_\_( 'You are not allowed to remove Permalink Manager data!', 'permalink-manager' ), 'error updated\_slugs');
78
$nonce = sanitize\_key( $\_GET\['permalink-manager-nonce'\] );
79
80
if ( ! wp\_verify\_nonce( $nonce, 'permalink-manager' ) ) {
81
$permalink\_manager\_before\_sections\_html = Permalink\_Manager\_Admin\_Functions::get\_alert\_message( \_\_( 'You are not allowed to remove Permalink Manager data!', 'permalink-manager' ), 'error updated\_slugs' );
82
295
83
return;
296
84
}
297
85
298
if(isset($\_GET\['clear-permalink-manager-uris'\])) {
86
if ( isset( $\_GET\['clear-permalink-manager-uris'\] ) ) {
299
87
self::clear\_all\_uris();
300
} else if(isset($\_GET\['remove-permalink-manager-settings'\])) {
301
$option\_name = sanitize\_text\_field($\_GET\['remove-permalink-manager-settings'\]);
302
self::remove\_plugin\_data($option\_name);
303
} else if(!empty($\_REQUEST\['remove-uri'\])) {
304
$uri\_key = sanitize\_text\_field($\_REQUEST\['remove-uri'\]);
305
self::force\_clear\_single\_element\_uris\_and\_redirects($uri\_key);
306
} else if(!empty($\_REQUEST\['remove-redirect'\])) {
307
$redirect\_key = sanitize\_text\_field($\_REQUEST\['remove-redirect'\]);
308
self::force\_clear\_single\_redirect($redirect\_key);
309
}
310
} else if(!empty($\_POST\['screen-options-apply'\])) {
88
} else if ( isset( $\_GET\['remove-permalink-manager-settings'\] ) ) {
89
$option\_name = sanitize\_text\_field( $\_GET\['remove-permalink-manager-settings'\] );
90
self::remove\_plugin\_data( $option\_name );
91
} else if ( ! empty( $\_REQUEST\['remove-uri'\] ) ) {
92
$uri\_key = sanitize\_text\_field( $\_REQUEST\['remove-uri'\] );
93
self::force\_clear\_single\_element\_uris\_and\_redirects( $uri\_key );
94
} else if ( ! empty( $\_REQUEST\['remove-redirect'\] ) ) {
95
$redirect\_key = sanitize\_text\_field( $\_REQUEST\['remove-redirect'\] );
96
self::force\_clear\_single\_redirect( $redirect\_key );
97
}
98
} else if ( ! empty( $\_POST\['screen-options-apply'\] ) ) {
311
99
self::save\_screen\_options();
312
100
}
…
…
314
102
315
103
/\*\*
316
\* Save "Screen Options"
317
\*/
318
public static function save\_screen\_options() {
319
check\_admin\_referer('screen-options-nonce', 'screenoptionnonce');
320
321
// The values will be sanitized inside the function
322
self::save\_settings('screen-options', $\_POST\['screen-options'\]);
323
}
324
325
/\*\*
326
\* Save permastructures
327
\*/
328
public static function save\_permastructures() {
329
global $permalink\_manager\_permastructs;
330
331
$post\_fields = $\_POST;
332
$permastructure\_options = $permastructures = array();
333
$permastructure\_types = array('post\_types', 'taxonomies');
334
335
// Split permastructures & sanitize them
336
foreach($permastructure\_types as $type) {
337
if(empty($\_POST\[$type\]) || !is\_array($\_POST\[$type\])) { continue; }
338
339
$permastructures\[$type\] = $\_POST\[$type\];
340
341
foreach($permastructures\[$type\] as &$single\_permastructure) {
342
$single\_permastructure = Permalink\_Manager\_Helper\_Functions::sanitize\_title($single\_permastructure, true, false, false);
343
$single\_permastructure = trim($single\_permastructure, '\\/ ');
344
}
345
}
346
347
if(!empty($\_POST\['permastructure-settings'\])) {
348
$permastructure\_options = $\_POST\['permastructure-settings'\];
349
}
350
351
// A. Permastructures
352
if(!empty($permastructures\['post\_types'\]) || !empty($permastructures\['taxonomies'\])) {
353
// Override the global with settings
354
$permalink\_manager\_permastructs = $permastructures;
355
356
// Save the settings in database
357
update\_option('permalink-manager-permastructs', $permastructures);
358
}
359
360
// B. Permastructure settings
361
if(!empty($permastructure\_options)) {
362
self::save\_settings('permastructure-settings', $permastructure\_options);
363
}
364
}
365
366
/\*\*
367
\* Clear URIs
104
\* Bulk remove obsolete custom permalinks and redirects
368
105
\*/
369
106
public static function clear\_all\_uris() {
370
global $permalink\_manager\_uris, $permalink\_manager\_redirects, $wpdb, $permalink\_manager\_before\_sections\_html;
107
global $permalink\_manager\_uris, $permalink\_manager\_redirects, $permalink\_manager\_before\_sections\_html;
371
108
372
109
// Check if array with custom URIs exists
373
if(empty($permalink\_manager\_uris)) { return; }
110
if ( empty( $permalink\_manager\_uris ) ) {
111
return;
112
}
374
113
375
114
// Count removed URIs & redirects
376
$removed\_uris \= 0;
115
$removed\_uris \= 0;
377
116
$removed\_redirects = 0;
378
117
379
118
// Get all element IDs
380
$element\_ids = array\_merge(array\_keys((array) $permalink\_manager\_uris), array\_keys((array) $permalink\_manager\_redirects));
119
$element\_ids = array\_merge( array\_keys( (array) $permalink\_manager\_uris ), array\_keys( (array) $permalink\_manager\_redirects ) );
381
120
382
121
// 1. Remove unused custom URI & redirects for deleted post or term
383
foreach($element\_ids as $element\_id) {
384
$count = self::clear\_single\_element\_uris\_and\_redirects($element\_id, true);
385
386
$removed\_uris \= (!empty($count\[0\])) ? $count\[0\] + $removed\_uris : $removed\_uris;
387
$removed\_redirects = (!empty($count\[1\])) ? $count\[1\] + $removed\_redirects : $removed\_redirects;
122
foreach ( $element\_ids as $element\_id ) {
123
$count = self::clear\_single\_element\_uris\_and\_redirects( $element\_id, true );
124
125
$removed\_uris = ( ! empty( $count\[0\] ) ) ? $count\[0\] + $removed\_uris : $removed\_uris;
126
$removed\_redirects = ( ! empty( $count\[1\] ) ) ? $count\[1\] + $removed\_redirects : $removed\_redirects;
388
127
}
389
128
390
129
// 2. Keep only a single redirect (make it unique)
391
$removed\_redirects += self::clear\_redirects\_array(true);
130
$removed\_redirects += self::clear\_redirects\_array();
392
131
393
132
// 3. Optional method to keep the permalinks unique
394
if(apply\_filters('permalink\_manager\_fix\_uri\_duplicates', false) == true) {
133
if ( apply\_filters( 'permalink\_manager\_fix\_uri\_duplicates', false ) ) {
395
134
self::fix\_uri\_duplicates();
396
135
}
…
…
402
141
403
142
// Save cleared URIs & Redirects
404
if($removed\_uris > 0 || $removed\_redirects > 0) {
405
update\_option('permalink-manager-uris', array\_filter($permalink\_manager\_uris));
406
update\_option('permalink-manager-redirects', array\_filter($permalink\_manager\_redirects));
407
408
$permalink\_manager\_before\_sections\_html .= Permalink\_Manager\_Admin\_Functions::get\_alert\_message(sprintf(\_\_( '%d Custom URIs and %d Custom Redirects were removed!', 'permalink-manager' ), $removed\_uris, $removed\_redirects), 'updated updated\_slugs');
143
if ( $removed\_uris > 0 || $removed\_redirects > 0 ) {
144
update\_option( 'permalink-manager-uris', array\_filter( $permalink\_manager\_uris ) );
145
update\_option( 'permalink-manager-redirects', array\_filter( $permalink\_manager\_redirects ) );
146
147
$permalink\_manager\_before\_sections\_html .= Permalink\_Manager\_Admin\_Functions::get\_alert\_message( sprintf( \_\_( '%d Custom URIs and %d Custom Redirects were removed!', 'permalink-manager' ), $removed\_uris, $removed\_redirects ), 'updated updated\_slugs' );
409
148
} else {
410
$permalink\_manager\_before\_sections\_html .= Permalink\_Manager\_Admin\_Functions::get\_alert\_message(\_\_( 'No Custom URIs or Custom Redirects were removed!', 'permalink-manager' ), 'error updated\_slugs');
411
}
412
}
413
414
/\*\*
415
\* Remove plugin data
416
\*/
417
public static function remove\_plugin\_data($field\_name) {
149
$permalink\_manager\_before\_sections\_html .= Permalink\_Manager\_Admin\_Functions::get\_alert\_message( \_\_( 'No Custom URIs or Custom Redirects were removed!', 'permalink-manager' ), 'error updated\_slugs' );
150
}
151
}
152
153
/\*\*
154
\* Remove obsolete custom permalink & redirects for specific post or term
155
\*
156
\* @param string|int $element\_id
157
\* @param bool $count\_removed
158
\*
159
\* @return array
160
\*/
161
public static function clear\_single\_element\_uris\_and\_redirects( $element\_id, $count\_removed = false ) {
162
global $wpdb, $permalink\_manager\_uris, $permalink\_manager\_redirects;
163
164
// Count removed URIs & redirects
165
$removed\_uris = 0;
166
$removed\_redirects = 0;
167
168
// Only admin users can remove the broken URIs for removed post types & taxonomies
169
$check\_if\_admin = is\_admin();
170
171
// 1. Check if element exists
172
if ( strpos( $element\_id, 'tax-' ) !== false ) {
173
$term\_id = preg\_replace( "/\[^0-9\]/", "", $element\_id );
174
$term\_info = $wpdb->get\_row( $wpdb->prepare( "SELECT taxonomy, meta\_value FROM {$wpdb->term\_taxonomy} AS t LEFT JOIN {$wpdb->termmeta} AS tm ON tm.term\_id = t.term\_id AND tm.meta\_key = 'auto\_update\_uri' WHERE t.term\_id = %d", $term\_id ) );
175
176
// Custom URIs for disabled taxonomies may only be deleted via the admin dashboard, although they will always be removed if the term no longer exists in the database
177
$remove = ( ! empty( $term\_info->taxonomy ) ) ? Permalink\_Manager\_Helper\_Functions::is\_taxonomy\_disabled( $term\_info->taxonomy, $check\_if\_admin ) : true;
178
179
// Remove custom URIs for URIs disabled in URI Editor
180
$remove = ( ! empty( $term\_info->meta\_value ) && $term\_info->meta\_value == 2 ) ? true : $remove;
181
182
} else if ( is\_numeric( $element\_id ) ) {
183
$post\_info = $wpdb->get\_row( $wpdb->prepare( "SELECT post\_type, meta\_value FROM {$wpdb->posts} AS p LEFT JOIN {$wpdb->postmeta} AS pm ON pm.post\_ID = p.ID AND pm.meta\_key = 'auto\_update\_uri' WHERE ID = %d AND post\_status NOT IN ('auto-draft', 'trash') AND post\_type != 'nav\_menu\_item'", $element\_id ) );
184
185
// Custom URIs for disabled post types may only be deleted via the admin dashboard, although they will always be removed if the post no longer exists in the database
186
$remove = ( ! empty( $post\_info->post\_type ) ) ? Permalink\_Manager\_Helper\_Functions::is\_post\_type\_disabled( $post\_info->post\_type, $check\_if\_admin ) : true;
187
188
// Remove custom URIs for URIs disabled in URI Editor
189
$remove = ( ! empty( $post\_info->meta\_value ) && $post\_info->meta\_value == 2 ) ? true : $remove;
190
191
// Remove custom URIs for attachments redirected with Yoast's SEO Premium
192
$yoast\_permalink\_options = ( class\_exists( 'WPSEO\_Premium' ) ) ? get\_option( 'wpseo\_permalinks' ) : array();
193
194
if ( ! empty( $yoast\_permalink\_options\['redirectattachment'\] ) && $post\_info->post\_type == 'attachment' ) {
195
$attachment\_parent = $wpdb->get\_var( "SELECT post\_parent FROM {$wpdb->prefix}posts WHERE ID = {$element\_id} AND post\_type = 'attachment'" );
196
if ( ! empty( $attachment\_parent ) ) {
197
$remove = true;
198
}
199
}
200
}
201
202
// 2A. Remove ALL unused custom permalinks & redirects
203
if ( ! empty( $remove ) ) {
204
// Remove URI
205
if ( ! empty( $permalink\_manager\_uris\[ $element\_id \] ) ) {
206
$removed\_uris = 1;
207
unset( $permalink\_manager\_uris\[ $element\_id \] );
208
}
209
210
// Remove all custom redirects
211
if ( ! empty( $permalink\_manager\_redirects\[ $element\_id \] ) && is\_array( $permalink\_manager\_redirects\[ $element\_id \] ) ) {
212
$removed\_redirects = count( $permalink\_manager\_redirects\[ $element\_id \] );
213
unset( $permalink\_manager\_redirects\[ $element\_id \] );
214
}
215
} // 2B. Check if the post/term uses the same URI for both permalink & custom redirects
216
else {
217
$removed\_redirect = self::clear\_single\_element\_duplicated\_redirect( $element\_id, false );
218
$removed\_redirects = ( ! empty( $removed\_redirect ) ) ? 1 : 0;
219
}
220
221
// Check if function should only return the counts or update
222
if ( $count\_removed ) {
223
return array( $removed\_uris, $removed\_redirects );
224
} else if ( ! empty( $removed\_uris ) || ! empty( $removed\_redirects ) ) {
225
update\_option( 'permalink-manager-uris', array\_filter( $permalink\_manager\_uris ) );
226
update\_option( 'permalink-manager-redirects', array\_filter( $permalink\_manager\_redirects ) );
227
}
228
229
return array();
230
}
231
232
/\*\*
233
\* Remove the duplicated custom redirect if the post/term has the same URI for both custom permalink and custom redirect
234
\*
235
\* @param string|int $element\_id
236
\* @param bool $save\_redirects
237
\* @param string $uri
238
\*
239
\* @return int
240
\*/
241
public static function clear\_single\_element\_duplicated\_redirect( $element\_id, $save\_redirects = true, $uri = null ) {
242
global $permalink\_manager\_uris, $permalink\_manager\_redirects;
243
244
$custom\_uri = ( empty( $uri ) && ! empty( $permalink\_manager\_uris\[ $element\_id \] ) ) ? $permalink\_manager\_uris\[ $element\_id \] : $uri;
245
246
if ( $custom\_uri && ! empty( $permalink\_manager\_redirects\[ $element\_id \] ) && in\_array( $custom\_uri, $permalink\_manager\_redirects\[ $element\_id \] ) ) {
247
$duplicated\_redirect\_id = array\_search( $custom\_uri, $permalink\_manager\_redirects\[ $element\_id \] );
248
unset( $permalink\_manager\_redirects\[ $element\_id \]\[ $duplicated\_redirect\_id \] );
249
}
250
251
// Update the redirects array in the database if the duplicated redirect was unset
252
if ( isset( $duplicated\_redirect\_id ) && $save\_redirects ) {
253
update\_option( 'permalink-manager-redirects', array\_filter( $permalink\_manager\_redirects ) );
254
}
255
256
return ( isset( $duplicated\_redirect\_id ) ) ? 1 : 0;
257
}
258
259
/\*\*
260
\* Remove the duplicated if the same URI is used for multiple custom redirects and return the removed redirects count
261
\*
262
\* @param bool $save\_redirects
263
\*
264
\* @return int
265
\*/
266
public static function clear\_redirects\_array( $save\_redirects = false ) {
267
global $permalink\_manager\_redirects;
268
269
$removed\_redirects = 0;
270
271
$all\_redirect\_duplicates = Permalink\_Manager\_Helper\_Functions::get\_all\_duplicates();
272
273
foreach ( $all\_redirect\_duplicates as $single\_redirect\_duplicate ) {
274
$last\_element = reset( $single\_redirect\_duplicate );
275
276
foreach ( $single\_redirect\_duplicate as $redirect\_key ) {
277
// Keep a single redirect
278
if ( $last\_element == $redirect\_key ) {
279
continue;
280
}
281
preg\_match( "/redirect-(\\d+)\_(tax-\\d+|\\d+)/", $redirect\_key, $ids );
282
283
if ( ! empty( $ids\[2\] ) && ! empty( $permalink\_manager\_redirects\[ $ids\[2\] \]\[ $ids\[1\] \] ) ) {
284
$removed\_redirects ++;
285
unset( $permalink\_manager\_redirects\[ $ids\[2\] \]\[ $ids\[1\] \] );
286
}
287
}
288
}
289
290
// Update the redirects array in the database if the duplicated redirect was unset
291
if ( isset( $duplicated\_redirect\_id ) && $save\_redirects ) {
292
update\_option( 'permalink-manager-redirects', array\_filter( $permalink\_manager\_redirects ) );
293
}
294
295
return $removed\_redirects;
296
}
297
298
/\*\*
299
\* If the custom permalink is duplicated, append the index (-2, -3, etc.)
300
\*/
301
public static function fix\_uri\_duplicates() {
302
global $permalink\_manager\_uris;
303
304
$duplicates = array\_count\_values( $permalink\_manager\_uris );
305
306
foreach ( $duplicates as $uri => $count ) {
307
if ( $count == 1 ) {
308
continue;
309
}
310
311
$ids = array\_keys( $permalink\_manager\_uris, $uri );
312
foreach ( $ids as $index => $id ) {
313
if ( $index > 0 ) {
314
$permalink\_manager\_uris\[ $id \] = preg\_replace( '/(.+?)(\\.\[^.\]+$|$)/', '$1-' . $index . '$2', $uri );
315
}
316
}
317
}
318
319
update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
320
}
321
322
/\*\*
323
\* Remove custom permalinks & custom redirects for requested post or term
324
\*
325
\* @param $uri\_key
326
\*
327
\* @return bool
328
\*/
329
public static function force\_clear\_single\_element\_uris\_and\_redirects( $uri\_key ) {
330
global $permalink\_manager\_uris, $permalink\_manager\_redirects, $permalink\_manager\_before\_sections\_html;
331
332
// Check if custom URI is set
333
if ( isset( $permalink\_manager\_uris\[ $uri\_key \] ) ) {
334
$uri = $permalink\_manager\_uris\[ $uri\_key \];
335
336
unset( $permalink\_manager\_uris\[ $uri\_key \] );
337
update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
338
339
$updated = Permalink\_Manager\_Admin\_Functions::get\_alert\_message( sprintf( \_\_( 'URI "%s" was removed successfully!', 'permalink-manager' ), $uri ), 'updated' );
340
}
341
342
// Check if custom redirects are set
343
if ( isset( $permalink\_manager\_redirects\[ $uri\_key \] ) ) {
344
unset( $permalink\_manager\_redirects\[ $uri\_key \] );
345
update\_option( 'permalink-manager-redirects', $permalink\_manager\_redirects );
346
347
$updated = Permalink\_Manager\_Admin\_Functions::get\_alert\_message( \_\_( 'Broken redirects were removed successfully!', 'permalink-manager' ), 'updated' );
348
}
349
350
if ( empty( $updated ) ) {
351
$permalink\_manager\_before\_sections\_html .= Permalink\_Manager\_Admin\_Functions::get\_alert\_message( \_\_( 'URI and/or custom redirects does not exist or were already removed!', 'permalink-manager' ), 'error' );
352
} else {
353
// Display the alert in admin panel
354
if ( ! empty( $permalink\_manager\_before\_sections\_html ) && is\_admin() ) {
355
$permalink\_manager\_before\_sections\_html .= $updated;
356
}
357
}
358
359
return true;
360
}
361
362
/\*\*
363
\* Remove only custom redirects for requested post or term
364
\*
365
\* @param string $redirect\_key
366
\*/
367
public static function force\_clear\_single\_redirect( $redirect\_key ) {
368
global $permalink\_manager\_redirects, $permalink\_manager\_before\_sections\_html;
369
370
preg\_match( "/redirect-(\\d+)\_(tax-\\d+|\\d+)/", $redirect\_key, $ids );
371
372
if ( ! empty( $permalink\_manager\_redirects\[ $ids\[2\] \]\[ $ids\[1\] \] ) ) {
373
unset( $permalink\_manager\_redirects\[ $ids\[2\] \]\[ $ids\[1\] \] );
374
375
update\_option( 'permalink-manager-redirects', array\_filter( $permalink\_manager\_redirects ) );
376
377
$permalink\_manager\_before\_sections\_html = Permalink\_Manager\_Admin\_Functions::get\_alert\_message( \_\_( 'The redirect was removed successfully!', 'permalink-manager' ), 'updated' );
378
}
379
}
380
381
/\*\*
382
\* Save "Screen Options"
383
\*/
384
public static function save\_screen\_options() {
385
check\_admin\_referer( 'screen-options-nonce', 'screenoptionnonce' );
386
387
// The values will be sanitized inside the function
388
self::save\_settings( 'screen-options', $\_POST\['screen-options'\] );
389
}
390
391
/\*\*
392
\* Save the plugin settings
393
\*
394
\* @param bool $field
395
\* @param bool $value
396
\* @param bool $display\_alert
397
\*/
398
public static function save\_settings( $field = false, $value = false, $display\_alert = true ) {
399
global $permalink\_manager\_options, $permalink\_manager\_before\_sections\_html;
400
401
// Info: The settings array is used also by "Screen Options"
402
$new\_options = $permalink\_manager\_options;
403
//$new\_options = array();
404
405
// Save only selected field/sections
406
if ( $field && $value ) {
407
$new\_options\[ $field \] = $value;
408
} else {
409
$post\_fields = $\_POST;
410
411
foreach ( $post\_fields as $option\_name => $option\_value ) {
412
$new\_options\[ $option\_name \] = $option\_value;
413
}
414
}
415
416
// Allow only white-listed option groups
417
foreach ( $new\_options as $group => $group\_options ) {
418
if ( ! in\_array( $group, array( 'licence', 'screen-options', 'general', 'permastructure-settings', 'stop-words' ) ) ) {
419
unset( $new\_options\[ $group \] );
420
}
421
}
422
423
// Sanitize & override the global with new settings
424
$new\_options = Permalink\_Manager\_Helper\_Functions::sanitize\_array( $new\_options );
425
$permalink\_manager\_options = $new\_options = array\_filter( $new\_options );
426
427
// Save the settings in database
428
update\_option( 'permalink-manager', $new\_options );
429
430
// Display the message
431
$permalink\_manager\_before\_sections\_html .= ( $display\_alert ) ? Permalink\_Manager\_Admin\_Functions::get\_alert\_message( \_\_( 'The settings are saved!', 'permalink-manager' ), 'updated' ) : "";
432
}
433
434
/\*\*
435
\* Save the permastructures
436
\*/
437
public static function save\_permastructures() {
438
global $permalink\_manager\_permastructs;
439
440
$permastructure\_options = $permastructures = array();
441
$permastructure\_types = array( 'post\_types', 'taxonomies' );
442
443
// Split permastructures & sanitize them
444
foreach ( $permastructure\_types as $type ) {
445
if ( empty( $\_POST\[ $type \] ) || ! is\_array( $\_POST\[ $type \] ) ) {
446
continue;
447
}
448
449
$permastructures\[ $type \] = $\_POST\[ $type \];
450
451
foreach ( $permastructures\[ $type \] as &$single\_permastructure ) {
452
$single\_permastructure = Permalink\_Manager\_Helper\_Functions::sanitize\_title( $single\_permastructure, true, false, false );
453
$single\_permastructure = trim( $single\_permastructure, '\\/ ' );
454
}
455
}
456
457
if ( ! empty( $\_POST\['permastructure-settings'\] ) ) {
458
$permastructure\_options = $\_POST\['permastructure-settings'\];
459
}
460
461
// A. Permastructures
462
if ( ! empty( $permastructures\['post\_types'\] ) || ! empty( $permastructures\['taxonomies'\] ) ) {
463
// Override the global with settings
464
$permalink\_manager\_permastructs = $permastructures;
465
466
// Save the settings in database
467
update\_option( 'permalink-manager-permastructs', $permastructures );
468
}
469
470
// B. Permastructure settings
471
if ( ! empty( $permastructure\_options ) ) {
472
self::save\_settings( 'permastructure-settings', $permastructure\_options );
473
}
474
}
475
476
/\*\*
477
\* Update all permalinks in "Bulk URI Editor"
478
\*/
479
function update\_all\_permalinks() {
480
// Check if posts or terms should be updated
481
if ( ! empty( $\_POST\['content\_type'\] ) && $\_POST\['content\_type'\] == 'taxonomies' ) {
482
return Permalink\_Manager\_URI\_Functions\_Tax::update\_all\_permalinks();
483
} else {
484
return Permalink\_Manager\_URI\_Functions\_Post::update\_all\_permalinks();
485
}
486
}
487
488
/\*\*
489
\* Remove a specific section of the plugin data stored in the database
490
\*
491
\* @param $field\_name
492
\*/
493
public static function remove\_plugin\_data( $field\_name ) {
418
494
global $permalink\_manager, $permalink\_manager\_before\_sections\_html;
419
495
420
496
// Make sure that the user is allowed to remove the plugin data
421
if(!current\_user\_can('manage\_options')) {
422
$permalink\_manager\_before\_sections\_html .= Permalink\_Manager\_Admin\_Functions::get\_alert\_message(\_\_( 'You are not allowed to remove Permalink Manager data!', 'permalink-manager' ), 'error updated\_slugs');
423
}
424
425
switch($field\_name) {
497
if ( ! current\_user\_can( 'manage\_options' ) ) {
498
$permalink\_manager\_before\_sections\_html .= Permalink\_Manager\_Admin\_Functions::get\_alert\_message( \_\_( 'You are not allowed to remove Permalink Manager data!', 'permalink-manager' ), 'error updated\_slugs' );
499
}
500
501
switch ( $field\_name ) {
426
502
case 'uris' :
427
503
$option\_name = 'permalink-manager-uris';
428
$alert \= \_\_('Custom permalinks', 'permalink-manager');
504
$alert = \_\_( 'Custom permalinks', 'permalink-manager' );
429
505
break;
430
506
case 'redirects' :
431
507
$option\_name = 'permalink-manager-redirects';
432
$alert \= \_\_('Custom redirects', 'permalink-manager');
508
$alert = \_\_( 'Custom redirects', 'permalink-manager' );
433
509
break;
434
510
case 'external-redirects' :
435
511
$option\_name = 'permalink-manager-external-redirects';
436
$alert \= \_\_('External redirects', 'permalink-manager');
512
$alert = \_\_( 'External redirects', 'permalink-manager' );
437
513
break;
438
514
case 'permastructs' :
439
515
$option\_name = 'permalink-manager-permastructs';
440
$alert \= \_\_('Permastructure settings', 'permalink-manager');
516
$alert = \_\_( 'Permastructure settings', 'permalink-manager' );
441
517
break;
442
518
case 'settings' :
443
519
$option\_name = 'permalink-manager';
444
$alert \= \_\_('Permastructure settings', 'permalink-manager');
520
$alert = \_\_( 'Permastructure settings', 'permalink-manager' );
445
521
break;
446
}
447
448
if(!empty($option\_name)) {
522
default :
523
$alert = '';
524
}
525
526
if ( ! empty( $option\_name ) ) {
449
527
// Remove the option from DB
450
delete\_option($option\_name);
528
delete\_option( $option\_name );
451
529
452
530
// Reload globals
453
531
$permalink\_manager->get\_options\_and\_globals();
454
532
455
$alert\_message = sprintf(\_\_('%s were removed!', 'permalink-manager'), $alert);
456
$permalink\_manager\_before\_sections\_html .= Permalink\_Manager\_Admin\_Functions::get\_alert\_message($alert\_message, 'updated updated\_slugs');
457
}
458
}
459
460
/\*\*
461
\* Check if the post/term uses the same URI for both permalink & custom redirects
462
\*/
463
public static function clear\_single\_element\_duplicated\_redirect($element\_id, $count\_removed = false, $uri = null) {
464
global $permalink\_manager\_uris, $permalink\_manager\_redirects;
465
466
$custom\_uri = (empty($uri) && !empty($permalink\_manager\_uris\[$element\_id\])) ? $permalink\_manager\_uris\[$element\_id\] : $uri;
467
468
if($custom\_uri && !empty($permalink\_manager\_redirects\[$element\_id\]) && in\_array($custom\_uri, $permalink\_manager\_redirects\[$element\_id\])) {
469
$duplicated\_redirect\_id = array\_search($custom\_uri, $permalink\_manager\_redirects\[$element\_id\]);
470
unset($permalink\_manager\_redirects\[$element\_id\]\[$duplicated\_redirect\_id\]);
471
}
472
473
// Check if function should only return the counts or update
474
if($count\_removed) {
475
return (isset($duplicated\_redirect\_id)) ? 1 : 0;
476
} else if(isset($duplicated\_redirect\_id)) {
477
update\_option('permalink-manager-redirects', array\_filter($permalink\_manager\_redirects));
478
return true;
479
}
480
}
481
482
/\*\*
483
\* Remove unused custom URI & redirects for deleted post or term
484
\*/
485
public static function clear\_single\_element\_uris\_and\_redirects($element\_id, $count\_removed = false) {
486
global $wpdb, $permalink\_manager\_uris, $permalink\_manager\_redirects;
487
488
// Count removed URIs & redirects
489
$removed\_uris = 0;
490
$removed\_redirects = 0;
491
492
// Only admin users can remove the broken URIs for removed post types & taxonomies
493
$check\_if\_exists = (is\_admin()) ? true : false;
494
495
// 1. Check if element exists
496
if(strpos($element\_id, 'tax-') !== false) {
497
$term\_id = preg\_replace("/\[^0-9\]/", "", $element\_id);
498
$term\_info = $wpdb->get\_row($wpdb->prepare("SELECT taxonomy, meta\_value FROM {$wpdb->term\_taxonomy} AS t LEFT JOIN {$wpdb->termmeta} AS tm ON tm.term\_id = t.term\_id AND tm.meta\_key = 'auto\_update\_uri' WHERE t.term\_id = %d", $term\_id));
499
500
// Remove custom URIs for removed terms or disabled taxonomies
501
$remove = (!empty($term\_info->taxonomy)) ? Permalink\_Manager\_Helper\_Functions::is\_taxonomy\_disabled($term\_info->taxonomy, $check\_if\_exists) : true;
502
503
// Remove custom URIs for URIs disabled in URI Editor
504
$remove = (!empty($term\_info->meta\_value) && $term\_info->meta\_value == 2) ? true : $remove;
505
506
} else if(is\_numeric($element\_id)) {
507
$post\_info = $wpdb->get\_row($wpdb->prepare("SELECT post\_type, meta\_value FROM {$wpdb->posts} AS p LEFT JOIN {$wpdb->postmeta} AS pm ON pm.post\_ID = p.ID AND pm.meta\_key = 'auto\_update\_uri' WHERE ID = %d AND post\_status NOT IN ('auto-draft', 'trash') AND post\_type != 'nav\_menu\_item'", $element\_id));
508
509
// Remove custom URIs for removed, auto-draft posts or disabled post types
510
$remove = (!empty($post\_info->post\_type)) ? Permalink\_Manager\_Helper\_Functions::is\_post\_type\_disabled($post\_info->post\_type, $check\_if\_exists) : true;
511
512
// Remove custom URIs for URIs disabled in URI Editor
513
$remove = (!empty($post\_info->meta\_value) && $post\_info->meta\_value == 2) ? true : $remove;
514
515
// Remove custom URIs for attachments redirected with Yoast's SEO Premium
516
$yoast\_permalink\_options = (class\_exists('WPSEO\_Premium')) ? get\_option('wpseo\_permalinks') : array();
517
518
if(!empty($yoast\_permalink\_options\['redirectattachment'\]) && $post\_info->post\_type == 'attachment') {
519
$attachment\_parent = $wpdb->get\_var("SELECT post\_parent FROM {$wpdb->prefix}posts WHERE ID = {$element\_id} AND post\_type = 'attachment'");
520
if(!empty($attachment\_parent)) {
521
$remove = true;
522
}
523
}
524
}
525
526
// 2A. Remove ALL unused custom permalinks & redirects
527
if(!empty($remove)) {
528
// Remove URI
529
if(!empty($permalink\_manager\_uris\[$element\_id\])) {
530
$removed\_uris = 1;
531
unset($permalink\_manager\_uris\[$element\_id\]);
532
}
533
534
// Remove all custom redirects
535
if(!empty($permalink\_manager\_redirects\[$element\_id\]) && is\_array($permalink\_manager\_redirects\[$element\_id\])) {
536
$removed\_redirects = count($permalink\_manager\_redirects\[$element\_id\]);
537
unset($permalink\_manager\_redirects\[$element\_id\]);;
538
}
539
}
540
// 2B. Check if the post/term uses the same URI for both permalink & custom redirects
541
else {
542
$removed\_redirect = self::clear\_single\_element\_duplicated\_redirect($element\_id, true);
543
$removed\_redirects = (!empty($removed\_redirect)) ? 1 : 0;
544
}
545
546
// Check if function should only return the counts or update
547
if($count\_removed) {
548
return array($removed\_uris, $removed\_redirects);
549
} else if(!empty($removed\_uris) || !empty($removed\_redirects)) {
550
update\_option('permalink-manager-uris', array\_filter($permalink\_manager\_uris));
551
update\_option('permalink-manager-redirects', array\_filter($permalink\_manager\_redirects));
552
return true;
553
}
554
}
555
556
/\*\*
557
\* Make the redirects unique
558
\*/
559
public static function clear\_redirects\_array($count\_removed = false) {
560
global $permalink\_manager\_redirects;
561
562
$removed\_redirects = 0;
563
564
$all\_redirect\_duplicates = Permalink\_Manager\_Helper\_Functions::get\_all\_duplicates(true);
565
566
foreach($all\_redirect\_duplicates as $single\_redirect\_duplicate) {
567
$last\_element = reset($single\_redirect\_duplicate);
568
569
foreach($single\_redirect\_duplicate as $redirect\_key) {
570
// Keep a single redirect
571
if($last\_element == $redirect\_key) { continue; }
572
preg\_match("/redirect-(\[\\d\]+)\_((?:tax-)?(?:\[\\d\]+))/", $redirect\_key, $ids);
573
574
if(!empty($ids\[2\]) && !empty($permalink\_manager\_redirects\[$ids\[2\]\]\[$ids\[1\]\])) {
575
$removed\_redirects++;
576
unset($permalink\_manager\_redirects\[$ids\[2\]\]\[$ids\[1\]\]);
577
}
578
}
579
}
580
581
// Check if function should only return the counts or update
582
if($count\_removed) {
583
return $removed\_redirects;
584
} else if(isset($duplicated\_redirect\_id)) {
585
update\_option('permalink-manager-redirects', array\_filter($permalink\_manager\_redirects));
586
return true;
587
}
588
}
589
590
/\*\*
591
\* Remove custom URI & redirects for any requested post or term
592
\*/
593
public static function force\_clear\_single\_element\_uris\_and\_redirects($uri\_key) {
594
global $permalink\_manager\_uris, $permalink\_manager\_redirects, $permalink\_manager\_before\_sections\_html;
595
596
// Check if custom URI is set
597
if(isset($permalink\_manager\_uris\[$uri\_key\])) {
598
$uri = $permalink\_manager\_uris\[$uri\_key\];
599
600
unset($permalink\_manager\_uris\[$uri\_key\]);
601
update\_option('permalink-manager-uris', $permalink\_manager\_uris);
602
603
$updated = Permalink\_Manager\_Admin\_Functions::get\_alert\_message(sprintf(\_\_( 'URI "%s" was removed successfully!', 'permalink-manager' ), $uri), 'updated');
604
}
605
606
// Check if custom redirects are set
607
if(isset($permalink\_manager\_redirects\[$uri\_key\])) {
608
unset($permalink\_manager\_redirects\[$uri\_key\]);
609
update\_option('permalink-manager-redirects', $permalink\_manager\_redirects);
610
611
$updated = Permalink\_Manager\_Admin\_Functions::get\_alert\_message(\_\_( 'Broken redirects were removed successfully!', 'permalink-manager' ), 'updated');
612
}
613
614
if(empty($updated)) {
615
$permalink\_manager\_before\_sections\_html .= Permalink\_Manager\_Admin\_Functions::get\_alert\_message(\_\_( 'URI and/or custom redirects does not exist or were already removed!', 'permalink-manager' ), 'error');
533
$alert\_message = sprintf( \_\_( '%s were removed!', 'permalink-manager' ), $alert );
534
$permalink\_manager\_before\_sections\_html .= Permalink\_Manager\_Admin\_Functions::get\_alert\_message( $alert\_message, 'updated updated\_slugs' );
535
}
536
}
537
538
/\*\*
539
\* Trigger bulk tools ("Regenerate & reset", "Find & replace") via AJAX
540
\*/
541
function ajax\_bulk\_tools() {
542
global $sitepress, $wpdb;
543
544
// Define variables
545
$return = array( 'alert' => Permalink\_Manager\_Admin\_Functions::get\_alert\_message( \_\_( '<strong>No slugs</strong> were updated!', 'permalink-manager' ), 'error updated\_slugs' ) );
546
547
// Get the name of the function
548
if ( isset( $\_POST\['regenerate'\] ) && wp\_verify\_nonce( $\_POST\['regenerate'\], 'permalink-manager' ) ) {
549
$function\_name = 'regenerate\_all\_permalinks';
550
} else if ( isset( $\_POST\['find\_and\_replace'\] ) && wp\_verify\_nonce( $\_POST\['find\_and\_replace'\], 'permalink-manager' ) && ! empty( $\_POST\['old\_string'\] ) && ! empty( $\_POST\['new\_string'\] ) ) {
551
$function\_name = 'find\_and\_replace';
552
}
553
554
// Get the session ID
555
$uniq\_id = ( ! empty( $\_POST\['pm\_session\_id'\] ) ) ? $\_POST\['pm\_session\_id'\] : '';
556
557
// Get content type & post statuses
558
if ( ! empty( $\_POST\['content\_type'\] ) && $\_POST\['content\_type'\] == 'taxonomies' ) {
559
$content\_type = 'taxonomies';
560
561
if ( empty( $\_POST\['taxonomies'\] ) ) {
562
$error = true;
563
$return = array( 'alert' => Permalink\_Manager\_Admin\_Functions::get\_alert\_message( \_\_( '<strong>No taxonomy</strong> selected!', 'permalink-manager' ), 'error updated\_slugs' ) );
564
}
616
565
} else {
617
// Display the alert in admin panel
618
if(!empty($permalink\_manager\_before\_sections\_html) && is\_admin()) {
619
$permalink\_manager\_before\_sections\_html .= $updated;
620
}
621
return true;
622
}
623
}
624
625
public static function force\_clear\_single\_redirect($redirect\_key) {
626
global $permalink\_manager\_redirects, $permalink\_manager\_before\_sections\_html;
627
628
preg\_match("/redirect-(\[\\d\]+)\_((?:tax-)?(?:\[\\d\]+))/", $redirect\_key, $ids);
629
630
if(!empty($permalink\_manager\_redirects\[$ids\[2\]\]\[$ids\[1\]\])) {
631
unset($permalink\_manager\_redirects\[$ids\[2\]\]\[$ids\[1\]\]);
632
633
update\_option('permalink-manager-redirects', array\_filter($permalink\_manager\_redirects));
634
635
$permalink\_manager\_before\_sections\_html = Permalink\_Manager\_Admin\_Functions::get\_alert\_message(\_\_( 'The redirect was removed successfully!', 'permalink-manager' ), 'updated');
636
}
637
}
638
639
/\*\*
640
\* Keep the permalinks unique
641
\*/
642
public static function fix\_uri\_duplicates() {
643
global $permalink\_manager\_uris;
644
645
$duplicates = array\_count\_values($permalink\_manager\_uris);
646
647
foreach($duplicates as $uri => $count) {
648
if($count == 1) { continue; }
649
650
$ids = array\_keys($permalink\_manager\_uris, $uri);
651
foreach($ids as $index => $id) {
652
if($index > 0) {
653
$permalink\_manager\_uris\[$id\] = preg\_replace('/(.+?)(\\.\[^\\.\]+$|$)/', '$1-' . $index . '$2', $uri);
654
}
655
}
656
}
657
658
update\_option('permalink-manager-uris', $permalink\_manager\_uris);
566
$content\_type = 'post\_types';
567
568
// Check if any post type was selected
569
if ( empty( $\_POST\['post\_types'\] ) ) {
570
$error = true;
571
$return = array( 'alert' => Permalink\_Manager\_Admin\_Functions::get\_alert\_message( \_\_( '<strong>No post type</strong> selected!', 'permalink-manager' ), 'error updated\_slugs' ) );
572
}
573
574
// Check post status
575
if ( empty( $\_POST\['post\_statuses'\] ) ) {
576
$error = true;
577
$return = array( 'alert' => Permalink\_Manager\_Admin\_Functions::get\_alert\_message( \_\_( '<strong>No post status</strong> selected!', 'permalink-manager' ), 'error updated\_slugs' ) );
578
}
579
}
580
581
// Check if both strings are set for "Find and replace" tool
582
if ( ! empty( $function\_name ) && ! empty( $content\_type ) && empty( $error ) ) {
583
584
// Hotfix for WPML (start)
585
if ( $sitepress ) {
586
remove\_filter( 'get\_terms\_args', array( $sitepress, 'get\_terms\_args\_filter' ), 10 );
587
remove\_filter( 'get\_term', array( $sitepress, 'get\_term\_adjust\_id' ), 1 );
588
remove\_filter( 'terms\_clauses', array( $sitepress, 'terms\_clauses' ), 10 );
589
remove\_filter( 'get\_pages', array( $sitepress, 'get\_pages\_adjust\_ids' ), 1 );
590
}
591
592
// Get the mode
593
$mode = isset( $\_POST\['mode'\] ) ? $\_POST\['mode'\] : 'custom\_uris';
594
595
// Get the content type
596
if ( $content\_type == 'taxonomies' ) {
597
$class\_name = 'Permalink\_Manager\_URI\_Functions\_Tax';
598
} else {
599
$class\_name = 'Permalink\_Manager\_URI\_Functions\_Post';
600
}
601
602
// Get items (try to get them from transient)
603
$items = get\_transient( "pm\_{$uniq\_id}" );
604
$progress = get\_transient( "pm\_{$uniq\_id}\_progress" );
605
606
$chunk\_size = apply\_filters( 'permalink\_manager\_chunk\_size', 50 );
607
608
if ( empty( $items ) ) {
609
$items = $class\_name::get\_items();
610
611
if ( ! empty( $items ) ) {
612
// Set stats (to display the progress)
613
$total = count( $items );
614
615
// Split items array into chunks and save them to transient
616
$items = array\_chunk( $items, $chunk\_size );
617
618
set\_transient( "pm\_{$uniq\_id}\_progress", 0, 300 );
619
set\_transient( "pm\_{$uniq\_id}", $items, 300 );
620
621
// Check for MySQL errors
622
if ( ! empty( $wpdb->last\_error ) ) {
623
printf( '%s (%sMB)', $wpdb->last\_error, strlen( serialize( $items ) ) / 1000000 );
624
http\_response\_code( 500 );
625
die();
626
}
627
}
628
}
629
630
// Get homepage URL and ensure that it ends with slash
631
$home\_url = Permalink\_Manager\_Helper\_Functions::get\_permalink\_base() . "/";
632
633
// Process the variables from $\_POST object
634
$old\_string = ( ! empty( $\_POST\['old\_string'\] ) ) ? str\_replace( $home\_url, '', esc\_sql( $\_POST\['old\_string'\] ) ) : '';
635
$new\_string = ( ! empty( $\_POST\['old\_string'\] ) ) ? str\_replace( $home\_url, '', esc\_sql( $\_POST\['new\_string'\] ) ) : '';
636
637
// Process only one subarray
638
if ( ! empty( $items\[0\] ) ) {
639
$chunk = array\_shift( $items );
640
set\_transient( "pm\_{$uniq\_id}", $items, 300 );
641
642
// Check if posts or terms should be updated
643
if ( $function\_name == 'find\_and\_replace' ) {
644
$output = $class\_name::find\_and\_replace( $chunk, $mode, $old\_string, $new\_string );
645
} else {
646
$output = $class\_name::regenerate\_all\_permalinks( $chunk, $mode );
647
}
648
649
if ( ! empty( $output\['updated\_count'\] ) ) {
650
$return = array\_merge( $return, (array) Permalink\_Manager\_Admin\_Functions::display\_updated\_slugs( $output\['updated'\], true ) );
651
$return\['updated\_count'\] = $output\['updated\_count'\];
652
}
653
654
// Send total number of processed items with a first chunk
655
if ( ! empty( $total ) ) {
656
$return\['total'\] = $total;
657
}
658
659
// Check if there are any chunks left
660
if ( count( $items ) > 0 ) {
661
// Update progress
662
$progress += $chunk\_size;
663
set\_transient( "pm\_{$uniq\_id}\_progress", $progress, 300 );
664
665
$return\['left\_chunks'\] = true;
666
$return\['progress'\] = $progress;
667
} else {
668
delete\_transient( "pm\_{$uniq\_id}" );
669
delete\_transient( "pm\_{$uniq\_id}\_progress" );
670
}
671
}
672
673
// Hotfix for WPML (end)
674
if ( $sitepress ) {
675
add\_filter( 'terms\_clauses', array( $sitepress, 'terms\_clauses' ), 10, 4 );
676
add\_filter( 'get\_term', array( $sitepress, 'get\_term\_adjust\_id' ), 1, 1 );
677
add\_filter( 'get\_terms\_args', array( $sitepress, 'get\_terms\_args\_filter' ), 10, 2 );
678
add\_filter( 'get\_pages', array( $sitepress, 'get\_pages\_adjust\_ids' ), 1, 2 );
679
}
680
}
681
682
wp\_send\_json( $return );
683
die();
684
}
685
686
/\*\*
687
\* Save permalink via AJAX
688
\*/
689
public function ajax\_save\_permalink() {
690
$element\_id = ( ! empty( $\_POST\['permalink-manager-edit-uri-element-id'\] ) ) ? sanitize\_text\_field( $\_POST\['permalink-manager-edit-uri-element-id'\] ) : '';
691
692
if ( ! empty( $element\_id ) && is\_numeric( $element\_id ) ) {
693
Permalink\_Manager\_URI\_Functions\_Post::update\_post\_uri( $element\_id );
694
695
// Reload URI Editor & clean post cache
696
clean\_post\_cache( $element\_id );
697
die();
698
}
659
699
}
660
700
661
701
/\*\*
662
702
\* Check if URI was used before
663
\*/
664
function ajax\_detect\_duplicates($uri = null, $element\_id = null) {
665
$duplicate\_alert = \_\_("URI is already in use, please select another one!", "permalink-manager");
666
667
if(!empty($\_REQUEST\['custom\_uris'\])) {
703
\*
704
\* @param string $uri
705
\* @param string $element\_id
706
\*/
707
function ajax\_detect\_duplicates( $uri = null, $element\_id = null ) {
708
$duplicate\_alert = \_\_( "URI is already in use, please select another one!", "permalink-manager" );
709
710
if ( ! empty( $\_REQUEST\['custom\_uris'\] ) ) {
668
711
// Sanitize the array
669
$custom\_uris \= Permalink\_Manager\_Helper\_Functions::sanitize\_array($\_REQUEST\['custom\_uris'\]);
712
$custom\_uris = Permalink\_Manager\_Helper\_Functions::sanitize\_array( $\_REQUEST\['custom\_uris'\] );
670
713
$duplicates\_array = array();
671
714
672
715
// Check each URI
673
foreach($custom\_uris as $element\_id => $uri) {
674
$duplicates\_array\[$element\_id\] = Permalink\_Manager\_Helper\_Functions::is\_uri\_duplicated($uri, $element\_id) ? $duplicate\_alert : 0;
716
foreach ( $custom\_uris as $element\_id => $uri ) {
717
$duplicates\_array\[ $element\_id \] = Permalink\_Manager\_Helper\_Functions::is\_uri\_duplicated( $uri, $element\_id ) ? $duplicate\_alert : 0;
675
718
}
676
719
677
720
// Convert the output to JSON and stop the function
678
echo json\_encode($duplicates\_array);
679
} else if(!empty($\_REQUEST\['custom\_uri'\]) && !empty($\_REQUEST\['element\_id'\])) {
680
$is\_duplicated = Permalink\_Manager\_Helper\_Functions::is\_uri\_duplicated($uri, $element\_id);
681
682
echo ($is\_duplicated) ? $duplicate\_alert : 0;
721
echo json\_encode( $duplicates\_array );
722
} else if ( ! empty( $\_REQUEST\['custom\_uri'\] ) && ! empty( $\_REQUEST\['element\_id'\] ) ) {
723
$is\_duplicated = Permalink\_Manager\_Helper\_Functions::is\_uri\_duplicated( $uri, $element\_id );
724
725
echo ( $is\_duplicated ) ? $duplicate\_alert : 0;
683
726
}
684
727
…
…
693
736
694
737
// Get the ID of the alert
695
$alert\_id = (!empty($\_REQUEST\['alert\_id'\])) ? sanitize\_title($\_REQUEST\['alert\_id'\]) : "";
696
if(!empty($permalink\_manager\_alerts\[$alert\_id\])) {
697
$dismissed\_transient\_name = sprintf('permalink-manager-notice\_%s', $alert\_id);
698
$dismissed\_time \= (!empty($permalink\_manager\_alerts\[$alert\_id\]\['dismissed\_time'\])) ? (int) $permalink\_manager\_alerts\[$alert\_id\]\['dismissed\_time'\] : DAY\_IN\_SECONDS;
699
700
set\_transient($dismissed\_transient\_name, 1, $dismissed\_time);
738
$alert\_id = ( ! empty( $\_REQUEST\['alert\_id'\] ) ) ? sanitize\_title( $\_REQUEST\['alert\_id'\] ) : "";
739
if ( ! empty( $permalink\_manager\_alerts\[ $alert\_id \] ) ) {
740
$dismissed\_transient\_name = sprintf( 'permalink-manager-notice\_%s', $alert\_id );
741
$dismissed\_time = ( ! empty( $permalink\_manager\_alerts\[ $alert\_id \]\['dismissed\_time'\] ) ) ? (int) $permalink\_manager\_alerts\[ $alert\_id \]\['dismissed\_time'\] : DAY\_IN\_SECONDS;
742
743
set\_transient( $dismissed\_transient\_name, 1, $dismissed\_time );
701
744
}
702
745
}
…
…
710
753
711
754
/\*\*
712
\* "Automatically remove duplicates" (if enabled) in background
755
\* Remove the duplicated custom permalinks & redirects automatically in the background
713
756
\*/
714
757
function clean\_permalinks\_hook() {
…
…
716
759
717
760
// Backup the custom URIs
718
if(is\_array($permalink\_manager\_uris)) {
719
update\_option('permalink-manager-uris\_backup', $permalink\_manager\_uris, false);
761
if ( is\_array( $permalink\_manager\_uris ) ) {
762
update\_option( 'permalink-manager-uris\_backup', $permalink\_manager\_uris, false );
720
763
}
721
764
// Backup the custom redirects
722
if(is\_array($permalink\_manager\_redirects)) {
723
update\_option('permalink-manager-redirects\_backup', $permalink\_manager\_redirects, false);
765
if ( is\_array( $permalink\_manager\_redirects ) ) {
766
update\_option( 'permalink-manager-redirects\_backup', $permalink\_manager\_redirects, false );
724
767
}
725
768
…
…
727
770
}
728
771
772
/\*\*
773
\* Schedule the function that automatically removes the custom permalinks & redirects duplicates
774
\*/
729
775
function clean\_permalinks\_cronjob() {
730
776
global $permalink\_manager\_options;
…
…
732
778
$event\_name = 'clean\_permalinks\_event';
733
779
734
// Set\-up the "Automatically remove duplicates" function that runs in background once a day
735
if(!empty($permalink\_manager\_options\['general'\]\['auto\_remove\_duplicates'\]) && $permalink\_manager\_options\['general'\]\['auto\_remove\_duplicates'\] == 2) {
736
if(!wp\_next\_scheduled($event\_name)) {
737
wp\_schedule\_event(time(), 'daily', $event\_name);
738
}
739
} else if(wp\_next\_scheduled($event\_name)) {
740
$event\_timestamp = wp\_next\_scheduled($event\_name);
741
wp\_unschedule\_event($event\_timestamp, $event\_name);
780
// Set up the "Automatically remove duplicates" function that runs in background once a day
781
if ( ! empty( $permalink\_manager\_options\['general'\]\['auto\_remove\_duplicates'\] ) && $permalink\_manager\_options\['general'\]\['auto\_remove\_duplicates'\] == 2 ) {
782
if ( ! wp\_next\_scheduled( $event\_name ) ) {
783
wp\_schedule\_event( time(), 'daily', $event\_name );
784
}
785
} else if ( wp\_next\_scheduled( $event\_name ) ) {
786
$event\_timestamp = wp\_next\_scheduled( $event\_name );
787
wp\_unschedule\_event( $event\_timestamp, $event\_name );
742
788
}
743
789
}
permalink-manager/trunk/includes/core/permalink-manager-admin-functions.php
r2748381
r2833667
2
2
3
3
/\*\*
4
\* Additional back-end functions related to Wordpress Dashboard UI
5
\*/
6
class Permalink\_Manager\_Admin\_Functions extends Permalink\_Manager\_Class {
4
\* Additional functions related to WordPress Admin Dashboard UI
5
\*/
6
class Permalink\_Manager\_Admin\_Functions {
7
7
8
8
public $menu\_name, $sections, $active\_section, $active\_subsection;
9
public $plugin\_basename = PERMALINK\_MANAGER\_BASENAME;
10
9
11
10
public function \_\_construct() {
12
add\_action( 'admin\_menu', array($this, 'add\_menu\_page') );
13
add\_action( 'admin\_init', array($this, 'init') );
14
add\_action( 'admin\_bar\_menu', array($this, 'fix\_customize\_url'), 41);
15
16
add\_action( 'admin\_notices', array($this, 'display\_plugin\_notices'));
17
add\_action( 'admin\_notices', array($this, 'display\_global\_notices'));
18
19
add\_filter( 'default\_hidden\_columns', array($this, 'quick\_edit\_hide\_column'), 99, 2 );
11
add\_action( 'admin\_menu', array( $this, 'add\_menu\_page' ) );
12
add\_action( 'admin\_init', array( $this, 'init' ) );
13
add\_action( 'admin\_bar\_menu', array( $this, 'fix\_customize\_url' ), 41 );
14
15
add\_action( 'admin\_notices', array( $this, 'display\_plugin\_notices' ) );
16
add\_action( 'admin\_notices', array( $this, 'display\_global\_notices' ) );
17
18
add\_filter( 'default\_hidden\_columns', array( $this, 'quick\_edit\_hide\_column' ), 99 );
20
19
}
21
20
…
…
25
24
public function init() {
26
25
// Additional links in "Plugins" page
27
add\_filter( "plugin\_action\_links\_{$this->plugin\_basename}", array($this, "plugins\_page\_links") );
28
add\_filter( "plugin\_row\_meta", array($this, "plugins\_page\_meta"), 10, 2 );
26
add\_filter( "plugin\_action\_links\_" . PERMALINK\_MANAGER\_BASENAME, array( $this, "plugins\_page\_links" ) );
27
add\_filter( "plugin\_row\_meta", array( $this, "plugins\_page\_meta" ), 10, 2 );
29
28
30
29
// Detect current section
31
$this->sections = apply\_filters('permalink\_manager\_sections', array());
30
$this->sections = apply\_filters( 'permalink\_manager\_sections', array() );
32
31
$this->get\_current\_section();
33
32
}
34
33
35
34
/\*\*
36
\* Fix Customize URL
37
\*/
38
public function fix\_customize\_url($wp\_admin\_bar) {
39
$object = get\_queried\_object();
40
41
$customize = $wp\_admin\_bar->get\_node('customize');
42
43
if(empty($customize->href)) { return; }
44
45
$\_REQUEST\['customize\_url'\] = true;
46
if(!empty($object->ID)) {
47
$new\_url = get\_permalink($object->ID);
48
} else if(!empty($object->term\_id)) {
49
50
}
51
$\_REQUEST\['customize\_url'\] = false;
52
53
if(!empty($new\_url)) {
54
$new\_url = urlencode\_deep($new\_url);
55
$customize\_url = preg\_replace('/url=(\[^&\]+)/', "url={$new\_url}", $customize->href);
56
57
$wp\_admin\_bar->add\_node(array(
58
'id' => 'customize',
35
\* Use the native URL for "Customize" button in the admin bar
36
\*
37
\* @param WP\_Admin\_Bar $wp\_admin\_bar
38
\*/
39
public function fix\_customize\_url( $wp\_admin\_bar ) {
40
global $permalink\_manager\_ignore\_permalink\_filters;
41
42
$object = get\_queried\_object();
43
$customize = $wp\_admin\_bar->get\_node( 'customize' );
44
45
if ( empty( $customize->href ) ) {
46
return;
47
}
48
49
$permalink\_manager\_ignore\_permalink\_filters = true;
50
if ( ! empty( $object->ID ) ) {
51
$new\_url = get\_permalink( $object->ID );
52
}
53
$permalink\_manager\_ignore\_permalink\_filters = false;
54
55
if ( ! empty( $new\_url ) ) {
56
$new\_url = urlencode\_deep( $new\_url );
57
$customize\_url = preg\_replace( '/url=(\[^&\]+)/', "url={$new\_url}", $customize->href );
58
59
$wp\_admin\_bar->add\_node( array(
60
'id' => 'customize',
59
61
'href' => $customize\_url,
60
));
61
}
62
}
63
64
/\*\*
65
\* Get current section (only in plugin sections)
62
) );
63
}
64
}
65
66
/\*\*
67
\* Get current section of Permalink Manager admin panel
66
68
\*/
67
69
public function get\_current\_section() {
…
…
69
71
70
72
// 1. Get current section
71
if(isset($\_GET\['page'\]) && $\_GET\['page'\] == PERMALINK\_MANAGER\_PLUGIN\_SLUG) {
72
if(isset($\_POST\['section'\])) {
73
$this->active\_section = sanitize\_title\_with\_dashes($\_POST\['section'\]);
74
} else if(isset($\_GET\['section'\])) {
75
$this->active\_section = sanitize\_title\_with\_dashes($\_GET\['section'\]);
73
if ( isset( $\_GET\['page'\] ) && $\_GET\['page'\] == PERMALINK\_MANAGER\_PLUGIN\_SLUG ) {
74
if ( isset( $\_POST\['section'\] ) ) {
75
$this->active\_section = sanitize\_title\_with\_dashes( $\_POST\['section'\] );
76
} else if ( isset( $\_GET\['section'\] ) ) {
77
$this->active\_section = sanitize\_title\_with\_dashes( $\_GET\['section'\] );
76
78
} else {
77
$sections\_names \= array\_keys($this->sections);
79
$sections\_names = array\_keys( $this->sections );
78
80
$this->active\_section = $sections\_names\[0\];
79
81
}
…
…
81
83
82
84
// 2. Get current subsection
83
if($this->active\_section && isset($this->sections\[$this->active\_section\]\['subsections'\])) {
84
if(isset($\_POST\['subsection'\])) {
85
$this->active\_subsection = sanitize\_title\_with\_dashes($\_POST\['subsection'\]);
86
} else if(isset($\_GET\['subsection'\])) {
87
$this->active\_subsection = sanitize\_title\_with\_dashes($\_GET\['subsection'\]);
85
if ( $this->active\_section && isset( $this->sections\[ $this->active\_section \]\['subsections'\] ) ) {
86
if ( isset( $\_POST\['subsection'\] ) ) {
87
$this->active\_subsection = sanitize\_title\_with\_dashes( $\_POST\['subsection'\] );
88
} else if ( isset( $\_GET\['subsection'\] ) ) {
89
$this->active\_subsection = sanitize\_title\_with\_dashes( $\_GET\['subsection'\] );
88
90
} else {
89
$subsections\_names \= array\_keys($this->sections\[$this->active\_section\]\['subsections'\]);
91
$subsections\_names = array\_keys( $this->sections\[ $this->active\_section \]\['subsections'\] );
90
92
$this->active\_subsection = $subsections\_names\[0\];
91
93
}
92
94
}
93
95
94
// Check if current admin page is related to taxonomies
95
if(!empty($this->active\_subsection) && substr($this->active\_subsection, 0, 4) == 'tax\_') {
96
$current\_admin\_tax = substr($this->active\_subsection, 4, strlen($this->active\_subsection));
96
// 3\. Check if current admin page is related to taxonomies
97
if ( ! empty( $this->active\_subsection ) && substr( $this->active\_subsection, 0, 4 ) == 'tax\_' ) {
98
$current\_admin\_tax = substr( $this->active\_subsection, 4, strlen( $this->active\_subsection ) );
97
99
} else {
98
100
$current\_admin\_tax = false;
…
…
100
102
101
103
// Set globals
102
$active\_section \= $this->active\_section;
104
$active\_section \= $this->active\_section;
103
105
$active\_subsection = $this->active\_subsection;
104
106
}
105
107
106
108
/\*\*
107
\* Add menu page.
109
\* Add "Tools -> Permalink Manager" to the admin sidebar menu
108
110
\*/
109
111
public function add\_menu\_page() {
110
$this->menu\_name = add\_management\_page( \_\_('Permalink Manager', 'permalink-manager'), \_\_('Permalink Manager', 'permalink-manager'), 'manage\_options', PERMALINK\_MANAGER\_PLUGIN\_SLUG, array($this, 'display\_section') );
111
112
add\_action( 'admin\_init', array($this, 'enqueue\_styles' ) );
113
add\_action( 'admin\_init', array($this, 'enqueue\_scripts' ) );
114
}
115
116
/\*\*
117
\* Register the CSS file for the dashboard.
112
$this->menu\_name = add\_management\_page( \_\_( 'Permalink Manager', 'permalink-manager' ), \_\_( 'Permalink Manager', 'permalink-manager' ), 'manage\_options', PERMALINK\_MANAGER\_PLUGIN\_SLUG, array( $this, 'display\_section' ) );
113
114
add\_action( 'admin\_init', array( $this, 'enqueue\_styles' ) );
115
add\_action( 'admin\_init', array( $this, 'enqueue\_scripts' ) );
116
}
117
118
/\*\*
119
\* Register the CSS files for the plugin's dashboard
118
120
\*/
119
121
public function enqueue\_styles() {
120
wp\_enqueue\_style( 'permalink-manager-plugins', PERMALINK\_MANAGER\_URL . '/out/permalink-manager-plugins.css', array(), PERMALINK\_MANAGER\_VERSION, 'all' );
121
wp\_enqueue\_style( 'permalink-manager', PERMALINK\_MANAGER\_URL . '/out/permalink-manager-admin.css', array('permalink-manager-plugins'), PERMALINK\_MANAGER\_VERSION, 'all' );
122
}
123
124
/\*\*
125
\* Register the JavaScript file for the dashboard.
122
wp\_enqueue\_style( 'permalink-manager-plugins', PERMALINK\_MANAGER\_URL . '/out/permalink-manager-plugins.css', array(), PERMALINK\_MANAGER\_VERSION );
123
wp\_enqueue\_style( 'permalink-manager', PERMALINK\_MANAGER\_URL . '/out/permalink-manager-admin.css', array( 'permalink-manager-plugins' ), PERMALINK\_MANAGER\_VERSION );
124
}
125
126
/\*\*
127
\* Register the JavaScript files for the plugin's dashboard.
126
128
\*/
127
129
public function enqueue\_scripts() {
128
wp\_enqueue\_script( 'permalink-manager-plugins', PERMALINK\_MANAGER\_URL . '/out/permalink-manager-plugins.js', array( 'jquery', ), PERMALINK\_MANAGER\_VERSION, false );
129
wp\_enqueue\_script( 'permalink-manager', PERMALINK\_MANAGER\_URL . '/out/permalink-manager-admin.js', array( 'jquery', 'permalink-manager-plugins' ), PERMALINK\_MANAGER\_VERSION, false );
130
wp\_enqueue\_script( 'permalink-manager-plugins', PERMALINK\_MANAGER\_URL . '/out/permalink-manager-plugins.js', array( 'jquery', ), PERMALINK\_MANAGER\_VERSION );
131
wp\_enqueue\_script( 'permalink-manager', PERMALINK\_MANAGER\_URL . '/out/permalink-manager-admin.js', array( 'jquery', 'permalink-manager-plugins' ), PERMALINK\_MANAGER\_VERSION );
130
132
131
133
wp\_localize\_script( 'permalink-manager', 'permalink\_manager', array(
132
'ajax\_url' => admin\_url('admin-ajax.php'),
133
'url' => PERMALINK\_MANAGER\_URL,
134
'confirm' => \_\_('Are you sure? This action cannot be undone!', 'permalink-manager'),
135
'spinners' => admin\_url('images'))
134
'ajax\_url' => admin\_url( 'admin-ajax.php' ),
135
'url' => PERMALINK\_MANAGER\_URL,
136
'confirm' => \_\_( 'Are you sure? This action cannot be undone!', 'permalink-manager' ),
137
'spinners' => admin\_url( 'images' )
138
) );
139
140
}
141
142
/\*\*
143
\* Get the URL of the plugin's dashboard
144
\*
145
\* @param string $append
146
\*
147
\* @return string
148
\*/
149
public static function get\_admin\_url( $append = '' ) {
150
//return menu\_page\_url(PERMALINK\_MANAGER\_PLUGIN\_SLUG, false) . $append;
151
$admin\_page = sprintf( "tools.php?page=%s", PERMALINK\_MANAGER\_PLUGIN\_SLUG . $append );
152
153
return admin\_url( $admin\_page );
154
}
155
156
/\*\*
157
\* Add shortcut links for Permalink Manager on "Plugins" page
158
\*
159
\* @param array $links
160
\*
161
\* @return array
162
\*/
163
public function plugins\_page\_links( $links ) {
164
$new\_links = array(
165
sprintf( '<a href="%s">%s</a>', $this->get\_admin\_url(), \_\_( 'URI Editor', 'permalink-manager' ) ),
166
sprintf( '<a href="%s">%s</a>', $this->get\_admin\_url( '§ion=settings' ), \_\_( 'Settings', 'permalink-manager' ) ),
136
167
);
137
168
138
}
139
140
/\*\*
141
\* Get admin url for the plugin
142
\*/
143
public static function get\_admin\_url($append = '') {
144
//return menu\_page\_url(PERMALINK\_MANAGER\_PLUGIN\_SLUG, false) . $append;
145
$admin\_page = sprintf("tools.php?page=%s", PERMALINK\_MANAGER\_PLUGIN\_SLUG . $append);
146
147
return admin\_url($admin\_page);
148
}
149
150
/\*\*
151
\* Additional links on "Plugins" page
152
\*/
153
public function plugins\_page\_links($links) {
154
$new\_links = array(
155
sprintf('<a href="%s">%s</a>', $this->get\_admin\_url(), \_\_( 'URI Editor', 'permalink-manager' )),
156
sprintf('<a href="%s">%s</a>', $this->get\_admin\_url('§ion=settings'), \_\_( 'Settings', 'permalink-manager' )),
157
);
158
159
return array\_merge($links, $new\_links);
160
}
161
162
/\*\*
163
\* Additional meta links on "Plugins" page
164
\*/
165
public function plugins\_page\_meta($links, $file) {
166
if($file == PERMALINK\_MANAGER\_BASENAME) {
169
return array\_merge( $links, $new\_links );
170
}
171
172
/\*\*
173
\* Add shortcut meta links for Permalink Manager on "Plugins" page
174
\*
175
\* @param array $links
176
\* @param string $file
177
\*
178
\* @return array
179
\*/
180
public function plugins\_page\_meta( $links, $file ) {
181
if ( $file == PERMALINK\_MANAGER\_BASENAME ) {
167
182
$new\_links = array(
168
'doc' => sprintf('<a href="%s?utm\_source=plugin\_admin\_page" target="\_blank">%s</a>', 'https://permalinkmanager.pro/docs/', \_\_( 'Documentation', 'permalink-manager' ))
183
'doc' => sprintf( '<a href="%s?utm\_source=plugin\_admin\_page" target="\_blank">%s</a>', 'https://permalinkmanager.pro/docs/', \_\_( 'Documentation', 'permalink-manager' ) )
169
184
);
170
185
171
if(!defined('PERMALINK\_MANAGER\_PRO')) {
172
$new\_links\['upgrade'\] = sprintf('<a href="%s?utm\_source=plugin\_admin\_page" target="\_blank"><strong>%s</strong></a>', PERMALINK\_MANAGER\_WEBSITE, \_\_( 'Buy Permalink Manager Pro', 'permalink-manager' ));
173
}
174
175
$links = array\_merge($links, $new\_links);
186
if ( ! defined( 'PERMALINK\_MANAGER\_PRO' ) ) {
187
$new\_links\['upgrade'\] = sprintf( '<a href="%s?utm\_source=plugin\_admin\_page" target="\_blank"><strong>%s</strong></a>', PERMALINK\_MANAGER\_WEBSITE, \_\_( 'Buy Permalink Manager Pro', 'permalink-manager' ) );
188
}
189
190
$links = array\_merge( $links, $new\_links );
176
191
}
177
192
…
…
180
195
181
196
/\*\*
182
\* Generate the fields
183
\*/
184
static public function generate\_option\_field($input\_name, $args) {
197
\* Generate the option field
198
\*
199
\* @param $input\_name
200
\* @param $args
201
\*
202
\* @return string
203
\*/
204
static public function generate\_option\_field( $input\_name, $args ) {
185
205
global $permalink\_manager\_options, $permalink\_manager\_permastructs;
186
206
187
207
// Reset $fields variables
188
$fields = $section\_name = $field\_name = '';
208
$fields = '';
189
209
190
210
// Allow to filter the $args
191
$args = apply\_filters('permalink\_manager\_field\_args', $args, $input\_name);
192
193
$field\_type \= (isset($args\['type'\])) ? $args\['type'\] : 'text';
194
$default \= (isset($args\['default'\])) ? $args\['default'\] : '';
195
$label \= (isset($args\['label'\])) ? $args\['label'\] : '';
196
$rows \= (isset($args\['rows'\])) ? "rows=\\"{$rows}\\"" : "rows=\\"5\\"";
197
$description \= (isset($args\['before\_description'\])) ? $args\['before\_description'\] : "";
198
$description .= (isset($args\['description'\])) ? "<p class=\\"field-description description\\">{$args\['description'\]}</p>" : "";
199
$description .= (isset($args\['after\_description'\])) ? $args\['after\_description'\] : "";
200
$description .= (isset($args\['pro'\])) ? sprintf("<p class=\\"field-description description alert info\\">%s</p>", (self::pro\_text(true))) : "";
201
$append\_content = (isset($args\['append\_content'\])) ? "{$args\['append\_content'\]}" : "";
211
$args = apply\_filters( 'permalink\_manager\_field\_args', $args, $input\_name );
212
213
$field\_type = ( isset( $args\['type'\] ) ) ? $args\['type'\] : 'text';
214
$default = ( isset( $args\['default'\] ) ) ? $args\['default'\] : '';
215
$label = ( isset( $args\['label'\] ) ) ? $args\['label'\] : '';
216
$rows = ( isset( $args\['rows'\] ) ) ? "rows=\\"{$args\['rows'\]}\\"" : "rows=\\"5\\"";
217
$description = ( isset( $args\['before\_description'\] ) ) ? $args\['before\_description'\] : "";
218
$description .= ( isset( $args\['description'\] ) ) ? "<p class=\\"field-description description\\">{$args\['description'\]}</p>" : "";
219
$description .= ( isset( $args\['after\_description'\] ) ) ? $args\['after\_description'\] : "";
220
$description .= ( isset( $args\['pro'\] ) ) ? sprintf( "<p class=\\"field-description description alert info\\">%s</p>", ( self::pro\_text( true ) ) ) : "";
221
$append\_content = ( isset( $args\['append\_content'\] ) ) ? "{$args\['append\_content'\]}" : "";
202
222
203
223
// Input attributes
204
$input\_atts = (isset($args\['input\_class'\])) ? "class='{$args\['input\_class'\]}'" : '';
205
$input\_atts .= (isset($args\['readonly'\])) ? " readonly='readonly'" : '';
206
$input\_atts .= (isset($args\['disabled'\])) ? " disabled='disabled'" : '';
207
$input\_atts .= (isset($args\['placeholder'\])) ? " placeholder='{$args\['placeholder'\]}'" : '';
208
$input\_atts .= (isset($args\['extra\_atts'\])) ? " {$args\['extra\_atts'\]}" : '';
224
$input\_atts = ( isset( $args\['input\_class'\] ) ) ? "class='{$args\['input\_class'\]}'" : '';
225
$input\_atts .= ( isset( $args\['readonly'\] ) ) ? " readonly='readonly'" : '';
226
$input\_atts .= ( isset( $args\['disabled'\] ) ) ? " disabled='disabled'" : '';
227
$input\_atts .= ( isset( $args\['placeholder'\] ) ) ? " placeholder='{$args\['placeholder'\]}'" : '';
228
$input\_atts .= ( isset( $args\['extra\_atts'\] ) ) ? " {$args\['extra\_atts'\]}" : '';
209
229
210
230
// Display the field if the related class exists
211
if(!empty($args\['class\_exists'\])) {
212
$related\_classes \= (array) $args\['class\_exists'\];
231
if ( ! empty( $args\['class\_exists'\] ) ) {
232
$related\_classes \= (array) $args\['class\_exists'\];
213
233
$related\_classes\_exist = 0;
214
234
215
foreach($related\_classes as $related\_class) {
216
if(class\_exists($related\_class)) {
235
foreach ( $related\_classes as $related\_class ) {
236
if ( class\_exists( $related\_class ) ) {
217
237
$related\_classes\_exist = 1;
218
238
break;
…
…
221
241
222
242
// Do not display if the related class it not found
223
if(empty($related\_classes\_exist)) {
243
if ( empty( $related\_classes\_exist ) ) {
224
244
$field\_type = $args\['container\_class'\] = 'hidden';
225
245
}
…
…
227
247
228
248
// Check the container classes
229
$container\_class = (isset($args\['container\_class'\])) ? " class=\\"{$args\['container\_class'\]} field-container\\"" : " class=\\"field-container\\"";
249
$container\_class = ( isset( $args\['container\_class'\] ) ) ? " class=\\"{$args\['container\_class'\]} field-container\\"" : " class=\\"field-container\\"";
230
250
231
251
// Get the field value (if it is not set in $args)
232
if(isset($args\['value'\]) && empty($args\['value'\]) == false) {
252
if ( isset( $args\['value'\] ) && ! empty( $args\['value'\] ) ) {
233
253
$value = $args\['value'\];
234
254
} else {
235
255
// Extract the section and field name from $input\_name
236
preg\_match('/(\[^\\\[\]+)(?:\\\[(\[^\\\[\]+)\\\])(?:\\\[(\[^\\\[\]+)\\\])?/', $input\_name, $field\_section\_and\_name);
237
238
if($field\_section\_and\_name) {
256
preg\_match( '/(\[^\\\[\]+)(?:\\\[(\[^\\\[\]+)\\\])(?:\\\[(\[^\\\[\]+)\\\])?/', $input\_name, $field\_section\_and\_name );
257
258
if ( $field\_section\_and\_name ) {
239
259
$section\_name = $field\_section\_and\_name\[1\];
240
if(!empty($field\_section\_and\_name\[3\])) {
241
$field\_name = $field\_section\_and\_name\[2\];
260
$field\_name = $field\_section\_and\_name\[2\];
261
262
if ( ! empty( $field\_section\_and\_name\[3\] ) ) {
242
263
$subsection\_name = $field\_section\_and\_name\[3\];
243
$value \= (isset($permalink\_manager\_options\[$section\_name\]\[$field\_name\]\[$subsection\_name\])) ? $permalink\_manager\_options\[$section\_name\]\[$field\_name\]\[$subsection\_name\] : $default;
264
$value = ( isset( $permalink\_manager\_options\[ $section\_name \]\[ $field\_name \]\[ $subsection\_name \] ) ) ? $permalink\_manager\_options\[ $section\_name \]\[ $field\_name \]\[ $subsection\_name \] : $default;
244
265
} else {
245
$field\_name = $field\_section\_and\_name\[2\];
246
$value = (isset($permalink\_manager\_options\[$section\_name\]\[$field\_name\])) ? $permalink\_manager\_options\[$section\_name\]\[$field\_name\] : $default;
266
$value = ( isset( $permalink\_manager\_options\[ $section\_name \]\[ $field\_name \] ) ) ? $permalink\_manager\_options\[ $section\_name \]\[ $field\_name \] : $default;
247
267
}
248
268
} else {
249
$value = (isset($permalink\_manager\_options\[$input\_name\])) ? $permalink\_manager\_options\[$input\_name\] : $default;
250
}
251
}
252
253
switch($field\_type) {
269
$value = ( isset( $permalink\_manager\_options\[ $input\_name \] ) ) ? $permalink\_manager\_options\[ $input\_name \] : $default;
270
}
271
}
272
273
switch ( $field\_type ) {
254
274
case 'checkbox' :
255
275
$fields .= '<div class="checkboxes">';
256
foreach($args\['choices'\] as $choice\_value => $choice) {
276
foreach ( $args\['choices'\] as $choice\_value => $choice ) {
257
277
$input\_template = "<label for='%s\[\]'><input type='checkbox' %s value='%s' name='%s\[\]' %s /> %s</label>";
258
278
259
if(empty($choice\['label'\]) && is\_array($choice)) {
260
if(in\_array($choice\_value, array('post\_types', 'taxonomies'))) {
261
$group\_labels = array('post\_types' => \_\_('Post types', 'permalink-manager'), 'taxonomies' => \_\_('Taxonomies', 'permalink-manager'));
262
$fields .= sprintf('<p>%s</p>', $group\_labels\[$choice\_value\]);
279
if ( empty( $choice\['label'\] ) && is\_array( $choice ) ) {
280
if ( in\_array( $choice\_value, array( 'post\_types', 'taxonomies' ) ) ) {
281
$group\_labels = array( 'post\_types' => \_\_( 'Post types', 'permalink-manager' ), 'taxonomies' => \_\_( 'Taxonomies', 'permalink-manager' ) );
282
$fields .= sprintf( '<p>%s</p>', $group\_labels\[ $choice\_value \] );
263
283
}
264
284
265
foreach($choice as $sub\_choice\_value => $sub\_choice) {
266
$label = (!empty($sub\_choice\['label'\])) ? $sub\_choice\['label'\] : $sub\_choice;
267
$atts \= (!empty($value\[$choice\_value\]) && in\_array($sub\_choice\_value, $value\[$choice\_value\])) ? "checked='checked'" : "";
268
$atts .= (!empty($sub\_choice\['atts'\])) ? " {$sub\_choice\['atts'\]}" : "";
269
270
$fields .= sprintf($input\_template, $input\_name, $input\_atts, $sub\_choice\_value, "{$input\_name}\[{$choice\_value}\]", $atts, $label);
285
foreach ( $choice as $sub\_choice\_value => $sub\_choice ) {
286
$label = ( ! empty( $sub\_choice\['label'\] ) ) ? $sub\_choice\['label'\] : $sub\_choice;
287
$atts = ( ! empty( $value\[ $choice\_value \] ) && in\_array( $sub\_choice\_value, $value\[ $choice\_value \] ) ) ? "checked='checked'" : "";
288
$atts .= ( ! empty( $sub\_choice\['atts'\] ) ) ? " {$sub\_choice\['atts'\]}" : "";
289
290
$fields .= sprintf( $input\_template, $input\_name, $input\_atts, $sub\_choice\_value, "{$input\_name}\[{$choice\_value}\]", $atts, $label );
271
291
}
272
292
} else {
273
$label = (!empty($choice\['label'\])) ? $choice\['label'\] : $choice;
274
$atts \= (is\_array($value) && in\_array($choice\_value, $value)) ? "checked='checked'" : "";
275
$atts .= (!empty($choice\['atts'\])) ? " {$choice\['atts'\]}" : "";
276
277
$fields .= sprintf($input\_template, $input\_name, $input\_atts, $choice\_value, $input\_name, $atts, $label);
293
$label = ( ! empty( $choice\['label'\] ) ) ? $choice\['label'\] : $choice;
294
$atts = ( is\_array( $value ) && in\_array( $choice\_value, $value ) ) ? "checked='checked'" : "";
295
$atts .= ( ! empty( $choice\['atts'\] ) ) ? " {$choice\['atts'\]}" : "";
296
297
$fields .= sprintf( $input\_template, $input\_name, $input\_atts, $choice\_value, $input\_name, $atts, $label );
278
298
}
279
299
}
…
…
281
301
282
302
// Add helper checkboxes for bulk actions
283
if(isset($args\['select\_all'\]) || isset($args\['unselect\_all'\])) {
284
$select\_all\_label \= (!empty($args\['select\_all'\])) ? $args\['select\_all'\] : \_\_('Select all', 'permalink-manager');
285
$unselect\_all\_label = (!empty($args\['unselect\_all'\])) ? $args\['unselect\_all'\] : \_\_('Unselect all', 'permalink-manager');
303
if ( isset( $args\['select\_all'\] ) || isset( $args\['unselect\_all'\] ) ) {
304
$select\_all\_label = ( ! empty( $args\['select\_all'\] ) ) ? $args\['select\_all'\] : \_\_( 'Select all', 'permalink-manager' );
305
$unselect\_all\_label = ( ! empty( $args\['unselect\_all'\] ) ) ? $args\['unselect\_all'\] : \_\_( 'Unselect all', 'permalink-manager' );
286
306
287
307
$fields .= "<p class=\\"checkbox\_actions extra-links\\">";
288
$fields .= (isset($args\['select\_all'\])) ? "<a href=\\"#\\" class=\\"select\_all\\">{$select\_all\_label}</a> " : "";
289
$fields .= (isset($args\['unselect\_all'\])) ? "<a href=\\"#\\" class=\\"unselect\_all\\">{$unselect\_all\_label}</a>" : "";
308
$fields .= ( isset( $args\['select\_all'\] ) ) ? "<a href=\\"#\\" class=\\"select\_all\\">{$select\_all\_label}</a> " : "";
309
$fields .= ( isset( $args\['unselect\_all'\] ) ) ? "<a href=\\"#\\" class=\\"unselect\_all\\">{$unselect\_all\_label}</a>" : "";
290
310
$fields .= "</p>";
291
311
}
292
break;
312
break;
293
313
294
314
case 'single\_checkbox' :
295
315
$fields .= '<div class="single\_checkbox">';
296
if(is\_array($value)) {
297
$input\_key = preg\_replace('/(.\*)(?:\\\[(\[^\\\[\]+)\\\])$/', '$2', $input\_name);
298
$checked \= (!empty($value\[$input\_key\])) ? "checked='checked'" : "";
316
if ( is\_array( $value ) ) {
317
$input\_key = preg\_replace( '/(.\*)(?:\\\[(\[^\\\[\]+)\\\])$/', '$2', $input\_name );
318
$checked = ( ! empty( $value\[ $input\_key \] ) ) ? "checked='checked'" : "";
299
319
} else {
300
$checked = ($value == 1) ? "checked='checked'" : "";
301
}
302
$checkbox\_label = (isset($args\['checkbox\_label'\])) ? $args\['checkbox\_label'\] : '';
320
$checked = ( $value == 1 ) ? "checked='checked'" : "";
321
}
322
$checkbox\_label = ( isset( $args\['checkbox\_label'\] ) ) ? $args\['checkbox\_label'\] : '';
303
323
304
324
$fields .= "<input type='hidden' {$input\_atts} value='0' name='{$input\_name}' />";
305
325
$fields .= "<label for='{$input\_name}'><input type='checkbox' {$input\_atts} value='1' name='{$input\_name}' {$checked} /> {$checkbox\_label}</label>";
306
326
$fields .= '</div>';
307
break;
327
break;
308
328
309
329
case 'radio' :
310
330
$fields .= '<div class="radios">';
311
foreach($args\['choices'\] as $choice\_value => $choice) {
312
$label = (is\_array($choice)) ? $choice\['label'\] : $choice;
313
$atts \= ($choice\_value == $value) ? "checked='checked'" : "";
314
$atts .= (!empty($choice\['atts'\])) ? " {$choice\['atts'\]}" : "";
331
foreach ( $args\['choices'\] as $choice\_value => $choice ) {
332
$label = ( is\_array( $choice ) ) ? $choice\['label'\] : $choice;
333
$atts = ( $choice\_value == $value ) ? "checked='checked'" : "";
334
$atts .= ( ! empty( $choice\['atts'\] ) ) ? " {$choice\['atts'\]}" : "";
315
335
316
336
$fields .= "<label for='{$input\_name}\[\]'><input type='radio' {$input\_atts} value='{$choice\_value}' name='{$input\_name}\[\]' {$atts} /> {$label}</label>";
317
337
}
318
338
$fields .= '</div>';
319
break;
339
break;
320
340
321
341
case 'select' :
322
342
$fields .= '<span class="select">';
323
343
$fields .= "<select name='{$input\_name}' {$input\_atts}>";
324
foreach($args\['choices'\] as $choice\_value => $choice) {
325
$label = (is\_array($choice)) ? $choice\['label'\] : $choice;
326
$atts \= ($choice\_value == $value) ? "selected='selected'" : "";
327
$atts .= (!empty($choice\['atts'\])) ? " {$choice\['atts'\]}" : "";
328
329
if($choice == '---') {
344
foreach ( $args\['choices'\] as $choice\_value => $choice ) {
345
$label = ( is\_array( $choice ) ) ? $choice\['label'\] : $choice;
346
$atts = ( $choice\_value == $value ) ? "selected='selected'" : "";
347
$atts .= ( ! empty( $choice\['atts'\] ) ) ? " {$choice\['atts'\]}" : "";
348
349
if ( $choice == '---' ) {
330
350
$fields .= "<option disabled=\\"disabled\\">------------------</option>";
331
351
} else {
…
…
363
383
$siteurl = Permalink\_Manager\_Helper\_Functions::get\_permalink\_base();
364
384
365
if(!empty($args\['post\_type'\])) {
366
$type \= $args\['post\_type'\];
367
$type\_name \= $type\['name'\];
385
if ( ! empty( $args\['post\_type'\] ) ) {
386
$type \= $args\['post\_type'\];
387
$type\_name \= $type\['name'\];
368
388
$content\_type = 'post\_types';
369
389
370
$permastructures = (!empty($permalink\_manager\_permastructs\['post\_types'\])) ? $permalink\_manager\_permastructs\['post\_types'\] : array();
371
} else if(!empty($args\['taxonomy'\])) {
372
$type \= $args\['taxonomy'\];
373
$type\_name \= $type\['name'\];
390
$permastructures = ( ! empty( $permalink\_manager\_permastructs\['post\_types'\] ) ) ? $permalink\_manager\_permastructs\['post\_types'\] : array();
391
} else if ( ! empty( $args\['taxonomy'\] ) ) {
392
$type \= $args\['taxonomy'\];
393
$type\_name \= $type\['name'\];
374
394
$content\_type = "taxonomies";
375
395
376
$permastructures = (!empty($permalink\_manager\_permastructs\['taxonomies'\])) ? $permalink\_manager\_permastructs\['taxonomies'\] : array();
396
$permastructures = ( ! empty( $permalink\_manager\_permastructs\['taxonomies'\] ) ) ? $permalink\_manager\_permastructs\['taxonomies'\] : array();
377
397
} else {
378
398
break;
…
…
380
400
381
401
// Get permastructures
382
$default\_permastruct = trim(Permalink\_Manager\_Helper\_Functions::get\_default\_permastruct($type\_name), "/");
383
$current\_permastruct = isset($permastructures\[$type\_name\]) ? $permastructures\[$type\_name\] : $default\_permastruct;
402
$default\_permastruct = trim( Permalink\_Manager\_Helper\_Functions::get\_default\_permastruct( $type\_name ), "/" );
403
$current\_permastruct = isset( $permastructures\[ $type\_name \] ) ? $permastructures\[ $type\_name \] : $default\_permastruct;
384
404
385
405
// Append extra attributes
…
…
398
418
399
419
// 2A. Permastructure for each language
400
$languages = (array) Permalink\_Manager\_Language\_Plugins::get\_all\_languages(true);
401
if($languages) {
402
$fields .= sprintf(
403
"<h4>%s</h4><p class=\\"permastruct-instruction\\">%s</p>",
404
\_\_("Permastructure translations", "permalink-manager"),
405
\_\_("If you would like to translate the permastructures and set-up different permalink structure per language, please fill in the fields below. Otherwise the permastructure set for default language (see field above) will be applied.", "permalink-manager")
406
);
407
408
foreach($languages as $lang => $name) {
409
$current\_lang\_permastruct = isset($permastructures\["{$type\_name}\_{$lang}"\]) ? $permastructures\["{$type\_name}\_{$lang}"\] : '';
410
$lang\_siteurl = Permalink\_Manager\_Language\_Plugins::prepend\_lang\_prefix($siteurl, null, $lang);
420
$languages = Permalink\_Manager\_Language\_Plugins::get\_all\_languages( true );
421
if ( $languages ) {
422
$fields .= sprintf( "<h4>%s</h4><p class=\\"permastruct-instruction\\">%s</p>", \_\_( "Permastructure translations", "permalink-manager" ), \_\_( "If you would like to translate the permastructures and set-up different permalink structure per language, please fill in the fields below. Otherwise the permastructure set for default language (see field above) will be applied.", "permalink-manager" ) );
423
424
foreach ( $languages as $lang => $name ) {
425
$current\_lang\_permastruct = isset( $permastructures\["{$type\_name}\_{$lang}"\] ) ? $permastructures\["{$type\_name}\_{$lang}"\] : '';
426
$lang\_siteurl = Permalink\_Manager\_Language\_Plugins::prepend\_lang\_prefix( $siteurl, '', $lang );
411
427
412
428
$fields .= "<label>{$name}</label>";
413
429
$fields .= "<div class=\\"permastruct-container\\">";
414
430
$fields .= "<span><code>{$lang\_siteurl}/</code></span>";
415
$fields .= sprintf("<span><input type='text' %s value='%s' name='%s'/></span>", $input\_atts, $current\_lang\_permastruct, str\_replace("\]", "\_{$lang}\]", $input\_name));
431
$fields .= sprintf( "<span><input type='text' %s value='%s' name='%s'/></span>", $input\_atts, $current\_lang\_permastruct, str\_replace( "\]", "\_{$lang}\]", $input\_name ) );
416
432
$fields .= "</div>";
417
433
}
…
…
419
435
420
436
// 2B. Restore default permalinks
421
$fields .= sprintf(
422
"<p class=\\"default-permastruct-row columns-container\\"><span class=\\"column-2\_4\\"><strong>%s:</strong> %s</span><span class=\\"column-2\_4\\"><a href=\\"#\\" class=\\"restore-default\\"><span class=\\"dashicons dashicons-image-rotate\\"></span> %s</a></span></p>",
423
\_\_("Default permastructure", "permalink-manager"), esc\_html($default\_permastruct),
424
\_\_("Restore default permastructure", "permalink-manager")
425
);
437
$fields .= sprintf( "<p class=\\"default-permastruct-row columns-container\\"><span class=\\"column-2\_4\\"><strong>%s:</strong> %s</span><span class=\\"column-2\_4\\"><a href=\\"#\\" class=\\"restore-default\\"><span class=\\"dashicons dashicons-image-rotate\\"></span> %s</a></span></p>", \_\_( "Default permastructure", "permalink-manager" ), esc\_html( $default\_permastruct ), \_\_( "Restore default permastructure", "permalink-manager" ) );
426
438
427
439
// 2B. Do not auto-append slug field
428
$fields .= sprintf(
429
"<h4>%s</h4><div class=\\"settings-container\\">%s</div>",
430
\_\_("Permastructure settings", "permalink-manager"),
431
self::generate\_option\_field("permastructure-settings\[do\_not\_append\_slug\]\[$content\_type\]\[{$type\_name}\]", array('type' => 'single\_checkbox', 'checkbox\_label' => \_\_("Do not automatically append the slug", "permalink-manager")))
432
);
440
$fields .= sprintf( "<h4>%s</h4><div class=\\"settings-container\\">%s</div>", \_\_( "Permastructure settings", "permalink-manager" ), self::generate\_option\_field( "permastructure-settings\[do\_not\_append\_slug\]\[$content\_type\]\[{$type\_name}\]", array( 'type' => 'single\_checkbox', 'checkbox\_label' => \_\_( "Do not automatically append the slug", "permalink-manager" ) ) ) );
433
441
434
442
$fields .= "</div>";
435
443
436
444
// 3. Show toggle button
437
$fields .= sprintf(
438
"<p class=\\"permastruct-toggle-button\\"><a href=\\"#\\"><span class=\\"dashicons dashicons-admin-settings\\"></span> %s</a></p>",
439
\_\_("Show additional settings", "permalink-manager")
440
);
445
$fields .= sprintf( "<p class=\\"permastruct-toggle-button\\"><a href=\\"#\\"><span class=\\"dashicons dashicons-admin-settings\\"></span> %s</a></p>", \_\_( "Show additional settings", "permalink-manager" ) );
441
446
442
447
$fields .= "</div>";
…
…
449
454
450
455
// Get the final HTML output
451
if(isset($args\['container'\]) && $args\['container'\] == 'tools') {
456
if ( isset( $args\['container'\] ) && $args\['container'\] == 'tools' ) {
452
457
$html = "<div{$container\_class}>";
453
458
$html .= "<h4>{$label}</h4>";
…
…
456
461
$html .= $append\_content;
457
462
$html .= "</div>";
458
} else if(isset($args\['container'\]) && $args\['container'\] == 'row') {
459
$html = sprintf("<tr id=\\"%s\\" data-field=\\"%s\\" %s>", esc\_attr(preg\_replace('/(?:.\*\\\[)(.\*)(?:\\\].\*)/', '$1', $input\_name)), $input\_name, $container\_class);
460
$html .= sprintf("<th><label for=\\"%s\\">%s</label></th>", $input\_name, $args\['label'\]);
461
$html .= sprintf("<td><fieldset>%s%s</fieldset></td>", $fields, $description);
463
} else if ( isset( $args\['container'\] ) && $args\['container'\] == 'row' ) {
464
$html = sprintf( "<tr id=\\"%s\\" data-field=\\"%s\\" %s>", esc\_attr( preg\_replace( '/(?:.\*\\\[)(.\*)(?:\\\].\*)/', '$1', $input\_name ) ), $input\_name, $container\_class );
465
$html .= sprintf( "<th><label for=\\"%s\\">%s</label></th>", $input\_name, $args\['label'\] );
466
$html .= sprintf( "<td><fieldset>%s%s</fieldset></td>", $fields, $description );
462
467
$html .= "</tr>";
463
$html .= ($append\_content) ? "<tr class=\\"appended-row\\"><td colspan=\\"2\\">{$append\_content}</td></tr>" : "";
464
} else if(isset($args\['container'\]) && $args\['container'\] == 'screen-options') {
468
$html .= ( $append\_content ) ? "<tr class=\\"appended-row\\"><td colspan=\\"2\\">{$append\_content}</td></tr>" : "";
469
} else if ( isset( $args\['container'\] ) && $args\['container'\] == 'screen-options' ) {
465
470
$html = "<fieldset data-field=\\"{$input\_name}\\" {$container\_class}><legend>{$args\['label'\]}</legend>";
466
471
$html .= "<div class=\\"field-content\\">{$fields}{$description}</div>";
467
$html .= ($append\_content) ? "<div class=\\"appended-row\\">{$append\_content}</div>" : "";
472
$html .= ( $append\_content ) ? "<div class=\\"appended-row\\">{$append\_content}</div>" : "";
468
473
$html .= "</fieldset>";
469
474
} else {
…
…
471
476
}
472
477
473
return apply\_filters('permalink\_manager\_field\_output', $html);
478
return apply\_filters( 'permalink\_manager\_field\_output', $html );
474
479
}
475
480
476
481
/\*\*
477
482
\* Display hidden field to indicate posts or taxonomies admin sections
478
\*/
479
static public function section\_type\_field($type = 'post') {
480
return self::generate\_option\_field('content\_type', array('value' => $type, 'type' => 'hidden'));
481
}
482
483
/\*\*
484
\* Display the form
485
\*/
486
static public function get\_the\_form($fields = array(), $container = '', $button = array(), $sidebar = '', $nonce = array(), $wrap = false, $form\_class = '') {
483
\*
484
\* @param string $type
485
\*
486
\* @return string
487
\*/
488
static public function section\_type\_field( $type = 'post' ) {
489
return self::generate\_option\_field( 'content\_type', array( 'value' => $type, 'type' => 'hidden' ) );
490
}
491
492
/\*\*
493
\* Display the HTML output of form for provided fields array
494
\*
495
\* @param array $fields
496
\* @param string $container
497
\* @param array $button
498
\* @param string $sidebar
499
\* @param array $nonce
500
\* @param bool $wrap
501
\* @param string $form\_class
502
\*
503
\* @return string
504
\*/
505
static public function get\_the\_form( $fields = array(), $container = '', $button = array(), $sidebar = '', $nonce = array(), $wrap = false, $form\_class = '' ) {
487
506
// 1. Check if the content will be displayed in columns and button details
488
switch($container) {
507
switch ( $container ) {
489
508
case 'columns-3' :
490
$wrapper\_class \= 'columns-container';
509
$wrapper\_class \= 'columns-container';
491
510
$form\_column\_class = 'column column-2\_3';
492
$sidebar\_class \= 'column column-1\_3';
511
$sidebar\_class \= 'column column-1\_3';
493
512
break;
494
513
…
…
498
517
break;
499
518
500
// there will be more cases in future ...
519
// there will be more cases in the future ...
501
520
default :
502
521
$sidebar\_class = 'sidebar';
…
…
505
524
506
525
// 2. Process the array with button and nonce field settings
507
$button\_text \= (!empty($button\['text'\])) ? $button\['text'\] : '';
508
$button\_class \= (!empty($button\['class'\])) ? $button\['class'\] : '';
509
$button\_attributes = (!empty($button\['attributes'\])) ? $button\['attributes'\] : '';
510
$nonce\_action \= (!empty($nonce\['action'\])) ? $nonce\['action'\] : '';
511
$nonce\_name \= (!empty($nonce\['name'\])) ? $nonce\['name'\] : '';
512
$form\_classes \= (!empty($form\_class)) ? $form\_class : '';
526
$button\_text = ( ! empty( $button\['text'\] ) ) ? $button\['text'\] : '';
527
$button\_class = ( ! empty( $button\['class'\] ) ) ? $button\['class'\] : '';
528
$button\_attributes = ( ! empty( $button\['attributes'\] ) ) ? $button\['attributes'\] : '';
529
$nonce\_action = ( ! empty( $nonce\['action'\] ) ) ? $nonce\['action'\] : '';
530
$nonce\_name = ( ! empty( $nonce\['name'\] ) ) ? $nonce\['name'\] : '';
531
$form\_classes = ( ! empty( $form\_class ) ) ? $form\_class : '';
513
532
514
533
// 3. Now get the HTML output (start section row container)
515
$html = ($wrapper\_class) ? "<div class=\\"{$wrapper\_class}\\">" : '';
534
$html = ( $wrapper\_class ) ? "<div class=\\"{$wrapper\_class}\\">" : '';
516
535
517
536
// 4. Display settings tabs
518
if($container == 'tabs') {
537
if ( $container == 'tabs' ) {
519
538
// Get active section
520
$active\_tab = (!empty($\_POST\['pm\_active\_tab'\])) ? $\_POST\['pm\_active\_tab'\] : key(array\_slice($fields, 0, 1, true));
539
$active\_tab = ( ! empty( $\_POST\['pm\_active\_tab'\] ) ) ? $\_POST\['pm\_active\_tab'\] : key( array\_slice( $fields, 0, 1, true ) );
521
540
522
541
$html .= "<ul class=\\"subsubsub\\">";
523
foreach ($fields as $tab\_name => $tab) {
524
$active\_class = ($active\_tab === $tab\_name) ? 'current' : '';
525
$html .= sprintf("<li><a href=\\"%s\\" class=\\"%s\\" data-tab=\\"%s\\">%s</a></li>", "#pm\_tab\_{$tab\_name}", $active\_class, $tab\_name, $tab\['section\_name'\]);
542
foreach ( $fields as $tab\_name => $tab ) {
543
$active\_class = ( $active\_tab === $tab\_name ) ? 'current' : '';
544
$html .= sprintf( "<li><a href=\\"%s\\" class=\\"%s\\" data-tab=\\"%s\\">%s</a></li>", "#pm\_tab\_{$tab\_name}", $active\_class, $tab\_name, $tab\['section\_name'\] );
526
545
}
527
546
$html .= "</ul>";
…
…
529
548
530
549
// 5. Display some notes
531
if($sidebar\_class && $sidebar) {
550
if ( $sidebar\_class && $sidebar ) {
532
551
$html .= "<div class=\\"{$sidebar\_class}\\">";
533
552
$html .= "<div class=\\"section-notes\\">";
…
…
538
557
539
558
// 6. Start fields' section
540
$html .= ($form\_column\_class) ? "<div class=\\"{$form\_column\_class}\\">" : "";
559
$html .= ( $form\_column\_class ) ? "<div class=\\"{$form\_column\_class}\\">" : "";
541
560
$html .= "<form method=\\"POST\\" class=\\"{$form\_classes}\\">";
542
$html .= ($wrap) ? "<table class=\\"form-table\\">" : "";
561
$html .= ( $wrap ) ? "<table class=\\"form-table\\">" : "";
543
562
544
563
// 7. Loop through all fields assigned to this section
545
foreach($fields as $field\_name => $field) {
546
$tab\_name \= (isset($field\['fields'\])) ? $field\_name : '';
547
$field\_name = (!empty($field\['name'\])) ? $field\['name'\] : $field\_name;
564
foreach ( $fields as $field\_name => $field ) {
565
$tab\_name = ( isset( $field\['fields'\] ) ) ? $field\_name : '';
566
$field\_name = ( ! empty( $field\['name'\] ) ) ? $field\['name'\] : $field\_name;
548
567
549
568
// A. Display table row
550
if(isset($field\['container'\]) && $field\['container'\] == 'row') {
569
if ( isset( $field\['container'\] ) && $field\['container'\] == 'row' ) {
551
570
$row\_output = "";
552
571
553
572
// Loop through all fields assigned to this section
554
if(isset($field\['fields'\])) {
555
foreach($field\['fields'\] as $section\_field\_id => $section\_field) {
556
$section\_field\_name \= (!empty($section\_field\['name'\])) ? $section\_field\['name'\] : "{$field\_name}\[$section\_field\_id\]";
573
if ( isset( $field\['fields'\] ) ) {
574
foreach ( $field\['fields'\] as $section\_field\_id => $section\_field ) {
575
$section\_field\_name = ( ! empty( $section\_field\['name'\] ) ) ? $section\_field\['name'\] : "{$field\_name}\[$section\_field\_id\]";
557
576
$section\_field\['container'\] = 'row';
558
577
559
$row\_output .= self::generate\_option\_field($section\_field\_name, $section\_field);
578
$row\_output .= self::generate\_option\_field( $section\_field\_name, $section\_field );
560
579
}
561
580
} else {
562
$row\_output .= self::generate\_option\_field($field\_name, $field);
563
}
564
565
if(isset($field\['section\_name'\])) {
566
if($container == 'tabs') {
567
$is\_active\_tab = (!empty($active\_tab) && $active\_tab == $tab\_name) ? 'class="active-tab"' : '';
581
$row\_output .= self::generate\_option\_field( $field\_name, $field );
582
}
583
584
if ( isset( $field\['section\_name'\] ) ) {
585
if ( $container == 'tabs' ) {
586
$is\_active\_tab = ( ! empty( $active\_tab ) && $active\_tab == $tab\_name ) ? 'class="active-tab"' : '';
568
587
569
588
$html .= "<div id=\\"pm\_{$tab\_name}\\" data-tab=\\"{$tab\_name}\\" {$is\_active\_tab}>";
…
…
571
590
572
591
$html .= "<h3>{$field\['section\_name'\]}</h3>";
573
$html .= (isset($field\['append\_content'\])) ? $field\['append\_content'\] : "";
574
$html .= (isset($field\['description'\])) ? "<p class=\\"description\\">{$field\['description'\]}</p>" : "";
592
$html .= ( isset( $field\['append\_content'\] ) ) ? $field\['append\_content'\] : "";
593
$html .= ( isset( $field\['description'\] ) ) ? "<p class=\\"description\\">{$field\['description'\]}</p>" : "";
575
594
$html .= "<table class=\\"form-table\\" data-field=\\"{$field\_name}\\">{$row\_output}</table>";
576
$html .= ($container == 'tabs') ? "</div>" : "";
595
$html .= ( $container == 'tabs' ) ? "</div>" : "";
577
596
} else {
578
597
$html .= $row\_output;
579
598
}
580
}
581
// B. Display single field
599
} // B. Display single field
582
600
else {
583
$html .= self::generate\_option\_field($field\_name, $field);
584
}
585
}
586
587
$html .= ($wrap) ? "</table>" : "";
601
$html .= self::generate\_option\_field( $field\_name, $field );
602
}
603
}
604
605
$html .= ( $wrap ) ? "</table>" : "";
588
606
589
607
// 8. Add a hidden field with section name for settings page
590
if($container == 'tabs' && !empty($active\_tab)) {
591
$html .= self::generate\_option\_field('pm\_active\_tab', array('value' => $active\_tab, 'type' => 'hidden', 'readonly' => true));
608
if ( $container == 'tabs' && ! empty( $active\_tab ) ) {
609
$html .= self::generate\_option\_field( 'pm\_active\_tab', array( 'value' => $active\_tab, 'type' => 'hidden', 'readonly' => true ) );
592
610
}
593
611
594
612
// 9. End the fields' section + add button & nonce fields
595
if($nonce\_action && $nonce\_name) {
596
$html .= wp\_nonce\_field($nonce\_action, $nonce\_name, true, true);
597
$html .= self::generate\_option\_field('pm\_session\_id', array('value' => uniqid(), 'type' => 'hidden'));
598
}
599
$html .= ($button\_text) ? get\_submit\_button($button\_text, $button\_class, '', false, $button\_attributes) : "";
613
if ( $nonce\_action && $nonce\_name ) {
614
$html .= wp\_nonce\_field( $nonce\_action, $nonce\_name );
615
$html .= self::generate\_option\_field( 'pm\_session\_id', array( 'value' => uniqid(), 'type' => 'hidden' ) );
616
}
617
$html .= ( $button\_text ) ? get\_submit\_button( $button\_text, $button\_class, '', false, $button\_attributes ) : "";
600
618
$html .= '</form>';
601
$html .= ($form\_column\_class) ? "</div>" : "";
619
$html .= ( $form\_column\_class ) ? "</div>" : "";
602
620
603
621
// 10. End the section row container
604
$html .= ($wrapper\_class) ? "</div>" : "";
622
$html .= ( $wrapper\_class ) ? "</div>" : "";
605
623
606
624
return $html;
…
…
608
626
609
627
/\*\*
610
\* Display the plugin sections.
628
\* Display the plugin sections
611
629
\*/
612
630
public function display\_section() {
613
global $wpdb, $permalink\_manager\_before\_sections\_html, $permalink\_manager\_after\_sections\_html;
631
global $permalink\_manager\_after\_sections\_html;
614
632
615
633
$html = "<div id=\\"permalink-manager\\" class=\\"wrap\\">";
616
$html .= sprintf("<h2 id=\\"plugin-name-heading\\">%s <a href=\\"http://maciejbis.net\\" class=\\"author-link\\" target=\\"\_blank\\">%s</a></h2>", PERMALINK\_MANAGER\_PLUGIN\_NAME, \_\_("by Maciej Bis", "permalink-manager"));
634
$html .= sprintf( "<h2 id=\\"plugin-name-heading\\">%s <a href=\\"https://maciejbis.net\\" class=\\"author-link\\" target=\\"\_blank\\">%s</a></h2>", PERMALINK\_MANAGER\_PLUGIN\_NAME, \_\_( "by Maciej Bis", "permalink-manager" ) );
617
635
618
636
// Display the tab navigation
619
637
$html .= "<div id=\\"permalink-manager-tab-nav\\" class=\\"nav-tab-wrapper\\">";
620
foreach($this->sections as $section\_name => $section\_properties) {
621
$active\_class = ($this->active\_section === $section\_name) ? 'nav-tab-active nav-tab' : 'nav-tab';
622
$section\_url \= $this->get\_admin\_url("§ion={$section\_name}");
623
624
$html .= sprintf("<a href=\\"%s\\" class=\\"%s section\_%s\\">%s</a>", $section\_url, $active\_class, $section\_name, $section\_properties\['name'\]);
638
foreach ( $this->sections as $section\_name => $section\_properties ) {
639
$active\_class = ( $this->active\_section === $section\_name ) ? 'nav-tab-active nav-tab' : 'nav-tab';
640
$section\_url = $this->get\_admin\_url( "§ion={$section\_name}" );
641
642
$html .= sprintf( "<a href=\\"%s\\" class=\\"%s section\_%s\\">%s</a>", $section\_url, $active\_class, $section\_name, $section\_properties\['name'\] );
625
643
}
626
644
627
645
// Upgrade to Pro version
628
$html .= (self::is\_pro\_active() == false) ? sprintf("<a href=\\"%s\\" target=\\"\_blank\\" class=\\"nav-tab section\_upgrade\\">%s</a>", 'https://permalinkmanager.pro/buy-permalink-manager-pro/?utm\_source=plugin\_upgrade', \_\_('Upgrade to PRO', 'permalink-manager')) : '';
646
$html .= ( ! self::is\_pro\_active() ) ? sprintf( "<a href=\\"%s\\" target=\\"\_blank\\" class=\\"nav-tab section\_upgrade\\">%s</a>", 'https://permalinkmanager.pro/buy-permalink-manager-pro/?utm\_source=plugin\_upgrade', \_\_( 'Upgrade to PRO', 'permalink-manager' ) ) : '';
629
647
$html .= "</div>";
630
648
631
649
// Now display the active section
632
$html .= "<div id=\\"permalink-manager-sections\\">";
633
$active\_section\_array = (isset($this->sections\[$this->active\_section\])) ? $this->sections\[$this->active\_section\] : "";
634
635
// Display addidional navigation for subsections
636
if(isset($this->sections\[$this->active\_section\]\['subsections'\])) {
650
$html .= "<div id=\\"permalink-manager-sections\\">";
651
$active\_section\_array = ( isset( $this->sections\[ $this->active\_section \] ) ) ? $this->sections\[ $this->active\_section \] : "";
652
653
// Display additional navigation for subsections
654
if ( isset( $this->sections\[ $this->active\_section \]\['subsections'\] ) ) {
637
655
$html .= "<ul class=\\"subsubsub\\">";
638
foreach ($this->sections\[$this->active\_section\]\['subsections'\] as $subsection\_name => $subsection) {
639
$active\_class \= ($this->active\_subsection === $subsection\_name) ? 'current' : '';
640
$subsection\_url = $this->get\_admin\_url("§ion={$this->active\_section}&subsection={$subsection\_name}");
656
foreach ( $this->sections\[ $this->active\_section \]\['subsections'\] as $subsection\_name => $subsection ) {
657
$active\_class = ( $this->active\_subsection === $subsection\_name ) ? 'current' : '';
658
$subsection\_url = $this->get\_admin\_url( "§ion={$this->active\_section}&subsection={$subsection\_name}" );
641
659
642
660
$html .= "<li><a href=\\"{$subsection\_url}\\" class=\\"{$active\_class}\\">{$subsection\['name'\]}</a></li>";
…
…
646
664
647
665
// A. Execute the function assigned to the subsection
648
if(isset($active\_section\_array\['subsections'\]\[$this->active\_subsection\]\['function'\])) {
649
$class\_name \= $active\_section\_array\['subsections'\]\[$this->active\_subsection\]\['function'\]\['class'\];
666
if ( isset( $active\_section\_array\['subsections'\]\[ $this->active\_subsection \]\['function'\] ) ) {
667
$class\_name = $active\_section\_array\['subsections'\]\[ $this->active\_subsection \]\['function'\]\['class'\];
650
668
$section\_object = new $class\_name();
651
669
652
$section\_content = call\_user\_func(array($section\_object, $active\_section\_array\['subsections'\]\[$this->active\_subsection\]\['function'\]\['method'\]));
653
}
654
// B. Execute the function assigned to the section
655
else if(isset($active\_section\_array\['function'\])) {
656
$class\_name = $active\_section\_array\['function'\]\['class'\];
670
$section\_content = call\_user\_func( array( $section\_object, $active\_section\_array\['subsections'\]\[ $this->active\_subsection \]\['function'\]\['method'\] ) );
671
} // B. Execute the function assigned to the section
672
else if ( isset( $active\_section\_array\['function'\] ) ) {
673
$class\_name = $active\_section\_array\['function'\]\['class'\];
657
674
$section\_object = new $class\_name();
658
675
659
$section\_content = call\_user\_func(array($section\_object, $active\_section\_array\['function'\]\['method'\]));
660
}
661
// C. Display the raw HTMl output of subsection
662
else if(isset($active\_section\_array\['subsections'\]\[$this->active\_subsection\]\['html'\])) {
663
$section\_content = (isset($active\_section\_array\['subsections'\]\[$this->active\_subsection\]\['html'\])) ? $active\_section\_array\['subsections'\]\[$this->active\_subsection\]\['html'\] : "";
664
}
665
// D. Try to display the raw HTMl output of section
676
$section\_content = call\_user\_func( array( $section\_object, $active\_section\_array\['function'\]\['method'\] ) );
677
} // C. Display the raw HTMl output of subsection
678
else if ( isset( $active\_section\_array\['subsections'\]\[ $this->active\_subsection \]\['html'\] ) ) {
679
$section\_content = ( isset( $active\_section\_array\['subsections'\]\[ $this->active\_subsection \]\['html'\] ) ) ? $active\_section\_array\['subsections'\]\[ $this->active\_subsection \]\['html'\] : "";
680
} // D. Try to display the raw HTMl output of section
666
681
else {
667
$section\_content = (isset($active\_section\_array\['html'\])) ? $active\_section\_array\['html'\] : "";
682
$section\_content = ( isset( $active\_section\_array\['html'\] ) ) ? $active\_section\_array\['html'\] : "";
668
683
}
669
684
…
…
679
694
680
695
/\*\*
681
\* Display the table with updated slugs after one of the actions is triggered
682
\*/
683
static function display\_updated\_slugs($updated\_array, $return\_array = false, $display\_full\_table = true) {
684
global $permalink\_manager\_before\_sections\_html, $permalink\_manager\_after\_sections\_html;
696
\* Display the array or HTML table with updated slugs after one of the actions is triggered
697
\*
698
\* @param array $updated\_array
699
\* @param bool $return\_array
700
\* @param bool $display\_full\_table
701
\*
702
\* @return array|string
703
\*/
704
static function display\_updated\_slugs( $updated\_array, $return\_array = false, $display\_full\_table = true ) {
705
global $permalink\_manager\_before\_sections\_html, $adjust\_id\_url\_filter\_off;
685
706
686
707
$updated\_slugs\_count = 0;
687
$html = $main\_content = $alert = "";
688
689
if(is\_array($updated\_array)) {
708
$html = $main\_content = $alert = "";
709
710
// Disable "Adjust IDs for multilingual functionality" in WPML to make sure that the correct URLs are displayed in the results table
711
$adjust\_id\_url\_filter\_off = true;
712
713
if ( is\_array( $updated\_array ) ) {
690
714
// Check if slugs should be displayed
691
$first\_slug = reset($updated\_array);
692
$show\_slugs = (!empty($\_POST\['mode'\]) && $\_POST\['mode'\] == 'slugs') ? true : false;
715
$first\_slug = reset( $updated\_array );
716
$show\_slugs = ( ! empty( $\_POST\['mode'\] ) && $\_POST\['mode'\] == 'slugs' ) ? true : false;
693
717
694
718
$header\_footer = '<tr>';
695
$header\_footer .= '<th class="column-primary">' . \_\_('Title', 'permalink-manager') . '</th>';
696
if($show\_slugs) {
697
$header\_footer .= (isset($first\_slug\['old\_slug'\])) ? '<th>' . \_\_('Old Slug', 'permalink-manager') . '</th>' : "";
698
$header\_footer .= (isset($first\_slug\['new\_slug'\])) ? '<th>' . \_\_('New Slug', 'permalink-manager') . '</th>' : "";
719
$header\_footer .= sprintf( '<th class="column-primary">%s</th>', \_\_( 'Title', 'permalink-manager' ) );
720
if ( $show\_slugs ) {
721
$header\_footer .= ( isset( $first\_slug\['old\_slug'\] ) ) ? sprintf( '<th>%s</th>', \_\_( 'Old Slug', 'permalink-manager' ) ) : '';
722
$header\_footer .= ( isset( $first\_slug\['new\_slug'\] ) ) ? sprintf( '<th>%s</th>', \_\_( 'New Slug', 'permalink-manager' ) ) : '';
699
723
} else {
700
$header\_footer .= '<th>' . \_\_('Old URI', 'permalink-manager') . '</th>';
701
$header\_footer .= '<th>' . \_\_('New URI', 'permalink-manager') . '</th>';
724
$header\_footer .= sprintf( '<th>%s</th>', \_\_( 'Old URI', 'permalink-manager' ) );
725
$header\_footer .= sprintf( '<th>%s</th>', \_\_( 'New URI', 'permalink-manager' ) );
702
726
}
703
727
$header\_footer .= '</tr>';
704
728
705
foreach($updated\_array as $row) {
729
$screen\_reader\_button = sprintf( '<button type="button" class="toggle-row"><span class="screen-reader-text">%s</span></button>', \_\_( 'Show more details', 'permalink-manager' ) );
730
731
foreach ( $updated\_array as $row ) {
706
732
// Odd/even class
707
$updated\_slugs\_count++;
708
$alternate\_class = ($updated\_slugs\_count % 2 == 1) ? ' class="alternate"' : '';
733
$updated\_slugs\_count ++;
734
$alternate\_class = ( $updated\_slugs\_count % 2 == 1 ) ? ' class="alternate"' : '';
709
735
710
736
// Taxonomy
711
if(!empty($row\['tax'\])) {
712
$term\_link = get\_term\_link(intval($row\['ID'\]), $row\['tax'\]);
713
$permalink = (is\_wp\_error($term\_link)) ? "-" : $term\_link;
737
if ( ! empty( $row\['tax'\] ) ) {
738
$term\_link = get\_term\_link( intval( $row\['ID'\] ), $row\['tax'\] );
739
$permalink = ( is\_wp\_error( $term\_link ) ) ? "-" : $term\_link;
714
740
} else {
715
$permalink = get\_permalink($row\['ID'\]);
741
$permalink = get\_permalink( $row\['ID'\] );
716
742
}
717
743
718
744
// Decode permalink
719
$permalink = rawurldecode(rawurldecode($permalink));
720
721
$main\_content .= "<tr{$alternate\_class}>";
722
$main\_content .= '<td class="row-title column-primary" data-colname="' . \_\_('Title', 'permalink-manager') . '">' . $row\['item\_title'\] . "<a target=\\"\_blank\\" href=\\"{$permalink}\\"><span class=\\"small\\">{$permalink}</span></a>" . '<button type="button" class="toggle-row"><span class="screen-reader-text">' . \_\_('Show more details', 'permalink-manager') . '</span></button></td>';
723
if($show\_slugs) {
724
$main\_content .= (isset($row\['old\_slug'\])) ? '<td data-colname="' . \_\_('Old Slug', 'permalink-manager') . '">' . rawurldecode($row\['old\_slug'\]) . '</td>' : "";
725
$main\_content .= (isset($row\['new\_slug'\])) ? '<td data-colname="' . \_\_('New Slug', 'permalink-manager') . '">' . rawurldecode($row\['new\_slug'\]) . '</td>' : "";
745
$permalink = rawurldecode( rawurldecode( $permalink ) );
746
747
$main\_content .= sprintf( '<tr data-id="%s" %s>', $row\['ID'\], $alternate\_class );
748
$main\_content .= sprintf( '<td class="row-title column-primary" data-colname="%s">%s<a target="\_blank" href="%s"><span class="small">%s</span></a> %s</td>', \_\_( 'Title', 'permalink-manager' ), sanitize\_text\_field( $row\['item\_title'\] ), $permalink, $permalink, $screen\_reader\_button );
749
750
if ( $show\_slugs ) {
751
$main\_content .= ( isset( $row\['old\_slug'\] ) ) ? sprintf( '<td data-colname="%s">%s</td>', \_\_( 'Old Slug', 'permalink-manager' ), rawurldecode( $row\['old\_slug'\] ) ) : "";
752
$main\_content .= ( isset( $row\['new\_slug'\] ) ) ? sprintf( '<td data-colname="%s">%s</td>', \_\_( 'New Slug', 'permalink-manager' ), rawurldecode( $row\['new\_slug'\] ) ) : "";
726
753
} else {
727
$main\_content .= '<td data-colname="' . \_\_('Old URI', 'permalink-manager') . '">' . rawurldecode($row\['old\_uri'\]) . '</td>';
728
$main\_content .= '<td data-colname="' . \_\_('New URI', 'permalink-manager') . '">' . rawurldecode($row\['new\_uri'\]) . '</td>';
754
$main\_content .= sprintf( '<td data-colname="%s">%s</td>', \_\_( 'Old URI', 'permalink-manager' ), rawurldecode( $row\['old\_uri'\] ) );
755
$main\_content .= sprintf( '<td data-colname="%s">%s</td>', \_\_( 'New URI', 'permalink-manager' ), rawurldecode( $row\['new\_uri'\] ) );
729
756
}
730
757
$main\_content .= '</tr>';
…
…
732
759
733
760
// Merge header, footer and content
734
if($display\_full\_table) {
735
$html = '<h3 id="updated-list">' . \_\_('List of updated items', 'permalink-manager') . '</h3>';
761
if ( $display\_full\_table ) {
762
$html = sprintf( '<h3 id="updated-list">%s</h3>', \_\_( 'List of updated items', 'permalink-manager' ) );
736
763
$html .= '<table class="widefat wp-list-table updated-slugs-table">';
737
$html .= "<thead>{$header\_footer}</thead><tbody>{$main\_content}</tbody><tfoot>{$header\_footer}</tfoot>";
764
$html .= sprintf( '<thead>%s</thead><tbody>%s</tbody><tfoot>%s</tfoot>', $header\_footer, $main\_content, $header\_footer );
738
765
} else {
739
766
$html = $main\_content;
…
…
744
771
745
772
// 3. Display the alert
746
if(isset($updated\_slugs\_count)) {
747
if($updated\_slugs\_count > 0) {
773
if ( isset( $updated\_slugs\_count ) ) {
774
if ( $updated\_slugs\_count > 0 ) {
748
775
$alert\_content = sprintf( \_n( '<strong class="updated\_count">%d</strong> slug was updated!', '<strong class="updated\_count">%d</strong> slugs were updated!', $updated\_slugs\_count, 'permalink-manager' ), $updated\_slugs\_count ) . ' ';
749
$alert\_content .= sprintf( \_\_( '<a %s>Click here</a> to go to the list of updated slugs', 'permalink-manager' ), "href=\\"#updated-list\\"");
750
751
$alert = self::get\_alert\_message($alert\_content, 'updated updated\_slugs');
776
$alert\_content .= sprintf( \_\_( '<a %s>Click here</a> to go to the list of updated slugs', 'permalink-manager' ), "href=\\"#updated-list\\"" );
777
778
$alert = self::get\_alert\_message( $alert\_content, 'updated updated\_slugs' );
752
779
} else {
753
$alert = self::get\_alert\_message(\_\_( '<strong>No slugs</strong> were updated!', 'permalink-manager' ), 'error updated\_slugs');
754
}
755
}
756
757
if($return\_array) {
780
$alert = self::get\_alert\_message( \_\_( '<strong>No slugs</strong> were updated!', 'permalink-manager' ), 'error updated\_slugs' );
781
}
782
}
783
784
if ( $return\_array ) {
758
785
return array(
759
'html' \=> $html,
786
'html' \=> $html,
760
787
'alert' => $alert
761
788
);
…
…
768
795
769
796
/\*\*
770
\* Check if URI Editors should be displayed for current user
797
\* Check if URI Editor should be displayed for current user
798
\*
799
\* @return bool
771
800
\*/
772
801
public static function current\_user\_can\_edit\_uris() {
773
802
global $permalink\_manager\_options;
774
803
775
$edit\_uris\_cap = (!empty($permalink\_manager\_options\['general'\]\['edit\_uris\_cap'\])) ? $permalink\_manager\_options\['general'\]\['edit\_uris\_cap'\] : 'publish\_posts';
776
777
return current\_user\_can($edit\_uris\_cap);
804
$edit\_uris\_cap = ( ! empty( $permalink\_manager\_options\['general'\]\['edit\_uris\_cap'\] ) ) ? $permalink\_manager\_options\['general'\]\['edit\_uris\_cap'\] : 'publish\_posts';
805
806
return current\_user\_can( $edit\_uris\_cap );
778
807
}
779
808
780
809
/\*\*
781
810
\* "Quick Edit" Box
782
\*/
783
public static function quick\_edit\_column\_form($is\_taxonomy = false) {
811
\*
812
\* @return string
813
\*/
814
public static function quick\_edit\_column\_form() {
784
815
// Check the user capabilities
785
if(self::current\_user\_can\_edit\_uris() === false) {
786
return;
787
}
788
789
$html = self::generate\_option\_field('permalink-manager-quick-edit', array('value' => true, 'type' => 'hidden'));
790
$html .= "<fieldset class=\\"inline-edit-permalink\\">";
791
$html .= sprintf("<legend class=\\"inline-edit-legend\\">%s</legend>", \_\_("Permalink Manager", "permalink-manager"));
792
793
$html .= "<div class=\\"inline-edit-col\\">";
794
$html .= sprintf("<label class=\\"inline-edit-group\\"><span class=\\"title\\">%s</span><span class=\\"input-text-wrap\\">%s</span></label>",
795
\_\_("Current URI", "permalink-manager"),
796
self::generate\_option\_field("custom\_uri", array("input\_class" => "custom\_uri", "value" => ''))
797
);
816
if ( self::current\_user\_can\_edit\_uris() === false ) {
817
return '';
818
}
819
820
$html = self::generate\_option\_field( 'permalink-manager-quick-edit', array( 'value' => true, 'type' => 'hidden' ) );
821
$html .= '<fieldset class="inline-edit-permalink">';
822
$html .= sprintf( "<legend class=\\"inline-edit-legend\\">%s</legend>", \_\_( "Permalink Manager", "permalink-manager" ) );
823
824
$html .= '<div class="inline-edit-col">';
825
$html .= sprintf( "<label class=\\"inline-edit-group\\"><span class=\\"title\\">%s</span><span class=\\"input-text-wrap\\">%s</span></label>", \_\_( "Current URI", "permalink-manager" ), self::generate\_option\_field( "custom\_uri", array( "input\_class" => "custom\_uri", "value" => '' ) ) );
798
826
$html .= "</div>";
799
827
…
…
801
829
802
830
// Append nonce field & element ID
803
$html .= self::generate\_option\_field("permalink-manager-edit-uri-element-id", array("type" => "hidden", "input\_class" => "permalink-manager-edit-uri-element-id", "value" => ""));
831
$html .= self::generate\_option\_field( "permalink-manager-edit-uri-element-id", array( "type" => "hidden", "input\_class" => "permalink-manager-edit-uri-element-id", "value" => "" ) );
804
832
$html .= wp\_nonce\_field( 'permalink-manager-edit-uri-box', 'permalink-manager-nonce', true, false );
805
833
…
…
809
837
/\*\*
810
838
\* Hide "Custom URI" column
811
\*/
812
function quick\_edit\_hide\_column($hidden, $screen) {
839
\*
840
\* @param array $hidden
841
\*
842
\* @return array
843
\*/
844
function quick\_edit\_hide\_column( $hidden ) {
813
845
$hidden\[\] = 'permalink-manager-col';
846
814
847
return $hidden;
815
848
}
816
849
817
850
/\*\*
818
\* Display "Permalink Manager" box
819
\*/
820
public static function display\_uri\_box($element, $gutenberg = false) {
821
global $permalink\_manager\_options, $permalink\_manager\_uris;
851
\* Get the HTML output of URI Editor
852
\*
853
\* @param WP\_Post|WP\_Term $element
854
\* @param bool $gutenberg
855
\*
856
\* @return string
857
\*/
858
public static function display\_uri\_box( $element, $gutenberg = false ) {
859
global $permalink\_manager\_options;
822
860
823
861
// Check the user capabilities
824
if(self::current\_user\_can\_edit\_uris() === false) {
825
return;
826
}
827
828
if(!empty($element->ID)) {
829
$id \= $element\_id = $element->ID;
830
$native\_slug \= $element->post\_name;
831
$is\_draft \= (!empty($element->post\_status) && (in\_array($element->post\_status, array('draft', 'auto-draft')))) ? true : false;
832
$is\_front\_page = Permalink\_Manager\_Helper\_Functions::is\_front\_page($id);
833
834
$auto\_update\_val = get\_post\_meta($id, "auto\_update\_uri", true);
862
if ( self::current\_user\_can\_edit\_uris() === false ) {
863
return '';
864
}
865
866
if ( ! empty( $element->ID ) ) {
867
$id \= $element\_id = $element->ID;
868
$native\_slug \= $element->post\_name;
869
$is\_draft = ( ! empty( $element->post\_status ) && ( in\_array( $element->post\_status, array( 'draft', 'auto-draft' ) ) ) ) ? true : false;
870
$is\_front\_page = Permalink\_Manager\_Helper\_Functions::is\_front\_page( $id );
871
872
$auto\_update\_val = get\_post\_meta( $id, "auto\_update\_uri", true );
835
873
836
874
// Get URIs
837
$uri \= Permalink\_Manager\_URI\_Functions\_Post::get\_post\_uri($id, true, $is\_draft);
838
$default\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri($id);
839
$native\_uri \= Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri($id, true);
840
} else if(class\_exists('Permalink\_Manager\_URI\_Functions\_Tax')) {
841
$id \= $element->term\_id;
842
$element\_id \= "tax-{$id}";
875
$uri = Permalink\_Manager\_URI\_Functions\_Post::get\_post\_uri( $id, true, $is\_draft );
876
$default\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri( $id );
877
$native\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri( $id, true );
878
} else if ( class\_exists( 'Permalink\_Manager\_URI\_Functions\_Tax' ) ) {
879
$id \= $element->term\_id;
880
$element\_id \= "tax-{$id}";
843
881
$native\_slug = $element->slug;
844
882
845
$auto\_update\_val = get\_term\_meta($id, "auto\_update\_uri", true);
883
$auto\_update\_val = get\_term\_meta( $id, "auto\_update\_uri", true );
846
884
847
885
// Get URIs
848
$uri \= Permalink\_Manager\_URI\_Functions\_Tax::get\_term\_uri($element->term\_id, true);
849
$default\_uri = Permalink\_Manager\_URI\_Functions\_Tax::get\_default\_term\_uri($element->term\_id);
850
$native\_uri \= Permalink\_Manager\_URI\_Functions\_Tax::get\_default\_term\_uri($element->term\_id, true);
886
$uri = Permalink\_Manager\_URI\_Functions\_Tax::get\_term\_uri( $element->term\_id, true );
887
$default\_uri = Permalink\_Manager\_URI\_Functions\_Tax::get\_default\_term\_uri( $element->term\_id );
888
$native\_uri = Permalink\_Manager\_URI\_Functions\_Tax::get\_default\_term\_uri( $element->term\_id, true );
851
889
} else {
852
return;
890
return '';
853
891
}
854
892
…
…
856
894
$auto\_update\_def\_val = $permalink\_manager\_options\["general"\]\["auto\_update\_uris"\];
857
895
858
if($auto\_update\_def\_val == 1) {
859
$auto\_update\_def\_label = \_\_("Auto-update \\"Current URI\\"", "permalink-manager");
860
} else if($auto\_update\_def\_val == 2) {
861
$auto\_update\_def\_label = \_\_("Disable URI Editor", "permalink-manager");
896
if ( $auto\_update\_def\_val == 1 ) {
897
$auto\_update\_def\_label = \_\_( "Auto-update \\"Current URI\\"", "permalink-manager" );
898
} else if ( $auto\_update\_def\_val == 2 ) {
899
$auto\_update\_def\_label = \_\_( "Disable URI Editor", "permalink-manager" );
862
900
} else {
863
$auto\_update\_def\_label = \_\_("Don't auto-update \\"Current URI\\"", "permalink-manager");
901
$auto\_update\_def\_label = \_\_( "Don't auto-update \\"Current URI\\"", "permalink-manager" );
864
902
}
865
903
866
904
$auto\_update\_choices = array(
867
0 => array("label" => sprintf(\_\_("Use global settings \[%s\]", "permalink-manager"), $auto\_update\_def\_label), "atts" => "data-readonly=\\"{$auto\_update\_def\_val}\\""),
868
10 \=> '---',
869
-1 => array("label" => \_\_("Don't auto-update \\"Current URI\\"", "permalink-manager"), "atts" => "data-readonly=\\"0\\""),
870
-2 => array("label" => \_\_("Don't auto-update \\"Current URI\\" and exclude from the \\"Regenerate/reset\\" tool", "permalink-manager"), "atts" => "data-readonly=\\"0\\""),
871
1 => array("label" => \_\_("Auto-update \\"Current URI\\"", "permalink-manager"), "atts" => "data-readonly=\\"1\\""),
872
11 \=> '---',
873
2 => array("label" => \_\_("Disable URI Editor to disallow permalink changes", "permalink-manager"), "atts" => "data-readonly=\\"2\\""),
905
0 => array( "label" => sprintf( \_\_( "Use global settings \[%s\]", "permalink-manager" ), $auto\_update\_def\_label ), "atts" => "data-readonly=\\"{$auto\_update\_def\_val}\\"" ),
906
10 \=> '---',
907
- 1 => array( "label" => \_\_( "Don't auto-update \\"Current URI\\"", "permalink-manager" ), "atts" => "data-readonly=\\"0\\"" ),
908
- 2 => array( "label" => \_\_( "Don't auto-update \\"Current URI\\" and exclude from the \\"Regenerate/reset\\" tool", "permalink-manager" ), "atts" => "data-readonly=\\"0\\"" ),
909
1 => array( "label" => \_\_( "Auto-update \\"Current URI\\"", "permalink-manager" ), "atts" => "data-readonly=\\"1\\"" ),
910
11 \=> '---',
911
2 => array( "label" => \_\_( "Disable URI Editor to disallow permalink changes", "permalink-manager" ), "atts" => "data-readonly=\\"2\\"" ),
874
912
);
875
913
876
914
// Decode default URI
877
$default\_uri = rawurldecode($default\_uri);
915
$default\_uri = rawurldecode( $default\_uri );
878
916
879
917
// Start HTML output
880
918
// 1. Button
881
if(!$gutenberg) {
882
$html = sprintf("<span><button type=\\"button\\" class=\\"button button-small hide-if-no-js\\" id=\\"permalink-manager-toggle\\">%s</button></span>", \_\_("Permalink Manager", "permalink-manager"));
919
if ( ! $gutenberg ) {
920
$html = sprintf( "<span><button type=\\"button\\" class=\\"button button-small hide-if-no-js\\" id=\\"permalink-manager-toggle\\">%s</button></span>", \_\_( "Permalink Manager", "permalink-manager" ) );
883
921
884
922
$html .= "<div id=\\"permalink-manager\\" class=\\"postbox permalink-manager-edit-uri-box\\" style=\\"display: none;\\">";
885
923
886
924
// 2. The heading
887
$html .= "<a class=\\"close-button\\"><span class=\\"screen-reader-text\\">" . \_\_("Close: ", "permalink-manager") . \_\_("Permalink Manager", "permalink-manager") . "</span><span class=\\"close-icon\\" aria-hidden=\\"false\\"></span></a>";
888
$html .= sprintf("<h2><span>%s</span></h2>", \_\_("Permalink Manager", "permalink-manager"));
925
$html .= "<a class=\\"close-button\\"><span class=\\"screen-reader-text\\">" . \_\_( "Close: ", "permalink-manager" ) . \_\_( "Permalink Manager", "permalink-manager" ) . "</span><span class=\\"close-icon\\" aria-hidden=\\"false\\"></span></a>";
926
$html .= sprintf( "<h2><span>%s</span></h2>", \_\_( "Permalink Manager", "permalink-manager" ) );
889
927
890
928
// 3. The fields container \[start\]
…
…
895
933
896
934
// 4. Custom URI
897
if(!empty($is\_front\_page)) {
898
$custom\_uri\_field = self::generate\_option\_field("custom\_uri", array("type" => "hidden", "extra\_atts" => "data-default=\\"{$default\_uri}\\" data-element-id=\\"{$element\_id}\\"", "input\_class" => "widefat custom\_uri", "value" => rawurldecode($uri)));
899
$custom\_uri\_field .= \_\_("The custom URI cannot be edited on frontpage.", "permalink-manager");
935
if ( ! empty( $is\_front\_page ) ) {
936
$custom\_uri\_field = self::generate\_option\_field( "custom\_uri", array( "type" => "hidden", "extra\_atts" => "data-default=\\"{$default\_uri}\\" data-element-id=\\"{$element\_id}\\"", "input\_class" => "widefat custom\_uri", "value" => rawurldecode( $uri ) ) );
937
$custom\_uri\_field .= \_\_( "The custom URI cannot be edited on frontpage.", "permalink-manager" );
900
938
} else {
901
$custom\_uri\_field = self::generate\_option\_field("custom\_uri", array("extra\_atts" => "data-default=\\"{$default\_uri}\\" data-element-id=\\"{$element\_id}\\"", "input\_class" => "widefat custom\_uri", "value" => rawurldecode($uri)));
902
$custom\_uri\_field .= sprintf('<p class="uri\_locked hidden">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', \_\_('The URL above is displayed in read-only mode. To enable editing, change the "<strong>URI update mode</strong>" to <em>Don\\'t auto-update "Current URI"</em>.', 'permalink-manager'));
903
}
904
905
$html .= sprintf("<div class=\\"custom\_uri\_container\\"><p><label for=\\"custom\_uri\\" class=\\"strong\\">%s</label></p><span>%s</span><span class=\\"duplicated\_uri\_alert\\"></span></div>",
906
\_\_("Current URI", "permalink-manager"),
907
$custom\_uri\_field
908
);
939
$custom\_uri\_field = self::generate\_option\_field( "custom\_uri", array( "extra\_atts" => "data-default=\\"{$default\_uri}\\" data-element-id=\\"{$element\_id}\\"", "input\_class" => "widefat custom\_uri", "value" => rawurldecode( $uri ) ) );
940
$custom\_uri\_field .= sprintf( '<p class="uri\_locked hidden">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', \_\_( 'The URL above is displayed in read-only mode. To enable editing, change the "<strong>URI update mode</strong>" to <em>Don\\'t auto-update "Current URI"</em>.', 'permalink-manager' ) );
941
}
942
943
$html .= sprintf( "<div class=\\"custom\_uri\_container\\"><p><label for=\\"custom\_uri\\" class=\\"strong\\">%s</label></p><span>%s</span><span class=\\"duplicated\_uri\_alert\\"></span></div>", \_\_( "Current URI", "permalink-manager" ), $custom\_uri\_field );
909
944
910
945
// 5. Auto-update URI
911
if(empty($is\_front\_page)) {
912
if(!empty($auto\_update\_choices)) {
913
$html .= sprintf("<div><p><label for=\\"auto\_auri\\" class=\\"strong\\">%s %s</label></p><span>%s</span></div>",
914
\_\_("URI update mode", "permalink-manager"),
915
self::help\_tooltip(\_\_("If 'auto-update mode' is turned on, the 'Current URI' field will be automatically changed to 'Default URI' (displayed below) after the post is saved or updated.", "permalink-manager")),
916
self::generate\_option\_field("auto\_update\_uri", array("type" => "select", "input\_class" => "widefat auto\_update", "value" => $auto\_update\_val, "choices" => $auto\_update\_choices))
917
);
946
if ( empty( $is\_front\_page ) ) {
947
if ( ! empty( $auto\_update\_choices ) ) {
948
$html .= sprintf( "<div><p><label for=\\"auto\_auri\\" class=\\"strong\\">%s %s</label></p><span>%s</span></div>", \_\_( "URI update mode", "permalink-manager" ), self::help\_tooltip( \_\_( "If 'auto-update mode' is turned on, the 'Current URI' field will be automatically changed to 'Default URI' (displayed below) after the post is saved or updated.", "permalink-manager" ) ), self::generate\_option\_field( "auto\_update\_uri", array( "type" => "select", "input\_class" => "widefat auto\_update", "value" => $auto\_update\_val, "choices" => $auto\_update\_choices ) ) );
918
949
}
919
950
}
920
951
921
952
// 6. Native slug
922
if(!empty($element->ID) && !empty($permalink\_manager\_options\["general"\]\["show\_native\_slug\_field"\])) {
923
$native\_slug\_field = self::generate\_option\_field("native\_slug", array("extra\_atts" => "data-default=\\"{$native\_slug}\\" data-element-id=\\"{$element\_id}\\"", "input\_class" => "widefat native\_slug", "value" => rawurldecode($native\_slug)));
924
925
$html .= sprintf("<div class=\\"native\_slug\_container\\"><p><label for=\\"native\_slug\\" class=\\"strong\\">%s %s</label></p><span>%s</span></div>",
926
\_\_("Native slug", "permalink-manager"),
927
self::help\_tooltip(\_\_("The native slug is by default automatically used in native permalinks (when Permalink Manager is disabled).", "permalink-manager")),
928
$native\_slug\_field
929
);
930
}
931
932
if(empty($is\_front\_page)) {
953
if ( ! empty( $element->ID ) && ! empty( $permalink\_manager\_options\["general"\]\["show\_native\_slug\_field"\] ) ) {
954
$native\_slug\_field = self::generate\_option\_field( "native\_slug", array( "extra\_atts" => "data-default=\\"{$native\_slug}\\" data-element-id=\\"{$element\_id}\\"", "input\_class" => "widefat native\_slug", "value" => rawurldecode( $native\_slug ) ) );
955
956
$html .= sprintf( "<div class=\\"native\_slug\_container\\"><p><label for=\\"native\_slug\\" class=\\"strong\\">%s %s</label></p><span>%s</span></div>", \_\_( "Native slug", "permalink-manager" ), self::help\_tooltip( \_\_( "The native slug is by default automatically used in native permalinks (when Permalink Manager is disabled).", "permalink-manager" ) ), $native\_slug\_field );
957
}
958
959
if ( empty( $is\_front\_page ) ) {
933
960
// 7. Default URI
934
$html .= sprintf(
935
"<div class=\\"default-permalink-row columns-container\\"><span class=\\"column-3\_4\\"><strong>%s:</strong> %s</span><span class=\\"column-1\_4\\"><a href=\\"#\\" class=\\"restore-default\\"><span class=\\"dashicons dashicons-image-rotate\\"></span> %s</a></span></div>",
936
\_\_("Default URI", "permalink-manager"), esc\_html($default\_uri),
937
\_\_("Restore Default URI", "permalink-manager")
938
);
961
$html .= sprintf( "<div class=\\"default-permalink-row columns-container\\"><span class=\\"column-3\_4\\"><strong>%s:</strong> %s</span><span class=\\"column-1\_4\\"><a href=\\"#\\" class=\\"restore-default\\"><span class=\\"dashicons dashicons-image-rotate\\"></span> %s</a></span></div>", \_\_( "Default URI", "permalink-manager" ), esc\_html( $default\_uri ), \_\_( "Restore Default URI", "permalink-manager" ) );
939
962
940
963
// 8. Native URI info
941
if(!empty($permalink\_manager\_options\['general'\]\['redirect'\]) && ((!empty($element->post\_status) && in\_array($element->post\_status, array('auto-draft', 'trash', 'draft'))) == false)) {
942
$native\_permalink = trim(Permalink\_Manager\_Helper\_Functions::get\_permalink\_base($element), "/") . "/";
964
if ( ! empty( $permalink\_manager\_options\['general'\]\['redirect'\] ) && ! ( ! empty( $element->post\_status ) && in\_array( $element->post\_status, array( 'auto-draft', 'trash', 'draft' ) ) ) ) {
965
$native\_permalink = trim( Permalink\_Manager\_Helper\_Functions::get\_permalink\_base( $element ), "/" ) . "/";
943
966
$native\_permalink .= $native\_uri;
944
967
945
$html .= sprintf(
946
"<div class=\\"default-permalink-row columns-container\\"><span><strong>%s</strong> <a href=\\"%s\\">%s</a></span></div>",
947
\_\_("Automatic redirect for native URI enabled:", "permalink-manager"),
948
$native\_permalink,
949
rawurldecode($native\_uri)
950
);
968
$html .= sprintf( "<div class=\\"default-permalink-row columns-container\\"><span><strong>%s</strong> <a href=\\"%s\\">%s</a></span></div>", \_\_( "Automatic redirect for native URI enabled:", "permalink-manager" ), $native\_permalink, rawurldecode( $native\_uri ) );
951
969
}
952
970
}
953
971
954
972
// 9. Custom redirects
955
$html .= ($element->ID) ? self::display\_redirect\_panel($id) : self::display\_redirect\_panel("tax-{$id}");
973
$html .= ( $element->ID ) ? self::display\_redirect\_panel( $id ) : self::display\_redirect\_panel( "tax-{$id}" );
956
974
957
975
// 10. Extra save button for Gutenberg
958
if($gutenberg) {
959
$html .= sprintf(
960
"<div class=\\"default-permalink-row save-row columns-container hidden\\"><div><a href=\\"#\\" class=\\"button button-primary\\" id=\\"permalink-manager-save-button\\">%s</a></div></div>",
961
\_\_("Save permalink", "permalink-manager")
962
);
976
if ( $gutenberg ) {
977
$html .= sprintf( "<div class=\\"default-permalink-row save-row columns-container hidden\\"><div><a href=\\"#\\" class=\\"button button-primary\\" id=\\"permalink-manager-save-button\\">%s</a></div></div>", \_\_( "Save permalink", "permalink-manager" ) );
963
978
} else {
964
979
$html .= "</div>";
…
…
968
983
969
984
// 11. Append nonce field, element ID & native slug
970
$html .= self::generate\_option\_field("permalink-manager-edit-uri-element-slug", array("type" => "hidden", "value" => $native\_slug));
971
$html .= self::generate\_option\_field("permalink-manager-edit-uri-element-id", array("type" => "hidden", "value" => $element\_id));
972
$html .= wp\_nonce\_field('permalink-manager-edit-uri-box', 'permalink-manager-nonce', true, false);
985
$html .= self::generate\_option\_field( "permalink-manager-edit-uri-element-slug", array( "type" => "hidden", "value" => $native\_slug ) );
986
$html .= self::generate\_option\_field( "permalink-manager-edit-uri-element-id", array( "type" => "hidden", "value" => $element\_id ) );
987
$html .= wp\_nonce\_field( 'permalink-manager-edit-uri-box', 'permalink-manager-nonce', true, false );
973
988
974
989
return $html;
…
…
976
991
977
992
/\*\*
978
\* Display the redirect panel
979
\*/
980
public static function display\_redirect\_panel($element\_id) {
981
global $permalink\_manager\_options, $permalink\_manager\_redirects;
982
993
\* Get the HTML output of the redirect panel
994
\*
995
\* @param string|int $element\_id
996
\*
997
\* @return string
998
\*/
999
public static function display\_redirect\_panel( $element\_id ) {
983
1000
// Heading
984
1001
$html = "<div class=\\"permalink-manager redirects-row redirects-panel columns-container\\">";
985
986
$html .= sprintf(
987
"<div><a class=\\"button\\" href=\\"#\\" id=\\"toggle-redirect-panel\\">%s</a></div>",
988
\_\_("Manage redirects", "permalink-manager")
989
);
1002
$html .= sprintf( "<div><a class=\\"button\\" href=\\"#\\" id=\\"toggle-redirect-panel\\">%s</a></div>", \_\_( "Manage redirects", "permalink-manager" ) );
990
1003
991
1004
$html .= "<div id=\\"redirect-panel-inside\\">";
992
if(class\_exists('Permalink\_Manager\_Pro\_Addons')) {
993
$html .= Permalink\_Manager\_Pro\_Addons::display\_redirect\_form($element\_id);
1005
if ( class\_exists( 'Permalink\_Manager\_Pro\_Addons' ) ) {
1006
$html .= Permalink\_Manager\_Pro\_Addons::display\_redirect\_form( $element\_id );
994
1007
} else {
995
$html .= self::pro\_text(true);
1008
$html .= self::pro\_text( true );
996
1009
}
997
1010
$html .= "</div>";
998
999
1011
$html .= "</div>";
1000
1012
…
…
1003
1015
1004
1016
/\*\*
1005
\* Display error/info message
1006
\*/
1007
public static function get\_alert\_message($alert\_content = "", $alert\_type = "", $dismissable = true, $id = false) {
1017
\* Get the HTML output of error/info message
1018
\*
1019
\* @param string $alert\_content
1020
\* @param string $alert\_type
1021
\* @param bool $dismissible
1022
\* @param bool $id
1023
\*
1024
\* @return string
1025
\*/
1026
public static function get\_alert\_message( $alert\_content = "", $alert\_type = "", $dismissible = true, $id = false ) {
1008
1027
// Ignore empty messages (just in case)
1009
if(empty($alert\_content) || empty($alert\_type)) {
1028
if ( empty( $alert\_content ) || empty( $alert\_type ) ) {
1010
1029
return "";
1011
1030
}
1012
1031
1013
$class = ($dismissable) ? "is-dismissible" : "";
1014
$alert\_id = ($id) ? " data-alert\_id=\\"{$id}\\"" : "";
1015
1016
$html = sprintf( "<div class=\\"{$alert\_type} permalink-manager-notice notice {$class}\\"{$alert\_id}> %s</div>", wpautop($alert\_content) );
1017
1018
return $html;
1019
}
1020
1021
/\*\*
1022
\* Help tooltip
1023
\*/
1024
static function help\_tooltip($text = '') {
1025
$html = " <a href=\\"#\\" title=\\"{$text}\\" class=\\"help\_tooltip\\"><span class=\\"dashicons dashicons-editor-help\\"></span></a>";
1026
return $html;
1032
$class = ( $dismissible ) ? "is-dismissible" : "";
1033
$alert\_id = ( $id ) ? " data-alert\_id=\\"{$id}\\"" : "";
1034
1035
return sprintf( "<div class=\\"{$alert\_type} permalink-manager-notice notice {$class}\\"{$alert\_id}> %s</div>", wpautop( $alert\_content ) );
1036
}
1037
1038
/\*\*
1039
\* Get the HTML output of help tooltip
1040
\*
1041
\* @param string $text
1042
\*
1043
\* @return string
1044
\*/
1045
static function help\_tooltip( $text = '' ) {
1046
return " <a href=\\"#\\" title=\\"{$text}\\" class=\\"help\_tooltip\\"><span class=\\"dashicons dashicons-editor-help\\"></span></a>";
1027
1047
}
1028
1048
…
…
1034
1054
1035
1055
$html = "";
1036
if(!empty($permalink\_manager\_alerts) && is\_array($permalink\_manager\_alerts)) {
1037
foreach($permalink\_manager\_alerts as $alert\_id => $alert) {
1038
$dismissed\_transient\_name = sprintf('permalink-manager-notice\_%s', sanitize\_title($alert\_id));
1039
$dismissed \= get\_transient($dismissed\_transient\_name);
1056
if ( ! empty( $permalink\_manager\_alerts ) && is\_array( $permalink\_manager\_alerts ) ) {
1057
foreach ( $permalink\_manager\_alerts as $alert\_id => $alert ) {
1058
$dismissed\_transient\_name = sprintf( 'permalink-manager-notice\_%s', sanitize\_title( $alert\_id ) );
1059
$dismissed = get\_transient( $dismissed\_transient\_name );
1040
1060
1041
1061
// Check if alert was dismissed
1042
if(empty($dismissed)) {
1062
if ( empty( $dismissed ) ) {
1043
1063
// Display the notice only on the plugin pages
1044
if(empty($active\_section) && !empty($alert\['plugin\_only'\])) { continue; }
1064
if ( empty( $active\_section ) && ! empty( $alert\['plugin\_only'\] ) ) {
1065
continue;
1066
}
1045
1067
1046
1068
// Check if the notice did not expire
1047
if(isset($alert\['until'\]) && (time() > strtotime($alert\['until'\]))) { continue; }
1048
1049
$html .= self::get\_alert\_message($alert\['txt'\], $alert\['type'\], true, $alert\_id);
1069
if ( isset( $alert\['until'\] ) && ( time() > strtotime( $alert\['until'\] ) ) ) {
1070
continue;
1071
}
1072
1073
$html .= self::get\_alert\_message( $alert\['txt'\], $alert\['type'\], true, $alert\_id );
1050
1074
}
1051
1075
}
…
…
1066
1090
/\*\*
1067
1091
\* Check if Permalink Manager Pro is active
1068
\*/
1069
public static function is\_pro\_active($return\_text = false) {
1070
if(defined('PERMALINK\_MANAGER\_PRO') && PERMALINK\_MANAGER\_PRO == true) {
1071
$is\_pro = true;
1092
\*
1093
\* @return bool
1094
\*/
1095
public static function is\_pro\_active() {
1096
if ( defined( 'PERMALINK\_MANAGER\_PRO' ) && class\_exists( 'Permalink\_Manager\_Pro\_Functions' ) ) {
1097
// Check if license is active
1098
$exp\_date = Permalink\_Manager\_Pro\_Functions::get\_expiration\_date( true );
1099
1100
$is\_pro = ( $exp\_date > 2 ) ? false : true;
1072
1101
} else {
1073
1102
$is\_pro = false;
1074
1103
}
1075
1104
1076
// Check if license is active
1077
if(class\_exists('Permalink\_Manager\_Pro\_Functions')) {
1078
$exp\_date = Permalink\_Manager\_Pro\_Functions::get\_expiration\_date(true);
1079
1080
$is\_pro = ($exp\_date > 2) ? false : true;
1105
return $is\_pro;
1106
}
1107
1108
/\*\*
1109
\* Display the license expiration date (in Pro version) or information about the premium functionality
1110
\*
1111
\* @param string $text\_only
1112
\*
1113
\* @return string
1114
\*/
1115
static function pro\_text( $text\_only = false ) {
1116
if ( class\_exists( 'Permalink\_Manager\_Pro\_Functions' ) ) {
1117
$text = Permalink\_Manager\_Pro\_Functions::get\_expiration\_date( false, true );
1081
1118
} else {
1082
$is\_pro = false;
1083
}
1084
1085
return $is\_pro;
1086
}
1087
1088
static function pro\_text($text\_only = false) {
1089
if(class\_exists('Permalink\_Manager\_Pro\_Functions')) {
1090
$text = Permalink\_Manager\_Pro\_Functions::get\_expiration\_date(false, true);
1091
} else {
1092
$text = sprintf(\_\_('This functionality is available only in <a href="%s" target="\_blank">Permalink Manager Pro</a>.', 'permalink-manager'), PERMALINK\_MANAGER\_WEBSITE);
1093
}
1094
1095
return ($text\_only) ? $text : sprintf("<div class=\\"alert info\\"> %s</div>", wpautop($text, 'alert', false));
1119
$text = sprintf( \_\_( 'This functionality is available only in <a href="%s" target="\_blank">Permalink Manager Pro</a>.', 'permalink-manager' ), PERMALINK\_MANAGER\_WEBSITE );
1120
}
1121
1122
return ( $text\_only ) ? $text : sprintf( "<div class=\\"alert info\\"> %s</div>", wpautop( $text, 'alert' ) );
1096
1123
}
1097
1124
permalink-manager/trunk/includes/core/permalink-manager-core-functions.php
r2818142
r2833667
2
2
3
3
/\*\*
4
\* Core functions
5
\*/
6
class Permalink\_Manager\_Core\_Functions extends Permalink\_Manager\_Class {
4
\* Core functions
5
\*/
6
class Permalink\_Manager\_Core\_Functions {
7
7
8
8
public function \_\_construct() {
9
add\_action( 'init', array($this, 'init\_hooks'), 99);
9
add\_action( 'init', array( $this, 'init\_hooks' ), 99 );
10
10
}
11
11
12
/\*\*
13
\* Add hooks used by plugin to change the way the permalinks are detected
14
\*
15
\* @return false|void
16
\*/
12
17
function init\_hooks() {
13
18
global $permalink\_manager\_options;
14
19
15
20
// Trailing slashes
16
add\_filter( 'permalink\_manager\_filter\_final\_term\_permalink', array($this, 'control\_trailing\_slashes'), 9);
17
add\_filter( 'permalink\_manager\_filter\_final\_post\_permalink', array($this, 'control\_trailing\_slashes'), 9);
18
add\_filter( 'permalink\_manager\_filter\_post\_sample\_uri', array($this, 'control\_trailing\_slashes'), 9);
19
add\_filter( 'wpseo\_canonical', array($this, 'control\_trailing\_slashes'), 9);
20
add\_filter( 'wpseo\_opengraph\_url', array($this, 'control\_trailing\_slashes'), 9);
21
add\_filter( 'paginate\_links', array($this, 'control\_trailing\_slashes'), 9);
21
add\_filter( 'permalink\_manager\_filter\_final\_term\_permalink', array( $this, 'control\_trailing\_slashes' ), 9 );
22
add\_filter( 'permalink\_manager\_filter\_final\_post\_permalink', array( $this, 'control\_trailing\_slashes' ), 9 );
23
add\_filter( 'permalink\_manager\_filter\_post\_sample\_uri', array( $this, 'control\_trailing\_slashes' ), 9 );
24
add\_filter( 'wpseo\_canonical', array( $this, 'control\_trailing\_slashes' ), 9 );
25
add\_filter( 'wpseo\_opengraph\_url', array( $this, 'control\_trailing\_slashes' ), 9 );
26
add\_filter( 'paginate\_links', array( $this, 'control\_trailing\_slashes' ), 9 );
22
27
23
28
/\*\*
…
…
25
30
\*/
26
31
// Do not trigger in back-end
27
if(is\_admin()) { return false; }
32
if ( is\_admin() ) {
33
return false;
34
}
28
35
29
36
// Do not trigger if Customizer is loaded
30
if(function\_exists('is\_customize\_preview') && is\_customize\_preview()) { return false; }
37
if ( function\_exists( 'is\_customize\_preview' ) && is\_customize\_preview() ) {
38
return false;
39
}
31
40
32
41
// Use the URIs set in this plugin
33
add\_filter( 'request', array($this, 'detect\_post'), 0, 1 );
42
add\_filter( 'request', array( $this, 'detect\_post' ), 0, 1 );
34
43
35
44
// Redirect from old URIs to new URIs + adjust canonical redirect settings
36
add\_action( 'template\_redirect', array($this, 'new\_uri\_redirect\_and\_404'), 1);
37
add\_action( 'wp', array($this, 'adjust\_canonical\_redirect'), 1);
38
39
// Case insensitive permalinks
40
if(!empty($permalink\_manager\_options\['general'\]\['case\_insensitive\_permalinks'\])) {
41
add\_action( 'parse\_request', array($this, 'case\_insensitive\_permalinks'), 0);
45
add\_action( 'template\_redirect', array( $this, 'new\_uri\_redirect\_and\_404' ), 1 );
46
add\_action( 'wp', array( $this, 'adjust\_canonical\_redirect' ), 1 );
47
48
// Case\-insensitive permalinks
49
if ( ! empty( $permalink\_manager\_options\['general'\]\['case\_insensitive\_permalinks'\] ) ) {
50
add\_action( 'parse\_request', array( $this, 'case\_insensitive\_permalinks' ), 0 );
42
51
}
43
52
// Force 404 on non-existing pagination pages
44
if(!empty($permalink\_manager\_options\['general'\]\['pagination\_redirect'\])) {
45
add\_action( 'wp', array($this, 'fix\_pagination\_pages'), 0);
53
if ( ! empty( $permalink\_manager\_options\['general'\]\['pagination\_redirect'\] ) ) {
54
add\_action( 'wp', array( $this, 'fix\_pagination\_pages' ), 0 );
46
55
}
47
56
}
48
57
49
58
/\*\*
50
\* The most important Permalink Manager function
51
\*/
52
public static function detect\_post($query, $request\_url = false, $return\_object = false) {
53
global $wpdb, $wp, $wp\_rewrite, $permalink\_manager, $permalink\_manager\_uris, $wp\_filter, $permalink\_manager\_options, $pm\_query;
59
\* Change the request array used by WordPress to load specific content item (post, term, archive, etc.)
60
\*
61
\* @param array $query
62
\* @param bool $request\_url
63
\* @param bool $return\_object
64
\*
65
\* @return array|WP\_Post|WP\_Term
66
\*/
67
public static function detect\_post( $query, $request\_url = false, $return\_object = false ) {
68
global $wpdb, $wp, $wp\_rewrite, $permalink\_manager\_uris, $permalink\_manager\_options, $pm\_query;
54
69
55
70
// Check if the array with custom URIs is set
56
if(!(is\_array($permalink\_manager\_uris))) return $query;
71
if ( ! ( is\_array( $permalink\_manager\_uris ) ) ) {
72
return $query;
73
}
57
74
58
75
// Used in debug mode & endpoints
…
…
60
77
61
78
/\*\*
62
\* 1. Prepare URL and check if it is correct (make sure that both requested URL & home\_url share the same protoocl and get rid of www prefix)
63
\*/
64
$request\_url = (!empty($request\_url)) ? parse\_url($request\_url, PHP\_URL\_PATH) : $\_SERVER\['REQUEST\_URI'\];
65
$request\_url = strtok($request\_url, "?");
79
\* 1. Prepare URL and check if it is correct (make sure that both requested URL & home\_url share the same protocol and get rid of www prefix)
80
\*/
81
$request\_url = ( ! empty( $request\_url ) ) ? parse\_url( $request\_url, PHP\_URL\_PATH ) : $\_SERVER\['REQUEST\_URI'\];
82
$request\_url = strtok( $request\_url, "?" );
66
83
67
84
// Make sure that either $\_SERVER\['SERVER\_NAME'\] or $\_SERVER\['HTTP\_HOST'\] are set
68
if(empty($\_SERVER\['HTTP\_HOST'\]) && empty($\_SERVER\['SERVER\_NAME'\])) { return $query; }
69
70
$http\_host = (!empty($\_SERVER\['HTTP\_HOST'\])) ? $\_SERVER\['HTTP\_HOST'\] : preg\_replace('/www\\./i', '', $\_SERVER\['SERVER\_NAME'\]);
71
$request\_url = sprintf("http://%s%s", str\_replace("www.", "", $http\_host), $request\_url);
72
$raw\_home\_url = trim(get\_option('home'));
73
$home\_url = preg\_replace("/http(s)?:\\/\\/(www\\.)?(.+?)\\/?$/", "http://$3", $raw\_home\_url);
74
75
if(filter\_var($request\_url, FILTER\_VALIDATE\_URL)) {
85
if ( empty( $\_SERVER\['HTTP\_HOST'\] ) && empty( $\_SERVER\['SERVER\_NAME'\] ) ) {
86
return $query;
87
}
88
89
$http\_host = ( ! empty( $\_SERVER\['HTTP\_HOST'\] ) ) ? $\_SERVER\['HTTP\_HOST'\] : preg\_replace( '/www\\./i', '', $\_SERVER\['SERVER\_NAME'\] );
90
$request\_url = sprintf( "http://%s%s", str\_replace( "www.", "", $http\_host ), $request\_url );
91
$raw\_home\_url = trim( get\_option( 'home' ) );
92
$home\_url = preg\_replace( "/http(s)?:\\/\\/(www\\.)?(.+?)\\/?$/", "http://$3", $raw\_home\_url );
93
94
if ( filter\_var( $request\_url, FILTER\_VALIDATE\_URL ) ) {
76
95
// Check if "Deep Detect" is enabled
77
$deep\_detect\_enabled = apply\_filters('permalink\_manager\_deep\_uri\_detect', true);
96
$deep\_detect\_enabled = apply\_filters( 'permalink\_manager\_deep\_uri\_detect', true );
78
97
79
98
// Sanitize the URL
…
…
81
100
82
101
// Keep only the URI
83
$request\_url = str\_replace($home\_url, "", $request\_url);
102
$request\_url = str\_replace( $home\_url, "", $request\_url );
84
103
85
104
// Hotfix for language plugins
86
if(filter\_var($request\_url, FILTER\_VALIDATE\_URL)) {
87
$request\_url = parse\_url($request\_url, PHP\_URL\_PATH);
88
}
89
90
$request\_url = trim($request\_url, "/");
105
if ( filter\_var( $request\_url, FILTER\_VALIDATE\_URL ) ) {
106
$request\_url = parse\_url( $request\_url, PHP\_URL\_PATH );
107
}
108
109
$request\_url = trim( $request\_url, "/" );
91
110
92
111
// Get all the endpoints & pattern
93
112
$endpoints = Permalink\_Manager\_Helper\_Functions::get\_endpoints();
94
$pattern \= "/^(.+?)(?|\\/({$endpoints})(?|\\/(.\*)|$)|\\/()(\[\\d\]+)\\/?)?$/i";
113
$pattern = "/^(.+?)(?|\\/({$endpoints})(?|\\/(.\*)|$)|\\/(\[\\d\]+)\\/?)?$/i";
95
114
96
115
// Use default REGEX to detect post
97
preg\_match($pattern, $request\_url, $regex\_parts);
98
$uri\_parts\['lang'\] \= false;
99
$uri\_parts\['uri'\] \= (!empty($regex\_parts\[1\])) ? $regex\_parts\[1\] : "";
100
$uri\_parts\['endpoint'\] \= (!empty($regex\_parts\[2\])) ? $regex\_parts\[2\] : "";
101
$uri\_parts\['endpoint\_value'\] = (!empty($regex\_parts\[3\])) ? $regex\_parts\[3\] : "";
116
preg\_match( $pattern, $request\_url, $regex\_parts );
117
$uri\_parts\['lang'\] \= false;
118
$uri\_parts\['uri'\] = ( ! empty( $regex\_parts\[1\] ) ) ? $regex\_parts\[1\] : "";
119
$uri\_parts\['endpoint'\] = ( ! empty( $regex\_parts\[2\] ) ) ? $regex\_parts\[2\] : "";
120
$uri\_parts\['endpoint\_value'\] = ( ! empty( $regex\_parts\[3\] ) ) ? $regex\_parts\[3\] : "";
102
121
103
122
// Allow to filter the results by third-parties + store the URI parts with $pm\_query global
104
$uri\_parts = apply\_filters('permalink\_manager\_detect\_uri', $uri\_parts, $request\_url, $endpoints);
123
$uri\_parts = apply\_filters( 'permalink\_manager\_detect\_uri', $uri\_parts, $request\_url, $endpoints );
105
124
106
125
// Support comment pages
107
preg\_match("/(.\*)\\/{$wp\_rewrite->comments\_pagination\_base}-(\[\\d\]+)/", $uri\_parts\['uri'\], $regex\_parts);
108
if(!empty($regex\_parts\[2\])) {
109
$uri\_parts\['uri'\] \= $regex\_parts\[1\];
110
$uri\_parts\['endpoint'\] \= 'cpage';
126
preg\_match( "/(.\*)\\/{$wp\_rewrite->comments\_pagination\_base}-(\[\\d\]+)/", $uri\_parts\['uri'\], $regex\_parts );
127
if ( ! empty( $regex\_parts\[2\] ) ) {
128
$uri\_parts\['uri'\] \= $regex\_parts\[1\];
129
$uri\_parts\['endpoint'\] \= 'cpage';
111
130
$uri\_parts\['endpoint\_value'\] = $regex\_parts\[2\];
112
131
}
113
132
114
133
// Support pagination endpoint
115
if($uri\_parts\['endpoint'\] == $wp\_rewrite->pagination\_base) {
134
if ( $uri\_parts\['endpoint'\] == $wp\_rewrite->pagination\_base ) {
116
135
$uri\_parts\['endpoint'\] = 'page';
117
136
}
118
137
119
138
// Stop the function if $uri\_parts is empty
120
if(empty($uri\_parts)) return $query;
139
if ( empty( $uri\_parts ) ) {
140
return $query;
141
}
121
142
122
143
// Store the URI parts in a separate global variable
…
…
124
145
125
146
// Get the URI parts from REGEX parts
126
$lang = $uri\_parts\['lang'\];
127
$uri \= $uri\_parts\['uri'\];
128
$endpoint \= $uri\_parts\['endpoint'\];
147
// $lang \= $uri\_parts\['lang'\];
148
$uri \= $uri\_parts\['uri'\];
149
$endpoint \= $uri\_parts\['endpoint'\];
129
150
$endpoint\_value = $uri\_parts\['endpoint\_value'\];
130
151
131
152
// Trim slashes
132
$uri = trim($uri, "/");
153
$uri = trim( $uri, "/" );
133
154
134
155
// Ignore URLs with no URI grabbed
135
if(empty($uri)) return $query;
156
if ( empty( $uri ) ) {
157
return $query;
158
}
136
159
137
160
// Store an array with custom permalinks in a separate variable
…
…
139
162
140
163
// Check what content type should be loaded in case of duplicate ("posts" or "terms")
141
$duplicates\_priority = apply\_filters('permalink\_manager\_duplicates\_priority', false);
142
if($duplicates\_priority !== false) {
143
$uri\_count = array\_count\_values($all\_uris);
144
145
foreach($uri\_count as $duplicated\_uri => $count) {
146
if($count <= 1) { continue; }
147
148
$duplicates\_ids = array\_keys($all\_uris, $duplicated\_uri);
149
150
foreach($duplicates\_ids as $id) {
151
if($duplicates\_priority == 'posts' && !is\_numeric($id)) {
152
unset($all\_uris\[$id\]);
153
} else if($duplicates\_priority !== 'posts' && is\_numeric($id)) {
154
unset($all\_uris\[$id\]);
164
$duplicates\_priority = apply\_filters( 'permalink\_manager\_duplicates\_priority', false );
165
if ( $duplicates\_priority !== false ) {
166
$uri\_count = array\_count\_values( $all\_uris );
167
168
foreach ( $uri\_count as $duplicated\_uri => $count ) {
169
if ( $count <= 1 ) {
170
continue;
171
}
172
173
$duplicates\_ids = array\_keys( $all\_uris, $duplicated\_uri );
174
175
foreach ( $duplicates\_ids as $id ) {
176
if ( $duplicates\_priority == 'posts' && ! is\_numeric( $id ) ) {
177
unset( $all\_uris\[ $id \] );
178
} else if ( $duplicates\_priority !== 'posts' && is\_numeric( $id ) ) {
179
unset( $all\_uris\[ $id \] );
155
180
}
156
181
}
…
…
159
184
160
185
// Exclude draft posts
161
$exclude\_drafts = (isset($permalink\_manager\_options\['general'\]\['ignore\_drafts'\])) ? $permalink\_manager\_options\['general'\]\['ignore\_drafts'\] : false;
162
$exclude\_drafts = apply\_filters('permalink\_manager\_exclude\_drafts', $exclude\_drafts);
163
164
if($exclude\_drafts) {
165
$post\_ids = $wpdb->get\_col("SELECT DISTINCT ID FROM {$wpdb->posts} AS p WHERE p.post\_status = 'draft' ORDER BY ID DESC");
166
if(!empty($post\_ids)) {
167
foreach($post\_ids as $post\_id) {
168
unset($permalink\_manager\_uris\[$post\_id\]);
186
$exclude\_drafts = ( isset( $permalink\_manager\_options\['general'\]\['ignore\_drafts'\] ) ) ? $permalink\_manager\_options\['general'\]\['ignore\_drafts'\] : false;
187
$exclude\_drafts = apply\_filters( 'permalink\_manager\_exclude\_drafts', $exclude\_drafts );
188
189
if ( $exclude\_drafts ) {
190
$post\_ids = $wpdb->get\_col( "SELECT DISTINCT ID FROM {$wpdb->posts} AS p WHERE p.post\_status = 'draft' ORDER BY ID DESC" );
191
if ( ! empty( $post\_ids ) ) {
192
foreach ( $post\_ids as $post\_id ) {
193
unset( $permalink\_manager\_uris\[ $post\_id \] );
169
194
}
170
195
}
…
…
172
197
173
198
// Flip array for better performance
174
$all\_uris = array\_flip($all\_uris);
199
$all\_uris = array\_flip( $all\_uris );
175
200
176
201
// Attempt 1.
177
202
// Find the element ID
178
$element\_id = isset($all\_uris\[$uri\]) ? $all\_uris\[$uri\] : false;
179
180
// Atempt 2.
203
$element\_id = isset( $all\_uris\[ $uri \] ) ? $all\_uris\[ $uri \] : false;
204
205
// Attempt 2.
181
206
// Decode both request URI & URIs array & make them lowercase (and save in a separate variable)
182
if(empty($element\_id)) {
183
$uri = strtolower(urldecode($uri));
184
185
foreach($all\_uris as $raw\_uri => $uri\_id) {
186
$raw\_uri \= urldecode($raw\_uri);
187
$all\_uris\[$raw\_uri\] = $uri\_id;
207
if ( empty( $element\_id ) ) {
208
$uri = strtolower( urldecode( $uri ) );
209
210
foreach ( $all\_uris as $raw\_uri => $uri\_id ) {
211
$raw\_uri = urldecode( $raw\_uri );
212
$all\_uris\[ $raw\_uri \] = $uri\_id;
188
213
}
189
214
190
215
// Convert array keys lowercase
191
$all\_uris = array\_change\_key\_case($all\_uris, CASE\_LOWER);
192
193
$element\_id = isset($all\_uris\[$uri\]) ? $all\_uris\[$uri\] : $element\_id;
194
}
195
196
// Atempt 3.
216
$all\_uris = array\_change\_key\_case( $all\_uris );
217
218
$element\_id = isset( $all\_uris\[ $uri \] ) ? $all\_uris\[ $uri \] : $element\_id;
219
}
220
221
// Attempt 3.
197
222
// Check again in case someone used post/tax IDs instead of slugs
198
if($deep\_detect\_enabled && is\_numeric($endpoint\_value) && isset($all\_uris\["{$uri}/{$endpoint\_value}"\])) {
199
$element\_id \= $all\_uris\["{$uri}/{$endpoint\_value}"\];
223
if ( $deep\_detect\_enabled && is\_numeric( $endpoint\_value ) && isset( $all\_uris\["{$uri}/{$endpoint\_value}"\] ) ) {
224
$element\_id \= $all\_uris\["{$uri}/{$endpoint\_value}"\];
200
225
$endpoint\_value = $endpoint = "";
201
226
}
202
227
203
// Atempt 4.
228
// Attempt 4.
204
229
// Check again for attachment custom URIs
205
if(empty($element\_id) && isset($old\_query\['attachment'\])) {
206
$element\_id = isset($all\_uris\["{$uri}/{$endpoint}/{$endpoint\_value}"\]) ? $all\_uris\["{$uri}/{$endpoint}/{$endpoint\_value}"\] : $element\_id;
207
208
if($element\_id) {
230
if ( empty( $element\_id ) && isset( $old\_query\['attachment'\] ) ) {
231
$element\_id = isset( $all\_uris\["{$uri}/{$endpoint}/{$endpoint\_value}"\] ) ? $all\_uris\["{$uri}/{$endpoint}/{$endpoint\_value}"\] : $element\_id;
232
233
if ( $element\_id ) {
209
234
$endpoint\_value = $endpoint = "";
210
235
}
…
…
212
237
213
238
// Allow to filter the item\_id by third-parties after initial detection
214
$element\_id = apply\_filters('permalink\_manager\_detected\_element\_id', $element\_id, $uri\_parts, $request\_url);
239
$element\_id = apply\_filters( 'permalink\_manager\_detected\_element\_id', $element\_id, $uri\_parts, $request\_url );
215
240
216
241
// Clear the original query before it is filtered
217
$query = ($element\_id) ? array() : $query;
218
219
/\*\*
220
\* 3A. Custom URI assigned to taxonomy
221
\*/
222
if(strpos($element\_id, 'tax-') !== false) {
242
$query = ( $element\_id ) ? array() : $query;
243
244
/\*\*
245
\* 3A. Custom URI assigned to taxonomy
246
\*/
247
if ( strpos( $element\_id, 'tax-' ) !== false ) {
223
248
// Remove the "tax-" prefix
224
$element\_id = intval(preg\_replace("/\[^0-9\]/", "", $element\_id));
249
$element\_id = intval( preg\_replace( "/\[^0-9\]/", "", $element\_id ) );
225
250
226
251
// Filter detected post ID
227
$element\_id = apply\_filters('permalink\_manager\_detected\_term\_id', intval($element\_id), $uri\_parts, true);
252
$element\_id = apply\_filters( 'permalink\_manager\_detected\_term\_id', $element\_id, $uri\_parts, true );
228
253
229
254
// Get the variables to filter wp\_query and double-check if taxonomy exists
230
$term \= get\_term($element\_id);
231
$term\_taxonomy = (!empty($term->taxonomy)) ? $term->taxonomy : false;
255
$term = get\_term( $element\_id );
256
$term\_taxonomy = ( ! empty( $term->taxonomy ) ) ? $term->taxonomy : false;
232
257
233
258
// Check if term is allowed
234
$disabled = ($term\_taxonomy && Permalink\_Manager\_Helper\_Functions::is\_term\_excluded($term)) ? true : false;
259
$disabled = ( $term\_taxonomy && Permalink\_Manager\_Helper\_Functions::is\_term\_excluded( $term ) ) ? true : false;
235
260
236
261
// Proceed only if the term is not removed and its taxonomy is not disabled
237
if(!$disabled && $term\_taxonomy) {
262
if ( ! $disabled && $term\_taxonomy ) {
238
263
// Get some term data
239
if($term\_taxonomy == 'category') {
264
if ( $term\_taxonomy == 'category' ) {
240
265
$query\_parameter = 'category\_name';
241
} else if($term\_taxonomy == 'post\_tag') {
266
} else if ( $term\_taxonomy == 'post\_tag' ) {
242
267
$query\_parameter = 'tag';
243
268
} else {
244
269
$query\["taxonomy"\] = $term\_taxonomy;
245
$query\_parameter \= $term\_taxonomy;
246
}
247
$term\_ancestors = get\_ancestors($element\_id, $term\_taxonomy);
248
$final\_uri \= $term->slug;
270
$query\_parameter \= $term\_taxonomy;
271
}
272
$term\_ancestors = get\_ancestors( $element\_id, $term\_taxonomy );
273
$final\_uri \= $term->slug;
249
274
250
275
// Fix for hierarchical terms
251
if(!empty($term\_ancestors)) {
252
foreach ($term\_ancestors as $parent\_id) {
253
$parent = get\_term((int) $parent\_id, $term\_taxonomy);
254
if(!empty($parent->slug)) {
276
if ( ! empty( $term\_ancestors ) ) {
277
foreach ( $term\_ancestors as $parent\_id ) {
278
$parent = get\_term( $parent\_id, $term\_taxonomy );
279
if ( ! empty( $parent->slug ) ) {
255
280
$final\_uri = $parent->slug . '/' . $final\_uri;
256
281
}
…
…
258
283
}
259
284
260
//$query\["term"\] = $final\_uri;
261
$query\["term"\] = $term->slug;
262
//$query\[$query\_parameter\] = $final\_uri;
263
$query\[$query\_parameter\] = $term->slug;
264
} else if($disabled) {
285
// $query\["term"\] = $final\_uri;
286
// $query\[$query\_parameter\] = $final\_uri;
287
288
$query\["term"\] = $term->slug;
289
$query\[ $query\_parameter \] = $term->slug;
290
} else if ( $disabled ) {
265
291
$broken\_uri = true;
266
$query \= $old\_query;
292
$query \= $old\_query;
267
293
} else {
268
294
$query = $old\_query;
…
…
270
296
}
271
297
/\*\*
272
\* 3B. Custom URI assigned to post/page/cpt item
273
\*/
274
else if(isset($element\_id) && is\_numeric($element\_id)) {
298
\* 3B. Custom URI assigned to post/page/CPT item
299
\*/ else if ( isset( $element\_id ) && is\_numeric( $element\_id ) ) {
275
300
// Fix for revisions
276
$is\_revision = wp\_is\_post\_revision($element\_id);
277
if($is\_revision) {
301
$is\_revision = wp\_is\_post\_revision( $element\_id );
302
if ( $is\_revision ) {
278
303
$revision\_id = $element\_id;
279
$element\_id \= $is\_revision;
304
$element\_id \= $is\_revision;
280
305
}
281
306
282
307
// Filter detected post ID
283
$element\_id = apply\_filters('permalink\_manager\_detected\_post\_id', $element\_id, $uri\_parts);
284
285
$post\_to\_load = get\_post($element\_id);
286
$final\_uri \= (!empty($post\_to\_load->post\_name)) ? $post\_to\_load->post\_name : false;
287
$post\_type \= (!empty($post\_to\_load->post\_type)) ? $post\_to\_load->post\_type : false;
308
$element\_id = apply\_filters( 'permalink\_manager\_detected\_post\_id', $element\_id, $uri\_parts );
309
310
$post\_to\_load = get\_post( $element\_id );
311
$final\_uri = ( ! empty( $post\_to\_load->post\_name ) ) ? $post\_to\_load->post\_name : false;
312
$post\_type = ( ! empty( $post\_to\_load->post\_type ) ) ? $post\_to\_load->post\_type : false;
288
313
289
314
// Check if post is allowed
290
$disabled = ($post\_type && Permalink\_Manager\_Helper\_Functions::is\_post\_excluded($post\_to\_load)) ? true : false;
315
$disabled = ( $post\_type && Permalink\_Manager\_Helper\_Functions::is\_post\_excluded( $post\_to\_load ) ) ? true : false;
291
316
292
317
// Proceed only if the term is not removed and its taxonomy is not disabled
293
if(!$disabled && $post\_type) {
294
$post\_type\_object = get\_post\_type\_object($post\_type);
318
if ( ! $disabled && $post\_type ) {
319
$post\_type\_object = get\_post\_type\_object( $post\_type );
295
320
296
321
// Fix for hierarchical CPT & pages
297
if(!(empty($post\_to\_load->ancestors)) && !empty($post\_type\_object->hierarchical)) {
298
foreach ($post\_to\_load->ancestors as $parent) {
299
$parent = get\_post($parent);
300
if($parent && $parent->post\_name) {
322
if ( ! ( empty( $post\_to\_load->ancestors ) ) && ! empty( $post\_type\_object->hierarchical ) ) {
323
foreach ( $post\_to\_load->ancestors as $parent ) {
324
$parent = get\_post( $parent );
325
if ( $parent && $parent->post\_name ) {
301
326
$final\_uri = $parent->post\_name . '/' . $final\_uri;
302
327
}
…
…
305
330
306
331
// Alter the final query array
307
if($post\_to\_load->post\_status == 'private' && (!is\_user\_logged\_in() || current\_user\_can('read\_private\_posts', $element\_id) !== true)) {
332
if ( $post\_to\_load->post\_status == 'private' && ( ! is\_user\_logged\_in() || current\_user\_can( 'read\_private\_posts', $element\_id ) !== true ) ) {
308
333
$element\_id = null;
309
$query \= $old\_query;
310
} else if($post\_to\_load->post\_status == 'draft' || empty($final\_uri)) {
311
if(is\_user\_logged\_in()) {
312
if($post\_type == 'page') {
334
$query \= $old\_query;
335
} else if ( $post\_to\_load->post\_status == 'draft' || empty( $final\_uri ) ) {
336
if ( is\_user\_logged\_in() ) {
337
if ( $post\_type == 'page' ) {
313
338
$query\['page\_id'\] = $element\_id;
314
339
} else {
…
…
316
341
}
317
342
318
$query\['preview'\] \= true;
343
$query\['preview'\] \= true;
319
344
$query\['post\_type'\] = $post\_type;
320
} else if($post\_to\_load->post\_status == 'draft') {
345
} else if ( $post\_to\_load->post\_status == 'draft' ) {
321
346
$query\['pagename'\] = '-';
322
$query\['error'\] \= '404';
347
$query\['error'\] \= '404';
323
348
324
349
$element\_id = 0;
…
…
326
351
$query = $old\_query;
327
352
}
328
} else if($post\_type == 'page') {
353
} else if ( $post\_type == 'page' ) {
329
354
$query\['pagename'\] = $final\_uri;
330
355
// $query\['post\_type'\] = $post\_type;
331
} else if($post\_type == 'post') {
356
} else if ( $post\_type == 'post' ) {
332
357
$query\['name'\] = $final\_uri;
333
} else if($post\_type == 'attachment') {
358
} else if ( $post\_type == 'attachment' ) {
334
359
$query\['attachment'\] = $final\_uri;
335
360
} else {
336
361
// Get the query var
337
$query\_var = (!empty($post\_type\_object->query\_var)) ? $post\_type\_object->query\_var : $post\_type;
338
339
$query\['name'\] \= $final\_uri;
340
$query\['post\_type'\] \= $post\_type;
341
$query\[$query\_var\] = $final\_uri;
342
}
343
} else if($disabled) {
362
$query\_var = ( ! empty( $post\_type\_object->query\_var ) ) ? $post\_type\_object->query\_var : $post\_type;
363
364
$query\['name'\] \= $final\_uri;
365
$query\['post\_type'\] \= $post\_type;
366
$query\[ $query\_var \] = $final\_uri;
367
}
368
} else if ( $disabled ) {
344
369
$broken\_uri = true;
345
$query \= $old\_query;
370
$query \= $old\_query;
346
371
} else {
347
372
$query = $old\_query;
…
…
352
377
\* 4. Auto-remove removed term custom URI & redirects (works if enabled in plugin settings)
353
378
\*/
354
if(!empty($broken\_uri) && (!empty($permalink\_manager\_options\['general'\]\['auto\_fix\_duplicates'\])) && $permalink\_manager\_options\['general'\]\['auto\_fix\_duplicates'\] == 1) {
379
if ( ! empty( $broken\_uri ) && ( ! empty( $permalink\_manager\_options\['general'\]\['auto\_fix\_duplicates'\] ) ) && $permalink\_manager\_options\['general'\]\['auto\_fix\_duplicates'\] == 1 ) {
355
380
// Do not trigger if WP Rocket cache plugin is turned on
356
if(!defined('WP\_ROCKET\_VERSION') && is\_array($permalink\_manager\_uris)) {
357
$broken\_element\_id = (!empty($revision\_id)) ? $revision\_id : $element\_id;
358
$remove\_broken\_uri = (!empty($broken\_element\_id)) ? Permalink\_Manager\_Actions::force\_clear\_single\_element\_uris\_and\_redirects($broken\_element\_id) : '';
381
if ( ! defined( 'WP\_ROCKET\_VERSION' ) && is\_array( $permalink\_manager\_uris ) ) {
382
$broken\_element\_id = ( ! empty( $revision\_id ) ) ? $revision\_id : $element\_id;
383
$remove\_broken\_uri = ( ! empty( $broken\_element\_id ) ) ? Permalink\_Manager\_Actions::force\_clear\_single\_element\_uris\_and\_redirects( $broken\_element\_id ) : '';
359
384
360
385
// Reload page if success
361
if($remove\_broken\_uri && !headers\_sent()) {
362
header("Refresh:0");
386
if ( $remove\_broken\_uri && ! headers\_sent() ) {
387
header( "Refresh:0" );
363
388
exit();
364
389
}
…
…
369
394
\* 5A. Endpoints
370
395
\*/
371
if(!empty($element\_id) && empty($disabled) && (!empty($endpoint) || !empty($endpoint\_value))) {
372
if(is\_array($endpoint)) {
373
foreach($endpoint as $endpoint\_name => $endpoint\_value) {
374
$query\[$endpoint\_name\] = $endpoint\_value;
375
}
376
} else if($endpoint == 'feed') {
377
$query\[$endpoint\] = 'feed';
378
} else if($endpoint == 'embed') {
379
$query\[$endpoint\] = true;
380
} else if($endpoint == 'page') {
396
if ( ! empty( $element\_id ) && empty( $disabled ) && ( ! empty( $endpoint ) || ! empty( $endpoint\_value ) ) ) {
397
if ( is\_array( $endpoint ) ) {
398
foreach ( $endpoint as $endpoint\_name => $endpoint\_value ) {
399
$query\[ $endpoint\_name \] = $endpoint\_value;
400
}
401
} else if ( $endpoint == 'feed' ) {
402
$query\[ $endpoint \] = 'feed';
403
} else if ( $endpoint == 'embed' ) {
404
$query\[ $endpoint \] = true;
405
} else if ( $endpoint == 'page' ) {
381
406
$endpoint = 'paged';
382
if(is\_numeric($endpoint\_value)) {
383
$query\[$endpoint\] = $endpoint\_value;
407
if ( is\_numeric( $endpoint\_value ) ) {
408
$query\[ $endpoint \] = $endpoint\_value;
384
409
} else {
385
410
$query = $old\_query;
386
411
}
387
} else if($endpoint == 'trackback') {
388
$endpoint \= 'tb';
389
$query\[$endpoint\] = 1;
390
} else if(empty($endpoint) && is\_numeric($endpoint\_value)) {
412
} else if ( $endpoint == 'trackback' ) {
413
$endpoint \= 'tb';
414
$query\[ $endpoint \] = 1;
415
} else if ( empty( $endpoint ) && is\_numeric( $endpoint\_value ) ) {
391
416
$query\['page'\] = $endpoint\_value;
392
417
} else {
393
$query\[$endpoint\] = $endpoint\_value;
418
$query\[ $endpoint \] = $endpoint\_value;
394
419
}
395
420
396
421
// Fix for attachments
397
if(!empty($query\['attachment'\])) {
398
$query = array('attachment' => $query\['attachment'\], 'do\_not\_redirect' => 1);
422
if ( ! empty( $query\['attachment'\] ) ) {
423
$query = array( 'attachment' => $query\['attachment'\], 'do\_not\_redirect' => 1 );
399
424
}
400
425
}
…
…
403
428
\* 5B. Endpoints - check if any endpoint is set with $\_GET parameter
404
429
\*/
405
if(!empty($element\_id) && $deep\_detect\_enabled && !empty($\_GET)) {
406
$get\_endpoints = array\_intersect($wp->public\_query\_vars, array\_keys($\_GET));
407
408
if(!empty($get\_endpoints)) {
430
if ( ! empty( $element\_id ) && $deep\_detect\_enabled && ! empty( $\_GET ) ) {
431
$get\_endpoints = array\_intersect( $wp->public\_query\_vars, array\_keys( $\_GET ) );
432
433
if ( ! empty( $get\_endpoints ) ) {
409
434
// Append query vars from $\_GET parameters
410
foreach($get\_endpoints as $endpoint) {
435
foreach ( $get\_endpoints as $endpoint ) {
411
436
// Numeric endpoints
412
$endpoint\_value = (in\_array($endpoint, array('page', 'paged', 'attachment\_id'))) ? filter\_var($\_GET\[$endpoint\], FILTER\_SANITIZE\_NUMBER\_INT) : $\_GET\[$endpoint\];
437
$endpoint\_value = ( in\_array( $endpoint, array( 'page', 'paged', 'attachment\_id' ) ) ) ? filter\_var( $\_GET\[ $endpoint \], FILTER\_SANITIZE\_NUMBER\_INT ) : $\_GET\[ $endpoint \];
413
438
414
439
// Ignore page endpoint if its value is 1
415
if(in\_array($endpoint, array('page', 'paged')) && $endpoint\_value == 1) { continue; }
440
if ( in\_array( $endpoint, array( 'page', 'paged' ) ) && $endpoint\_value == 1 ) {
441
continue;
442
}
416
443
417
444
// Replace whitespaces with '+' (for YITH WooCommerce Ajax Product Filter URLs only) and sanitize the value
418
$endpoint\_value \= (isset($\_GET\['yith\_wcan'\])) ? preg\_replace('/\\s+/', '+', $endpoint\_value) : $endpoint\_value;
419
$query\[$endpoint\] = sanitize\_text\_field($endpoint\_value);
445
$endpoint\_value = ( isset( $\_GET\['yith\_wcan'\] ) ) ? preg\_replace( '/\\s+/', '+', $endpoint\_value ) : $endpoint\_value;
446
$query\[ $endpoint \] = sanitize\_text\_field( $endpoint\_value );
420
447
}
421
448
}
…
…
425
452
\* 6. Set global with detected item id
426
453
\*/
427
if(!empty($element\_id) && empty($disabled)) {
454
if ( ! empty( $element\_id ) && empty( $disabled ) ) {
428
455
$pm\_query\['id'\] = $element\_id;
429
456
…
…
436
463
\* 7. Debug data
437
464
\*/
438
if(!empty($term\_taxonomy)) {
465
if ( ! empty( $term\_taxonomy ) ) {
439
466
$content\_type = "Taxonomy: {$term\_taxonomy}";
440
} else if(!empty($post\_type)) {
467
} else if ( ! empty( $post\_type ) ) {
441
468
$content\_type = "Post type: {$post\_type}";
442
469
} else {
443
470
$content\_type = '';
444
471
}
445
$uri\_parts = (!empty($uri\_parts)) ? $uri\_parts : '';
446
$query \= apply\_filters('permalink\_manager\_filter\_query', $query, $old\_query, $uri\_parts, $pm\_query, $content\_type);
447
448
if($return\_object && !empty($term)) {
472
$uri\_parts = ( ! empty( $uri\_parts ) ) ? $uri\_parts : '';
473
$query = apply\_filters( 'permalink\_manager\_filter\_query', $query, $old\_query, $uri\_parts, $pm\_query, $content\_type );
474
475
if ( $return\_object && ! empty( $term ) ) {
449
476
return $term;
450
} else if($return\_object && !empty($post\_to\_load)) {
477
} else if ( $return\_object && ! empty( $post\_to\_load ) ) {
451
478
return $post\_to\_load;
452
479
} else {
…
…
457
484
/\*\*
458
485
\* Trailing slash & remove BOM and double slashes
486
\*
487
\* @param string $permalink
488
\*
489
\* @return string
459
490
\*/
460
static function control\_trailing\_slashes($permalink) {
491
static function control\_trailing\_slashes( $permalink ) {
461
492
global $permalink\_manager\_options;
462
493
463
494
// Ignore empty permalinks
464
if(empty($permalink)) { return $permalink; }
495
if ( empty( $permalink ) ) {
496
return $permalink;
497
}
465
498
466
499
// Keep the original permalink in a separate variable
467
500
$original\_permalink = $permalink;
468
501
469
$trailing\_slash\_setting = (!empty($permalink\_manager\_options\['general'\]\['trailing\_slashes'\])) ? $permalink\_manager\_options\['general'\]\['trailing\_slashes'\] : "";
502
$trailing\_slash\_setting = ( ! empty( $permalink\_manager\_options\['general'\]\['trailing\_slashes'\] ) ) ? $permalink\_manager\_options\['general'\]\['trailing\_slashes'\] : "";
470
503
471
504
// Remove trailing slashes from URLs that end with file extension (eg. .html)
472
if(preg\_match('/(http(?:s)?:\\/\\/(?:\[^\\/\]+)\\/.\*\\.(\[a-zA-Z\]{3,4}))\\/?$/', $permalink)) {
473
$permalink = preg\_replace('/^(?!http(?:s):\\/\\/\[^\\/\]+\\/$)(.+?)(\[\\/\]\*)(\\\[\\?\\#\]\[^\\/\]+|$)/', '$1$3', $permalink); // Instead of untrailingslashit()
505
if ( preg\_match( '/(http(?:s)?:\\/\\/(?:\[^\\/\]+)\\/.\*\\.(\[a-zA-Z\]{3,4}))\\/?$/', $permalink ) ) {
506
$permalink = preg\_replace( '/^(?!http(?:s):\\/\\/\[^\\/\]+\\/$)(.+?)(\[\\/\]\*)(\\\[\\?\\#\]\[^\\/\]+|$)/', '$1$3', $permalink ); // Instead of untrailingslashit()
474
507
} else {
475
508
// Add trailing slashes
476
if(in\_array($trailing\_slash\_setting, array(1, 10))) {
477
$permalink = preg\_replace('/(.+?)(\[\\/\]\*)(\\\[\\?\\#\]\[^\\/\]+|$)/', '$1/$3', $permalink); // Instead of trailingslashit()
478
}
479
// Remove trailing slashes
480
else if(in\_array($trailing\_slash\_setting, array(2, 20))) {
481
$permalink = preg\_replace('/(.+?)(\[\\/\]\*)(\\\[\\?\\#\]\[^\\/\]+|$)/', '$1$3', $permalink); // Instead of untrailingslashit()
482
}
483
// Default settings
509
if ( in\_array( $trailing\_slash\_setting, array( 1, 10 ) ) ) {
510
$permalink = preg\_replace( '/(.+?)(\[\\/\]\*)(\\\[\\?\\#\]\[^\\/\]+|$)/', '$1/$3', $permalink ); // Instead of trailingslashit()
511
} // Remove trailing slashes
512
else if ( in\_array( $trailing\_slash\_setting, array( 2, 20 ) ) ) {
513
$permalink = preg\_replace( '/(.+?)(\[\\/\]\*)(\\\[\\?\\#\]\[^\\/\]+|$)/', '$1$3', $permalink ); // Instead of untrailingslashit()
514
} // Default settings
484
515
else {
485
$permalink = user\_trailingslashit($permalink);
516
$permalink = user\_trailingslashit( $permalink );
486
517
}
487
518
}
488
519
489
520
// Remove double slashes
490
$permalink = preg\_replace('/(\[^:\])(\\/{2,})/', '$1/', $permalink);
521
$permalink = preg\_replace( '/(\[^:\])(\\/{2,})/', '$1/', $permalink );
491
522
492
523
// Remove trailing slashes from URLs that end with query string or anchors
493
$permalink = preg\_replace('/(\[\\?\\#\]{1}\[^\\/\]+)(\[\\/\]+)$/', '$1', $permalink);
494
495
return apply\_filters('permalink\_manager\_control\_trailing\_slashes', $permalink, $original\_permalink);
524
$permalink = preg\_replace( '/(\[\\?\\#\]{1}\[^\\/\]+)(\[\\/\]+)$/', '$1', $permalink );
525
526
return apply\_filters( 'permalink\_manager\_control\_trailing\_slashes', $permalink, $original\_permalink );
496
527
}
497
528
498
529
/\*\*
499
\* Display 404 if requested page does not exist in pagination
530
\* Display 404 if requested page does not exist in pagination or the pagination format is incorrect
500
531
\*/
501
532
function fix\_pagination\_pages() {
…
…
504
535
// 1. Get the queried object
505
536
$post = get\_queried\_object();
506
$post = (empty($post) && !empty($wp\_query->post)) ? $wp\_query->post : $post;
537
$post = ( empty( $post ) && ! empty( $wp\_query->post ) ) ? $wp\_query->post : $post;
507
538
508
539
// 2. Check if post object is defined
509
if((!empty($post->post\_type) && isset($post->post\_content)) || (!empty($wp\_query->max\_num\_pages))) {
510
// 2A. Check if pagination is detected
511
$current\_page = (!empty($wp\_query->query\_vars\['page'\])) ? $wp\_query->query\_vars\['page'\] : 1;
512
$current\_page = (empty($wp\_query->query\_vars\['page'\]) && !empty($wp\_query->query\_vars\['paged'\])) ? $wp\_query->query\_vars\['paged'\] : $current\_page;
513
514
// 2B. Count post pages
515
$post\_content = (!empty($post->post\_content)) ? $post->post\_content : '';
516
$num\_pages \= (is\_home() || is\_archive() || is\_search()) ? $wp\_query->max\_num\_pages : substr\_count(strtolower($post\_content), '<!--nextpage-->') + 1;
517
518
// 2C. Remove 'do\_not\_redirect' parameter if the first page of content is requested to force canonical redirect
519
if(!empty($pm\_query\['id'\]) && is\_numeric($pm\_query\['id'\]) && !empty($wp->query\_vars\['do\_not\_redirect'\]) && empty($pm\_query\['endpoint'\]) && $pm\_query\['endpoint\_value'\] == 1) {
520
$is\_404 \= true;
540
if ( ( ! empty( $post->post\_type ) && isset( $post->post\_content ) ) || ( ! empty( $wp\_query->max\_num\_pages ) ) ) {
541
// 2.1A. Check if pagination is detected
542
$current\_page = ( ! empty( $wp\_query->query\_vars\['page'\] ) ) ? $wp\_query->query\_vars\['page'\] : 1;
543
$current\_page = ( empty( $wp\_query->query\_vars\['page'\] ) && ! empty( $wp\_query->query\_vars\['paged'\] ) ) ? $wp\_query->query\_vars\['paged'\] : $current\_page;
544
545
// 2.1B. Count post pages
546
$post\_content = ( ! empty( $post->post\_content ) ) ? $post->post\_content : '';
547
$num\_pages = ( is\_home() || is\_archive() || is\_search() ) ? $wp\_query->max\_num\_pages : substr\_count( strtolower( $post\_content ), '<!--nextpage-->' ) + 1;
548
549
// 2.1C. Remove 'do\_not\_redirect' parameter if the first page of content is requested to force canonical redirect
550
if ( ! empty( $pm\_query\['id'\] ) && is\_numeric( $pm\_query\['id'\] ) && ! empty( $wp->query\_vars\['do\_not\_redirect'\] ) && empty( $pm\_query\['endpoint'\] ) && $pm\_query\['endpoint\_value'\] == 1 ) {
551
$is\_404 \= true;
521
552
$wp->query\_vars\['do\_not\_redirect'\] = 0;
522
set\_query\_var('p', $pm\_query\['id'\]);
553
set\_query\_var( 'p', $pm\_query\['id'\] );
523
554
} else {
524
$is\_404 = ($current\_page > 1 && ($current\_page > $num\_pages)) ? true : false;
525
}
526
}
527
// 3. Force 404 if no posts are loaded
528
else if(!empty($wp\_query->query\['paged'\]) && $wp\_query->post\_count == 0) {
555
$is\_404 = ( $current\_page > 1 && ( $current\_page > $num\_pages ) ) ? true : false;
556
}
557
} // 2.2. Force 404 if no posts are loaded
558
else if ( ! empty( $wp\_query->query\['paged'\] ) && $wp\_query->post\_count == 0 ) {
529
559
$is\_404 = true;
530
560
}
531
// 4. Force 404 if endpoint value is not set
532
else if(!empty($pm\_query\['endpoint'\]) && $pm\_query\['endpoint'\] == 'page' && empty($pm\_query\['endpoint\_value'\])) {
561
562
// 2.3. Force 404 if endpoint value is not set or not numeric
563
if ( ! empty( $pm\_query\['endpoint'\] ) && $pm\_query\['endpoint'\] == 'page' && ( empty( $pm\_query\['endpoint\_value'\] ) || ! is\_numeric( $pm\_query\['endpoint\_value'\] ) ) ) {
533
564
$is\_404 = true;
534
565
}
535
566
536
// 5. Block non-existent pages (Force 404 error)
537
if(!empty($is\_404)) {
567
// 3. Block non-existent pages (Force 404 error)
568
if ( ! empty( $is\_404 ) ) {
538
569
$wp\_query->query = $wp\_query->queried\_object = $wp\_query->queried\_object\_id = null;
539
570
$wp\_query->set\_404();
540
status\_header(404);
571
status\_header( 404 );
541
572
nocache\_headers();
542
573
$pm\_query = '';
…
…
545
576
546
577
/\*\*
547
\* Redirects
578
\* Enhance the existing canonical redirect functionality, allowing users define custom redirects and support custom permalinks
548
579
\*/
549
580
function new\_uri\_redirect\_and\_404() {
550
global $wp\_query, $wp, $wp\_rewrite, $wpdb, $permalink\_manager\_uris, $permalink\_manager\_redirects, $permalink\_manager\_external\_redirects, $permalink\_manager\_options, $pm\_query;
581
global $wp\_query, $wp, $wp\_rewrite, $wpdb, $permalink\_manager\_uris, $permalink\_manager\_redirects, $permalink\_manager\_external\_redirects, $permalink\_manager\_options, $pm\_query;
551
582
552
583
// Get the redirection mode & trailing slashes settings
553
$redirect\_mode \= (!empty($permalink\_manager\_options\['general'\]\['redirect'\])) ? $permalink\_manager\_options\['general'\]\['redirect'\] : false;
554
$trailing\_slashes\_mode \= (!empty($permalink\_manager\_options\['general'\]\['trailing\_slashes'\])) ? $permalink\_manager\_options\['general'\]\['trailing\_slashes'\] : false;
555
$trailing\_slashes\_redirect = (!empty($permalink\_manager\_options\['general'\]\['trailing\_slashes\_redirect'\])) ? $permalink\_manager\_options\['general'\]\['trailing\_slashes\_redirect'\] : false;
556
$extra\_redirects \= (!empty($permalink\_manager\_options\['general'\]\['extra\_redirects'\])) ? $permalink\_manager\_options\['general'\]\['extra\_redirects'\] : false;
557
$canonical\_redirect \= (!empty($permalink\_manager\_options\['general'\]\['canonical\_redirect'\])) ? $permalink\_manager\_options\['general'\]\['canonical\_redirect'\] : false;
558
$old\_slug\_redirect \= (!empty($permalink\_manager\_options\['general'\]\['old\_slug\_redirect'\])) ? $permalink\_manager\_options\['general'\]\['old\_slug\_redirect'\] : false;
559
$endpoint\_redirect \= (!empty($permalink\_manager\_options\['general'\]\['endpoint\_redirect'\])) ? $permalink\_manager\_options\['general'\]\['endpoint\_redirect'\] : false;
560
$pagination\_redirect \= (!empty($permalink\_manager\_options\['general'\]\['pagination\_redirect'\])) ? $permalink\_manager\_options\['general'\]\['pagination\_redirect'\] : false;
561
$copy\_query\_redirect \= (!empty($permalink\_manager\_options\['general'\]\['copy\_query\_redirect'\])) ? $permalink\_manager\_options\['general'\]\['copy\_query\_redirect'\] : false;
562
$redirect\_type \= '-';
584
$redirect\_mode = ( ! empty( $permalink\_manager\_options\['general'\]\['redirect'\] ) ) ? $permalink\_manager\_options\['general'\]\['redirect'\] : false;
585
$trailing\_slashes\_mode = ( ! empty( $permalink\_manager\_options\['general'\]\['trailing\_slashes'\] ) ) ? $permalink\_manager\_options\['general'\]\['trailing\_slashes'\] : false;
586
$trailing\_slashes\_redirect = ( ! empty( $permalink\_manager\_options\['general'\]\['trailing\_slashes\_redirect'\] ) ) ? $permalink\_manager\_options\['general'\]\['trailing\_slashes\_redirect'\] : false;
587
$extra\_redirects = ( ! empty( $permalink\_manager\_options\['general'\]\['extra\_redirects'\] ) ) ? $permalink\_manager\_options\['general'\]\['extra\_redirects'\] : false;
588
$canonical\_redirect = ( ! empty( $permalink\_manager\_options\['general'\]\['canonical\_redirect'\] ) ) ? $permalink\_manager\_options\['general'\]\['canonical\_redirect'\] : false;
589
$old\_slug\_redirect = ( ! empty( $permalink\_manager\_options\['general'\]\['old\_slug\_redirect'\] ) ) ? $permalink\_manager\_options\['general'\]\['old\_slug\_redirect'\] : false;
590
$endpoint\_redirect = ( ! empty( $permalink\_manager\_options\['general'\]\['endpoint\_redirect'\] ) ) ? $permalink\_manager\_options\['general'\]\['endpoint\_redirect'\] : false;
591
$pagination\_redirect = ( ! empty( $permalink\_manager\_options\['general'\]\['pagination\_redirect'\] ) ) ? $permalink\_manager\_options\['general'\]\['pagination\_redirect'\] : false;
592
$copy\_query\_redirect = ( ! empty( $permalink\_manager\_options\['general'\]\['copy\_query\_redirect'\] ) ) ? $permalink\_manager\_options\['general'\]\['copy\_query\_redirect'\] : false;
593
$redirect\_type \= '-';
563
594
564
595
// Get home URL
565
$home\_url = rtrim(get\_option('home'), "/");
566
$home\_dir = parse\_url($home\_url, PHP\_URL\_PATH);
596
$home\_url = rtrim( get\_option( 'home' ), "/" );
597
$home\_dir = parse\_url( $home\_url, PHP\_URL\_PATH );
567
598
568
599
// Set up $correct\_permalink variable
…
…
570
601
571
602
// Get query string & URI
572
if(empty($\_SERVER\['REQUEST\_URI'\])) { return; }
573
574
$query\_string = ($copy\_query\_redirect && !empty($\_SERVER\['QUERY\_STRING'\])) ? $\_SERVER\['QUERY\_STRING'\] : '';
575
$old\_uri = parse\_url($\_SERVER\['REQUEST\_URI'\], PHP\_URL\_PATH);
603
if ( empty( $\_SERVER\['REQUEST\_URI'\] ) ) {
604
return;
605
}
606
607
$query\_string = ( $copy\_query\_redirect && ! empty( $\_SERVER\['QUERY\_STRING'\] ) ) ? $\_SERVER\['QUERY\_STRING'\] : '';
608
$old\_uri = parse\_url( $\_SERVER\['REQUEST\_URI'\], PHP\_URL\_PATH );
576
609
577
610
// Fix for WP installed in directories (remove the directory name from the URI)
578
if(!empty($home\_dir)) {
579
$home\_dir\_regex = preg\_quote(trim($home\_dir), "/");
580
$old\_uri \= preg\_replace("/{$home\_dir\_regex}/", "", $old\_uri, 1);
611
if ( ! empty( $home\_dir ) ) {
612
$home\_dir\_regex = preg\_quote( trim( $home\_dir ), "/" );
613
$old\_uri = preg\_replace( "/{$home\_dir\_regex}/", "", $old\_uri, 1 );
581
614
}
582
615
583
616
// Do not use custom redirects on author pages, search & front page
584
if(!is\_author() && !is\_front\_page() && !is\_home() && !is\_feed() && !is\_search() && empty($\_GET\['s'\])) {
617
if ( ! is\_author() && ! is\_front\_page() && ! is\_home() && ! is\_feed() && ! is\_search() && empty( $\_GET\['s'\] ) ) {
585
618
// Sometimes $wp\_query indicates the wrong object if requested directly
586
619
$queried\_object = get\_queried\_object();
587
620
588
621
// Unset 404 if custom URI is detected
589
if(isset($pm\_query\['id'\]) && (empty($queried\_object->post\_status) || $queried\_object->post\_status !== 'private')) {
622
if ( ! empty( $pm\_query\['id'\] ) && ( empty( $queried\_object->post\_status ) || $queried\_object->post\_status !== 'private' ) ) {
590
623
$wp\_query->is\_404 = false;
591
624
}
592
625
593
626
/\*\*
594
\* 1A. External redirect
595
\*/
596
if(!empty($pm\_query\['id'\]) && !empty($permalink\_manager\_external\_redirects\[$pm\_query\['id'\]\])) {
597
$external\_url = $permalink\_manager\_external\_redirects\[$pm\_query\['id'\]\];
598
599
if(filter\_var($external\_url, FILTER\_VALIDATE\_URL)) {
627
\* 1A. External redirect
628
\*/
629
if ( ! empty( $pm\_query\['id'\] ) && ! empty( $permalink\_manager\_external\_redirects\[ $pm\_query\['id'\] \] ) ) {
630
$external\_url = $permalink\_manager\_external\_redirects\[ $pm\_query\['id'\] \];
631
632
if ( filter\_var( $external\_url, FILTER\_VALIDATE\_URL ) ) {
600
633
// Allow redirect
601
634
$wp\_query->query\_vars\['do\_not\_redirect'\] = 0;
602
635
603
wp\_redirect($external\_url, 301, PERMALINK\_MANAGER\_PLUGIN\_NAME);
636
wp\_redirect( $external\_url, 301, PERMALINK\_MANAGER\_PLUGIN\_NAME );
604
637
exit();
605
638
}
…
…
609
642
\* 1B. Custom redirects
610
643
\*/
611
if(empty($wp\_query->query\_vars\['do\_not\_redirect'\]) && $extra\_redirects && !empty($permalink\_manager\_redirects) && is\_array($permalink\_manager\_redirects) && !empty($wp->request) && !empty($pm\_query\['uri'\])) {
612
$uri \= $pm\_query\['uri'\];
644
if ( empty( $wp\_query->query\_vars\['do\_not\_redirect'\] ) && $extra\_redirects && ! empty( $permalink\_manager\_redirects ) && is\_array( $permalink\_manager\_redirects ) && ! empty( $wp->request ) && ! empty( $pm\_query\['uri'\] ) ) {
645
$uri \= $pm\_query\['uri'\];
613
646
$endpoint\_value = $pm\_query\['endpoint\_value'\];
614
647
615
648
// Make sure that URIs with non-ASCII characters are also detected + Check the URLs that end with number
616
$decoded\_url \= urldecode($uri);
649
$decoded\_url = urldecode( $uri );
617
650
$endpoint\_url = "{$uri}/{$endpoint\_value}";
618
651
619
// Convert to lowercase to make case insensitive
620
$force\_lowercase = apply\_filters('permalink\_manager\_force\_lowercase\_uris', true);
621
622
if($force\_lowercase) {
623
$uri \= strtolower($uri);
624
$decoded\_url \= strtolower($decoded\_url);
625
$endpoint\_url = strtolower($endpoint\_url);
652
// Convert to lowercase to make case\-insensitive
653
$force\_lowercase = apply\_filters( 'permalink\_manager\_force\_lowercase\_uris', true );
654
655
if ( $force\_lowercase ) {
656
$uri = strtolower( $uri );
657
$decoded\_url = strtolower( $decoded\_url );
658
$endpoint\_url = strtolower( $endpoint\_url );
626
659
}
627
660
628
661
// Check if the URI is not assigned to any post/term's redirects
629
foreach($permalink\_manager\_redirects as $element => $redirects) {
630
if(!is\_array($redirects)) { continue; }
631
632
if(in\_array($uri, $redirects) || in\_array($decoded\_url, $redirects) || (is\_numeric($endpoint\_value) && in\_array($endpoint\_url, $redirects))) {
662
foreach ( $permalink\_manager\_redirects as $element => $redirects ) {
663
if ( ! is\_array( $redirects ) ) {
664
continue;
665
}
666
667
if ( in\_array( $uri, $redirects ) || in\_array( $decoded\_url, $redirects ) || ( is\_numeric( $endpoint\_value ) && in\_array( $endpoint\_url, $redirects ) ) ) {
633
668
// Post is detected
634
if(is\_numeric($element)) {
635
$correct\_permalink = get\_permalink($element);
669
if ( is\_numeric( $element ) ) {
670
$correct\_permalink = get\_permalink( $element );
671
} // Term is detected
672
else {
673
$term\_id = intval( preg\_replace( "/\[^0-9\]/", "", $element ) );
674
$correct\_permalink = get\_term\_link( $term\_id );
636
675
}
637
// Term is detected
638
else {
639
$term\_id = intval(preg\_replace("/\[^0-9\]/", "", $element));
640
$correct\_permalink = get\_term\_link($term\_id);
641
}
642
676
643
677
// The custom redirect is found so there is no need to query the rest of array
644
continue;
645
}
646
}
647
648
$redirect\_type = (!empty($correct\_permalink)) ? 'custom\_redirect' : $redirect\_type;
678
break;
679
}
680
}
681
682
$redirect\_type = ( ! empty( $correct\_permalink ) ) ? 'custom\_redirect' : $redirect\_type;
649
683
}
650
684
651
685
// Ignore WP-Content links
652
if(!empty($\_SERVER\['REQUEST\_URI'\]) && (strpos($\_SERVER\['REQUEST\_URI'\], '/wp-content') !== false)) { return false; }
686
if ( strpos( $\_SERVER\['REQUEST\_URI'\], '/wp-content' ) !== false ) {
687
return;
688
}
653
689
654
690
/\*\*
655
691
\* 1C. Pagination redirect
656
692
\*/
657
if($pagination\_redirect && ((isset($wp\_query->query\_vars\['paged'\]) && $wp\_query->query\_vars\['paged'\] == 1) || (isset($wp\_query->query\_vars\['page'\]) && $wp\_query->query\_vars\['page'\] == 1 && !empty($pm\_query\['endpoint\_value'\])))) {
658
$pm\_query\['endpoint'\] \= $pm\_query\['endpoint\_value'\] = '';
693
if ( $pagination\_redirect && ( ( isset( $wp\_query->query\_vars\['paged'\] ) && $wp\_query->query\_vars\['paged'\] == 1 ) || ( isset( $wp\_query->query\_vars\['page'\] ) && $wp\_query->query\_vars\['page'\] == 1 && ! empty( $pm\_query\['endpoint\_value'\] ) ) ) ) {
694
$pm\_query\['endpoint'\] \= $pm\_query\['endpoint\_value'\] = '';
659
695
$wp\_query->query\_vars\['do\_not\_redirect'\] = 0;
660
696
}
…
…
663
699
\* 1D. Enhance native redirect
664
700
\*/
665
if($canonical\_redirect && empty($wp\_query->query\_vars\['do\_not\_redirect'\]) && !empty($queried\_object) && empty($correct\_permalink)) {
701
if ( $canonical\_redirect && empty( $wp\_query->query\_vars\['do\_not\_redirect'\] ) && ! empty( $queried\_object ) && empty( $correct\_permalink ) ) {
666
702
// Affect only posts with custom URI and old URIs
667
if(!empty($queried\_object->ID) && isset($permalink\_manager\_uris\[$queried\_object->ID\]) && empty($wp\_query->query\['preview'\])) {
703
if ( ! empty( $queried\_object->ID ) && isset( $permalink\_manager\_uris\[ $queried\_object->ID \] ) && empty( $wp\_query->query\['preview'\] ) ) {
668
704
// Ignore posts with specific statuses
669
if(!(empty($queried\_object->post\_status)) && in\_array($queried\_object->post\_status, array('draft', 'pending', 'auto-draft', 'future'))) {
705
if ( ! ( empty( $queried\_object->post\_status ) ) && in\_array( $queried\_object->post\_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) {
670
706
return;
671
707
}
672
708
673
709
// Check if the post is excluded
674
if(Permalink\_Manager\_Helper\_Functions::is\_post\_excluded($queried\_object)) { return; }
710
if ( Permalink\_Manager\_Helper\_Functions::is\_post\_excluded( $queried\_object ) ) {
711
return;
712
}
675
713
676
714
// Get the real URL
677
$correct\_permalink = get\_permalink($queried\_object->ID);
678
}
679
// Affect only terms with custom URI and old URIs
680
else if(!empty($queried\_object->term\_id) && isset($permalink\_manager\_uris\["tax-{$queried\_object->term\_id}"\]) && defined('PERMALINK\_MANAGER\_PRO')) {
715
$correct\_permalink = get\_permalink( $queried\_object->ID );
716
} // Affect only terms with custom URI and old URIs
717
else if ( ! empty( $queried\_object->term\_id ) && isset( $permalink\_manager\_uris\["tax-{$queried\_object->term\_id}"\] ) && defined( 'PERMALINK\_MANAGER\_PRO' ) ) {
681
718
// Check if the term is excluded
682
if(Permalink\_Manager\_Helper\_Functions::is\_term\_excluded($queried\_object)) { return; }
719
if ( Permalink\_Manager\_Helper\_Functions::is\_term\_excluded( $queried\_object ) ) {
720
return;
721
}
683
722
684
723
// Get the real URL
685
$correct\_permalink = get\_term\_link($queried\_object->term\_id, $queried\_object->taxonomy);
686
}
687
688
$redirect\_type = (!empty($correct\_permalink)) ? 'native\_redirect' : $redirect\_type;
724
$correct\_permalink = get\_term\_link( $queried\_object->term\_id, $queried\_object->taxonomy );
725
}
726
727
$redirect\_type = ( ! empty( $correct\_permalink ) ) ? 'native\_redirect' : $redirect\_type;
689
728
}
690
729
…
…
692
731
\* 1E. Old slug redirect
693
732
\*/
694
if($old\_slug\_redirect && !empty($pm\_query\['uri'\]) && empty($wp\_query->query\_vars\['do\_not\_redirect'\]) && is\_404() && empty($correct\_permalink)) {
695
$slug = basename($pm\_query\['uri'\]);
696
697
$post\_id = $wpdb->get\_var($wpdb->prepare("SELECT post\_id from {$wpdb->postmeta} WHERE meta\_key = '\_wp\_old\_slug' AND meta\_value = %s", $slug));
698
if(!empty($post\_id)) {
699
$correct\_permalink = get\_permalink($post\_id);
700
$redirect\_type \= 'old\_slug\_redirect';
733
if ( $old\_slug\_redirect && ! empty( $pm\_query\['uri'\] ) && empty( $wp\_query->query\_vars\['do\_not\_redirect'\] ) && is\_404() && empty( $correct\_permalink ) ) {
734
$slug = basename( $pm\_query\['uri'\] );
735
736
$post\_id = $wpdb->get\_var( $wpdb->prepare( "SELECT post\_id from {$wpdb->postmeta} WHERE meta\_key = '\_wp\_old\_slug' AND meta\_value = %s", $slug ) );
737
if ( ! empty( $post\_id ) ) {
738
$correct\_permalink = get\_permalink( $post\_id );
739
$redirect\_type \= 'old\_slug\_redirect';
701
740
}
702
741
}
…
…
705
744
\* 2. Check if URL contains duplicated slashes
706
745
\*/
707
if(!empty($old\_uri) && ($old\_uri !== '/') && preg\_match('/\\/{2,}/', $old\_uri)) {
708
$new\_uri \= ltrim(preg\_replace('/(\[^:\])(\[\\/\]+)/', '$1/', $old\_uri), '/');
709
$correct\_permalink = sprintf("%s/%s", $home\_url, $new\_uri);
710
711
$redirect\_type = ($redirect\_type == '-') ? 'duplicated\_slash\_redirect' : $redirect\_type;
746
if ( ! empty( $old\_uri ) && ( $old\_uri !== '/' ) && preg\_match( '/\\/{2,}/', $old\_uri ) ) {
747
$new\_uri = ltrim( preg\_replace( '/(\[^:\])(\[\\/\]+)/', '$1/', $old\_uri ), '/' );
748
$correct\_permalink = sprintf( "%s/%s", $home\_url, $new\_uri );
749
750
$redirect\_type = ( $redirect\_type == '-' ) ? 'duplicated\_slash\_redirect' : $redirect\_type;
712
751
}
713
752
…
…
715
754
\* 3. Prevent redirect loop
716
755
\*/
717
if(!empty($correct\_permalink) && is\_string($correct\_permalink) && !empty($wp->request) && !empty($redirect\_type) && !in\_array($redirect\_type, array('slash\_redirect', 'duplicated\_slash\_redirect'))) {
718
$current\_uri \= trim($wp->request, "/");
719
$redirect\_uri = trim(parse\_url($correct\_permalink, PHP\_URL\_PATH), "/");
720
721
$correct\_permalink = ($redirect\_uri == $current\_uri) ? null : $correct\_permalink;
756
if ( ! empty( $correct\_permalink ) && is\_string( $correct\_permalink ) && ! empty( $wp->request ) && ! empty( $redirect\_type ) && ! in\_array( $redirect\_type, array( 'slash\_redirect', 'duplicated\_slash\_redirect' ) ) ) {
757
$current\_uri = trim( $wp->request, "/" );
758
$redirect\_uri = trim( parse\_url( $correct\_permalink, PHP\_URL\_PATH ), "/" );
759
760
$correct\_permalink = ( $redirect\_uri == $current\_uri ) ? null : $correct\_permalink;
722
761
}
723
762
…
…
725
764
\* 4. Add endpoints to redirect URL
726
765
\*/
727
if(!empty($correct\_permalink) && $endpoint\_redirect && ($redirect\_type !== 'slash\_redirect') && (!empty($pm\_query\['endpoint\_value'\]) || !empty($pm\_query\['endpoint'\]))) {
766
if ( ! empty( $correct\_permalink ) && $endpoint\_redirect && ( $redirect\_type !== 'slash\_redirect' ) && ( ! empty( $pm\_query\['endpoint\_value'\] ) || ! empty( $pm\_query\['endpoint'\] ) ) ) {
728
767
$endpoint\_value = $pm\_query\['endpoint\_value'\];
729
768
730
if(empty($pm\_query\['endpoint'\]) && is\_numeric($endpoint\_value)) {
731
$correct\_permalink = sprintf("%s/%d", trim($correct\_permalink, "/"), $endpoint\_value);
732
} else if(isset($pm\_query\['endpoint'\]) && !empty($endpoint\_value)) {
733
if($pm\_query\['endpoint'\] == 'cpage') {
734
$correct\_permalink = sprintf("%s/%s-%s", trim($correct\_permalink, "/"), $wp\_rewrite->comments\_pagination\_base, $endpoint\_value);
769
if ( empty( $pm\_query\['endpoint'\] ) && is\_numeric( $endpoint\_value ) ) {
770
$correct\_permalink = sprintf( "%s/%d", trim( $correct\_permalink, "/" ), $endpoint\_value );
771
} else if ( isset( $pm\_query\['endpoint'\] ) && ! empty( $endpoint\_value ) ) {
772
if ( $pm\_query\['endpoint'\] == 'cpage' ) {
773
$correct\_permalink = sprintf( "%s/%s-%s", trim( $correct\_permalink, "/" ), $wp\_rewrite->comments\_pagination\_base, $endpoint\_value );
735
774
} else {
736
$correct\_permalink = sprintf("%s/%s/%s", trim($correct\_permalink, "/"), $pm\_query\['endpoint'\], $endpoint\_value);
775
$correct\_permalink = sprintf( "%s/%s/%s", trim( $correct\_permalink, "/" ), $pm\_query\['endpoint'\], $endpoint\_value );
737
776
}
738
777
} else {
739
$correct\_permalink = sprintf("%s/%s", trim($correct\_permalink, "/"), $pm\_query\['endpoint'\]);
778
$correct\_permalink = sprintf( "%s/%s", trim( $correct\_permalink, "/" ), $pm\_query\['endpoint'\] );
740
779
}
741
780
}
…
…
747
786
\* 5. Check trailing slashes (ignore links with query parameters)
748
787
\*/
749
if($trailing\_slashes\_mode && $trailing\_slashes\_redirect && empty($correct\_permalink) && empty($query\_string) && !empty($old\_uri) && !is\_front\_page()) {
788
if ( $trailing\_slashes\_mode && $trailing\_slashes\_redirect && empty( $correct\_permalink ) && empty( $query\_string ) && ! empty( $old\_uri ) && ! is\_front\_page() ) {
750
789
// Check if $old\_uri ends with slash or not
751
$ends\_with\_slash \= (substr($old\_uri, -1) == "/") ? true : false;
752
$trailing\_slashes\_mode = (preg\_match("/.\*\\.(\[a-zA-Z\]{3,4})\\/?$/", $old\_uri) && $trailing\_slashes\_mode == 1) ? 2 : $trailing\_slashes\_mode;
790
$ends\_with\_slash = ( substr( $old\_uri, - 1 ) == "/" ) ? true : false;
791
$trailing\_slashes\_mode = ( preg\_match( "/.\*\\.(\[a-zA-Z\]{3,4})\\/?$/", $old\_uri ) && $trailing\_slashes\_mode == 1 ) ? 2 : $trailing\_slashes\_mode;
753
792
754
793
// Ignore empty URIs
755
if($old\_uri != "/") {
756
$new\_uri = trim($old\_uri, '/');
794
if ( $old\_uri != "/" ) {
795
$new\_uri = trim( $old\_uri, '/' );
757
796
758
797
// 2A. Force trailing slashes
759
if($trailing\_slashes\_mode == 1 && $ends\_with\_slash == false) {
760
$correct\_permalink = sprintf("%s/%s/", $home\_url, $new\_uri);
761
}
762
// 2B. Remove trailing slashes
763
else if($trailing\_slashes\_mode == 2 && $ends\_with\_slash == true) {
764
$correct\_permalink = sprintf("%s/%s", $home\_url, $new\_uri);
765
}
766
// 2C. Remove duplicated trailing slashes
767
else if($trailing\_slashes\_mode == 1 && preg\_match('/\[\\/\]{2,}$/', $old\_uri)) {
768
$correct\_permalink = sprintf("%s/%s/", $home\_url, $new\_uri);
769
}
770
}
771
772
$redirect\_type = (!empty($correct\_permalink)) ? 'slash\_redirect' : '-';
798
if ( $trailing\_slashes\_mode == 1 && ! $ends\_with\_slash ) {
799
$correct\_permalink = sprintf( "%s/%s/", $home\_url, $new\_uri );
800
} // 2B. Remove trailing slashes
801
else if ( $trailing\_slashes\_mode == 2 && $ends\_with\_slash ) {
802
$correct\_permalink = sprintf( "%s/%s", $home\_url, $new\_uri );
803
} // 2C. Remove duplicated trailing slashes
804
else if ( $trailing\_slashes\_mode == 1 && preg\_match( '/\[\\/\]{2,}$/', $old\_uri ) ) {
805
$correct\_permalink = sprintf( "%s/%s/", $home\_url, $new\_uri );
806
}
807
}
808
809
$redirect\_type = ( ! empty( $correct\_permalink ) ) ? 'slash\_redirect' : '-';
773
810
}
774
811
…
…
776
813
\* 6. WWW prefix | SSL mismatch redirect
777
814
\*/
778
if(!empty($permalink\_manager\_options\['general'\]\['sslwww\_redirect'\])) {
779
$home\_url\_has\_www \= (strpos($home\_url, 'www.') !== false) ? true : false;
780
$requested\_url\_has\_www = (strpos($\_SERVER\['HTTP\_HOST'\], 'www.') !== false) ? true : false;
781
$home\_url\_has\_ssl \= (strpos($home\_url, 'https') !== false) ? true : false;
815
if ( ! empty( $permalink\_manager\_options\['general'\]\['sslwww\_redirect'\] ) ) {
816
$home\_url\_has\_www = ( strpos( $home\_url, 'www.' ) !== false ) ? true : false;
817
$requested\_url\_has\_www = ( strpos( $\_SERVER\['HTTP\_HOST'\], 'www.' ) !== false ) ? true : false;
818
$home\_url\_has\_ssl = ( strpos( $home\_url, 'https' ) !== false ) ? true : false;
782
819
$requested\_url\_has\_ssl = is\_ssl();
783
820
784
if(($home\_url\_has\_www !== $requested\_url\_has\_www) || ($home\_url\_has\_ssl !== $requested\_url\_has\_ssl)) {
785
$new\_uri \= ltrim($old\_uri, '/');
786
$correct\_permalink = sprintf("%s/%s", $home\_url, $new\_uri);
821
if ( ( $home\_url\_has\_www !== $requested\_url\_has\_www ) || ( $home\_url\_has\_ssl !== $requested\_url\_has\_ssl ) ) {
822
$new\_uri = ltrim( $old\_uri, '/' );
823
$correct\_permalink = sprintf( "%s/%s", $home\_url, $new\_uri );
787
824
788
825
$redirect\_type = 'www\_redirect';
…
…
793
830
\* 7. Debug redirect
794
831
\*/
795
$correct\_permalink = apply\_filters('permalink\_manager\_filter\_redirect', $correct\_permalink, $redirect\_type, $queried\_object);
832
$correct\_permalink = apply\_filters( 'permalink\_manager\_filter\_redirect', $correct\_permalink, $redirect\_type, $queried\_object, $old\_uri );
796
833
797
834
/\*\*
798
835
\* 8. Ignore default URIs (or do nothing if redirects are disabled)
799
836
\*/
800
if(!empty($correct\_permalink) && is\_string($correct\_permalink) && !empty($redirect\_mode)) {
837
if ( ! empty( $correct\_permalink ) && is\_string( $correct\_permalink ) && ! empty( $redirect\_mode ) ) {
801
838
// Allow redirect
802
839
$wp\_query->query\_vars\['do\_not\_redirect'\] = 0;
803
840
804
841
// Append query string
805
$correct\_permalink = (!empty($query\_string)) ? sprintf("%s?%s", strtok($correct\_permalink, "?"), $query\_string) : $correct\_permalink;
842
$correct\_permalink = ( ! empty( $query\_string ) ) ? sprintf( "%s?%s", strtok( $correct\_permalink, "?" ), $query\_string ) : $correct\_permalink;
806
843
807
844
// Adjust trailing slashes
808
$correct\_permalink = self::control\_trailing\_slashes($correct\_permalink);
845
$correct\_permalink = self::control\_trailing\_slashes( $correct\_permalink );
809
846
810
847
// Prevent redirect loop
811
$rel\_old\_uri = wp\_make\_link\_relative($old\_uri);
812
$rel\_new\_uri = wp\_make\_link\_relative($correct\_permalink);
813
814
if($redirect\_type === 'www\_redirect' || $rel\_old\_uri !== $rel\_new\_uri) {
815
wp\_safe\_redirect($correct\_permalink, $redirect\_mode, PERMALINK\_MANAGER\_PLUGIN\_NAME);
848
$rel\_old\_uri = wp\_make\_link\_relative( $old\_uri );
849
$rel\_new\_uri = wp\_make\_link\_relative( $correct\_permalink );
850
851
if ( $redirect\_type === 'www\_redirect' || $rel\_old\_uri !== $rel\_new\_uri ) {
852
wp\_safe\_redirect( $correct\_permalink, $redirect\_mode, PERMALINK\_MANAGER\_PLUGIN\_NAME );
816
853
exit();
817
854
}
818
855
}
819
}
820
856
}
857
858
/\*\*
859
\* Control how the canonical redirect function in WordPress and other popular plugins works
860
\*/
821
861
function adjust\_canonical\_redirect() {
822
global $permalink\_manager\_options, $permalink\_manager\_uris, $wp, $wp\_rewrite;
862
global $permalink\_manager\_options, $permalink\_manager\_uris, $wp, $wp\_rewrite;
823
863
824
864
// Adjust rewrite settings for trailing slashes
825
$trailing\_slash\_setting = (!empty($permalink\_manager\_options\['general'\]\['trailing\_slashes'\])) ? $permalink\_manager\_options\['general'\]\['trailing\_slashes'\] : "";
826
if(in\_array($trailing\_slash\_setting, array(1, 10))) {
865
$trailing\_slash\_setting = ( ! empty( $permalink\_manager\_options\['general'\]\['trailing\_slashes'\] ) ) ? $permalink\_manager\_options\['general'\]\['trailing\_slashes'\] : "";
866
if ( in\_array( $trailing\_slash\_setting, array( 1, 10 ) ) ) {
827
867
$wp\_rewrite->use\_trailing\_slashes = true;
828
} else if(in\_array($trailing\_slash\_setting, array(2, 20))) {
868
} else if ( in\_array( $trailing\_slash\_setting, array( 2, 20 ) ) ) {
829
869
$wp\_rewrite->use\_trailing\_slashes = false;
830
870
}
831
871
832
872
// Get endpoints
833
$endpoints \= Permalink\_Manager\_Helper\_Functions::get\_endpoints();
834
$endpoints\_array = ($endpoints) ? explode("|", $endpoints) : array();
873
$endpoints \= Permalink\_Manager\_Helper\_Functions::get\_endpoints();
874
$endpoints\_array = ( $endpoints ) ? explode( "|", $endpoints ) : array();
835
875
836
876
// Check if any endpoint is called (fix for endpoints)
837
foreach($endpoints\_array as $endpoint) {
838
if(!empty($wp->query\_vars\[$endpoint\]) && !in\_array($endpoint, array('attachment', 'page', 'paged', 'feed'))) {
877
foreach ( $endpoints\_array as $endpoint ) {
878
if ( ! empty( $wp->query\_vars\[ $endpoint \] ) && ! in\_array( $endpoint, array( 'attachment', 'page', 'paged', 'feed' ) ) ) {
839
879
$wp->query\_vars\['do\_not\_redirect'\] = 1;
840
880
break;
…
…
843
883
844
884
// Do nothing for posts and terms without custom URIs (when canonical redirect is enabled)
845
if(is\_singular() || is\_tax() || is\_category() || is\_tag()) {
885
if ( is\_singular() || is\_tax() || is\_category() || is\_tag() ) {
846
886
$element = get\_queried\_object();
847
if(!empty($element->ID)) {
848
$custom\_uri = (!empty($permalink\_manager\_uris\[$element->ID\])) ? $permalink\_manager\_uris\[$element->ID\] : "";
849
} else if(!empty($element->term\_id)) {
850
$custom\_uri = (!empty($permalink\_manager\_uris\["tax-{$element->term\_id}"\])) ? $permalink\_manager\_uris\["tax-{$element->term\_id}"\] : "";
851
}
852
}
853
854
if(empty($permalink\_manager\_options\['general'\]\['canonical\_redirect'\])) {
855
remove\_action('template\_redirect', 'redirect\_canonical');
856
}
857
858
if(empty($permalink\_manager\_options\['general'\]\['old\_slug\_redirect'\])) {
859
remove\_action('template\_redirect', 'wp\_old\_slug\_redirect');
860
}
861
862
if(!empty($wp->query\_vars\['do\_not\_redirect'\])) {
887
if ( ! empty( $element->ID ) ) {
888
$custom\_uri = ( ! empty( $permalink\_manager\_uris\[ $element->ID \] ) ) ? $permalink\_manager\_uris\[ $element->ID \] : "";
889
} else if ( ! empty( $element->term\_id ) ) {
890
$custom\_uri = ( ! empty( $permalink\_manager\_uris\["tax-{$element->term\_id}"\] ) ) ? $permalink\_manager\_uris\["tax-{$element->term\_id}"\] : "";
891
}
892
}
893
894
if ( empty( $permalink\_manager\_options\['general'\]\['canonical\_redirect'\] ) ) {
895
remove\_action( 'template\_redirect', 'redirect\_canonical' );
896
}
897
898
if ( empty( $permalink\_manager\_options\['general'\]\['old\_slug\_redirect'\] ) ) {
899
remove\_action( 'template\_redirect', 'wp\_old\_slug\_redirect' );
900
}
901
902
if ( ! empty( $wp->query\_vars\['do\_not\_redirect'\] ) ) {
863
903
// RankMath
864
remove\_action('template\_redirect', 'do\_redirection', 11);
865
remove\_action('wp', 'do\_redirection', 11);
904
remove\_action( 'template\_redirect', 'do\_redirection', 11 );
905
remove\_action( 'wp', 'do\_redirection', 11 );
866
906
867
907
// SEOPress
868
remove\_action('template\_redirect', 'seopress\_category\_redirect', 1);
869
870
remove\_action('template\_redirect', 'wp\_old\_slug\_redirect');
871
remove\_action('template\_redirect', 'redirect\_canonical');
872
add\_filter('wpml\_is\_redirected', '\_\_return\_false', 99, 2);
873
add\_filter('pll\_check\_canonical\_url', '\_\_return\_false', 99, 2);
874
}
875
}
908
remove\_action( 'template\_redirect', 'seopress\_category\_redirect', 1 );
909
910
remove\_action( 'template\_redirect', 'wp\_old\_slug\_redirect' );
911
remove\_action( 'template\_redirect', 'redirect\_canonical' );
912
add\_filter( 'wpml\_is\_redirected', '\_\_return\_false', 99, 2 );
913
add\_filter( 'pll\_check\_canonical\_url', '\_\_return\_false', 99, 2 );
914
}
915
}
876
916
877
917
/\*\*
878
\* Case insensitive permalinks
918
\* Enable case-insensitive permalinks mode
879
919
\*/
880
920
function case\_insensitive\_permalinks() {
881
global $permalink\_manager\_options, $permalink\_manager\_uris;
882
883
if(!empty($\_SERVER\['REQUEST\_URI'\])) {
884
$\_SERVER\['REQUEST\_URI'\] = strtolower($\_SERVER\['REQUEST\_URI'\]);
885
$permalink\_manager\_uris = array\_map('strtolower', $permalink\_manager\_uris);
921
global $permalink\_manager\_uris;
922
923
if ( ! empty( $\_SERVER\['REQUEST\_URI'\] ) ) {
924
$\_SERVER\['REQUEST\_URI'\] = strtolower( $\_SERVER\['REQUEST\_URI'\] );
925
$permalink\_manager\_uris = array\_map( 'strtolower', $permalink\_manager\_uris );
886
926
}
887
927
}
permalink-manager/trunk/includes/core/permalink-manager-debug.php
r2726011
r2833667
2
2
3
3
/\*\*
4
\* Additional debug functions for "Permalink Manager Pro"
5
\*/
6
class Permalink\_Manager\_Debug\_Functions extends Permalink\_Manager\_Class {
4
\* Additional debug functions for "Permalink Manager Pro"
5
\*/
6
class Permalink\_Manager\_Debug\_Functions {
7
7
8
8
public function \_\_construct() {
9
add\_action('init', array($this, 'debug\_data'), 99);
10
}
11
9
add\_action( 'init', array( $this, 'debug\_data' ), 99 );
10
}
11
12
/\*\*
13
\* Map the debug functions to specific hooks
14
\*/
12
15
public function debug\_data() {
13
add\_filter('permalink\_manager\_filter\_query', array($this, 'debug\_query'), 9, 5);
14
add\_filter('permalink\_manager\_filter\_redirect', array($this, 'debug\_redirect'), 9, 3);
15
add\_filter('wp\_redirect', array($this, 'debug\_wp\_redirect'), 9, 2);
16
add\_filter( 'permalink\_manager\_filter\_query', array( $this, 'debug\_query' ), 9, 5 );
17
add\_filter( 'permalink\_manager\_filter\_redirect', array( $this, 'debug\_redirect' ), 9, 3 );
18
add\_filter( 'wp\_redirect', array( $this, 'debug\_wp\_redirect' ), 9, 2 );
16
19
17
20
self::debug\_custom\_redirects();
…
…
20
23
21
24
/\*\*
22
\* 1. Used in Permalink\_Manager\_Core\_Functions::detect\_post();
23
\*/
24
public function debug\_query($query, $old\_query = null, $uri\_parts = null, $pm\_query = null, $content\_type = null) {
25
\* Debug the WordPress query filtered in the Permalink\_Manager\_Core\_Functions::detect\_post(); function
26
\*
27
\* @param array $query
28
\* @param array $old\_query
29
\* @param array $uri\_parts
30
\* @param array $pm\_query
31
\* @param string $content\_type
32
\*
33
\* @return array
34
\*/
35
public function debug\_query( $query, $old\_query = null, $uri\_parts = null, $pm\_query = null, $content\_type = null ) {
25
36
global $permalink\_manager;
26
37
27
if(isset($\_REQUEST\['debug\_url'\])) {
28
$debug\_info\['uri\_parts'\] \= $uri\_parts;
38
if ( isset( $\_REQUEST\['debug\_url'\] ) ) {
39
$debug\_info\['uri\_parts'\] \= $uri\_parts;
29
40
$debug\_info\['old\_query\_vars'\] = $old\_query;
30
41
$debug\_info\['new\_query\_vars'\] = $query;
31
$debug\_info\['pm\_query'\] \= (!empty($pm\_query\['id'\])) ? $pm\_query\['id'\] : "-";
32
$debug\_info\['content\_type'\] \= (!empty($content\_type)) ? $content\_type : "-";
42
$debug\_info\['pm\_query'\] = ( ! empty( $pm\_query\['id'\] ) ) ? $pm\_query\['id'\] : "-";
43
$debug\_info\['content\_type'\] = ( ! empty( $content\_type ) ) ? $content\_type : "-";
33
44
34
45
// License key info
35
if(class\_exists('Permalink\_Manager\_Pro\_Functions')) {
46
if ( class\_exists( 'Permalink\_Manager\_Pro\_Functions' ) ) {
36
47
$license\_key = $permalink\_manager->functions\['pro-functions'\]->get\_license\_key();
37
48
38
49
// Mask the license key
39
$debug\_info\['license\_key'\] = preg\_replace('/(\[^-\]+)-(\[^-\]+)-(\[^-\]+)-(\[^-\]+)$/', '\*\*\*-\*\*\*-$3', $license\_key);
50
$debug\_info\['license\_key'\] = preg\_replace( '/(\[^-\]+)-(\[^-\]+)-(\[^-\]+)-(\[^-\]+)$/', '\*\*\*-\*\*\*-$3', $license\_key );
40
51
}
41
52
…
…
43
54
$debug\_info\['version'\] = PERMALINK\_MANAGER\_VERSION;
44
55
45
self::display\_debug\_data($debug\_info);
56
self::display\_debug\_data( $debug\_info );
46
57
}
47
58
…
…
50
61
51
62
/\*\*
52
\* 2. Used in Permalink\_Manager\_Core\_Functions::new\_uri\_redirect\_and\_404();
53
\*/
54
public function debug\_redirect($correct\_permalink, $redirect\_type, $queried\_object) {
63
\* Debug the redirect controlled by Permalink\_Manager\_Core\_Functions::new\_uri\_redirect\_and\_404();
64
\*
65
\* @param string $correct\_permalink
66
\* @param string $redirect\_type
67
\* @param mixed $queried\_object
68
\*
69
\* @return string
70
\*/
71
public function debug\_redirect( $correct\_permalink, $redirect\_type, $queried\_object ) {
55
72
global $wp\_query;
56
73
57
if(isset($\_REQUEST\['debug\_redirect'\])) {
58
$debug\_info\['query\_vars'\] \= $wp\_query->query\_vars;
59
$debug\_info\['redirect\_url'\] \= (!empty($correct\_permalink)) ? $correct\_permalink : '-';
60
$debug\_info\['redirect\_type'\] \= (!empty($redirect\_type)) ? $redirect\_type : "-";
61
$debug\_info\['queried\_object'\] = (!empty($queried\_object)) ? $queried\_object : "-";
62
63
self::display\_debug\_data($debug\_info);
74
if ( isset( $\_REQUEST\['debug\_redirect'\] ) ) {
75
$debug\_info\['query\_vars'\] \= $wp\_query->query\_vars;
76
$debug\_info\['redirect\_url'\] = ( ! empty( $correct\_permalink ) ) ? $correct\_permalink : '-';
77
$debug\_info\['redirect\_type'\] = ( ! empty( $redirect\_type ) ) ? $redirect\_type : "-";
78
$debug\_info\['queried\_object'\] = ( ! empty( $queried\_object ) ) ? $queried\_object : "-";
79
80
self::display\_debug\_data( $debug\_info );
64
81
}
65
82
…
…
68
85
69
86
/\*\*
70
\* 3. Used to debug wp\_redirect() function used in 3rd party plugins
71
\*/
72
public function debug\_wp\_redirect($url, $status) {
73
if(isset($\_GET\['debug\_wp\_redirect'\])) {
74
$debug\_info\['url'\] = $url;
75
$debug\_info\['backtrace'\] = debug\_backtrace(DEBUG\_BACKTRACE\_IGNORE\_ARGS, 10);
76
77
self::display\_debug\_data($debug\_info);
78
}
79
80
return $url;
81
}
82
83
/\*\*
84
\* 4. Outputs a list of native & custom redirects
87
\* Debug wp\_redirect() function used in 3rd party plugins
88
\*
89
\* @param string $url
90
\* @param string $status
91
\*
92
\* @return string
93
\*/
94
public function debug\_wp\_redirect( $url, $status ) {
95
if ( isset( $\_GET\['debug\_wp\_redirect'\] ) ) {
96
$debug\_info\['url'\] = $url;
97
$debug\_info\['status'\] = $status;
98
$debug\_info\['backtrace'\] = debug\_backtrace( DEBUG\_BACKTRACE\_IGNORE\_ARGS, 10 );
99
100
self::display\_debug\_data( $debug\_info );
101
}
102
103
return $url;
104
}
105
106
/\*\*
107
\* Display the list of native & custom redirects
85
108
\*/
86
109
public function debug\_custom\_redirects() {
87
global $permalink\_manager, $permalink\_manager\_uris, $permalink\_manager\_redirects;
88
89
if(isset($\_GET\['debug\_custom\_redirects'\]) && current\_user\_can('manage\_options')) {
90
if(!empty($permalink\_manager\_uris)) {
91
$uri\_post\_class = $permalink\_manager->functions\['uri-functions-post'\];
92
$uri\_tax\_class = $permalink\_manager->functions\['uri-functions-tax'\];
93
$home\_url = Permalink\_Manager\_Helper\_Functions::get\_permalink\_base();
94
95
remove\_filter('\_get\_page\_link', array($uri\_post\_class, 'custom\_post\_permalinks'), 99, 2);
96
remove\_filter('page\_link', array($uri\_post\_class, 'custom\_post\_permalinks'), 99, 2);
97
remove\_filter('post\_link', array($uri\_post\_class, 'custom\_post\_permalinks'), 99, 2);
98
remove\_filter('post\_type\_link', array($uri\_post\_class, 'custom\_post\_permalinks'), 99, 2);
99
remove\_filter('attachment\_link', array($uri\_post\_class, 'custom\_post\_permalinks'), 99, 2);
100
remove\_filter('term\_link', array($uri\_tax\_class, 'custom\_tax\_permalinks'), 999, 2 );
101
// remove\_filter('category\_link', array($uri\_tax\_class, 'custom\_tax\_permalinks'), 999, 2 );
102
// remove\_filter('tag\_link', array($uri\_tax\_class, 'custom\_tax\_permalinks'), 999, 2 );
103
104
$csv = array();
110
global $permalink\_manager\_uris, $permalink\_manager\_redirects, $permalink\_manager\_ignore\_permalink\_filters;
111
112
if ( isset( $\_GET\['debug\_custom\_redirects'\] ) && current\_user\_can( 'manage\_options' ) ) {
113
$home\_url = Permalink\_Manager\_Helper\_Functions::get\_permalink\_base();
114
$csv = array();
115
116
if ( ! empty( $permalink\_manager\_uris ) ) {
117
$permalink\_manager\_ignore\_permalink\_filters = true;
105
118
106
119
// Native redirects
107
foreach($permalink\_manager\_uris as $element\_id => $uri) {
108
if(is\_numeric($element\_id)) {
109
$original\_permalink = user\_trailingslashit(get\_permalink($element\_id));
110
$custom\_permalink = user\_trailingslashit($home\_url . "/" . $uri);
120
foreach ( $permalink\_manager\_uris as $element\_id => $uri ) {
121
if ( is\_numeric( $element\_id ) ) {
122
$original\_permalink = user\_trailingslashit( get\_permalink( $element\_id ) );
111
123
} else {
112
$term\_id = preg\_replace("/\[^0-9\]/", "", $element\_id);
113
$term = get\_term($term\_id);
114
115
if(empty($term->taxonomy)) { continue; }
116
117
$original\_permalink = user\_trailingslashit(get\_term\_link($term->term\_id, $term->taxonomy));
118
$custom\_permalink = user\_trailingslashit($home\_url . "/" . $uri);
119
}
120
121
if($original\_permalink == $custom\_permalink && $original\_permalink !== '/') { continue; }
122
123
$csv\[$element\_id\] = array(
124
$term\_id = preg\_replace( "/\[^0-9\]/", "", $element\_id );
125
$term = get\_term( $term\_id );
126
127
if ( empty( $term->taxonomy ) ) {
128
continue;
129
}
130
131
$original\_permalink = user\_trailingslashit( get\_term\_link( $term->term\_id, $term->taxonomy ) );
132
}
133
134
$custom\_permalink = user\_trailingslashit( $home\_url . "/" . $uri );
135
136
if ( $original\_permalink == $custom\_permalink && $original\_permalink !== '/' ) {
137
continue;
138
}
139
140
$csv\[ $element\_id \] = array(
124
141
'type' => 'native\_redirect',
125
142
'from' => $original\_permalink,
126
'to' \=> $custom\_permalink
143
'to' \=> $custom\_permalink
127
144
);
128
145
}
…
…
130
147
131
148
// Custom redirects
132
if($permalink\_manager\_redirects) {
133
foreach($permalink\_manager\_redirects as $element\_id => $redirects) {
134
if(empty($permalink\_manager\_uris\[$element\_id\])) { continue; }
135
$custom\_permalink = user\_trailingslashit($home\_url . "/" . $permalink\_manager\_uris\[$element\_id\]);
136
137
if(is\_array($redirects)) {
138
$redirects = array\_values($redirects);
139
$redirects\_count = count($redirects);
140
141
foreach($redirects as $index => $redirect) {
142
$redirect\_url = user\_trailingslashit($home\_url . "/" . $redirect);
149
if ( $permalink\_manager\_redirects ) {
150
foreach ( $permalink\_manager\_redirects as $element\_id => $redirects ) {
151
if ( empty( $permalink\_manager\_uris\[ $element\_id \] ) ) {
152
continue;
153
}
154
$custom\_permalink = user\_trailingslashit( $home\_url . "/" . $permalink\_manager\_uris\[ $element\_id \] );
155
156
if ( is\_array( $redirects ) ) {
157
$redirects = array\_values( $redirects );
158
// $redirects\_count = count( $redirects );
159
160
foreach ( $redirects as $index => $redirect ) {
161
$redirect\_url = user\_trailingslashit( $home\_url . "/" . $redirect );
143
162
144
163
$csv\["extra-redirect-{$index}-{$element\_id}"\] = array(
145
164
'type' => 'extra\_redirect',
146
165
'from' => $redirect\_url,
147
'to' \=> $custom\_permalink
166
'to' \=> $custom\_permalink
148
167
);
149
168
}
…
…
152
171
}
153
172
154
echo self::output\_csv($csv);
173
echo self::output\_csv( $csv );
155
174
die();
156
175
}
157
176
}
158
177
178
/\*\*
179
\* Display the list of all custom fields assigned to specific post
180
\*/
159
181
public static function debug\_custom\_fields() {
160
global $pagenow, $post;
161
162
if($pagenow == 'post.php' && isset($\_GET\['debug\_custom\_fields'\]) && isset($\_GET\['post'\])) {
163
$post\_id = intval($\_GET\['post'\]);
164
$custom\_fields = get\_post\_meta($post\_id);
165
166
self::display\_debug\_data($custom\_fields);
167
}
168
}
169
170
/\*\*
171
\* A function used to display the debug data in various functions
172
\*/
173
public static function display\_debug\_data($debug\_info) {
174
$debug\_txt = print\_r($debug\_info, true);
175
$debug\_txt = sprintf("<pre style=\\"display:block;\\">%s</pre>", esc\_html($debug\_txt));
176
177
wp\_die($debug\_txt);
178
}
179
180
public static function output\_csv($array, $filename = 'debug.csv') {
181
if(count($array) == 0) {
182
global $pagenow;
183
184
if ( $pagenow == 'post.php' && isset( $\_GET\['debug\_custom\_fields'\] ) && isset( $\_GET\['post'\] ) ) {
185
$post\_id = intval( $\_GET\['post'\] );
186
$custom\_fields = get\_post\_meta( $post\_id );
187
188
self::display\_debug\_data( $custom\_fields );
189
}
190
}
191
192
/\*\*
193
\* A helper function used to display the debug data in various functions
194
\*
195
\* @param mixed $debug\_info
196
\*/
197
public static function display\_debug\_data( $debug\_info ) {
198
$debug\_txt = print\_r( $debug\_info, true );
199
$debug\_txt = sprintf( "<pre style=\\"display:block;\\">%s</pre>", esc\_html( $debug\_txt ) );
200
201
wp\_die( $debug\_txt );
202
}
203
204
/\*\*
205
\* Generate a CSV file from array
206
\*
207
\* @param array $array
208
\* @param string $filename
209
\*/
210
public static function output\_csv( $array, $filename = 'debug.csv' ) {
211
if ( count( $array ) == 0 ) {
182
212
return null;
183
213
}
184
214
185
215
// Disable caching
186
$now = gmdate("D, d M Y H:i:s");
187
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
188
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
189
header("Last-Modified: {$now} GMT");
216
$now = gmdate( "D, d M Y H:i:s" );
217
header( "Expires: Tue, 03 Jul 2001 06:00:00 GMT" );
218
header( "Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate" );
219
header( "Last-Modified: {$now} GMT" );
190
220
191
221
// Force download
192
header("Content-Type: application/force-download");
193
header("Content-Type: application/octet-stream");
194
header("Content-Type: application/download");
195
header('Content-Type: text/csv');
222
header( "Content-Type: application/force-download" );
223
header( "Content-Type: application/octet-stream" );
224
header( "Content-Type: application/download" );
225
header( 'Content-Type: text/csv' );
196
226
197
227
// Disposition / encoding on response body
198
header("Content-Disposition: attachment;filename={$filename}");
199
header("Content-Transfer-Encoding: binary");
228
header( "Content-Disposition: attachment;filename={$filename}" );
229
header( "Content-Transfer-Encoding: binary" );
200
230
201
231
ob\_start();
202
232
203
$df = fopen("php://output", 'w');
204
205
fputcsv($df, array\_keys(reset($array)));
206
foreach ($array as $row) {
207
fputcsv($df, $row);
208
}
209
fclose($df);
233
$df = fopen( "php://output", 'w' );
234
235
fputcsv( $df, array\_keys( reset( $array ) ) );
236
foreach ( $array as $row ) {
237
fputcsv( $df, $row );
238
}
239
fclose( $df );
210
240
211
241
echo ob\_get\_clean();
…
…
214
244
215
245
}
216
217
?>
permalink-manager/trunk/includes/core/permalink-manager-gutenberg.php
r2796526
r2833667
2
2
3
3
/\*\*
4
\* Additional hooks for "Permalink Manager Pro"
5
\*/
6
class Permalink\_Manager\_Gutenberg extends Permalink\_Manager\_Class {
4
\* Support for Gutenberg editor
5
\*/
6
class Permalink\_Manager\_Gutenberg {
7
7
8
8
public function \_\_construct() {
9
add\_action('enqueue\_block\_editor\_assets', array($this, 'init'));
9
add\_action( 'enqueue\_block\_editor\_assets', array( $this, 'init' ) );
10
10
11
add\_action('wp\_ajax\_pm\_get\_uri\_editor', array($this, 'get\_uri\_editor'));
12
add\_action('wp\_ajax\_nopriv\_pm\_get\_uri\_editor', array($this, 'get\_uri\_editor'));
11
add\_action( 'wp\_ajax\_pm\_get\_uri\_editor', array( $this, 'get\_uri\_editor' ) );
12
add\_action( 'wp\_ajax\_nopriv\_pm\_get\_uri\_editor', array( $this, 'get\_uri\_editor' ) );
13
13
}
14
14
15
/\*\*
16
\* Add URI Editor meta box to Gutenberg editor
17
\*/
15
18
public function init() {
16
19
global $current\_screen, $post;
17
20
18
21
// Get displayed post type
19
if(empty($current\_screen->post\_type)) { return; }
20
$post\_type = $current\_screen->post\_type;
22
if ( empty( $current\_screen->post\_type ) ) {
23
return;
24
}
21
25
22
26
// Stop the hook (if needed)
23
$show\_uri\_editor = apply\_filters("permalink\_manager\_show\_uri\_editor\_post\_{$post->post\_type}", true, $post);
24
if(!$show\_uri\_editor) {
27
$show\_uri\_editor = apply\_filters( "permalink\_manager\_show\_uri\_editor\_post", true, $post, $post->post\_type );
28
if ( ! $show\_uri\_editor ) {
25
29
return;
26
30
}
27
31
28
32
// Check the user capabilities
29
if(Permalink\_Manager\_Admin\_Functions::current\_user\_can\_edit\_uris() === false) {
33
if ( Permalink\_Manager\_Admin\_Functions::current\_user\_can\_edit\_uris() === false ) {
30
34
return;
31
35
}
32
36
33
37
// Check if the post is excluded
34
if(!empty($post->ID) && Permalink\_Manager\_Helper\_Functions::is\_post\_excluded($post)) {
38
if ( ! empty( $post->ID ) && Permalink\_Manager\_Helper\_Functions::is\_post\_excluded( $post ) ) {
35
39
return;
36
40
}
37
41
38
add\_meta\_box('permalink-manager', \_\_('Permalink Manager', 'permalink-manager'), array($this, 'get\_uri\_editor'), '', 'side', 'high' );
42
add\_meta\_box( 'permalink-manager', \_\_( 'Permalink Manager', 'permalink-manager' ), array( $this, 'get\_uri\_editor' ), '', 'side', 'high' );
39
43
// wp\_enqueue\_script('permalink-manager-gutenberg', PERMALINK\_MANAGER\_URL . '/out/permalink-manager-gutenberg.js', array('wp-plugins', 'wp-edit-post', 'wp-i18n', 'wp-element'));
40
44
}
41
45
42
public function get\_uri\_editor($post = null) {
43
if(empty($post->ID) && empty($\_REQUEST\['post\_id'\])) {
44
return '';
45
} else if(!empty($\_REQUEST\['post\_id'\]) && is\_numeric($\_REQUEST\['post\_id'\])) {
46
$post = get\_post($\_REQUEST\['post\_id'\]);
46
/\*\*
47
\* Display the URI Editor for specific post
48
\*
49
\* @param WP\_Post|int $post
50
\*/
51
public function get\_uri\_editor( $post = null ) {
52
if ( empty( $post->ID ) && empty( $\_REQUEST\['post\_id'\] ) ) {
53
return;
54
} else if ( ! empty( $\_REQUEST\['post\_id'\] ) && is\_numeric( $\_REQUEST\['post\_id'\] ) ) {
55
$post = get\_post( $\_REQUEST\['post\_id'\] );
47
56
}
48
57
49
58
// Display URI Editor
50
echo ($post) ? Permalink\_Manager\_Admin\_Functions::display\_uri\_box($post, true) : '';
59
echo ( $post ) ? Permalink\_Manager\_Admin\_Functions::display\_uri\_box( $post, true ) : '';
51
60
52
if(wp\_doing\_ajax()) {
61
if ( wp\_doing\_ajax() ) {
53
62
die();
54
63
}
…
…
56
65
57
66
}
58
59
?>
permalink-manager/trunk/includes/core/permalink-manager-helper-functions.php
r2803362
r2833667
2
2
3
3
/\*\*
4
\* Additional functions used in classes and another subclasses
5
\*/
6
class Permalink\_Manager\_Helper\_Functions extends Permalink\_Manager\_Class {
4
\* Helper functions used in classes and another subclasses
5
\*/
6
class Permalink\_Manager\_Helper\_Functions {
7
7
8
8
public function \_\_construct() {
9
add\_action('plugins\_loaded', array($this, 'init'), 5);
10
}
11
9
add\_action( 'plugins\_loaded', array( $this, 'init' ), 5 );
10
}
11
12
/\*\*
13
\* Add hooks used by plugin to filter the custom permalinks
14
\*/
12
15
public function init() {
13
16
// Replace empty placeholder tags & remove BOM
14
add\_filter( 'permalink\_manager\_filter\_default\_post\_uri', array($this, 'replace\_empty\_placeholder\_tags'), 10, 5);
15
add\_filter( 'permalink\_manager\_filter\_default\_term\_uri', array($this, 'replace\_empty\_placeholder\_tags'), 10, 5);
17
add\_filter( 'permalink\_manager\_filter\_default\_post\_uri', array( $this, 'replace\_empty\_placeholder\_tags' ), 10, 5 );
18
add\_filter( 'permalink\_manager\_filter\_default\_term\_uri', array( $this, 'replace\_empty\_placeholder\_tags' ), 10, 5 );
16
19
17
20
// Clear the final default URIs
18
add\_filter( 'permalink\_manager\_filter\_default\_term\_uri', array($this, 'clear\_single\_uri'), 20);
19
add\_filter( 'permalink\_manager\_filter\_default\_post\_uri', array($this, 'clear\_single\_uri'), 20);
21
add\_filter( 'permalink\_manager\_filter\_default\_term\_uri', array( $this, 'clear\_single\_uri' ), 20 );
22
add\_filter( 'permalink\_manager\_filter\_default\_post\_uri', array( $this, 'clear\_single\_uri' ), 20 );
20
23
21
24
// Reload the globals when the blog is switched (multisite)
22
add\_action('switch\_blog', array($this, 'reload\_globals\_in\_network'), 9);
25
add\_action( 'switch\_blog', array( $this, 'reload\_globals\_in\_network' ), 9 );
23
26
}
24
27
25
28
/\*\*
26
29
\* Support for multidimensional arrays - array\_map()
27
\*/
28
static function multidimensional\_array\_map($function, $input) {
30
\*
31
\* @param string $function
32
\* @param array $input
33
\*
34
\* @return array
35
\*/
36
static function multidimensional\_array\_map( $function, $input ) {
29
37
$output = array();
30
38
31
if(is\_array($input)) {
32
foreach ($input as $key => $val) {
33
$output\[$key\] = (is\_array($val) ? self::multidimensional\_array\_map($function, $val) : $function($val));
39
if ( is\_array( $input ) ) {
40
foreach ( $input as $key => $val ) {
41
$output\[ $key \] = ( is\_array( $val ) ? self::multidimensional\_array\_map( $function, $val ) : $function( $val ) );
34
42
}
35
43
} else {
36
$output = $function($input);
44
$output = $function( $input );
37
45
}
38
46
…
…
41
49
42
50
/\*\*
43
\* Get primary term
44
\*/
45
static function get\_primary\_term($post\_id, $taxonomy, $slug\_only = true) {
51
\* Get the primary term for the specific post
52
\*
53
\* @param int $post\_id
54
\* @param string $taxonomy
55
\* @param bool $slug\_only
56
\*
57
\* @return array|string|WP\_Term
58
\*/
59
static function get\_primary\_term( $post\_id, $taxonomy, $slug\_only = true ) {
46
60
global $permalink\_manager\_options;
47
61
48
$primary\_term\_enabled = (isset($permalink\_manager\_options\['general'\]\['primary\_category'\])) ? (bool) $permalink\_manager\_options\['general'\]\['primary\_category'\] : true;
49
$primary\_term\_enabled = apply\_filters('permalink\_manager\_primary\_term', $primary\_term\_enabled);
50
51
if(!$primary\_term\_enabled) { return; }
62
$primary\_term\_enabled = ( isset( $permalink\_manager\_options\['general'\]\['primary\_category'\] ) ) ? (bool) $permalink\_manager\_options\['general'\]\['primary\_category'\] : true;
63
$primary\_term\_enabled = apply\_filters( 'permalink\_manager\_primary\_term', $primary\_term\_enabled );
64
65
if ( ! $primary\_term\_enabled ) {
66
return '';
67
}
52
68
53
69
// A. Yoast SEO
54
if(class\_exists('WPSEO\_Primary\_Term')) {
55
$yoast\_primary\_term\_label = sprintf('yoast\_wpseo\_primary\_%s\_term', $taxonomy);
56
57
// Hotfix: Yoast SEO saves the primary term using 'save\_post' hook with highest priority, so the primary term ID is taken directly from $\_POST
58
if(!empty($\_POST\[$yoast\_primary\_term\_label\])) {
59
$yoast\_primary\_term\_id = filter\_input(INPUT\_POST, $yoast\_primary\_term\_label, FILTER\_SANITIZE\_NUMBER\_INT);
70
if ( class\_exists( 'WPSEO\_Primary\_Term' ) ) {
71
$yoast\_primary\_term\_label = sprintf( 'yoast\_wpseo\_primary\_%s\_term', $taxonomy );
72
73
// Hotfix: Yoast SEO saves the primary term using 'save\_post' hook with the highest priority, so the primary term ID is taken directly from $\_POST
74
if ( ! empty( $\_POST\[ $yoast\_primary\_term\_label \] ) ) {
75
$yoast\_primary\_term\_id = filter\_input( INPUT\_POST, $yoast\_primary\_term\_label, FILTER\_SANITIZE\_NUMBER\_INT );
60
76
} else {
61
$yoast\_primary\_term \= new WPSEO\_Primary\_Term($taxonomy, $post\_id);
77
$yoast\_primary\_term = new WPSEO\_Primary\_Term( $taxonomy, $post\_id );
62
78
$yoast\_primary\_term\_id = $yoast\_primary\_term->get\_primary\_term();
63
79
}
64
80
65
$primary\_term = (is\_numeric($yoast\_primary\_term\_id)) ? get\_term($yoast\_primary\_term\_id, $taxonomy) : '';
66
}
67
// B. The SEO Framework
68
else if(function\_exists('the\_seo\_framework')) {
69
$primary\_term = the\_seo\_framework()->get\_primary\_term($post\_id, $taxonomy);
70
}
71
// C. RankMath
72
else if(class\_exists('RankMath')) {
73
$primary\_cat\_id = get\_post\_meta($post\_id, "rank\_math\_primary\_{$taxonomy}", true);
74
$primary\_term = (!empty($primary\_cat\_id)) ? get\_term($primary\_cat\_id, $taxonomy) : '';
75
}
76
// D. SEOPress
77
else if(function\_exists('seopress\_init') && $taxonomy == 'category') {
78
$primary\_cat\_id = get\_post\_meta($post\_id, '\_seopress\_robots\_primary\_cat', true);
79
$primary\_term = (!empty($primary\_cat\_id)) ? get\_term($primary\_cat\_id, 'category') : '';
80
}
81
82
if(!empty($primary\_term) && !is\_wp\_error($primary\_term)) {
83
return ($slug\_only) ? $primary\_term->slug : $primary\_term;
81
$primary\_term = ( is\_numeric( $yoast\_primary\_term\_id ) ) ? get\_term( $yoast\_primary\_term\_id, $taxonomy ) : '';
82
} // B. The SEO Framework
83
else if ( function\_exists( 'the\_seo\_framework' ) ) {
84
$primary\_term = the\_seo\_framework()->get\_primary\_term( $post\_id, $taxonomy );
85
} // C. RankMath
86
else if ( class\_exists( 'RankMath' ) ) {
87
$primary\_cat\_id = get\_post\_meta( $post\_id, "rank\_math\_primary\_{$taxonomy}", true );
88
$primary\_term = ( ! empty( $primary\_cat\_id ) ) ? get\_term( $primary\_cat\_id, $taxonomy ) : '';
89
} // D. SEOPress
90
else if ( function\_exists( 'seopress\_init' ) && $taxonomy == 'category' ) {
91
$primary\_cat\_id = get\_post\_meta( $post\_id, '\_seopress\_robots\_primary\_cat', true );
92
$primary\_term = ( ! empty( $primary\_cat\_id ) ) ? get\_term( $primary\_cat\_id, 'category' ) : '';
93
}
94
95
if ( ! empty( $primary\_term ) && ! is\_wp\_error( $primary\_term ) ) {
96
return ( $slug\_only ) ? $primary\_term->slug : $primary\_term;
84
97
} else {
85
return;
86
}
87
}
88
89
/\*\*
90
\* Get lowest level term/post
91
\*/
92
static function get\_lowest\_element($first\_element, $elements) {
93
if(!empty($elements) && !empty($first\_element)) {
98
return '';
99
}
100
}
101
102
/\*\*
103
\* Get the lowest level term/post in the specific array
104
\*
105
\* @param WP\_Post|WP\_Term|int $first\_element
106
\* @param array $elements
107
\*
108
\* @return WP\_Post|WP\_Term|int
109
\*/
110
static function get\_lowest\_element( $first\_element, $elements ) {
111
if ( ! empty( $elements ) && ! empty( $first\_element ) ) {
94
112
// Get the ID of first element
95
if(!empty($first\_element->term\_id)) {
113
if ( ! empty( $first\_element->term\_id ) ) {
96
114
$first\_element\_id = $first\_element->term\_id;
97
$parent\_key \= 'parent';
98
} else if(!empty($first\_element->ID)) {
115
$parent\_key \= 'parent';
116
} else if ( ! empty( $first\_element->ID ) ) {
99
117
$first\_element\_id = $first\_element->ID;
100
$parent\_key \= 'post\_parent';
101
} else if(is\_numeric($first\_element)) {
118
$parent\_key \= 'post\_parent';
119
} else if ( is\_numeric( $first\_element ) ) {
102
120
$first\_element\_id = $first\_element;
103
$parent\_key \= 'post\_parent';
121
$parent\_key \= 'post\_parent';
104
122
} else {
105
123
return false;
106
124
}
107
125
108
$children = wp\_filter\_object\_list($elements, array($parent\_key => $first\_element\_id));
109
if(!empty($children)) {
126
$children = wp\_filter\_object\_list( $elements, array( $parent\_key => $first\_element\_id ) );
127
if ( ! empty( $children ) ) {
110
128
// Get the first term
111
$child\_term = reset($children);
112
$first\_element = self::get\_lowest\_element($child\_term, $elements);
113
}
114
}
129
$child\_term = reset( $children );
130
$first\_element = self::get\_lowest\_element( $child\_term, $elements );
131
}
132
}
133
115
134
return $first\_element;
116
135
}
117
136
118
137
/\*\*
119
\* Get term full slug
120
\*/
121
static function get\_term\_full\_slug($term, $terms, $mode = false, $native\_uri = false) {
138
\* Get the full (hierarchical) slug for specific term object
139
\*
140
\* @param WP\_Term $term
141
\* @param mixed|WP\_Term\[\] $terms
142
\* @param bool $mode
143
\* @param bool $native\_uri
144
\*
145
\* @return string
146
\*/
147
static function get\_term\_full\_slug( $term, $terms, $mode = false, $native\_uri = false ) {
122
148
global $permalink\_manager\_uris;
123
149
124
150
// Check if term is not empty
125
if(empty($term->taxonomy)) { return ''; }
151
if ( empty( $term->taxonomy ) ) {
152
return '';
153
}
126
154
127
155
// Get taxonomy
…
…
129
157
130
158
// Check if mode is set
131
if(empty($mode)) {
132
$mode = (is\_taxonomy\_hierarchical($taxonomy)) ? 2 : 4;
159
if ( empty( $mode ) ) {
160
$mode = ( is\_taxonomy\_hierarchical( $taxonomy ) ) ? 2 : 4;
133
161
}
134
162
135
163
// A. Inherit the custom permalink from the term
136
if($mode == 1) {
137
$term\_slug = (!empty($permalink\_manager\_uris\["tax-{$term->term\_id}"\])) ? $permalink\_manager\_uris\["tax-{$term->term\_id}"\] : '';
138
}
139
// B. Hierarhcical taxonomy base
140
else if($mode == 2) {
141
$ancestors = get\_ancestors($term->term\_id, $taxonomy, 'taxonomy');
164
if ( $mode == 1 ) {
165
$term\_slug = ( ! empty( $permalink\_manager\_uris\["tax-{$term->term\_id}"\] ) ) ? $permalink\_manager\_uris\["tax-{$term->term\_id}"\] : '';
166
} // B. Hierarchical taxonomy base
167
else if ( $mode == 2 ) {
168
$ancestors = get\_ancestors( $term->term\_id, $taxonomy, 'taxonomy' );
142
169
$hierarchical\_slugs = array();
143
170
144
foreach((array) $ancestors as $ancestor) {
145
$ancestor\_term \= get\_term($ancestor, $taxonomy);
146
$hierarchical\_slugs\[\] = ($native\_uri) ? $ancestor\_term->slug : self::force\_custom\_slugs($ancestor\_term->slug, $ancestor\_term);
147
}
148
$hierarchical\_slugs = array\_reverse($hierarchical\_slugs);
149
$term\_slug \= implode('/', $hierarchical\_slugs);
171
foreach ( $ancestors as $ancestor ) {
172
$ancestor\_term = get\_term( $ancestor, $taxonomy );
173
$hierarchical\_slugs\[\] = ( $native\_uri ) ? $ancestor\_term->slug : self::force\_custom\_slugs( $ancestor\_term->slug, $ancestor\_term );
174
}
175
$hierarchical\_slugs = array\_reverse( $hierarchical\_slugs );
176
$term\_slug = implode( '/', $hierarchical\_slugs );
150
177
151
178
// Append the term slug now
152
$last\_term\_slug = ($native\_uri) ? $term->slug : self::force\_custom\_slugs($term->slug, $term);
153
$term\_slug = "{$term\_slug}/{$last\_term\_slug}";
154
}
155
// C. Force flat taxonomy base - get highest level term (if %taxonomy\_top% tag is used)
156
else if($mode == 3) {
157
if(!empty($term->parent)) {
158
$ancestors = get\_ancestors($term->term\_id, $taxonomy, 'taxonomy');
159
160
if(is\_array($ancestors)) {
161
$top\_ancestor = end($ancestors);
162
$top\_ancestor\_term = get\_term($top\_ancestor, $taxonomy);
163
$single\_term = (!empty($top\_ancestor\_term->slug)) ? $top\_ancestor\_term : $term;
164
}
165
}
166
167
$term\_slug = (!empty($single\_term->slug)) ? self::force\_custom\_slugs($single\_term->slug, $single\_term) : $term->slug;
168
}
169
// D. Force flat taxonomy base - get primary or lowest level term (if term is non-hierarchical or %taxonomy\_flat% tag is used)
179
$last\_term\_slug = ( $native\_uri ) ? $term->slug : self::force\_custom\_slugs( $term->slug, $term );
180
$term\_slug = "{$term\_slug}/{$last\_term\_slug}";
181
} // C. Force flat taxonomy base - get the highest level term (if %taxonomy\_top% tag is used)
182
else if ( $mode == 3 ) {
183
if ( ! empty( $term->parent ) ) {
184
$ancestors = get\_ancestors( $term->term\_id, $taxonomy, 'taxonomy' );
185
186
if ( is\_array( $ancestors ) ) {
187
$top\_ancestor = end( $ancestors );
188
$top\_ancestor\_term = get\_term( $top\_ancestor, $taxonomy );
189
$single\_term = ( ! empty( $top\_ancestor\_term->slug ) ) ? $top\_ancestor\_term : $term;
190
}
191
}
192
193
$term\_slug = ( ! empty( $single\_term->slug ) ) ? self::force\_custom\_slugs( $single\_term->slug, $single\_term ) : $term->slug;
194
} // D. Force flat taxonomy base - get primary or lowest level term (if term is non-hierarchical or %taxonomy\_flat% tag is used)
170
195
else {
171
if(!empty($term->slug)) {
172
$term\_slug = ($native\_uri) ? $term->slug : Permalink\_Manager\_Helper\_Functions::force\_custom\_slugs($term->slug, $term);
173
} else {
174
foreach($terms as $single\_term) {
175
if($single\_term->parent == 0) {
176
$term\_slug = self::force\_custom\_slugs($single\_term->slug, $single\_term);
196
if ( ! empty( $term->slug ) ) {
197
$term\_slug = ( $native\_uri ) ? $term->slug : Permalink\_Manager\_Helper\_Functions::force\_custom\_slugs( $term->slug, $term );
198
} else if ( !empty ( $terms ) ) {
199
foreach ( $terms as $single\_term ) {
200
if ( $single\_term->parent == 0 ) {
201
$term\_slug = self::force\_custom\_slugs( $single\_term->slug, $single\_term );
177
202
break;
178
203
}
…
…
181
206
}
182
207
183
return (!empty($term\_slug)) ? $term\_slug : "";
208
return ( ! empty( $term\_slug ) ) ? $term\_slug : "";
184
209
}
185
210
…
…
187
212
\* Allow to disable post types and taxonomies
188
213
\*/
189
static function get\_disabled\_post\_types($include\_user\_excluded = true) {
214
static function get\_disabled\_post\_types( $include\_user\_excluded = true ) {
190
215
global $wp\_post\_types, $permalink\_manager\_options;
191
216
192
217
$disabled\_post\_types = array(
193
'revision', 'nav\_menu\_item', 'algolia\_task', 'fl\_builder', 'fl-builder', 'fl-builder-template', 'fl-theme-layout', 'fusion\_tb\_layout', 'fusion\_tb\_section', 'fusion\_template', 'fusion\_element', 'wc\_product\_tab', 'wc\_voucher', 'wc\_voucher\_template',
194
'sliders', 'thirstylink', 'elementor\_library', 'elementor\_menu\_item', 'cms\_block', 'nooz\_coverage'
218
'revision',
219
'nav\_menu\_item',
220
'algolia\_task',
221
'fl\_builder',
222
'fl-builder',
223
'fl-builder-template',
224
'fl-theme-layout',
225
'fusion\_tb\_layout',
226
'fusion\_tb\_section',
227
'fusion\_template',
228
'fusion\_element',
229
'wc\_product\_tab',
230
'wc\_voucher',
231
'wc\_voucher\_template',
232
'sliders',
233
'thirstylink',
234
'elementor\_library',
235
'elementor\_menu\_item',
236
'cms\_block',
237
'nooz\_coverage'
195
238
);
196
239
197
240
// 1. Disable post types that are not publicly\_queryable
198
foreach($wp\_post\_types as $post\_type) {
199
if(!is\_post\_type\_viewable($post\_type) || (empty($post\_type->query\_var) && empty($post\_type->rewrite) && empty($post\_type->\_builtin) && !empty($permalink\_manager\_options\['general'\]\['partial\_disable\_strict'\]))) {
241
foreach ( $wp\_post\_types as $post\_type ) {
242
if ( ! is\_post\_type\_viewable( $post\_type ) || ( empty( $post\_type->query\_var ) && empty( $post\_type->rewrite ) && empty( $post\_type->\_builtin ) && ! empty( $permalink\_manager\_options\['general'\]\['partial\_disable\_strict'\] ) ) ) {
200
243
$disabled\_post\_types\[\] = $post\_type->name;
201
244
}
…
…
203
246
204
247
// 2. Add post types disabled by user
205
if($include\_user\_excluded) {
206
$disabled\_post\_types = (!empty($permalink\_manager\_options\['general'\]\['partial\_disable'\]\['post\_types'\])) ? array\_merge((array) $permalink\_manager\_options\['general'\]\['partial\_disable'\]\['post\_types'\], $disabled\_post\_types) : $disabled\_post\_types;
207
}
208
209
return apply\_filters('permalink\_manager\_disabled\_post\_types', $disabled\_post\_types);
210
}
211
212
static function get\_disabled\_taxonomies($include\_user\_excluded = true) {
248
if ( $include\_user\_excluded ) {
249
$disabled\_post\_types = ( ! empty( $permalink\_manager\_options\['general'\]\['partial\_disable'\]\['post\_types'\] ) ) ? array\_merge( (array) $permalink\_manager\_options\['general'\]\['partial\_disable'\]\['post\_types'\], $disabled\_post\_types ) : $disabled\_post\_types;
250
}
251
252
return apply\_filters( 'permalink\_manager\_disabled\_post\_types', $disabled\_post\_types );
253
}
254
255
/\*\*
256
\* Get the array of all (including/excluding user selected) disabled taxonomies
257
\*
258
\* @param bool $include\_user\_excluded
259
\*
260
\* @return array
261
\*/
262
static function get\_disabled\_taxonomies( $include\_user\_excluded = true ) {
213
263
global $wp\_taxonomies, $permalink\_manager\_options;
214
264
215
265
$disabled\_taxonomies = array(
216
'product\_shipping\_class', 'post\_status', 'fl-builder-template-category', 'post\_format', 'nav\_menu', 'language'
266
'product\_shipping\_class',
267
'post\_status',
268
'fl-builder-template-category',
269
'post\_format',
270
'nav\_menu',
271
'language'
217
272
);
218
273
219
274
// 1. Disable taxonomies that are not publicly\_queryable
220
foreach($wp\_taxonomies as $taxonomy) {
221
if(!is\_taxonomy\_viewable($taxonomy) || (empty($taxonomy->query\_var) && empty($taxonomy->rewrite) && empty($taxonomy->\_builtin) && !empty($permalink\_manager\_options\['general'\]\['partial\_disable\_strict'\]))) {
275
foreach ( $wp\_taxonomies as $taxonomy ) {
276
if ( ! is\_taxonomy\_viewable( $taxonomy ) || ( empty( $taxonomy->query\_var ) && empty( $taxonomy->rewrite ) && empty( $taxonomy->\_builtin ) && ! empty( $permalink\_manager\_options\['general'\]\['partial\_disable\_strict'\] ) ) ) {
222
277
$disabled\_taxonomies\[\] = $taxonomy->name;
223
278
}
…
…
225
280
226
281
// 2. Add taxonomies disabled by user
227
if($include\_user\_excluded) {
228
$disabled\_taxonomies = (!empty($permalink\_manager\_options\['general'\]\['partial\_disable'\]\['taxonomies'\])) ? array\_merge((array) $permalink\_manager\_options\['general'\]\['partial\_disable'\]\['taxonomies'\], $disabled\_taxonomies) : $disabled\_taxonomies;
229
}
230
231
return apply\_filters('permalink\_manager\_disabled\_taxonomies', $disabled\_taxonomies);
232
}
233
234
/\*\*
235
\* Check if post type should be ignored by Permalink Manager
236
\*/
237
static public function is\_post\_type\_disabled($post\_type, $check\_if\_exists = true) {
282
if ( $include\_user\_excluded ) {
283
$disabled\_taxonomies = ( ! empty( $permalink\_manager\_options\['general'\]\['partial\_disable'\]\['taxonomies'\] ) ) ? array\_merge( (array) $permalink\_manager\_options\['general'\]\['partial\_disable'\]\['taxonomies'\], $disabled\_taxonomies ) : $disabled\_taxonomies;
284
}
285
286
return apply\_filters( 'permalink\_manager\_disabled\_taxonomies', $disabled\_taxonomies );
287
}
288
289
/\*\*
290
\* Check if the post type should be ignored by Permalink Manager
291
\*
292
\* @param string $post\_type
293
\* @param bool $check\_if\_exists
294
\*
295
\* @return bool
296
\*/
297
static public function is\_post\_type\_disabled( $post\_type, $check\_if\_exists = true ) {
238
298
$disabled\_post\_types = self::get\_disabled\_post\_types();
239
$post\_type\_exists = ($check\_if\_exists) ? post\_type\_exists($post\_type) : true;
240
$out = ((is\_array($disabled\_post\_types) && in\_array($post\_type, $disabled\_post\_types)) || empty($post\_type\_exists)) ? true : false;
241
242
return $out;
243
}
244
245
/\*\*
246
\* Check if taxonomy should be ignored by Permalink Manager
247
\*/
248
static public function is\_taxonomy\_disabled($taxonomy, $check\_if\_exists = true) {
299
$post\_type\_exists = ( $check\_if\_exists ) ? post\_type\_exists( $post\_type ) : true;
300
301
return ( ( is\_array( $disabled\_post\_types ) && in\_array( $post\_type, $disabled\_post\_types ) ) || empty( $post\_type\_exists ) ) ? true : false;
302
}
303
304
/\*\*
305
\* Check if the taxonomy should be ignored by Permalink Manager
306
\*
307
\* @param string $taxonomy
308
\* @param bool $check\_if\_exists
309
\*
310
\* @return bool
311
\*/
312
static public function is\_taxonomy\_disabled( $taxonomy, $check\_if\_exists = true ) {
249
313
$disabled\_taxonomies = self::get\_disabled\_taxonomies();
250
$taxonomy\_exists = ($check\_if\_exists) ? taxonomy\_exists($taxonomy) : true;
251
$out = ((is\_array($disabled\_taxonomies) && in\_array($taxonomy, $disabled\_taxonomies)) || empty($taxonomy\_exists)) ? true : false;
252
253
return $out;
254
}
255
256
/\*\*
257
\* Check if single post should be ignored by Permalink Manager
258
\*/
259
public static function is\_post\_excluded($post = null) {
260
$post = (is\_integer($post)) ? get\_post($post) : $post;
314
$taxonomy\_exists = ( $check\_if\_exists ) ? taxonomy\_exists( $taxonomy ) : true;
315
316
return ( ( is\_array( $disabled\_taxonomies ) && in\_array( $taxonomy, $disabled\_taxonomies ) ) || empty( $taxonomy\_exists ) ) ? true : false;
317
}
318
319
/\*\*
320
\* Check if specific post should be ignored by Permalink Manager
321
\*
322
\* @param WP\_Post|int $post
323
\*
324
\* @return bool
325
\*/
326
public static function is\_post\_excluded( $post = null ) {
327
$post = ( is\_integer( $post ) ) ? get\_post( $post ) : $post;
261
328
262
329
// A. Check if post type is disabled
263
if(!empty($post->post\_type) && self::is\_post\_type\_disabled($post->post\_type)) {
330
if ( ! empty( $post->post\_type ) && self::is\_post\_type\_disabled( $post->post\_type ) ) {
264
331
return true;
265
332
}
266
333
267
$excluded\_post\_ids = apply\_filters('permalink\_manager\_excluded\_post\_ids', array());
334
$excluded\_post\_ids = apply\_filters( 'permalink\_manager\_excluded\_post\_ids', array() );
268
335
269
336
// B. Check if post ID is excluded
270
if(is\_array($excluded\_post\_ids) && !empty($post->ID) && in\_array($post->ID, $excluded\_post\_ids)) {
337
if ( is\_array( $excluded\_post\_ids ) && ! empty( $post->ID ) && in\_array( $post->ID, $excluded\_post\_ids ) ) {
271
338
return true;
272
339
}
…
…
276
343
277
344
/\*\*
278
\* Check if single term should be ignored by Permalink Manager
279
\*/
280
public static function is\_term\_excluded($term = null) {
281
$term = (is\_numeric($term)) ? get\_term($term) : $term;
345
\* Check if specific term should be ignored by Permalink Manager
346
\*
347
\* @param WP\_Term $term
348
\*
349
\* @return bool
350
\*/
351
public static function is\_term\_excluded( $term = null ) {
352
$term = ( is\_numeric( $term ) ) ? get\_term( $term ) : $term;
282
353
283
354
// A. Check if post type is disabled
284
if(!empty($term->taxonomy) && self::is\_taxonomy\_disabled($term->taxonomy)) {
355
if ( ! empty( $term->taxonomy ) && self::is\_taxonomy\_disabled( $term->taxonomy ) ) {
285
356
return true;
286
357
}
287
358
288
$excluded\_term\_ids = apply\_filters('permalink\_manager\_excluded\_term\_ids', array());
359
$excluded\_term\_ids = apply\_filters( 'permalink\_manager\_excluded\_term\_ids', array() );
289
360
290
361
// B. Check if post ID is excluded
291
if(is\_array($excluded\_term\_ids) && !empty($term->term\_id) && in\_array($term->term\_id, $excluded\_term\_ids)) {
362
if ( is\_array( $excluded\_term\_ids ) && ! empty( $term->term\_id ) && in\_array( $term->term\_id, $excluded\_term\_ids ) ) {
292
363
return true;
293
364
}
…
…
298
369
/\*\*
299
370
\* Get all post types supported by Permalink Manager
300
\*/
301
static function get\_post\_types\_array($format = null, $cpt = null, $include\_user\_excluded = false) {
371
\*
372
\* @param string $format
373
\* @param string $cpt
374
\* @param bool $include\_user\_excluded
375
\*
376
\* @return array
377
\*/
378
static function get\_post\_types\_array( $format = null, $cpt = null, $include\_user\_excluded = false ) {
302
379
global $wp\_post\_types;
303
380
304
$post\_types\_array \= array();
305
$disabled\_post\_types = self::get\_disabled\_post\_types(!$include\_user\_excluded);
306
307
foreach($wp\_post\_types as $post\_type) {
308
if($format == 'full') {
309
$post\_types\_array\[$post\_type->name\] = array('label' => $post\_type->labels->name, 'name' => $post\_type->name);
310
} else if($format == 'archive\_slug') {
381
$post\_types\_array \= array();
382
$disabled\_post\_types = self::get\_disabled\_post\_types( ! $include\_user\_excluded );
383
384
foreach ( $wp\_post\_types as $post\_type ) {
385
if ( $format == 'full' ) {
386
$post\_types\_array\[ $post\_type->name \] = array( 'label' => $post\_type->labels->name, 'name' => $post\_type->name );
387
} else if ( $format == 'archive\_slug' ) {
311
388
// Ignore non-public post types
312
if(!is\_post\_type\_viewable($post\_type) || empty($post\_type->has\_archive)) {
389
if ( ! is\_post\_type\_viewable( $post\_type ) || empty( $post\_type->has\_archive ) ) {
313
390
continue;
314
391
}
315
392
316
if($post\_type->has\_archive != true) {
393
if ( ! $post\_type->has\_archive ) {
317
394
$archive\_slug = $post\_type->has\_archive;
318
} else if(is\_array($post\_type->rewrite) && !empty($post\_type->rewrite\['slug'\])) {
395
} else if ( is\_array( $post\_type->rewrite ) && ! empty( $post\_type->rewrite\['slug'\] ) ) {
319
396
$archive\_slug = $post\_type->rewrite\['slug'\];
320
397
} else {
…
…
322
399
}
323
400
324
$post\_types\_array\[$post\_type->name\] = $archive\_slug;
401
$post\_types\_array\[ $post\_type->name \] = $archive\_slug;
325
402
} else {
326
$post\_types\_array\[$post\_type->name\] = $post\_type->labels->name;
327
}
328
}
329
330
if(is\_array($disabled\_post\_types)) {
331
foreach($disabled\_post\_types as $post\_type) {
332
if(!empty($post\_types\_array\[$post\_type\])) {
333
unset($post\_types\_array\[$post\_type\]);
334
}
335
}
336
}
337
338
return (empty($cpt)) ? $post\_types\_array : $post\_types\_array\[$cpt\];
403
$post\_types\_array\[ $post\_type->name \] = $post\_type->labels->name;
404
}
405
}
406
407
if ( is\_array( $disabled\_post\_types ) ) {
408
foreach ( $disabled\_post\_types as $post\_type ) {
409
if ( ! empty( $post\_types\_array\[ $post\_type \] ) ) {
410
unset( $post\_types\_array\[ $post\_type \] );
411
}
412
}
413
}
414
415
return ( empty( $cpt ) ) ? $post\_types\_array : $post\_types\_array\[ $cpt \];
339
416
}
340
417
341
418
/\*\*
342
419
\* Get all taxonomies supported by Permalink Manager
343
\*/
344
static function get\_taxonomies\_array($format = null, $tax = null, $prefix = false, $include\_user\_excluded = false, $settings = false) {
420
\*
421
\* @param string $format
422
\* @param string $tax
423
\* @param bool $include\_user\_excluded
424
\*
425
\* @return array
426
\*/
427
static function get\_taxonomies\_array( $format = null, $tax = null, $include\_user\_excluded = false ) {
345
428
global $wp\_taxonomies;
346
429
347
$taxonomies\_array = array();
348
$disabled\_taxonomies = self::get\_disabled\_taxonomies(!$include\_user\_excluded);
349
350
foreach($wp\_taxonomies as $taxonomy) {
351
$key = ($prefix) ? "tax-{$taxonomy->name}" : $taxonomy->name;
352
$taxonomy\_name = (!empty($taxonomy->labels->name)) ? $taxonomy->labels->name : '-';
353
354
$taxonomies\_array\[$taxonomy->name\] = ($format == 'full') ? array('label' => $taxonomy->labels->name, 'name' => $taxonomy->name) : $taxonomy\_name;
355
}
356
357
if(is\_array($disabled\_taxonomies)) {
358
foreach($disabled\_taxonomies as $taxonomy) {
359
if(!empty($taxonomies\_array\[$taxonomy\])) {
360
unset($taxonomies\_array\[$taxonomy\]);
361
}
362
}
363
}
364
365
ksort($taxonomies\_array);
366
367
return (empty($tax)) ? $taxonomies\_array : $taxonomies\_array\[$tax\];
430
$taxonomies\_array = array();
431
$disabled\_taxonomies = self::get\_disabled\_taxonomies( ! $include\_user\_excluded );
432
433
foreach ( $wp\_taxonomies as $taxonomy ) {
434
$taxonomy\_name = ( ! empty( $taxonomy->labels->name ) ) ? $taxonomy->labels->name : '-';
435
436
$taxonomies\_array\[ $taxonomy->name \] = ( $format == 'full' ) ? array( 'label' => $taxonomy->labels->name, 'name' => $taxonomy->name ) : $taxonomy\_name;
437
}
438
439
if ( is\_array( $disabled\_taxonomies ) ) {
440
foreach ( $disabled\_taxonomies as $taxonomy ) {
441
if ( ! empty( $taxonomies\_array\[ $taxonomy \] ) ) {
442
unset( $taxonomies\_array\[ $taxonomy \] );
443
}
444
}
445
}
446
447
ksort( $taxonomies\_array );
448
449
return ( empty( $tax ) ) ? $taxonomies\_array : $taxonomies\_array\[ $tax \];
368
450
}
369
451
…
…
374
456
$post\_statuses = get\_post\_statuses();
375
457
376
return apply\_filters('permalink\_manager\_post\_statuses', $post\_statuses);
377
}
378
379
/\*\*
380
\* Get permastruct
381
\*/
382
static function get\_default\_permastruct($post\_type = 'page', $remove\_post\_tag = false) {
458
return apply\_filters( 'permalink\_manager\_post\_statuses', $post\_statuses );
459
}
460
461
/\*\*
462
\* Get the default permalink format for specific post type
463
\*
464
\* @param string $post\_type
465
\* @param bool $remove\_post\_tag
466
\*
467
\* @return string
468
\*/
469
static function get\_default\_permastruct( $post\_type = 'page', $remove\_post\_tag = false ) {
383
470
global $wp\_rewrite;
384
471
385
472
// Get default permastruct
386
if($post\_type == 'page') {
473
if ( $post\_type == 'page' ) {
387
474
$permastruct = $wp\_rewrite->get\_page\_permastruct();
388
} else if($post\_type == 'post') {
389
$permastruct = get\_option('permalink\_structure');
475
} else if ( $post\_type == 'post' ) {
476
$permastruct = get\_option( 'permalink\_structure' );
390
477
} else {
391
$permastruct = $wp\_rewrite->get\_extra\_permastruct($post\_type);
392
}
393
394
return ($remove\_post\_tag) ? trim(str\_replace(array("%postname%", "%pagename%", "%{$post\_type}%"), "", $permastruct), "/") : $permastruct;
395
}
396
397
/\*\*
398
\* Get all endpoints
478
$permastruct = $wp\_rewrite->get\_extra\_permastruct( $post\_type );
479
}
480
481
return ( $remove\_post\_tag ) ? trim( str\_replace( array( "%postname%", "%pagename%", "%{$post\_type}%" ), "", $permastruct ), "/" ) : $permastruct;
482
}
483
484
/\*\*
485
\* Get all the endpoints registered for WP\_Rewrite object
399
486
\*/
400
487
static function get\_endpoints() {
401
488
global $wp\_rewrite;
402
489
403
$pagination\_endpoint = (!empty($wp\_rewrite->pagination\_base)) ? $wp\_rewrite->pagination\_base : 'page';
490
$pagination\_endpoint = ( ! empty( $wp\_rewrite->pagination\_base ) ) ? $wp\_rewrite->pagination\_base : 'page';
404
491
405
492
// Start with default endpoints
406
493
$endpoints = "{$pagination\_endpoint}|feed|embed|attachment|trackback|filter";
407
494
408
if(!empty($wp\_rewrite->endpoints)) {
409
foreach($wp\_rewrite->endpoints as $endpoint) {
495
if ( ! empty( $wp\_rewrite->endpoints ) ) {
496
foreach ( $wp\_rewrite->endpoints as $endpoint ) {
410
497
$endpoints .= "|{$endpoint\[1\]}";
411
498
}
412
499
}
413
500
414
return apply\_filters("permalink\_manager\_endpoints", str\_replace("/", "\\/", $endpoints));
415
}
416
417
/\*\*
418
\* Structure Tags & Rewrite functions
419
\*/
420
static function get\_all\_structure\_tags($code = true, $seperator = ', ', $hide\_slug\_tags = true) {
501
return apply\_filters( "permalink\_manager\_endpoints", str\_replace( "/", "\\/", $endpoints ) );
502
}
503
504
/\*\*
505
\* Get a list of all structure tags
506
\*
507
\* @param bool $code
508
\* @param string $separator
509
\* @param bool $hide\_slug\_tags
510
\*
511
\* @return string
512
\*/
513
static function get\_all\_structure\_tags( $code = true, $separator = ', ', $hide\_slug\_tags = true ) {
421
514
global $wp\_rewrite;
422
515
…
…
424
517
425
518
// Hide slug tags
426
if($hide\_slug\_tags) {
519
if ( $hide\_slug\_tags ) {
427
520
$post\_types = Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array();
428
foreach($post\_types as $post\_type => $post\_type\_name) {
429
$post\_type\_tag = Permalink\_Manager\_Helper\_Functions::get\_post\_tag($post\_type);
430
// Find key with post type tag from rewritecode
431
$key = array\_search($post\_type\_tag, $tags);
432
if($key) { unset($tags\[$key\]); }
521
foreach ( $post\_types as $post\_type => $post\_type\_name ) {
522
$post\_type\_tag = Permalink\_Manager\_Helper\_Functions::get\_post\_tag( $post\_type );
523
// Find key with post type tag from rewrite code
524
$key = array\_search( $post\_type\_tag, $tags );
525
if ( $key ) {
526
unset( $tags\[ $key \] );
527
}
433
528
}
434
529
}
…
…
440
535
$tags\[\] = '%monthname%';
441
536
442
foreach($tags as &$tag) {
443
$tag = ($code) ? "<code>{$tag}</code>" : "{$tag}";
444
}
445
$output = implode($seperator, $tags);
537
foreach ( $tags as &$tag ) {
538
$tag = ( $code ) ? "<code>{$tag}</code>" : "{$tag}";
539
}
540
$output = implode( $separator, $tags );
446
541
447
542
return "<span class=\\"structure-tags-list\\">{$output}</span>";
…
…
449
544
450
545
/\*\*
451
\* Get endpoint used to mark the postname or its equivalent for custom post types and pages in permastructures
452
\*/
453
static function get\_post\_tag($post\_type) {
546
\* Get the post name permastructure tag for specific post type
547
\*
548
\* @param string $post\_type
549
\*
550
\* @return string
551
\*/
552
static function get\_post\_tag( $post\_type ) {
454
553
// Get the post type (with fix for posts & pages)
455
if($post\_type == 'page') {
554
if ( $post\_type == 'page' ) {
456
555
$post\_type\_tag = '%pagename%';
457
} else if ($post\_type == 'post') {
556
} else if ( $post\_type == 'post' ) {
458
557
$post\_type\_tag = '%postname%';
459
558
} else {
460
559
$post\_type\_tag = "%{$post\_type}%";
461
560
}
561
462
562
return $post\_type\_tag;
463
563
}
464
564
465
565
/\*\*
466
\* Find taxonomy name using "term\_id"
467
\*/
468
static function get\_tax\_name($term, $term\_by = 'id') {
469
$term\_object = get\_term\_by($term\_by, $term);
470
return (isset($term\_object->taxonomy)) ? $term\_object->taxonomy : '';
471
}
472
473
/\*\*
474
\* Get permalink base (home URL)
475
\*/
476
public static function get\_permalink\_base($element = null) {
477
return apply\_filters('permalink\_manager\_filter\_permalink\_base', trim(get\_option('home'), "/"), $element);
478
}
479
480
/\*\*
481
\* Remove post tag from permastructure
482
\*/
483
static function remove\_post\_tag($permastruct) {
484
$post\_types = self::get\_post\_types\_array('full');
485
486
// Get all post tags
487
$post\_tags = array("%postname%", "%pagename%");
488
foreach($post\_types as $post\_type) {
489
$post\_tags\[\] = "%{$post\_type\['name'\]}%";
490
}
491
492
$permastruct = str\_replace($post\_tags, "", $permastruct);
493
return trim($permastruct, "/");
494
}
495
496
/\*\*
497
\* Get front-page ID
498
\*/
499
static function is\_front\_page($page\_id) {
500
$front\_page\_id = get\_option('page\_on\_front');
501
$bool = (!empty($front\_page\_id) && $page\_id == $front\_page\_id) ? true : false;
502
503
return apply\_filters('permalink\_manager\_is\_front\_page', $bool, $page\_id, $front\_page\_id);
504
}
505
506
/\*\*
507
\* Sanitize multidimensional array
508
\*/
509
static function sanitize\_array($data = array()) {
510
if (!is\_array($data) || !count($data)) {
566
\* Get the permalink base (home URL) for custom permalink
567
\*
568
\* @param string|int|WP\_Post|WP\_Term $element
569
\*
570
\* @return string
571
\*/
572
public static function get\_permalink\_base( $element = null ) {
573
return apply\_filters( 'permalink\_manager\_filter\_permalink\_base', trim( get\_option( 'home' ), "/" ), $element );
574
}
575
576
/\*\*
577
\* Check if the specific post is selected as a front-page
578
\*
579
\* @param int $page\_id
580
\*
581
\* @return bool
582
\*/
583
static function is\_front\_page( $page\_id ) {
584
$front\_page\_id = get\_option( 'page\_on\_front' );
585
$bool = ( ! empty( $front\_page\_id ) && $page\_id == $front\_page\_id ) ? true : false;
586
587
return apply\_filters( 'permalink\_manager\_is\_front\_page', $bool, $page\_id, $front\_page\_id );
588
}
589
590
/\*\*
591
\* Sanitize the multidimensional array
592
\*
593
\* @param array $data
594
\*
595
\* @return array
596
\*/
597
static function sanitize\_array( $data = array() ) {
598
if ( ! is\_array( $data ) || ! count( $data ) ) {
511
599
return array();
512
600
}
513
601
514
foreach ($data as $k => $v) {
515
if (!is\_array($v) && !is\_object($v)) {
516
$data\[$k\] = htmlspecialchars(trim($v));
517
}
518
if (is\_array($v)) {
519
$data\[$k\] = self::sanitize\_array($v);
520
}
521
}
602
foreach ( $data as $k => $v ) {
603
if ( ! is\_array( $v ) && ! is\_object( $v ) ) {
604
$data\[ $k \] = htmlspecialchars( trim( $v ) );
605
}
606
if ( is\_array( $v ) ) {
607
$data\[ $k \] = self::sanitize\_array( $v );
608
}
609
}
610
522
611
return $data;
523
612
}
…
…
525
614
/\*\*
526
615
\* Encode URI and keep special characters
527
\*/
528
static function encode\_uri($uri) {
529
return str\_replace(array('%2F', '%2C', '%7C', '%2B'), array('/', ',', '|', '+'), urlencode($uri));
530
}
531
532
/\*\*
533
\* Slugify function
534
\*/
535
public static function sanitize\_title($str, $keep\_percent\_sign = false, $force\_lowercase = null, $sanitize\_slugs = null) {
616
\*
617
\* @param string $uri
618
\*
619
\* @return string
620
\*/
621
static function encode\_uri( $uri ) {
622
return str\_replace( array( '%2F', '%2C', '%7C', '%2B' ), array( '/', ',', '|', '+' ), urlencode( $uri ) );
623
}
624
625
/\*\*
626
\* Sanitize the given string to URI-safe format
627
\*
628
\* @param string $str
629
\* @param bool $keep\_percent\_sign
630
\* @param bool $force\_lowercase
631
\* @param bool $sanitize\_slugs
632
\*
633
\* @return string
634
\*/
635
public static function sanitize\_title( $str, $keep\_percent\_sign = false, $force\_lowercase = null, $sanitize\_slugs = null ) {
536
636
global $permalink\_manager\_options;
537
637
538
// Foree lowercase & hyphens
539
$force\_lowercase = (!is\_null($force\_lowercase)) ? $force\_lowercase : apply\_filters('permalink\_manager\_force\_lowercase\_uris', true);
540
541
if(is\_null($sanitize\_slugs)) {
542
$sanitize\_slugs = (!empty($permalink\_manager\_options\['general'\]\['disable\_slug\_sanitization'\])) ? false : true;
638
// Force lowercase & hyphens
639
$force\_lowercase = ( ! is\_null( $force\_lowercase ) ) ? $force\_lowercase : apply\_filters( 'permalink\_manager\_force\_lowercase\_uris', true );
640
641
if ( is\_null( $sanitize\_slugs ) ) {
642
$sanitize\_slugs = ( ! empty( $permalink\_manager\_options\['general'\]\['disable\_slug\_sanitization'\] ) ) ? false : true;
543
643
}
544
644
545
645
// Allow to filter the slug before it is sanitized
546
$str = apply\_filters('permalink\_manager\_pre\_sanitize\_title', $str, $keep\_percent\_sign, $force\_lowercase, $sanitize\_slugs);
646
$str = apply\_filters( 'permalink\_manager\_pre\_sanitize\_title', $str, $keep\_percent\_sign, $force\_lowercase, $sanitize\_slugs );
547
647
548
648
// Remove accents & entities
549
$clean = (empty($permalink\_manager\_options\['general'\]\['keep\_accents'\])) ? remove\_accents($str) : $str;
550
$clean = str\_replace(array('<', '>', '&'), '', $clean);
551
552
$percent\_sign \= ($keep\_percent\_sign) ? "\\%" : "";
553
$sanitize\_regex = apply\_filters("permalink\_manager\_sanitize\_regex", "/\[^\\p{Xan}a-zA-Z0-9{$percent\_sign}\\/\_\\.|+, -\]/ui", $percent\_sign);
554
$clean \= preg\_replace($sanitize\_regex, '', $clean);
555
$clean \= ($force\_lowercase) ? strtolower($clean) : $clean;
556
557
// Remove amperand
558
$clean = str\_replace(array('%26', '&'), '', $clean);
649
$clean = ( empty( $permalink\_manager\_options\['general'\]\['keep\_accents'\] ) ) ? remove\_accents( $str ) : $str;
650
$clean = str\_replace( array( '<', '>', '&' ), '', $clean );
651
652
$percent\_sign = ( $keep\_percent\_sign ) ? "\\%" : "";
653
$sanitize\_regex = apply\_filters( "permalink\_manager\_sanitize\_regex", "/\[^\\p{Xan}a-zA-Z0-9{$percent\_sign}\\/\_\\.|+, -\]/ui", $percent\_sign );
654
$clean = preg\_replace( $sanitize\_regex, '', $clean );
655
$clean = ( $force\_lowercase ) ? strtolower( $clean ) : $clean;
656
657
// Remove ampersand
658
$clean = str\_replace( array( '%26', '&' ), '', $clean );
559
659
560
660
// Remove special characters
561
if($sanitize\_slugs !== false) {
562
$clean = preg\_replace("/\[\\s|+-\]+/", "-", $clean);
563
$clean = preg\_replace("/\[,\]+/", "", $clean);
564
$clean = preg\_replace('/(\[\\.\]+)(?!\[a-z\]{3,4}$)/i', '', $clean);
565
$clean = preg\_replace('/(\[-\\s+\]\\/\[-\\s+\])/', '-', $clean);
661
if ( $sanitize\_slugs !== false ) {
662
$clean = preg\_replace( "/\[\\s|+-\]+/", "-", $clean );
663
$clean = preg\_replace( "/\[,\]+/", "", $clean );
664
$clean = preg\_replace( '/(\[\\.\]+)(?!\[a-z\]{3,4}$)/i', '', $clean );
665
$clean = preg\_replace( '/(\[-\\s+\]\\/\[-\\s+\])/', '-', $clean );
566
666
} else {
567
$clean = preg\_replace("/\[\\s\]+/", "-", $clean);
667
$clean = preg\_replace( "/\[\\s\]+/", "-", $clean );
568
668
}
569
669
570
670
// Remove widow & duplicated slashes
571
$clean = preg\_replace('/(\[-\]\*\[\\/\]+\[-\]\*)/', '/', $clean);
572
$clean = preg\_replace('/(\[\\/\]+)/', '/', $clean);
671
$clean = preg\_replace( '/(\[-\]\*\[\\/\]+\[-\]\*)/', '/', $clean );
672
$clean = preg\_replace( '/(\[\\/\]+)/', '/', $clean );
573
673
574
674
// Trim slashes, dashes and whitespaces
575
$clean = trim($clean, " /-");
576
577
return $clean;
675
return trim( $clean, " /-" );
578
676
}
579
677
580
678
/\*\*
581
679
\* Replace empty placeholder tags & remove BOM
582
\*/
583
public static function replace\_empty\_placeholder\_tags($default\_uri, $native\_slug = "", $element = "", $slug = "", $native\_uri = "") {
680
\*
681
\* @param string $default\_uri
682
\* @param string $native\_slug
683
\* @param string $element
684
\* @param string $slug
685
\* @param string $native\_uri
686
\*
687
\* @return string
688
\*/
689
public static function replace\_empty\_placeholder\_tags( $default\_uri, $native\_slug = "", $element = "", $slug = "", $native\_uri = "" ) {
584
690
// Do not affect native URIs
585
if($native\_uri == true) { return $default\_uri; }
691
if ( $native\_uri ) {
692
return $default\_uri;
693
}
586
694
587
695
// Remove the BOM
588
$default\_uri = str\_replace(array("\\xEF\\xBB\\xBF", "%ef%bb%bf"), '', $default\_uri);
696
$default\_uri = str\_replace( array( "\\xEF\\xBB\\xBF", "%ef%bb%bf" ), '', $default\_uri );
589
697
590
698
// Encode the URI before placeholders are removed
591
$chunks = explode('/', $default\_uri);
592
foreach ($chunks as &$chunk) {
593
if(preg\_match("/^(%.+?%)$/", $chunk) == false) {
594
$chunk = rawurldecode($chunk);
595
}
596
}
597
$default\_uri = implode("/", $chunks);
598
599
$empty\_tag\_replacement = apply\_filters('permalink\_manager\_empty\_tag\_replacement', '', $element);
600
$default\_uri = preg\_replace("/%(.+?)%/", $empty\_tag\_replacement, $default\_uri);
601
$default\_uri = str\_replace("//", "/", $default\_uri);
602
603
return trim($default\_uri, "/");
604
}
605
606
/\*\*
607
\* Clear/Sanitize the URI
608
\*/
609
public static function clear\_single\_uri($uri) {
610
return self::sanitize\_title($uri, true);
611
}
612
613
/\*\*
614
\* Remove all slashes
615
\*/
616
public static function remove\_slashes($uri) {
617
return preg\_replace("/\[\\/\]+/", "", $uri);
618
}
619
620
/\*\*
621
\* Force custom slugs
622
\*/
623
public static function force\_custom\_slugs($slug, $object, $flat = false) {
699
$chunks = explode( '/', $default\_uri );
700
foreach ( $chunks as &$chunk ) {
701
if ( ! preg\_match( "/^(%.+?%)$/", $chunk ) ) {
702
$chunk = rawurldecode( $chunk );
703
}
704
}
705
$default\_uri = implode( "/", $chunks );
706
707
$empty\_tag\_replacement = apply\_filters( 'permalink\_manager\_empty\_tag\_replacement', '', $element );
708
$default\_uri = preg\_replace( "/%(.+?)%/", $empty\_tag\_replacement, $default\_uri );
709
$default\_uri = str\_replace( "//", "/", $default\_uri );
710
711
return trim( $default\_uri, "/" );
712
}
713
714
/\*\*
715
\* Sanitize the final custom permalink URI
716
\*
717
\* @param string $uri
718
\*
719
\* @return string
720
\*/
721
public static function clear\_single\_uri( $uri ) {
722
return self::sanitize\_title( $uri, true );
723
}
724
725
/\*\*
726
\* Remove all slashes from given string
727
\*
728
\* @param string $uri
729
\*
730
\* @return array|string|string\[\]|null
731
\*/
732
public static function remove\_slashes( $uri ) {
733
return preg\_replace( "/\[\\/\]+/", "", $uri );
734
}
735
736
/\*\*
737
\* Replace the given slug with the actual title or custom permalink of specific post or term
738
\*
739
\* @param string $slug
740
\* @param WP\_Post|WP\_Term $object
741
\* @param bool $flat
742
\*
743
\* @return string
744
\*/
745
public static function force\_custom\_slugs( $slug, $object, $flat = false ) {
624
746
global $permalink\_manager\_options, $permalink\_manager\_uris;
625
747
626
$force\_custom\_slugs = (!empty($permalink\_manager\_options\['general'\]\['force\_custom\_slugs'\])) ? $permalink\_manager\_options\['general'\]\['force\_custom\_slugs'\] : false;
627
$force\_custom\_slugs = apply\_filters('permalink\_manager\_force\_custom\_slugs', $force\_custom\_slugs, $slug, $object);
628
629
if($force\_custom\_slugs) {
748
$force\_custom\_slugs = ( ! empty( $permalink\_manager\_options\['general'\]\['force\_custom\_slugs'\] ) ) ? $permalink\_manager\_options\['general'\]\['force\_custom\_slugs'\] : false;
749
$force\_custom\_slugs = apply\_filters( 'permalink\_manager\_force\_custom\_slugs', $force\_custom\_slugs, $slug, $object );
750
751
if ( $force\_custom\_slugs ) {
630
752
// A. Custom slug (title)
631
if($force\_custom\_slugs == 1) {
632
if(!empty($object->name) && !empty($object->taxonomy)) {
753
if ( $force\_custom\_slugs == 1 ) {
754
if ( ! empty( $object->name ) && ! empty( $object->taxonomy ) ) {
633
755
$title = $object->name;
634
} else if(!empty($object->post\_title) && !empty($object->post\_type)) {
756
} else if ( ! empty( $object->post\_title ) && ! empty( $object->post\_type ) ) {
635
757
$title = $object->post\_title;
636
758
} else {
…
…
638
760
}
639
761
640
$title = strip\_tags($title);
641
$title = self::remove\_slashes($title);
642
643
$new\_slug = self::sanitize\_title($title, false, null, null);
644
}
645
// B. Custom slug (custom permalink)
762
$title = strip\_tags( $title );
763
$title = self::remove\_slashes( $title );
764
765
$new\_slug = self::sanitize\_title( $title );
766
} // B. Custom slug (custom permalink)
646
767
else {
647
$object\_id = (!empty($object->term\_id)) ? "tax-{$object->term\_id}" : $object->ID;
648
$new\_slug \= (!empty($permalink\_manager\_uris\[$object\_id\])) ? basename($permalink\_manager\_uris\[$object\_id\]) : '';
649
}
650
651
$slug = (!empty($new\_slug)) ? preg\_replace('/(\[^\\/\]+)$/', $new\_slug, $slug) : $slug;
652
}
653
654
if($flat) {
655
$slug = preg\_replace("/(\[^\\/\]+)(.\*)/", "$1", $slug);
768
$object\_id = ( ! empty( $object->term\_id ) ) ? "tax-{$object->term\_id}" : $object->ID;
769
$new\_slug = ( ! empty( $permalink\_manager\_uris\[ $object\_id \] ) ) ? basename( $permalink\_manager\_uris\[ $object\_id \] ) : '';
770
}
771
772
$slug = ( ! empty( $new\_slug ) ) ? preg\_replace( '/(\[^\\/\]+)$/', $new\_slug, $slug ) : $slug;
773
}
774
775
if ( $flat ) {
776
$slug = preg\_replace( "/(\[^\\/\]+)(.\*)/", "$1", $slug );
656
777
}
657
778
…
…
659
780
}
660
781
661
public static function element\_exists($element\_id) {
662
global $wpdb;
663
664
if(strpos($element\_id, 'tax-') !== false) {
665
$term\_id = intval(preg\_replace("/\[^0-9\]/", "", $element\_id));
666
$element\_exists = $wpdb->get\_var( "SELECT \* FROM {$wpdb->prefix}terms WHERE term\_id = {$term\_id}" );
667
} else {
668
$element\_exists = $wpdb->get\_var( "SELECT \* FROM {$wpdb->prefix}posts WHERE ID = {$element\_id} AND post\_status NOT IN ('auto-draft', 'trash') AND post\_type != 'nav\_menu\_item'" );
669
}
670
671
return (!empty($element\_exists)) ? $element\_exists : false;
672
}
673
674
/\*\*
675
\* Detect duplicates
676
\*/
677
public static function get\_all\_duplicates($include\_custom\_uris = true) {
678
global $permalink\_manager\_uris, $permalink\_manager\_redirects, $permalink\_manager\_options, $wpdb;
782
/\*\*
783
\* Get the list of all duplicated redirects and custom permalinks
784
\*
785
\* @param bool $include\_custom\_uris
786
\*
787
\* @return array
788
\*/
789
public static function get\_all\_duplicates( $include\_custom\_uris = true ) {
790
global $permalink\_manager\_uris, $permalink\_manager\_redirects;
679
791
680
792
// Make sure that both variables are arrays
681
$all\_uris \= ($include\_custom\_uris && is\_array($permalink\_manager\_uris)) ? $permalink\_manager\_uris : array();
682
$permalink\_manager\_redirects = (is\_array($permalink\_manager\_redirects)) ? $permalink\_manager\_redirects : array();
793
$all\_uris = ( $include\_custom\_uris && is\_array( $permalink\_manager\_uris ) ) ? $permalink\_manager\_uris : array();
794
$permalink\_manager\_redirects = ( is\_array( $permalink\_manager\_redirects ) ) ? $permalink\_manager\_redirects : array();
683
795
684
796
// Convert redirects list, so it can be merged with $permalink\_manager\_uris
685
foreach($permalink\_manager\_redirects as $element\_id => $redirects) {
686
if(is\_array($redirects)) {
687
foreach($redirects as $index => $uri) {
797
foreach ( $permalink\_manager\_redirects as $element\_id => $redirects ) {
798
if ( is\_array( $redirects ) ) {
799
foreach ( $redirects as $index => $uri ) {
688
800
$all\_uris\["redirect-{$index}\_{$element\_id}"\] = $uri;
689
801
}
…
…
692
804
693
805
// Count duplicates
694
$duplicates\_removed = 0;
695
806
$duplicates\_groups = array();
696
$duplicates\_list = array\_count\_values($all\_uris);
697
$duplicates\_list = array\_filter($duplicates\_list, function ($x) { return $x >= 2; });
807
$duplicates\_list = array\_count\_values( $all\_uris );
808
$duplicates\_list = array\_filter( $duplicates\_list, function ( $x ) {
809
return $x >= 2;
810
} );
698
811
699
812
// Assign keys to duplicates (group them)
700
if(count($duplicates\_list) > 0) {
701
foreach($duplicates\_list as $duplicated\_uri => $count) {
702
$duplicated\_ids = array\_keys($all\_uris, $duplicated\_uri);
813
if ( count( $duplicates\_list ) > 0 ) {
814
foreach ( $duplicates\_list as $duplicated\_uri => $count ) {
815
$duplicated\_ids = array\_keys( $all\_uris, $duplicated\_uri );
703
816
704
817
// Ignore duplicates in different langauges
705
if(self::is\_uri\_duplicated($duplicated\_uri, $duplicated\_ids\[0\], $duplicated\_ids)) {
706
$duplicates\_groups\[$duplicated\_uri\] = $duplicated\_ids;
818
if ( self::is\_uri\_duplicated( $duplicated\_uri, $duplicated\_ids\[0\], $duplicated\_ids ) ) {
819
$duplicates\_groups\[ $duplicated\_uri \] = $duplicated\_ids;
707
820
}
708
821
}
…
…
714
827
/\*\*
715
828
\* Check if a single URI is duplicated
716
\*/
717
public static function is\_uri\_duplicated($uri, $element\_id, $duplicated\_ids = array()) {
829
\*
830
\* @param string $uri
831
\* @param int $element\_id
832
\* @param array $duplicated\_ids
833
\*
834
\* @return bool
835
\*/
836
public static function is\_uri\_duplicated( $uri, $element\_id, $duplicated\_ids = array() ) {
718
837
global $permalink\_manager\_uris;
719
838
720
if(empty($uri) || empty($element\_id) || empty($permalink\_manager\_uris)) { return false; }
721
722
$uri = trim(trim(sanitize\_text\_field($uri)), "/");
723
$element\_id = sanitize\_text\_field($element\_id);
724
725
// Keep the URIs in a separate array just here
726
if(!empty($duplicated\_ids)) {
839
if ( empty( $uri ) || empty( $element\_id ) || empty( $permalink\_manager\_uris ) ) {
840
return false;
841
}
842
843
$uri = trim( trim( sanitize\_text\_field( $uri ) ), "/" );
844
$element\_id = sanitize\_text\_field( $element\_id );
845
846
// Keep the URIs in a separate array just here
847
if ( ! empty( $duplicated\_ids ) ) {
727
848
$all\_duplicates = $duplicated\_ids;
728
} else if(in\_array($uri, $permalink\_manager\_uris)) {
729
$all\_duplicates = (array) array\_keys($permalink\_manager\_uris, $uri);
730
}
731
732
if(!empty($all\_duplicates)) {
849
} else if ( in\_array( $uri, $permalink\_manager\_uris ) ) {
850
$all\_duplicates = array\_keys( $permalink\_manager\_uris, $uri );
851
}
852
853
if ( ! empty( $all\_duplicates ) ) {
733
854
// Get the language code of current element
734
$this\_uri\_lang = Permalink\_Manager\_Language\_Plugins::get\_language\_code($element\_id);
735
736
foreach($all\_duplicates as $key => $duplicated\_id) {
855
$this\_uri\_lang = apply\_filters( 'permalink\_manager\_get\_language\_code', '', $element\_id );
856
857
foreach ( $all\_duplicates as $key => $duplicated\_id ) {
737
858
// Ignore custom redirects
738
if(strpos($key, 'redirect-') !== false) {
739
unset($all\_duplicates\[$key\]);
859
if ( strpos( $key, 'redirect-' ) !== false ) {
860
unset( $all\_duplicates\[ $key \] );
740
861
continue;
741
862
}
742
863
743
if($this\_uri\_lang) {
744
$duplicated\_uri\_lang = Permalink\_Manager\_Language\_Plugins::get\_language\_code($duplicated\_id);
864
if ( $this\_uri\_lang ) {
865
$duplicated\_uri\_lang = apply\_filters( 'permalink\_manager\_get\_language\_code', '', $duplicated\_id );
745
866
}
746
867
747
868
// Ignore the URI for requested element and other elements in other languages to prevent the false alert
748
if((!empty($duplicated\_uri\_lang) && $duplicated\_uri\_lang !== $this\_uri\_lang) || $element\_id == $duplicated\_id) {
749
unset($all\_duplicates\[$key\]);
750
}
751
}
752
753
return (count($all\_duplicates) > 0) ? true : false;
869
if ( ( ! empty( $duplicated\_uri\_lang ) && $duplicated\_uri\_lang !== $this\_uri\_lang ) || $element\_id == $duplicated\_id ) {
870
unset( $all\_duplicates\[ $key \] );
871
}
872
}
873
874
return ( count( $all\_duplicates ) > 0 ) ? true : false;
754
875
} else {
755
876
return false;
756
877
}
757
}
758
759
/\*\*
760
\* URI Search
761
\*/
762
public static function search\_uri($search\_query, $content\_type = null) {
878
}
879
880
/\*\*
881
\* Allow to use custom permalinks in search queries in Bulk URI Editor
882
\*
883
\* @param string $search\_query
884
\* @param string $content\_type
885
\*
886
\* @return array
887
\*/
888
public static function search\_uri( $search\_query, $content\_type = null ) {
763
889
global $permalink\_manager\_uris;
764
890
765
$found \= array();
766
$search\_query = preg\_quote($search\_query, '/');
767
768
foreach($permalink\_manager\_uris as $id => $uri) {
769
if(preg\_match("/\\b$search\_query\\b/i", $uri)) {
770
if($content\_type && $content\_type == 'taxonomies' && (strpos($id, 'tax-') !== false)) {
771
$found\[\] = (int) abs(filter\_var($id, FILTER\_SANITIZE\_NUMBER\_INT));
772
} else if($content\_type && $content\_type == 'posts' && is\_numeric($id)) {
773
$found\[\] = (int) filter\_var($id, FILTER\_SANITIZE\_NUMBER\_INT);
891
$found \= array();
892
$search\_query = preg\_quote( $search\_query, '/' );
893
894
foreach ( $permalink\_manager\_uris as $id => $uri ) {
895
if ( preg\_match( "/\\b$search\_query\\b/i", $uri ) ) {
896
if ( $content\_type && $content\_type == 'taxonomies' && ( strpos( $id, 'tax-' ) !== false ) ) {
897
$found\[\] = (int) abs( filter\_var( $id, FILTER\_SANITIZE\_NUMBER\_INT ) );
898
} else if ( $content\_type && $content\_type == 'posts' && is\_numeric( $id ) ) {
899
$found\[\] = (int) filter\_var( $id, FILTER\_SANITIZE\_NUMBER\_INT );
774
900
} else {
775
901
$found\[\] = $id;
…
…
783
909
/\*\*
784
910
\* Reload the globals when the blog is switched (multisite)
785
\*/
786
public function reload\_globals\_in\_network($new\_blog\_id) {
787
global $permalink\_manager\_uris, $permalink\_manager\_redirects, $permalink\_manager\_external\_redirects;
788
789
if(function\_exists('get\_blog\_option')) {
790
$permalink\_manager\_uris = get\_blog\_option($new\_blog\_id, 'permalink-manager-uris');
791
$permalink\_manager\_redirects = get\_blog\_option($new\_blog\_id, 'permalink-manager-redirects');
792
$permalink\_manager\_external\_redirects = get\_blog\_option($new\_blog\_id, 'permalink-manager-external-redirects');
911
\*
912
\* @param int $new\_blog\_id
913
\*/
914
public function reload\_globals\_in\_network( $new\_blog\_id ) {
915
global $permalink\_manager\_uris, $permalink\_manager\_redirects, $permalink\_manager\_external\_redirects;
916
917
if ( function\_exists( 'get\_blog\_option' ) ) {
918
$permalink\_manager\_uris = get\_blog\_option( $new\_blog\_id, 'permalink-manager-uris' );
919
$permalink\_manager\_redirects = get\_blog\_option( $new\_blog\_id, 'permalink-manager-redirects' );
920
$permalink\_manager\_external\_redirects = get\_blog\_option( $new\_blog\_id, 'permalink-manager-external-redirects' );
793
921
}
794
922
}
permalink-manager/trunk/includes/core/permalink-manager-language-plugins.php
r2818536
r2833667
2
2
3
3
/\*\*
4
\* Third parties integration
5
\*/
6
class Permalink\_Manager\_Language\_Plugins extends Permalink\_Manager\_Class {
4
\* WPML & Polylang integration functions
5
\*/
6
class Permalink\_Manager\_Language\_Plugins {
7
7
8
8
public function \_\_construct() {
9
add\_action('init', array($this, 'init\_hooks'), 99);
10
}
11
9
add\_action( 'init', array( $this, 'init\_hooks' ), 99 );
10
}
11
12
/\*\*
13
\* Register hooks adding support for WPML and Polylang
14
\*/
12
15
function init\_hooks() {
13
global $sitepress\_settings, $permalink\_manager\_options, $polylang, $translate\_press\_settings;
16
global $sitepress\_settings, $polylang, $translate\_press\_settings;
14
17
15
18
// 1. WPML, Polylang & TranslatePress
16
if($sitepress\_settings || !empty($polylang->links\_model->options) || class\_exists('TRP\_Translate\_Press')) {
19
if ( $sitepress\_settings || ! empty( $polylang->links\_model->options ) || class\_exists( 'TRP\_Translate\_Press' ) ) {
17
20
// Detect Post/Term function
18
add\_filter('permalink\_manager\_detected\_post\_id', array($this, 'fix\_language\_mismatch'), 9, 3);
19
add\_filter('permalink\_manager\_detected\_term\_id', array($this, 'fix\_language\_mismatch'), 9, 3);
21
add\_filter( 'permalink\_manager\_detected\_post\_id', array( $this, 'fix\_language\_mismatch' ), 9, 3 );
22
add\_filter( 'permalink\_manager\_detected\_term\_id', array( $this, 'fix\_language\_mismatch' ), 9, 3 );
20
23
21
24
// Fix posts page
22
// else {
23
add\_filter('permalink\_manager\_filter\_query', array($this, 'fix\_posts\_page'), 5, 5);
24
// }
25
add\_filter( 'permalink\_manager\_filter\_query', array( $this, 'fix\_posts\_page' ), 5, 5 );
25
26
26
27
// URI Editor
27
add\_filter('permalink\_manager\_uri\_editor\_extra\_info', array($this, 'language\_column\_uri\_editor'), 9, 3);
28
add\_filter( 'permalink\_manager\_uri\_editor\_extra\_info', array( $this, 'uri\_editor\_get\_lang\_col' ), 9, 3 );
28
29
29
30
// Adjust front page ID
30
add\_filter('permalink\_manager\_is\_front\_page', array($this, 'wpml\_is\_front\_page'), 9, 3);
31
add\_filter( 'permalink\_manager\_is\_front\_page', array( $this, 'wpml\_is\_front\_page' ), 9, 3 );
32
33
// Provide the language code for specific post/term
34
add\_filter( 'permalink\_manager\_get\_language\_code', array( $this, 'filter\_get\_language\_code' ), 9, 2 );
31
35
32
36
// Get translation mode
…
…
34
38
35
39
// A. WPML
36
if(isset($sitepress\_settings\['language\_negotiation\_type'\])) {
40
if ( isset( $sitepress\_settings\['language\_negotiation\_type'\] ) ) {
37
41
$url\_settings = $sitepress\_settings\['language\_negotiation\_type'\];
38
42
39
if(in\_array($sitepress\_settings\['language\_negotiation\_type'\], array(1, 2))) {
43
if ( in\_array( $url\_settings, array( 1, 2 ) ) ) {
40
44
$mode = 'prepend';
41
} else if($sitepress\_settings\['language\_negotiation\_type'\] == 3) {
45
} else if ( $url\_settings == 3 ) {
42
46
$mode = 'append';
43
47
}
44
}
45
// B. Polylang
46
else if(isset($polylang->links\_model->options\['force\_lang'\])) {
48
} // B. Polylang
49
else if ( isset( $polylang->links\_model->options\['force\_lang'\] ) ) {
47
50
$url\_settings = $polylang->links\_model->options\['force\_lang'\];
48
51
49
if(in\_array($url\_settings, array(1, 2, 3))) {
52
if ( in\_array( $url\_settings, array( 1, 2, 3 ) ) ) {
50
53
$mode = 'prepend';
51
54
}
52
}
53
// C. TranslatePress
54
else if(class\_exists('TRP\_Translate\_Press')) {
55
$translate\_press\_settings = get\_option('trp\_settings');
55
} // C. TranslatePress
56
else if ( class\_exists( 'TRP\_Translate\_Press' ) ) {
57
$translate\_press\_settings = get\_option( 'trp\_settings' );
56
58
57
59
$mode = 'prepend';
58
60
}
59
61
60
if($mode === 'prepend') {
61
add\_filter('permalink\_manager\_detect\_uri', array($this, 'detect\_uri\_language'), 9, 3);
62
add\_filter('permalink\_manager\_filter\_permalink\_base', array($this, 'prepend\_lang\_prefix'), 9, 2);
63
add\_filter('template\_redirect', array($this, 'wpml\_redirect'), 0, 998 );
64
} else if($mode === 'append') {
65
add\_filter('permalink\_manager\_filter\_final\_post\_permalink', array($this, 'append\_lang\_prefix'), 5, 2);
66
add\_filter('permalink\_manager\_filter\_final\_term\_permalink', array($this, 'append\_lang\_prefix'), 5, 2);
67
add\_filter('permalink\_manager\_detect\_uri', array($this, 'wpml\_ignore\_lang\_query\_parameter'), 9);
62
if ( $mode === 'prepend' ) {
63
add\_filter( 'permalink\_manager\_detect\_uri', array( $this, 'detect\_uri\_language' ), 9, 3 );
64
add\_filter( 'permalink\_manager\_filter\_permalink\_base', array( $this, 'prepend\_lang\_prefix' ), 9, 2 );
65
} else if ( $mode === 'append' ) {
66
add\_filter( 'permalink\_manager\_filter\_final\_post\_permalink', array( $this, 'append\_lang\_prefix' ), 5, 2 );
67
add\_filter( 'permalink\_manager\_filter\_final\_term\_permalink', array( $this, 'append\_lang\_prefix' ), 5, 2 );
68
add\_filter( 'permalink\_manager\_detect\_uri', array( $this, 'wpml\_ignore\_lang\_query\_parameter' ), 9 );
68
69
}
69
70
70
71
// Translate permastructures
71
add\_filter('permalink\_manager\_filter\_permastructure', array($this, 'translate\_permastructure'), 9, 2);
72
add\_filter( 'permalink\_manager\_filter\_permastructure', array( $this, 'translate\_permastructure' ), 9, 2 );
72
73
73
74
// Translate custom permalinks
74
if($this->is\_wpml\_compatible()) {
75
add\_filter('permalink\_manager\_filter\_final\_post\_permalink', array($this, 'translate\_permalinks'), 9, 2);
75
if ( $this->is\_wpml\_compatible() ) {
76
add\_filter( 'permalink\_manager\_filter\_final\_post\_permalink', array( $this, 'translate\_permalinks' ), 9, 2 );
76
77
}
77
78
78
79
// Translate post type slug
79
if(class\_exists('WPML\_Slug\_Translation')) {
80
add\_filter('permalink\_manager\_filter\_post\_type\_slug', array($this, 'wpml\_translate\_post\_type\_slug'), 9, 3);
80
if ( class\_exists( 'WPML\_Slug\_Translation' ) ) {
81
add\_filter( 'permalink\_manager\_filter\_post\_type\_slug', array( $this, 'wpml\_translate\_post\_type\_slug' ), 9, 3 );
81
82
}
82
83
83
84
// Translate WooCommerce endpoints
84
if(class\_exists('WCML\_Endpoints')) {
85
add\_filter('request', array($this, 'wpml\_translate\_wc\_endpoints'), 99999);
85
if ( class\_exists( 'WCML\_Endpoints' ) ) {
86
add\_filter( 'request', array( $this, 'wpml\_translate\_wc\_endpoints' ), 99999 );
86
87
}
87
88
88
89
// Edit custom URI using WPML Classic Translation Editor
89
if(class\_exists('WPML\_Translation\_Editor\_UI')) {
90
add\_filter('wpml\_tm\_adjust\_translation\_fields', array($this, 'wpml\_translation\_edit\_uri'), 999, 2);
91
add\_action('icl\_pro\_translation\_saved', array($this, 'wpml\_translation\_save\_uri'), 999, 3);
92
add\_filter('wpml\_translation\_editor\_save\_job\_data', array($this, 'wpml\_translation\_save\_uri'), 999, 2);
90
if ( class\_exists( 'WPML\_Translation\_Editor\_UI' ) ) {
91
add\_filter( 'wpml\_tm\_adjust\_translation\_fields', array( $this, 'wpml\_translation\_edit\_uri' ), 999, 2 );
92
add\_action( 'icl\_pro\_translation\_saved', array( $this, 'wpml\_translation\_save\_uri' ), 999, 3 );
93
add\_filter( 'wpml\_translation\_editor\_save\_job\_data', array( $this, 'wpml\_translation\_save\_uri' ), 999, 2 );
93
94
}
94
95
95
96
// Generate custom permalink after WPML's Advanced Translation editor is used
96
if(!empty($sitepress\_settings\['translation-management'\]) && !empty($sitepress\_settings\['translation-management'\]\['doc\_translation\_method'\]) && $sitepress\_settings\['translation-management'\]\['doc\_translation\_method'\] == 'ATE') {
97
add\_action('icl\_pro\_translation\_completed', array($this, 'regenerate\_uri\_after\_wpml\_translation\_completed'), 99, 3);
98
}
99
100
add\_action('icl\_make\_duplicate', array($this, 'wpml\_duplicate\_uri'), 999, 4);
97
if ( ! empty( $sitepress\_settings\['translation-management'\] ) && ! empty( $sitepress\_settings\['translation-management'\]\['doc\_translation\_method'\] ) && $sitepress\_settings\['translation-management'\]\['doc\_translation\_method'\] == 'ATE' ) {
98
add\_action( 'icl\_pro\_translation\_completed', array( $this, 'regenerate\_uri\_after\_wpml\_translation\_completed' ), 99, 3 );
99
}
100
101
add\_action( 'icl\_make\_duplicate', array( $this, 'wpml\_duplicate\_uri' ), 999, 4 );
101
102
102
103
// Allow canonical redirect for default language if "Hide URL language information for default language" is turned on in Polylang settings
103
if(!empty($polylang) && !empty($polylang->links\_model) && !empty($polylang->links\_model->options\['hide\_default'\])) {
104
add\_filter('permalink\_manager\_filter\_query', array($this, 'pl\_allow\_canonical\_redirect'), 3, 5);
104
if ( ! empty( $polylang ) && ! empty( $polylang->links\_model ) && ! empty( $polylang->links\_model->options\['hide\_default'\] ) ) {
105
add\_filter( 'permalink\_manager\_filter\_query', array( $this, 'pl\_allow\_canonical\_redirect' ), 3, 5 );
105
106
}
106
107
}
…
…
114
115
115
116
// Use the current language if translation is not available but fallback mode is turned on
116
return (!empty($permalink\_manager\_options\['general'\]\['wpml\_support'\])) ? $permalink\_manager\_options\['general'\]\['wpml\_support'\] : false;
117
}
118
119
/\*\*
120
\* WPML/Polylang/TranslatePress filters
121
\*/
122
public static function get\_language\_code($element) {
123
global $TRP\_LANGUAGE, $translate\_press\_settings, $icl\_adjust\_id\_url\_filter\_off, $sitepress, $polylang, $wpml\_post\_translations, $wpml\_term\_translations;
117
return ( ! empty( $permalink\_manager\_options\['general'\]\['wpml\_support'\] ) ) ? $permalink\_manager\_options\['general'\]\['wpml\_support'\] : false;
118
}
119
120
/\*\*
121
\* Return the language code string for specific post or term
122
\*
123
\* @param string|int|WP\_Post|WP\_Term $element
124
\*
125
\* @return false|string
126
\*/
127
public static function get\_language\_code( $element ) {
128
global $TRP\_LANGUAGE, $icl\_adjust\_id\_url\_filter\_off, $sitepress, $polylang, $wpml\_post\_translations, $wpml\_term\_translations;
124
129
125
130
// Disable WPML adjust ID filter
…
…
127
132
128
133
// Fallback
129
if(is\_string($element) && strpos($element, 'tax-') !== false) {
130
$element\_id = intval(preg\_replace("/\[^0-9\]/", "", $element));
131
$element \= get\_term($element\_id);
132
} else if(is\_numeric($element)) {
133
$element = get\_post($element);
134
if ( is\_string( $element ) && strpos( $element, 'tax-' ) !== false ) {
135
$element\_id = intval( preg\_replace( "/\[^0-9\]/", "", $element ) );
136
$element = get\_term( $element\_id );
137
} else if ( is\_numeric( $element ) ) {
138
$element = get\_post( $element );
134
139
}
135
140
136
141
// A. TranslatePress
137
if(!empty($TRP\_LANGUAGE)) {
138
$lang\_code = self::get\_translatepress\_language\_code($TRP\_LANGUAGE);
139
}
140
// B. Polylang
141
else if(!empty($polylang) && function\_exists('pll\_get\_post\_language')) {
142
if(isset($element->post\_type)) {
143
$lang\_code = pll\_get\_post\_language($element->ID, 'slug');
144
} else if(isset($element->taxonomy)) {
145
$lang\_code = pll\_get\_term\_language($element->term\_id, 'slug');
146
}
147
}
148
// C. WPML
149
else if(!empty($sitepress)) {
150
$is\_wpml\_compatible = (method\_exists($sitepress, 'is\_display\_as\_translated\_post\_type')) ? self::is\_wpml\_compatible() : false;
151
152
if(isset($element->post\_type)) {
153
$element\_id = $element->ID;
142
if ( ! empty( $TRP\_LANGUAGE ) ) {
143
$lang\_code = self::get\_translatepress\_language\_code( $TRP\_LANGUAGE );
144
} // B. Polylang
145
else if ( ! empty( $polylang ) && function\_exists( 'pll\_get\_post\_language' ) ) {
146
if ( isset( $element->post\_type ) ) {
147
$lang\_code = pll\_get\_post\_language( $element->ID, 'slug' );
148
} else if ( isset( $element->taxonomy ) ) {
149
$lang\_code = pll\_get\_term\_language( $element->term\_id, 'slug' );
150
}
151
} // C. WPML
152
else if ( ! empty( $sitepress ) ) {
153
$is\_wpml\_compatible = ( method\_exists( $sitepress, 'is\_display\_as\_translated\_post\_type' ) ) ? self::is\_wpml\_compatible() : false;
154
155
if ( isset( $element->post\_type ) ) {
156
$element\_id = $element->ID;
154
157
$element\_type = $element->post\_type;
155
158
156
$fallback\_lang\_on = ($is\_wpml\_compatible) ? $sitepress->is\_display\_as\_translated\_post\_type($element\_type) : false;
157
} else if(isset($element->taxonomy)) {
158
$element\_id \= $element->term\_taxonomy\_id;
159
$fallback\_lang\_on = ( $is\_wpml\_compatible ) ? $sitepress->is\_display\_as\_translated\_post\_type( $element\_type ) : false;
160
} else if ( isset( $element->taxonomy ) ) {
161
$element\_id \= $element->term\_taxonomy\_id;
159
162
$element\_type = $element->taxonomy;
160
163
161
$fallback\_lang\_on = ($is\_wpml\_compatible) ? $sitepress->is\_display\_as\_translated\_taxonomy($element\_type) : false;
164
$fallback\_lang\_on = ( $is\_wpml\_compatible ) ? $sitepress->is\_display\_as\_translated\_taxonomy( $element\_type ) : false;
162
165
} else {
163
166
return false;
164
167
}
165
168
166
if(!empty($fallback\_lang\_on) && !is\_admin() && !wp\_doing\_ajax() && !defined('REST\_REQUEST')) {
169
if ( ! empty( $fallback\_lang\_on ) && ! is\_admin() && ! wp\_doing\_ajax() && ! defined( 'REST\_REQUEST' ) ) {
167
170
$current\_language = $sitepress->get\_current\_language();
168
171
169
if(!empty($element->post\_type)) {
170
$force\_current\_lang = $wpml\_post\_translations->element\_id\_in($element\_id, $current\_language) ? false : $current\_language;
171
} else if(!empty($element->taxonomy)) {
172
$force\_current\_lang = $wpml\_term\_translations->element\_id\_in($element\_id, $current\_language) ? false : $current\_language;
173
}
174
}
175
176
$lang\_code = (!empty($force\_current\_lang)) ? $force\_current\_lang : apply\_filters('wpml\_element\_language\_code', null, array('element\_id' => $element\_id, 'element\_type' => $element\_type));
172
if ( ! empty( $element->post\_type ) ) {
173
$force\_current\_lang = $wpml\_post\_translations->element\_id\_in( $element\_id, $current\_language ) ? false : $current\_language;
174
} else if ( ! empty( $element->taxonomy ) ) {
175
$force\_current\_lang = $wpml\_term\_translations->element\_id\_in( $element\_id, $current\_language ) ? false : $current\_language;
176
}
177
}
178
179
$lang\_code = ( ! empty( $force\_current\_lang ) ) ? $force\_current\_lang : apply\_filters( 'wpml\_element\_language\_code', null, array( 'element\_id' => $element\_id, 'element\_type' => $element\_type ) );
177
180
}
178
181
…
…
181
184
182
185
// Use default language if nothing detected
183
return (!empty($lang\_code)) ? $lang\_code : self::get\_default\_language();
184
}
185
186
public static function get\_translatepress\_language\_code($lang) {
186
return ( ! empty( $lang\_code ) ) ? $lang\_code : self::get\_default\_language();
187
}
188
189
/\*\*
190
\* Filter the language code of a provided post or term
191
\*
192
\* @param string $lang\_code
193
\* @param string|integer $element
194
\*
195
\* @return false|string
196
\*/
197
public function filter\_get\_language\_code( $lang\_code = '', $element = '' ) {
198
return self::get\_language\_code( $element );
199
}
200
201
/\*\*
202
\* Return the language URL prefix code for TranslatePress
203
\* @param string $lang
204
\*
205
\* @return false|string
206
\*/
207
public static function get\_translatepress\_language\_code( $lang ) {
187
208
global $translate\_press\_settings;
188
209
189
if(!empty($translate\_press\_settings\['url-slugs'\])) {
190
$lang\_code = (!empty($translate\_press\_settings\['url-slugs'\]\[$lang\])) ? $translate\_press\_settings\['url-slugs'\]\[$lang\] : '';
191
}
192
193
return (!empty($lang\_code)) ? $lang\_code : false;
194
}
195
210
if ( ! empty( $translate\_press\_settings\['url-slugs'\] ) ) {
211
$lang\_code = ( ! empty( $translate\_press\_settings\['url-slugs'\]\[ $lang \] ) ) ? $translate\_press\_settings\['url-slugs'\]\[ $lang \] : '';
212
}
213
214
return ( ! empty( $lang\_code ) ) ? $lang\_code : false;
215
}
216
217
/\*\*
218
\* Return the language code for the default language
219
\*
220
\* @return false|string
221
\*/
196
222
public static function get\_default\_language() {
197
223
global $sitepress, $translate\_press\_settings;
198
224
199
if(function\_exists('pll\_default\_language')) {
200
$def\_lang = pll\_default\_language('slug');
201
} else if(is\_object($sitepress)) {
225
if ( function\_exists( 'pll\_default\_language' ) ) {
226
$def\_lang = pll\_default\_language( 'slug' );
227
} else if ( is\_object( $sitepress ) ) {
202
228
$def\_lang = $sitepress->get\_default\_language();
203
} else if(!empty($translate\_press\_settings\['default-language'\])) {
204
$def\_lang = self::get\_translatepress\_language\_code($translate\_press\_settings\['default-language'\]);
229
} else if ( ! empty( $translate\_press\_settings\['default-language'\] ) ) {
230
$def\_lang = self::get\_translatepress\_language\_code( $translate\_press\_settings\['default-language'\] );
205
231
} else {
206
232
$def\_lang = '';
…
…
210
236
}
211
237
212
public static function get\_all\_languages($exclude\_default\_language = false) {
213
global $sitepress, $sitepress\_settings, $polylang, $translate\_press\_settings;
214
215
$languages\_array = $active\_languages = array();
238
/\*\*
239
\* Return the array with all defined languages
240
\*
241
\* @param bool $exclude\_default\_language
242
\*
243
\* @return array
244
\*/
245
public static function get\_all\_languages( $exclude\_default\_language = false ) {
246
global $sitepress, $sitepress\_settings;
247
248
$languages\_array = $active\_languages = array();
216
249
$default\_language = self::get\_default\_language();
217
250
218
if(!empty($sitepress\_settings\['active\_languages'\])) {
251
if ( ! empty( $sitepress\_settings\['active\_languages'\] ) ) {
219
252
$languages\_array = $sitepress\_settings\['active\_languages'\];
220
} elseif(function\_exists('pll\_languages\_list')) {
221
$languages\_array = pll\_languages\_list(array('fields' => null));
222
} if(!empty($translate\_press\_settings\['url-slugs'\])) {
223
// $languages\_array = $translate\_press\_settings\['url-slugs'\];
224
}
253
} elseif ( function\_exists( 'pll\_languages\_list' ) ) {
254
$languages\_array = pll\_languages\_list( array( 'fields' => null ) );
255
}
256
257
/\*if ( ! empty( $translate\_press\_settings\['url-slugs'\] ) ) {
258
$languages\_array = $translate\_press\_settings\['url-slugs'\];
259
}\*/
225
260
226
261
// Get native language names as value
227
if($languages\_array) {
228
foreach($languages\_array as $val) {
229
if(!empty($sitepress)) {
230
$lang \= $val;
231
$lang\_details \= $sitepress->get\_language\_details($lang);
262
if ( $languages\_array ) {
263
foreach ( $languages\_array as $val ) {
264
if ( ! empty( $sitepress ) ) {
265
$lang \= $val;
266
$lang\_details = $sitepress->get\_language\_details( $lang );
232
267
$language\_name = $lang\_details\['native\_name'\];
233
} else if(!empty($val->name)) {
234
$lang \= $val->slug;
268
} else if ( ! empty( $val->name ) ) {
269
$lang \= $val->slug;
235
270
$language\_name = $val->name;
236
271
}
237
272
238
$active\_languages\[$lang\] = (!empty($language\_name)) ? sprintf('%s <span>(%s)</span>', $language\_name, $lang) : '-';
273
if( !empty($lang) ) {
274
$active\_languages\[ $lang \] = ( ! empty( $language\_name ) ) ? sprintf( '%s <span>(%s)</span>', $language\_name, $lang ) : '-';
275
}
239
276
}
240
277
241
278
// Exclude default language if needed
242
if($exclude\_default\_language && $default\_language && !empty($active\_languages\[$default\_language\])) {
243
unset($active\_languages\[$default\_language\]);
244
}
245
}
246
247
return (array) $active\_languages;
248
}
249
250
function fix\_language\_mismatch($item\_id, $uri\_parts, $is\_term = false) {
251
global $wp, $polylang, $language\_code, $permalink\_manager\_options, $icl\_adjust\_id\_url\_filter\_off;
252
253
$mode = (!empty($permalink\_manager\_options\['general'\]\['fix\_language\_mismatch'\])) ? $permalink\_manager\_options\['general'\]\['fix\_language\_mismatch'\] : 0;
279
if ( $exclude\_default\_language && $default\_language && ! empty( $active\_languages\[ $default\_language \] ) ) {
280
unset( $active\_languages\[ $default\_language \] );
281
}
282
}
283
284
return $active\_languages;
285
}
286
287
/\*\*
288
\* If the requested language code does not match the language of the requested content, modify which post/term is to be loaded
289
\*
290
\* @param string|int $item\_id
291
\* @param array $uri\_parts
292
\* @param bool $is\_term
293
\*
294
\* @return false|int
295
\*/
296
function fix\_language\_mismatch( $item\_id, $uri\_parts, $is\_term = false ) {
297
global $polylang, $permalink\_manager\_options, $icl\_adjust\_id\_url\_filter\_off;
298
299
$mode = ( ! empty( $permalink\_manager\_options\['general'\]\['fix\_language\_mismatch'\] ) ) ? $permalink\_manager\_options\['general'\]\['fix\_language\_mismatch'\] : 0;
254
300
255
301
// Stop WPML from changing the output of the get\_term() and get\_post() functions
256
302
$icl\_adjust\_id\_url\_filter\_off\_prior = $icl\_adjust\_id\_url\_filter\_off;
257
$icl\_adjust\_id\_url\_filter\_off \= true;
258
259
if($is\_term) {
260
$element = get\_term($item\_id);
261
if(!empty($element) && !is\_wp\_error($element)) {
262
$element\_id \= $element->term\_taxonomy\_id;
303
$icl\_adjust\_id\_url\_filter\_off \= true;
304
305
if ( $is\_term ) {
306
$element = get\_term( $item\_id );
307
if ( ! empty( $element ) && ! is\_wp\_error( $element ) ) {
308
$element\_id \= $element->term\_taxonomy\_id;
263
309
$element\_type = $element->taxonomy;
264
310
} else {
…
…
266
312
}
267
313
} else {
268
$element = get\_post($item\_id);
269
270
if(!empty($element->post\_type)) {
271
$element\_id \= $item\_id;
314
$element = get\_post( $item\_id );
315
316
if ( ! empty( $element->post\_type ) ) {
317
$element\_id \= $item\_id;
272
318
$element\_type = $element->post\_type;
273
319
}
…
…
275
321
276
322
// Stop if no term or post is detected
277
if(empty($element)) { return false; }
323
if ( empty( $element\_id ) || empty( $element\_type ) ) {
324
return false;
325
}
278
326
279
327
// Get the language code of the found post/term
280
$element\_language\_code = self::get\_language\_code($element);
328
$element\_language\_code = self::get\_language\_code( $element );
281
329
282
330
// Get the detected language code
283
if(defined('ICL\_LANGUAGE\_CODE')) {
331
if ( defined( 'ICL\_LANGUAGE\_CODE' ) ) {
284
332
$detected\_language\_code = ICL\_LANGUAGE\_CODE;
285
} else if(!empty($uri\_parts\['lang'\])) {
333
} else if ( ! empty( $uri\_parts\['lang'\] ) ) {
286
334
$detected\_language\_code = $uri\_parts\['lang'\];
287
335
} else {
…
…
289
337
}
290
338
291
if($detected\_language\_code !== $element\_language\_code) {
339
if ( $detected\_language\_code !== $element\_language\_code ) {
292
340
// A. Display the content in requested language
293
if($mode == 1) {
294
if(!empty($polylang)) {
295
if(function\_exists('pll\_get\_post') && !$is\_term) {
296
$translated\_item\_id = pll\_get\_post($element\_id, $detected\_language\_code);
297
} else if(function\_exists('pll\_get\_term') && $is\_term) {
298
$translated\_item\_id = pll\_get\_term($element\_id, $detected\_language\_code);
341
if ( $mode == 1 ) {
342
if ( ! empty( $polylang ) ) {
343
if ( function\_exists( 'pll\_get\_post' ) && ! $is\_term ) {
344
$translated\_item\_id = pll\_get\_post( $element\_id, $detected\_language\_code );
345
} else if ( function\_exists( 'pll\_get\_term' ) && $is\_term ) {
346
$translated\_item\_id = pll\_get\_term( $element\_id, $detected\_language\_code );
299
347
}
300
348
301
$item\_id = (isset($translated\_item\_id)) ? $translated\_item\_id : $item\_id;
349
$item\_id = ( isset( $translated\_item\_id ) ) ? $translated\_item\_id : $item\_id;
302
350
} else {
303
$item\_id = apply\_filters('wpml\_object\_id', $element\_id, $element\_type);
304
}
305
}
306
// C. Display "404 error"
351
$item\_id = apply\_filters( 'wpml\_object\_id', $element\_id, $element\_type );
352
}
353
} // C. Display "404 error"
307
354
else {
308
355
$item\_id = 0;
…
…
316
363
317
364
/\*\*
318
\* 5C. Fix for WPML (language switcher on blog page)
319
\*/
320
function fix\_posts\_page($query, $old\_query, $uri\_parts, $pm\_query, $content\_type) {
321
if(empty($pm\_query\['id'\]) || !is\_numeric($pm\_query\['id'\])) {
365
\* Fix the language switcher on blog page (WPML bug)
366
\*
367
\* @param array $query
368
\* @param array $old\_query
369
\* @param array $uri\_parts
370
\* @param array $pm\_query
371
\* @param string $content\_type
372
\*
373
\* @return array
374
\*/
375
function fix\_posts\_page( $query, $old\_query, $uri\_parts, $pm\_query, $content\_type ) {
376
if ( empty( $pm\_query\['id'\] ) || ! is\_numeric( $pm\_query\['id'\] ) ) {
322
377
return $query;
323
378
}
324
379
325
$blog\_page\_id = apply\_filters('wpml\_object\_id', get\_option('page\_for\_posts'), 'page');
326
$element\_id \= apply\_filters('wpml\_object\_id', $pm\_query\['id'\], 'page');
327
328
if(!empty($blog\_page\_id) && !empty($blog\_page\_id) && ($blog\_page\_id == $element\_id) && !isset($query\['page'\])) {
380
$blog\_page\_id = apply\_filters( 'wpml\_object\_id', get\_option( 'page\_for\_posts' ), 'page' );
381
$element\_id = apply\_filters( 'wpml\_object\_id', $pm\_query\['id'\], 'page' );
382
383
if ( ! empty( $blog\_page\_id ) && ( $blog\_page\_id == $element\_id ) && ! isset( $query\['page'\] ) ) {
329
384
$query\['page'\] = '';
330
385
}
…
…
333
388
}
334
389
335
function detect\_uri\_language($uri\_parts, $request\_url, $endpoints) {
336
global $sitepress, $sitepress\_settings, $polylang, $translate\_press\_settings;
337
338
if(!empty($sitepress\_settings\['active\_languages'\])) {
390
/\*\*
391
\* Detect the language of requested content and add it to $uri\_parts array
392
\*
393
\* @param array $uri\_parts
394
\* @param string $request\_url
395
\* @param string $endpoints
396
\*
397
\* @return array
398
\*/
399
function detect\_uri\_language( $uri\_parts, $request\_url, $endpoints ) {
400
global $sitepress\_settings, $polylang, $translate\_press\_settings;
401
402
if ( ! empty( $sitepress\_settings\['active\_languages'\] ) ) {
339
403
$languages\_list = (array) $sitepress\_settings\['active\_languages'\];
340
} elseif(function\_exists('pll\_languages\_list')) {
404
} elseif ( function\_exists( 'pll\_languages\_list' ) ) {
341
405
$languages\_array = pll\_languages\_list();
342
$languages\_list \= (is\_array($languages\_array)) ? (array) $languages\_array : "";
343
} elseif($translate\_press\_settings\['url-slugs'\]) {
406
$languages\_list = ( is\_array( $languages\_array ) ) ? $languages\_array : "";
407
} elseif ( $translate\_press\_settings\['url-slugs'\] ) {
344
408
$languages\_list = $translate\_press\_settings\['url-slugs'\];
345
409
}
346
410
347
if(is\_array($languages\_list)) {
348
$languages\_list = implode("|", $languages\_list);
411
if ( ! empty( $languages\_list ) && is\_array( $languages\_list ) ) {
412
$languages\_list = implode( "|", $languages\_list );
349
413
} else {
350
414
return $uri\_parts;
…
…
354
418
355
419
// Fix for multidomain language configuration
356
if((isset($sitepress\_settings\['language\_negotiation\_type'\]) && $sitepress\_settings\['language\_negotiation\_type'\] == 2) || (!empty($polylang->options\['force\_lang'\]) && $polylang->options\['force\_lang'\] == 3)) {
357
if(!empty($polylang->options\['domains'\])) {
420
if ( ( isset( $sitepress\_settings\['language\_negotiation\_type'\] ) && $sitepress\_settings\['language\_negotiation\_type'\] == 2 ) || ( ! empty( $polylang->options\['force\_lang'\] ) && $polylang->options\['force\_lang'\] == 3 ) ) {
421
if ( ! empty( $polylang->options\['domains'\] ) ) {
358
422
$domains = (array) $polylang->options\['domains'\];
359
} else if(!empty($sitepress\_settings\['language\_domains'\])) {
423
} else if ( ! empty( $sitepress\_settings\['language\_domains'\] ) ) {
360
424
$domains = (array) $sitepress\_settings\['language\_domains'\];
361
425
}
362
426
363
foreach($domains as &$domain) {
364
$domain = preg\_replace('/((http(s)?:\\/\\/(www\\.)?)|(www\\.))?(.+?)\\/?$/', 'http://$6', $domain);
365
}
366
367
$request\_url = trim(str\_replace($domains, "", $request\_url), "/");
368
}
369
370
if(!empty($languages\_list)) {
371
//preg\_match("/^(?:({$languages\_list})\\/)?(.+?)(?|\\/({$endpoints})\[\\/$\](\[^\\/\]\*)|\\/()(\[\\d+\]))?\\/?$/i", $request\_url, $regex\_parts);
372
preg\_match("/^(?:({$languages\_list})\\/)?(.+?)(?|\\/({$endpoints})(?|\\/(.\*)|$)|\\/()(\[\\d\]+)\\/?)?$/i", $request\_url, $regex\_parts);
373
374
$uri\_parts\['lang'\] = (!empty($regex\_parts\[1\])) ? $regex\_parts\[1\] : $default\_language;
375
$uri\_parts\['uri'\] = (!empty($regex\_parts\[2\])) ? $regex\_parts\[2\] : "";
376
$uri\_parts\['endpoint'\] = (!empty($regex\_parts\[3\])) ? $regex\_parts\[3\] : "";
377
$uri\_parts\['endpoint\_value'\] = (!empty($regex\_parts\[4\])) ? $regex\_parts\[4\] : "";
427
if ( ! empty( $domains ) ) {
428
foreach ( $domains as &$domain ) {
429
$domain = preg\_replace( '/((http(s)?:\\/\\/(www\\.)?)|(www\\.))?(.+?)\\/?$/', 'http://$6', $domain );
430
}
431
432
$request\_url = trim( str\_replace( $domains, "", $request\_url ), "/" );
433
}
434
}
435
436
if ( ! empty( $languages\_list ) ) {
437
preg\_match( "/^(?:({$languages\_list})\\/)?(.+?)(?|\\/({$endpoints})(?|\\/(.\*)|$)|\\/(\[\\d\]+)\\/?)?$/i", $request\_url, $regex\_parts );
438
439
$uri\_parts\['lang'\] = ( ! empty( $regex\_parts\[1\] ) ) ? $regex\_parts\[1\] : $default\_language;
440
$uri\_parts\['uri'\] = ( ! empty( $regex\_parts\[2\] ) ) ? $regex\_parts\[2\] : "";
441
$uri\_parts\['endpoint'\] = ( ! empty( $regex\_parts\[3\] ) ) ? $regex\_parts\[3\] : "";
442
$uri\_parts\['endpoint\_value'\] = ( ! empty( $regex\_parts\[4\] ) ) ? $regex\_parts\[4\] : "";
378
443
}
379
444
…
…
381
446
}
382
447
383
static function prepend\_lang\_prefix($base, $element, $language\_code = '') {
384
global $sitepress\_settings, $polylang, $permalink\_manager\_uris, $translate\_press\_settings;
385
386
if(!empty($element) && empty($language\_code)) {
387
$language\_code = self::get\_language\_code($element);
388
389
// Last instance - use language paramater from &\_GET array
390
$language\_code = (is\_admin() && empty($language\_code) && !empty($\_GET\['lang'\])) ? sanitize\_key($\_GET\['lang'\]) : $language\_code;
448
/\*\*
449
\* Append the language code to the URL directly after the domain name
450
\*
451
\* @param string $base
452
\* @param string|int|WP\_Post|WP\_Term $element
453
\* @param string $language\_code
454
\*
455
\* @return string
456
\*/
457
static function prepend\_lang\_prefix( $base, $element, $language\_code = '' ) {
458
global $sitepress\_settings, $polylang, $translate\_press\_settings;
459
460
if ( ! empty( $element ) && empty( $language\_code ) ) {
461
$language\_code = self::get\_language\_code( $element );
462
463
// Last instance - use language parameter from &\_GET array
464
$language\_code = ( is\_admin() && empty( $language\_code ) && ! empty( $\_GET\['lang'\] ) ) ? sanitize\_key( $\_GET\['lang'\] ) : $language\_code;
391
465
}
392
466
393
467
// Adjust URL base
394
if(!empty($language\_code)) {
468
if ( ! empty( $language\_code ) ) {
395
469
$default\_language\_code = self::get\_default\_language();
396
$home\_url \= get\_home\_url();
470
$home\_url \= get\_home\_url();
397
471
398
472
// Hide language code if "Use directory for default language" option is enabled
399
$hide\_prefix\_for\_default\_lang = ((isset($sitepress\_settings\['urls'\]\['directory\_for\_default\_language'\]) && $sitepress\_settings\['urls'\]\['directory\_for\_default\_language'\] != 1) || !empty($polylang->links\_model->options\['hide\_default'\]) || (!empty($translate\_press\_settings) && $translate\_press\_settings\['add-subdirectory-to-default-language'\] !== 'yes')) ? true : false;
473
$hide\_prefix\_for\_default\_lang = ( ( isset( $sitepress\_settings\['urls'\]\['directory\_for\_default\_language'\] ) && $sitepress\_settings\['urls'\]\['directory\_for\_default\_language'\] != 1 ) || ! empty( $polylang->links\_model->options\['hide\_default'\] ) || ( ! empty( $translate\_press\_settings ) && $translate\_press\_settings\['add-subdirectory-to-default-language'\] !== 'yes' ) ) ? true : false;
400
474
401
475
// A. Different domain per language
402
if((isset($sitepress\_settings\['language\_negotiation\_type'\]) && $sitepress\_settings\['language\_negotiation\_type'\] == 2) || (!empty($polylang->options\['force\_lang'\]) && $polylang->options\['force\_lang'\] == 3)) {
403
if(!empty($polylang->options\['domains'\])) {
476
if ( ( isset( $sitepress\_settings\['language\_negotiation\_type'\] ) && $sitepress\_settings\['language\_negotiation\_type'\] == 2 ) || ( ! empty( $polylang->options\['force\_lang'\] ) && $polylang->options\['force\_lang'\] == 3 ) ) {
477
if ( ! empty( $polylang->options\['domains'\] ) ) {
404
478
$domains = $polylang->options\['domains'\];
405
} else if(!empty($sitepress\_settings\['language\_domains'\])) {
479
} else if ( ! empty( $sitepress\_settings\['language\_domains'\] ) ) {
406
480
$domains = $sitepress\_settings\['language\_domains'\];
407
481
}
408
482
409
483
// Replace the domain name
410
if(!empty($domains) && !empty($domains\[$language\_code\])) {
411
$base = trim($domains\[$language\_code\], "/");
484
if ( ! empty( $domains ) && ! empty( $domains\[ $language\_code \] ) ) {
485
$base = trim( $domains\[ $language\_code \], "/" );
412
486
413
487
// Append URL scheme
414
if(!preg\_match("~^(?:f|ht)tps?://~i", $base)) {
415
$scehme = parse\_url($home\_url, PHP\_URL\_SCHEME);
416
$base = "{$scehme}://{$base}";
417
}
418
}
419
}
420
// B. Prepend language code
421
else if(!empty($polylang->options\['force\_lang'\]) && $polylang->options\['force\_lang'\] == 2) {
422
if($hide\_prefix\_for\_default\_lang && ($default\_language\_code == $language\_code)) {
488
if ( ! preg\_match( "~^(?:f|ht)tps?://~i", $base ) ) {
489
$scheme = parse\_url( $home\_url, PHP\_URL\_SCHEME );
490
$base = "{$scheme}://{$base}";
491
}
492
}
493
} // B. Prepend language code
494
else if ( ! empty( $polylang->options\['force\_lang'\] ) && $polylang->options\['force\_lang'\] == 2 ) {
495
if ( $hide\_prefix\_for\_default\_lang && ( $default\_language\_code == $language\_code ) ) {
423
496
return $base;
424
497
} else {
425
$base = preg\_replace('/(https?:\\/\\/)/', "$1{$language\_code}.", $home\_url);
426
}
427
}
428
// C. Append prefix
498
$base = preg\_replace( '/(https?:\\/\\/)/', "$1{$language\_code}.", $home\_url );
499
}
500
} // C. Append prefix
429
501
else {
430
if($hide\_prefix\_for\_default\_lang && ($default\_language\_code == $language\_code)) {
502
if ( $hide\_prefix\_for\_default\_lang && ( $default\_language\_code == $language\_code ) ) {
431
503
return $base;
432
504
} else {
…
…
439
511
}
440
512
441
function append\_lang\_prefix($permalink, $element) {
442
global $sitepress\_settings, $polylang, $permalink\_manager\_uris;
443
444
$language\_code = self::get\_language\_code($element);
513
/\*\*
514
\* Append language code as a $\_GET parameter to the end of URL
515
\*
516
\* @param string $permalink
517
\* @param string|int|WP\_Post|WP\_Term $element
518
\*
519
\* @return string
520
\*/
521
function append\_lang\_prefix( $permalink, $element ) {
522
global $sitepress\_settings;
523
524
$language\_code = self::get\_language\_code( $element );
445
525
$default\_language\_code = self::get\_default\_language();
446
526
447
// Last instance - use language paramater from &\_GET array
448
if(is\_admin()) {
449
$language\_code = (empty($language\_code) && !empty($\_GET\['lang'\])) ? $\_GET\['lang'\] : $language\_code;
450
}
451
452
// B. Append ?lang query parameter
453
if(isset($sitepress\_settings\['language\_negotiation\_type'\]) && $sitepress\_settings\['language\_negotiation\_type'\] == 3) {
454
if($default\_language\_code == $language\_code) {
527
// Last instance - use language parameter from &\_GET array
528
if ( is\_admin() ) {
529
$language\_code = ( empty( $language\_code ) && ! empty( $\_GET\['lang'\] ) ) ? $\_GET\['lang'\] : $language\_code;
530
}
531
532
// Append ?lang query parameter
533
if ( isset( $sitepress\_settings\['language\_negotiation\_type'\] ) && $sitepress\_settings\['language\_negotiation\_type'\] == 3 ) {
534
if ( $default\_language\_code == $language\_code ) {
455
535
return $permalink;
456
} else if(strpos($permalink, "lang=") === false) {
536
} else if ( strpos( $permalink, "lang=" ) === false ) {
457
537
$permalink .= "?lang={$language\_code}";
458
538
}
…
…
462
542
}
463
543
464
function language\_column\_uri\_editor($output, $column, $element) {
465
$language\_code = self::get\_language\_code($element);
466
$output .= (!empty($language\_code)) ? sprintf(" | <span><strong>%s:</strong> %s</span>", \_\_("Language"), $language\_code) : "";
544
/\*\*
545
\* Display the language code in a table column in bulk URI Editor
546
\*
547
\* @param string $output
548
\* @param string $column
549
\* @param WP\_Post|WP\_Term $element
550
\*
551
\* @return string
552
\*/
553
function uri\_editor\_get\_lang\_col( $output, $column, $element ) {
554
$language\_code = self::get\_language\_code( $element );
555
$output .= ( ! empty( $language\_code ) ) ? sprintf( " | <span><strong>%s:</strong> %s</span>", \_\_( "Language" ), $language\_code ) : "";
467
556
468
557
return $output;
469
558
}
470
559
471
function wpml\_is\_front\_page($bool, $page\_id, $front\_page\_id) {
560
/\*\*
561
\* Check if requested URL is front page for any language
562
\*
563
\* @param bool $bool
564
\* @param int $page\_id
565
\* @param int $front\_page\_id
566
\*
567
\* @return bool
568
\*/
569
function wpml\_is\_front\_page( $bool, $page\_id, $front\_page\_id ) {
472
570
$default\_language\_code = self::get\_default\_language();
473
$page\_id = apply\_filters('wpml\_object\_id', $page\_id, 'page', true, $default\_language\_code);
474
475
return (!empty($page\_id) && $page\_id == $front\_page\_id) ? true : $bool;
476
}
477
478
function wpml\_ignore\_lang\_query\_parameter($uri\_parts) {
571
$page\_id = apply\_filters( 'wpml\_object\_id', $page\_id, 'page', true, $default\_language\_code );
572
573
return ( ! empty( $page\_id ) && $page\_id == $front\_page\_id ) ? true : $bool;
574
}
575
576
/\*\*
577
\* Ignore ?lang query parameters added to the custom permalink's array
578
\*
579
\* @param array $uri\_parts
580
\*
581
\* @return array
582
\*/
583
function wpml\_ignore\_lang\_query\_parameter( $uri\_parts ) {
479
584
global $permalink\_manager\_uris;
480
585
481
foreach($permalink\_manager\_uris as &$uri) {
482
$uri = trim(strtok($uri, '?'), "/");
586
foreach ( $permalink\_manager\_uris as &$uri ) {
587
$uri = trim( strtok( $uri, '?' ), "/" );
483
588
}
484
589
…
…
486
591
}
487
592
488
function wpml\_redirect() {
489
global $language\_code, $wp\_query;
490
491
if(!empty($language\_code) && defined('ICL\_LANGUAGE\_CODE') && ICL\_LANGUAGE\_CODE != $language\_code && !empty($wp\_query->query\['do\_not\_redirect'\])) {
492
unset($wp\_query->query\['do\_not\_redirect'\]);
493
}
494
}
495
496
/\*
497
\* Copy WPML URL hooks and use them for custom permalinks filtered with Permalink Manager
498
\*/
499
function translate\_permalinks($permalink, $post) {
500
global $wpml\_url\_filters, $wp\_filter;
501
502
if(!empty($wpml\_url\_filters)) {
503
$wpml\_url\_hook\_name = \_wp\_filter\_build\_unique\_id('post\_link', array($wpml\_url\_filters, 'permalink\_filter'), 1);
504
505
if(has\_filter('post\_link', $wpml\_url\_hook\_name)) {
506
$permalink = $wpml\_url\_filters->permalink\_filter($permalink, $post);
593
/\*\*
594
\* Reapply WPML URL hooks and use them for custom permalinks filtered with Permalink Manager
595
\*
596
\* @param string $permalink
597
\* @param int|WP\_Post $post
598
\*
599
\* @return string
600
\*/
601
function translate\_permalinks( $permalink, $post ) {
602
global $wpml\_url\_filters;
603
604
if ( ! empty( $wpml\_url\_filters ) ) {
605
$wpml\_url\_hook\_name = \_wp\_filter\_build\_unique\_id( 'post\_link', array( $wpml\_url\_filters, 'permalink\_filter' ), 1 );
606
607
if ( has\_filter( 'post\_link', $wpml\_url\_hook\_name ) ) {
608
$permalink = $wpml\_url\_filters->permalink\_filter( $permalink, $post );
507
609
}
508
610
}
…
…
511
613
}
512
614
513
function translate\_permastructure($permastructure, $element) {
514
global $permalink\_manager\_permastructs, $pagenow;;
615
/\*\*
616
\* Use the translated permastructure for the default custom permalinks
617
\*
618
\* @param string $permastructure
619
\* @param WP\_Post|WP\_Term $element
620
\*
621
\* @return string
622
\*/
623
function translate\_permastructure( $permastructure, $element ) {
624
global $permalink\_manager\_permastructs, $pagenow;
515
625
516
626
// Get element language code
517
if(!empty($\_REQUEST\['data'\]) && is\_string($\_REQUEST\['data'\]) && strpos($\_REQUEST\['data'\], "target\_lang")) {
518
$language\_code = preg\_replace('/(.\*target\_lang=)(\[^=&\]+)(.\*)/', '$2', $\_REQUEST\['data'\]);
519
} else if(in\_array($pagenow, array('post.php', 'post-new.php')) && !empty($\_GET\['lang'\])) {
627
if ( ! empty( $\_REQUEST\['data'\] ) && is\_string( $\_REQUEST\['data'\] ) && strpos( $\_REQUEST\['data'\], "target\_lang" ) ) {
628
$language\_code = preg\_replace( '/(.\*target\_lang=)(\[^=&\]+)(.\*)/', '$2', $\_REQUEST\['data'\] );
629
} else if ( in\_array( $pagenow, array( 'post.php', 'post-new.php' ) ) && ! empty( $\_GET\['lang'\] ) ) {
520
630
$language\_code = $\_GET\['lang'\];
521
} else if(!empty($\_REQUEST\['icl\_post\_language'\])) {
631
} else if ( ! empty( $\_REQUEST\['icl\_post\_language'\] ) ) {
522
632
$language\_code = $\_REQUEST\['icl\_post\_language'\];
523
} else if(!empty($\_POST\['action'\]) && $\_POST\['action'\] == 'pm\_save\_permalink' && defined('ICL\_LANGUAGE\_CODE')) {
633
} else if ( ! empty( $\_POST\['action'\] ) && $\_POST\['action'\] == 'pm\_save\_permalink' && defined( 'ICL\_LANGUAGE\_CODE' ) ) {
524
634
$language\_code = ICL\_LANGUAGE\_CODE;
525
635
} else {
526
$language\_code = self::get\_language\_code($element);
527
}
528
529
if(!empty($element->ID)) {
530
$translated\_permastructure = (!empty($permalink\_manager\_permastructs\["post\_types"\]\["{$element->post\_type}\_{$language\_code}"\])) ? $permalink\_manager\_permastructs\["post\_types"\]\["{$element->post\_type}\_{$language\_code}"\] : '';
531
} else if(!empty($element->term\_id)) {
532
$translated\_permastructure = (!empty($permalink\_manager\_permastructs\["taxonomies"\]\["{$element->taxonomy}\_{$language\_code}"\])) ? $permalink\_manager\_permastructs\["taxonomies"\]\["{$element->taxonomy}\_{$language\_code}"\] : '';
533
}
534
535
return (!empty($translated\_permastructure)) ? $translated\_permastructure : $permastructure;
536
}
537
538
function wpml\_translate\_post\_type\_slug($post\_type\_slug, $element, $post\_type) {
539
$post = (is\_integer($element)) ? get\_post($element) : $element;
540
$language\_code = self::get\_language\_code($post);
541
542
$post\_type\_slug = apply\_filters('wpml\_get\_translated\_slug', $post\_type\_slug, $post\_type, $language\_code);
543
544
// Translate %post\_type% tag in custom permastructures
545
return $post\_type\_slug;
546
}
547
548
function wpml\_translate\_wc\_endpoints($request) {
636
$language\_code = self::get\_language\_code( $element );
637
}
638
639
if ( ! empty( $element->ID ) ) {
640
$translated\_permastructure = ( ! empty( $permalink\_manager\_permastructs\["post\_types"\]\["{$element->post\_type}\_{$language\_code}"\] ) ) ? $permalink\_manager\_permastructs\["post\_types"\]\["{$element->post\_type}\_{$language\_code}"\] : '';
641
} else if ( ! empty( $element->term\_id ) ) {
642
$translated\_permastructure = ( ! empty( $permalink\_manager\_permastructs\["taxonomies"\]\["{$element->taxonomy}\_{$language\_code}"\] ) ) ? $permalink\_manager\_permastructs\["taxonomies"\]\["{$element->taxonomy}\_{$language\_code}"\] : '';
643
}
644
645
return ( ! empty( $translated\_permastructure ) ) ? $translated\_permastructure : $permastructure;
646
}
647
648
/\*\*
649
\* Translate %post\_type% tag in custom permastructures
650
\*
651
\* @param string $post\_type\_slug
652
\* @param int|WP\_Post $element
653
\* @param string $post\_type
654
\*
655
\* @return string
656
\*/
657
function wpml\_translate\_post\_type\_slug( $post\_type\_slug, $element, $post\_type ) {
658
$post = ( is\_integer( $element ) ) ? get\_post( $element ) : $element;
659
$language\_code = self::get\_language\_code( $post );
660
661
return apply\_filters( 'wpml\_get\_translated\_slug', $post\_type\_slug, $post\_type, $language\_code );
662
}
663
664
/\*\*
665
\* Translate WooCommerce URL endpoints
666
\*
667
\* @param array $request
668
\*
669
\* @return array
670
\*/
671
function wpml\_translate\_wc\_endpoints( $request ) {
549
672
global $woocommerce, $wpdb;
550
673
551
if(!empty($woocommerce->query->query\_vars)) {
674
if ( ! empty( $woocommerce->query->query\_vars ) ) {
552
675
// Get WooCommerce original endpoints
553
$endpoints = $woocommerce->query->query\_vars;
554
555
// Get all endppoint translations
556
$endpoint\_translations = $wpdb->get\_results("SELECT t.value AS translated\_endpoint, t.language, s.value AS endpoint FROM {$wpdb->prefix}icl\_string\_translations AS t LEFT JOIN {$wpdb->prefix}icl\_strings AS s ON t.string\_id = s.id WHERE context = 'WP Endpoints'");
676
// $endpoints = $woocommerce->query->query\_vars;
677
678
// Get all endpoint translations
679
$endpoint\_translations = $wpdb->get\_results( "SELECT t.value AS translated\_endpoint, t.language, s.value AS endpoint FROM {$wpdb->prefix}icl\_string\_translations AS t LEFT JOIN {$wpdb->prefix}icl\_strings AS s ON t.string\_id = s.id WHERE context = 'WP Endpoints'" );
557
680
558
681
// Replace translate endpoint with its original name
559
foreach($endpoint\_translations as $endpoint) {
560
if(isset($request\[$endpoint->translated\_endpoint\]) && ($endpoint->endpoint !== $endpoint->translated\_endpoint)) {
561
$request\[$endpoint->endpoint\] = $request\[$endpoint->translated\_endpoint\];
562
unset($request\[$endpoint->translated\_endpoint\]);
682
foreach ( $endpoint\_translations as $endpoint ) {
683
if ( isset( $request\[ $endpoint->translated\_endpoint \] ) && ( $endpoint->endpoint !== $endpoint->translated\_endpoint ) ) {
684
$request\[ $endpoint->endpoint \] = $request\[ $endpoint->translated\_endpoint \];
685
unset( $request\[ $endpoint->translated\_endpoint \] );
563
686
}
564
687
}
…
…
570
693
/\*\*
571
694
\* Generate custom permalink after WPML's Advanced Translation editor is used
572
\*/
573
function regenerate\_uri\_after\_wpml\_translation\_completed($post\_id, $postdata, $job) {
695
\*
696
\* @param string|int $post\_id
697
\* @param array $postdata
698
\* @param stdClass $job
699
\*/
700
function regenerate\_uri\_after\_wpml\_translation\_completed( $post\_id, $postdata, $job ) {
574
701
global $permalink\_manager\_uris;
575
702
576
703
// Get the default custom permalink based on a permastructure set with Permalink Manager
577
if(empty($permalink\_manager\_uris\[$post\_id\])) {
578
$permalink\_manager\_uris\[$post\_id\] = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri($post\_id);
704
if ( empty( $permalink\_manager\_uris\[ $post\_id \] ) ) {
705
$permalink\_manager\_uris\[ $post\_id \] = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri( $post\_id );
579
706
580
707
// Save the update
581
update\_option('permalink-manager-uris', $permalink\_manager\_uris);
708
update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
582
709
}
583
710
}
…
…
585
712
/\*\*
586
713
\* Edit custom URI using WPML Classic Translation Editor
587
\*/
588
function wpml\_translation\_edit\_uri($fields, $job) {
714
\*
715
\* @param array $fields
716
\* @param stdClass $job
717
\*
718
\* @return array
719
\*/
720
function wpml\_translation\_edit\_uri( $fields, $job ) {
589
721
global $permalink\_manager\_uris;
590
722
591
$element\_type = (!empty($job->original\_post\_type) && strpos($job->original\_post\_type, 'post\_') !== false) ? preg\_replace('/^(post\_)/', '', $job->original\_post\_type) : '';
592
593
if(!empty($element\_type)) {
594
$original\_id \= $job->original\_doc\_id;
595
$translation\_id = apply\_filters('wpml\_object\_id', $original\_id, $element\_type, false, $job->language\_code);
596
597
$original\_custom\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_post\_uri($original\_id, true);
598
599
if(!empty($translation\_id)) {
600
$translation\_custom\_uri \= Permalink\_Manager\_URI\_Functions\_Post::get\_post\_uri($translation\_id, true);
601
$uri\_translation\_complete = (!empty($permalink\_manager\_uris\[$translation\_id\])) ? '1' : '0';
723
$element\_type = ( ! empty( $job->original\_post\_type ) && strpos( $job->original\_post\_type, 'post\_' ) !== false ) ? preg\_replace( '/^(post\_)/', '', $job->original\_post\_type ) : '';
724
725
if ( ! empty( $element\_type ) ) {
726
$original\_id \= $job->original\_doc\_id;
727
$translation\_id = apply\_filters( 'wpml\_object\_id', $original\_id, $element\_type, false, $job->language\_code );
728
729
$original\_custom\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_post\_uri( $original\_id, true );
730
731
if ( ! empty( $translation\_id ) ) {
732
$translation\_custom\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_post\_uri( $translation\_id, true );
733
$uri\_translation\_complete = ( ! empty( $permalink\_manager\_uris\[ $translation\_id \] ) ) ? '1' : '0';
602
734
} else {
603
$translation\_custom\_uri \= $original\_custom\_uri;
735
$translation\_custom\_uri \= $original\_custom\_uri;
604
736
$uri\_translation\_complete = '0';
605
737
}
606
738
607
739
$fields\[\] = array(
608
'field\_type' \=> 'pm-custom\_uri',
740
'field\_type' \=> 'pm-custom\_uri',
609
741
//'tid' => 9999,
610
'field\_data' \=> $original\_custom\_uri,
742
'field\_data' \=> $original\_custom\_uri,
611
743
'field\_data\_translated' => $translation\_custom\_uri,
612
'field\_finished' \=> $uri\_translation\_complete,
613
'field\_style' \=> '0',
614
'title' \=> 'Custom URI',
744
'field\_finished' \=> $uri\_translation\_complete,
745
'field\_style' \=> '0',
746
'title' \=> 'Custom URI',
615
747
);
616
748
}
…
…
619
751
}
620
752
621
function wpml\_translation\_save\_uri($in = '', $data = '', $job = '') {
753
/\*\*
754
\* Save the custom permalink in Classic WPML Translation Editor
755
\*
756
\* @param array|int $in
757
\* @param array $data
758
\* @param stdClass $job
759
\*
760
\* @return array|int
761
\*/
762
function wpml\_translation\_save\_uri( $in = '', $data = '', $job = '' ) {
763
// A. Save the URI also when the translation is uncompleted
764
if ( ! empty( $in\['fields'\] ) ) {
765
$data = $in\['fields'\];
766
767
$original\_id = $in\['job\_post\_id'\];
768
$element\_type = ( strpos( $in\['job\_post\_type'\], 'post\_' ) !== false ) ? preg\_replace( '/^(post\_)/', '', $in\['job\_post\_type'\] ) : '';
769
770
$translation\_id = apply\_filters( 'wpml\_object\_id', $original\_id, $element\_type, false, $in\['target\_lang'\] );
771
} // B. Save the URI also when the translation is completed
772
else if ( is\_numeric( $in ) ) {
773
$translation\_id = $in;
774
}
775
776
if ( isset( $data\['pm-custom\_uri'\] ) && isset( $data\['pm-custom\_uri'\]\['data'\] ) && ! empty( $translation\_id ) ) {
777
$custom\_uri = ( ! empty( $data\['pm-custom\_uri'\]\['data'\] ) ) ? Permalink\_Manager\_Helper\_Functions::sanitize\_title( $data\['pm-custom\_uri'\]\['data'\], true ) : Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri( $translation\_id );
778
779
Permalink\_Manager\_URI\_Functions::save\_single\_uri( $translation\_id, $custom\_uri, false, true );
780
}
781
782
return $in;
783
}
784
785
/\*\*
786
\* Clone the custom permalink if post is duplicated with WPML
787
\*
788
\* @param int $master\_post\_id
789
\* @param string $lang
790
\* @param array $post\_array
791
\* @param int $id
792
\*/
793
function wpml\_duplicate\_uri( $master\_post\_id, $lang, $post\_array, $id ) {
622
794
global $permalink\_manager\_uris;
623
795
624
// A. Save the URI also when the translation is uncompleted
625
if(!empty($in\['fields'\])) {
626
$data = $in\['fields'\];
627
628
$original\_id = $in\['job\_post\_id'\];
629
$element\_type = (strpos($in\['job\_post\_type'\], 'post\_') !== false) ? preg\_replace('/^(post\_)/', '', $in\['job\_post\_type'\]) : '';
630
631
$translation\_id = apply\_filters('wpml\_object\_id', $original\_id, $element\_type, false, $in\['target\_lang'\]);
632
}
633
// B. Save the URI also when the translation is completed
634
else if(is\_numeric($in)) {
635
$translation\_id = $in;
636
}
637
638
if(isset($data\['pm-custom\_uri'\]) && isset($data\['pm-custom\_uri'\]\['data'\]) && !empty($translation\_id)) {
639
$permalink\_manager\_uris\[$translation\_id\] = (!empty($data\['pm-custom\_uri'\]\['data'\])) ? Permalink\_Manager\_Helper\_Functions::sanitize\_title($data\['pm-custom\_uri'\]\['data'\], true) : Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri($translation\_id);
640
641
update\_option('permalink-manager-uris', $permalink\_manager\_uris);
642
}
643
644
// Return the data when the translation is uncompleted
645
if(!empty($in\['fields'\])) {
646
return $in;
647
}
648
}
649
650
function wpml\_duplicate\_uri($master\_post\_id, $lang, $post\_array, $id) {
651
global $permalink\_manager\_uris;
652
653
796
// Trigger the function only if duplicate is created in the metabox
654
if(empty($\_POST\['action'\]) || $\_POST\['action'\] !== 'make\_duplicates') { return; }
655
656
$permalink\_manager\_uris\[$id\] = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri($id);
657
658
update\_option('permalink-manager-uris', $permalink\_manager\_uris);
659
}
660
661
function pl\_allow\_canonical\_redirect($query, $old\_query, $uri\_parts, $pm\_query, $content\_type) {
797
if ( empty( $\_POST\['action'\] ) || $\_POST\['action'\] !== 'make\_duplicates' ) {
798
return;
799
}
800
801
$permalink\_manager\_uris\[ $id \] = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri( $id );
802
803
update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
804
}
805
806
/\*\*
807
\* Allow the canonical redirect for default language if "Hide URL language information for default language" is turned on in Polylang settings
808
\*
809
\* @param array $query
810
\* @param array $old\_query
811
\* @param array $uri\_parts
812
\* @param array $pm\_query
813
\* @param string $content\_type
814
\*
815
\* @return array
816
\*/
817
function pl\_allow\_canonical\_redirect( $query, $old\_query, $uri\_parts, $pm\_query, $content\_type ) {
662
818
global $polylang;
663
819
664
820
// Run only if "Hide URL language information for default language" is turned on in Polylang settings
665
if(!empty($pm\_query\['id'\]) && !empty($pm\_query\['lang'\])) {
821
if ( ! empty( $pm\_query\['id'\] ) && ! empty( $pm\_query\['lang'\] ) ) {
666
822
$url\_lang = $polylang->links\_model->get\_language\_from\_url();
667
$def\_lang = pll\_default\_language('slug');
823
$def\_lang = pll\_default\_language( 'slug' );
668
824
669
825
// Check if the slug of default language is present in the requested URL
670
if($url\_lang == $def\_lang) {
826
if ( $url\_lang == $def\_lang ) {
671
827
// Allow canonical redirect
672
unset($query\['do\_not\_redirect'\]);
828
unset( $query\['do\_not\_redirect'\] );
673
829
}
674
830
}
permalink-manager/trunk/includes/core/permalink-manager-third-parties.php
r2796526
r2833667
2
2
3
3
/\*\*
4
\* Third parties integration
5
\*/
6
class Permalink\_Manager\_Third\_Parties extends Permalink\_Manager\_Class {
4
\* Third parties integration
5
\*/
6
class Permalink\_Manager\_Third\_Parties {
7
7
8
8
public function \_\_construct() {
9
add\_action('init', array($this, 'init\_hooks'), 99);
10
add\_action('plugins\_loaded', array($this, 'init\_early\_hooks'), 99);
11
}
12
9
add\_action( 'init', array( $this, 'init\_hooks' ), 99 );
10
add\_action( 'plugins\_loaded', array( $this, 'init\_early\_hooks' ), 99 );
11
}
12
13
/\*\*
14
\* Add support for 3rd party plugins using their hooks
15
\*/
13
16
function init\_hooks() {
14
17
global $permalink\_manager\_options;
15
18
16
19
// 0. Stop redirect
17
add\_action('wp', array($this, 'stop\_redirect'), 0);
18
19
// 2. AMP & AMP for WP
20
if(defined('AMP\_QUERY\_VAR')) {
21
add\_filter('permalink\_manager\_detect\_uri', array($this, 'detect\_amp'), 10, 2);
22
add\_filter('request', array($this, 'enable\_amp'), 10, 1);
23
}
24
25
if(defined('AMPFORWP\_AMP\_QUERY\_VAR')) {
26
add\_filter('permalink\_manager\_filter\_query', array($this, 'detect\_amp\_for\_wp'), 5);
20
add\_action( 'wp', array( $this, 'stop\_redirect' ), 0 );
21
22
// 1. AMP
23
if ( defined( 'AMP\_QUERY\_VAR' ) ) {
24
add\_filter( 'permalink\_manager\_detect\_uri', array( $this, 'detect\_amp' ), 10, 2 );
25
add\_filter( 'request', array( $this, 'enable\_amp' ), 10, 1 );
26
}
27
28
// 2. AMP for WP
29
if ( defined( 'AMPFORWP\_AMP\_QUERY\_VAR' ) ) {
30
add\_filter( 'permalink\_manager\_filter\_query', array( $this, 'detect\_amp\_for\_wp' ), 5 );
27
31
}
28
32
29
33
// 4. WooCommerce
30
if(class\_exists('WooCommerce')) {
31
add\_filter('request', array($this, 'woocommerce\_detect'), 20, 1);
32
add\_filter('template\_redirect', array($this, 'woocommerce\_checkout\_fix'), 9);
33
34
if(class\_exists('Permalink\_Manager\_Pro\_Functions')) {
35
if(empty($permalink\_manager\_options\['general'\]\['partial\_disable'\]\['post\_types'\]) || !in\_array('shop\_coupon', $permalink\_manager\_options\['general'\]\['partial\_disable'\]\['post\_types'\])) {
36
if(is\_admin()) {
37
add\_filter('woocommerce\_coupon\_data\_tabs', 'Permalink\_Manager\_Pro\_Functions::woocommerce\_coupon\_tabs');
38
add\_action('woocommerce\_coupon\_data\_panels', 'Permalink\_Manager\_Pro\_Functions::woocommerce\_coupon\_panel');
39
add\_action('woocommerce\_coupon\_options\_save', 'Permalink\_Manager\_Pro\_Functions::woocommerce\_save\_coupon\_uri', 9, 2);
34
if ( class\_exists( 'WooCommerce' ) ) {
35
add\_filter( 'request', array( $this, 'woocommerce\_detect' ), 20, 1 );
36
add\_filter( 'template\_redirect', array( $this, 'woocommerce\_checkout\_fix' ), 9 );
37
38
if ( class\_exists( 'Permalink\_Manager\_Pro\_Functions' ) ) {
39
if ( empty( $permalink\_manager\_options\['general'\]\['partial\_disable'\]\['post\_types'\] ) || ! in\_array( 'shop\_coupon', $permalink\_manager\_options\['general'\]\['partial\_disable'\]\['post\_types'\] ) ) {
40
if ( is\_admin() ) {
41
add\_filter( 'woocommerce\_coupon\_data\_tabs', 'Permalink\_Manager\_Pro\_Functions::woocommerce\_coupon\_tabs' );
42
add\_action( 'woocommerce\_coupon\_data\_panels', 'Permalink\_Manager\_Pro\_Functions::woocommerce\_coupon\_panel' );
43
add\_action( 'woocommerce\_coupon\_options\_save', 'Permalink\_Manager\_Pro\_Functions::woocommerce\_save\_coupon\_uri', 9, 2 );
40
44
}
41
45
42
add\_filter('request', 'Permalink\_Manager\_Pro\_Functions::woocommerce\_detect\_coupon\_code', 1, 1);
43
add\_filter('permalink\_manager\_disabled\_post\_types', 'Permalink\_Manager\_Pro\_Functions::woocommerce\_coupon\_uris', 9, 1);
46
add\_filter( 'request', 'Permalink\_Manager\_Pro\_Functions::woocommerce\_detect\_coupon\_code', 1, 1 );
47
add\_filter( 'permalink\_manager\_disabled\_post\_types', 'Permalink\_Manager\_Pro\_Functions::woocommerce\_coupon\_uris', 9, 1 );
44
48
}
45
49
}
46
50
47
51
// WooCommerce Import/Export
48
add\_filter('woocommerce\_product\_export\_product\_default\_columns', array($this, 'woocommerce\_csv\_custom\_uri\_column'), 9);
49
add\_filter('woocommerce\_product\_export\_product\_column\_custom\_uri', array($this, 'woocommerce\_export\_custom\_uri\_value'), 9, 3);
50
51
add\_filter('woocommerce\_csv\_product\_import\_mapping\_options', array($this, 'woocommerce\_csv\_custom\_uri\_column'), 9);
52
add\_filter('woocommerce\_csv\_product\_import\_mapping\_default\_columns', array($this, 'woocommerce\_csv\_custom\_uri\_column'), 9);
53
add\_action('woocommerce\_product\_import\_inserted\_product\_object', array($this, 'woocommerce\_csv\_import\_custom\_uri'), 9, 2);
54
55
add\_action('woocommerce\_product\_duplicate', array($this, 'woocommerce\_generate\_permalinks\_after\_duplicate'), 9, 2);
56
add\_filter('permalink\_manager\_filter\_default\_post\_uri', array($this, 'woocommerce\_product\_attributes'), 5, 5);
57
58
if(wp\_doing\_ajax() && class\_exists('SitePress')) {
59
add\_filter('permalink\_manager\_filter\_final\_post\_permalink', array($this, 'woocommerce\_translate\_ajax\_fragments\_urls'), 9999, 3);
52
add\_filter( 'woocommerce\_product\_export\_product\_default\_columns', array( $this, 'woocommerce\_csv\_custom\_uri\_column' ), 9 );
53
add\_filter( 'woocommerce\_product\_export\_product\_column\_custom\_uri', array( $this, 'woocommerce\_export\_custom\_uri\_value' ), 9, 3 );
54
55
add\_filter( 'woocommerce\_csv\_product\_import\_mapping\_options', array( $this, 'woocommerce\_csv\_custom\_uri\_column' ), 9 );
56
add\_filter( 'woocommerce\_csv\_product\_import\_mapping\_default\_columns', array( $this, 'woocommerce\_csv\_custom\_uri\_column' ), 9 );
57
add\_action( 'woocommerce\_product\_import\_inserted\_product\_object', array( $this, 'woocommerce\_csv\_import\_custom\_uri' ), 9, 2 );
58
59
add\_action( 'woocommerce\_product\_duplicate', array( $this, 'woocommerce\_generate\_permalinks\_after\_duplicate' ), 9, 2 );
60
add\_filter( 'permalink\_manager\_filter\_default\_post\_uri', array( $this, 'woocommerce\_product\_attributes' ), 5, 5 );
61
62
if ( wp\_doing\_ajax() && class\_exists( 'SitePress' ) ) {
63
add\_filter( 'permalink\_manager\_filter\_final\_post\_permalink', array( $this, 'woocommerce\_translate\_ajax\_fragments\_urls' ), 9999, 3 );
60
64
}
61
65
}
62
66
63
67
// 5. Theme My Login
64
if(class\_exists('Theme\_My\_Login')) {
65
add\_filter('permalink\_manager\_filter\_final\_post\_permalink', array($this, 'tml\_keep\_query\_parameters'), 9, 3);
68
if ( class\_exists( 'Theme\_My\_Login' ) ) {
69
add\_filter( 'permalink\_manager\_filter\_final\_post\_permalink', array( $this, 'tml\_keep\_query\_parameters' ), 9, 3 );
66
70
}
67
71
68
72
// 6. Yoast SEO
69
add\_filter('wpseo\_xml\_sitemap\_post\_url', array($this, 'yoast\_fix\_sitemap\_urls'), 9);
70
if(defined('WPSEO\_VERSION') && version\_compare(WPSEO\_VERSION, '14.0', '>=')) {
71
add\_action('permalink\_manager\_updated\_post\_uri', array($this, 'yoast\_update\_indexable\_permalink'), 10, 3);
72
add\_action('permalink\_manager\_updated\_term\_uri', array($this, 'yoast\_update\_indexable\_permalink'), 10, 3);
73
add\_filter('wpseo\_canonical', array($this, 'yoast\_fix\_canonical'), 10);
74
add\_filter('wpseo\_opengraph\_url', array($this, 'yoast\_fix\_canonical'), 10);
73
add\_filter( 'wpseo\_xml\_sitemap\_post\_url', array( $this, 'yoast\_fix\_sitemap\_urls' ), 9 );
74
if ( defined( 'WPSEO\_VERSION' ) && version\_compare( WPSEO\_VERSION, '14.0', '>=' ) ) {
75
add\_action( 'permalink\_manager\_updated\_post\_uri', array( $this, 'yoast\_update\_indexable\_permalink' ), 10, 3 );
76
add\_action( 'permalink\_manager\_updated\_term\_uri', array( $this, 'yoast\_update\_indexable\_permalink' ), 10, 3 );
77
add\_filter( 'wpseo\_canonical', array( $this, 'yoast\_fix\_canonical' ), 10 );
78
add\_filter( 'wpseo\_opengraph\_url', array( $this, 'yoast\_fix\_canonical' ), 10 );
75
79
}
76
80
77
81
// 7. Breadcrumbs
78
add\_filter('wpseo\_breadcrumb\_links', array($this, 'filter\_breadcrumbs'), 9);
79
add\_filter('rank\_math/frontend/breadcrumb/items', array($this, 'filter\_breadcrumbs'), 9);
80
add\_filter('seopress\_pro\_breadcrumbs\_crumbs', array($this, 'filter\_breadcrumbs'), 9);
81
add\_filter('woocommerce\_get\_breadcrumb', array($this, 'filter\_breadcrumbs'), 9);
82
add\_filter('slim\_seo\_breadcrumbs\_links', array($this, 'filter\_breadcrumbs'), 9);
83
add\_filter('avia\_breadcrumbs\_trail', array($this, 'filter\_breadcrumbs'), 100);
82
add\_filter( 'wpseo\_breadcrumb\_links', array( $this, 'filter\_breadcrumbs' ), 9 );
83
add\_filter( 'rank\_math/frontend/breadcrumb/items', array( $this, 'filter\_breadcrumbs' ), 9 );
84
add\_filter( 'seopress\_pro\_breadcrumbs\_crumbs', array( $this, 'filter\_breadcrumbs' ), 9 );
85
add\_filter( 'woocommerce\_get\_breadcrumb', array( $this, 'filter\_breadcrumbs' ), 9 );
86
add\_filter( 'slim\_seo\_breadcrumbs\_links', array( $this, 'filter\_breadcrumbs' ), 9 );
87
add\_filter( 'avia\_breadcrumbs\_trail', array( $this, 'filter\_breadcrumbs' ), 100 );
84
88
85
89
// 8. WooCommerce Wishlist Plugin
86
if(function\_exists('tinv\_get\_option')) {
87
add\_filter('permalink\_manager\_detect\_uri', array($this, 'ti\_woocommerce\_wishlist\_uris'), 15, 3);
90
if ( function\_exists( 'tinv\_get\_option' ) ) {
91
add\_filter( 'permalink\_manager\_detect\_uri', array( $this, 'ti\_woocommerce\_wishlist\_uris' ), 15, 3 );
88
92
}
89
93
90
94
// 9. Revisionize
91
if(defined('REVISIONIZE\_ROOT')) {
92
add\_action('revisionize\_after\_create\_revision', array($this, 'revisionize\_keep\_post\_uri'), 9, 2);
93
add\_action('revisionize\_before\_publish', array($this,'revisionize\_clone\_uri'), 9, 2);
95
if ( defined( 'REVISIONIZE\_ROOT' ) ) {
96
add\_action( 'revisionize\_after\_create\_revision', array( $this, 'revisionize\_keep\_post\_uri' ), 9, 2 );
97
add\_action( 'revisionize\_before\_publish', array( $this, 'revisionize\_clone\_uri' ), 9, 2 );
94
98
}
95
99
96
100
// 10. WP All Import
97
if(class\_exists('PMXI\_Plugin') && (!empty($permalink\_manager\_options\['general'\]\['pmxi\_support'\]))) {
98
add\_action('pmxi\_extend\_options\_featured', array($this, 'wpaiextra\_uri\_display'), 9, 2);
99
add\_filter('pmxi\_options\_options', array($this, 'wpai\_api\_options'));
100
add\_filter('pmxi\_addons', array($this, 'wpai\_api\_register'));
101
add\_filter('wp\_all\_import\_addon\_parse', array($this, 'wpai\_api\_parse'));
102
add\_filter('wp\_all\_import\_addon\_import', array($this, 'wpai\_api\_import'));
103
104
add\_action('pmxi\_saved\_post', array($this, 'wpai\_save\_redirects'));
105
106
add\_action('pmxi\_after\_xml\_import', array($this, 'wpai\_schedule\_regenerate\_uris\_after\_xml\_import'), 10, 1);
107
add\_action('wpai\_regenerate\_uris\_after\_import\_event', array($this, 'wpai\_regenerate\_uris\_after\_import'), 10, 1);
101
if ( class\_exists( 'PMXI\_Plugin' ) && ( ! empty( $permalink\_manager\_options\['general'\]\['pmxi\_support'\] ) ) ) {
102
add\_action( 'pmxi\_extend\_options\_featured', array( $this, 'wpaiextra\_uri\_display' ), 9, 2 );
103
add\_filter( 'pmxi\_options\_options', array( $this, 'wpai\_api\_options' ) );
104
add\_filter( 'pmxi\_addons', array( $this, 'wpai\_api\_register' ) );
105
add\_filter( 'wp\_all\_import\_addon\_parse', array( $this, 'wpai\_api\_parse' ) );
106
add\_filter( 'wp\_all\_import\_addon\_import', array( $this, 'wpai\_api\_import' ) );
107
108
add\_action( 'pmxi\_saved\_post', array( $this, 'wpai\_save\_redirects' ) );
109
110
add\_action( 'pmxi\_after\_xml\_import', array( $this, 'wpai\_schedule\_regenerate\_uris\_after\_xml\_import' ), 10, 1 );
111
add\_action( 'wpai\_regenerate\_uris\_after\_import\_event', array( $this, 'wpai\_regenerate\_uris\_after\_import' ), 10, 1 );
108
112
}
109
113
110
114
// 11. WP All Export
111
if(class\_exists('PMXE\_Plugin') && (!empty($permalink\_manager\_options\['general'\]\['pmxi\_support'\]))) {
112
add\_filter('wp\_all\_export\_available\_sections', array($this, 'wpae\_custom\_uri\_section'), 9);
113
add\_filter('wp\_all\_export\_available\_data', array($this, 'wpae\_custom\_uri\_section\_fields'), 9);
114
add\_filter('wp\_all\_export\_csv\_rows', array($this,'wpae\_export\_custom\_uri'), 10, 2);
115
if ( class\_exists( 'PMXE\_Plugin' ) && ( ! empty( $permalink\_manager\_options\['general'\]\['pmxi\_support'\] ) ) ) {
116
add\_filter( 'wp\_all\_export\_available\_sections', array( $this, 'wpae\_custom\_uri\_section' ), 9 );
117
add\_filter( 'wp\_all\_export\_available\_data', array( $this, 'wpae\_custom\_uri\_section\_fields' ), 9 );
118
add\_filter( 'wp\_all\_export\_csv\_rows', array( $this, 'wpae\_export\_custom\_uri' ), 10, 2 );
115
119
}
116
120
117
121
// 12. Duplicate Post
118
if(defined('DUPLICATE\_POST\_CURRENT\_VERSION')) {
119
add\_action('dp\_duplicate\_post', array($this, 'duplicate\_custom\_uri'), 100, 2);
120
add\_action('dp\_duplicate\_page', array($this, 'duplicate\_custom\_uri'), 100, 2);
122
if ( defined( 'DUPLICATE\_POST\_CURRENT\_VERSION' ) ) {
123
add\_action( 'dp\_duplicate\_post', array( $this, 'duplicate\_custom\_uri' ), 100, 2 );
124
add\_action( 'dp\_duplicate\_page', array( $this, 'duplicate\_custom\_uri' ), 100, 2 );
121
125
}
122
126
123
127
// 13. My Listing by 27collective
124
if(class\_exists('\\MyListing\\Post\_Types')) {
125
add\_filter('permalink\_manager\_filter\_default\_post\_uri', array($this, 'ml\_listing\_custom\_fields'), 5, 5 );
126
add\_action('mylisting/submission/save-listing-data', array($this, 'ml\_set\_listing\_uri'), 100);
127
add\_filter('permalink\_manager\_filter\_query', array($this, 'ml\_detect\_archives'), 1, 2);
128
if ( class\_exists( '\\MyListing\\Post\_Types' ) ) {
129
add\_filter( 'permalink\_manager\_filter\_default\_post\_uri', array( $this, 'ml\_listing\_custom\_fields' ), 5, 5 );
130
add\_action( 'mylisting/submission/save-listing-data', array( $this, 'ml\_set\_listing\_uri' ), 100 );
131
add\_filter( 'permalink\_manager\_filter\_query', array( $this, 'ml\_detect\_archives' ), 1, 2 );
128
132
}
129
133
130
134
// 14. bbPress
131
if(class\_exists('bbPress') && function\_exists('bbp\_get\_edit\_slug')) {
132
add\_filter('permalink\_manager\_endpoints', array($this, 'bbpress\_endpoints'), 9);
133
add\_action('wp', array($this, 'bbpress\_detect\_endpoints'), 0);
135
if ( class\_exists( 'bbPress' ) && function\_exists( 'bbp\_get\_edit\_slug' ) ) {
136
add\_filter( 'permalink\_manager\_endpoints', array( $this, 'bbpress\_endpoints' ), 9 );
137
add\_action( 'wp', array( $this, 'bbpress\_detect\_endpoints' ), 0 );
134
138
}
135
139
136
140
// 15. Dokan
137
if(class\_exists('WeDevs\_Dokan')) {
138
add\_action('wp', array($this, 'dokan\_detect\_endpoints'), 999);
139
add\_filter('permalink\_manager\_endpoints', array($this,'dokan\_endpoints'));
141
if ( class\_exists( 'WeDevs\_Dokan' ) ) {
142
add\_action( 'wp', array( $this, 'dokan\_detect\_endpoints' ), 999 );
143
add\_filter( 'permalink\_manager\_endpoints', array( $this, 'dokan\_endpoints' ) );
140
144
}
141
145
142
146
// 16. GeoDirectory
143
if(class\_exists('GeoDirectory')) {
144
add\_filter('permalink\_manager\_filter\_default\_post\_uri', array($this, 'geodir\_custom\_fields'), 5, 5 );
147
if ( class\_exists( 'GeoDirectory' ) ) {
148
add\_filter( 'permalink\_manager\_filter\_default\_post\_uri', array( $this, 'geodir\_custom\_fields' ), 5, 5 );
145
149
}
146
150
147
151
// 17. BasePress
148
if(class\_exists('Basepress')) {
149
add\_filter('permalink\_manager\_filter\_query', array($this, 'kb\_adjust\_query'), 5, 5);
152
if ( class\_exists( 'Basepress' ) ) {
153
add\_filter( 'permalink\_manager\_filter\_query', array( $this, 'kb\_adjust\_query' ), 5, 5 );
150
154
}
151
155
152
156
// 18. Ultimate Member
153
if(class\_exists('UM') && !(empty($permalink\_manager\_options\['general'\]\['um\_support'\]))) {
154
add\_filter('permalink\_manager\_detect\_uri', array($this, 'um\_detect\_extra\_pages'), 20);
157
if ( class\_exists( 'UM' ) && ! ( empty( $permalink\_manager\_options\['general'\]\['um\_support'\] ) ) ) {
158
add\_filter( 'permalink\_manager\_detect\_uri', array( $this, 'um\_detect\_extra\_pages' ), 20 );
155
159
}
156
160
157
161
// 19. WooCommerce Subscriptions
158
if(class\_exists('WC\_Subscriptions')) {
159
add\_filter('permalink\_manager\_filter\_final\_post\_permalink', array($this, 'fix\_wcs\_subscription\_links'), 10, 3);
160
}
161
}
162
163
/\*\*
164
\* Some of the hooks must be called shortly after all the plugins are loaded
162
if ( class\_exists( 'WC\_Subscriptions' ) ) {
163
add\_filter( 'permalink\_manager\_filter\_final\_post\_permalink', array( $this, 'fix\_wcs\_subscription\_links' ), 10, 3 );
164
}
165
}
166
167
/\*\*
168
\* Some hooks must be called shortly after all the plugins are loaded
165
169
\*/
166
170
public function init\_early\_hooks() {
167
171
// WP Store Locator
168
if(class\_exists('WPSL\_CSV')) {
169
add\_action('added\_post\_meta', array($this, 'wpsl\_regenerate\_after\_import'), 10, 4);
170
add\_action('updated\_post\_meta', array($this, 'wpsl\_regenerate\_after\_import'), 10, 4);
172
if ( class\_exists( 'WPSL\_CSV' ) ) {
173
add\_action( 'added\_post\_meta', array( $this, 'wpsl\_regenerate\_after\_import' ), 10, 4 );
174
add\_action( 'updated\_post\_meta', array( $this, 'wpsl\_regenerate\_after\_import' ), 10, 4 );
171
175
}
172
176
// Woocommerce
173
if(class\_exists('WooCommerce')) {
174
add\_filter('woocommerce\_get\_endpoint\_url', array('Permalink\_Manager\_Core\_Functions', 'control\_trailing\_slashes'), 9);
175
}
176
}
177
178
/\*\*
179
\* 0. Stop redirect
177
if ( class\_exists( 'WooCommerce' ) ) {
178
add\_filter( 'woocommerce\_get\_endpoint\_url', array( 'Permalink\_Manager\_Core\_Functions', 'control\_trailing\_slashes' ), 9 );
179
}
180
}
181
182
/\*\*
183
\* 0. Stop canonical redirect if specific query variables are set
180
184
\*/
181
185
public static function stop\_redirect() {
182
global $wp, $wp\_query, $post;
183
184
if(!empty($wp\_query->query)) {
186
global $wp\_query, $post;
187
188
if ( ! empty( $wp\_query->query ) ) {
185
189
$query\_vars = $wp\_query->query;
186
190
187
191
// WordPress Photo Seller Plugin
188
if(!empty($query\_vars\['image\_id'\]) && !empty($query\_vars\['gallery\_id'\])) {
192
if ( ! empty( $query\_vars\['image\_id'\] ) && ! empty( $query\_vars\['gallery\_id'\] ) ) {
189
193
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
190
}
191
// Ultimate Member
192
else if(!empty($query\_vars\['um\_user'\]) || !empty($query\_vars\['um\_tab'\]) || (!empty($query\_vars\['provider'\]) && !empty($query\_vars\['state'\]))) {
194
} // Ultimate Member
195
else if ( ! empty( $query\_vars\['um\_user'\] ) || ! empty( $query\_vars\['um\_tab'\] ) || ( ! empty( $query\_vars\['provider'\] ) && ! empty( $query\_vars\['state'\] ) ) ) {
193
196
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
194
}
195
// Mailster
196
else if(!empty($query\_vars\['\_mailster\_page'\])) {
197
} // Mailster
198
else if ( ! empty( $query\_vars\['\_mailster\_page'\] ) ) {
197
199
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
198
}
199
// WP Route
200
else if(!empty($query\_vars\['WP\_Route'\])) {
200
} // WP Route
201
else if ( ! empty( $query\_vars\['WP\_Route'\] ) ) {
201
202
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
202
}
203
// WooCommerce Wishlist
204
else if(!empty($query\_vars\['wishlist-action'\])) {
203
} // WooCommerce Wishlist
204
else if ( ! empty( $query\_vars\['wishlist-action'\] ) ) {
205
205
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
206
}
207
// UserPro
208
else if(!empty($query\_vars\['up\_username'\])) {
206
} // UserPro
207
else if ( ! empty( $query\_vars\['up\_username'\] ) ) {
209
208
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
210
}
211
// The Events Calendar
212
else if(!empty($query\_vars\['eventDisplay'\])) {
209
} // The Events Calendar
210
else if ( ! empty( $query\_vars\['eventDisplay'\] ) ) {
213
211
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
214
}
215
// Groundhogg
216
else if(class\_exists('\\Groundhogg\\Plugin') && function\_exists('\\Groundhogg\\get\_managed\_page\_name')) {
217
$gh\_slug = \\Groundhogg\\get\_managed\_page\_name();
218
219
if(!empty($gh\_slug) && !empty($wp->request) && (strpos($wp->request, $gh\_slug) === 0)) {
220
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
221
}
222
}
223
// MyListing theme
224
else if(!empty($query\_vars\['explore\_tab'\]) || !empty($query\_vars\['explore\_region'\]) || !empty($\_POST\['submit\_job'\])) {
212
} // Groundhogg
213
else if ( class\_exists( '\\Groundhogg\\Plugin' ) && ! empty( $query\_vars\['subpage'\] ) ) {
225
214
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
226
}
227
// GeoDirectory
228
else if(function\_exists('geodir\_location\_page\_id') && !empty($post->ID) && geodir\_location\_page\_id() == $post->ID) {
215
} // MyListing theme
216
else if ( ! empty( $query\_vars\['explore\_tab'\] ) || ! empty( $query\_vars\['explore\_region'\] ) || ! empty( $\_POST\['submit\_job'\] ) ) {
229
217
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
230
}
231
// RankMath Pro
232
else if(isset($query\_vars\['schema-preview'\])) {
218
} // GeoDirectory
219
else if ( function\_exists( 'geodir\_location\_page\_id' ) && ! empty( $post->ID ) && geodir\_location\_page\_id() == $post->ID ) {
233
220
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
234
}
235
// Theme.co - Pro Theme
236
else if(!empty($\_POST\['\_cs\_nonce'\])) {
221
} // RankMath Pro
222
else if ( isset( $query\_vars\['schema-preview'\] ) ) {
237
223
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
238
}
239
// Tutor LMS
240
else if(!empty($query\_vars\['tutor\_dashboard\_page'\])) {
224
} // Theme.co - Pro Theme
225
else if ( ! empty( $\_POST\['\_cs\_nonce'\] ) ) {
241
226
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
242
}
243
// AMP
244
else if(function\_exists('amp\_get\_slug') && array\_key\_exists(amp\_get\_slug(), $query\_vars)) {
227
} // Tutor LMS
228
else if ( ! empty( $query\_vars\['tutor\_dashboard\_page'\] ) ) {
245
229
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
230
} // AMP
231
else if ( function\_exists( 'amp\_get\_slug' ) && array\_key\_exists( amp\_get\_slug(), $query\_vars ) ) {
232
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
246
233
}
247
234
}
248
235
249
236
// WPForo
250
if(defined('WPFORO\_VERSION')) {
251
$forum\_page\_id = get\_option('wpforo\_pageid');
252
253
if(!empty($forum\_page\_id) && !empty($post->ID) && $forum\_page\_id == $post->ID) {
237
if ( defined( 'WPFORO\_VERSION' ) ) {
238
$forum\_page\_id = get\_option( 'wpforo\_pageid' );
239
240
if ( ! empty( $forum\_page\_id ) && ! empty( $post->ID ) && $forum\_page\_id == $post->ID ) {
254
241
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
255
242
}
…
…
258
245
259
246
/\*\*
260
\* 2. AMP hooks (support for older versions)
261
\*/
262
function detect\_amp($uri\_parts, $request\_url) {
263
global $amp\_enabled, $wp;
264
$amp\_query\_var = AMP\_QUERY\_VAR;
265
266
// Check if AMP should be triggered
267
preg\_match("/^(.+?)\\/({$amp\_query\_var})?\\/?$/i", $uri\_parts\['uri'\], $regex\_parts);
268
if(!empty($regex\_parts\[2\])) {
269
$uri\_parts\['uri'\] = $regex\_parts\[1\];
270
$amp\_enabled = true;
247
\* 1A. AMP hooks (support for older versions)
248
\*
249
\* @param array $uri\_parts
250
\* @param string $request\_url
251
\*
252
\* @return array
253
\*/
254
function detect\_amp( $uri\_parts, $request\_url ) {
255
global $amp\_enabled;
256
257
if ( defined( 'AMP\_QUERY\_VAR' ) ) {
258
$amp\_query\_var = AMP\_QUERY\_VAR;
259
260
// Check if AMP should be triggered
261
preg\_match( "/^(.+?)\\/({$amp\_query\_var})?\\/?$/i", $uri\_parts\['uri'\], $regex\_parts );
262
if ( ! empty( $regex\_parts\[2\] ) ) {
263
$uri\_parts\['uri'\] = $regex\_parts\[1\];
264
$amp\_enabled = true;
265
}
271
266
}
272
267
…
…
274
269
}
275
270
276
function enable\_amp($query) {
271
/\*\*
272
\* 1B. AMP hooks
273
\*
274
\* @param array $query
275
\*
276
\* @return array
277
\*/
278
function enable\_amp( $query ) {
277
279
global $amp\_enabled;
278
280
279
if(!empty($amp\_enabled)) {
280
$query\[AMP\_QUERY\_VAR\] = 1;
281
if ( ! empty( $amp\_enabled ) && defined( 'AMP\_QUERY\_VAR' ) ) {
282
$query\[ AMP\_QUERY\_VAR \] = 1;
281
283
}
282
284
…
…
284
286
}
285
287
286
function detect\_amp\_for\_wp($query) {
288
/\*\*
289
\* 2. AMP for WP hooks (support for older versions)
290
\*
291
\* @param array $query
292
\*
293
\* @return array
294
\*/
295
function detect\_amp\_for\_wp( $query ) {
287
296
global $wp\_rewrite, $pm\_query;
288
297
289
$amp\_endpoint = AMPFORWP\_AMP\_QUERY\_VAR;
290
$paged\_endpoint = $wp\_rewrite->pagination\_base;
291
292
if(!empty($pm\_query\['endpoint'\]) && strpos($pm\_query\['endpoint\_value'\], "{$paged\_endpoint}/") !== false) {
293
$paged\_val = preg\_replace("/({$paged\_endpoint}\\/)(\[\\d\]+)/", '$2', $pm\_query\['endpoint\_value'\]);
294
295
if(!empty($paged\_val)) {
296
$query\[$amp\_endpoint\] = 1;
297
$query\['paged'\] = $paged\_val;
298
if ( defined( 'AMPFORWP\_AMP\_QUERY\_VAR' ) ) {
299
$amp\_endpoint = AMPFORWP\_AMP\_QUERY\_VAR;
300
$paged\_endpoint = $wp\_rewrite->pagination\_base;
301
302
if ( ! empty( $pm\_query\['endpoint'\] ) && strpos( $pm\_query\['endpoint\_value'\], "{$paged\_endpoint}/" ) !== false ) {
303
$paged\_val = preg\_replace( "/({$paged\_endpoint}\\/)(\[\\d\]+)/", '$2', $pm\_query\['endpoint\_value'\] );
304
305
if ( ! empty( $paged\_val ) ) {
306
$query\[ $amp\_endpoint \] = 1;
307
$query\['paged'\] = $paged\_val;
308
}
298
309
}
299
310
}
…
…
303
314
304
315
/\*\*
305
\* 3. Parse Custom Permalinks import
316
\* 3A. Parse Custom Permalinks import
306
317
\*/
307
318
public static function custom\_permalinks\_uris() {
…
…
310
321
$custom\_permalinks\_uris = array();
311
322
312
// 1. List tags/categories
313
$table = get\_option('custom\_permalink\_table');
314
if($table && is\_array($table)) {
315
foreach ( $table as $permalink => $info ) {
316
$custom\_permalinks\_uris\[\] = array(
317
'id' \=> "tax-" . $info\['id'\],
318
'uri' => trim($permalink, "/")
323
// 1. List tags/categories
324
$table = get\_option( 'custom\_permalink\_table' );
325
if ( $table && is\_array( $table ) ) {
326
foreach ( $table as $permalink => $info ) {
327
$custom\_permalinks\_uris\[\] = array(
328
'id' \=> "tax-" . $info\['id'\],
329
'uri' => trim( $permalink, "/" )
319
330
);
320
}
321
}
322
323
// 2. List posts/pages
324
$query = "SELECT p.ID, m.meta\_value FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON (p.ID = m.post\_id) WHERE m.meta\_key = 'custom\_permalink' AND m.meta\_value != '';";
325
$posts = $wpdb->get\_results($query);
326
foreach($posts as $post) {
327
$custom\_permalinks\_uris\[\] = array(
328
'id' \=> $post->ID,
329
'uri' => trim($post->meta\_value, "/"),
331
}
332
}
333
334
// 2. List posts/pages
335
$query = "SELECT p.ID, m.meta\_value FROM $wpdb->posts AS p LEFT JOIN $wpdb->postmeta AS m ON (p.ID = m.post\_id) WHERE m.meta\_key = 'custom\_permalink' AND m.meta\_value != '';";
336
$posts = $wpdb->get\_results( $query );
337
foreach ( $posts as $post ) {
338
$custom\_permalinks\_uris\[\] = array(
339
'id' \=> $post->ID,
340
'uri' => trim( $post->meta\_value, "/" ),
330
341
);
331
}
342
}
332
343
333
344
return $custom\_permalinks\_uris;
334
345
}
335
346
347
/\*\*
348
\* 3B. Import the URIs from the Custom Permalinks plugin.
349
\*/
336
350
static public function import\_custom\_permalinks\_uris() {
337
351
global $permalink\_manager\_uris, $permalink\_manager\_before\_sections\_html;
…
…
339
353
$custom\_permalinks\_plugin = 'custom-permalinks/custom-permalinks.php';
340
354
341
if(is\_plugin\_active($custom\_permalinks\_plugin) && !empty($\_POST\['disable\_custom\_permalinks'\])) {
342
deactivate\_plugins($custom\_permalinks\_plugin);
355
if ( is\_plugin\_active( $custom\_permalinks\_plugin ) && ! empty( $\_POST\['disable\_custom\_permalinks'\] ) ) {
356
deactivate\_plugins( $custom\_permalinks\_plugin );
343
357
}
344
358
…
…
346
360
$custom\_permalinks\_uris = self::custom\_permalinks\_uris();
347
361
348
if(!empty($custom\_permalinks\_uris) && count($custom\_permalinks\_uris) > 0) {
349
foreach($custom\_permalinks\_uris as $item) {
350
$permalink\_manager\_uris\[$item\['id'\]\] = Permalink\_Manager\_Helper\_Functions::sanitize\_title($item\['uri'\]);
351
}
352
353
$permalink\_manager\_before\_sections\_html .= Permalink\_Manager\_Admin\_Functions::get\_alert\_message(\_\_( '"Custom Permalinks" URIs were imported!', 'permalink-manager' ), 'updated');
354
update\_option('permalink-manager-uris', $permalink\_manager\_uris);
362
if ( ! empty( $custom\_permalinks\_uris ) && count( $custom\_permalinks\_uris ) > 0 ) {
363
foreach ( $custom\_permalinks\_uris as $item ) {
364
$permalink\_manager\_uris\[ $item\['id'\] \] = Permalink\_Manager\_Helper\_Functions::sanitize\_title( $item\['uri'\] );
365
}
366
367
$permalink\_manager\_before\_sections\_html .= Permalink\_Manager\_Admin\_Functions::get\_alert\_message( \_\_( '"Custom Permalinks" URIs were imported!', 'permalink-manager' ), 'updated' );
368
update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
355
369
} else {
356
$permalink\_manager\_before\_sections\_html .= Permalink\_Manager\_Admin\_Functions::get\_alert\_message(\_\_( 'No "Custom Permalinks" URIs were imported!', 'permalink-manager' ), 'error');
357
}
358
}
359
360
/\*\*
361
\* 4. WooCommerce
362
\*/
363
function woocommerce\_detect($query) {
370
$permalink\_manager\_before\_sections\_html .= Permalink\_Manager\_Admin\_Functions::get\_alert\_message( \_\_( 'No "Custom Permalinks" URIs were imported!', 'permalink-manager' ), 'error' );
371
}
372
}
373
374
/\*\*
375
\* 4A. Fix query on WooCommerce shop page & disable the canonical redirect if WooCommerce query variables are set
376
\*/
377
function woocommerce\_detect( $query ) {
364
378
global $woocommerce, $pm\_query;
365
379
366
$shop\_page\_id = get\_option('woocommerce\_shop\_page\_id');
380
$shop\_page\_id = get\_option( 'woocommerce\_shop\_page\_id' );
367
381
368
382
// WPML - translate shop page id
369
$shop\_page\_id = apply\_filters('wpml\_object\_id', $shop\_page\_id, 'page', TRUE);
383
$shop\_page\_id = apply\_filters( 'wpml\_object\_id', $shop\_page\_id, 'page', true );
370
384
371
385
// Fix shop page
372
if(get\_theme\_support('woocommerce') && !empty($pm\_query\['id'\]) && is\_numeric($pm\_query\['id'\]) && $shop\_page\_id == $pm\_query\['id'\]) {
386
if ( get\_theme\_support( 'woocommerce' ) && ! empty( $pm\_query\['id'\] ) && is\_numeric( $pm\_query\['id'\] ) && $shop\_page\_id == $pm\_query\['id'\] ) {
373
387
$query\['post\_type'\] = 'product';
374
unset($query\['pagename'\]);
388
unset( $query\['pagename'\] );
375
389
}
376
390
377
391
// Fix WooCommerce pages
378
if(!empty($woocommerce->query->query\_vars)) {
392
if ( ! empty( $woocommerce->query->query\_vars ) ) {
379
393
$query\_vars = $woocommerce->query->query\_vars;
380
394
381
foreach($query\_vars as $key => $val) {
382
if(isset($query\[$key\])) {
383
$woocommerce\_page = true;
395
foreach ( $query\_vars as $key => $val ) {
396
if ( isset( $query\[ $key \] ) ) {
384
397
$query\['do\_not\_redirect'\] = 1;
385
398
break;
…
…
391
404
}
392
405
406
/\*\*
407
\* 4B. Redirects the user from the Shop archive to the Shop page if the user is not searching for anything
408
\* Disable canonical redirect on "thank you" & another WooCommerce pages
409
\*/
393
410
function woocommerce\_checkout\_fix() {
394
411
global $wp\_query, $pm\_query, $permalink\_manager\_options;
395
412
396
413
// Redirect from Shop archive to selected page
397
if(is\_shop() && empty($pm\_query\['id'\])) {
398
$redirect\_mode = (!empty($permalink\_manager\_options\['general'\]\['redirect'\])) ? $permalink\_manager\_options\['general'\]\['redirect'\] : false;
399
$redirect\_shop = apply\_filters('permalink\_manager\_redirect\_shop\_archive', false);
400
$shop\_page \= get\_option('woocommerce\_shop\_page\_id');
401
402
if($redirect\_mode && $redirect\_shop && $shop\_page && empty($wp\_query->query\_vars\['s'\])) {
403
$shop\_url = get\_permalink($shop\_page);
404
wp\_safe\_redirect($shop\_url, $redirect\_mode);
414
if ( is\_shop() && empty( $pm\_query\['id'\] ) ) {
415
$redirect\_mode = ( ! empty( $permalink\_manager\_options\['general'\]\['redirect'\] ) ) ? $permalink\_manager\_options\['general'\]\['redirect'\] : false;
416
$redirect\_shop = apply\_filters( 'permalink\_manager\_redirect\_shop\_archive', false );
417
$shop\_page = get\_option( 'woocommerce\_shop\_page\_id' );
418
419
if ( $redirect\_mode && $redirect\_shop && $shop\_page && empty( $wp\_query->query\_vars\['s'\] ) ) {
420
$shop\_url = get\_permalink( $shop\_page );
421
wp\_safe\_redirect( $shop\_url, $redirect\_mode );
405
422
exit();
406
423
}
407
424
}
408
425
409
// Do not redirect "thank you" & another WooCommerce pages
410
if(is\_checkout() || (function\_exists('is\_wc\_endpoint\_url') && is\_wc\_endpoint\_url())) {
426
if ( is\_checkout() || ( function\_exists( 'is\_wc\_endpoint\_url' ) && is\_wc\_endpoint\_url() ) ) {
411
427
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
412
428
}
413
429
}
414
430
415
function woocommerce\_generate\_permalinks\_after\_duplicate($new\_product, $old\_product) {
431
/\*\*
432
\* 4C. Generate a new custom permalink for duplicated product
433
\*
434
\* @param WC\_Product $new\_product The new product object.
435
\* @param WC\_Product $old\_product The product that was duplicated.
436
\*/
437
function woocommerce\_generate\_permalinks\_after\_duplicate( $new\_product, $old\_product ) {
438
if ( ! empty( $new\_product ) ) {
439
$product\_id = $new\_product->get\_id();
440
441
// Ignore variations
442
if ( $new\_product->get\_type() !== 'variation' ) {
443
$custom\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri( $product\_id, false, true );
444
445
Permalink\_Manager\_URI\_Functions::save\_single\_uri( $product\_id, $custom\_uri, false, true );
446
}
447
}
448
}
449
450
/\*\*
451
\* 4D. If the URI contains %pa\_attribute\_name% tag, replace it with the value of the attribute
452
\*
453
\* @param string $default\_uri The default custom permalink that WordPress would use for the post.
454
\* @param string $slug The post slug.
455
\* @param WP\_Post $post The post object.
456
\* @param string $post\_name The post slug.
457
\* @param bool $native\_uri true if the URI is a native URI, false if it's a custom URI
458
\*
459
\* @return string The default custom permalink
460
\*/
461
function woocommerce\_product\_attributes( $default\_uri, $slug, $post, $post\_name, $native\_uri ) {
462
// Do not affect native URIs
463
if ( $native\_uri ) {
464
return $default\_uri;
465
}
466
467
// Use only for products
468
if ( empty( $post->post\_type ) || $post->post\_type !== 'product' ) {
469
return $default\_uri;
470
}
471
472
preg\_match\_all( "/%pa\_(.\[^\\%\]+)%/", $default\_uri, $custom\_fields );
473
474
if ( ! empty( $custom\_fields\[1\] ) ) {
475
$product = wc\_get\_product( $post->ID );
476
477
foreach ( $custom\_fields\[1\] as $i => $custom\_field ) {
478
$attribute\_name = sanitize\_title( $custom\_field );
479
$attribute\_value = $product->get\_attribute( $attribute\_name );
480
481
$default\_uri = str\_replace( $custom\_fields\[0\]\[ $i \], Permalink\_Manager\_Helper\_Functions::sanitize\_title( $attribute\_value ), $default\_uri );
482
}
483
}
484
485
return $default\_uri;
486
}
487
488
/\*\*
489
\* 4E. Check the current request is a WooCommerce AJAX request. If it is, check the translated page's URL should be returned
490
\*
491
\* @param string $permalink The full URL of the post
492
\* @param WP\_Post $post The post object
493
\* @param string $old\_permalink The original URL of the post.
494
\*
495
\* @return string The permalink is being returned.
496
\*/
497
function woocommerce\_translate\_ajax\_fragments\_urls( $permalink, $post, $old\_permalink ) {
498
// Use it only if the permalinks are different
499
if ( $permalink == $old\_permalink || $post->post\_type !== 'page' ) {
500
return $permalink;
501
}
502
503
// A. Native WooCommerce AJAX events
504
if ( ! empty( $\_REQUEST\['wc-ajax'\] ) ) {
505
$action = sanitize\_title( $\_REQUEST\['wc-ajax'\] );
506
} // B. Shoptimizer theme
507
else if ( ! empty( $\_REQUEST\['action'\] ) ) {
508
$action = sanitize\_title( $\_REQUEST\['action'\] );
509
}
510
511
// Allowed action names
512
$allowed\_actions = array( 'shoptimizer\_pdp\_ajax\_atc', 'get\_refreshed\_fragments' );
513
514
if ( ! empty( $action ) && in\_array( $action, $allowed\_actions ) ) {
515
$translated\_post\_id = apply\_filters( 'wpml\_object\_id', $post->ID, 'page' );
516
$permalink = ( $translated\_post\_id !== $post->ID ) ? get\_permalink( $translated\_post\_id ) : $permalink;
517
}
518
519
return $permalink;
520
}
521
522
/\*\*
523
\* 4FA. Add a new column to the WooCommerce CSV Import/Export tool
524
\*
525
\* @param array $columns The array of columns to be displayed.
526
\*
527
\* @return array The $columns array.
528
\*/
529
function woocommerce\_csv\_custom\_uri\_column( $columns ) {
530
if ( ! is\_array( $columns ) ) {
531
return $columns;
532
}
533
534
$label = \_\_( 'Custom URI', 'permalink-manager' );
535
$key = 'custom\_uri';
536
537
if ( current\_filter() == 'woocommerce\_csv\_product\_import\_mapping\_default\_columns' ) {
538
$columns\[ $label \] = $key;
539
} else {
540
$columns\[ $key \] = $label;
541
}
542
543
return $columns;
544
}
545
546
/\*\*
547
\* 4FB. Return the custom permalink of the product if it exists, otherwise return the default URI
548
\*
549
\* @param string $value The value of the column.
550
\* @param WC\_Product $product The product object.
551
\* @param mixed $column\_id The column ID.
552
\*
553
\* @return string The custom permalink or default permalink
554
\*/
555
function woocommerce\_export\_custom\_uri\_value( $value, $product, $column\_id ) {
556
if ( empty( $value ) && ! empty( $product ) ) {
557
$product\_id = $product->get\_id();
558
559
// Get custom permalink or default permalink
560
$value = Permalink\_Manager\_URI\_Functions\_Post::get\_post\_uri( $product\_id );
561
}
562
563
return $value;
564
}
565
566
/\*\*
567
\* 4FC. Set the custom URI for the product using the value from CSV file, if not set use the default permalink
568
\*
569
\* @param WC\_Product $product The product object.
570
\* @param array $data The data array for the current row being imported.
571
\*/
572
function woocommerce\_csv\_import\_custom\_uri( $product, $data ) {
416
573
global $permalink\_manager\_uris;
417
574
418
if(!empty($new\_product)) {
419
$product\_id = $new\_product->get\_id();
575
if ( ! empty( $product ) ) {
576
$product\_id = $product->get\_id();
420
577
421
578
// Ignore variations
422
if($new\_product->get\_type() !== 'variation') {
423
$custom\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri($product\_id, false, true);
424
425
Permalink\_Manager\_URI\_Functions::save\_single\_uri($product\_id, $custom\_uri, false, true);
426
}
427
}
428
}
429
430
function woocommerce\_product\_attributes($default\_uri, $slug, $post, $post\_name, $native\_uri) {
431
// Do not affect native URIs
432
if($native\_uri == true) { return $default\_uri; }
433
434
// Use only for products
435
if(empty($post->post\_type) || $post->post\_type !== 'product') { return $default\_uri; }
436
437
preg\_match\_all("/%pa\_(.\[^\\%\]+)%/", $default\_uri, $custom\_fields);
438
439
if(!empty($custom\_fields\[1\])) {
440
$product = wc\_get\_product($post->ID);
441
442
foreach($custom\_fields\[1\] as $i => $custom\_field) {
443
$attribute\_name = sanitize\_title($custom\_field);
444
$attribute\_value = $product->get\_attribute($attribute\_name);
445
446
$default\_uri = str\_replace($custom\_fields\[0\]\[$i\], Permalink\_Manager\_Helper\_Functions::sanitize\_title($attribute\_value), $default\_uri);
447
}
448
}
449
450
return $default\_uri;
451
}
452
453
function woocommerce\_translate\_ajax\_fragments\_urls($permalink, $post, $old\_permalink) {
454
// Use it only if the permalinks are different
455
if($permalink == $old\_permalink || $post->post\_type !== 'page') {
456
return $permalink;
457
}
458
459
// A. Native WooCommerce AJAX events
460
if(!empty($\_REQUEST\['wc-ajax'\])) {
461
$action = sanitize\_title($\_REQUEST\['wc-ajax'\]);
462
}
463
// B. Shoptimizer theme
464
else if(!empty($\_REQUEST\['action'\])) {
465
$action = sanitize\_title($\_REQUEST\['action'\]);
466
}
467
468
// Allowed action names
469
$allowed\_actions = array('shoptimizer\_pdp\_ajax\_atc', 'get\_refreshed\_fragments');
470
471
if(in\_array($action, $allowed\_actions)) {
472
$translated\_post\_id = apply\_filters('wpml\_object\_id', $post->ID, 'page');
473
$permalink = ($translated\_post\_id !== $post->ID) ? get\_permalink($translated\_post\_id) : $permalink;
474
}
475
476
return $permalink;
477
}
478
479
/\*\*
480
\* 4A. WooCommerce CSV Import/Export
481
\*/
482
function woocommerce\_csv\_custom\_uri\_column($columns) {
483
if(!is\_array($columns)) { return $columns; }
484
485
$label = \_\_('Custom URI', 'permalink-manager');
486
$key = 'custom\_uri';
487
488
if(current\_filter() == 'woocommerce\_csv\_product\_import\_mapping\_default\_columns') {
489
$columns\[$label\] = $key;
490
} else {
491
$columns\[$key\] = $label;
492
}
493
494
return $columns;
495
}
496
497
function woocommerce\_export\_custom\_uri\_value($value, $product, $column\_id) {
498
if(empty($value) && !empty($product)) {
499
$product\_id = $product->get\_id();
500
501
// Get custom permalink or default permalink
502
$value = Permalink\_Manager\_URI\_Functions\_Post::get\_post\_uri($product\_id);
503
}
504
505
return $value;
506
}
507
508
function woocommerce\_csv\_import\_custom\_uri($product, $data) {
509
global $permalink\_manager\_uris;
510
511
if(!empty($product)) {
512
$product\_id = $product->get\_id();
513
514
// Ignore variations
515
if($product->get\_type() == 'variation') {
579
if ( $product->get\_type() == 'variation' ) {
516
580
return;
517
581
}
518
582
519
583
// A. Use default permalink if "Custom URI" is not set and did not exist before
520
if(empty($permalink\_manager\_uris\[$product\_id\]) && empty($data\['custom\_uri'\])) {
521
$custom\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri($product\_id, false, true);
522
} else if(!empty($data\['custom\_uri'\])) {
523
$custom\_uri = Permalink\_Manager\_Helper\_Functions::sanitize\_title($data\['custom\_uri'\]);
584
if ( empty( $permalink\_manager\_uris\[ $product\_id \] ) && empty( $data\['custom\_uri'\] ) ) {
585
$custom\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri( $product\_id, false, true );
586
} else if ( ! empty( $data\['custom\_uri'\] ) ) {
587
$custom\_uri = Permalink\_Manager\_Helper\_Functions::sanitize\_title( $data\['custom\_uri'\] );
524
588
} else {
525
589
return;
526
590
}
527
591
528
Permalink\_Manager\_URI\_Functions::save\_single\_uri($product\_id, $custom\_uri, false, true);
529
}
530
}
531
532
/\*\*
533
\* 5. Theme My Login
534
\*/
535
function tml\_keep\_query\_parameters($permalink, $post, $old\_permalink) {
592
Permalink\_Manager\_URI\_Functions::save\_single\_uri( $product\_id, $custom\_uri, false, true );
593
}
594
}
595
596
/\*\*
597
\* 5. Keep the unique Theme My Login query parameters in the final custom permalink
598
\*
599
\* @param string $permalink
600
\* @param WP\_Post $post
601
\* @param string $old\_permalink
602
\*
603
\* @return string
604
\*/
605
function tml\_keep\_query\_parameters( $permalink, $post, $old\_permalink ) {
536
606
// Get the query string from old permalink
537
$get\_parameters = (($pos = strpos($old\_permalink, "?")) !== false) ? substr($old\_permalink, $pos) : "";
607
$get\_parameters = ( ( $pos = strpos( $old\_permalink, "?" ) ) !== false ) ? substr( $old\_permalink, $pos ) : "";
538
608
539
609
return $permalink . $get\_parameters;
…
…
541
611
542
612
/\*\*
543
\* 6. Yoast SEO hooks
544
\*/
545
function yoast\_fix\_sitemap\_urls($permalink) {
546
if(class\_exists('WPSEO\_Utils')) {
547
$home\_url = WPSEO\_Utils::home\_url();
548
$home\_protocol = parse\_url($home\_url, PHP\_URL\_SCHEME);
549
550
$permalink = preg\_replace("/^http(s)?/", $home\_protocol, $permalink);
613
\* 6A. Get the HTTP protocol of the home URL and use it in Yoast SEO sitemap permalinks
614
\*
615
\* @param string $permalink The permalink in the sitemap
616
\*
617
\* @return string The sitemap's permalink
618
\*/
619
function yoast\_fix\_sitemap\_urls( $permalink ) {
620
if ( class\_exists( 'WPSEO\_Utils' ) ) {
621
$home\_url = WPSEO\_Utils::home\_url();
622
$home\_protocol = parse\_url( $home\_url, PHP\_URL\_SCHEME );
623
624
$permalink = preg\_replace( "/^http(s)?/", $home\_protocol, $permalink );
551
625
}
552
626
…
…
554
628
}
555
629
556
function yoast\_update\_indexable\_permalink($element\_id, $new\_uri, $old\_uri) {
630
/\*\*
631
\* 6B. Update the permalink in the Yoast SEO indexable table when the permalink is changed
632
\*
633
\* @param int $element\_id The ID of the post/term element that was updated.
634
\* @param string $new\_uri The new URI of the element.
635
\* @param string $old\_uri The old URI of the element.
636
\*/
637
function yoast\_update\_indexable\_permalink( $element\_id, $new\_uri, $old\_uri ) {
557
638
global $wpdb;
558
639
559
if(!empty($new\_uri) && !empty($old\_uri) && $new\_uri !== $old\_uri) {
560
if(current\_filter() == 'permalink\_manager\_updated\_term\_uri') {
561
$permalink \= get\_term\_link((int) $element\_id);
640
if ( ! empty( $new\_uri ) && ! empty( $old\_uri ) && $new\_uri !== $old\_uri ) {
641
if ( current\_filter() == 'permalink\_manager\_updated\_term\_uri' ) {
642
$permalink = get\_term\_link( (int) $element\_id );
562
643
$object\_type = 'term';
563
644
} else {
564
$permalink \= get\_permalink($element\_id);
645
$permalink = get\_permalink( $element\_id );
565
646
$object\_type = 'post';
566
647
}
567
648
568
if(!empty($permalink)) {
569
$permalink\_hash = strlen($permalink) . ':' . md5($permalink);
570
$wpdb->update("{$wpdb->prefix}yoast\_indexable", array('permalink' => $permalink, 'permalink\_hash' => $permalink\_hash), array('object\_id' => $element\_id, 'object\_type' => $object\_type), array('%s', '%s'), array('%d', '%s'));
571
}
572
}
573
}
574
575
function yoast\_fix\_canonical($url) {
649
if ( ! empty( $permalink ) ) {
650
$permalink\_hash = strlen( $permalink ) . ':' . md5( $permalink );
651
$wpdb->update( "{$wpdb->prefix}yoast\_indexable", array( 'permalink' => $permalink, 'permalink\_hash' => $permalink\_hash ), array( 'object\_id' => $element\_id, 'object\_type' => $object\_type ), array( '%s', '%s' ), array( '%d', '%s' ) );
652
}
653
}
654
}
655
656
/\*\*
657
\* 6C. Filter the canonical permalink used by SEO using 'wpseo\_canonical' & 'wpseo\_opengraph\_url' hooks
658
\*
659
\* @param string $url The canonical URL that Yoast SEO has generated.
660
\*
661
\* @return string the URL.
662
\*/
663
function yoast\_fix\_canonical( $url ) {
576
664
global $pm\_query, $wp\_rewrite;
577
665
578
if(!empty($pm\_query\['id'\])) {
666
if ( ! empty( $pm\_query\['id'\] ) ) {
579
667
$element = get\_queried\_object();
580
668
581
if(!empty($element->ID) && !empty($element->post\_type)) {
582
$new\_url = get\_permalink($element->ID);
669
if ( ! empty( $element->ID ) && ! empty( $element->post\_type ) ) {
670
$new\_url = get\_permalink( $element->ID );
583
671
584
672
// Do not filter if custom canonical URL is set
585
$yoast\_canonical\_url = get\_post\_meta($element->ID, '\_yoast\_wpseo\_canonical', true);
586
if(!empty($yoast\_canonical\_url)) { return $url; }
587
588
if(is\_home()) {
589
$paged = (get\_query\_var('paged')) ? get\_query\_var('paged') : 1;
590
$new\_url = ($paged > 1) ? sprintf('%s/%s/%d', trim($new\_url, '/'), $wp\_rewrite->pagination\_base, $paged) : $new\_url;
673
$yoast\_canonical\_url = get\_post\_meta( $element->ID, '\_yoast\_wpseo\_canonical', true );
674
if ( ! empty( $yoast\_canonical\_url ) ) {
675
return $url;
676
}
677
678
if ( is\_home() ) {
679
$paged = ( get\_query\_var( 'paged' ) ) ? get\_query\_var( 'paged' ) : 1;
680
$new\_url = ( $paged > 1 ) ? sprintf( '%s/%s/%d', trim( $new\_url, '/' ), $wp\_rewrite->pagination\_base, $paged ) : $new\_url;
591
681
} else {
592
$paged \= (get\_query\_var('page')) ? get\_query\_var('page') : 1;
593
$new\_url = ($paged > 1) ? sprintf('%s/%d', trim($new\_url, '/'), $paged) : $new\_url;
594
}
595
} else if(!empty($element->taxonomy) && !empty($element->term\_id)) {
596
$new\_url = get\_term\_link($element, $element->taxonomy);
682
$paged = ( get\_query\_var( 'page' ) ) ? get\_query\_var( 'page' ) : 1;
683
$new\_url = ( $paged > 1 ) ? sprintf( '%s/%d', trim( $new\_url, '/' ), $paged ) : $new\_url;
684
}
685
} else if ( ! empty( $element->taxonomy ) && ! empty( $element->term\_id ) ) {
686
$new\_url = get\_term\_link( $element, $element->taxonomy );
597
687
598
688
// Do not filter if custom canonical URL is set
599
if(class\_exists('WPSEO\_Taxonomy\_Meta')) {
600
$yoast\_canonical\_url = WPSEO\_Taxonomy\_Meta::get\_term\_meta($element, $element->taxonomy, 'canonical' );
601
if(!empty($yoast\_canonical\_url)) { return $url; }
602
}
603
604
$paged = (get\_query\_var('paged')) ? get\_query\_var('paged') : 1;
605
if($paged > 1) {
606
$new\_url = sprintf('%s/%s/%d', trim($new\_url, '/'), $wp\_rewrite->pagination\_base, $paged);
607
}
608
}
609
610
$url = (!empty($new\_url)) ? $new\_url : $url;
611
$url = Permalink\_Manager\_Core\_Functions::control\_trailing\_slashes($url);
689
if ( class\_exists( 'WPSEO\_Taxonomy\_Meta' ) ) {
690
$yoast\_canonical\_url = WPSEO\_Taxonomy\_Meta::get\_term\_meta( $element, $element->taxonomy, 'canonical' );
691
if ( ! empty( $yoast\_canonical\_url ) ) {
692
return $url;
693
}
694
}
695
696
$paged = ( get\_query\_var( 'paged' ) ) ? get\_query\_var( 'paged' ) : 1;
697
if ( $paged > 1 ) {
698
$new\_url = sprintf( '%s/%s/%d', trim( $new\_url, '/' ), $wp\_rewrite->pagination\_base, $paged );
699
}
700
}
701
702
$url = ( ! empty( $new\_url ) ) ? $new\_url : $url;
703
$url = Permalink\_Manager\_Core\_Functions::control\_trailing\_slashes( $url );
612
704
}
613
705
…
…
616
708
617
709
/\*\*
618
\* 7. Breadcrumbs
619
\*/
620
function filter\_breadcrumbs($links) {
621
// Get post type permastructure settings
622
global $permalink\_manager\_uris, $permalink\_manager\_options, $post, $wpdb, $wp, $wp\_current\_filter, $wp\_post\_types;
623
624
// Check if the filter should be activated
625
if(empty($permalink\_manager\_options\['general'\]\['yoast\_breadcrumbs'\]) || empty($permalink\_manager\_uris)) { return $links; }
626
627
// Get current post/page/term (if available)
628
$queried\_element = get\_queried\_object();
629
if(!empty($queried\_element->ID)) {
630
$element\_id = $queried\_element->ID;
631
} else if(!empty($queried\_element->term\_id)) {
632
$element\_id = "tax-{$queried\_element->term\_id}";
633
} else if(defined('REST\_REQUEST') && !empty($post->ID)) {
710
\* 7. Filter the breadcrumbs array to match the structure of currently requested URL
711
\*
712
\* @param array $links The current breadcrumb links.
713
\*
714
\* @return array The $links array.
715
\*/
716
function filter\_breadcrumbs( $links ) {
717
// Get post type permastructure settings
718
global $permalink\_manager\_uris, $permalink\_manager\_options, $post, $wpdb, $wp, $wp\_current\_filter;
719
720
// Check if the filter should be activated
721
if ( empty( $permalink\_manager\_options\['general'\]\['yoast\_breadcrumbs'\] ) || empty( $permalink\_manager\_uris ) ) {
722
return $links;
723
}
724
725
// Get current post/page/term (if available)
726
$queried\_element = get\_queried\_object();
727
if ( ! empty( $queried\_element->ID ) ) {
728
$element\_id = $queried\_element->ID;
729
} else if ( ! empty( $queried\_element->term\_id ) ) {
730
$element\_id = "tax-{$queried\_element->term\_id}";
731
} else if ( defined( 'REST\_REQUEST' ) && ! empty( $post->ID ) ) {
634
732
$element\_id = $post->ID;
635
733
}
636
734
637
// Get the custom permalink (if available) or the current request URL (if unavailable)
638
if(!empty($element\_id) && !empty($permalink\_manager\_uris\[$element\_id\])) {
639
$custom\_uri = preg\_replace("/(\[^\\/\]+)$/", '', $permalink\_manager\_uris\[$element\_id\]);
640
} else {
641
$custom\_uri = trim(preg\_replace("/(\[^\\/\]+)$/", '', $wp->request), "/");
642
}
643
644
$all\_uris \= array\_flip($permalink\_manager\_uris);
645
$custom\_uri\_parts = explode('/', trim($custom\_uri));
646
$breadcrumbs = array();
647
$snowball = '';
648
$available\_taxonomies = Permalink\_Manager\_Helper\_Functions::get\_taxonomies\_array(null, null, false, true);
649
$available\_post\_types \= Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array(null, null, true);
650
$available\_post\_types\_archive = Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array('archive\_slug', null, true);
651
$current\_filter = end($wp\_current\_filter);
652
653
// Get Yoast Meta (the breadcrumbs titles can be changed in Yoast metabox)
654
$yoast\_meta\_terms = get\_option('wpseo\_taxonomy\_meta');
655
656
// Get internal breadcrumb elements
657
foreach($custom\_uri\_parts as $slug) {
658
if(empty($slug)) { continue; }
659
660
$snowball = (empty($snowball)) ? $slug : "{$snowball}/{$slug}";
661
662
// 1A. Try to match any custom URI
663
if($snowball) {
664
$uri = trim($snowball, "/");
665
$element = (!empty($all\_uris\[$uri\])) ? $all\_uris\[$uri\] : false;
666
667
if(!empty($element) && strpos($element, 'tax-') !== false) {
668
$element\_id = intval(preg\_replace("/\[^0-9\]/", "", $element));
669
$element = get\_term($element\_id);
670
} else if(is\_numeric($element)) {
671
$element = get\_post($element);
672
}
673
}
674
675
// 1B. Try to get term
676
if(empty($element) && !empty($available\_taxonomies)) {
677
$sql = sprintf("SELECT t.term\_id, t.name, tt.taxonomy FROM {$wpdb->terms} AS t LEFT JOIN {$wpdb->term\_taxonomy} AS tt ON t.term\_id = tt.term\_id WHERE slug = '%s' AND tt.taxonomy IN ('%s') LIMIT 1", esc\_sql($slug), implode("','", array\_keys($available\_taxonomies)));
678
679
$element = $wpdb->get\_row($sql);
680
}
681
682
// 1C. Try to get page/post
683
if(empty($element) && !empty($available\_post\_types)) {
684
$sql = sprintf("SELECT ID, post\_title, post\_type FROM {$wpdb->posts} WHERE post\_name = '%s' AND post\_status = 'publish' AND post\_type IN ('%s') AND post\_type != 'attachment' LIMIT 1", esc\_sql($slug), implode("','", array\_keys($available\_post\_types)));
685
686
$element = $wpdb->get\_row($sql);
687
}
688
689
// 1D. Try to get post type archive
690
if(empty($element) && !empty($available\_post\_types\_archive) && in\_array($snowball, $available\_post\_types\_archive)) {
691
$post\_type\_slug = array\_search($snowball, $available\_post\_types\_archive);
692
$element \= get\_post\_type\_object($post\_type\_slug);
693
}
694
695
// 2A. When the term is found, we can add it to the breadcrumbs
696
if(!empty($element->term\_id)) {
697
$term\_id = apply\_filters('wpml\_object\_id', $element->term\_id, $element->taxonomy, true);
698
$term \= ($element->term\_id !== $term\_id) ? get\_term($term\_id) : $element;
735
// Get the custom permalink (if available) or the current request URL (if unavailable)
736
if ( ! empty( $element\_id ) && ! empty( $permalink\_manager\_uris\[ $element\_id \] ) ) {
737
$custom\_uri = preg\_replace( "/(\[^\\/\]+)$/", '', $permalink\_manager\_uris\[ $element\_id \] );
738
} else {
739
$custom\_uri = trim( preg\_replace( "/(\[^\\/\]+)$/", '', $wp->request ), "/" );
740
}
741
742
$all\_uris = array\_flip( $permalink\_manager\_uris );
743
$custom\_uri\_parts = explode( '/', trim( $custom\_uri ) );
744
$breadcrumbs = array();
745
$snowball \= '';
746
$available\_taxonomies = Permalink\_Manager\_Helper\_Functions::get\_taxonomies\_array( null, null, true );
747
$available\_post\_types = Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array( null, null, true );
748
$available\_post\_types\_archive = Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array( 'archive\_slug', null, true );
749
$current\_filter = end( $wp\_current\_filter );
750
751
// Get Yoast Meta (the breadcrumbs titles can be changed in Yoast metabox)
752
$yoast\_meta\_terms = get\_option( 'wpseo\_taxonomy\_meta' );
753
754
// Get internal breadcrumb elements
755
foreach ( $custom\_uri\_parts as $slug ) {
756
if ( empty( $slug ) ) {
757
continue;
758
}
759
760
$snowball = ( empty( $snowball ) ) ? $slug : "{$snowball}/{$slug}";
761
762
// 1A. Try to match any custom URI
763
$uri = trim( $snowball, "/" );
764
$element = ( ! empty( $all\_uris\[ $uri \] ) ) ? $all\_uris\[ $uri \] : false;
765
766
if ( ! empty( $element ) && strpos( $element, 'tax-' ) !== false ) {
767
$element\_id = intval( preg\_replace( "/\[^0-9\]/", "", $element ) );
768
$element = get\_term( $element\_id );
769
} else if ( is\_numeric( $element ) ) {
770
$element = get\_post( $element );
771
}
772
773
// 1B. Try to get term
774
if ( empty( $element ) && ! empty( $available\_taxonomies ) ) {
775
$sql = sprintf( "SELECT t.term\_id, t.name, tt.taxonomy FROM {$wpdb->terms} AS t LEFT JOIN {$wpdb->term\_taxonomy} AS tt ON t.term\_id = tt.term\_id WHERE slug = '%s' AND tt.taxonomy IN ('%s') LIMIT 1", esc\_sql( $slug ), implode( "','", array\_keys( $available\_taxonomies ) ) );
776
777
$element = $wpdb->get\_row( $sql );
778
}
779
780
// 1C. Try to get page/post
781
if ( empty( $element ) && ! empty( $available\_post\_types ) ) {
782
$sql = sprintf( "SELECT ID, post\_title, post\_type FROM {$wpdb->posts} WHERE post\_name = '%s' AND post\_status = 'publish' AND post\_type IN ('%s') AND post\_type != 'attachment' LIMIT 1", esc\_sql( $slug ), implode( "','", array\_keys( $available\_post\_types ) ) );
783
784
$element = $wpdb->get\_row( $sql );
785
}
786
787
// 1D. Try to get post type archive
788
if ( empty( $element ) && ! empty( $available\_post\_types\_archive ) && in\_array( $snowball, $available\_post\_types\_archive ) ) {
789
$post\_type\_slug = array\_search( $snowball, $available\_post\_types\_archive );
790
$element = get\_post\_type\_object( $post\_type\_slug );
791
}
792
793
// 2A. When the term is found, we can add it to the breadcrumbs
794
if ( ! empty( $element->term\_id ) ) {
795
$term\_id = apply\_filters( 'wpml\_object\_id', $element->term\_id, $element->taxonomy, true );
796
$term = ( $element->term\_id !== $term\_id ) ? get\_term( $term\_id ) : $element;
699
797
700
798
// Alternative title
701
if($current\_filter == 'wpseo\_breadcrumb\_links') {
702
$alt\_title = (!empty($yoast\_meta\_terms\[$term->taxonomy\]\[$term->term\_id\]\['wpseo\_bctitle'\])) ? $yoast\_meta\_terms\[$term->taxonomy\]\[$term->term\_id\]\['wpseo\_bctitle'\] : '';
703
} else if($current\_filter == 'seopress\_pro\_breadcrumbs\_crumbs') {
704
$alt\_title = get\_term\_meta($term->term\_id, '\_seopress\_robots\_breadcrumbs', true);
705
} else if($current\_filter == 'rank\_math/frontend/breadcrumb/items') {
706
$alt\_title = get\_term\_meta($term->term\_id, 'rank\_math\_breadcrumb\_title', true);
707
}
708
709
$title = (!empty($alt\_title)) ? $alt\_title : $term->name;
710
711
$breadcrumbs\[\] = array(
712
'text' => wp\_strip\_all\_tags($title),
713
'url' => get\_term\_link((int) $term->term\_id, $term->taxonomy),
714
);
715
}
716
// 2B. When the post/page is found, we can add it to the breadcrumbs
717
else if(!empty($element->ID)) {
718
$page\_id = apply\_filters('wpml\_object\_id', $element->ID, $element->post\_type, true);
719
$page = ($element->ID !== $page\_id) ? get\_post($page\_id) : $element;
799
if ( $current\_filter == 'wpseo\_breadcrumb\_links' ) {
800
$alt\_title = ( ! empty( $yoast\_meta\_terms\[ $term->taxonomy \]\[ $term->term\_id \]\['wpseo\_bctitle'\] ) ) ? $yoast\_meta\_terms\[ $term->taxonomy \]\[ $term->term\_id \]\['wpseo\_bctitle'\] : '';
801
} else if ( $current\_filter == 'seopress\_pro\_breadcrumbs\_crumbs' ) {
802
$alt\_title = get\_term\_meta( $term->term\_id, '\_seopress\_robots\_breadcrumbs', true );
803
} else if ( $current\_filter == 'rank\_math/frontend/breadcrumb/items' ) {
804
$alt\_title = get\_term\_meta( $term->term\_id, 'rank\_math\_breadcrumb\_title', true );
805
}
806
807
$title = ( ! empty( $alt\_title ) ) ? $alt\_title : $term->name;
808
809
$breadcrumbs\[\] = array(
810
'text' => wp\_strip\_all\_tags( $title ),
811
'url' => get\_term\_link( (int) $term->term\_id, $term->taxonomy ),
812
);
813
} // 2B. When the post/page is found, we can add it to the breadcrumbs
814
else if ( ! empty( $element->ID ) ) {
815
$page\_id = apply\_filters( 'wpml\_object\_id', $element->ID, $element->post\_type, true );
816
$page = ( $element->ID !== $page\_id ) ? get\_post( $page\_id ) : $element;
720
817
721
818
// Alternative title
722
if($current\_filter == 'wpseo\_breadcrumb\_links') {
723
$alt\_title = get\_post\_meta($page->ID, '\_yoast\_wpseo\_bctitle', true);
724
} else if($current\_filter == 'seopress\_pro\_breadcrumbs\_crumbs') {
725
$alt\_title = get\_post\_meta($page->ID, '\_seopress\_robots\_breadcrumbs', true);
726
} else if($current\_filter == 'rank\_math/frontend/breadcrumb/items') {
727
$alt\_title = get\_post\_meta($page->ID, 'rank\_math\_breadcrumb\_title', true);
728
}
729
730
$title = (!empty($alt\_title)) ? $alt\_title : $page->post\_title;
731
732
$breadcrumbs\[\] = array(
733
'text' => wp\_strip\_all\_tags($title),
734
'url' => get\_permalink($page->ID),
735
);
736
}
737
// 2C. When the post archive is found, we can add it to the breadcrumbs
738
else if(!empty($element->rewrite) && (!empty($element->labels->name))) {
739
$breadcrumbs\[\] = array(
740
'text' => apply\_filters('post\_type\_archive\_title', $element->labels->name, $element->name),
741
'url' => get\_post\_type\_archive\_link($element->name),
742
);
743
}
744
}
819
if ( $current\_filter == 'wpseo\_breadcrumb\_links' ) {
820
$alt\_title = get\_post\_meta( $page->ID, '\_yoast\_wpseo\_bctitle', true );
821
} else if ( $current\_filter == 'seopress\_pro\_breadcrumbs\_crumbs' ) {
822
$alt\_title = get\_post\_meta( $page->ID, '\_seopress\_robots\_breadcrumbs', true );
823
} else if ( $current\_filter == 'rank\_math/frontend/breadcrumb/items' ) {
824
$alt\_title = get\_post\_meta( $page->ID, 'rank\_math\_breadcrumb\_title', true );
825
}
826
827
$title = ( ! empty( $alt\_title ) ) ? $alt\_title : $page->post\_title;
828
829
$breadcrumbs\[\] = array(
830
'text' => wp\_strip\_all\_tags( $title ),
831
'url' => get\_permalink( $page->ID ),
832
);
833
} // 2C. When the post archive is found, we can add it to the breadcrumbs
834
else if ( ! empty( $element->rewrite ) && ( ! empty( $element->labels->name ) ) ) {
835
$breadcrumbs\[\] = array(
836
'text' => apply\_filters( 'post\_type\_archive\_title', $element->labels->name, $element->name ),
837
'url' => get\_post\_type\_archive\_link( $element->name ),
838
);
839
}
840
}
745
841
746
842
// Add new links to current breadcrumbs array
747
if(!empty($links) && is\_array($links)) {
748
$first\_element = reset($links);
749
$last\_element = end($links);
750
$breadcrumbs = (!empty($breadcrumbs)) ? $breadcrumbs : array();
751
752
// Support RankMath/SEOPress/WooCommerce/Slim SEO breadcrumbs
753
if(in\_array($current\_filter, array('wpseo\_breadcrumb\_links', 'rank\_math/frontend/breadcrumb/items', 'seopress\_pro\_breadcrumbs\_crumbs', 'woocommerce\_get\_breadcrumb', 'slim\_seo\_breadcrumbs\_links'))) {
754
foreach($breadcrumbs as &$breadcrumb) {
755
if(isset($breadcrumb\['text'\])) {
756
$breadcrumb\[0\] = $breadcrumb\['text'\];
757
$breadcrumb\[1\] = $breadcrumb\['url'\];
758
}
759
}
760
761
if(in\_array($current\_filter, array('slim\_seo\_breadcrumbs\_links'))) {
762
$links = array\_merge(array($first\_element), $breadcrumbs);
843
if ( ! empty( $links ) && is\_array( $links ) ) {
844
$first\_element = reset( $links );
845
$last\_element = end( $links );
846
$breadcrumbs = ( ! empty( $breadcrumbs ) ) ? $breadcrumbs : array();
847
848
// Support RankMath/SEOPress/WooCommerce/Slim SEO breadcrumbs
849
if ( in\_array( $current\_filter, array( 'wpseo\_breadcrumb\_links', 'rank\_math/frontend/breadcrumb/items', 'seopress\_pro\_breadcrumbs\_crumbs', 'woocommerce\_get\_breadcrumb', 'slim\_seo\_breadcrumbs\_links' ) ) ) {
850
foreach ( $breadcrumbs as &$breadcrumb ) {
851
if ( isset( $breadcrumb\['text'\] ) ) {
852
$breadcrumb\[0\] = $breadcrumb\['text'\];
853
$breadcrumb\[1\] = $breadcrumb\['url'\];
854
}
855
}
856
857
if ( in\_array( $current\_filter, array( 'slim\_seo\_breadcrumbs\_links' ) ) ) {
858
$links = array\_merge( array( $first\_element ), $breadcrumbs );
763
859
} else {
764
$links = array\_merge(array($first\_element), $breadcrumbs, array($last\_element));
765
}
766
}
767
// Support Avia/Enfold breadcrumbs
768
else if($current\_filter == 'avia\_breadcrumbs\_trail') {
769
foreach($breadcrumbs as &$breadcrumb) {
770
if(isset($breadcrumb\['text'\])) {
771
$breadcrumb = sprintf('<a href="%s" title="%2$s">%2$s</a>', esc\_attr($breadcrumb\['url'\]), esc\_attr($breadcrumb\['text'\]));
772
}
773
}
774
775
$links = $breadcrumbs;
860
$links = array\_merge( array( $first\_element ), $breadcrumbs, array( $last\_element ) );
861
}
862
} // Support Avia/Enfold breadcrumbs
863
else if ( $current\_filter == 'avia\_breadcrumbs\_trail' ) {
864
foreach ( $breadcrumbs as &$breadcrumb ) {
865
if ( isset( $breadcrumb\['text'\] ) ) {
866
$breadcrumb = sprintf( '<a href="%s" title="%2$s">%2$s</a>', esc\_attr( $breadcrumb\['url'\] ), esc\_attr( $breadcrumb\['text'\] ) );
867
}
868
}
869
870
$links = $breadcrumbs;
776
871
$links\['trail\_end'\] = $last\_element;
777
872
}
778
}
779
780
return array\_filter($links);
781
}
782
783
/\*\*
784
\* 8. Support WooCommerce Wishlist Plugin
785
\*/
786
function ti\_woocommerce\_wishlist\_uris($uri\_parts, $request\_url, $endpoints) {
787
global $permalink\_manager\_uris, $wp;
788
789
$wishlist\_pid = tinv\_get\_option('general', 'page\_wishlist');
873
}
874
875
return array\_filter( $links );
876
}
877
878
/\*\*
879
\* 8. Extracts the Wishlist ID from the URI and add it to the $uri\_parts array (WooCommerce Wishlist Plugin)
880
\*
881
\* @param array $uri\_parts An array of the URI parts.
882
\* @param string $request\_url The URL that was requested.
883
\* @param array $endpoints An array of all the endpoints that are currently registered.
884
\*
885
\* @return array The URI parts.
886
\*/
887
function ti\_woocommerce\_wishlist\_uris( $uri\_parts, $request\_url, $endpoints ) {
888
global $permalink\_manager\_uris;
889
890
$wishlist\_pid = tinv\_get\_option( 'general', 'page\_wishlist' );
790
891
791
892
// Find the Wishlist page URI
792
if(is\_numeric($wishlist\_pid) && !empty($permalink\_manager\_uris\[$wishlist\_pid\])) {
793
$wishlist\_uri = preg\_quote($permalink\_manager\_uris\[$wishlist\_pid\], '/');
893
if ( is\_numeric( $wishlist\_pid ) && ! empty( $permalink\_manager\_uris\[ $wishlist\_pid \] ) ) {
894
$wishlist\_uri = preg\_quote( $permalink\_manager\_uris\[ $wishlist\_pid \], '/' );
794
895
795
896
// Extract the Wishlist ID
796
preg\_match("/^({$wishlist\_uri})\\/(\[^\\/\]+)\\/?$/", $uri\_parts\['uri'\], $output\_array);
797
798
if(!empty($output\_array\[2\])) {
799
$uri\_parts\['uri'\] \= $output\_array\[1\];
800
$uri\_parts\['endpoint'\] \= 'tinvwlID';
897
preg\_match( "/^({$wishlist\_uri})\\/(\[^\\/\]+)\\/?$/", $uri\_parts\['uri'\], $output\_array );
898
899
if ( ! empty( $output\_array\[2\] ) ) {
900
$uri\_parts\['uri'\] \= $output\_array\[1\];
901
$uri\_parts\['endpoint'\] \= 'tinvwlID';
801
902
$uri\_parts\['endpoint\_value'\] = $output\_array\[2\];
802
903
}
…
…
807
908
808
909
/\*\*
809
\* 9. Revisionize
810
\*/
811
function revisionize\_keep\_post\_uri($old\_id, $new\_id) {
910
\* 9A. Copy the custom URI from original post and apply it to the new temp. revision post (Revisionize)
911
\*
912
\* @param int $old\_id
913
\* @param int $new\_id
914
\*/
915
function revisionize\_keep\_post\_uri( $old\_id, $new\_id ) {
812
916
global $permalink\_manager\_uris;
813
917
814
// Copy the custom URI from original post and apply it to the new temp. revision post
815
if(!empty($permalink\_manager\_uris\[$old\_id\])) {
816
$permalink\_manager\_uris\[$new\_id\] = $permalink\_manager\_uris\[$old\_id\];
817
818
update\_option('permalink-manager-uris', $permalink\_manager\_uris);
819
}
820
}
821
822
function revisionize\_clone\_uri($old\_id, $new\_id) {
918
if ( ! empty( $permalink\_manager\_uris\[ $old\_id \] ) ) {
919
$permalink\_manager\_uris\[ $new\_id \] = $permalink\_manager\_uris\[ $old\_id \];
920
921
update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
922
}
923
}
924
925
/\*\*
926
\* 9B. Copy the custom URI from revision post and apply it to the original post
927
\*
928
\* @param int $old\_id
929
\* @param int $new\_id
930
\*/
931
function revisionize\_clone\_uri( $old\_id, $new\_id ) {
823
932
global $permalink\_manager\_uris;
824
933
825
if(!empty($permalink\_manager\_uris\[$new\_id\])) {
826
// Copy the custom URI from revision post and apply it to the original post
827
$permalink\_manager\_uris\[$old\_id\] = $permalink\_manager\_uris\[$new\_id\];
828
unset($permalink\_manager\_uris\[$new\_id\]);
829
830
update\_option('permalink-manager-uris', $permalink\_manager\_uris);
831
}
832
}
833
834
/\*\*
835
\* 10. WP All Import
836
\*/
837
function wpaiextra\_uri\_display($content\_type, $current\_values) {
934
if ( ! empty( $permalink\_manager\_uris\[ $new\_id \] ) ) {
935
$permalink\_manager\_uris\[ $old\_id \] = $permalink\_manager\_uris\[ $new\_id \];
936
unset( $permalink\_manager\_uris\[ $new\_id \] );
937
938
update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
939
}
940
}
941
942
/\*\*
943
\* 10A. Add a new section to the WP All Import interface
944
\*
945
\* @param string $content\_type The type of content being imported
946
\* @param array $current\_values An array of the current values for the post
947
\*/
948
function wpaiextra\_uri\_display( $content\_type, $current\_values ) {
838
949
// Check if post type is supported
839
if($content\_type !== 'taxonomies' && Permalink\_Manager\_Helper\_Functions::is\_post\_type\_disabled($content\_type)) {
950
if ( $content\_type !== 'taxonomies' && Permalink\_Manager\_Helper\_Functions::is\_post\_type\_disabled( $content\_type ) ) {
840
951
return;
841
952
}
842
953
843
954
// Get custom URI format
844
$custom\_uri = (!empty($current\_values\['custom\_uri'\])) ? sanitize\_text\_field($current\_values\['custom\_uri'\]) : "";
955
$custom\_uri = ( ! empty( $current\_values\['custom\_uri'\] ) ) ? sanitize\_text\_field( $current\_values\['custom\_uri'\] ) : "";
845
956
846
957
$html = '<div class="wpallimport-collapsed closed wpallimport-section">';
847
958
$html .= '<div class="wpallimport-content-section">';
848
$html .= sprintf('<div class="wpallimport-collapsed-header"><h3>%s</h3></div>', \_\_('Permalink Manager', 'permalink-manager'));
959
$html .= sprintf( '<div class="wpallimport-collapsed-header"><h3>%s</h3></div>', \_\_( 'Permalink Manager', 'permalink-manager' ) );
849
960
$html .= '<div class="wpallimport-collapsed-content">';
850
961
851
962
$html .= '<div class="template\_input">';
852
$html .= Permalink\_Manager\_Admin\_Functions::generate\_option\_field('custom\_uri', array('extra\_atts' => 'style="width:100%; line-height: 25px;"', 'placeholder' => \_\_('Custom URI', 'permalink-manager'), 'value' => $custom\_uri));
853
$html .= wpautop(sprintf(\_\_('If empty, a default permalink based on your current <a href="%s" target="\_blank">permastructure settings</a> will be used.', 'permalink-manager'), Permalink\_Manager\_Admin\_Functions::get\_admin\_url('§ion=permastructs')));
963
$html .= Permalink\_Manager\_Admin\_Functions::generate\_option\_field( 'custom\_uri', array( 'extra\_atts' => 'style="width:100%; line-height: 25px;"', 'placeholder' => \_\_( 'Custom URI', 'permalink-manager' ), 'value' => $custom\_uri ) );
964
$html .= wpautop( sprintf( \_\_( 'If empty, a default permalink based on your current <a href="%s" target="\_blank">permastructure settings</a> will be used.', 'permalink-manager' ), Permalink\_Manager\_Admin\_Functions::get\_admin\_url( '§ion=permastructs' ) ) );
854
965
$html .= '</div>';
855
856
// $html .= print\_r($current\_values, true);
857
966
858
967
$html .= '</div>';
…
…
863
972
}
864
973
865
function wpai\_api\_options($all\_options) {
866
return $all\_options + array('custom\_uri' => null);
867
}
868
869
function wpai\_api\_register($addons) {
870
if(empty($addons\[PERMALINK\_MANAGER\_PLUGIN\_SLUG\])) {
871
$addons\[PERMALINK\_MANAGER\_PLUGIN\_SLUG\] = 1;
872
}
974
/\*\*
975
\* 10BA. Add a new field to the list of WP All Import options
976
\*
977
\* @param array $all\_options The array of all options that are currently set
978
\*
979
\* @return array The array of all options plus the custom\_uri option
980
\*/
981
function wpai\_api\_options( $all\_options ) {
982
return $all\_options + array( 'custom\_uri' => null );
983
}
984
985
/\*\*
986
\* 10BB. Add Permalink Manager plugin to the WP All Import API
987
\*
988
\* @param array $addons
989
\*
990
\* @return array
991
\*/
992
function wpai\_api\_register( $addons ) {
993
if ( empty( $addons\[ PERMALINK\_MANAGER\_PLUGIN\_SLUG \] ) ) {
994
$addons\[ PERMALINK\_MANAGER\_PLUGIN\_SLUG \] = 1;
995
}
996
873
997
return $addons;
874
998
}
875
999
876
function wpai\_api\_parse($functions) {
877
$functions\[PERMALINK\_MANAGER\_PLUGIN\_SLUG\] = array($this, 'wpai\_api\_parse\_function');
1000
/\*\*
1001
\* 10BC. Register function that parses Permalink Manager plugin data in WP All Import API data feed
1002
\*
1003
\* @param array $functions
1004
\*
1005
\* @return array
1006
\*/
1007
function wpai\_api\_parse( $functions ) {
1008
$functions\[ PERMALINK\_MANAGER\_PLUGIN\_SLUG \] = array( $this, 'wpai\_api\_parse\_function' );
1009
878
1010
return $functions;
879
1011
}
880
1012
881
function wpai\_api\_import($functions) {
882
$functions\[PERMALINK\_MANAGER\_PLUGIN\_SLUG\] = array($this, 'wpai\_api\_import\_function');
1013
/\*\*
1014
\* 10BD. Register function that saves Permalink Manager plugin data extracted from WP All Import API data feed
1015
\*
1016
\* @param array $functions
1017
\*
1018
\* @return array
1019
\*/
1020
function wpai\_api\_import( $functions ) {
1021
$functions\[ PERMALINK\_MANAGER\_PLUGIN\_SLUG \] = array( $this, 'wpai\_api\_import\_function' );
1022
883
1023
return $functions;
884
1024
}
885
1025
886
function wpai\_api\_parse\_function($data) {
887
extract($data);
888
889
$data = array(); // parsed data
1026
/\*\*
1027
\* 10C. Parse Permalink Manager plugin data in WP All Import API data feed
1028
\*
1029
\* @param array $data
1030
\*
1031
\* @return array
1032
\*/
1033
function wpai\_api\_parse\_function( $data ) {
1034
extract( $data );
1035
1036
$data = array(); // parsed data
890
1037
$option\_name = 'custom\_uri';
891
1038
892
if(!empty($import->options\[$option\_name\])) {
893
$this->logger = $data\['logger'\];
894
$cxpath = $xpath\_prefix . $import->xpath;
1039
if ( ! empty( $import->options\[ $option\_name \] ) && class\_exists( 'XmlImportParser' ) ) {
1040
$cxpath = $xpath\_prefix . $import->xpath;
895
1041
$tmp\_files = array();
896
1042
897
if(isset($import->options\[$option\_name\]) && $import->options\[$option\_name\] != '') {
898
if($import->options\[$option\_name\] == "xpath") {
899
if ($import->options\[$this->slug\]\['xpaths'\]\[$option\_name\] == "") {
900
$count and $this->data\[$option\_name\] = array\_fill(0, $count, "");
901
} else {
902
$data\[$option\_name\] = XmlImportParser::factory($xml, $cxpath, (string) $import->options\['xpaths'\]\[$option\_name\], $file)->parse();
903
$tmp\_files\[\] = $file;
1043
if ( isset( $import->options\[ $option\_name \] ) && $import->options\[ $option\_name \] != '' ) {
1044
if ( $import->options\[ $option\_name \] == "xpath" ) {
1045
$data\[ $option\_name \] = XmlImportParser::factory( $xml, $cxpath, (string) $import->options\['xpaths'\]\[ $option\_name \], $file )->parse();
1046
} else {
1047
$data\[ $option\_name \] = XmlImportParser::factory( $xml, $cxpath, (string) $import->options\[ $option\_name \], $file )->parse();
1048
}
1049
1050
$tmp\_files\[\] = $file;
1051
} else {
1052
$data\[ $option\_name \] = array\_fill( 0, $count, "" );
1053
}
1054
1055
foreach ( $tmp\_files as $file ) {
1056
unlink( $file );
1057
}
1058
}
1059
1060
return $data;
1061
}
1062
1063
/\*\*
1064
\* 10D. Save the Permalink Manager plugin data extracted from WP All Import API data feed
1065
\*
1066
\* @param array $importData
1067
\* @param array $parsedData
1068
\*/
1069
function wpai\_api\_import\_function( $importData, $parsedData ) {
1070
// Check if the array with $parsedData is not empty
1071
if ( empty( $parsedData ) || empty( $importData\['post\_type'\] ) ) {
1072
return;
1073
}
1074
1075
// Check if the imported elements are terms
1076
if ( $importData\['post\_type'\] == 'taxonomies' ) {
1077
$is\_term = true;
1078
} else if ( Permalink\_Manager\_Helper\_Functions::is\_post\_type\_disabled( $importData\['post\_type'\] ) ) {
1079
return;
1080
}
1081
1082
// Get the parsed custom URI
1083
$index = ( isset( $importData\['i'\] ) ) ? $importData\['i'\] : false;
1084
$pid = ( ! empty( $importData\['pid'\] ) ) ? (int) $importData\['pid'\] : false;
1085
1086
if ( isset( $index ) && ! empty( $pid ) && ! empty( $parsedData\['custom\_uri'\]\[ $index \] ) ) {
1087
$new\_uri = Permalink\_Manager\_Helper\_Functions::sanitize\_title( $parsedData\['custom\_uri'\]\[ $index \] );
1088
1089
if ( ! empty( $new\_uri ) ) {
1090
if ( ! empty( $is\_term ) ) {
1091
$default\_uri = Permalink\_Manager\_URI\_Functions\_Tax::get\_default\_term\_uri( $pid );
1092
$native\_uri = Permalink\_Manager\_URI\_Functions\_Tax::get\_default\_term\_uri( $pid, true );
1093
$custom\_uri = Permalink\_Manager\_URI\_Functions\_Tax::get\_term\_uri( $pid, false, true );
1094
$old\_uri = ( ! empty( $custom\_uri ) ) ? $custom\_uri : $native\_uri;
1095
1096
if ( $new\_uri !== $old\_uri ) {
1097
Permalink\_Manager\_URI\_Functions::save\_single\_uri( $pid, $new\_uri, true, true );
1098
do\_action( 'permalink\_manager\_updated\_term\_uri', $pid, $new\_uri, $old\_uri, $native\_uri, $default\_uri, $single\_update = true, $uri\_saved = true );
904
1099
}
905
1100
} else {
906
$data\[$option\_name\] = XmlImportParser::factory($xml, $cxpath, (string) $import->options\[$option\_name\], $file)->parse();
907
$tmp\_files\[\] = $file;
908
}
909
} else {
910
$data\[$option\_name\] = array\_fill(0, $count, "");
911
}
912
913
foreach ($tmp\_files as $file) {
914
unlink($file);
915
}
916
}
917
918
return $data;
919
}
920
921
function wpai\_api\_import\_function($importData, $parsedData) {
922
// Check if the array with $parsedData is not empty
923
if(empty($parsedData) || empty($importData\['post\_type'\])) { return; }
924
925
// Check if the imported elements are terms
926
if($importData\['post\_type'\] == 'taxonomies') {
927
$is\_term = true;
928
} else if(Permalink\_Manager\_Helper\_Functions::is\_post\_type\_disabled($importData\['post\_type'\])) {
1101
$default\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri( $pid );
1102
$native\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri( $pid, true );
1103
$custom\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_post\_uri( $pid, false, true );
1104
$old\_uri = ( ! empty( $custom\_uri ) ) ? $custom\_uri : $native\_uri;
1105
1106
if ( $new\_uri !== $old\_uri ) {
1107
Permalink\_Manager\_URI\_Functions::save\_single\_uri( $pid, $new\_uri, false, true );
1108
do\_action( 'permalink\_manager\_updated\_post\_uri', $pid, $new\_uri, $old\_uri, $native\_uri, $default\_uri, $single\_update = true, $uri\_saved = true );
1109
}
1110
}
1111
}
1112
}
1113
}
1114
1115
/\*\*
1116
\* 10E. Copy the external redirect from the "external\_redirect" custom field to the data model used by Permalink Manager Pro
1117
\*
1118
\* @param int $pid The post ID of the post being imported.
1119
\*/
1120
function wpai\_save\_redirects( $pid ) {
1121
$external\_url = get\_post\_meta( $pid, '\_external\_redirect', true );
1122
$external\_url = ( empty( $external\_url ) ) ? get\_post\_meta( $pid, 'external\_redirect', true ) : $external\_url;
1123
1124
if ( $external\_url && class\_exists( 'Permalink\_Manager\_Pro\_Functions' ) ) {
1125
Permalink\_Manager\_Pro\_Functions::save\_external\_redirect( $external\_url, $pid );
1126
}
1127
}
1128
1129
/\*\*
1130
\* 10FA. Use the import ID to extract all the post IDs that were imported, then splits them into chunks and schedule a single regenerate permalink event for each chunk
1131
\*
1132
\* @param int $import\_id The ID of the import.
1133
\*/
1134
function wpai\_schedule\_regenerate\_uris\_after\_xml\_import( $import\_id ) {
1135
global $wpdb;
1136
1137
$post\_ids = $wpdb->get\_col( "SELECT post\_id FROM {$wpdb->prefix}pmxi\_posts WHERE import\_id = {$import\_id}" );
1138
$chunks = array\_chunk( $post\_ids, 200 );
1139
1140
// Schedule URI regenerate and split into bulks
1141
foreach ( $chunks as $i => $chunk ) {
1142
wp\_schedule\_single\_event( time() + ( $i \* 30 ), 'wpai\_regenerate\_uris\_after\_import\_event', array( $chunk ) );
1143
}
1144
}
1145
1146
/\*\*
1147
\* 10FB. Regenerate the custom permalinks for all imported posts
1148
\*
1149
\* @param array $post\_ids An array of post IDs that were just imported.
1150
\*/
1151
function wpai\_regenerate\_uris\_after\_import( $post\_ids ) {
1152
global $permalink\_manager\_uris;
1153
1154
if ( ! is\_array( $post\_ids ) ) {
929
1155
return;
930
1156
}
931
1157
932
// Get the parsed custom URI
933
$index = (isset($importData\['i'\])) ? $importData\['i'\] : false;
934
$pid = (!empty($importData\['pid'\])) ? (int) $importData\['pid'\] : false;
935
936
if(isset($index) && !empty($pid) && !empty($parsedData\['custom\_uri'\]\[$index\])) {
937
$new\_uri = Permalink\_Manager\_Helper\_Functions::sanitize\_title($parsedData\['custom\_uri'\]\[$index\]);
938
939
if(!empty($new\_uri)) {
940
if(!empty($is\_term)) {
941
$default\_uri = Permalink\_Manager\_URI\_Functions\_Tax::get\_default\_term\_uri($pid);
942
$native\_uri = Permalink\_Manager\_URI\_Functions\_Tax::get\_default\_term\_uri($pid, true);
943
$custom\_uri = Permalink\_Manager\_URI\_Functions\_Tax::get\_term\_uri($pid, false, true);
944
$old\_uri = (!empty($custom\_uri)) ? $custom\_uri : $native\_uri;
945
946
if($new\_uri !== $old\_uri) {
947
Permalink\_Manager\_URI\_Functions::save\_single\_uri($pid, $new\_uri, true, true);
948
do\_action('permalink\_manager\_updated\_term\_uri', $pid, $new\_uri, $old\_uri, $native\_uri, $default\_uri, $single\_update = true, $uri\_saved = true);
949
}
950
} else {
951
$default\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri($pid);
952
$native\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri($pid, true);
953
$custom\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_post\_uri($pid, false, true);
954
$old\_uri = (!empty($custom\_uri)) ? $custom\_uri : $native\_uri;
955
956
if($new\_uri !== $old\_uri) {
957
Permalink\_Manager\_URI\_Functions::save\_single\_uri($pid, $new\_uri, false, true);
958
do\_action('permalink\_manager\_updated\_post\_uri', $pid, $new\_uri, $old\_uri, $native\_uri, $default\_uri, $single\_update = true, $uri\_saved = true);
959
}
960
}
961
}
962
}
963
}
964
965
function wpai\_save\_redirects($pid) {
966
global $permalink\_manager\_external\_redirects, $permalink\_manager\_uris;
967
968
$external\_url = get\_post\_meta($pid, '\_external\_redirect', true);
969
$external\_url = (empty($external\_url)) ? get\_post\_meta($pid, 'external\_redirect', true) : $external\_url;
970
971
if($external\_url && class\_exists('Permalink\_Manager\_Pro\_Functions')) {
972
Permalink\_Manager\_Pro\_Functions::save\_external\_redirect($external\_url, $pid);
973
}
974
}
975
976
function wpai\_schedule\_regenerate\_uris\_after\_xml\_import($import\_id) {
977
global $wpdb;
978
979
$post\_ids = $wpdb->get\_col("SELECT post\_id FROM {$wpdb->prefix}pmxi\_posts WHERE import\_id = {$import\_id}");
980
$chunks = array\_chunk($post\_ids, 200);
981
982
// Schedule URI regenerate and split into bulks
983
foreach($chunks as $i => $chunk) {
984
wp\_schedule\_single\_event(time() + ($i \* 30), 'wpai\_regenerate\_uris\_after\_import\_event', array($chunk));
985
}
986
}
987
988
function wpai\_regenerate\_uris\_after\_import($post\_ids) {
989
global $permalink\_manager\_uris;
990
991
if(!is\_array($post\_ids)) { return; }
992
993
foreach($post\_ids as $id) {
994
if(!empty($permalink\_manager\_uris\[$id\])) { continue; }
995
$permalink\_manager\_uris\[$id\] = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri($id);
996
}
997
998
update\_option('permalink-manager-uris', $permalink\_manager\_uris);
999
}
1000
1001
/\*\*
1002
\* 11. WP All Export
1003
\*/
1004
function wpae\_custom\_uri\_section($sections) {
1005
if(is\_array($sections)) {
1158
foreach ( $post\_ids as $id ) {
1159
if ( ! empty( $permalink\_manager\_uris\[ $id \] ) ) {
1160
continue;
1161
}
1162
$permalink\_manager\_uris\[ $id \] = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri( $id );
1163
}
1164
1165
update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
1166
}
1167
1168
/\*\*
1169
\* 11A. Add a new section to the WP All Export interface
1170
\*
1171
\* @param array $sections
1172
\*
1173
\* @return array
1174
\*/
1175
function wpae\_custom\_uri\_section( $sections ) {
1176
if ( is\_array( $sections ) ) {
1006
1177
$sections\['permalink\_manager'\] = array(
1007
'title' => \_\_('Permalink Manager', 'permalink-manager'),
1178
'title' => \_\_( 'Permalink Manager', 'permalink-manager' ),
1008
1179
'content' => 'permalink\_manager\_fields'
1009
1180
);
…
…
1013
1184
}
1014
1185
1015
function wpae\_custom\_uri\_section\_fields($fields) {
1016
if(is\_array($fields)) {
1186
/\*\*
1187
\* 11B. Add a new field to the "Permalink Manager" section of the WP All Export interface
1188
\*
1189
\* @param array $fields The fields to be displayed in the section.
1190
\*
1191
\* @return array
1192
\*/
1193
function wpae\_custom\_uri\_section\_fields( $fields ) {
1194
if ( is\_array( $fields ) ) {
1017
1195
$fields\['permalink\_manager\_fields'\] = array(
1018
1196
array(
…
…
1027
1205
}
1028
1206
1029
function wpae\_export\_custom\_uri($articles, $options) {
1030
if((!empty($options\['selected\_post\_type'\]) && $options\['selected\_post\_type'\] == 'taxonomies') || !empty($options\['is\_taxonomy\_export'\])) {
1207
/\*\*
1208
\* 11C. Add a new column to the export file with the custom permalink for each post/term
1209
\*
1210
\* @param array $articles The array of articles to be exported.
1211
\* @param array $options an array of options for the export.
1212
\*
1213
\* @return array
1214
\*/
1215
function wpae\_export\_custom\_uri( $articles, $options ) {
1216
if ( ( ! empty( $options\['selected\_post\_type'\] ) && $options\['selected\_post\_type'\] == 'taxonomies' ) || ! empty( $options\['is\_taxonomy\_export'\] ) ) {
1031
1217
$is\_term = true;
1032
1218
} else {
…
…
1034
1220
}
1035
1221
1036
foreach($articles as &$article) {
1037
if(!empty($article\['id'\])) {
1222
foreach ( $articles as &$article ) {
1223
if ( ! empty( $article\['id'\] ) ) {
1038
1224
$item\_id = $article\['id'\];
1039
} else if(!empty($article\['ID'\])) {
1225
} else if ( ! empty( $article\['ID'\] ) ) {
1040
1226
$item\_id = $article\['ID'\];
1041
} else if(!empty($article\['Term ID'\])) {
1227
} else if ( ! empty( $article\['Term ID'\] ) ) {
1042
1228
$item\_id = $article\['Term ID'\];
1043
1229
} else {
…
…
1045
1231
}
1046
1232
1047
if(!empty($is\_term)) {
1048
$article\['Custom URI'\] = Permalink\_Manager\_URI\_Functions\_Tax::get\_term\_uri($item\_id);
1233
if ( ! empty( $is\_term ) ) {
1234
$article\['Custom URI'\] = Permalink\_Manager\_URI\_Functions\_Tax::get\_term\_uri( $item\_id );
1049
1235
} else {
1050
$article\['Custom URI'\] = Permalink\_Manager\_URI\_Functions\_Post::get\_post\_uri($item\_id);
1236
$article\['Custom URI'\] = Permalink\_Manager\_URI\_Functions\_Post::get\_post\_uri( $item\_id );
1051
1237
}
1052
1238
}
…
…
1056
1242
1057
1243
/\*\*
1058
\* 12. Duplicate Page
1059
\*/
1060
function duplicate\_custom\_uri($new\_post\_id, $old\_post) {
1244
\* 12. Check if the "custom\_uri" is not blacklisted in the "duplicate\_post\_blacklist" option and if it's not, clone the custom permalink of the original post to the new one
1245
\*
1246
\* @param int $new\_post\_id The ID of the newly created post.
1247
\* @param WP\_Post $old\_post The post object of the original post.
1248
\*/
1249
function duplicate\_custom\_uri( $new\_post\_id, $old\_post ) {
1061
1250
global $permalink\_manager\_uris;
1062
1251
1063
$duplicate\_post\_blacklist \= get\_option('duplicate\_post\_blacklist', false);
1064
$duplicate\_custom\_uri\_bool = (!empty($duplicate\_post\_blacklist) && strpos($duplicate\_post\_blacklist, 'custom\_uri') !== false) ? false : true;
1065
1066
if(!empty($old\_post->ID) && $duplicate\_custom\_uri\_bool) {
1067
$old\_post\_id = intval($old\_post->ID);
1252
$duplicate\_post\_blacklist = get\_option( 'duplicate\_post\_blacklist', false );
1253
$duplicate\_custom\_uri\_bool = ( ! empty( $duplicate\_post\_blacklist ) && strpos( $duplicate\_post\_blacklist, 'custom\_uri' ) !== false ) ? false : true;
1254
1255
if ( ! empty( $old\_post->ID ) && $duplicate\_custom\_uri\_bool ) {
1256
$old\_post\_id = $old\_post->ID;
1068
1257
1069
1258
// Clone custom permalink (if set for cloned post/page)
1070
if(!empty($permalink\_manager\_uris\[$old\_post\_id\])) {
1071
$old\_post\_uri = $permalink\_manager\_uris\[$old\_post\_id\];
1072
$new\_post\_uri = preg\_replace('/(.+?)(\\.\[^\\.\]+$|$)/', '$1-2$2', $old\_post\_uri);
1073
1074
$permalink\_manager\_uris\[$new\_post\_id\] = $new\_post\_uri;
1075
update\_option('permalink-manager-uris', $permalink\_manager\_uris);
1076
}
1077
}
1078
}
1079
1080
/\*\*
1081
\* 13. My Listing by 27collective
1082
\*/
1083
public function ml\_listing\_custom\_fields($default\_uri, $native\_slug, $element, $slug, $native\_uri) {
1259
if ( ! empty( $permalink\_manager\_uris\[ $old\_post\_id \] ) ) {
1260
$old\_post\_uri = $permalink\_manager\_uris\[ $old\_post\_id \];
1261
$new\_post\_uri = preg\_replace( '/(.+?)(\\.\[^\\.\]+$|$)/', '$1-2$2', $old\_post\_uri );
1262
1263
$permalink\_manager\_uris\[ $new\_post\_id \] = $new\_post\_uri;
1264
update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
1265
}
1266
}
1267
}
1268
1269
/\*\*
1270
\* 13A. Replace in the default permalink format the unique permastructure tags available for My Listing theme
1271
\*
1272
\* @param string $default\_uri The default permalink for the element.
1273
\* @param string $native\_slug The native slug of the post type.
1274
\* @param WP\_Post $element The post object.
1275
\* @param string $slug The slug of the post type.
1276
\* @param bool $native\_uri
1277
\*
1278
\* @return string
1279
\*/
1280
public function ml\_listing\_custom\_fields( $default\_uri, $native\_slug, $element, $slug, $native\_uri ) {
1281
// Use only for "listing" post type & custom permalink
1282
if ( empty( $element->post\_type ) || $element->post\_type !== 'job\_listing' ) {
1283
return $default\_uri;
1284
}
1285
1286
// A1. Listing type
1287
if ( strpos( $default\_uri, '%listing-type%' ) !== false || strpos( $default\_uri, '%listing\_type%' ) !== false ) {
1288
if ( class\_exists( 'MyListing\\Src\\Listing' ) ) {
1289
$listing\_type\_post = MyListing\\Src\\Listing::get( $element );
1290
$listing\_type = ( is\_object( $listing\_type\_post ) && ! empty( $listing\_type\_post->type ) ) ? $listing\_type\_post->type->get\_permalink\_name() : '';
1291
} else {
1292
$listing\_type\_slug = get\_post\_meta( $element->ID, '\_case27\_listing\_type', true );
1293
$listing\_type\_post = get\_page\_by\_path( $listing\_type\_slug, OBJECT, 'case27\_listing\_type' );
1294
1295
if ( ! empty( $listing\_type\_post ) ) {
1296
$listing\_type\_post\_settings = get\_post\_meta( $listing\_type\_post->ID, 'case27\_listing\_type\_settings\_page', true );
1297
$listing\_type\_post\_settings = ( is\_serialized( $listing\_type\_post\_settings ) ) ? unserialize( $listing\_type\_post\_settings ) : array();
1298
1299
$listing\_type = ( ! empty( $listing\_type\_post\_settings\['permalink'\] ) ) ? $listing\_type\_post\_settings\['permalink'\] : $listing\_type\_post->post\_name;
1300
}
1301
}
1302
1303
if ( ! empty( $listing\_type ) ) {
1304
$default\_uri = str\_replace( array( '%listing-type%', '%listing\_type%' ), Permalink\_Manager\_Helper\_Functions::sanitize\_title( $listing\_type, true ), $default\_uri );
1305
}
1306
}
1307
1308
// A2. Listing type (slug)
1309
if ( strpos( $default\_uri, '%listing-type-slug%' ) !== false || strpos( $default\_uri, '%listing\_type\_slug%' ) !== false || strpos( $default\_uri, '%case27\_listing\_type%' ) !== false ) {
1310
$listing\_type = get\_post\_meta( $element->ID, '\_case27\_listing\_type', true );
1311
1312
if ( ! empty( $listing\_type ) ) {
1313
$listing\_type = Permalink\_Manager\_Helper\_Functions::sanitize\_title( $listing\_type, true );
1314
$default\_uri = str\_replace( array( '%listing-type-slug%', '%listing\_type\_slug%', '%case27\_listing\_type%' ), $listing\_type, $default\_uri );
1315
}
1316
}
1317
1318
// B. Listing location
1319
if ( strpos( $default\_uri, '%listing-location%' ) !== false || strpos( $default\_uri, '%listing\_location%' ) !== false ) {
1320
$listing\_location = get\_post\_meta( $element->ID, '\_job\_location', true );
1321
1322
if ( ! empty( $listing\_location ) ) {
1323
$listing\_location = Permalink\_Manager\_Helper\_Functions::sanitize\_title( $listing\_location, true );
1324
$default\_uri = str\_replace( array( '%listing-location%', '%listing\_location%' ), $listing\_location, $default\_uri );
1325
}
1326
}
1327
1328
// C. Listing region
1329
if ( strpos( $default\_uri, '%listing-region%' ) !== false || strpos( $default\_uri, '%listing\_region%' ) !== false ) {
1330
$listing\_region\_terms = wp\_get\_object\_terms( $element->ID, 'region' );
1331
$listing\_region\_term = ( ! is\_wp\_error( $listing\_region\_terms ) && ! empty( $listing\_region\_terms ) && is\_object( $listing\_region\_terms\[0\] ) ) ? Permalink\_Manager\_Helper\_Functions::get\_lowest\_element( $listing\_region\_terms\[0\], $listing\_region\_terms ) : "";
1332
1333
if ( ! empty( $listing\_region\_term ) ) {
1334
$listing\_region = Permalink\_Manager\_Helper\_Functions::get\_term\_full\_slug( $listing\_region\_term, $listing\_region\_terms, 2 );
1335
$listing\_region = Permalink\_Manager\_Helper\_Functions::sanitize\_title( $listing\_region, true );
1336
1337
$default\_uri = str\_replace( array( '%listing-region%', '%listing\_region%' ), $listing\_region, $default\_uri );
1338
}
1339
}
1340
1341
// D. Listing category
1342
if ( strpos( $default\_uri, '%listing-category%' ) !== false || strpos( $default\_uri, '%listing\_category%' ) !== false ) {
1343
$listing\_category\_terms = wp\_get\_object\_terms( $element->ID, 'job\_listing\_category' );
1344
$listing\_category\_term = ( ! is\_wp\_error( $listing\_category\_terms ) && ! empty( $listing\_category\_terms ) && is\_object( $listing\_category\_terms\[0\] ) ) ? Permalink\_Manager\_Helper\_Functions::get\_lowest\_element( $listing\_category\_terms\[0\], $listing\_category\_terms ) : "";
1345
1346
if ( ! empty( $listing\_category\_term ) ) {
1347
$listing\_category = Permalink\_Manager\_Helper\_Functions::get\_term\_full\_slug( $listing\_category\_term, $listing\_category\_terms, 2 );
1348
$listing\_category = Permalink\_Manager\_Helper\_Functions::sanitize\_title( $listing\_category, true );
1349
1350
$default\_uri = str\_replace( array( '%listing-category%', '%listing\_category%' ), $listing\_category, $default\_uri );
1351
}
1352
}
1353
1354
return $default\_uri;
1355
}
1356
1357
/\*\*
1358
\* 13B. Set the default custom permalink for the listing item when it is created
1359
\*
1360
\* @param int $post\_id
1361
\*/
1362
function ml\_set\_listing\_uri( $post\_id ) {
1084
1363
global $permalink\_manager\_uris;
1085
1364
1086
// Use only for "listing" post type & custom permalink
1087
if(empty($element->post\_type) || $element->post\_type !== 'job\_listing') { return $default\_uri; }
1088
1089
// A1. Listing type
1090
if(strpos($default\_uri, '%listing-type%') !== false || strpos($default\_uri, '%listing\_type%') !== false) {
1091
if(class\_exists('MyListing\\Src\\Listing')) {
1092
$listing\_type\_post = MyListing\\Src\\Listing::get($element);
1093
$listing\_type = (is\_object($listing\_type\_post) && !empty($listing\_type\_post->type)) ? $listing\_type\_post->type->get\_permalink\_name() : '';
1094
} else {
1095
$listing\_type\_slug = get\_post\_meta($element->ID, '\_case27\_listing\_type', true);
1096
$listing\_type\_post = get\_page\_by\_path($listing\_type\_slug, OBJECT, 'case27\_listing\_type');
1097
1098
if(!empty($listing\_type\_post)) {
1099
$listing\_type\_post\_settings = get\_post\_meta($listing\_type\_post->ID, 'case27\_listing\_type\_settings\_page', true);
1100
$listing\_type\_post\_settings = (is\_serialized($listing\_type\_post\_settings)) ? unserialize($listing\_type\_post\_settings) : array();
1101
1102
$listing\_type = (!empty($listing\_type\_post\_settings\['permalink'\])) ? $listing\_type\_post\_settings\['permalink'\] : $listing\_type\_post->post\_name;
1103
}
1104
}
1105
1106
if(!empty($listing\_type)) {
1107
$default\_uri = str\_replace(array('%listing-type%', '%listing\_type%'), Permalink\_Manager\_Helper\_Functions::sanitize\_title($listing\_type, true), $default\_uri);
1108
}
1109
}
1110
1111
// A2. Listing type (slug)
1112
if(strpos($default\_uri, '%listing-type-slug%') !== false || strpos($default\_uri, '%listing\_type\_slug%') !== false || strpos($default\_uri, '%case27\_listing\_type%') !== false) {
1113
$listing\_type = get\_post\_meta($element->ID, '\_case27\_listing\_type', true);
1114
1115
if(!empty($listing\_type)) {
1116
$listing\_type = Permalink\_Manager\_Helper\_Functions::sanitize\_title($listing\_type, true);
1117
$default\_uri = str\_replace(array('%listing-type-slug%', '%listing\_type\_slug%', '%case27\_listing\_type%'), $listing\_type, $default\_uri);
1118
}
1119
}
1120
1121
// B. Listing location
1122
if(strpos($default\_uri, '%listing-location%') !== false || strpos($default\_uri, '%listing\_location%') !== false) {
1123
$listing\_location = get\_post\_meta($element->ID, '\_job\_location', true);
1124
1125
if(!empty($listing\_location)) {
1126
$listing\_location = Permalink\_Manager\_Helper\_Functions::sanitize\_title($listing\_location, true);
1127
$default\_uri = str\_replace(array('%listing-location%', '%listing\_location%'), $listing\_location, $default\_uri);
1128
}
1129
}
1130
1131
// C. Listing region
1132
if(strpos($default\_uri, '%listing-region%') !== false || strpos($default\_uri, '%listing\_region%') !== false) {
1133
$listing\_region\_terms = wp\_get\_object\_terms($element->ID, 'region');
1134
$listing\_region\_term = (!is\_wp\_error($listing\_region\_terms) && !empty($listing\_region\_terms) && is\_object($listing\_region\_terms\[0\])) ? Permalink\_Manager\_Helper\_Functions::get\_lowest\_element($listing\_region\_terms\[0\], $listing\_region\_terms) : "";
1135
1136
if(!empty($listing\_region\_term)) {
1137
$listing\_region = Permalink\_Manager\_Helper\_Functions::get\_term\_full\_slug($listing\_region\_term, $listing\_region\_terms, 2, false);
1138
$listing\_region = Permalink\_Manager\_Helper\_Functions::sanitize\_title($listing\_region, true);
1139
1140
$default\_uri = str\_replace(array('%listing-region%', '%listing\_region%'), $listing\_region, $default\_uri);
1141
}
1142
}
1143
1144
// D. Listing category
1145
if(strpos($default\_uri, '%listing-category%') !== false || strpos($default\_uri, '%listing\_category%') !== false) {
1146
$listing\_category\_terms = wp\_get\_object\_terms($element->ID, 'job\_listing\_category');
1147
$listing\_category\_term = (!is\_wp\_error($listing\_category\_terms) && !empty($listing\_category\_terms) && is\_object($listing\_category\_terms\[0\])) ? Permalink\_Manager\_Helper\_Functions::get\_lowest\_element($listing\_category\_terms\[0\], $listing\_category\_terms) : "";
1148
1149
if(!empty($listing\_category\_term)) {
1150
$listing\_category = Permalink\_Manager\_Helper\_Functions::get\_term\_full\_slug($listing\_category\_term, $listing\_category\_terms, 2, false);
1151
$listing\_category = Permalink\_Manager\_Helper\_Functions::sanitize\_title($listing\_category, true);
1152
1153
$default\_uri = str\_replace(array('%listing-category%', '%listing\_category%'), $listing\_category, $default\_uri);
1154
}
1155
}
1156
1157
return $default\_uri;
1158
}
1159
1160
function ml\_set\_listing\_uri($post\_id) {
1161
global $permalink\_manager\_uris;
1162
1163
if(!empty($permalink\_manager\_uris)) {
1164
$default\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri($post\_id);
1165
1166
if($default\_uri) {
1167
$permalink\_manager\_uris\[$post\_id\] = $default\_uri;
1168
update\_option('permalink-manager-uris', $permalink\_manager\_uris);
1169
}
1170
}
1171
}
1172
1173
function ml\_detect\_archives($query, $old\_query) {
1174
if(function\_exists('mylisting\_custom\_taxonomies') && empty($\_POST\['submit\_job'\])) {
1175
$explore\_page\_id = get\_option('options\_general\_explore\_listings\_page', false);
1176
if(empty($explore\_page\_id)) { return $query; }
1365
if ( ! empty( $permalink\_manager\_uris ) ) {
1366
$default\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri( $post\_id );
1367
1368
if ( $default\_uri ) {
1369
$permalink\_manager\_uris\[ $post\_id \] = $default\_uri;
1370
update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
1371
}
1372
}
1373
}
1374
1375
/\*\*
1376
\* 13C. If the user is on a MyListing archive page submitting a job, redirect the user to the Explore Listings page
1377
\*
1378
\* @param array $query The query object.
1379
\* @param array $old\_query The original query array.
1380
\*
1381
\* @return array The new query array is being returned if the explore\_tab property is present. Otherwise, the original query is returned.
1382
\*/
1383
function ml\_detect\_archives( $query, $old\_query ) {
1384
if ( function\_exists( 'mylisting\_custom\_taxonomies' ) && empty( $\_POST\['submit\_job'\] ) ) {
1385
$explore\_page\_id = get\_option( 'options\_general\_explore\_listings\_page', false );
1386
if ( empty( $explore\_page\_id ) ) {
1387
return $query;
1388
}
1177
1389
1178
1390
// 1. Set-up new query array variable
…
…
1184
1396
$ml\_taxonomies = mylisting\_custom\_taxonomies();
1185
1397
1186
if(!empty($ml\_taxonomies) && is\_array($ml\_taxonomies)) {
1187
$ml\_taxonomies = array\_keys($ml\_taxonomies);
1188
1189
foreach($ml\_taxonomies as $taxonomy) {
1190
if(!empty($query\[$taxonomy\]) && empty($\_GET\[$taxonomy\])) {
1191
$new\_query\["explore\_tab"\] \= $taxonomy;
1398
if ( ! empty( $ml\_taxonomies ) && is\_array( $ml\_taxonomies ) ) {
1399
$ml\_taxonomies = array\_keys( $ml\_taxonomies );
1400
1401
foreach ( $ml\_taxonomies as $taxonomy ) {
1402
if ( ! empty( $query\[ $taxonomy \] ) && empty( $\_GET\[ $taxonomy \] ) ) {
1403
$new\_query\["explore\_tab"\] \= $taxonomy;
1192
1404
$new\_query\["explore\_{$taxonomy}"\] = $query\['term'\];
1193
1405
}
…
…
1197
1409
// 2b. Check if any MyListing query var was detected
1198
1410
$ml\_query\_vars = array(
1199
'explore\_tag' \=> 'tags',
1200
'explore\_region' \=> 'regions',
1411
'explore\_tag' \=> 'tags',
1412
'explore\_region' \=> 'regions',
1201
1413
'explore\_category' => 'categories'
1202
1414
);
1203
1415
1204
foreach($ml\_query\_vars as $query\_var => $explore\_tab) {
1205
if(!empty($old\_query\[$query\_var\]) && empty($\_GET\[$query\_var\])) {
1206
$new\_query\[$query\_var\] = $old\_query\[$query\_var\];
1416
foreach ( $ml\_query\_vars as $query\_var => $explore\_tab ) {
1417
if ( ! empty( $old\_query\[ $query\_var \] ) && empty( $\_GET\[ $query\_var \] ) ) {
1418
$new\_query\[ $query\_var \] = $old\_query\[ $query\_var \];
1207
1419
$new\_query\["explore\_tab"\] = $explore\_tab;
1208
1420
}
…
…
1210
1422
}
1211
1423
1212
return (!empty($new\_query\["explore\_tab"\])) ? $new\_query : $query;
1213
}
1214
1215
/\*\*
1216
\* 14. bbPress
1217
\*/
1218
function bbpress\_endpoints($endpoints, $all = true) {
1219
$bbpress\_endpoints = array();
1424
return ( ! empty( $new\_query\["explore\_tab"\] ) ) ? $new\_query : $query;
1425
}
1426
1427
/\*\*
1428
\* 14A. Add the bbPress endpoints to the list of endpoints that are supported by the plugin
1429
\*
1430
\* @param string $endpoints
1431
\* @param bool $all Whether to return all endpoints or just the bbPress ones
1432
\*
1433
\* @return string|array
1434
\*/
1435
function bbpress\_endpoints( $endpoints, $all = true ) {
1436
$bbpress\_endpoints = array();
1220
1437
$bbpress\_endpoints\[\] = bbp\_get\_edit\_slug();
1221
// $bbpress\_endpoints\[\] = bbp\_get\_paged\_slug();
1222
1223
return ($all) ? $endpoints . "|" . implode("|", $bbpress\_endpoints) : $bbpress\_endpoints;
1224
}
1225
1438
1439
return ( $all ) ? $endpoints . "|" . implode( "|", $bbpress\_endpoints ) : $bbpress\_endpoints;
1440
}
1441
1442
/\*\*
1443
\* 14B. If the query contains the edit endpoint, then set the appropriate bbPress query variable
1444
\*/
1226
1445
function bbpress\_detect\_endpoints() {
1227
1446
global $wp\_query;
1228
1447
1229
if(!empty($wp\_query->query)) {
1448
if ( ! empty( $wp\_query->query ) ) {
1230
1449
$edit\_endpoint = bbp\_get\_edit\_slug();
1231
1450
1232
if(isset($wp\_query->query\[$edit\_endpoint\])) {
1233
if(isset($wp\_query->query\['forum'\])) {
1451
if ( isset( $wp\_query->query\[ $edit\_endpoint \] ) ) {
1452
if ( isset( $wp\_query->query\['forum'\] ) ) {
1234
1453
$wp\_query->bbp\_is\_forum\_edit = true;
1235
} else if(isset($wp\_query->query\['topic'\])) {
1454
} else if ( isset( $wp\_query->query\['topic'\] ) ) {
1236
1455
$wp\_query->bbp\_is\_topic\_edit = true;
1237
} else if(isset($wp\_query->query\['reply'\])) {
1456
} else if ( isset( $wp\_query->query\['reply'\] ) ) {
1238
1457
$wp\_query->bbp\_is\_reply\_edit = true;
1239
1458
}
…
…
1243
1462
1244
1463
/\*\*
1245
\* 15. Dokan
1246
\*\*/
1247
function dokan\_endpoints($endpoints) {
1464
\* 15A. Add the endpoint "edit" used by Dokan to the endpoints array supported by Permalink Manager
1465
\*
1466
\* @param string $endpoints
1467
\*
1468
\* @return string
1469
\*/
1470
function dokan\_endpoints( $endpoints ) {
1248
1471
return "{$endpoints}|edit|edit-account";
1249
1472
}
1250
1473
1474
/\*\*
1475
\* 15B. Check if the current page is a Dokan page, and if so, adjust the query variables to disable the canonical redirect
1476
\*/
1251
1477
function dokan\_detect\_endpoints() {
1252
1478
global $post, $wp\_query, $wp, $pm\_query;
1253
1479
1254
1480
// Check if Dokan is activated
1255
if(!function\_exists('dokan\_get\_option') || is\_admin() || empty($pm\_query\['id'\])) { return; }
1481
if ( ! function\_exists( 'dokan\_get\_option' ) || is\_admin() || empty( $pm\_query\['id'\] ) ) {
1482
return;
1483
}
1256
1484
1257
1485
// Get Dokan dashboard page id
1258
$dashboard\_page = dokan\_get\_option('dashboard', 'dokan\_pages');
1486
$dashboard\_page = dokan\_get\_option( 'dashboard', 'dokan\_pages' );
1259
1487
1260
1488
// Stop the redirect
1261
if(!empty($dashboard\_page) && !empty($post->ID) && ($post->ID == $dashboard\_page)) {
1489
if ( ! empty( $dashboard\_page ) && ! empty( $post->ID ) && ( $post->ID == $dashboard\_page ) ) {
1262
1490
$wp->query\_vars\['do\_not\_redirect'\] = 1;
1263
1491
1264
1492
// Detect Dokan shortcode
1265
if(empty($pm\_query\['endpoint'\])) {
1493
if ( empty( $pm\_query\['endpoint'\] ) ) {
1266
1494
$wp->query\_vars\['page'\] = 1;
1267
} else if(isset($wp->query\_vars\['page'\])) {
1268
unset($wp->query\_vars\['page'\]);
1495
} else if ( isset( $wp->query\_vars\['page'\] ) ) {
1496
unset( $wp->query\_vars\['page'\] );
1269
1497
}
1270
1498
}
1271
1499
1272
1500
// 2. Support "Edit Product" pages
1273
if(isset($wp\_query->query\_vars\['edit'\])) {
1274
$wp\_query->query\_vars\['edit'\] \= 1;
1501
if ( isset( $wp\_query->query\_vars\['edit'\] ) ) {
1502
$wp\_query->query\_vars\['edit'\] \= 1;
1275
1503
$wp\_query->query\_vars\['do\_not\_redirect'\] = 1;
1276
1504
}
…
…
1278
1506
1279
1507
/\*\*
1280
\* 16. GeoDirectory
1281
\*/
1282
public function geodir\_custom\_fields($default\_uri, $native\_slug, $element, $slug, $native\_uri) {
1283
global $permalink\_manager\_uris;
1284
1508
\* 16. Replace in the default permalink format the unique permastructure tags available for GeoDirectory plugin
1509
\*
1510
\* @param string $default\_uri The default permalink for the element.
1511
\* @param string $native\_slug The native slug of the post type.
1512
\* @param WP\_Post $element The post object.
1513
\* @param string $slug The slug of the post type.
1514
\* @param bool $native\_uri
1515
\*
1516
\* @return string
1517
\*/
1518
public function geodir\_custom\_fields( $default\_uri, $native\_slug, $element, $slug, $native\_uri ) {
1285
1519
// Use only for GeoDirectory post types & custom permalinks
1286
if(empty($element->post\_type) || (strpos($element->post\_type, 'gd\_') === false) || $native\_uri || !function\_exists('geodir\_get\_post\_info')) { return $default\_uri; }
1520
if ( empty( $element->post\_type ) || ( strpos( $element->post\_type, 'gd\_' ) === false ) || $native\_uri || ! function\_exists( 'geodir\_get\_post\_info' ) ) {
1521
return $default\_uri;
1522
}
1287
1523
1288
1524
// Get place info
1289
$place\_data = geodir\_get\_post\_info($element->ID);
1525
$place\_data = geodir\_get\_post\_info( $element->ID );
1290
1526
1291
1527
// A. Category
1292
if(strpos($default\_uri, '%category%') !== false) {
1293
$place\_category\_terms = wp\_get\_object\_terms($element->ID, 'gd\_placecategory');
1294
$place\_category\_term \= (!is\_wp\_error($place\_category\_terms) && !empty($place\_category\_terms) && is\_object($place\_category\_terms\[0\])) ? Permalink\_Manager\_Helper\_Functions::get\_lowest\_element($place\_category\_terms\[0\], $place\_category\_terms) : "";
1295
1296
if(!empty($place\_category\_term)) {
1297
$place\_category = Permalink\_Manager\_Helper\_Functions::get\_term\_full\_slug($place\_category\_term, $place\_category\_term, 2, false);
1298
$place\_category = Permalink\_Manager\_Helper\_Functions::sanitize\_title($place\_category, true);
1299
1300
$default\_uri = str\_replace('%category%', $place\_category, $default\_uri);
1528
if ( strpos( $default\_uri, '%category%' ) !== false ) {
1529
$place\_category\_terms = wp\_get\_object\_terms( $element->ID, 'gd\_placecategory' );
1530
$place\_category\_term = ( ! is\_wp\_error( $place\_category\_terms ) && ! empty( $place\_category\_terms ) && is\_object( $place\_category\_terms\[0\] ) ) ? Permalink\_Manager\_Helper\_Functions::get\_lowest\_element( $place\_category\_terms\[0\], $place\_category\_terms ) : "";
1531
1532
if ( ! empty( $place\_category\_term ) && is\_a( $place\_category\_term, 'WP\_Term' ) ) {
1533
$place\_category = Permalink\_Manager\_Helper\_Functions::get\_term\_full\_slug( $place\_category\_term, '', 2 );
1534
$place\_category = Permalink\_Manager\_Helper\_Functions::sanitize\_title( $place\_category, true );
1535
1536
$default\_uri = str\_replace( '%category%', $place\_category, $default\_uri );
1301
1537
}
1302
1538
}
1303
1539
1304
1540
// B. Country
1305
if(strpos($default\_uri, '%country%') !== false && !empty($place\_data->country)) {
1306
$place\_country = Permalink\_Manager\_Helper\_Functions::sanitize\_title($place\_data->country, true);
1307
$default\_uri \= str\_replace('%country%', $place\_country, $default\_uri);
1541
if ( strpos( $default\_uri, '%country%' ) !== false && ! empty( $place\_data->country ) ) {
1542
$place\_country = Permalink\_Manager\_Helper\_Functions::sanitize\_title( $place\_data->country, true );
1543
$default\_uri = str\_replace( '%country%', $place\_country, $default\_uri );
1308
1544
}
1309
1545
1310
1546
// C. Region
1311
if(strpos($default\_uri, '%region%') !== false && !empty($place\_data->region)) {
1312
$place\_region = Permalink\_Manager\_Helper\_Functions::sanitize\_title($place\_data->region, true);
1313
$default\_uri \= str\_replace('%region%', $place\_region, $default\_uri);
1547
if ( strpos( $default\_uri, '%region%' ) !== false && ! empty( $place\_data->region ) ) {
1548
$place\_region = Permalink\_Manager\_Helper\_Functions::sanitize\_title( $place\_data->region, true );
1549
$default\_uri = str\_replace( '%region%', $place\_region, $default\_uri );
1314
1550
}
1315
1551
1316
1552
// D. City
1317
if(strpos($default\_uri, '%city%') !== false && !empty($place\_data->city)) {
1318
$place\_city \= Permalink\_Manager\_Helper\_Functions::sanitize\_title($place\_data->city, true);
1319
$default\_uri = str\_replace('%city%', $place\_city, $default\_uri);
1553
if ( strpos( $default\_uri, '%city%' ) !== false && ! empty( $place\_data->city ) ) {
1554
$place\_city = Permalink\_Manager\_Helper\_Functions::sanitize\_title( $place\_data->city, true );
1555
$default\_uri = str\_replace( '%city%', $place\_city, $default\_uri );
1320
1556
}
1321
1557
…
…
1324
1560
1325
1561
/\*\*
1326
\* 17. BasePress
1327
\*/
1328
function kb\_adjust\_query($query, $old\_query, $uri\_parts, $pm\_query, $content\_type) {
1329
$knowledgebase\_options = get\_option('basepress\_settings');
1330
$knowledgebase\_page = (!empty($knowledgebase\_options\['entry\_page'\])) ? $knowledgebase\_options\['entry\_page'\] : '';
1562
\* 17. Adjust the query if BasePress page is detected
1563
\*
1564
\* @param array $query The query object.
1565
\* @param array $old\_query The original query array.
1566
\* @param array $uri\_parts An array of the URI parts.
1567
\* @param array $pm\_query
1568
\* @param string $content\_type
1569
\*
1570
\* @return array
1571
\*/
1572
function kb\_adjust\_query( $query, $old\_query, $uri\_parts, $pm\_query, $content\_type ) {
1573
$knowledgebase\_options = get\_option( 'basepress\_settings' );
1574
$knowledgebase\_page = ( ! empty( $knowledgebase\_options\['entry\_page'\] ) ) ? $knowledgebase\_options\['entry\_page'\] : '';
1331
1575
1332
1576
// A. Knowledgebase category
1333
if(isset($query\['knowledgebase\_cat'\]) && !empty($pm\_query\['id'\]) && strpos($pm\_query\['id'\], 'tax-') !== false) {
1334
$query\['post\_type'\] = 'knowledgebase';
1335
unset($query\['taxonomy'\]);
1336
unset($query\['term'\]);
1337
1338
$term\_id = intval(preg\_replace("/\[^0-9\]/", "", $pm\_query\['id'\]));
1339
$term = get\_term($term\_id);
1340
1341
if(empty($term->parent)) {
1342
$query\['is\_knowledgebase\_product'\] = 1;
1343
}
1344
}
1345
// B. Knowledgebase main page
1346
else if(!empty($knowledgebase\_page) && !empty($pm\_query\['id'\]) && $pm\_query\['id'\] == $knowledgebase\_page) {
1577
if ( isset( $query\['knowledgebase\_cat'\] ) && ! empty( $pm\_query\['id'\] ) ) {
1578
$kb\_category = $query\['knowledgebase\_cat'\];
1579
1580
$query = array(
1581
'post\_type' => 'knowledgebase',
1582
'knowledgebase\_items' => $kb\_category
1583
);
1584
1585
// Disable the canonical redirect function included in BasePress
1586
add\_filter('basepress\_canonical\_redirect', '\_\_return\_false');
1587
} // B. Knowledgebase main page
1588
else if ( ! empty( $knowledgebase\_page ) && ! empty( $pm\_query\['id'\] ) && $pm\_query\['id'\] == $knowledgebase\_page ) {
1347
1589
$query = array(
1348
1590
'page\_id' => $knowledgebase\_page
…
…
1354
1596
1355
1597
/\*\*
1356
\* 18. Ultimate Member
1357
\*/
1358
public function um\_detect\_extra\_pages($uri\_parts) {
1598
\* 18. Detect the extra pages created by Ultimate Member plugin
1599
\*
1600
\* @param array $uri\_parts
1601
\*
1602
\* @return array
1603
\*/
1604
public function um\_detect\_extra\_pages( $uri\_parts ) {
1359
1605
global $permalink\_manager\_uris;
1360
1606
1361
$request\_url = trim("{$uri\_parts\['uri'\]}/{$uri\_parts\['endpoint\_value'\]}", "/");
1362
$um\_pages \= array(
1363
'user' \=> 'um\_user',
1607
$request\_url = trim( "{$uri\_parts\['uri'\]}/{$uri\_parts\['endpoint\_value'\]}", "/" );
1608
$um\_pages \= array(
1609
'user' \=> 'um\_user',
1364
1610
'account' => 'um\_tab',
1365
1611
);
1366
1612
1367
1613
// Detect UM permalinks
1368
foreach($um\_pages as $um\_page => $query\_var) {
1369
$um\_page\_id = UM()->config()->permalinks\[$um\_page\];
1614
foreach ( $um\_pages as $um\_page => $query\_var ) {
1615
$um\_page\_id = UM()->config()->permalinks\[ $um\_page \];
1370
1616
// Support for WPML/Polylang
1371
$um\_page\_id = (!empty($uri\_parts\['lang'\])) ? apply\_filters('wpml\_object\_id', $um\_page\_id, 'page', true, $uri\_parts\['lang'\]) : $um\_page\_id;
1372
1373
if(!empty($um\_page\_id) && !empty($permalink\_manager\_uris\[$um\_page\_id\])) {
1374
$user\_page\_uri = preg\_quote($permalink\_manager\_uris\[$um\_page\_id\], '/');
1375
preg\_match("/^({$user\_page\_uri})\\/(\[^\\/\]+)?$/", $request\_url, $parts);
1376
1377
if(!empty($parts\[2\])) {
1378
$uri\_parts\['uri'\] \= $parts\[1\];
1379
$uri\_parts\['endpoint'\] \= $query\_var;
1380
$uri\_parts\['endpoint\_value'\] = Permalink\_Manager\_Helper\_Functions::sanitize\_title($parts\[2\], null, null, false);
1617
$um\_page\_id = ( ! empty( $uri\_parts\['lang'\] ) ) ? apply\_filters( 'wpml\_object\_id', $um\_page\_id, 'page', true, $uri\_parts\['lang'\] ) : $um\_page\_id;
1618
1619
if ( ! empty( $um\_page\_id ) && ! empty( $permalink\_manager\_uris\[ $um\_page\_id \] ) ) {
1620
$user\_page\_uri = preg\_quote( $permalink\_manager\_uris\[ $um\_page\_id \], '/' );
1621
preg\_match( "/^({$user\_page\_uri})\\/(\[^\\/\]+)?$/", $request\_url, $parts );
1622
1623
if ( ! empty( $parts\[2\] ) ) {
1624
$uri\_parts\['uri'\] \= $parts\[1\];
1625
$uri\_parts\['endpoint'\] \= $query\_var;
1626
$uri\_parts\['endpoint\_value'\] = Permalink\_Manager\_Helper\_Functions::sanitize\_title( $parts\[2\], null, null, false );
1381
1627
}
1382
1628
}
…
…
1387
1633
1388
1634
/\*\*
1389
\* 19. WooCommerce Subscriptions
1390
\*/
1391
function fix\_wcs\_subscription\_links($permalink, $post, $old\_permalink) {
1392
if(!empty($post->post\_type) && $post->post\_type == 'product' && strpos($old\_permalink, 'switch-subscription=') !== false) {
1393
$query\_arg = parse\_url($old\_permalink, PHP\_URL\_QUERY);
1635
\* 19. Keep the query strings appended to the product permalinks by WooCommerce Subscriptions
1636
\*
1637
\* @param string $permalink
1638
\* @param WP\_Post $post
1639
\* @param string $old\_permalink
1640
\*
1641
\* @return string
1642
\*/
1643
function fix\_wcs\_subscription\_links( $permalink, $post, $old\_permalink ) {
1644
if ( ! empty( $post->post\_type ) && $post->post\_type == 'product' && strpos( $old\_permalink, 'switch-subscription=' ) !== false ) {
1645
$query\_arg = parse\_url( $old\_permalink, PHP\_URL\_QUERY );
1394
1646
$permalink = "{$permalink}?{$query\_arg}";
1395
1647
}
…
…
1399
1651
1400
1652
/\*\*
1401
\* 20. Store Locator - CSV Manager
1402
\*/
1403
public function wpsl\_regenerate\_after\_import($meta\_id, $post\_id, $meta\_key, $meta\_value) {
1653
\* 20. Regenerate the default permalink for the post after the custom permalink is imported by Store Locator - CSV Manager
1654
\*
1655
\* @param int $meta\_id The ID of the metadata entry.
1656
\* @param int $post\_id The ID of the post that the metadata is for.
1657
\* @param string $meta\_key The meta key of the metadata being updated.
1658
\* @param mixed $meta\_value The value of the meta key.
1659
\*/
1660
public function wpsl\_regenerate\_after\_import( $meta\_id, $post\_id, $meta\_key, $meta\_value ) {
1404
1661
global $permalink\_manager\_uris;
1405
1662
1406
if(strpos($meta\_key, 'wpsl\_') !== false && isset($\_POST\['wpsl\_csv\_import\_nonce'\])) {
1407
$default\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri($post\_id);
1408
1409
if($default\_uri) {
1410
$permalink\_manager\_uris\[$post\_id\] = $default\_uri;
1411
update\_option('permalink-manager-uris', $permalink\_manager\_uris);
1663
if ( strpos( $meta\_key, 'wpsl\_' ) !== false && isset( $\_POST\['wpsl\_csv\_import\_nonce'\] ) ) {
1664
$default\_uri = Permalink\_Manager\_URI\_Functions\_Post::get\_default\_post\_uri( $post\_id );
1665
1666
if ( $default\_uri ) {
1667
$permalink\_manager\_uris\[ $post\_id \] = $default\_uri;
1668
update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
1412
1669
}
1413
1670
}
permalink-manager/trunk/includes/core/permalink-manager-uri-functions-post.php
r2818142
r2833667
2
2
3
3
/\*\*
4
\* Additional functions used in classes and another subclasses
5
\*/
6
class Permalink\_Manager\_URI\_Functions\_Post extends Permalink\_Manager\_Class {
4
\* A set of functions for processing and applying the custom permalink to posts
5
\*/
6
class Permalink\_Manager\_URI\_Functions\_Post {
7
7
8
8
public function \_\_construct() {
9
add\_action( 'admin\_init', array($this, 'admin\_init'), 99, 3);
10
11
add\_filter( '\_get\_page\_link', array($this, 'custom\_post\_permalinks'), 99, 2);
12
add\_filter( 'page\_link', array($this, 'custom\_post\_permalinks'), 99, 2);
13
add\_filter( 'post\_link', array($this, 'custom\_post\_permalinks'), 99, 2);
14
add\_filter( 'post\_type\_link', array($this, 'custom\_post\_permalinks'), 99, 2);
15
add\_filter( 'attachment\_link', array($this, 'custom\_post\_permalinks'), 99, 2);
16
17
add\_filter( 'permalink\_manager\_uris', array($this, 'exclude\_homepage'), 99);
9
add\_action( 'admin\_init', array( $this, 'admin\_init' ), 99, 3 );
10
11
add\_filter( '\_get\_page\_link', array( $this, 'custom\_post\_permalinks' ), 99, 2 );
12
add\_filter( 'page\_link', array( $this, 'custom\_post\_permalinks' ), 99, 2 );
13
add\_filter( 'post\_link', array( $this, 'custom\_post\_permalinks' ), 99, 2 );
14
add\_filter( 'post\_type\_link', array( $this, 'custom\_post\_permalinks' ), 99, 2 );
15
add\_filter( 'attachment\_link', array( $this, 'custom\_post\_permalinks' ), 99, 2 );
16
17
add\_filter( 'permalink\_manager\_uris', array( $this, 'exclude\_homepage' ), 99 );
18
18
19
19
// Support url\_to\_postid
20
add\_filter( 'url\_to\_postid', array($this, 'url\_to\_postid'), 999);
21
22
/\*\*
23
\* URI Editor
24
\*/
25
add\_filter( 'get\_sample\_permalink\_html', array($this, 'edit\_uri\_box'), 10, 5 );
26
27
add\_action( 'save\_post', array($this, 'update\_post\_uri'), 99, 1);
28
add\_action( 'edit\_attachment', array($this, 'update\_post\_uri'), 99, 1 );
29
add\_action( 'wp\_insert\_post', array($this, 'new\_post\_uri'), 99, 1 );
30
add\_action( 'add\_attachment', array($this, 'new\_post\_uri'), 99, 1 );
31
add\_action( 'wp\_trash\_post', array($this, 'remove\_post\_uri'), 100, 1 );
32
add\_action( 'delete\_post', array($this, 'remove\_post\_uri'), 100, 1 );
33
34
add\_action( 'quick\_edit\_custom\_box', array($this, 'quick\_edit\_column\_form'), 99, 3);
35
}
36
37
/\*\*
38
\* Init
20
add\_filter( 'url\_to\_postid', array( $this, 'url\_to\_postid' ), 999 );
21
22
add\_filter( 'get\_sample\_permalink\_html', array( $this, 'edit\_uri\_box' ), 10, 5 );
23
24
add\_action( 'save\_post', array( $this, 'update\_post\_uri' ), 99, 1 );
25
add\_action( 'edit\_attachment', array( $this, 'update\_post\_uri' ), 99, 1 );
26
add\_action( 'wp\_insert\_post', array( $this, 'new\_post\_uri' ), 99, 1 );
27
add\_action( 'add\_attachment', array( $this, 'new\_post\_uri' ), 99, 1 );
28
add\_action( 'wp\_trash\_post', array( $this, 'remove\_post\_uri' ), 100, 1 );
29
add\_action( 'delete\_post', array( $this, 'remove\_post\_uri' ), 100, 1 );
30
31
add\_action( 'quick\_edit\_custom\_box', array( $this, 'quick\_edit\_column\_form' ), 99, 3 );
32
}
33
34
/\*\*
35
\* Add "Current URI" input field to "Quick Edit" form
39
36
\*/
40
37
function admin\_init() {
41
$post\_types = Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array();
42
43
// Add "URI Editor" to "Quick Edit" for all post\_types
44
foreach($post\_types as $post\_type => $label) {
45
add\_filter( "manage\_{$post\_type}\_posts\_columns" , array($this, 'quick\_edit\_column') );
46
add\_filter( "manage\_{$post\_type}\_posts\_custom\_column" , array($this, 'quick\_edit\_column\_content'), 10, 2 );
47
}
48
}
49
50
/\*\*
51
\* Change permalinks for posts, pages & custom post types
52
\*/
53
static function custom\_post\_permalinks($permalink, $post) {
54
global $wp\_rewrite, $permalink\_manager\_uris, $permalink\_manager\_options, $permalink\_manager\_ignore\_permalink\_filters;
38
$post\_types = Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array();
39
40
// Add "URI Editor" to "Quick Edit" for all post\_types
41
foreach ( $post\_types as $post\_type => $label ) {
42
add\_filter( "manage\_{$post\_type}\_posts\_columns", array( $this, 'quick\_edit\_column' ) );
43
add\_filter( "manage\_{$post\_type}\_posts\_custom\_column", array( $this, 'quick\_edit\_column\_content' ), 10, 2 );
44
}
45
}
46
47
/\*\*
48
\* Apply the custom permalinks to the posts
49
\*
50
\* @param string $permalink
51
\* @param WP\_Post|int $post
52
\*
53
\* @return string
54
\*/
55
static function custom\_post\_permalinks( $permalink, $post ) {
56
global $permalink\_manager\_uris, $permalink\_manager\_options, $permalink\_manager\_ignore\_permalink\_filters;
55
57
56
58
// Do not filter permalinks in Customizer
57
if((function\_exists('is\_customize\_preview') && is\_customize\_preview()) || !empty($\_REQUEST\['customize\_url'\])) { return $permalink; }
59
if ( function\_exists( 'is\_customize\_preview' ) && is\_customize\_preview() ) {
60
return $permalink;
61
}
58
62
59
63
// Do not filter in WPML String Editor
60
if(!empty($\_REQUEST\['icl\_ajx\_action'\]) && $\_REQUEST\['icl\_ajx\_action'\] == 'icl\_st\_save\_translation') { return $permalink; }
64
if ( ! empty( $\_REQUEST\['icl\_ajx\_action'\] ) && $\_REQUEST\['icl\_ajx\_action'\] == 'icl\_st\_save\_translation' ) {
65
return $permalink;
66
}
61
67
62
68
// WPML (prevent duplicated posts)
63
if(!empty($\_REQUEST\['trid'\]) && !empty($\_REQUEST\['skip\_sitepress\_actions'\])) { return $permalink; }
69
if ( ! empty( $\_REQUEST\['trid'\] ) && ! empty( $\_REQUEST\['skip\_sitepress\_actions'\] ) ) {
70
return $permalink;
71
}
64
72
65
73
// Do not run when metaboxes are loaded with Gutenberg
66
if(!empty($\_REQUEST\['meta-box-loader'\]) && empty($\_POST\['custom\_uri'\])) { return $permalink; }
74
if ( ! empty( $\_REQUEST\['meta-box-loader'\] ) && empty( $\_POST\['custom\_uri'\] ) ) {
75
return $permalink;
76
}
67
77
68
78
// Do not filter if $permalink\_manager\_ignore\_permalink\_filters global is set
69
if(!empty($permalink\_manager\_ignore\_permalink\_filters)) { return $permalink; }
70
71
$post = (is\_integer($post)) ? get\_post($post) : $post;
79
if ( ! empty( $permalink\_manager\_ignore\_permalink\_filters ) ) {
80
return $permalink;
81
}
82
83
$post = ( is\_integer( $post ) ) ? get\_post( $post ) : $post;
72
84
73
85
// Do not run if post object is invalid
74
if(empty($post) || empty($post->ID) || empty($post->post\_type)) { return $permalink; }
86
if ( empty( $post ) || empty( $post->ID ) || empty( $post->post\_type ) ) {
87
return $permalink;
88
}
75
89
76
90
// Start with homepage URL
77
$home\_url = Permalink\_Manager\_Helper\_Functions::get\_permalink\_base($post);
91
$home\_url = Permalink\_Manager\_Helper\_Functions::get\_permalink\_base( $post );
78
92
79
93
// Check if the post is excluded
80
if(!empty($post->post\_type) && Permalink\_Manager\_Helper\_Functions::is\_post\_excluded($post) && $post->post\_type !== 'attachment') { return $permalink; }
94
if ( ! empty( $post->post\_type ) && Permalink\_Manager\_Helper\_Functions::is\_post\_excluded( $post ) && $post->post\_type !== 'attachment' ) {
95
return $permalink;
96
}
81
97
82
98
// 2A. Do not change permalink of frontpage
83
if(Permalink\_Manager\_Helper\_Functions::is\_front\_page($post->ID)) {
99
if ( Permalink\_Manager\_Helper\_Functions::is\_front\_page( $post->ID ) ) {
84
100
return $permalink;
85
}
86
// 2B. Do not change permalink for drafts and future posts (+ remove trailing slash from them)
87
else if(in\_array($post->post\_status, array('draft', 'pending', 'auto-draft', 'future'))) {
101
} // 2B. Do not change permalink for drafts and future posts (+ remove trailing slash from them)
102
else if ( in\_array( $post->post\_status, array( 'draft', 'pending', 'auto-draft', 'future' ) ) ) {
88
103
return $permalink;
89
104
}
…
…
93
108
94
109
// 4. Filter only the posts with custom permalink assigned
95
if(isset($permalink\_manager\_uris\[$post->ID\])) {
110
if ( isset( $permalink\_manager\_uris\[ $post->ID \] ) ) {
96
111
// Encode URI?
97
if(!empty($permalink\_manager\_options\['general'\]\['decode\_uris'\])) {
98
$permalink = "{$home\_url}/" . rawurldecode("/{$permalink\_manager\_uris\[$post->ID\]}");
112
if ( ! empty( $permalink\_manager\_options\['general'\]\['decode\_uris'\] ) ) {
113
$permalink = "{$home\_url}/" . rawurldecode( "/{$permalink\_manager\_uris\[$post->ID\]}" );
99
114
} else {
100
$permalink = "{$home\_url}/" . Permalink\_Manager\_Helper\_Functions::encode\_uri("{$permalink\_manager\_uris\[$post->ID\]}");
101
}
102
} else if($post->post\_type == 'attachment' && $post->post\_parent > 0 && $post->post\_parent != $post->ID && !empty($permalink\_manager\_uris\[$post->post\_parent\])) {
115
$permalink = "{$home\_url}/" . Permalink\_Manager\_Helper\_Functions::encode\_uri( "{$permalink\_manager\_uris\[$post->ID\]}" );
116
}
117
} else if ( $post->post\_type == 'attachment' && $post->post\_parent > 0 && $post->post\_parent != $post->ID && ! empty( $permalink\_manager\_uris\[ $post->post\_parent \] ) ) {
103
118
$permalink = "{$home\_url}/{$permalink\_manager\_uris\[$post->post\_parent\]}/attachment/{$post->post\_name}";
104
} else if(!empty($permalink\_manager\_options\['general'\]\['decode\_uris'\])) {
105
$permalink = "{$home\_url}/" . rawurldecode("/{$permalink}");
119
} else if ( ! empty( $permalink\_manager\_options\['general'\]\['decode\_uris'\] ) ) {
120
$permalink = "{$home\_url}/" . rawurldecode( "/{$permalink}" );
106
121
}
107
122
108
123
// 5. Allow to filter (do not filter in Customizer)
109
if(!(function\_exists('is\_customize\_preview') && is\_customize\_preview())) {
110
return apply\_filters('permalink\_manager\_filter\_final\_post\_permalink', $permalink, $post, $old\_permalink);
124
if ( ! ( function\_exists( 'is\_customize\_preview' ) && is\_customize\_preview() ) ) {
125
return apply\_filters( 'permalink\_manager\_filter\_final\_post\_permalink', $permalink, $post, $old\_permalink );
111
126
} else {
112
127
return $old\_permalink;
…
…
115
130
116
131
/\*\*
117
\* Check if the provided slug is unique and then update it with SQL query.
118
\*/
119
static function update\_slug\_by\_id($slug, $id) {
132
\* Check if the provided slug is unique and then update it with SQL query.
133
\*
134
\* @param string $slug
135
\* @param int $id
136
\*
137
\* @return string
138
\*/
139
static function update\_slug\_by\_id( $slug, $id ) {
120
140
global $wpdb;
121
141
122
142
// Update slug and make it unique
123
$slug = (empty($slug)) ? get\_the\_title($id) : $slug;
124
$slug = sanitize\_title($slug);
125
126
$new\_slug = wp\_unique\_post\_slug($slug, $id, get\_post\_status($id), get\_post\_type($id), 0);
127
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post\_name = %s WHERE ID = %d", $new\_slug, $id));
143
$slug = ( empty( $slug ) ) ? get\_the\_title( $id ) : $slug;
144
$slug = sanitize\_title( $slug );
145
146
$new\_slug = wp\_unique\_post\_slug( $slug, $id, get\_post\_status( $id ), get\_post\_type( $id ), 0 );
147
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->posts} SET post\_name = %s WHERE ID = %d", $new\_slug, $id ) );
128
148
129
149
return $new\_slug;
…
…
131
151
132
152
/\*\*
133
\* Get the active URI
134
\*/
135
public static function get\_post\_uri($post\_id, $native\_uri = false, $no\_fallback = false) {
153
\* Get the currently used custom permalink (or default/empty URI)
154
\*
155
\* @param int $post\_id
156
\* @param bool $native\_uri
157
\* @param bool $no\_fallback
158
\*
159
\* @return string
160
\*/
161
public static function get\_post\_uri( $post\_id, $native\_uri = false, $no\_fallback = false ) {
136
162
global $permalink\_manager\_uris;
137
163
138
164
// Check if input is post object
139
$post\_id = (isset($post\_id->ID)) ? $post\_id->ID : $post\_id;
140
141
if(!empty($permalink\_manager\_uris\[$post\_id\])) {
142
$final\_uri = $permalink\_manager\_uris\[$post\_id\];
143
} else if(!$no\_fallback) {
144
$final\_uri = self::get\_default\_post\_uri($post\_id, $native\_uri);
165
$post\_id = ( isset( $post\_id->ID ) ) ? $post\_id->ID : $post\_id;
166
167
if ( ! empty( $permalink\_manager\_uris\[ $post\_id \] ) ) {
168
$final\_uri = $permalink\_manager\_uris\[ $post\_id \];
169
} else if ( ! $no\_fallback ) {
170
$final\_uri = self::get\_default\_post\_uri( $post\_id, $native\_uri );
145
171
} else {
146
172
$final\_uri = '';
…
…
151
177
152
178
/\*\*
153
\* Get the default (not overwritten by the user) or native URI (unfiltered)
154
\*/
155
public static function get\_default\_post\_uri($post, $native\_uri = false, $check\_if\_disabled = false) {
179
\* Get the default custom permalink (not overwritten by the user) or native URI (unfiltered)
180
\*
181
\* @param WP\_Post|int $post
182
\* @param bool $native\_uri
183
\* @param bool $check\_if\_disabled
184
\*
185
\* @return string
186
\*/
187
public static function get\_default\_post\_uri( $post, $native\_uri = false, $check\_if\_disabled = false ) {
156
188
global $permalink\_manager\_options, $permalink\_manager\_uris, $permalink\_manager\_permastructs, $wp\_post\_types, $icl\_adjust\_id\_url\_filter\_off;
157
189
…
…
160
192
161
193
// Load all bases & post
162
$post = is\_object($post) ? $post : get\_post($post);
194
$post = is\_object( $post ) ? $post : get\_post( $post );
163
195
164
196
// Check if post ID is defined (and front page permalinks should be empty)
165
if(empty($post->ID) || Permalink\_Manager\_Helper\_Functions::is\_front\_page($post->ID)) { return ''; }
166
167
$post\_id = $post->ID;
197
if ( empty( $post->ID ) || Permalink\_Manager\_Helper\_Functions::is\_front\_page( $post->ID ) ) {
198
return '';
199
}
200
168
201
$post\_type = $post->post\_type;
169
$post\_name = (empty($post->post\_name)) ? Permalink\_Manager\_Helper\_Functions::sanitize\_title($post->post\_title) : $post->post\_name;
202
$post\_name = ( empty( $post->post\_name ) ) ? Permalink\_Manager\_Helper\_Functions::sanitize\_title( $post->post\_title ) : $post->post\_name;
170
203
171
204
// 1A. Check if post type is allowed
172
if($check\_if\_disabled && Permalink\_Manager\_Helper\_Functions::is\_post\_type\_disabled($post\_type)) { return ''; }
205
if ( $check\_if\_disabled && Permalink\_Manager\_Helper\_Functions::is\_post\_type\_disabled( $post\_type ) ) {
206
return '';
207
}
173
208
174
209
// 1A. Get the native permastructure
175
if($post\_type == 'attachment') {
176
$parent\_page = ($post->post\_parent > 0 && $post->post\_parent != $post->ID) ? get\_post($post->post\_parent) : false;
177
178
if(!empty($parent\_page->ID)) {
179
$parent\_page\_uri = (!empty($permalink\_manager\_uris\[$parent\_page->ID\])) ? $permalink\_manager\_uris\[$parent\_page->ID\] : get\_page\_uri($parent\_page->ID);
210
if ( $post\_type == 'attachment' ) {
211
$parent\_page = ( $post->post\_parent > 0 && $post->post\_parent != $post->ID ) ? get\_post( $post->post\_parent ) : false;
212
213
if ( ! empty( $parent\_page->ID ) ) {
214
$parent\_page\_uri = ( ! empty( $permalink\_manager\_uris\[ $parent\_page->ID \] ) ) ? $permalink\_manager\_uris\[ $parent\_page->ID \] : get\_page\_uri( $parent\_page->ID );
180
215
} else {
181
216
$parent\_page\_uri = "";
182
217
}
183
218
184
$native\_permastructure = ($parent\_page) ? trim($parent\_page\_uri, "/") . "/attachment" : "";
219
$native\_permastructure = ( $parent\_page ) ? trim( $parent\_page\_uri, "/" ) . "/attachment" : "";
185
220
} else {
186
$native\_permastructure = Permalink\_Manager\_Helper\_Functions::get\_default\_permastruct($post\_type);
221
$native\_permastructure = Permalink\_Manager\_Helper\_Functions::get\_default\_permastruct( $post\_type );
187
222
}
188
223
189
224
// 1B. Get the permastructure
190
if($native\_uri) {
225
if ( $native\_uri ) {
191
226
$permastructure = $native\_permastructure;
192
227
} else {
193
$permastructure = (!empty($permalink\_manager\_permastructs\['post\_types'\]\[$post\_type\])) ? $permalink\_manager\_permastructs\['post\_types'\]\[$post\_type\] : $native\_permastructure;
194
$permastructure = apply\_filters('permalink\_manager\_filter\_permastructure', $permastructure, $post);
228
$permastructure = ( ! empty( $permalink\_manager\_permastructs\['post\_types'\]\[ $post\_type \] ) ) ? $permalink\_manager\_permastructs\['post\_types'\]\[ $post\_type \] : $native\_permastructure;
229
$permastructure = apply\_filters( 'permalink\_manager\_filter\_permastructure', $permastructure, $post );
195
230
}
196
231
197
232
// 1C. Set the permastructure
198
$default\_base = (!empty($permastructure)) ? trim($permastructure, '/') : "";
233
$default\_base = ( ! empty( $permastructure ) ) ? trim( $permastructure, '/' ) : "";
199
234
200
235
// 2A. Get the date
201
$date \= explode(" ", date('Y m d H i s', strtotime($post->post\_date)));
202
$monthname = sanitize\_title(date\_i18n('F', strtotime($post->post\_date)));
236
$date = explode( " ", date( 'Y m d H i s', strtotime( $post->post\_date ) ) );
237
$monthname = sanitize\_title( date\_i18n( 'F', strtotime( $post->post\_date ) ) );
203
238
204
239
// 2B. Get the author (if needed)
205
240
$author = '';
206
if(strpos($default\_base, '%author%') !== false) {
207
$authordata = get\_userdata($post->post\_author);
208
$author \= $authordata->user\_nicename;
241
if ( strpos( $default\_base, '%author%' ) !== false ) {
242
$authordata = get\_userdata( $post->post\_author );
243
$author \= $authordata->user\_nicename;
209
244
}
210
245
211
246
// 2C. Get the post type slug
212
if(!empty($wp\_post\_types\[$post\_type\])) {
213
if(!empty($wp\_post\_types\[$post\_type\]->rewrite\['slug'\])) {
214
$post\_type\_slug = $wp\_post\_types\[$post\_type\]->rewrite\['slug'\];
215
} else if(is\_string($wp\_post\_types\[$post\_type\]->rewrite)) {
216
$post\_type\_slug = $wp\_post\_types\[$post\_type\]->rewrite;
217
}
218
}
219
220
$post\_type\_slug = (!empty($post\_type\_slug)) ? $post\_type\_slug : $post\_type;
221
$post\_type\_slug = apply\_filters('permalink\_manager\_filter\_post\_type\_slug', $post\_type\_slug, $post, $post\_type);
222
$post\_type\_slug = preg\_replace('/(%(\[^%\]+)%\\/?)/', '', $post\_type\_slug);
247
if ( ! empty( $wp\_post\_types\[ $post\_type \] ) ) {
248
if ( ! empty( $wp\_post\_types\[ $post\_type \]->rewrite\['slug'\] ) ) {
249
$post\_type\_slug = $wp\_post\_types\[ $post\_type \]->rewrite\['slug'\];
250
} else if ( is\_string( $wp\_post\_types\[ $post\_type \]->rewrite ) ) {
251
$post\_type\_slug = $wp\_post\_types\[ $post\_type \]->rewrite;
252
}
253
}
254
255
$post\_type\_slug = ( ! empty( $post\_type\_slug ) ) ? $post\_type\_slug : $post\_type;
256
$post\_type\_slug = apply\_filters( 'permalink\_manager\_filter\_post\_type\_slug', $post\_type\_slug, $post, $post\_type );
257
$post\_type\_slug = preg\_replace( '/(%(\[^%\]+)%\\/?)/', '', $post\_type\_slug );
223
258
224
259
// 3B. Get the full slug
225
$post\_name \= Permalink\_Manager\_Helper\_Functions::remove\_slashes($post\_name);
226
$custom\_slug \= $full\_custom\_slug = Permalink\_Manager\_Helper\_Functions::force\_custom\_slugs($post\_name, $post);
260
$post\_name = Permalink\_Manager\_Helper\_Functions::remove\_slashes( $post\_name );
261
$custom\_slug = $full\_custom\_slug = Permalink\_Manager\_Helper\_Functions::force\_custom\_slugs( $post\_name, $post );
227
262
$full\_native\_slug = $post\_name;
228
263
229
264
// 3A. Fix for hierarchical CPT (start)
230
265
// $full\_slug = (is\_post\_type\_hierarchical($post\_type)) ? get\_page\_uri($post) : $post\_name;
231
if($post->ancestors && is\_post\_type\_hierarchical($post\_type)) {
232
foreach($post->ancestors as $parent) {
233
$parent = get\_post($parent);
234
if($parent && $parent->post\_name) {
266
if ( $post->ancestors && is\_post\_type\_hierarchical( $post\_type ) ) {
267
foreach ( $post->ancestors as $parent ) {
268
$parent = get\_post( $parent );
269
if ( $parent && $parent->post\_name ) {
235
270
$full\_native\_slug = $parent->post\_name . '/' . $full\_native\_slug;
236
$full\_custom\_slug = Permalink\_Manager\_Helper\_Functions::force\_custom\_slugs($parent->post\_name, $parent) . '/' . $full\_custom\_slug;
237
}
238
}
271
$full\_custom\_slug = Permalink\_Manager\_Helper\_Functions::force\_custom\_slugs( $parent->post\_name, $parent ) . '/' . $full\_custom\_slug;
272
}
273
}
239
274
}
240
275
241
276
// 3B. Allow filter the default slug (only custom permalinks)
242
if(!$native\_uri) {
243
$full\_slug = apply\_filters('permalink\_manager\_filter\_default\_post\_slug', $full\_custom\_slug, $post, $post\_name);
277
if ( ! $native\_uri ) {
278
$full\_slug = apply\_filters( 'permalink\_manager\_filter\_default\_post\_slug', $full\_custom\_slug, $post, $post\_name );
244
279
} else {
245
280
$full\_slug = $full\_native\_slug;
246
281
}
247
282
248
$post\_type\_tag = Permalink\_Manager\_Helper\_Functions::get\_post\_tag($post\_type);
283
$post\_type\_tag = Permalink\_Manager\_Helper\_Functions::get\_post\_tag( $post\_type );
249
284
250
285
// 3C. Get the standard tags and replace them with their values
251
$tags \= array('%year%', '%monthnum%', '%monthname%', '%day%', '%hour%', '%minute%', '%second%', '%post\_id%', '%author%', '%post\_type%');
252
$tags\_replacements = array($date\[0\], $date\[1\], $monthname, $date\[2\], $date\[3\], $date\[4\], $date\[5\], $post->ID, $author, $post\_type\_slug);
253
$default\_uri \= str\_replace($tags, $tags\_replacements, $default\_base);
286
$tags = array( '%year%', '%monthnum%', '%monthname%', '%day%', '%hour%', '%minute%', '%second%', '%post\_id%', '%author%', '%post\_type%' );
287
$tags\_replacements = array( $date\[0\], $date\[1\], $monthname, $date\[2\], $date\[3\], $date\[4\], $date\[5\], $post->ID, $author, $post\_type\_slug );
288
$default\_uri = str\_replace( $tags, $tags\_replacements, $default\_base );
254
289
255
290
// 3D. Get the slug tags
256
$slug\_tags \= array($post\_type\_tag, "%postname%", "%postname\_flat%", "%{$post\_type}\_flat%", "%native\_slug%");
257
$slug\_tags\_replacement = array($full\_slug, $full\_slug, $custom\_slug, $custom\_slug, $full\_native\_slug);
291
$slug\_tags = array( $post\_type\_tag, "%postname%", "%postname\_flat%", "%{$post\_type}\_flat%", "%native\_slug%" );
292
$slug\_tags\_replacement = array( $full\_slug, $full\_slug, $custom\_slug, $custom\_slug, $full\_native\_slug );
258
293
259
294
// 3E. Check if any post tag is present in custom permastructure
260
$do\_not\_append\_slug = (!empty($permalink\_manager\_options\['permastructure-settings'\]\['do\_not\_append\_slug'\]\['post\_types'\]\[$post\_type\])) ? true : false;
261
$do\_not\_append\_slug = apply\_filters("permalink\_manager\_do\_not\_append\_slug", $do\_not\_append\_slug, $post\_type, $post);
262
if($do\_not\_append\_slug == false) {
263
foreach($slug\_tags as $tag) {
264
if(strpos($default\_uri, $tag) !== false) {
295
$do\_not\_append\_slug = ( ! empty( $permalink\_manager\_options\['permastructure-settings'\]\['do\_not\_append\_slug'\]\['post\_types'\]\[ $post\_type \] ) ) ? true : false;
296
$do\_not\_append\_slug = apply\_filters( "permalink\_manager\_do\_not\_append\_slug", $do\_not\_append\_slug, $post\_type, $post );
297
if ( ! $do\_not\_append\_slug ) {
298
foreach ( $slug\_tags as $tag ) {
299
if ( strpos( $default\_uri, $tag ) !== false ) {
265
300
$do\_not\_append\_slug = true;
266
301
break;
…
…
269
304
}
270
305
271
// 3F. Replace the post tags with slugs or rppend the slug if no post tag is defined
272
if(!empty($do\_not\_append\_slug)) {
273
$default\_uri = str\_replace($slug\_tags, $slug\_tags\_replacement, $default\_uri);
306
// 3F. Replace the post tags with slugs or append the slug if no post tag is defined
307
if ( ! empty( $do\_not\_append\_slug ) ) {
308
$default\_uri = str\_replace( $slug\_tags, $slug\_tags\_replacement, $default\_uri );
274
309
} else {
275
310
$default\_uri .= "/{$full\_slug}";
…
…
279
314
$taxonomies = get\_taxonomies();
280
315
281
if($taxonomies) {
282
foreach($taxonomies as $taxonomy) {
316
if ( $taxonomies ) {
317
foreach ( $taxonomies as $taxonomy ) {
283
318
// 0. Check if taxonomy tag is present
284
if(strpos($default\_uri, "%{$taxonomy}") === false) { continue; }
285
286
// 1. Reset $replacement variable
287
$replacement = $replacement\_term = "";
288
$terms = wp\_get\_object\_terms($post->ID, $taxonomy);
319
if ( strpos( $default\_uri, "%{$taxonomy}" ) === false ) {
320
continue;
321
}
322
323
// 1. Get terms assigned to this post
324
$terms = wp\_get\_object\_terms( $post->ID, $taxonomy );
289
325
290
326
// 2. Sort the terms
291
if(!empty($terms)) {
292
$terms = wp\_list\_sort(
293
$terms,
294
array(
327
if ( ! empty( $terms ) ) {
328
$terms = wp\_list\_sort( $terms, array(
295
329
'parent' => 'DESC',
296
330
'term\_id' => 'ASC',
297
)
298
);
331
) );
299
332
}
300
333
301
334
// 3A. Try to use Yoast SEO Primary Term
302
$replacement\_term = $primary\_term = Permalink\_Manager\_Helper\_Functions::get\_primary\_term($post->ID, $taxonomy, false);
335
$replacement\_term = Permalink\_Manager\_Helper\_Functions::get\_primary\_term( $post->ID, $taxonomy, false );
303
336
304
337
// 3B. Get the first assigned term to this taxonomy
305
if(empty($replacement\_term)) {
306
$replacement\_term = (!is\_wp\_error($terms) && !empty($terms) && is\_object($terms\[0\])) ? Permalink\_Manager\_Helper\_Functions::get\_lowest\_element($terms\[0\], $terms) : '';
307
$replacement\_term = apply\_filters('permalink\_manager\_filter\_post\_terms', $replacement\_term, $post, $terms, $taxonomy, $native\_uri);
338
if ( empty( $replacement\_term ) ) {
339
$replacement\_term = ( ! is\_wp\_error( $terms ) && ! empty( $terms ) && is\_object( $terms\[0\] ) ) ? Permalink\_Manager\_Helper\_Functions::get\_lowest\_element( $terms\[0\], $terms ) : '';
340
$replacement\_term = apply\_filters( 'permalink\_manager\_filter\_post\_terms', $replacement\_term, $post, $terms, $taxonomy, $native\_uri );
308
341
}
309
342
310
343
// 4A. Custom URI as term base
311
if(!empty($replacement\_term->term\_id) && strpos($default\_uri, "%{$taxonomy}\_custom\_uri%") !== false && !empty($permalink\_manager\_uris\["tax-{$replacement\_term->term\_id}"\])) {
344
if ( ! empty( $replacement\_term->term\_id ) && strpos( $default\_uri, "%{$taxonomy}\_custom\_uri%" ) !== false && ! empty( $permalink\_manager\_uris\["tax-{$replacement\_term->term\_id}"\] ) ) {
312
345
$mode = 1;
313
}
314
// 4B. Hierarhcical term base
315
else if(!empty($replacement\_term->term\_id) && strpos($default\_uri, "%{$taxonomy}\_flat%") === false && strpos($default\_uri, "%{$taxonomy}\_top%") === false && is\_taxonomy\_hierarchical($taxonomy)) {
346
} // 4B. Hierarchical term base
347
else if ( ! empty( $replacement\_term->term\_id ) && strpos( $default\_uri, "%{$taxonomy}\_flat%" ) === false && strpos( $default\_uri, "%{$taxonomy}\_top%" ) === false && is\_taxonomy\_hierarchical( $taxonomy ) ) {
316
348
$mode = 2;
317
}
318
// 4C. Force flat/non-hierarchical term base - get highest level term (if %taxonomy\_top% tag is used)
319
else if(strpos($default\_uri, "%{$taxonomy}\_top%") !== false) {
349
} // 4C. Force flat/non-hierarchical term base - get the highest level term (if %taxonomy\_top% tag is used)
350
else if ( strpos( $default\_uri, "%{$taxonomy}\_top%" ) !== false ) {
320
351
$mode = 3;
321
}
322
// 4D. Force flat/non-hierarchical term base - get lowest level term (if %taxonomy\_flat% tag is used)
352
} // 4D. Force flat/non-hierarchical term base - get the lowest level term (if %taxonomy\_flat% tag is used)
323
353
else {
324
354
$mode = 4;
…
…
326
356
327
357
// Get the replacement slug (custom + native)
328
$replacement \= Permalink\_Manager\_Helper\_Functions::get\_term\_full\_slug($replacement\_term, $terms, $mode, $native\_uri);
329
$native\_replacement = Permalink\_Manager\_Helper\_Functions::get\_term\_full\_slug($replacement\_term, $terms, $mode, true);
358
$replacement = Permalink\_Manager\_Helper\_Functions::get\_term\_full\_slug( $replacement\_term, $terms, $mode, $native\_uri );
359
$native\_replacement = Permalink\_Manager\_Helper\_Functions::get\_term\_full\_slug( $replacement\_term, $terms, $mode, true );
330
360
331
361
// Trim slashes
332
$replacement \= trim($replacement, '/');
333
$native\_replacement = trim($native\_replacement, '/');
362
$replacement = trim( $replacement, '/' );
363
$native\_replacement \= trim( $native\_replacement, '/' );
334
364
335
365
// Filter final category slug
336
$replacement = apply\_filters('permalink\_manager\_filter\_term\_slug', $replacement, $replacement\_term, $post, $terms, $taxonomy, $native\_uri);
366
$replacement = apply\_filters( 'permalink\_manager\_filter\_term\_slug', $replacement, $replacement\_term, $post, $terms, $taxonomy, $native\_uri );
337
367
338
368
// 4. Do the replacement
339
$default\_uri = (!empty($replacement)) ? str\_replace(array("%{$taxonomy}%", "%{$taxonomy}\_flat%", "%{$taxonomy}\_custom\_uri%", "%{$taxonomy}\_top%"), $replacement, $default\_uri) : $default\_uri;
340
$default\_uri = (!empty($native\_replacement)) ? str\_replace("%{$taxonomy}\_native\_slug%", $native\_replacement, $default\_uri) : $default\_uri;
369
$default\_uri = ( ! empty( $replacement ) ) ? str\_replace( array( "%{$taxonomy}%", "%{$taxonomy}\_flat%", "%{$taxonomy}\_custom\_uri%", "%{$taxonomy}\_top%" ), $replacement, $default\_uri ) : $default\_uri;
370
$default\_uri = ( ! empty( $native\_replacement ) ) ? str\_replace( "%{$taxonomy}\_native\_slug%", $native\_replacement, $default\_uri ) : $default\_uri;
341
371
}
342
372
}
…
…
345
375
$icl\_adjust\_id\_url\_filter\_off = false;
346
376
347
return apply\_filters('permalink\_manager\_filter\_default\_post\_uri', $default\_uri, $post->post\_name, $post, $post\_name, $native\_uri);
348
}
349
350
/\*\*
351
\* The homepage should not use URI
352
\*/
353
function exclude\_homepage($uris) {
377
return apply\_filters( 'permalink\_manager\_filter\_default\_post\_uri', $default\_uri, $post->post\_name, $post, $post\_name, $native\_uri );
378
}
379
380
/\*\*
381
\* Exclude the page selected as "Front page"
382
\*
383
\* @param array $uris
384
\*
385
\* @return array
386
\*/
387
function exclude\_homepage( $uris ) {
354
388
// Find the homepage URI
355
$homepage\_id = get\_option('page\_on\_front');
356
357
if(is\_array($uris) && !empty($uris\[$homepage\_id\])) {
358
unset($uris\[$homepage\_id\]);
389
$homepage\_id = get\_option( 'page\_on\_front' );
390
391
if ( is\_array( $uris ) && ! empty( $uris\[ $homepage\_id \] ) ) {
392
unset( $uris\[ $homepage\_id \] );
359
393
}
360
394
…
…
364
398
/\*\*
365
399
\* Support url\_to\_postid
366
\*/
367
public function url\_to\_postid($url) {
400
\*
401
\* @param string $url
402
\*
403
\* @return string
404
\*/
405
public function url\_to\_postid( $url ) {
368
406
global $pm\_query;
369
407
370
408
// Filter only defined URLs
371
if(empty($url)) { return $url; }
409
if ( empty( $url ) || ! is\_array( $pm\_query ) ) {
410
return $url;
411
}
372
412
373
413
// Make sure that $pm\_query global is not changed
374
414
$old\_pm\_query = $pm\_query;
375
$post \= Permalink\_Manager\_Core\_Functions::detect\_post(null, $url, true);
376
$pm\_query \= $old\_pm\_query;
377
378
if(!empty($post->ID)) {
415
$post = Permalink\_Manager\_Core\_Functions::detect\_post( array(), $url, true );
416
$pm\_query \= $old\_pm\_query;
417
418
if ( ! empty( $post->ID ) ) {
379
419
$native\_url = "/?p={$post->ID}";
380
420
}
381
421
382
return (!empty($native\_url)) ? $native\_url : $url;
383
}
384
385
/\*\*
386
\* Bulk tools
422
return ( ! empty( $native\_url ) ) ? $native\_url : $url;
423
}
424
425
/\*\*
426
\* Get array with all post items based on the user-selected settings in the "Bulk tools" form
427
\*
428
\* @return array|false
387
429
\*/
388
430
public static function get\_items() {
…
…
390
432
391
433
// Check if post types & statuses are not empty
392
if(empty($\_POST\['post\_types'\]) || empty($\_POST\['post\_statuses'\])) { return false; }
393
394
$post\_types\_array = ($\_POST\['post\_types'\]);
395
$post\_statuses\_array = ($\_POST\['post\_statuses'\]);
396
$post\_types = implode("', '", $post\_types\_array);
397
$post\_statuses = implode("', '", $post\_statuses\_array);
434
if ( empty( $\_POST\['post\_types'\] ) || empty( $\_POST\['post\_statuses'\] ) ) {
435
return false;
436
}
437
438
$post\_types\_array = array\_map( 'sanitize\_key', $\_POST\['post\_types'\] );
439
$post\_statuses\_array = array\_map( 'sanitize\_key', $\_POST\['post\_statuses'\] );
440
$post\_types = implode( "', '", $post\_types\_array );
441
$post\_statuses = implode( "', '", $post\_statuses\_array );
398
442
399
443
// Filter the posts by IDs
400
444
$where = '';
401
if(!empty($\_POST\['ids'\])) {
445
if ( ! empty( $\_POST\['ids'\] ) ) {
402
446
// Remove whitespaces and prepare array with IDs and/or ranges
403
$ids = esc\_sql(preg\_replace('/\\s\*/m', '', $\_POST\['ids'\]));
404
preg\_match\_all("/(\[\\d\]+(?:-?\[\\d\]+)?)/x", $ids, $groups);
447
$ids = esc\_sql( preg\_replace( '/\\s\*/m', '', $\_POST\['ids'\] ) );
448
preg\_match\_all( "/(\[\\d\]+(?:-?\[\\d\]+)?)/x", $ids, $groups );
405
449
406
450
// Prepare the extra ID filters
407
451
$where .= "AND (";
408
foreach($groups\[0\] as $group) {
409
$where .= ($group == reset($groups\[0\])) ? "" : " OR ";
452
foreach ( $groups\[0\] as $group ) {
453
$where .= ( $group == reset( $groups\[0\] ) ) ? "" : " OR ";
410
454
// A. Single number
411
if(is\_numeric($group)) {
455
if ( is\_numeric( $group ) ) {
412
456
$where .= "(ID = {$group})";
413
}
414
// B. Range
415
else if(substr\_count($group, '-')) {
416
$range\_edges = explode("-", $group);
417
$where .= "(ID BETWEEN {$range\_edges\[0\]} AND {$range\_edges\[1\]})";
457
} // B. Range
458
else if ( substr\_count( $group, '-' ) ) {
459
$range\_edges = explode( "-", $group );
460
$where .= "(ID BETWEEN {$range\_edges\[0\]} AND {$range\_edges\[1\]})";
418
461
}
419
462
}
…
…
422
465
423
466
// Get excluded items
424
$excluded\_posts = (array) apply\_filters('permalink\_manager\_excluded\_post\_ids', array());
425
if(!empty($excluded\_posts)) {
426
$where .= sprintf(" AND ID NOT IN ('%s') ", implode("', '", $excluded\_posts));
467
$excluded\_posts = (array) apply\_filters( 'permalink\_manager\_excluded\_post\_ids', array() );
468
if ( ! empty( $excluded\_posts ) ) {
469
$where .= sprintf( " AND ID NOT IN ('%s') ", implode( "', '", $excluded\_posts ) );
427
470
}
428
471
429
472
// Support for attachments
430
$attachment\_support = (in\_array('attachment', $post\_types\_array)) ? " OR (post\_type = 'attachment')" : "";
473
$attachment\_support = ( in\_array( 'attachment', $post\_types\_array ) ) ? " OR (post\_type = 'attachment')" : "";
431
474
432
475
// Check the auto-update mode
433
476
// A. Allow only user-approved posts
434
if(!empty($permalink\_manager\_options\["general"\]\["auto\_update\_uris"\]) && $permalink\_manager\_options\["general"\]\["auto\_update\_uris"\] == 2) {
477
if ( ! empty( $permalink\_manager\_options\["general"\]\["auto\_update\_uris"\] ) && $permalink\_manager\_options\["general"\]\["auto\_update\_uris"\] == 2 ) {
435
478
$where .= " AND meta\_value IN (1, -1) ";
436
}
437
// B. Allow all posts not disabled by the user
479
} // B. Allow all posts not disabled by the user
438
480
else {
439
481
$where .= " AND (meta\_value IS NULL OR meta\_value IN (1, -1)) ";
…
…
441
483
442
484
// Get the rows before they are altered
443
return $wpdb->get\_results(
444
"SELECT post\_type, post\_title, post\_name, ID FROM {$wpdb->posts} AS p LEFT JOIN {$wpdb->postmeta} AS pm ON pm.post\_ID = p.ID AND pm.meta\_key = 'auto\_update\_uri' WHERE ((post\_status IN ('{$post\_statuses}') AND post\_type IN ('{$post\_types}')){$attachment\_support}) {$where}",
445
ARRAY\_A
446
);
447
}
448
449
/\*\*
450
\* Find & replace (bulk action)
451
\*/
452
public static function find\_and\_replace($chunk = null, $mode = '', $old\_string = '', $new\_string = '') {
453
global $wpdb, $permalink\_manager\_uris;
485
return $wpdb->get\_results( "SELECT post\_type, post\_title, post\_name, ID FROM {$wpdb->posts} AS p LEFT JOIN {$wpdb->postmeta} AS pm ON pm.post\_ID = p.ID AND pm.meta\_key = 'auto\_update\_uri' WHERE ((post\_status IN ('{$post\_statuses}') AND post\_type IN ('{$post\_types}')){$attachment\_support}) {$where}", ARRAY\_A );
486
}
487
488
/\*\*
489
\* Process the custom permalinks or (native slugs) in "Find & replace" tool
490
\*
491
\* @param array $chunk
492
\* @param string $mode
493
\* @param string $old\_string
494
\* @param string $new\_string
495
\*
496
\* @return array|false
497
\*/
498
public static function find\_and\_replace( $chunk = null, $mode = '', $old\_string = '', $new\_string = '' ) {
499
global $permalink\_manager\_uris;
454
500
455
501
// Reset variables
456
502
$updated\_slugs\_count = 0;
457
$updated\_array \= array();
458
$alert\_type = $alert\_content = $errors = '';
503
$updated\_array \= array();
504
$errors = '';
459
505
460
506
// Get the rows before they are altered
461
$posts\_to\_update = ($chunk) ? $chunk : self::get\_items();
507
$posts\_to\_update = ( $chunk ) ? $chunk : self::get\_items();
462
508
463
509
// Now if the array is not empty use IDs from each subarray as a key
464
if($posts\_to\_update && empty($errors)) {
465
foreach ($posts\_to\_update as $row) {
510
if ( $posts\_to\_update && empty( $errors ) ) {
511
foreach ( $posts\_to\_update as $row ) {
466
512
// Get default & native URL
467
$native\_uri \= self::get\_default\_post\_uri($row\['ID'\], true);
468
$default\_uri = self::get\_default\_post\_uri($row\['ID'\]);
513
$native\_uri = self::get\_default\_post\_uri( $row\['ID'\], true );
514
$default\_uri = self::get\_default\_post\_uri( $row\['ID'\] );
469
515
470
516
$old\_post\_name = $old\_slug = $row\['post\_name'\];
471
$old\_uri \= (isset($permalink\_manager\_uris\[$row\['ID'\]\])) ? $permalink\_manager\_uris\[$row\['ID'\]\] : $native\_uri;
517
$old\_uri = ( isset( $permalink\_manager\_uris\[ $row\['ID'\] \] ) ) ? $permalink\_manager\_uris\[ $row\['ID'\] \] : $native\_uri;
472
518
473
519
// Do replacement on slugs (non-REGEX)
474
if(preg\_match("/^\\/.+\\/\[a-z\]\*$/i", $old\_string)) {
475
$regex \= stripslashes(trim(sanitize\_text\_field($\_POST\['old\_string'\]), "/"));
476
$regex \= preg\_quote($regex, '~');
520
if ( preg\_match( "/^\\/.+\\/\[a-z\]\*$/i", $old\_string ) ) {
521
$regex = stripslashes( trim( sanitize\_text\_field( $\_POST\['old\_string'\] ), "/" ) );
522
$regex = preg\_quote( $regex, '~' );
477
523
$pattern = "~{$regex}~";
478
524
479
$new\_post\_name = ($mode == 'slugs') ? preg\_replace($pattern, $new\_string, $old\_post\_name) : $old\_post\_name;
480
$new\_uri \= ($mode != 'slugs') ? preg\_replace($pattern, $new\_string, $old\_uri) : $old\_uri;
525
$new\_post\_name = ( $mode == 'slugs' ) ? preg\_replace( $pattern, $new\_string, $old\_post\_name ) : $old\_post\_name;
526
$new\_uri = ( $mode != 'slugs' ) ? preg\_replace( $pattern, $new\_string, $old\_uri ) : $old\_uri;
481
527
} else {
482
$new\_post\_name = ($mode == 'slugs') ? str\_replace($old\_string, $new\_string, $old\_post\_name) : $old\_post\_name; // Post name is changed only in first mode
483
$new\_uri = ($mode != 'slugs') ? str\_replace($old\_string, $new\_string, $old\_uri) : $old\_uri;
484
}
485
486
// echo "{$old\_uri} - {$new\_uri} - {$native\_uri} - {$default\_uri} \\n";
528
$new\_post\_name = ( $mode == 'slugs' ) ? str\_replace( $old\_string, $new\_string, $old\_post\_name ) : $old\_post\_name; // Post name is changed only in first mode
529
$new\_uri = ( $mode != 'slugs' ) ? str\_replace( $old\_string, $new\_string, $old\_uri ) : $old\_uri;
530
}
487
531
488
532
// Check if native slug should be changed
489
if(($mode == 'slugs') && ($old\_post\_name != $new\_post\_name)) {
490
$new\_slug = self::update\_slug\_by\_id($new\_post\_name, $row\['ID'\]);
491
}
492
493
if(($old\_uri != $new\_uri) || ($old\_post\_name != $new\_post\_name) && !(empty($new\_uri))) {
494
$permalink\_manager\_uris\[$row\['ID'\]\] = trim($new\_uri, '/');
495
$updated\_array\[\] = array('item\_title' => $row\['post\_title'\], 'ID' => $row\['ID'\], 'old\_uri' => $old\_uri, 'new\_uri' => $new\_uri, 'old\_slug' => $old\_slug, 'new\_slug' => $new\_slug);
496
$updated\_slugs\_count++;
497
}
498
499
do\_action('permalink\_manager\_updated\_post\_uri', $row\['ID'\], $new\_uri, $old\_uri, $native\_uri, $default\_uri);
533
if ( ( $mode == 'slugs' ) && ( $old\_post\_name != $new\_post\_name ) ) {
534
$new\_slug = self::update\_slug\_by\_id( $new\_post\_name, $row\['ID'\] );
535
} else {
536
$new\_slug = $new\_post\_name;
537
}
538
539
if ( ( $old\_uri != $new\_uri ) || ( $old\_post\_name != $new\_post\_name ) && ! ( empty( $new\_uri ) ) ) {
540
$permalink\_manager\_uris\[ $row\['ID'\] \] = trim( $new\_uri, '/' );
541
$updated\_array\[\] = array( 'item\_title' => $row\['post\_title'\], 'ID' => $row\['ID'\], 'old\_uri' => $old\_uri, 'new\_uri' => $new\_uri, 'old\_slug' => $old\_slug, 'new\_slug' => $new\_slug );
542
$updated\_slugs\_count ++;
543
}
544
545
do\_action( 'permalink\_manager\_updated\_post\_uri', $row\['ID'\], $new\_uri, $old\_uri, $native\_uri, $default\_uri );
500
546
}
501
547
502
548
// Filter array before saving
503
if(is\_array($permalink\_manager\_uris)) {
504
$permalink\_manager\_uris = array\_filter($permalink\_manager\_uris);
505
update\_option('permalink-manager-uris', $permalink\_manager\_uris);
506
}
507
508
$output = array('updated' => $updated\_array, 'updated\_count' => $updated\_slugs\_count);
549
if ( is\_array( $permalink\_manager\_uris ) ) {
550
$permalink\_manager\_uris = array\_filter( $permalink\_manager\_uris );
551
update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
552
}
553
554
$output = array( 'updated' => $updated\_array, 'updated\_count' => $updated\_slugs\_count );
509
555
wp\_reset\_postdata();
510
556
}
511
557
512
return ($output) ? $output : "";
513
}
514
515
/\*\*
516
\* Regenerate slugs & bases (bulk action)
517
\*/
518
static function regenerate\_all\_permalinks($chunk = null, $mode = '') {
519
global $wpdb, $permalink\_manager\_uris;
558
return ( ! empty( $output ) ) ? $output : false;
559
}
560
561
/\*\*
562
\* Process the custom permalinks or (native slugs) in "Regenerate/reset" tool
563
\*
564
\* @param array $chunk
565
\* @param string $mode
566
\*
567
\* @return array|bool
568
\*/
569
static function regenerate\_all\_permalinks( $chunk = null, $mode = '' ) {
570
global $permalink\_manager\_uris;
520
571
521
572
// Reset variables
522
573
$updated\_slugs\_count = 0;
523
$updated\_array \= array();
524
$alert\_type = $alert\_content = $errors = '';
574
$updated\_array \= array();
575
$errors = '';
525
576
526
577
// Get the rows before they are altered
527
$posts\_to\_update = ($chunk) ? $chunk : self::get\_items();
578
$posts\_to\_update = ( $chunk ) ? $chunk : self::get\_items();
528
579
529
580
// Now if the array is not empty use IDs from each subarray as a key
530
if($posts\_to\_update && empty($errors)) {
531
foreach ($posts\_to\_update as $row) {
581
if ( $posts\_to\_update && empty( $errors ) ) {
582
foreach ( $posts\_to\_update as $row ) {
532
583
// Get default & native URL
533
$native\_uri \= self::get\_default\_post\_uri($row\['ID'\], true);
534
$default\_uri \= self::get\_default\_post\_uri($row\['ID'\]);
584
$native\_uri = self::get\_default\_post\_uri( $row\['ID'\], true );
585
$default\_uri = self::get\_default\_post\_uri( $row\['ID'\] );
535
586
$old\_post\_name = $row\['post\_name'\];
536
$old\_uri \= isset($permalink\_manager\_uris\[$row\['ID'\]\]) ? trim($permalink\_manager\_uris\[$row\['ID'\]\], "/") : '';
537
$correct\_slug \= ($mode == 'slugs') ? sanitize\_title($row\['post\_title'\]) : Permalink\_Manager\_Helper\_Functions::sanitize\_title($row\['post\_title'\]);
587
$old\_uri = isset( $permalink\_manager\_uris\[ $row\['ID'\] \] ) ? trim( $permalink\_manager\_uris\[ $row\['ID'\] \], "/" ) : '';
588
$correct\_slug = ( $mode == 'slugs' ) ? sanitize\_title( $row\['post\_title'\] ) : Permalink\_Manager\_Helper\_Functions::sanitize\_title( $row\['post\_title'\] );
538
589
539
590
// Process URI & slug
540
$new\_slug \= wp\_unique\_post\_slug($correct\_slug, $row\['ID'\], get\_post\_status($row\['ID'\]), get\_post\_type($row\['ID'\]), 0);
541
$new\_post\_name = ($mode == 'slugs') ? $new\_slug : $old\_post\_name; // Post name is changed only in first mode
591
$new\_slug = wp\_unique\_post\_slug( $correct\_slug, $row\['ID'\], get\_post\_status( $row\['ID'\] ), get\_post\_type( $row\['ID'\] ), 0 );
592
$new\_post\_name = ( $mode == 'slugs' ) ? $new\_slug : $old\_post\_name; // Post name is changed only in first mode
542
593
543
594
// Prepare the new URI
544
if($mode == 'slugs') {
545
$new\_uri = ($old\_uri) ? $old\_uri : $native\_uri;
546
} else if($mode == 'native') {
595
if ( $mode == 'slugs' ) {
596
$new\_uri = ( $old\_uri ) ? $old\_uri : $native\_uri;
597
} else if ( $mode == 'native' ) {
547
598
$new\_uri = $native\_uri;
548
599
} else {
…
…
550
601
}
551
602
552
//print\_r("{$old\_uri} - {$new\_uri} - {$native\_uri} - {$default\_uri} / - {$new\_slug} - {$new\_post\_name} \\n");
553
554
603
// Check if native slug should be changed
555
if(($mode == 'slugs') && ($old\_post\_name != $new\_post\_name)) {
556
self::update\_slug\_by\_id($new\_post\_name, $row\['ID'\]);
557
clean\_post\_cache($row\['ID'\]);
558
}
559
560
if(($old\_uri != $new\_uri) || ($old\_post\_name != $new\_post\_name)) {
561
$permalink\_manager\_uris\[$row\['ID'\]\] = $new\_uri;
562
$updated\_array\[\] \= array('item\_title' => $row\['post\_title'\], 'ID' => $row\['ID'\], 'old\_uri' => $old\_uri, 'new\_uri' => $new\_uri, 'old\_slug' => $old\_post\_name, 'new\_slug' => $new\_post\_name);
563
$updated\_slugs\_count++;
564
}
565
566
do\_action('permalink\_manager\_updated\_post\_uri', $row\['ID'\], $new\_uri, $old\_uri, $native\_uri, $default\_uri);
604
if ( ( $mode == 'slugs' ) && ( $old\_post\_name != $new\_post\_name ) ) {
605
self::update\_slug\_by\_id( $new\_post\_name, $row\['ID'\] );
606
clean\_post\_cache( $row\['ID'\] );
607
}
608
609
if ( ( $old\_uri != $new\_uri ) || ( $old\_post\_name != $new\_post\_name ) ) {
610
$permalink\_manager\_uris\[ $row\['ID'\] \] = $new\_uri;
611
$updated\_array\[\] = array( 'item\_title' => $row\['post\_title'\], 'ID' => $row\['ID'\], 'old\_uri' => $old\_uri, 'new\_uri' => $new\_uri, 'old\_slug' => $old\_post\_name, 'new\_slug' => $new\_post\_name );
612
$updated\_slugs\_count ++;
613
}
614
615
do\_action( 'permalink\_manager\_updated\_post\_uri', $row\['ID'\], $new\_uri, $old\_uri, $native\_uri, $default\_uri );
567
616
}
568
617
569
618
// Filter array before saving
570
if(is\_array($permalink\_manager\_uris)) {
571
$permalink\_manager\_uris = array\_filter($permalink\_manager\_uris);
572
update\_option('permalink-manager-uris', $permalink\_manager\_uris);
573
}
574
575
$output = array('updated' => $updated\_array, 'updated\_count' => $updated\_slugs\_count);
619
if ( is\_array( $permalink\_manager\_uris ) ) {
620
$permalink\_manager\_uris = array\_filter( $permalink\_manager\_uris );
621
update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
622
}
623
624
$output = array( 'updated' => $updated\_array, 'updated\_count' => $updated\_slugs\_count );
576
625
wp\_reset\_postdata();
577
626
}
578
627
579
return (!empty($output)) ? $output : "";
580
}
581
582
/\*\*
583
\* Update all slugs & bases (bulk action)
584
\*/
628
return ( ! empty( $output ) ) ? $output : false;
629
}
630
631
/\*\*
632
\* Save the custom permalinks in "Bulk URI Editor" tool
633
\*
634
\* @return array|false
635
\*/
585
636
static public function update\_all\_permalinks() {
586
637
global $permalink\_manager\_uris;
…
…
588
639
// Setup needed variables
589
640
$updated\_slugs\_count = 0;
590
$updated\_array \= array();
641
$updated\_array \= array();
591
642
592
643
$old\_uris = $permalink\_manager\_uris;
593
$new\_uris = isset($\_POST\['uri'\]) ? $\_POST\['uri'\] : array();
644
$new\_uris = isset( $\_POST\['uri'\] ) ? $\_POST\['uri'\] : array();
594
645
595
646
// Double check if the slugs and ids are stored in arrays
596
if (!is\_array($new\_uris)) $new\_uris = explode(',', $new\_uris);
597
598
if (!empty($new\_uris)) {
599
foreach($new\_uris as $id => $new\_uri) {
647
if ( ! is\_array( $new\_uris ) ) {
648
$new\_uris = explode( ',', $new\_uris );
649
}
650
651
if ( ! empty( $new\_uris ) ) {
652
foreach ( $new\_uris as $id => $new\_uri ) {
600
653
// Prepare variables
601
$this\_post = get\_post($id);
602
$updated = '';
654
$this\_post = get\_post( $id );
603
655
604
656
// Get default & native URL
605
$native\_uri = self::get\_default\_post\_uri($id, true);
606
$default\_uri = self::get\_default\_post\_uri($id);
607
608
$old\_uri = isset($old\_uris\[$id\]) ? trim($old\_uris\[$id\], "/") : "";
657
$native\_uri = self::get\_default\_post\_uri( $this\_post, true );
658
$default\_uri = self::get\_default\_post\_uri( $this\_post );
659
$old\_uri = isset( $old\_uris\[ $id \] ) ? trim( $old\_uris\[ $id \], "/" ) : "";
609
660
610
661
// Process new values - empty entries will be treated as default values
611
$new\_uri = Permalink\_Manager\_Helper\_Functions::sanitize\_title($new\_uri);
612
$new\_uri = (!empty($new\_uri)) ? trim($new\_uri, "/") : $default\_uri;
613
$new\_slug = (strpos($new\_uri, '/') !== false) ? substr($new\_uri, strrpos($new\_uri, '/') + 1) : $new\_uri;
614
615
//print\_r("{$old\_uri} - {$new\_uri} - {$native\_uri} - {$default\_uri}\\n");
616
617
if($new\_uri != $old\_uri) {
618
$old\_uris\[$id\] = $new\_uri;
619
$updated\_array\[\] = array('item\_title' => get\_the\_title($id), 'ID' => $id, 'old\_uri' => $old\_uri, 'new\_uri' => $new\_uri);
620
$updated\_slugs\_count++;
621
}
622
623
do\_action('permalink\_manager\_updated\_post\_uri', $id, $new\_uri, $old\_uri, $native\_uri, $default\_uri);
662
$new\_uri = Permalink\_Manager\_Helper\_Functions::sanitize\_title( $new\_uri );
663
$new\_uri = ( ! empty( $new\_uri ) ) ? trim( $new\_uri, "/" ) : $default\_uri;
664
665
if ( $new\_uri != $old\_uri ) {
666
$old\_uris\[ $id \] = $new\_uri;
667
$updated\_array\[\] = array( 'item\_title' => get\_the\_title( $id ), 'ID' => $id, 'old\_uri' => $old\_uri, 'new\_uri' => $new\_uri );
668
$updated\_slugs\_count ++;
669
}
670
671
do\_action( 'permalink\_manager\_updated\_post\_uri', $id, $new\_uri, $old\_uri, $native\_uri, $default\_uri );
624
672
}
625
673
626
674
// Filter array before saving & append the global
627
if(is\_array($permalink\_manager\_uris)) {
628
$permalink\_manager\_uris = array\_filter($old\_uris);
629
update\_option('permalink-manager-uris', $permalink\_manager\_uris);
630
}
631
632
$output = array('updated' => $updated\_array, 'updated\_count' => $updated\_slugs\_count);
633
}
634
635
return ($output) ? $output : "";
636
}
637
638
/\*\*
639
\* Allow to edit URIs from "Edit Post" admin pages
640
\*/
641
function edit\_uri\_box($html, $id, $new\_title, $new\_slug, $post) {
675
if ( is\_array( $permalink\_manager\_uris ) ) {
676
$permalink\_manager\_uris = array\_filter( $old\_uris );
677
update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
678
}
679
680
$output = array( 'updated' => $updated\_array, 'updated\_count' => $updated\_slugs\_count );
681
}
682
683
return ( ! empty( $output ) ) ? $output : false;
684
}
685
686
/\*\*
687
\* Allow to edit URIs from "Edit Post" admin pages
688
\*
689
\* @param string $html
690
\* @param int $id
691
\* @param string $new\_title
692
\* @param string $new\_slug
693
\* @param WP\_Post $post
694
\*
695
\* @return string
696
\*/
697
function edit\_uri\_box( $html, $id, $new\_title, $new\_slug, $post ) {
642
698
global $permalink\_manager\_uris, $permalink\_manager\_options;
643
699
644
700
// Detect auto drafts
645
$autosave = (!empty($new\_title) && empty($new\_slug)) ? true : false;
701
$autosave = ( ! empty( $new\_title ) && empty( $new\_slug ) ) ? true : false;
646
702
647
703
// Check if the post is excluded
648
if(empty($post->post\_type) || Permalink\_Manager\_Helper\_Functions::is\_post\_excluded($post)) { return $html; }
704
if ( empty( $post->post\_type ) || Permalink\_Manager\_Helper\_Functions::is\_post\_excluded( $post ) ) {
705
return $html;
706
}
649
707
650
708
// Ignore drafts
651
if(!empty($permalink\_manager\_options\["general"\]\["ignore\_drafts"\]) && !empty($post->post\_status) && $post->post\_status == 'draft') { return $html; }
709
if ( ! empty( $permalink\_manager\_options\["general"\]\["ignore\_drafts"\] ) && ! empty( $post->post\_status ) && $post->post\_status == 'draft' ) {
710
return $html;
711
}
652
712
653
713
// Stop the hook (if needed)
654
$show\_uri\_editor = apply\_filters("permalink\_manager\_show\_uri\_editor\_post\_{$post->post\_type}", true, $post);
655
if(!$show\_uri\_editor) { return $html; }
656
657
$new\_html = preg\_replace("/^(<strong>(.\*)<\\/strong>)(.\*)/is", "$1 ", $html);
658
$default\_uri = self::get\_default\_post\_uri($id);
659
$native\_uri = self::get\_default\_post\_uri($id, true);
714
$show\_uri\_editor = apply\_filters( "permalink\_manager\_show\_uri\_editor\_post", true, $post, $post->post\_type );
715
if ( ! $show\_uri\_editor ) {
716
return $html;
717
}
718
719
$new\_html = preg\_replace( "/^(<strong>(.\*)<\\/strong>)(.\*)/is", "$1 ", $html );
720
$default\_uri = self::get\_default\_post\_uri( $id );
721
$native\_uri = self::get\_default\_post\_uri( $id, true );
660
722
661
723
// Make sure that home URL ends with slash
662
$home\_url = Permalink\_Manager\_Helper\_Functions::get\_permalink\_base($post);
724
$home\_url = Permalink\_Manager\_Helper\_Functions::get\_permalink\_base( $post );
663
725
664
726
// A. Display original permalink on front-page editor
665
if(Permalink\_Manager\_Helper\_Functions::is\_front\_page($id)) {
666
preg\_match('/href="(\[^"\]+)"/mi', $html, $matches);
667
$sample\_permalink = (!empty($matches\[1\])) ? $matches\[1\] : "";
668
}
669
else {
727
if ( Permalink\_Manager\_Helper\_Functions::is\_front\_page( $id ) ) {
728
preg\_match( '/href="(\[^"\]+)"/mi', $html, $matches );
729
$sample\_permalink = ( ! empty( $matches\[1\] ) ) ? $matches\[1\] : "";
730
} else {
670
731
// B. Do not change anything if post is not saved yet (display sample permalink instead)
671
if($autosave || empty($post->post\_status)) {
732
if ( $autosave || empty( $post->post\_status ) ) {
672
733
$sample\_permalink\_uri = $default\_uri;
673
}
674
// C. Display custom URI if set
734
} // C. Display custom URI if set
675
735
else {
676
$sample\_permalink\_uri = (!empty($permalink\_manager\_uris\[$id\])) ? $permalink\_manager\_uris\[$id\] : $native\_uri;
736
$sample\_permalink\_uri = ( ! empty( $permalink\_manager\_uris\[ $id \] ) ) ? $permalink\_manager\_uris\[ $id \] : $native\_uri;
677
737
}
678
738
679
739
// Decode URI & allow to filter it
680
$sample\_permalink\_uri = apply\_filters('permalink\_manager\_filter\_post\_sample\_uri', rawurldecode($sample\_permalink\_uri), $post);
740
$sample\_permalink\_uri = apply\_filters( 'permalink\_manager\_filter\_post\_sample\_uri', rawurldecode( $sample\_permalink\_uri ), $post );
681
741
682
742
// Prepare the sample & default permalink
683
$sample\_permalink = sprintf("%s/<span class=\\"editable\\">%s</span>", $home\_url, str\_replace("//", "/", $sample\_permalink\_uri));
743
$sample\_permalink = sprintf( "%s/<span class=\\"editable\\">%s</span>", $home\_url, str\_replace( "//", "/", $sample\_permalink\_uri ) );
684
744
685
745
// Allow to filter the sample permalink URL
…
…
688
748
689
749
// Append new HTML output
690
$new\_html .= sprintf("<span class=\\"sample-permalink-span\\"><a id=\\"sample-permalink\\" href=\\"%s\\">%s</a></span> ", strip\_tags($sample\_permalink), $sample\_permalink);
691
$new\_html .= (!$autosave) ? Permalink\_Manager\_Admin\_Functions::display\_uri\_box($post) : "";
750
$new\_html .= sprintf( "<span class=\\"sample-permalink-span\\"><a id=\\"sample-permalink\\" href=\\"%s\\">%s</a></span> ", strip\_tags( $sample\_permalink ), $sample\_permalink );
751
$new\_html .= ( ! $autosave ) ? Permalink\_Manager\_Admin\_Functions::display\_uri\_box( $post ) : "";
692
752
693
753
// Append hidden field with native slug
694
$new\_html .= (!empty($post->post\_name)) ? "<span id=\\"editable-post-name-full\\">{$post->post\_name}</span>" : "";
754
$new\_html .= ( ! empty( $post->post\_name ) ) ? "<span id=\\"editable-post-name-full\\">{$post->post\_name}</span>" : "";
695
755
696
756
return $new\_html;
…
…
698
758
699
759
/\*\*
700
\* "Quick Edit" form
701
\*/
702
function quick\_edit\_column($columns) {
760
\* Add "Current URI" input field to "Quick Edit" form
761
\*
762
\* @param array $columns
763
\*
764
\* @return array mixed
765
\*/
766
function quick\_edit\_column( $columns ) {
703
767
global $current\_screen;
704
768
705
769
// Get post type
706
$post\_type = (!empty($current\_screen->post\_type)) ? $current\_screen->post\_type : false;
770
$post\_type = ( ! empty( $current\_screen->post\_type ) ) ? $current\_screen->post\_type : false;
707
771
708
772
// Check if post type is disabled
709
if($post\_type && Permalink\_Manager\_Helper\_Functions::is\_post\_type\_disabled($post\_type)) { return $columns; }
710
711
return (is\_array($columns)) ? array\_merge($columns, array('permalink-manager-col' => \_\_( 'Current URI', 'permalink-manager'))) : $columns;
712
}
713
714
function quick\_edit\_column\_content($column\_name, $post\_id) {
773
if ( $post\_type && Permalink\_Manager\_Helper\_Functions::is\_post\_type\_disabled( $post\_type ) ) {
774
return $columns;
775
}
776
777
return ( is\_array( $columns ) ) ? array\_merge( $columns, array( 'permalink-manager-col' => \_\_( 'Current URI', 'permalink-manager' ) ) ) : $columns;
778
}
779
780
/\*\*
781
\* Display the URI of the current post in the "Current URI" column
782
\*
783
\* @param string $column\_name The name of the column to display. In this case, we named our column permalink-manager-col.
784
\* @param int $post\_id The ID of the term.
785
\*/
786
function quick\_edit\_column\_content( $column\_name, $post\_id ) {
715
787
global $permalink\_manager\_uris, $permalink\_manager\_options;
716
788
717
if($column\_name == "permalink-manager-col") {
718
$exclude\_drafts = (isset($permalink\_manager\_options\['general'\]\['ignore\_drafts'\])) ? $permalink\_manager\_options\['general'\]\['ignore\_drafts'\] : false;
789
if ( $column\_name == "permalink-manager-col" ) {
790
$exclude\_drafts = ( isset( $permalink\_manager\_options\['general'\]\['ignore\_drafts'\] ) ) ? $permalink\_manager\_options\['general'\]\['ignore\_drafts'\] : false;
719
791
720
792
// A. Disable the "Quick Edit" form for draft posts if "Exclude drafts" option is turned on
721
if($exclude\_drafts && get\_post\_status($post\_id) == 'draft') {
793
if ( $exclude\_drafts && get\_post\_status( $post\_id ) == 'draft' ) {
722
794
$readonly = 1;
723
}
724
// B. Get auto-update settings
795
} // B. Get auto-update settings
725
796
else {
726
$auto\_update\_val = get\_post\_meta($post\_id, "auto\_update\_uri", true);
727
$readonly = (!empty($auto\_update\_val)) ? $auto\_update\_val : $permalink\_manager\_options\["general"\]\["auto\_update\_uris"\];
728
}
729
730
$uri = (!empty($permalink\_manager\_uris\[$post\_id\])) ? rawurldecode($permalink\_manager\_uris\[$post\_id\]) : self::get\_post\_uri($post\_id, true);
731
printf('<span class="permalink-manager-col-uri" data-readonly="%s">%s</span>', intval($readonly), $uri);
732
}
733
}
734
735
function quick\_edit\_column\_form($column\_name, $post\_type, $taxonomy = '') {
736
if(!$taxonomy && $column\_name == 'permalink-manager-col') {
797
$auto\_update\_val = get\_post\_meta( $post\_id, "auto\_update\_uri", true );
798
$readonly = ( ! empty( $auto\_update\_val ) ) ? $auto\_update\_val : $permalink\_manager\_options\["general"\]\["auto\_update\_uris"\];
799
}
800
801
$uri = ( ! empty( $permalink\_manager\_uris\[ $post\_id \] ) ) ? rawurldecode( $permalink\_manager\_uris\[ $post\_id \] ) : self::get\_post\_uri( $post\_id, true );
802
printf( '<span class="permalink-manager-col-uri" data-readonly="%s">%s</span>', intval( $readonly ), $uri );
803
}
804
}
805
806
/\*\*
807
\* Display the simplified URI Editor in "Quick Edit" mode
808
\*
809
\* @param string $column\_name
810
\* @param string $post\_type
811
\* @param string $taxonomy
812
\*/
813
function quick\_edit\_column\_form( $column\_name, $post\_type, $taxonomy = '' ) {
814
if ( ! $taxonomy && $column\_name == 'permalink-manager-col' ) {
737
815
echo Permalink\_Manager\_Admin\_Functions::quick\_edit\_column\_form();
738
816
}
…
…
740
818
741
819
/\*\*
742
\* Update URI when new post is added
743
\*/
744
function new\_post\_uri($post\_id) {
745
global $post, $permalink\_manager\_uris, $permalink\_manager\_options, $permalink\_manager\_before\_sections\_html;
820
\* Set the custom permalink for new term item
821
\*
822
\* @param int $post\_id Term ID.
823
\*/
824
function new\_post\_uri( $post\_id ) {
825
global $post, $permalink\_manager\_uris, $permalink\_manager\_options;
746
826
747
827
// Do not trigger if post is a revision or imported via WP All Import (URI should be set after the post meta is added)
748
if(wp\_is\_post\_revision($post\_id) || (!empty($\_REQUEST\['page'\]) && $\_REQUEST\['page'\] == 'pmxi-admin-import')) { return $post\_id; }
828
if ( wp\_is\_post\_revision( $post\_id ) || ( ! empty( $\_REQUEST\['page'\] ) && $\_REQUEST\['page'\] == 'pmxi-admin-import' ) ) {
829
return;
830
}
749
831
750
832
// Prevent language mismatch in MultilingualPress plugin
751
if(is\_admin() && !empty($post->ID) && $post->ID != $post\_id) { return $post\_id; }
833
if ( is\_admin() && ! empty( $post->ID ) && $post->ID != $post\_id ) {
834
return;
835
}
752
836
753
837
// Stop when products are imported with WooCommerce importer
754
if(!empty($\_REQUEST\['action'\]) && $\_REQUEST\['action'\] == 'woocommerce\_do\_ajax\_product\_import') { return $post\_id; }
755
756
// Do not do anything if post is autosaved
757
if(defined('DOING\_AUTOSAVE') && DOING\_AUTOSAVE) { return $post\_id; }
838
if ( ! empty( $\_REQUEST\['action'\] ) && $\_REQUEST\['action'\] == 'woocommerce\_do\_ajax\_product\_import' ) {
839
return;
840
}
841
842
// Do not do anything if post is auto-saved
843
if ( defined( 'DOING\_AUTOSAVE' ) && DOING\_AUTOSAVE ) {
844
return;
845
}
758
846
759
847
// Do not do anything on in "Bulk Edit"
760
if(!empty($\_REQUEST\['bulk\_edit'\])) { return $post\_id; }
848
if ( ! empty( $\_REQUEST\['bulk\_edit'\] ) ) {
849
return;
850
}
761
851
762
852
// Hotfix
763
if(isset($\_POST\['custom\_uri'\]) || isset($\_POST\['permalink-manager-quick-edit'\]) || isset($permalink\_manager\_uris\[$post\_id\])) { return $post\_id; }
764
765
$post\_object = get\_post($post\_id);
853
if ( isset( $\_POST\['custom\_uri'\] ) || isset( $\_POST\['permalink-manager-quick-edit'\] ) || isset( $permalink\_manager\_uris\[ $post\_id \] ) ) {
854
return;
855
}
856
857
$post\_object = get\_post( $post\_id );
766
858
767
859
// Check if post is allowed
768
if(empty($post\_object->post\_type) || Permalink\_Manager\_Helper\_Functions::is\_post\_excluded($post\_object)) { return $post\_id; }
860
if ( empty( $post\_object->post\_type ) || Permalink\_Manager\_Helper\_Functions::is\_post\_excluded( $post\_object ) ) {
861
return;
862
}
769
863
770
864
// Exclude drafts
771
if(!empty($permalink\_manager\_options\["general"\]\["ignore\_drafts"\]) && !empty($post\_object->post\_status) && $post\_object->post\_status == 'draft') { return $post\_id; }
865
if ( ! empty( $permalink\_manager\_options\["general"\]\["ignore\_drafts"\] ) && ! empty( $post\_object->post\_status ) && $post\_object->post\_status == 'draft' ) {
866
return;
867
}
772
868
773
869
// Ignore menu items
774
if($post\_object->post\_type == 'nav\_menu\_item') { return $post\_id; }
870
if ( $post\_object->post\_type == 'nav\_menu\_item' ) {
871
return;
872
}
775
873
776
874
// Ignore auto-drafts, revisions, removed posts and posts without title
777
if(in\_array($post\_object->post\_status, array('auto-draft', 'trash')) || (strpos($post\_object->post\_name, 'revision-v1') !== false) || empty($post\_object->post\_title) || (!empty($post\_object->post\_name) && $post\_object->post\_name == 'auto-draft')) { return $post\_id; }
875
if ( in\_array( $post\_object->post\_status, array( 'auto-draft', 'trash' ) ) || ( strpos( $post\_object->post\_name, 'revision-v1' ) !== false ) || empty( $post\_object->post\_title ) || ( ! empty( $post\_object->post\_name ) && $post\_object->post\_name == 'auto-draft' ) ) {
876
return;
877
}
778
878
779
879
// Check if the new URIs should be disabled
780
$auto\_update\_uri = (!empty($permalink\_manager\_options\["general"\]\["auto\_update\_uris"\])) ? $permalink\_manager\_options\["general"\]\["auto\_update\_uris"\] : 0;
781
782
$native\_uri = self::get\_default\_post\_uri($post\_id, true);
783
$new\_uri \= self::get\_default\_post\_uri($post\_id);
880
$auto\_update\_uri = ( ! empty( $permalink\_manager\_options\["general"\]\["auto\_update\_uris"\] ) ) ? $permalink\_manager\_options\["general"\]\["auto\_update\_uris"\] : 0;
881
882
$native\_uri = self::get\_default\_post\_uri( $post\_id, true );
883
$new\_uri = self::get\_default\_post\_uri( $post\_id );
784
884
785
885
// Stop the hook (if needed)
786
$allow\_new\_uri = apply\_filters("permalink\_manager\_allow\_new\_post\_uri", true, $post\_object);
787
788
if(!$allow\_new\_uri || (!empty($auto\_update\_uri) && $auto\_update\_uri == 2)) {
886
$allow\_new\_uri = apply\_filters( "permalink\_manager\_allow\_new\_post\_uri", true, $post\_object );
887
888
if ( ! $allow\_new\_uri || ( ! empty( $auto\_update\_uri ) && $auto\_update\_uri == 2 ) ) {
789
889
$uri\_saved = false;
790
} else if(is\_array($permalink\_manager\_uris) && !empty($new\_uri)) {
791
$permalink\_manager\_uris\[$post\_object->ID\] = $new\_uri;
792
$uri\_saved \= update\_option('permalink-manager-uris', $permalink\_manager\_uris);
890
} else if ( is\_array( $permalink\_manager\_uris ) && ! empty( $new\_uri ) ) {
891
$permalink\_manager\_uris\[ $post\_object->ID \] = $new\_uri;
892
$uri\_saved = update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
793
893
} else {
794
894
$uri\_saved = false;
795
895
}
796
896
797
do\_action('permalink\_manager\_new\_post\_uri', $post\_id, $new\_uri, $native\_uri, $uri\_saved);
798
}
799
800
/\*\*
801
\* Update URI from "Edit Post" admin page
802
\*/
803
static public function update\_post\_uri($post\_id) {
804
global $permalink\_manager\_uris, $permalink\_manager\_options, $permalink\_manager\_before\_sections\_html;
897
do\_action( 'permalink\_manager\_new\_post\_uri', $post\_id, $new\_uri, $native\_uri, $uri\_saved );
898
}
899
900
/\*\*
901
\* Update the custom permalink
902
\*
903
\* @param int $post\_id Term ID.
904
\*/
905
static public function update\_post\_uri( $post\_id ) {
906
global $permalink\_manager\_uris, $permalink\_manager\_options;
805
907
806
908
// Verify nonce at first
807
if(!isset($\_POST\['permalink-manager-nonce'\]) || !wp\_verify\_nonce($\_POST\['permalink-manager-nonce'\], 'permalink-manager-edit-uri-box')) { return $post\_id; }
909
if ( ! isset( $\_POST\['permalink-manager-nonce'\] ) || ! wp\_verify\_nonce( $\_POST\['permalink-manager-nonce'\], 'permalink-manager-edit-uri-box' ) ) {
910
return;
911
}
808
912
809
913
// Do not do anything if the field with URI or element ID are not present
810
if(!isset($\_POST\['custom\_uri'\]) || empty($\_POST\['permalink-manager-edit-uri-element-id'\])) { return $post\_id; }
914
if ( ! isset( $\_POST\['custom\_uri'\] ) || empty( $\_POST\['permalink-manager-edit-uri-element-id'\] ) ) {
915
return;
916
}
811
917
812
918
// Hotfix
813
if($\_POST\['permalink-manager-edit-uri-element-id'\] != $post\_id) { return $post\_id; }
814
815
// Do not do anything if post is autosaved
816
if(defined('DOING\_AUTOSAVE') && DOING\_AUTOSAVE) { return $post\_id; }
919
if ( $\_POST\['permalink-manager-edit-uri-element-id'\] != $post\_id ) {
920
return;
921
}
922
923
// Do not do anything if post is auto-saved
924
if ( defined( 'DOING\_AUTOSAVE' ) && DOING\_AUTOSAVE ) {
925
return;
926
}
817
927
818
928
// Do not do anything on in "Bulk Edit" or when the post is imported via WP All Import
819
if(!empty($\_REQUEST\['bulk\_edit'\]) || (!empty($\_REQUEST\['page'\]) && $\_REQUEST\['page'\] == 'pmxi-admin-import')) { return $post\_id; }
929
if ( ! empty( $\_REQUEST\['bulk\_edit'\] ) || ( ! empty( $\_REQUEST\['page'\] ) && $\_REQUEST\['page'\] == 'pmxi-admin-import' ) ) {
930
return;
931
}
820
932
821
933
// Fix for revisions
822
$is\_revision = wp\_is\_post\_revision($post\_id);
823
$post\_id \= ($is\_revision) ? $is\_revision : $post\_id;
824
$post \= get\_post($post\_id);
934
$is\_revision = wp\_is\_post\_revision( $post\_id );
935
$post\_id = ( $is\_revision ) ? $is\_revision : $post\_id;
936
$post = get\_post( $post\_id );
825
937
826
938
// Check if post is allowed
827
if(empty($post->post\_type) || Permalink\_Manager\_Helper\_Functions::is\_post\_excluded($post)) { return $post\_id; }
939
if ( empty( $post->post\_type ) || Permalink\_Manager\_Helper\_Functions::is\_post\_excluded( $post ) ) {
940
return;
941
}
828
942
829
943
// Exclude drafts
830
if(!empty($permalink\_manager\_options\["general"\]\["ignore\_drafts"\]) && !empty($post->post\_status) && $post->post\_status == 'draft') { return $post\_id; }
944
if ( ! empty( $permalink\_manager\_options\["general"\]\["ignore\_drafts"\] ) && ! empty( $post->post\_status ) && $post->post\_status == 'draft' ) {
945
return;
946
}
831
947
832
948
// Ignore auto-drafts, removed posts and posts without title
833
if(in\_array($post->post\_status, array('auto-draft', 'trash')) || empty($post->post\_title)) { return $post\_id; }
949
if ( in\_array( $post->post\_status, array( 'auto-draft', 'trash' ) ) || empty( $post->post\_title ) ) {
950
return;
951
}
834
952
835
953
// Get auto-update URI setting (if empty use global setting)
836
if(!empty($\_POST\["auto\_update\_uri"\])) {
837
$auto\_update\_uri\_current = intval($\_POST\["auto\_update\_uri"\]);
838
} else if(!empty($\_POST\["action"\]) && $\_POST\['action'\] == 'inline-save') {
839
$auto\_update\_uri\_current = get\_post\_meta($post\_id, "auto\_update\_uri", true);
840
}
841
$auto\_update\_uri = (!empty($auto\_update\_uri\_current)) ? $auto\_update\_uri\_current : $permalink\_manager\_options\["general"\]\["auto\_update\_uris"\];
954
if ( ! empty( $\_POST\["auto\_update\_uri"\] ) ) {
955
$auto\_update\_uri\_current = intval( $\_POST\["auto\_update\_uri"\] );
956
} else if ( ! empty( $\_POST\["action"\] ) && $\_POST\['action'\] == 'inline-save' ) {
957
$auto\_update\_uri\_current = get\_post\_meta( $post\_id, "auto\_update\_uri", true );
958
}
959
$auto\_update\_uri = ( ! empty( $auto\_update\_uri\_current ) ) ? $auto\_update\_uri\_current : $permalink\_manager\_options\["general"\]\["auto\_update\_uris"\];
842
960
843
961
// Update the slug (if changed)
844
if(isset($\_POST\['permalink-manager-edit-uri-element-slug'\]) && isset($\_POST\['native\_slug'\]) && ($\_POST\['native\_slug'\] !== $\_POST\['permalink-manager-edit-uri-element-slug'\])) {
962
if ( isset( $\_POST\['permalink-manager-edit-uri-element-slug'\] ) && isset( $\_POST\['native\_slug'\] ) && ( $\_POST\['native\_slug'\] !== $\_POST\['permalink-manager-edit-uri-element-slug'\] ) ) {
845
963
846
964
// Make sure that '\_wp\_old\_slug' is saved
847
if(!empty($\_POST\['post\_name'\]) || (isset($\_POST\['action'\]) && $\_POST\['action'\] == 'pm\_save\_permalink')) {
965
if ( ! empty( $\_POST\['post\_name'\] ) || ( isset( $\_POST\['action'\] ) && $\_POST\['action'\] == 'pm\_save\_permalink' ) ) {
848
966
$post\_before = $post;
849
967
850
// Clone the instance of WP\_Post object
851
$post\_after \= unserialize(serialize($post));
852
$post\_after->post\_name = sanitize\_title($\_POST\['native\_slug'\]);
853
854
wp\_check\_for\_changed\_slugs($post\_id, $post\_after, $post\_before);
855
}
856
857
self::update\_slug\_by\_id($\_POST\['native\_slug'\], $post\_id);
858
clean\_post\_cache($post\_id);
859
}
860
861
$default\_uri = self::get\_default\_post\_uri($post\_id);
862
$native\_uri \= self::get\_default\_post\_uri($post\_id, true);
863
$old\_uri \= (isset($permalink\_manager\_uris\[$post->ID\])) ? $permalink\_manager\_uris\[$post->ID\] : $native\_uri;
968
// Clone the instance of WP\_Post object
969
$post\_after = unserialize( serialize( $post ) );
970
$post\_after->post\_name = sanitize\_title( $\_POST\['native\_slug'\] );
971
972
wp\_check\_for\_changed\_slugs( $post\_id, $post\_after, $post\_before );
973
}
974
975
self::update\_slug\_by\_id( $\_POST\['native\_slug'\], $post\_id );
976
clean\_post\_cache( $post\_id );
977
}
978
979
$default\_uri = self::get\_default\_post\_uri( $post\_id );
980
$native\_uri = self::get\_default\_post\_uri( $post\_id, true );
981
$old\_uri = ( isset( $permalink\_manager\_uris\[ $post->ID \] ) ) ? $permalink\_manager\_uris\[ $post->ID \] : $native\_uri;
864
982
865
983
// Use default URI if URI is cleared by user OR URI should be automatically updated
866
$new\_uri = (($\_POST\['custom\_uri'\] == '') || $auto\_update\_uri == 1) ? $default\_uri : Permalink\_Manager\_Helper\_Functions::sanitize\_title($\_POST\['custom\_uri'\], true);
984
$new\_uri = ( ( $\_POST\['custom\_uri'\] == '' ) || $auto\_update\_uri == 1 ) ? $default\_uri : Permalink\_Manager\_Helper\_Functions::sanitize\_title( $\_POST\['custom\_uri'\], true );
867
985
868
986
// Save or remove "Auto-update URI" settings
869
if(!empty($auto\_update\_uri\_current)) {
870
update\_post\_meta($post\_id, "auto\_update\_uri", $auto\_update\_uri\_current);
871
} elseif(isset($\_POST\['auto\_update\_uri'\])) {
872
delete\_post\_meta($post\_id, "auto\_update\_uri");
987
if ( ! empty( $auto\_update\_uri\_current ) ) {
988
update\_post\_meta( $post\_id, "auto\_update\_uri", $auto\_update\_uri\_current );
989
} elseif ( isset( $\_POST\['auto\_update\_uri'\] ) ) {
990
delete\_post\_meta( $post\_id, "auto\_update\_uri" );
873
991
}
874
992
875
993
// Stop the hook (if needed)
876
$allow\_update\_uri = apply\_filters("permalink\_manager\_allow\_update\_post\_uri", true, $post);
877
878
if(!$allow\_update\_uri || (!empty($auto\_update\_uri) && $auto\_update\_uri == 2)) {
994
$allow\_update\_uri = apply\_filters( "permalink\_manager\_allow\_update\_post\_uri", true, $post );
995
996
if ( ! $allow\_update\_uri || ( ! empty( $auto\_update\_uri ) && $auto\_update\_uri == 2 ) ) {
879
997
$uri\_saved = false;
880
} else if(is\_array($permalink\_manager\_uris) && !empty($new\_uri)) {
881
$permalink\_manager\_uris\[$post\_id\] = $new\_uri;
882
$uri\_saved \= update\_option('permalink-manager-uris', $permalink\_manager\_uris);
998
} else if ( is\_array( $permalink\_manager\_uris ) && ! empty( $new\_uri ) ) {
999
$permalink\_manager\_uris\[ $post\_id \] = $new\_uri;
1000
$uri\_saved = update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
883
1001
} else {
884
1002
$uri\_saved = false;
885
1003
}
886
1004
887
do\_action('permalink\_manager\_updated\_post\_uri', $post\_id, $new\_uri, $old\_uri, $native\_uri, $default\_uri, $single\_update = true, $uri\_saved);
888
}
889
890
/\*\*
891
\* Remove URI from options array after post is moved to the trash
892
\*/
893
function remove\_post\_uri($post\_id) {
1005
do\_action( 'permalink\_manager\_updated\_post\_uri', $post\_id, $new\_uri, $old\_uri, $native\_uri, $default\_uri, $single\_update = true, $uri\_saved );
1006
}
1007
1008
/\*\*
1009
\* Remove URI from options array after post is moved to the trash
1010
\*
1011
\* @param int $post\_id
1012
\*/
1013
function remove\_post\_uri( $post\_id ) {
894
1014
global $permalink\_manager\_uris;
895
1015
896
1016
// Check if the custom permalink is assigned to this post
897
if(isset($permalink\_manager\_uris\[$post\_id\])) {
898
unset($permalink\_manager\_uris\[$post\_id\]);
899
}
900
901
if(is\_array($permalink\_manager\_uris)) {
902
update\_option('permalink-manager-uris', $permalink\_manager\_uris);
1017
if ( isset( $permalink\_manager\_uris\[ $post\_id \] ) ) {
1018
unset( $permalink\_manager\_uris\[ $post\_id \] );
1019
}
1020
1021
if ( is\_array( $permalink\_manager\_uris ) ) {
1022
update\_option( 'permalink-manager-uris', $permalink\_manager\_uris );
903
1023
}
904
1024
}
permalink-manager/trunk/includes/core/permalink-manager-uri-functions.php
r2521331
r2833667
4
4
\* Functions used to create, edit and remove custom permalinks
5
5
\*/
6
class Permalink\_Manager\_URI\_Functions extends Permalink\_Manager\_Class {
6
class Permalink\_Manager\_URI\_Functions {
7
7
8
8
public function \_\_construct() {
…
…
10
10
}
11
11
12
public static function get\_single\_uri\_key($element\_id, $is\_tax = false) {
12
/\*\*
13
\* Get the custom permalink's array key for specific post or term
14
\*
15
\* @param int|string $element\_id
16
\* @param bool $is\_tax
17
\*
18
\* @return int|string
19
\*/
20
public static function get\_single\_uri\_key( $element\_id, $is\_tax = false ) {
13
21
// Check if the element ID is numeric
14
if(empty($element\_id) || !is\_numeric($element\_id)) { return; }
22
if ( empty( $element\_id ) || ! is\_numeric( $element\_id ) ) {
23
return '';
24
}
15
25
16
if($is\_tax) {
26
if ( $is\_tax ) {
17
27
$element\_id = "tax-{$element\_id}";
18
28
}
…
…
22
32
23
33
/\*\*
24
\* Save URI to the custom permalinks array
34
\* Save single custom permalink to the custom permalinks array
35
\*
36
\* @param int|string $element
37
\* @param string $element\_uri
38
\* @param bool $is\_tax
39
\* @param bool $db\_save
25
40
\*/
26
public static function save\_single\_uri($element, $element\_uri = null, $is\_tax = false, $db\_save = false) {
41
public static function save\_single\_uri( $element, $element\_uri = null, $is\_tax = false, $db\_save = false ) {
27
42
global $permalink\_manager\_uris;
28
43
29
44
// Get the element key
30
$element\_key = self::get\_single\_uri\_key($element, $is\_tax);
45
$element\_key = self::get\_single\_uri\_key( $element, $is\_tax );
31
46
32
47
// Save the custom permalink if the URI is not empty
33
if(!empty($element\_key) && !empty($element\_uri)) {
34
$permalink\_manager\_uris\[$element\_key\] = Permalink\_Manager\_Helper\_Functions::sanitize\_title($element\_uri, true);
48
if ( ! empty( $element\_key ) && ! empty( $element\_uri ) ) {
49
$permalink\_manager\_uris\[ $element\_key \] = Permalink\_Manager\_Helper\_Functions::sanitize\_title( $element\_uri, true );
35
50
36
if($db\_save) {
37
self::save\_all\_uris($permalink\_manager\_uris);
51
if ( $db\_save ) {
52
self::save\_all\_uris( $permalink\_manager\_uris );
38
53
}
39
54
}
…
…
41
56
42
57
/\*\*
43
\* Remove URI to the custom permalinks array
58
\* Remove single custom permalink from the custom permalinks array
59
\*
60
\* @param int|string $element
61
\* @param bool $is\_tax
62
\* @param bool $db\_save
44
63
\*/
45
public static function remove\_single\_uri($element, $is\_tax = false, $db\_save = false) {
64
public static function remove\_single\_uri( $element, $is\_tax = false, $db\_save = false ) {
46
65
global $permalink\_manager\_uris;
47
66
48
67
// Get the element key
49
$element\_key = self::get\_single\_uri\_key($element, $is\_tax);
68
$element\_key = self::get\_single\_uri\_key( $element, $is\_tax );
50
69
51
70
// Check if the custom permalink is assigned to this post
52
if(!empty($element\_key) && isset($permalink\_manager\_uris\[$element\_key\])) {
53
unset($permalink\_manager\_uris\[$element\_key\]);
71
if ( ! empty( $element\_key ) && isset( $permalink\_manager\_uris\[ $element\_key \] ) ) {
72
unset( $permalink\_manager\_uris\[ $element\_key \] );
54
73
}
55
74
56
if($db\_save) {
57
self::save\_all\_uris($permalink\_manager\_uris);
75
if ( $db\_save ) {
76
self::save\_all\_uris( $permalink\_manager\_uris );
58
77
}
59
78
}
…
…
61
80
/\*\*
62
81
\* Save the array with custom permalinks
82
\*
83
\* @param array $updated\_uris
63
84
\*/
64
public static function save\_all\_uris($updated\_uris = null) {
65
if(is\_null($updated\_uris)) {
85
public static function save\_all\_uris( $updated\_uris = null ) {
86
if ( is\_null( $updated\_uris ) ) {
66
87
global $permalink\_manager\_uris;
67
88
$updated\_uris = $permalink\_manager\_uris;
68
89
}
69
90
70
if(is\_array($updated\_uris) && !empty($updated\_uris)) {
71
update\_option('permalink-manager-uris', $updated\_uris);
91
if ( is\_array( $updated\_uris ) && ! empty( $updated\_uris ) ) {
92
update\_option( 'permalink-manager-uris', $updated\_uris );
72
93
}
73
94
}
74
95
75
96
}
76
77
?>
permalink-manager/trunk/includes/views/permalink-manager-debug.php
r2769264
r2833667
2
2
3
3
/\*\*
4
\* Display the page where the slugs could be regenerated or replaced
5
\*/
6
class Permalink\_Manager\_Debug extends Permalink\_Manager\_Class {
4
\* Display the page where the slugs could be regenerated or replaced
5
\*/
6
class Permalink\_Manager\_Debug {
7
7
8
8
public function \_\_construct() {
9
add\_filter( 'permalink\_manager\_sections', array($this, 'add\_debug\_section'), 4 );
9
add\_filter( 'permalink\_manager\_sections', array( $this, 'add\_debug\_section' ), 4 );
10
10
}
11
11
12
public function add\_debug\_section($admin\_sections) {
12
/\*\*
13
\* Add a new section to the Permalink Manager UI
14
\*
15
\* @param array $admin\_sections
16
\*
17
\* @return array
18
\*/
19
public function add\_debug\_section( $admin\_sections ) {
13
20
$admin\_sections\['debug'\] = array(
14
'name' => \_\_('Debug', 'permalink-manager'),
15
'function' => array('class' => 'Permalink\_Manager\_Debug', 'method' => 'output')
21
'name' => \_\_( 'Debug', 'permalink-manager' ),
22
'function' \=> array( 'class' => 'Permalink\_Manager\_Debug', 'method' => 'output' )
16
23
);
17
24
…
…
19
26
}
20
27
21
public function get\_remove\_settings\_url($field = '') {
22
$debug\_section\_url = add\_query\_arg(array(
23
'section' => 'debug',
28
/\*\*
29
\* Get a URL pointing to the "Debug" tab in Permalink Manager UI
30
\*
31
\* @param string $field
32
\*
33
\* @return string
34
\*/
35
public function get\_remove\_settings\_url( $field = '' ) {
36
return add\_query\_arg( array(
37
'section' => 'debug',
24
38
'remove-permalink-manager-settings' => $field,
25
'\_wpnonce' => wp\_create\_nonce('permalink-manager')
26
), Permalink\_Manager\_Admin\_Functions::get\_admin\_url());
27
28
return $debug\_section\_url;
39
'permalink-manager-nonce' => wp\_create\_nonce( 'permalink-manager' )
40
), Permalink\_Manager\_Admin\_Functions::get\_admin\_url() );
29
41
}
30
42
43
/\*\*
44
\* Define and display HTML output of a new section with the "Debug" data
45
\*
46
\* @return string
47
\*/
31
48
public function output() {
32
global $permalink\_manager\_options, $permalink\_manager\_uris, $permalink\_manager\_permastructs, $permalink\_manager\_redirects, $permalink\_manager\_external\_redirects, $wp\_filter;
49
global $permalink\_manager\_options, $permalink\_manager\_uris, $permalink\_manager\_permastructs, $permalink\_manager\_redirects, $permalink\_manager\_external\_redirects;
33
50
34
$debug\_section\_url = Permalink\_Manager\_Admin\_Functions::get\_admin\_url('§ion=debug');
35
36
$sections\_and\_fields = apply\_filters('permalink\_manager\_debug\_fields', array(
51
$sections\_and\_fields = apply\_filters( 'permalink\_manager\_debug\_fields', array(
37
52
'debug-data' => array(
38
'section\_name' => \_\_('Debug data', 'permalink-manager'),
39
'fields' => array(
40
'uris' => array(
41
'type' => 'textarea',
42
'description' => sprintf('%s<br /><strong><a class="pm-confirm-action" href="%s">%s</a></strong>',
43
\_\_('List of the URIs generated by this plugin.', 'permalink-manager'),
44
$this->get\_remove\_settings\_url('uris'),
45
\_\_('Remove all custom permalinks', 'permalink-manager')
46
),
47
'label' => \_\_('Array with URIs', 'permalink-manager'),
53
'section\_name' => \_\_( 'Debug data', 'permalink-manager' ),
54
'fields' => array(
55
'uris' => array(
56
'type' => 'textarea',
57
'description' => sprintf( '%s<br /><strong><a class="pm-confirm-action" href="%s">%s</a></strong>', \_\_( 'List of the URIs generated by this plugin.', 'permalink-manager' ), $this->get\_remove\_settings\_url( 'uris' ), \_\_( 'Remove all custom permalinks', 'permalink-manager' ) ),
58
'label' => \_\_( 'Array with URIs', 'permalink-manager' ),
48
59
'input\_class' => 'short-textarea widefat',
49
'value' \=> ($permalink\_manager\_uris) ? print\_r($permalink\_manager\_uris, true) : ''
60
'value' => ( $permalink\_manager\_uris ) ? print\_r( $permalink\_manager\_uris, true ) : ''
50
61
),
51
'custom-redirects' => array(
52
'type' => 'textarea',
53
'description' => sprintf('%s<br /><strong><a class="pm-confirm-action" href="%s">%s</a></strong>',
54
\_\_('List of custom redirects set-up by this plugin.', 'permalink-manager'),
55
$this->get\_remove\_settings\_url('redirects'),
56
\_\_('Remove all custom redirects', 'permalink-manager')
57
),
58
'label' => \_\_('Array with redirects', 'permalink-manager'),
62
'custom-redirects' => array(
63
'type' => 'textarea',
64
'description' => sprintf( '%s<br /><strong><a class="pm-confirm-action" href="%s">%s</a></strong>', \_\_( 'List of custom redirects set-up by this plugin.', 'permalink-manager' ), $this->get\_remove\_settings\_url( 'redirects' ), \_\_( 'Remove all custom redirects', 'permalink-manager' ) ),
65
'label' => \_\_( 'Array with redirects', 'permalink-manager' ),
59
66
'input\_class' => 'short-textarea widefat',
60
'value' \=> ($permalink\_manager\_redirects) ? print\_r($permalink\_manager\_redirects, true) : ''
67
'value' => ( $permalink\_manager\_redirects ) ? print\_r( $permalink\_manager\_redirects, true ) : ''
61
68
),
62
69
'external-redirects' => array(
63
'type' => 'textarea',
64
'description' => sprintf('%s<br /><strong><a class="pm-confirm-action" href="%s">%s</a></strong>',
65
\_\_('List of external redirects set-up by this plugin.', 'permalink-manager'),
66
$this->get\_remove\_settings\_url('external-redirects'),
67
\_\_('Remove all external redirects', 'permalink-manager')
68
),
69
'label' => \_\_('Array with external redirects', 'permalink-manager'),
70
'type' => 'textarea',
71
'description' => sprintf( '%s<br /><strong><a class="pm-confirm-action" href="%s">%s</a></strong>', \_\_( 'List of external redirects set-up by this plugin.', 'permalink-manager' ), $this->get\_remove\_settings\_url( 'external-redirects' ), \_\_( 'Remove all external redirects', 'permalink-manager' ) ),
72
'label' => \_\_( 'Array with external redirects', 'permalink-manager' ),
70
73
'input\_class' => 'short-textarea widefat',
71
'value' \=> ($permalink\_manager\_external\_redirects) ? print\_r(array\_filter($permalink\_manager\_external\_redirects), true) : ''
74
'value' => ( $permalink\_manager\_external\_redirects ) ? print\_r( array\_filter( $permalink\_manager\_external\_redirects ), true ) : ''
72
75
),
73
'permastructs' => array(
74
'type' => 'textarea',
75
'description' => sprintf('%s<br /><strong><a class="pm-confirm-action" href="%s">%s</a></strong>',
76
\_\_('List of permastructures set-up by this plugin.', 'permalink-manager'),
77
$this->get\_remove\_settings\_url('permastructs'),
78
\_\_('Remove all permastructures settings', 'permalink-manager')
79
),
80
'label' => \_\_('Array with permastructures', 'permalink-manager'),
76
'permastructs' => array(
77
'type' => 'textarea',
78
'description' => sprintf( '%s<br /><strong><a class="pm-confirm-action" href="%s">%s</a></strong>', \_\_( 'List of permastructures set-up by this plugin.', 'permalink-manager' ), $this->get\_remove\_settings\_url( 'permastructs' ), \_\_( 'Remove all permastructures settings', 'permalink-manager' ) ),
79
'label' => \_\_( 'Array with permastructures', 'permalink-manager' ),
81
80
'input\_class' => 'short-textarea widefat',
82
'value' \=> ($permalink\_manager\_permastructs) ? print\_r($permalink\_manager\_permastructs, true) : ''
81
'value' => ( $permalink\_manager\_permastructs ) ? print\_r( $permalink\_manager\_permastructs, true ) : ''
83
82
),
84
'settings' => array(
85
'type' => 'textarea',
86
'description' => sprintf('%s<br /><strong><a class="pm-confirm-action" href="%s">%s</a></strong>',
87
\_\_('List of plugin settings.', 'permalink-manager'),
88
$this->get\_remove\_settings\_url('settings'),
89
\_\_('Remove all plugin settings', 'permalink-manager')
90
),
91
'label' => \_\_('Array with settings used in this plugin.', 'permalink-manager'),
83
'settings' => array(
84
'type' => 'textarea',
85
'description' => sprintf( '%s<br /><strong><a class="pm-confirm-action" href="%s">%s</a></strong>', \_\_( 'List of plugin settings.', 'permalink-manager' ), $this->get\_remove\_settings\_url( 'settings' ), \_\_( 'Remove all plugin settings', 'permalink-manager' ) ),
86
'label' => \_\_( 'Array with settings used in this plugin.', 'permalink-manager' ),
92
87
'input\_class' => 'short-textarea widefat',
93
'value' \=> print\_r($permalink\_manager\_options, true)
88
'value' => print\_r( $permalink\_manager\_options, true )
94
89
)
95
90
)
96
91
)
97
));
92
) );
98
93
99
94
// Now get the HTML output
100
95
$output = '';
101
foreach($sections\_and\_fields as $section\_id => $section) {
102
$output .= (isset($section\['section\_name'\])) ? "<h3>{$section\['section\_name'\]}</h3>" : "";
103
$output .= (isset($section\['description'\])) ? "<p class=\\"description\\">{$section\['description'\]}</p>" : "";
96
foreach ( $sections\_and\_fields as $section\_id => $section ) {
97
$output .= ( isset( $section\['section\_name'\] ) ) ? "<h3>{$section\['section\_name'\]}</h3>" : "";
98
$output .= ( isset( $section\['description'\] ) ) ? "<p class=\\"description\\">{$section\['description'\]}</p>" : "";
104
99
$output .= "<table class=\\"form-table fixed-table\\">";
105
100
106
101
// Loop through all fields assigned to this section
107
foreach($section\['fields'\] as $field\_id => $field) {
108
$field\_name \= "{$section\_id}\[$field\_id\]";
102
foreach ( $section\['fields'\] as $field\_id => $field ) {
103
$field\_name \= "{$section\_id}\[$field\_id\]";
109
104
$field\['container'\] = 'row';
110
105
111
$output .= Permalink\_Manager\_Admin\_Functions::generate\_option\_field($field\_name, $field);
106
$output .= Permalink\_Manager\_Admin\_Functions::generate\_option\_field( $field\_name, $field );
112
107
}
113
108
permalink-manager/trunk/includes/views/permalink-manager-permastructs.php
r2521331
r2833667
2
2
3
3
/\*\*
4
\* Display the page where the slugs could be regenerated or replaced
5
\*/
6
class Permalink\_Manager\_Permastructs extends Permalink\_Manager\_Class {
4
\* Display the page where the slugs could be regenerated or replaced
5
\*/
6
class Permalink\_Manager\_Permastructs {
7
7
8
8
public function \_\_construct() {
9
add\_filter( 'permalink\_manager\_sections', array($this, 'add\_admin\_section'), 2 );
9
add\_filter( 'permalink\_manager\_sections', array( $this, 'add\_admin\_section' ), 2 );
10
10
}
11
11
12
public function add\_admin\_section($admin\_sections) {
13
12
/\*\*
13
\* Add a new section to the Permalink Manager UI
14
\*
15
\* @param array $admin\_sections
16
\*
17
\* @return array
18
\*/
19
public function add\_admin\_section( $admin\_sections ) {
14
20
$admin\_sections\['permastructs'\] = array(
15
'name' => \_\_('Permastructures', 'permalink-manager'),
16
'function' => array('class' => 'Permalink\_Manager\_Permastructs', 'method' => 'output')
21
'name' => \_\_( 'Permastructures', 'permalink-manager' ),
22
'function' \=> array( 'class' => 'Permalink\_Manager\_Permastructs', 'method' => 'output' )
17
23
);
18
24
…
…
20
26
}
21
27
28
/\*\*
29
\* Return an array of fields that will be used to adjust the permastructure settings
30
\*
31
\* @return array
32
\*/
22
33
public function get\_fields() {
23
global $permalink\_manager\_permastructs;
24
25
$all\_post\_types = Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array('full');
34
$all\_post\_types = Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array( 'full' );
26
35
$woocommerce\_icon = "<i class=\\"woocommerce-icon woocommerce-cart\\"></i>";
27
36
…
…
29
38
$fields = array(
30
39
'post\_types' => array(
31
'section\_name' => \_\_('Post types', 'permalink-manager'),
32
'container' \=> 'row',
33
'fields' \=> array()
40
'section\_name' => \_\_( 'Post types', 'permalink-manager' ),
41
'container' \=> 'row',
42
'fields' \=> array()
34
43
),
35
44
'taxonomies' => array(
36
'section\_name' \=> \_\_('Taxonomies', 'permalink-manager'),
37
'container' \=> 'row',
45
'section\_name' => \_\_( 'Taxonomies', 'permalink-manager' ),
46
'container' \=> 'row',
38
47
'append\_content' => Permalink\_Manager\_Admin\_Functions::pro\_text(),
39
'fields' \=> array()
48
'fields' \=> array()
40
49
)
41
50
);
42
51
43
52
// 2. Woocommerce support
44
if(class\_exists('WooCommerce')) {
53
if ( class\_exists( 'WooCommerce' ) ) {
45
54
$fields\['woocommerce'\] = array(
46
'section\_name' \=> "{$woocommerce\_icon} " . \_\_('WooCommerce', 'permalink-manager'),
47
'container' \=> 'row',
55
'section\_name' => "{$woocommerce\_icon} " . \_\_( 'WooCommerce', 'permalink-manager' ),
56
'container' \=> 'row',
48
57
'append\_content' => Permalink\_Manager\_Admin\_Functions::pro\_text(),
49
'fields' \=> array()
58
'fields' \=> array()
50
59
);
51
60
}
52
61
53
62
// 3. Append fields for all post types
54
foreach($all\_post\_types as $post\_type) {
55
if($post\_type\['name'\] == 'shop\_coupon') { continue; }
63
foreach ( $all\_post\_types as $post\_type ) {
64
if ( $post\_type\['name'\] == 'shop\_coupon' ) {
65
continue;
66
}
56
67
57
$fields\["post\_types"\]\["fields"\]\[$post\_type\['name'\]\] = array(
58
'label' \=> $post\_type\['label'\],
59
'container' \=> 'row',
68
$fields\["post\_types"\]\["fields"\]\[ $post\_type\['name'\] \] = array(
69
'label' \=> $post\_type\['label'\],
70
'container' \=> 'row',
60
71
'input\_class' => 'permastruct-field',
61
'post\_type' \=> $post\_type,
62
'type' \=> 'permastruct'
72
'post\_type' \=> $post\_type,
73
'type' \=> 'permastruct'
63
74
);
64
75
}
65
76
66
return apply\_filters('permalink\_manager\_permastructs\_fields', $fields);
77
return apply\_filters( 'permalink\_manager\_permastructs\_fields', $fields );
67
78
}
68
79
69
80
/\*\*
70
\* Get the array with settings and render the HTML output
71
\*/
81
\* Get the array with settings and render the HTML output
82
\*/
72
83
public function output() {
73
global $permalink\_manager\_permastructs;
74
75
$sidebar = sprintf('<h3>%s</h3>', \_\_('Instructions', 'permalink-manager'));
84
$sidebar = sprintf( '<h3>%s</h3>', \_\_( 'Instructions', 'permalink-manager' ) );
76
85
$sidebar .= "<div class=\\"notice notice-warning\\"><p>";
77
$sidebar .= \_\_('The current permastructures settings will be automatically applied <strong>only to the new posts & terms</strong>.');
86
$sidebar .= \_\_( 'The current permastructures settings will be automatically applied <strong>only to the new posts & terms</strong>.' );
78
87
$sidebar .= '<br />';
79
$sidebar .= sprintf(\_\_('To apply the <strong>new format to existing posts and terms</strong>, please use "<a href="%s">Regenerate/reset</a>" tool after you update the permastructure settings below.', 'permalink-manager'), admin\_url('tools.php?page=permalink-manager§ion=tools&subsection=regenerate\_slugs'));
88
$sidebar .= sprintf( \_\_( 'To apply the <strong>new format to existing posts and terms</strong>, please use "<a href="%s">Regenerate/reset</a>" tool after you update the permastructure settings below.', 'permalink-manager' ), admin\_url( 'tools.php?page=permalink-manager§ion=tools&subsection=regenerate\_slugs' ) );
80
89
$sidebar .= "</p></div>";
81
90
82
$sidebar .= sprintf('<h4>%s</h4>', \_\_('Permastructure tags', 'permalink-manager'));
83
$sidebar .= wpautop(sprintf(\_\_('All allowed <a href="%s" target="\_blank">permastructure tags</a> are listed below. Please note that some of them can be used only for particular post types or taxonomies.', 'permalink-manager'), "https://codex.wordpress.org/Using\_Permalinks#Structure\_Tags"));
91
$sidebar .= sprintf( '<h4>%s</h4>', \_\_( 'Permastructure tags', 'permalink-manager' ) );
92
$sidebar .= wpautop( sprintf( \_\_( 'All allowed <a href="%s" target="\_blank">permastructure tags</a> are listed below. Please note that some of them can be used only for particular post types or taxonomies.', 'permalink-manager' ), "https://codex.wordpress.org/Using\_Permalinks#Structure\_Tags" ) );
84
93
$sidebar .= Permalink\_Manager\_Helper\_Functions::get\_all\_structure\_tags();
85
94
86
return Permalink\_Manager\_Admin\_Functions::get\_the\_form(self::get\_fields(), '', array('text' => \_\_( 'Save permastructures', 'permalink-manager' ), 'class' => 'primary margin-top'), $sidebar, array('action' => 'permalink-manager', 'name' => 'permalink\_manager\_permastructs'));
95
return Permalink\_Manager\_Admin\_Functions::get\_the\_form( self::get\_fields(), '', array( 'text' => \_\_( 'Save permastructures', 'permalink-manager' ), 'class' => 'primary margin-top' ), $sidebar, array( 'action' => 'permalink-manager', 'name' => 'permalink\_manager\_permastructs' ) );
87
96
}
88
97
permalink-manager/trunk/includes/views/permalink-manager-settings.php
r2796526
r2833667
2
2
3
3
/\*\*
4
\* Display the settings page
5
\*/
6
class Permalink\_Manager\_Settings extends Permalink\_Manager\_Class {
4
\* Display the settings page
5
\*/
6
class Permalink\_Manager\_Settings {
7
7
8
8
public function \_\_construct() {
9
add\_filter( 'permalink\_manager\_sections', array($this, 'add\_admin\_section'), 3 );
9
add\_filter( 'permalink\_manager\_sections', array( $this, 'add\_admin\_section' ), 3 );
10
10
}
11
11
12
public function add\_admin\_section($admin\_sections) {
12
/\*\*
13
\* Add a new section to the Permalink Manager UI
14
\*
15
\* @param array $admin\_sections
16
\*
17
\* @return array
18
\*/
19
public function add\_admin\_section( $admin\_sections ) {
13
20
$admin\_sections\['settings'\] = array(
14
'name' => \_\_('Settings', 'permalink-manager'),
15
'function' => array('class' => 'Permalink\_Manager\_Settings', 'method' => 'output')
21
'name' => \_\_( 'Settings', 'permalink-manager' ),
22
'function' \=> array( 'class' => 'Permalink\_Manager\_Settings', 'method' => 'output' )
16
23
);
17
24
…
…
20
27
21
28
/\*\*
22
\* Get the array with settings and render the HTML output
23
\*/
29
\* Get the array with settings and render the HTML output
30
\*
31
\* @return string
32
\*/
24
33
public function output() {
25
// Get all registered post types array & statuses
26
$all\_post\_statuses\_array = get\_post\_statuses();
27
$all\_post\_types = Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array(null, null, true);
28
$all\_taxonomies = Permalink\_Manager\_Helper\_Functions::get\_taxonomies\_array(false, false, false, true);
29
$content\_types = (defined('PERMALINK\_MANAGER\_PRO')) ? array('post\_types' => $all\_post\_types, 'taxonomies' => $all\_taxonomies) : array('post\_types' => $all\_post\_types);
30
31
$sections\_and\_fields = apply\_filters('permalink\_manager\_settings\_fields', array(
32
'general' => array(
33
'section\_name' => \_\_('General settings', 'permalink-manager'),
34
'container' => 'row',
35
'name' => 'general',
36
'fields' => array(
37
'auto\_update\_uris' => array(
38
'type' => 'select',
39
'label' => \_\_('URI update mode', 'permalink-manager'),
40
'input\_class' => '',
41
'choices' => array(0 => \_\_('Don\\'t auto-update permalinks (default mode)', 'permalink-manager'), 1 => \_\_('Auto-update permalinks', 'permalink-manager'), 2 => \_\_('Disable URI Editor to disallow permalink changes', 'permalink-manager')),
42
'description' => sprintf('%s<br />%s<br />%s',
43
\_\_('<strong>Permalink Manager can automatically update the custom permalink after post or term is saved/updated.</strong>', 'permalink-manager'),
44
\_\_('If enabled, Permalink Manager will always force the default custom permalink format (based on current <strong>Permastructure</strong> settings).', 'permalink-manager'),
45
\_\_('Use the last option if you want to to customize only specific permalinks and keep the rest of URLs in their original format.', 'permalink-manager')
46
)
34
// Get all registered post types & taxonomies
35
$all\_post\_types = Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array( null, null, true );
36
$all\_taxonomies = Permalink\_Manager\_Helper\_Functions::get\_taxonomies\_array( false, false, true );
37
$content\_types = ( defined( 'PERMALINK\_MANAGER\_PRO' ) ) ? array( 'post\_types' => $all\_post\_types, 'taxonomies' => $all\_taxonomies ) : array( 'post\_types' => $all\_post\_types );
38
39
$sections\_and\_fields = apply\_filters( 'permalink\_manager\_settings\_fields', array(
40
'general' => array(
41
'section\_name' => \_\_( 'General settings', 'permalink-manager' ),
42
'container' => 'row',
43
'name' => 'general',
44
'fields' => array(
45
'auto\_update\_uris' => array(
46
'type' => 'select',
47
'label' => \_\_( 'URI update mode', 'permalink-manager' ),
48
'input\_class' => '',
49
'choices' => array( 0 => \_\_( 'Don\\'t auto-update permalinks (default mode)', 'permalink-manager' ), 1 => \_\_( 'Auto-update permalinks', 'permalink-manager' ), 2 => \_\_( 'Disable URI Editor to disallow permalink changes', 'permalink-manager' ) ),
50
'description' => sprintf( '%s<br />%s<br />%s', \_\_( '<strong>Permalink Manager can automatically update the custom permalink after post or term is saved/updated.</strong>', 'permalink-manager' ), \_\_( 'If enabled, Permalink Manager will always force the default custom permalink format (based on current <strong>Permastructure</strong> settings).', 'permalink-manager' ), \_\_( 'Use the last option if you want to to customize only specific permalinks and keep the rest of URLs in their original format.', 'permalink-manager' ) )
47
51
),
48
52
'force\_custom\_slugs' => array(
49
'type' => 'select',
50
'label' => \_\_('Slugs mode', 'permalink-manager'),
51
'input\_class' => 'settings-select',
52
'choices' => array(0 => \_\_('Use native slugs', 'permalink-manager'), 1 => \_\_('Use actual titles as slugs', 'permalink-manager'), 2 => \_\_('Inherit parents\\' slugs', 'permalink-manager')),
53
'description' => sprintf('%s<br />%s<br />%s',
54
\_\_('<strong>Permalink Manager can use either native slugs or actual titles for custom permalinks.</strong>', 'permalink-manager'),
55
\_\_('The native slug is generated from the initial title after the post or term is published.', 'permalink-manager'),
56
\_\_('Use this field if you would like Permalink Manager to use the actual titles instead of native slugs.', 'permalink-manager')
57
)
58
),
59
'trailing\_slashes' => array(
60
'type' => 'select',
61
'label' => \_\_('Trailing slashes', 'permalink-manager'),
62
'input\_class' => 'settings-select',
63
'choices' => array(0 => \_\_('Use default settings', 'permalink-manager'), 1 => \_\_('Add trailing slashes', 'permalink-manager'), 2 => \_\_('Remove trailing slashes', 'permalink-manager')),
64
'description' => \_\_('This option can be used to alter the native settings and control if trailing slash should be added or removed from the end of posts & terms permalinks.', 'permalink-manager'),
65
'description' => sprintf('%s<br />%s',
66
\_\_('<strong>You can use this feature to either add or remove the slases from end of WordPress permalinks.</strong>', 'permalink-manager'),
67
\_\_('Please go to "<em>Redirect settings -> Trailing slashes redirect</em>" to force the trailing slashes mode with redirect.', 'permalink-manager')
68
)
69
),
70
'partial\_disable' => array(
71
'type' => 'checkbox',
72
'label' => \_\_('Exclude content types', 'permalink-manager'),
73
'choices' => $content\_types,
74
'description' => \_\_('Permalink Manager will ignore and not filter the custom permalinks of all selected above post types & taxonomies.', 'permalink-manager')
75
),
76
'ignore\_drafts' => array(
77
'type' => 'single\_checkbox',
78
'label' => \_\_('Exclude drafts', 'permalink-manager'),
79
'description' => \_\_('If enabled, the custom permalinks for post drafts will not be saved.', 'permalink-manager')
53
'type' => 'select',
54
'label' => \_\_( 'Slugs mode', 'permalink-manager' ),
55
'input\_class' => 'settings-select',
56
'choices' => array( 0 => \_\_( 'Use native slugs', 'permalink-manager' ), 1 => \_\_( 'Use actual titles as slugs', 'permalink-manager' ), 2 => \_\_( 'Inherit parents\\' slugs', 'permalink-manager' ) ),
57
'description' => sprintf( '%s<br />%s<br />%s', \_\_( '<strong>Permalink Manager can use either native slugs or actual titles for custom permalinks.</strong>', 'permalink-manager' ), \_\_( 'The native slug is generated from the initial title after the post or term is published.', 'permalink-manager' ), \_\_( 'Use this field if you would like Permalink Manager to use the actual titles instead of native slugs.', 'permalink-manager' ) )
58
),
59
'trailing\_slashes' => array(
60
'type' => 'select',
61
'label' => \_\_( 'Trailing slashes', 'permalink-manager' ),
62
'input\_class' => 'settings-select',
63
'choices' => array( 0 => \_\_( 'Use default settings', 'permalink-manager' ), 1 => \_\_( 'Add trailing slashes', 'permalink-manager' ), 2 => \_\_( 'Remove trailing slashes', 'permalink-manager' ) ),
64
'description' => sprintf( '<strong>%s</strong><br />%s<br />%s', \_\_( 'This option can be used to alter the native settings and control if trailing slash should be added or removed from the end of posts & terms permalinks.', 'permalink-manager' ), \_\_( 'You can use this feature to either add or remove the slashes from end of WordPress permalinks.', 'permalink-manager' ), \_\_( 'Please go to "<em>Redirect settings -> Trailing slashes redirect</em>" to force the trailing slashes mode with redirect.', 'permalink-manager' ) )
65
),
66
'partial\_disable' => array(
67
'type' => 'checkbox',
68
'label' => \_\_( 'Exclude content types', 'permalink-manager' ),
69
'choices' => $content\_types,
70
'description' => \_\_( 'Permalink Manager will ignore and not filter the custom permalinks of all selected above post types & taxonomies.', 'permalink-manager' )
71
),
72
'ignore\_drafts' => array(
73
'type' => 'single\_checkbox',
74
'label' => \_\_( 'Exclude drafts', 'permalink-manager' ),
75
'description' => \_\_( 'If enabled, the custom permalinks for post drafts will not be saved.', 'permalink-manager' )
80
76
)
81
77
)
82
78
),
83
'redirect' => array(
84
'section\_name' => \_\_('Redirect settings', 'permalink-manager'),
85
'container' => 'row',
86
'name' => 'general',
87
'fields' => array(
88
'canonical\_redirect' => array(
89
'type' => 'single\_checkbox',
90
'label' => \_\_('Canonical redirect', 'permalink-manager'),
91
'input\_class' => '',
92
'description' => sprintf('%s<br />%s',
93
\_\_('<strong>Canonical redirect allows WordPress to "correct" the requested URL and redirect visitor to the canonical permalink.</strong>', 'permalink-manager'),
94
\_\_('This feature will be also used to redirect (old) original permalinks to (new) custom permalinks set with Permalink Manager.', 'permalink-manager')
95
)
79
'redirect' => array(
80
'section\_name' => \_\_( 'Redirect settings', 'permalink-manager' ),
81
'container' => 'row',
82
'name' => 'general',
83
'fields' => array(
84
'canonical\_redirect' => array(
85
'type' => 'single\_checkbox',
86
'label' => \_\_( 'Canonical redirect', 'permalink-manager' ),
87
'input\_class' => '',
88
'description' => sprintf( '%s<br />%s', \_\_( '<strong>Canonical redirect allows WordPress to "correct" the requested URL and redirect visitor to the canonical permalink.</strong>', 'permalink-manager' ), \_\_( 'This feature will be also used to redirect (old) original permalinks to (new) custom permalinks set with Permalink Manager.', 'permalink-manager' ) )
96
89
),
97
90
/\*'endpoint\_redirect' => array(
…
…
102
95
\_\_('<strong>Please enable this option if you would like to copy the endpoint from source URL to the target URL during the canonical redirect.</strong>', 'permalink-manager')
103
96
)
104
),\*/
105
'old\_slug\_redirect' => array(
106
'type' => 'single\_checkbox',
107
'label' => \_\_('Old slug redirect', 'permalink-manager'),
108
'input\_class' => '',
109
'description' => sprintf('%s<br />%s',
110
\_\_('<strong>Old slug redirect is used by WordPress to provide a fallback for old version of slugs after they are changed.</strong>', 'permalink-manager'),
111
\_\_('If enabled, the visitors trying to access the URL with the old slug will be redirected to the canonical permalink.', 'permalink-manager')
112
)
113
),
114
'extra\_redirects' => array(
115
'type' => 'single\_checkbox',
116
'label' => \_\_('Extra redirects (aliases)', 'permalink-manager'),
117
'input\_class' => '',
118
'pro' => true,
119
'disabled' => true,
120
'description' => sprintf('%s<br /><strong>%s</strong>',
121
\_\_('Please enable this option if you would like to manage additional custom redirects (aliasees) in URI Editor for individual posts & terms.', 'permalink-manager'),
122
\_\_('You can disable this feature if you use another plugin to control the redirects, eg. Yoast SEO Premium or Redirection.', 'permalink-manager')
123
)
124
),
125
'setup\_redirects' => array(
126
'type' => 'single\_checkbox',
127
'label' => \_\_('Save old custom permalinks as extra redirects', 'permalink-manager'),
128
'input\_class' => '',
129
'pro' => true,
130
'disabled' => true,
131
'description' => sprintf('%s<br /><strong>%s</strong>',
132
\_\_('If enabled, Permalink Manager will save the "extra redirect" for earlier version of custom permalink after you change it (eg. with URI Editor or Regenerate/reset tool).', 'permalink-manager'),
133
\_\_('Please note that the new redirects will be saved only if "Extra redirects (aliases)" option is turned on above.', 'permalink-manager')
134
)
135
),
136
'trailing\_slashes\_redirect' => array(
137
'type' => 'single\_checkbox',
138
'label' => \_\_('Trailing slashes redirect', 'permalink-manager'),
139
'input\_class' => '',
140
'description' => sprintf('%s<br /><strong>%s</strong>',
141
\_\_('Permalink Manager can force the trailing slashes settings in the custom permalinks with redirect.', 'permalink-manager'),
142
\_\_('Please go to "<em>General settings -> Trailing slashes</em>" to choose if trailing slashes should be added or removed from WordPress permalinks.', 'permalink-manager')
143
)
144
),
145
'copy\_query\_redirect' => array(
146
'type' => 'single\_checkbox',
147
'label' => \_\_('Redirect with query parameters', 'permalink-manager'),
148
'input\_class' => '',
149
'description' => sprintf('%s<br />%s',
150
\_\_('If enabled, the query parameters will be copied to the target URL when the redirect is triggered.', 'permalink-manager'),
151
\_\_('Example: <em>https://example.com/product/old-product-url/<strong>?discount-code=blackfriday</strong></em> => <em>https://example.com/new-product-url/<strong>?discount-code=blackfriday</strong></em>', 'permalink-manager')
152
)
153
),
154
'sslwww\_redirect' => array(
155
'type' => 'single\_checkbox',
156
'label' => \_\_('Force HTTPS/WWW', 'permalink-manager'),
157
'input\_class' => '',
158
'description' => sprintf('%s<br />%s',
159
\_\_('<strong>You can use Permalink Manager to force SSL or "www" prefix in WordPress permalinks.</strong>', 'permalink-manager'),
160
\_\_('Please disable it if you encounter any redirect loop issues.', 'permalink-manager')
161
)
162
),
163
'redirect' => array(
164
'type' => 'select',
165
'label' => \_\_('Redirect mode', 'permalink-manager'),
166
'input\_class' => 'settings-select',
167
'choices' => array(0 => \_\_('Disable (Permalink Manager redirect functions)', 'permalink-manager'), "301" => \_\_('301 redirect', 'permalink-manager'), "302" => \_\_('302 redirect', 'permalink-manager')),
168
'description' => sprintf('%s<br /><strong>%s</strong>',
169
\_\_('Permalink Manager includes a set of hooks that allow to extend the redirect functions used natively by WordPress to avoid 404 errors.', 'permalink-manager'),
170
\_\_('You can disable this feature if you do not want Permalink Manager to trigger any additional redirect functions at all.', 'permalink-manager')
171
)
97
),\*/ 'old\_slug\_redirect' => array(
98
'type' => 'single\_checkbox',
99
'label' => \_\_( 'Old slug redirect', 'permalink-manager' ),
100
'input\_class' => '',
101
'description' => sprintf( '%s<br />%s', \_\_( '<strong>Old slug redirect is used by WordPress to provide a fallback for old version of slugs after they are changed.</strong>', 'permalink-manager' ), \_\_( 'If enabled, the visitors trying to access the URL with the old slug will be redirected to the canonical permalink.', 'permalink-manager' ) )
102
),
103
'extra\_redirects' => array(
104
'type' => 'single\_checkbox',
105
'label' => \_\_( 'Extra redirects (aliases)', 'permalink-manager' ),
106
'input\_class' => '',
107
'pro' => true,
108
'disabled' => true,
109
'description' => sprintf( '%s<br /><strong>%s</strong>', \_\_( 'Please enable this option if you would like to manage additional custom redirects (aliases) in URI Editor for individual posts & terms.', 'permalink-manager' ), \_\_( 'You can disable this feature if you use another plugin to control the redirects, eg. Yoast SEO Premium or Redirection.', 'permalink-manager' ) )
110
),
111
'setup\_redirects' => array(
112
'type' => 'single\_checkbox',
113
'label' => \_\_( 'Save old custom permalinks as extra redirects', 'permalink-manager' ),
114
'input\_class' => '',
115
'pro' => true,
116
'disabled' => true,
117
'description' => sprintf( '%s<br /><strong>%s</strong>', \_\_( 'If enabled, Permalink Manager will save the "extra redirect" for earlier version of custom permalink after you change it (eg. with URI Editor or Regenerate/reset tool).', 'permalink-manager' ), \_\_( 'Please note that the new redirects will be saved only if "Extra redirects (aliases)" option is turned on above.', 'permalink-manager' ) )
118
),
119
'trailing\_slashes\_redirect' => array(
120
'type' => 'single\_checkbox',
121
'label' => \_\_( 'Trailing slashes redirect', 'permalink-manager' ),
122
'input\_class' => '',
123
'description' => sprintf( '%s<br /><strong>%s</strong>', \_\_( 'Permalink Manager can force the trailing slashes settings in the custom permalinks with redirect.', 'permalink-manager' ), \_\_( 'Please go to "<em>General settings -> Trailing slashes</em>" to choose if trailing slashes should be added or removed from WordPress permalinks.', 'permalink-manager' ) )
124
),
125
'copy\_query\_redirect' => array(
126
'type' => 'single\_checkbox',
127
'label' => \_\_( 'Redirect with query parameters', 'permalink-manager' ),
128
'input\_class' => '',
129
'description' => sprintf( '%s<br />%s', \_\_( 'If enabled, the query parameters will be copied to the target URL when the redirect is triggered.', 'permalink-manager' ), \_\_( 'Example: <em>https://example.com/product/old-product-url/<strong>?discount-code=blackfriday</strong></em> => <em>https://example.com/new-product-url/<strong>?discount-code=blackfriday</strong></em>', 'permalink-manager' ) )
130
),
131
'sslwww\_redirect' => array(
132
'type' => 'single\_checkbox',
133
'label' => \_\_( 'Force HTTPS/WWW', 'permalink-manager' ),
134
'input\_class' => '',
135
'description' => sprintf( '%s<br />%s', \_\_( '<strong>You can use Permalink Manager to force SSL or "www" prefix in WordPress permalinks.</strong>', 'permalink-manager' ), \_\_( 'Please disable it if you encounter any redirect loop issues.', 'permalink-manager' ) )
136
),
137
'redirect' => array(
138
'type' => 'select',
139
'label' => \_\_( 'Redirect mode', 'permalink-manager' ),
140
'input\_class' => 'settings-select',
141
'choices' => array( 0 => \_\_( 'Disable (Permalink Manager redirect functions)', 'permalink-manager' ), "301" => \_\_( '301 redirect', 'permalink-manager' ), "302" => \_\_( '302 redirect', 'permalink-manager' ) ),
142
'description' => sprintf( '%s<br /><strong>%s</strong>', \_\_( 'Permalink Manager includes a set of hooks that allow to extend the redirect functions used natively by WordPress to avoid 404 errors.', 'permalink-manager' ), \_\_( 'You can disable this feature if you do not want Permalink Manager to trigger any additional redirect functions at all.', 'permalink-manager' ) )
172
143
)
173
144
)
174
145
),
175
146
'third\_parties' => array(
176
'section\_name' => \_\_('Third party plugins', 'permalink-manager'),
177
'container' \=> 'row',
178
'name' \=> 'general',
179
'fields' \=> array(
147
'section\_name' => \_\_( 'Third party plugins', 'permalink-manager' ),
148
'container' \=> 'row',
149
'name' \=> 'general',
150
'fields' \=> array(
180
151
'fix\_language\_mismatch' => array(
181
'type' \=> 'single\_checkbox',
182
'label' \=> \_\_('WPML/Polylang language mismatch', 'permalink-manager'),
183
'input\_class' \=> '',
184
'class\_exists' => array('SitePress', 'Polylang'),
185
'description' \=> \_\_('If enabled, the plugin will load the adjacent translation of post when the custom permalink is detected, but the language code in the URL does not match the language code assigned to the post/term.', 'permalink-manager')
186
),
187
'wpml\_support' \=> array(
188
'type' \=> 'single\_checkbox',
189
'label' \=> \_\_('WPML compatibility functions', 'permalink-manager'),
190
'input\_class' \=> '',
191
'class\_exists' => array('SitePress'),
192
'description' \=> \_\_('Please disable this feature if the language code in the custom permalinks is incorrect.', 'permalink-manager')
193
),
194
'pmxi\_support' \=> array(
195
'type' \=> 'single\_checkbox',
196
'label' \=> \_\_('WP All Import/Export support', 'permalink-manager'),
197
'input\_class' \=> '',
198
'class\_exists' => array('PMXI\_Plugin', 'PMXE\_Plugin'),
199
'description' \=> \_\_('If disabled, the custom permalinks <strong>will not be saved</strong> for the posts imported with WP All Import plugin.', 'permalink-manager')
200
),
201
'um\_support' \=> array(
202
'type' \=> 'single\_checkbox',
203
'label' \=> \_\_('Ultimate Member support', 'permalink-manager'),
204
'input\_class' \=> '',
152
'type' \=> 'single\_checkbox',
153
'label' => \_\_( 'WPML/Polylang language mismatch', 'permalink-manager' ),
154
'input\_class' \=> '',
155
'class\_exists' => array( 'SitePress', 'Polylang' ),
156
'description' => \_\_( 'If enabled, the plugin will load the adjacent translation of post when the custom permalink is detected, but the language code in the URL does not match the language code assigned to the post/term.', 'permalink-manager' )
157
),
158
'wpml\_support' \=> array(
159
'type' \=> 'single\_checkbox',
160
'label' => \_\_( 'WPML compatibility functions', 'permalink-manager' ),
161
'input\_class' \=> '',
162
'class\_exists' => array( 'SitePress' ),
163
'description' => \_\_( 'Please disable this feature if the language code in the custom permalinks is incorrect.', 'permalink-manager' )
164
),
165
'pmxi\_support' \=> array(
166
'type' \=> 'single\_checkbox',
167
'label' => \_\_( 'WP All Import/Export support', 'permalink-manager' ),
168
'input\_class' \=> '',
169
'class\_exists' => array( 'PMXI\_Plugin', 'PMXE\_Plugin' ),
170
'description' => \_\_( 'If disabled, the custom permalinks <strong>will not be saved</strong> for the posts imported with WP All Import plugin.', 'permalink-manager' )
171
),
172
'um\_support' \=> array(
173
'type' \=> 'single\_checkbox',
174
'label' => \_\_( 'Ultimate Member support', 'permalink-manager' ),
175
'input\_class' \=> '',
205
176
'class\_exists' => 'UM',
206
'description' \=> \_\_('If enabled, Permalink Manager will detect the additional Ultimate Member pages (eg. "account" sections).', 'permalink-manager')
207
),
208
'yoast\_breadcrumbs' \=> array(
209
'type' \=> 'single\_checkbox',
210
'label' \=> \_\_('Breadcrumbs support', 'permalink-manager'),
211
'input\_class' => '',
212
'description' => \_\_('If enabled, the HTML breadcrumbs will be filtered by Permalink Manager to mimic the current URL structure.<br />Works with: <strong>WooCommerce, Yoast SEO, Slim Seo, RankMath and SEOPress</strong> breadcrumbs.', 'permalink-manager')
213
),
214
'primary\_category' \=> array(
215
'type' \=> 'single\_checkbox',
216
'label' \=> \_\_('"Primary category" support', 'permalink-manager'),
217
'input\_class' => '',
218
'description' => \_\_('If enabled, Permalink Manager will use the "primary category" for the default post permalinks.<br />Works with: <strong>Yoast SEO, The SEO Framework, RankMath and SEOPress</strong>.', 'permalink-manager')
177
'description' => \_\_( 'If enabled, Permalink Manager will detect the additional Ultimate Member pages (eg. "account" sections).', 'permalink-manager' )
178
),
179
'yoast\_breadcrumbs' \=> array(
180
'type' \=> 'single\_checkbox',
181
'label' => \_\_( 'Breadcrumbs support', 'permalink-manager' ),
182
'input\_class' => '',
183
'description' => \_\_( 'If enabled, the HTML breadcrumbs will be filtered by Permalink Manager to mimic the current URL structure.<br />Works with: <strong>WooCommerce, Yoast SEO, Slim Seo, RankMath and SEOPress</strong> breadcrumbs.', 'permalink-manager' )
184
),
185
'primary\_category' \=> array(
186
'type' \=> 'single\_checkbox',
187
'label' => \_\_( '"Primary category" support', 'permalink-manager' ),
188
'input\_class' => '',
189
'description' => \_\_( 'If enabled, Permalink Manager will use the "primary category" for the default post permalinks.<br />Works with: <strong>Yoast SEO, The SEO Framework, RankMath and SEOPress</strong>.', 'permalink-manager' )
219
190
),
220
191
)
221
192
),
222
'advanced' \=> array(
223
'section\_name' => \_\_('Advanced settings', 'permalink-manager'),
224
'container' \=> 'row',
225
'name' \=> 'general',
226
'fields' \=> array(
227
'show\_native\_slug\_field' \=> array(
228
'type' \=> 'single\_checkbox',
229
'label' => \_\_('Show "Native slug" field in URI Editor', 'permalink-manager')
230
),
231
'partial\_disable\_strict' \=> array(
232
'type' \=> 'single\_checkbox',
233
'label' \=> \_\_('"Exclude content types" strict mode', 'permalink-manager'),
234
'description' => \_\_('If this option is enabled, any custom post types and taxonomies with the "<strong>query\_var</strong>" and "<strong>rewrite</strong>" attributes set to "<em>false</em>" will be excluded from the plugin and hence will not be shown in the "<em>General settings -> Exclude content types</em>" options.', 'permalink-manager')
235
),
236
'pagination\_redirect' \=> array(
237
'type' \=> 'single\_checkbox',
238
'label' \=> \_\_('Force 404 on non-existing pagination pages', 'permalink-manager'),
239
'description' => \_\_('If enabled, the non-existing pagination pages (for single posts) will return 404 ("Not Found") error.<br /><strong>Please disable it, if you encounter any problems with pagination pages or use custom pagination system.</strong>', 'permalink-manager')
193
'advanced' \=> array(
194
'section\_name' => \_\_( 'Advanced settings', 'permalink-manager' ),
195
'container' \=> 'row',
196
'name' \=> 'general',
197
'fields' \=> array(
198
'show\_native\_slug\_field' \=> array(
199
'type' \=> 'single\_checkbox',
200
'label' => \_\_( 'Show "Native slug" field in URI Editor', 'permalink-manager' )
201
),
202
'partial\_disable\_strict' \=> array(
203
'type' \=> 'single\_checkbox',
204
'label' => \_\_( '"Exclude content types" strict mode', 'permalink-manager' ),
205
'description' => \_\_( 'If this option is enabled, any custom post types and taxonomies with the "<strong>query\_var</strong>" and "<strong>rewrite</strong>" attributes set to "<em>false</em>" will be excluded from the plugin and hence will not be shown in the "<em>General settings -> Exclude content types</em>" options.', 'permalink-manager' )
206
),
207
'pagination\_redirect' \=> array(
208
'type' \=> 'single\_checkbox',
209
'label' => \_\_( 'Force 404 on non-existing pagination pages', 'permalink-manager' ),
210
'description' => \_\_( 'If enabled, the non-existing pagination pages (for single posts) will return 404 ("Not Found") error.<br /><strong>Please disable it, if you encounter any problems with pagination pages or use custom pagination system.</strong>', 'permalink-manager' )
240
211
),
241
212
'disable\_slug\_sanitization' => array(
242
'type' => 'select',
243
'label' => \_\_('Strip special characters', 'permalink-manager'),
244
'input\_class' => 'settings-select',
245
'choices' => array(0 => \_\_('Yes, use native settings', 'permalink-manager'), 1 => \_\_('No, keep special characters (.,|\_+) in the slugs', 'permalink-manager')),
246
'description' => \_\_('If enabled only alphanumeric characters, underscores and dashes will be allowed for post/term slugs.', 'permalink-manager')
247
),
248
'keep\_accents' => array(
249
'type' => 'select',
250
'label' => \_\_('Convert accented letters', 'permalink-manager'),
251
'input\_class' => 'settings-select',
252
'choices' => array(0 => \_\_('Yes, use native settings', 'permalink-manager'), 1 => \_\_('No, keep accented letters in the slugs', 'permalink-manager')),
253
'description' => \_\_('If enabled, all the accented letters will be replaced with their non-accented equivalent (eg. Å => A, Æ => AE, Ø => O, Ć => C).', 'permalink-manager')
254
),
255
'edit\_uris\_cap' => array(
256
'type' => 'select',
257
'label' => \_\_('URI Editor role capability', 'permalink-manager'),
258
'choices' => array('edit\_theme\_options' => \_\_('Administrator (edit\_theme\_options)', 'permalink-manager'), 'publish\_pages' => \_\_('Editor (publish\_pages)', 'permalink-manager'), 'publish\_posts' => \_\_('Author (publish\_posts)', 'permalink-manager'), 'edit\_posts' => \_\_('Contributor (edit\_posts)', 'permalink-manager')),
259
'description' => sprintf(\_\_('Only the users who have selected capability will be able to access URI Editor.<br />The list of capabilities <a href="%s" target="\_blank">can be found here</a>.', 'permalink-manager'), 'https://wordpress.org/support/article/roles-and-capabilities/#capability-vs-role-table')
260
),
261
'auto\_fix\_duplicates' => array(
262
'type' => 'select',
263
'label' => \_\_('Automatically fix broken URIs', 'permalink-manager'),
264
'input\_class' => 'settings-select',
265
'choices' => array(0 => \_\_('No', 'permalink-manager'), 1 => \_\_('Fix URIs individually (during page load)', 'permalink-manager'), 2 => \_\_('Bulk fix all URIs (once a day, in the background)', 'permalink-manager')),
266
'description' => sprintf('%s',
267
\_\_('Enable this option if you would like to automatically remove redundant permalinks & duplicated redirects.', 'permalink-manager')
268
)
213
'type' => 'select',
214
'label' => \_\_( 'Strip special characters', 'permalink-manager' ),
215
'input\_class' => 'settings-select',
216
'choices' => array( 0 => \_\_( 'Yes, use native settings', 'permalink-manager' ), 1 => \_\_( 'No, keep special characters (.,|\_+) in the slugs', 'permalink-manager' ) ),
217
'description' => \_\_( 'If enabled only alphanumeric characters, underscores and dashes will be allowed for post/term slugs.', 'permalink-manager' )
218
),
219
'keep\_accents' => array(
220
'type' => 'select',
221
'label' => \_\_( 'Convert accented letters', 'permalink-manager' ),
222
'input\_class' => 'settings-select',
223
'choices' => array( 0 => \_\_( 'Yes, use native settings', 'permalink-manager' ), 1 => \_\_( 'No, keep accented letters in the slugs', 'permalink-manager' ) ),
224
'description' => \_\_( 'If enabled, all the accented letters will be replaced with their non-accented equivalent (eg. Å => A, Æ => AE, Ø => O, Ć => C).', 'permalink-manager' )
225
),
226
'edit\_uris\_cap' => array(
227
'type' => 'select',
228
'label' => \_\_( 'URI Editor role capability', 'permalink-manager' ),
229
'choices' => array( 'edit\_theme\_options' => \_\_( 'Administrator (edit\_theme\_options)', 'permalink-manager' ), 'publish\_pages' => \_\_( 'Editor (publish\_pages)', 'permalink-manager' ), 'publish\_posts' => \_\_( 'Author (publish\_posts)', 'permalink-manager' ), 'edit\_posts' => \_\_( 'Contributor (edit\_posts)', 'permalink-manager' ) ),
230
'description' => sprintf( \_\_( 'Only the users who have selected capability will be able to access URI Editor.<br />The list of capabilities <a href="%s" target="\_blank">can be found here</a>.', 'permalink-manager' ), 'https://wordpress.org/support/article/roles-and-capabilities/#capability-vs-role-table' )
231
),
232
'auto\_fix\_duplicates' => array(
233
'type' => 'select',
234
'label' => \_\_( 'Automatically fix broken URIs', 'permalink-manager' ),
235
'input\_class' => 'settings-select',
236
'choices' => array( 0 => \_\_( 'No', 'permalink-manager' ), 1 => \_\_( 'Fix URIs individually (during page load)', 'permalink-manager' ), 2 => \_\_( 'Bulk fix all URIs (once a day, in the background)', 'permalink-manager' ) ),
237
'description' => sprintf( '%s', \_\_( 'Enable this option if you would like to automatically remove redundant permalinks & duplicated redirects.', 'permalink-manager' ) )
269
238
)
270
239
)
271
240
)
272
));
273
274
$output = Permalink\_Manager\_Admin\_Functions::get\_the\_form($sections\_and\_fields, 'tabs', array('text' => \_\_( 'Save settings', 'permalink-manager' ), 'class' => 'primary margin-top'), '', array('action' => 'permalink-manager', 'name' => 'permalink\_manager\_options'));
275
return $output;
241
) );
242
243
return Permalink\_Manager\_Admin\_Functions::get\_the\_form( $sections\_and\_fields, 'tabs', array( 'text' => \_\_( 'Save settings', 'permalink-manager' ), 'class' => 'primary margin-top' ), '', array( 'action' => 'permalink-manager', 'name' => 'permalink\_manager\_options' ) );
276
244
}
277
245
}
permalink-manager/trunk/includes/views/permalink-manager-tools.php
r2818142
r2833667
2
2
3
3
/\*\*
4
\* Display the page where the slugs could be regenerated or replaced
5
\*/
6
class Permalink\_Manager\_Tools extends Permalink\_Manager\_Class {
4
\* Display the page where the slugs could be regenerated or replaced
5
\*/
6
class Permalink\_Manager\_Tools {
7
7
8
8
public function \_\_construct() {
9
add\_filter( 'permalink\_manager\_sections', array($this, 'add\_admin\_section'), 1 );
10
}
11
12
public function add\_admin\_section($admin\_sections) {
13
9
add\_filter( 'permalink\_manager\_sections', array( $this, 'add\_admin\_section' ), 1 );
10
}
11
12
/\*\*
13
\* Add a new section to the Permalink Manager UI
14
\*
15
\* @param array $admin\_sections
16
\*
17
\* @return array
18
\*/
19
public function add\_admin\_section( $admin\_sections ) {
14
20
$admin\_sections\['tools'\] = array(
15
'name' => \_\_('Tools', 'permalink-manager'),
21
'name' => \_\_( 'Tools', 'permalink-manager' ),
16
22
'subsections' => array(
17
'duplicates' \=> array(
18
'name' => \_\_('Permalink Duplicates', 'permalink-manager'),
19
'function' => array('class' => 'Permalink\_Manager\_Tools', 'method' => 'duplicates\_output')
23
'duplicates' \=> array(
24
'name' => \_\_( 'Permalink Duplicates', 'permalink-manager' ),
25
'function' => array( 'class' => 'Permalink\_Manager\_Tools', 'method' => 'duplicates\_output' )
20
26
),
21
27
'find\_and\_replace' => array(
22
'name' => \_\_('Find & Replace', 'permalink-manager'),
23
'function' => array('class' => 'Permalink\_Manager\_Tools', 'method' => 'find\_and\_replace\_output')
28
'name' => \_\_( 'Find & Replace', 'permalink-manager' ),
29
'function' => array( 'class' => 'Permalink\_Manager\_Tools', 'method' => 'find\_and\_replace\_output' )
24
30
),
25
31
'regenerate\_slugs' => array(
26
'name' => \_\_('Regenerate/Reset', 'permalink-manager'),
27
'function' => array('class' => 'Permalink\_Manager\_Tools', 'method' => 'regenerate\_slugs\_output')
28
),
29
'stop\_words' \=> array(
30
'name' => \_\_('Stop Words', 'permalink-manager'),
31
'function' => array('class' => 'Permalink\_Manager\_Admin\_Functions', 'method' => 'pro\_text')
32
),
33
'import' \=> array(
34
'name' => \_\_('Custom Permalinks', 'permalink-manager'),
35
'function' => array('class' => 'Permalink\_Manager\_Admin\_Functions', 'method' => 'pro\_text')
32
'name' => \_\_( 'Regenerate/Reset', 'permalink-manager' ),
33
'function' => array( 'class' => 'Permalink\_Manager\_Tools', 'method' => 'regenerate\_slugs\_output' )
34
),
35
'stop\_words' \=> array(
36
'name' => \_\_( 'Stop Words', 'permalink-manager' ),
37
'function' => array( 'class' => 'Permalink\_Manager\_Admin\_Functions', 'method' => 'pro\_text' )
38
),
39
'import' \=> array(
40
'name' => \_\_( 'Custom Permalinks', 'permalink-manager' ),
41
'function' => array( 'class' => 'Permalink\_Manager\_Admin\_Functions', 'method' => 'pro\_text' )
36
42
)
37
43
)
…
…
41
47
}
42
48
49
/\*\*
50
\* Display a warning message before the user changes the permalinks mode to "Native slugs"
51
\*
52
\* @return string
53
\*/
43
54
public function display\_instructions() {
44
return wpautop(\_\_('<strong>A MySQL backup is highly recommended before using "<em>Native slugs</em>" mode!</strong>', 'permalink-manager'));
45
}
46
55
return wpautop( \_\_( '<strong>A MySQL backup is highly recommended before using "<em>Native slugs</em>" mode!</strong>', 'permalink-manager' ) );
56
}
57
58
/\*\*
59
\* Display a list of all duplicated URIs and redirects
60
\*
61
\* @return string
62
\*/
47
63
public function duplicates\_output() {
48
global $permalink\_manager\_uris, $permalink\_manager\_redirects;
49
50
64
// Get the duplicates & another variables
51
65
$all\_duplicates = Permalink\_Manager\_Helper\_Functions::get\_all\_duplicates();
52
$home\_url \= trim(get\_option('home'), "/");
53
54
$button\_url = add\_query\_arg(array(
55
'section' \=> 'tools',
56
'subsection' \=> 'duplicates',
66
$home\_url = trim( get\_option( 'home' ), "/" );
67
68
$button\_url = add\_query\_arg( array(
69
'section' \=> 'tools',
70
'subsection' \=> 'duplicates',
57
71
'clear-permalink-manager-uris' => 1,
58
'\_wpnonce' => wp\_create\_nonce('permalink-manager')
59
), Permalink\_Manager\_Admin\_Functions::get\_admin\_url());
60
61
$html = sprintf("<h3>%s</h3>", \_\_("List of duplicated permalinks", "permalink-manager"));
62
$html .= wpautop(sprintf("<a class=\\"button button-primary\\" href=\\"%s\\">%s</a>", $button\_url, \_\_('Fix custom permalinks & redirects', 'permalink-manager')));
63
64
if(!empty($all\_duplicates)) {
65
foreach($all\_duplicates as $uri => $duplicates) {
72
'permalink-manager-nonce' => wp\_create\_nonce( 'permalink-manager' )
73
), Permalink\_Manager\_Admin\_Functions::get\_admin\_url() );
74
75
$html = sprintf( "<h3>%s</h3>", \_\_( "List of duplicated permalinks", "permalink-manager" ) );
76
$html .= wpautop( sprintf( "<a class=\\"button button-primary\\" href=\\"%s\\">%s</a>", $button\_url, \_\_( 'Fix custom permalinks & redirects', 'permalink-manager' ) ) );
77
78
if ( ! empty( $all\_duplicates ) ) {
79
foreach ( $all\_duplicates as $uri => $duplicates ) {
66
80
$html .= "<div class=\\"permalink-manager postbox permalink-manager-duplicate-box\\">";
67
81
$html .= "<h4 class=\\"heading\\"><a href=\\"{$home\_url}/{$uri}\\" target=\\"\_blank\\">{$home\_url}/{$uri} <span class=\\"dashicons dashicons-external\\"></span></a></h4>";
68
82
$html .= "<table>";
69
83
70
foreach($duplicates as $item\_id) {
84
foreach ( $duplicates as $item\_id ) {
71
85
$html .= "<tr>";
72
86
73
87
// Detect duplicate type
74
preg\_match("/(redirect-(\[\\d\]+)\_)?(?:(tax-)?(\[\\d\]\*))/", $item\_id, $parts);
75
76
$is\_extra\_redirect = (!empty($parts\[1\])) ? true : false;
77
$duplicate\_type \= ($is\_extra\_redirect) ? \_\_('Extra Redirect', 'permalink-manager') : \_\_('Custom URI', 'permalink-manager');
78
$detected\_id \= $parts\[4\];
79
$detected\_index = $parts\[2\];
80
$detected\_term = (!empty($parts\[3\])) ? true : false;
81
$remove\_link \= ($is\_extra\_redirect) ? sprintf(" <a href=\\"%s\\"><span class=\\"dashicons dashicons-trash\\"></span> %s</a>", admin\_url("tools.php?page=permalink-manager§ion=tools&subsection=duplicates&remove-redirect={$item\_id}"), \_\_("Remove Redirect")) : "";
88
preg\_match( "/(redirect-(\[\\d\]+)\_)?(?:(tax-)?(\[\\d\]\*))/", $item\_id, $parts );
89
90
$is\_extra\_redirect = ( ! empty( $parts\[1\] ) ) ? true : false;
91
$duplicate\_type = ( $is\_extra\_redirect ) ? \_\_( 'Extra Redirect', 'permalink-manager' ) : \_\_( 'Custom URI', 'permalink-manager' );
92
$detected\_id \= $parts\[4\];
93
// $detected\_index = $parts\[2\];
94
$detected\_term = ( ! empty( $parts\[3\] ) ) ? true : false;
95
$remove\_link = ( $is\_extra\_redirect ) ? sprintf( " <a href=\\"%s\\"><span class=\\"dashicons dashicons-trash\\"></span> %s</a>", admin\_url( "tools.php?page=permalink-manager§ion=tools&subsection=duplicates&remove-redirect={$item\_id}" ), \_\_( "Remove Redirect" ) ) : "";
82
96
83
97
// Get term
84
if($detected\_term && !empty($detected\_id)) {
85
$term = get\_term($detected\_id);
86
if(!empty($term->name)) {
87
$title \= $term->name;
88
$edit\_label = "<span class=\\"dashicons dashicons-edit\\"></span>" . \_\_("Edit term", "permalink-manager");
89
$edit\_link \= get\_edit\_tag\_link($term->term\_id, $term->taxonomy);
98
if ( $detected\_term && ! empty( $detected\_id ) ) {
99
$term = get\_term( $detected\_id );
100
if ( ! empty( $term->name ) ) {
101
$title \= $term->name;
102
$edit\_label = "<span class=\\"dashicons dashicons-edit\\"></span>" . \_\_( "Edit term", "permalink-manager" );
103
$edit\_link = get\_edit\_tag\_link( $term->term\_id, $term->taxonomy );
90
104
} else {
91
$title \= \_\_("(Removed term)", "permalink-manager");
92
$edit\_label = "<span class=\\"dashicons dashicons-trash\\"></span>" . \_\_("Remove broken URI", "permalink-manager");
93
$edit\_link \= admin\_url("tools.php?page=permalink-manager§ion=tools&subsection=duplicates&remove-uri=tax-{$detected\_id}");
105
$title = \_\_( "(Removed term)", "permalink-manager" );
106
$edit\_label = "<span class=\\"dashicons dashicons-trash\\"></span>" . \_\_( "Remove broken URI", "permalink-manager" );
107
$edit\_link = admin\_url( "tools.php?page=permalink-manager§ion=tools&subsection=duplicates&remove-uri=tax-{$detected\_id}" );
94
108
}
95
}
96
// Get post
97
else if(!empty($detected\_id)) {
98
$post = get\_post($detected\_id);
99
if(!empty($post->post\_title) && post\_type\_exists($post->post\_type)) {
100
$title = $post->post\_title;
101
$edit\_label = "<span class=\\"dashicons dashicons-edit\\"></span>" . \_\_("Edit post", "permalink-manager");
102
$edit\_link = get\_edit\_post\_link($post->ID);
109
} // Get post
110
else if ( ! empty( $detected\_id ) ) {
111
$post = get\_post( $detected\_id );
112
if ( ! empty( $post->post\_title ) && post\_type\_exists( $post->post\_type ) ) {
113
$title = $post->post\_title;
114
$edit\_label = "<span class=\\"dashicons dashicons-edit\\"></span>" . \_\_( "Edit post", "permalink-manager" );
115
$edit\_link = get\_edit\_post\_link( $post->ID );
103
116
} else {
104
$title \= \_\_("(Removed post)", "permalink-manager");
105
$edit\_label = "<span class=\\"dashicons dashicons-trash\\"></span>" . \_\_("Remove broken URI", "permalink-manager");
106
$edit\_link \= admin\_url("tools.php?page=permalink-manager§ion=tools&subsection=duplicates&remove-uri={$detected\_id}");
117
$title = \_\_( "(Removed post)", "permalink-manager" );
118
$edit\_label = "<span class=\\"dashicons dashicons-trash\\"></span>" . \_\_( "Remove broken URI", "permalink-manager" );
119
$edit\_link = admin\_url( "tools.php?page=permalink-manager§ion=tools&subsection=duplicates&remove-uri={$detected\_id}" );
107
120
}
108
121
} else {
…
…
110
123
}
111
124
112
$html .= sprintf(
113
'<td><a href="%1$s">%2$s</a>%3$s</td><td>%4$s</td><td class="actions"><a href="%1$s">%5$s</a>%6$s</td>',
114
$edit\_link,
115
$title,
116
" <small>#{$detected\_id}</small>",
117
$duplicate\_type,
118
$edit\_label,
119
$remove\_link
120
);
125
$html .= sprintf( '<td><a href="%1$s">%2$s</a>%3$s</td><td>%4$s</td><td class="actions"><a href="%1$s">%5$s</a>%6$s</td>', $edit\_link, $title, " <small>#{$detected\_id}</small>", $duplicate\_type, $edit\_label, $remove\_link );
121
126
$html .= "</tr>";
122
127
}
…
…
125
130
}
126
131
} else {
127
$html .= sprintf("<p class=\\"alert notice-success notice\\">%s</p>", \_\_('Congratulations! No duplicated URIs or Redirects found!', 'permalink-manager'));
132
$html .= sprintf( "<p class=\\"alert notice-success notice\\">%s</p>", \_\_( 'Congratulations! No duplicated URIs or Redirects found!', 'permalink-manager' ) );
128
133
}
129
134
…
…
131
136
}
132
137
138
/\*\*
139
\* Generate a form for "Tools -> Find & replace" tool
140
\*
141
\* @return string
142
\*/
133
143
public function find\_and\_replace\_output() {
134
144
// Get all registered post types array & statuses
135
145
$all\_post\_statuses\_array = Permalink\_Manager\_Helper\_Functions::get\_post\_statuses();
136
$all\_post\_types = Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array();
137
$all\_taxonomies = Permalink\_Manager\_Helper\_Functions::get\_taxonomies\_array();
138
139
$fields = apply\_filters('permalink\_manager\_tools\_fields', array(
140
'old\_string' => array(
141
'label' => \_\_( 'Find ...', 'permalink-manager' ),
142
'type' => 'text',
146
$all\_post\_types = Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array();
147
$all\_taxonomies = Permalink\_Manager\_Helper\_Functions::get\_taxonomies\_array();
148
149
$fields = apply\_filters( 'permalink\_manager\_tools\_fields', array(
150
'old\_string' => array(
151
'label' => \_\_( 'Find ...', 'permalink-manager' ),
152
'type' => 'text',
153
'container' => 'row',
154
'input\_class' => 'widefat'
155
),
156
'new\_string' => array(
157
'label' => \_\_( 'Replace with ...', 'permalink-manager' ),
158
'type' => 'text',
159
'container' => 'row',
160
'input\_class' => 'widefat'
161
),
162
'mode' => array(
163
'label' => \_\_( 'Mode', 'permalink-manager' ),
164
'type' => 'select',
143
165
'container' => 'row',
144
'input\_class' => 'widefat'
145
),
146
'new\_string' => array(
147
'label' => \_\_( 'Replace with ...', 'permalink-manager' ),
148
'type' => 'text',
166
'choices' => array(
167
'custom\_uris' => \_\_( 'Custom URIs', 'permalink-manager' ),
168
'slugs' => \_\_( 'Native slugs', 'permalink-manager' )
169
),
170
),
171
'content\_type' => array(
172
'label' => \_\_( 'Select content type', 'permalink-manager' ),
173
'type' => 'select',
174
'disabled' => true,
175
'pro' => true,
149
176
'container' => 'row',
150
'input\_class' => 'widefat'
151
),
152
'mode' => array(
153
'label' => \_\_( 'Mode', 'permalink-manager' ),
154
'type' => 'select',
155
'container' => 'row',
156
'choices' => array(
157
'custom\_uris' => \_\_('Custom URIs', 'permalink-manager'),
158
'slugs' => \_\_('Native slugs', 'permalink-manager')
159
),
160
),
161
'content\_type' => array(
162
'label' => \_\_( 'Select content type', 'permalink-manager' ),
163
'type' => 'select',
164
'disabled' => true,
165
'pro' => true,
166
'container' => 'row',
167
'default' => 'post\_types',
168
'choices' => array(
169
'post\_types' => \_\_('Post types', 'permalink-manager'),
170
'taxonomies' => \_\_('Taxonomies', 'permalink-manager')
171
),
172
),
173
'post\_types' => array(
174
'label' => \_\_( 'Select post types', 'permalink-manager' ),
175
'type' => 'checkbox',
176
'container' => 'row',
177
'default' => array('post', 'page'),
178
'choices' => $all\_post\_types,
179
'select\_all' => '',
177
'default' => 'post\_types',
178
'choices' => array(
179
'post\_types' => \_\_( 'Post types', 'permalink-manager' ),
180
'taxonomies' => \_\_( 'Taxonomies', 'permalink-manager' )
181
),
182
),
183
'post\_types' => array(
184
'label' => \_\_( 'Select post types', 'permalink-manager' ),
185
'type' => 'checkbox',
186
'container' => 'row',
187
'default' => array( 'post', 'page' ),
188
'choices' => $all\_post\_types,
189
'select\_all' => '',
180
190
'unselect\_all' => '',
181
191
),
182
'taxonomies' \=> array(
183
'label' \=> \_\_( 'Select taxonomies', 'permalink-manager' ),
184
'type' \=> 'checkbox',
185
'container' \=> 'row',
192
'taxonomies' \=> array(
193
'label' \=> \_\_( 'Select taxonomies', 'permalink-manager' ),
194
'type' \=> 'checkbox',
195
'container' \=> 'row',
186
196
'container\_class' => 'hidden',
187
'default' => array('category', 'post\_tag'),
188
'choices' => $all\_taxonomies,
189
'pro' => true,
190
'select\_all' => '',
197
'default' => array( 'category', 'post\_tag' ),
198
'choices' => $all\_taxonomies,
199
'pro' => true,
200
'select\_all' => '',
201
'unselect\_all' => '',
202
),
203
'post\_statuses' => array(
204
'label' => \_\_( 'Select post statuses', 'permalink-manager' ),
205
'type' => 'checkbox',
206
'container' => 'row',
207
'default' => array( 'publish' ),
208
'choices' => $all\_post\_statuses\_array,
209
'select\_all' => '',
191
210
'unselect\_all' => '',
192
211
),
193
'post\_statuses' => array(
194
'label' => \_\_( 'Select post statuses', 'permalink-manager' ),
195
'type' => 'checkbox',
196
'container' => 'row',
197
'default' => array('publish'),
198
'choices' => $all\_post\_statuses\_array,
199
'select\_all' => '',
200
'unselect\_all' => '',
201
),
202
'ids' => array(
203
'label' => \_\_( 'Select IDs', 'permalink-manager' ),
204
'type' => 'text',
205
'container' => 'row',
212
'ids' => array(
213
'label' => \_\_( 'Select IDs', 'permalink-manager' ),
214
'type' => 'text',
215
'container' => 'row',
206
216
//'disabled' => true,
207
'description' => \_\_('To narrow the above filters you can type the post IDs (or ranges) here. Eg. <strong>1-8, 10, 25</strong>.', 'permalink-manager'),
217
'description' => \_\_( 'To narrow the above filters you can type the post IDs (or ranges) here. Eg. <strong>1-8, 10, 25</strong>.', 'permalink-manager' ),
208
218
//'pro' => true,
209
219
'input\_class' => 'widefat'
210
220
)
211
), 'find\_and\_replace');
212
213
$sidebar = '<h3>' . \_\_('Important notices', 'permalink-manager') . '</h3>';
221
), 'find\_and\_replace' );
222
223
$sidebar = '<h3>' . \_\_( 'Important notices', 'permalink-manager' ) . '</h3>';
214
224
$sidebar .= self::display\_instructions();
215
225
216
$output = Permalink\_Manager\_Admin\_Functions::get\_the\_form($fields, 'columns-3', array('text' => \_\_('Find and replace', 'permalink-manager'), 'class' => 'primary margin-top'), $sidebar, array('action' => 'permalink-manager', 'name' => 'find\_and\_replace'), true, 'form-ajax');
217
218
return $output;
219
}
220
226
return Permalink\_Manager\_Admin\_Functions::get\_the\_form( $fields, 'columns-3', array( 'text' => \_\_( 'Find and replace', 'permalink-manager' ), 'class' => 'primary margin-top' ), $sidebar, array( 'action' => 'permalink-manager', 'name' => 'find\_and\_replace' ), true, 'form-ajax' );
227
}
228
229
/\*\*
230
\* Generate a form for "Tools -> Regenerate/reset" tool
231
\*
232
\* @return string
233
\*/
221
234
public function regenerate\_slugs\_output() {
222
235
// Get all registered post types array & statuses
223
236
$all\_post\_statuses\_array = Permalink\_Manager\_Helper\_Functions::get\_post\_statuses();
224
$all\_post\_types \= Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array();
225
$all\_taxonomies \= Permalink\_Manager\_Helper\_Functions::get\_taxonomies\_array();
226
227
$fields = apply\_filters('permalink\_manager\_tools\_fields', array(
228
'mode' \=> array(
229
'label' \=> \_\_( 'Mode', 'permalink-manager' ),
230
'type' \=> 'select',
237
$all\_post\_types \= Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array();
238
$all\_taxonomies \= Permalink\_Manager\_Helper\_Functions::get\_taxonomies\_array();
239
240
$fields = apply\_filters( 'permalink\_manager\_tools\_fields', array(
241
'mode' \=> array(
242
'label' \=> \_\_( 'Mode', 'permalink-manager' ),
243
'type' \=> 'select',
231
244
'container' => 'row',
232
'choices' \=> array(
233
'custom\_uris' => \_\_('Regenerate custom permalinks', 'permalink-manager'),
234
'slugs' \=> \_\_('Regenerate native slugs', 'permalink-manager'),
235
'native' \=> \_\_('Use original URLs as custom permalinks', 'permalink-manager')
236
),
237
),
238
'content\_type' \=> array(
239
'label' \=> \_\_( 'Select content type', 'permalink-manager' ),
240
'type' \=> 'select',
241
'disabled' \=> true,
242
'pro' \=> true,
245
'choices' \=> array(
246
'custom\_uris' => \_\_( 'Regenerate custom permalinks', 'permalink-manager' ),
247
'slugs' => \_\_( 'Regenerate native slugs', 'permalink-manager' ),
248
'native' => \_\_( 'Use original URLs as custom permalinks', 'permalink-manager' )
249
),
250
),
251
'content\_type' \=> array(
252
'label' \=> \_\_( 'Select content type', 'permalink-manager' ),
253
'type' \=> 'select',
254
'disabled' \=> true,
255
'pro' \=> true,
243
256
'container' => 'row',
244
'default' \=> 'post\_types',
245
'choices' \=> array(
246
'post\_types' => \_\_('Post types', 'permalink-manager'),
247
'taxonomies' => \_\_('Taxonomies', 'permalink-manager')
248
),
249
),
250
'post\_types' \=> array(
251
'label' \=> \_\_( 'Select post types', 'permalink-manager' ),
252
'type' \=> 'checkbox',
253
'container' \=> 'row',
254
'default' \=> array('post', 'page'),
255
'choices' \=> $all\_post\_types,
256
'select\_all' \=> '',
257
'default' \=> 'post\_types',
258
'choices' \=> array(
259
'post\_types' => \_\_( 'Post types', 'permalink-manager' ),
260
'taxonomies' => \_\_( 'Taxonomies', 'permalink-manager' )
261
),
262
),
263
'post\_types' \=> array(
264
'label' \=> \_\_( 'Select post types', 'permalink-manager' ),
265
'type' \=> 'checkbox',
266
'container' \=> 'row',
267
'default' => array( 'post', 'page' ),
268
'choices' \=> $all\_post\_types,
269
'select\_all' \=> '',
257
270
'unselect\_all' => '',
258
271
),
259
'taxonomies' \=> array(
260
'label' \=> \_\_( 'Select taxonomies', 'permalink-manager' ),
261
'type' \=> 'checkbox',
262
'container' \=> 'row',
272
'taxonomies' \=> array(
273
'label' \=> \_\_( 'Select taxonomies', 'permalink-manager' ),
274
'type' \=> 'checkbox',
275
'container' \=> 'row',
263
276
'container\_class' => 'hidden',
264
'default' => array('category', 'post\_tag'),
265
'choices' => $all\_taxonomies,
266
'pro' => true,
267
'select\_all' => '',
277
'default' => array( 'category', 'post\_tag' ),
278
'choices' => $all\_taxonomies,
279
'pro' => true,
280
'select\_all' => '',
281
'unselect\_all' => '',
282
),
283
'post\_statuses' => array(
284
'label' => \_\_( 'Select post statuses', 'permalink-manager' ),
285
'type' => 'checkbox',
286
'container' => 'row',
287
'default' => array( 'publish' ),
288
'choices' => $all\_post\_statuses\_array,
289
'select\_all' => '',
268
290
'unselect\_all' => '',
269
291
),
270
'post\_statuses' => array(
271
'label' => \_\_( 'Select post statuses', 'permalink-manager' ),
272
'type' => 'checkbox',
273
'container' => 'row',
274
'default' => array('publish'),
275
'choices' => $all\_post\_statuses\_array,
276
'select\_all' => '',
277
'unselect\_all' => '',
278
),
279
'ids' => array(
280
'label' => \_\_( 'Select IDs', 'permalink-manager' ),
281
'type' => 'text',
282
'container' => 'row',
292
'ids' => array(
293
'label' => \_\_( 'Select IDs', 'permalink-manager' ),
294
'type' => 'text',
295
'container' => 'row',
283
296
//'disabled' => true,
284
'description' => \_\_('To narrow the above filters you can type the post IDs (or ranges) here. Eg. <strong>1-8, 10, 25</strong>.', 'permalink-manager'),
297
'description' => \_\_( 'To narrow the above filters you can type the post IDs (or ranges) here. Eg. <strong>1-8, 10, 25</strong>.', 'permalink-manager' ),
285
298
//'pro' => true,
286
299
'input\_class' => 'widefat'
287
300
)
288
), 'regenerate');
289
290
$sidebar = '<h3>' . \_\_('Important notices', 'permalink-manager') . '</h3>';
301
), 'regenerate' );
302
303
$sidebar = '<h3>' . \_\_( 'Important notices', 'permalink-manager' ) . '</h3>';
291
304
$sidebar .= self::display\_instructions();
292
305
293
$output = Permalink\_Manager\_Admin\_Functions::get\_the\_form($fields, 'columns-3', array('text' => \_\_( 'Regenerate', 'permalink-manager' ), 'class' => 'primary margin-top'), $sidebar, array('action' => 'permalink-manager', 'name' => 'regenerate'), true, 'form-ajax');
294
295
return $output;
306
return Permalink\_Manager\_Admin\_Functions::get\_the\_form( $fields, 'columns-3', array( 'text' => \_\_( 'Regenerate', 'permalink-manager' ), 'class' => 'primary margin-top' ), $sidebar, array( 'action' => 'permalink-manager', 'name' => 'regenerate' ), true, 'form-ajax' );
296
307
}
297
308
}
permalink-manager/trunk/includes/views/permalink-manager-uri-editor-post.php
r2617181
r2833667
2
2
3
3
/\*\*
4
\* Extend WP\_List\_Table with two subclasses for post types and taxonomies
5
\*/
4
\* Use WP\_List\_Table to display the "Bulk URI Editor" for post items
5
\*/
6
6
class Permalink\_Manager\_URI\_Editor\_Post extends WP\_List\_Table {
7
7
…
…
9
9
10
10
public function \_\_construct() {
11
global $status, $page, $permalink\_manager\_options, $active\_subsection;
12
13
parent::\_\_construct(array(
14
'singular' => 'slug',
15
'plural' => 'slugs'
16
));
17
18
$this->displayed\_post\_statuses = (isset($permalink\_manager\_options\['screen-options'\]\['post\_statuses'\])) ? "'" . implode("', '", $permalink\_manager\_options\['screen-options'\]\['post\_statuses'\]) . "'" : "'no-post-status'";
19
$this->displayed\_post\_types = ($active\_subsection && $active\_subsection == 'all') ? "'" . implode("', '", $permalink\_manager\_options\['screen-options'\]\['post\_types'\]) . "'" : "'{$active\_subsection}'";
20
}
21
22
/\*\*
23
\* Get the HTML output with the WP\_List\_Table
24
\*/
11
global $permalink\_manager\_options, $active\_subsection;
12
13
parent::\_\_construct( array(
14
'singular' => 'slug',
15
'plural' => 'slugs'
16
) );
17
18
$this->displayed\_post\_statuses = ( isset( $permalink\_manager\_options\['screen-options'\]\['post\_statuses'\] ) ) ? "'" . implode( "', '", $permalink\_manager\_options\['screen-options'\]\['post\_statuses'\] ) . "'" : "'no-post-status'";
19
$this->displayed\_post\_types = ( $active\_subsection && $active\_subsection == 'all' ) ? "'" . implode( "', '", $permalink\_manager\_options\['screen-options'\]\['post\_types'\] ) . "'" : "'{$active\_subsection}'";
20
}
21
22
/\*\*
23
\* Get the HTML output with the whole WP\_List\_Table
24
\*
25
\* @return string
26
\*/
25
27
public function display\_admin\_section() {
26
global $wpdb;
27
28
28
$output = "<form id=\\"permalinks-post-types-table\\" class=\\"slugs-table\\" method=\\"post\\">";
29
$output .= wp\_nonce\_field('permalink-manager', 'uri\_editor', true, true);
30
$output .= Permalink\_Manager\_Admin\_Functions::generate\_option\_field('pm\_session\_id', array('value' => uniqid(), 'type' => 'hidden'));
29
$output .= wp\_nonce\_field( 'permalink-manager', 'uri\_editor' );
30
$output .= Permalink\_Manager\_Admin\_Functions::generate\_option\_field( 'pm\_session\_id', array( 'value' => uniqid(), 'type' => 'hidden' ) );
31
31
32
32
// Bypass
…
…
44
44
}
45
45
46
/\*\*
47
\* Return an array of classes to be used in the HTML table
48
\*
49
\* @return array
50
\*/
46
51
function get\_table\_classes() {
47
52
return array( 'widefat', 'striped', $this->\_args\['plural'\] );
…
…
49
54
50
55
/\*\*
51
\* Override the parent columns method. Defines the columns to use in your listing table
52
\*/
56
\* Add columns to the table
57
\*
58
\* @return array
59
\*/
53
60
public function get\_columns() {
54
return apply\_filters('permalink\_manager\_uri\_editor\_columns', array(
55
'item\_title' => \_\_('Post title', 'permalink-manager'),
56
'item\_uri' => \_\_('Full URI & Permalink', 'permalink-manager')
57
));
58
}
59
60
/\*\*
61
\* Hidden columns
62
\*/
63
public function get\_hidden\_columns() {
64
return array();
65
}
66
67
/\*\*
68
\* Sortable columns
69
\*/
61
return apply\_filters( 'permalink\_manager\_uri\_editor\_columns', array(
62
'item\_title' => \_\_( 'Post title', 'permalink-manager' ),
63
'item\_uri' => \_\_( 'Full URI & Permalink', 'permalink-manager' )
64
) );
65
}
66
67
/\*\*
68
\* Define sortable columns
69
\*
70
\* @return array
71
\*/
70
72
public function get\_sortable\_columns() {
71
73
return array(
72
'item\_title' => array('post\_title', false)
74
'item\_title' => array( 'post\_title', false )
73
75
);
74
76
}
75
77
76
78
/\*\*
77
\* Data inside the columns
78
\*/
79
public function column\_default($item, $column\_name) {
79
\* Data inside the columns
80
\*
81
\* @param array $item
82
\* @param string $column\_name
83
\*
84
\* @return string
85
\*/
86
public function column\_default( $item, $column\_name ) {
80
87
global $permalink\_manager\_options;
81
88
82
$uri = Permalink\_Manager\_URI\_Functions\_Post::get\_post\_uri($item\['ID'\], true);
83
$uri = (!empty($permalink\_manager\_options\['general'\]\['decode\_uris'\])) ? urldecode($uri) : $uri;
84
85
$field\_args\_base = array('type' => 'text', 'value' => $uri, 'without\_label' => true, 'input\_class' => 'custom\_uri', 'extra\_atts' => "data-element-id=\\"{$item\['ID'\]}\\"");
86
$permalink = get\_permalink($item\['ID'\]);
87
88
$post\_statuses\_array = get\_post\_statuses();
89
$post\_statuses\_array\['inherit'\] = \_\_('Inherit (Attachment)', 'permalink-manager');
90
91
$output = apply\_filters('permalink\_manager\_uri\_editor\_column\_content', '', $column\_name, get\_post($item\['ID'\]));
92
if(!empty($output)) { return $output; }
93
94
switch( $column\_name ) {
89
$uri = Permalink\_Manager\_URI\_Functions\_Post::get\_post\_uri( $item\['ID'\], true );
90
$uri = ( ! empty( $permalink\_manager\_options\['general'\]\['decode\_uris'\] ) ) ? urldecode( $uri ) : $uri;
91
92
$field\_args\_base = array( 'type' => 'text', 'value' => $uri, 'without\_label' => true, 'input\_class' => 'custom\_uri', 'extra\_atts' => "data-element-id=\\"{$item\['ID'\]}\\"" );
93
$permalink = get\_permalink( $item\['ID'\] );
94
$post\_title = sanitize\_text\_field( $item\['post\_title'\] );
95
96
$post\_statuses\_array = get\_post\_statuses();
97
$post\_statuses\_array\['inherit'\] = \_\_( 'Inherit (Attachment)', 'permalink-manager' );
98
99
$output = apply\_filters( 'permalink\_manager\_uri\_editor\_column\_content', '', $column\_name, get\_post( $item\['ID'\] ) );
100
if ( ! empty( $output ) ) {
101
return $output;
102
}
103
104
switch ( $column\_name ) {
95
105
case 'item\_uri':
96
106
// Get auto-update settings
97
$auto\_update\_val = get\_post\_meta($item\['ID'\], "auto\_update\_uri", true);
98
$auto\_update\_uri = (!empty($auto\_update\_val)) ? $auto\_update\_val : $permalink\_manager\_options\["general"\]\["auto\_update\_uris"\];
99
if($auto\_update\_uri) {
100
$field\_args\_base\['readonly'\] \= true;
101
$field\_args\_base\['append\_content'\] = sprintf('<p class="small uri\_locked">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', \_\_('The above permalink will be automatically updated and is locked for editing.', 'permalink-manager'));
107
$auto\_update\_val = get\_post\_meta( $item\['ID'\], "auto\_update\_uri", true );
108
$auto\_update\_uri = ( ! empty( $auto\_update\_val ) ) ? $auto\_update\_val : $permalink\_manager\_options\["general"\]\["auto\_update\_uris"\];
109
if ( $auto\_update\_uri ) {
110
$field\_args\_base\['readonly'\] \= true;
111
$field\_args\_base\['append\_content'\] = sprintf( '<p class="small uri\_locked">%s %s</p>', '<span class="dashicons dashicons-lock"></span>', \_\_( 'The above permalink will be automatically updated and is locked for editing.', 'permalink-manager' ) );
102
112
}
103
113
104
114
$output = '<div class="custom\_uri\_container">';
105
$output .= Permalink\_Manager\_Admin\_Functions::generate\_option\_field("uri\[{$item\['ID'\]}\]", $field\_args\_base);
115
$output .= Permalink\_Manager\_Admin\_Functions::generate\_option\_field( "uri\[{$item\['ID'\]}\]", $field\_args\_base );
106
116
$output .= "<span class=\\"duplicated\_uri\_alert\\"></span>";
107
$output .= sprintf("<a class=\\"small post\_permalink\\" href=\\"%s\\" target=\\"\_blank\\"><span class=\\"dashicons dashicons-admin-links\\"></span> %s</a>", $permalink, urldecode($permalink));
117
$output .= sprintf( "<a class=\\"small post\_permalink\\" href=\\"%s\\" target=\\"\_blank\\"><span class=\\"dashicons dashicons-admin-links\\"></span> %s</a>", $permalink, urldecode( $permalink ) );
108
118
$output .= '</div>';
119
109
120
return $output;
110
121
111
122
case 'item\_title':
112
$output = $item\[ 'post\_title' \];
123
$output = $post\_title;
113
124
$output .= '<div class="extra-info small">';
114
$output .= sprintf("<span><strong>%s:</strong> %s</span>", \_\_("Slug", "permalink-manager"), urldecode($item\['post\_name'\]));
115
$output .= sprintf(" | <span><strong>%s:</strong> {$post\_statuses\_array\[$item\["post\_status"\]\]}</span>", \_\_("Post status", "permalink-manager"));
116
$output .= apply\_filters('permalink\_manager\_uri\_editor\_extra\_info', '', $column\_name, get\_post($item\['ID'\]));
125
$output .= sprintf( "<span><strong>%s:</strong> %s</span>", \_\_( "Slug", "permalink-manager" ), urldecode( $item\['post\_name'\] ) );
126
$output .= sprintf( " | <span><strong>%s:</strong> {$post\_statuses\_array\[$item\["post\_status"\]\]}</span>", \_\_( "Post status", "permalink-manager" ) );
127
$output .= apply\_filters( 'permalink\_manager\_uri\_editor\_extra\_info', '', $column\_name, get\_post( $item\['ID'\] ) );
117
128
$output .= '</div>';
118
129
119
130
$output .= '<div class="row-actions">';
120
$output .= sprintf("<span class=\\"edit\\"><a href=\\"%s/wp-admin/post.php?post={$item\['ID'\]}&action=edit\\" title=\\"%s\\">%s</a> | </span>", get\_option('home'), \_\_('Edit', 'permalink-manager'), \_\_('Edit', 'permalink-manager'));
121
$output .= '<span class="view"><a target="\_blank" href="' . $permalink . '" title="' . \_\_('View', 'permalink-manager') . ' ' . $item\[ 'post\_title' \] . '" rel="permalink">' . \_\_('View', 'permalink-manager') . '</a> | </span>';
122
$output .= '<span class="id">#' . $item\[ 'ID' \] . '</span>';
131
$output .= sprintf( "<span class=\\"edit\\"><a href=\\"%s/wp-admin/post.php?post={$item\['ID'\]}&action=edit\\" title=\\"%s\\">%s</a> | </span>", get\_option( 'home' ), \_\_( 'Edit', 'permalink-manager' ), \_\_( 'Edit', 'permalink-manager' ) );
132
$output .= '<span class="view"><a target="\_blank" href="' . $permalink . '" title="' . \_\_( 'View', 'permalink-manager' ) . ' ' . $post\_title . '" rel="permalink">' . \_\_( 'View', 'permalink-manager' ) . '</a> | </span>';
133
$output .= '<span class="id">#' . $item\['ID'\] . '</span>';
123
134
$output .= '</div>';
135
124
136
return $output;
125
137
126
138
default:
127
return $item\[$column\_name\];
128
}
129
}
130
131
/\*\*
132
\* Sort the data
133
\*/
134
private function sort\_data($a, $b) {
135
// Set defaults
136
$orderby = (!empty($\_GET\['orderby'\])) ? sanitize\_sql\_orderby($\_GET\['orderby'\]) : 'post\_title';
137
$order = (!empty($\_GET\['order'\])) ? sanitize\_sql\_orderby($\_GET\['order'\]) : 'asc';
138
$result = strnatcasecmp( $a\[$orderby\], $b\[$orderby\] );
139
140
return ($order === 'asc') ? $result : -$result;
141
}
142
143
/\*\*
144
\* The button that allows to save updated slugs
145
\*/
146
function extra\_tablenav($which) {
139
return $item\[ $column\_name \];
140
}
141
}
142
143
/\*\*
144
\* The button that allows to save updated slugs
145
\*/
146
function extra\_tablenav( $which ) {
147
147
global $wpdb, $active\_section, $active\_subsection;
148
148
149
$button\_top \= \_\_( 'Save all the URIs below', 'permalink-manager' );
149
$button\_top \= \_\_( 'Save all the URIs below', 'permalink-manager' );
150
150
$button\_bottom = \_\_( 'Save all the URIs above', 'permalink-manager' );
151
151
…
…
153
153
$html .= get\_submit\_button( ${"button\_$which"}, 'primary alignleft', "update\_all\_slugs\[{$which}\]", false, array( 'id' => 'doaction', 'value' => 'update\_all\_slugs' ) );
154
154
155
if ($which == "top") {
156
// Searchbox
155
if ( $which == "top" ) {
157
156
$html .= '<div class="alignright">';
158
$html .= $this->search\_box(\_\_('Search', 'permalink-manager'), 'search-input');
157
$html .= $this->search\_box( \_\_( 'Search', 'permalink-manager' ), 'search-input' );
159
158
$html .= '</div>';
160
159
161
160
// Filter by date
162
$months = $wpdb->get\_results("SELECT DISTINCT month(post\_date) AS m, year(post\_date) AS y FROM {$wpdb->posts} WHERE post\_status IN ($this->displayed\_post\_statuses) AND post\_type IN ($this->displayed\_post\_types) ORDER BY post\_date DESC", ARRAY\_A);
163
if($months) {
164
$month\_key \= 'month';
165
$screen \= get\_current\_screen();
166
$current\_url = add\_query\_arg(array(
167
'page' => PERMALINK\_MANAGER\_PLUGIN\_SLUG,
168
'section' => $active\_section,
169
'subsection' => $active\_subsection
170
), admin\_url($screen->parent\_file));
161
$months = $wpdb->get\_results( "SELECT DISTINCT month(post\_date) AS m, year(post\_date) AS y FROM {$wpdb->posts} WHERE post\_status IN ($this->displayed\_post\_statuses) AND post\_type IN ($this->displayed\_post\_types) ORDER BY post\_date DESC", ARRAY\_A );
162
if ( $months ) {
163
$month\_key \= 'month';
164
$screen \= get\_current\_screen();
165
$current\_url = add\_query\_arg( array(
166
'page' \=> PERMALINK\_MANAGER\_PLUGIN\_SLUG,
167
'section' => $active\_section,
168
'subsection' => $active\_subsection
169
), admin\_url( $screen->parent\_file ) );
171
170
172
171
$html .= "<div id=\\"months-filter\\" class=\\"alignright hide-if-no-js\\" data-filter-url=\\"{$current\_url}\\">";
173
172
$html .= "<select id=\\"months-filter-select\\" name=\\"{$month\_key}\\">";
174
$html .= sprintf("<option value=\\"\\">%s</option>", \_\_("All dates", "permalink-manager"));
175
foreach($months as $month) {
176
$month\_raw \= "{$month\['y'\]}-{$month\['m'\]}";
177
$month\_human\_name = date\_i18n("F Y", strtotime($month\_raw));
178
179
$selected = (!empty($\_REQUEST\[$month\_key\])) ? selected($\_REQUEST\[$month\_key\], $month\_raw, false) : "";
180
$html .= "<option value=\\"{$month\_raw}\\" {$selected}>{$month\_human\_name}</option>";
173
$html .= sprintf( "<option value=\\"\\">%s</option>", \_\_( "All dates", "permalink-manager" ) );
174
foreach ( $months as $month ) {
175
$month\_raw \= "{$month\['y'\]}-{$month\['m'\]}";
176
$month\_human\_name = date\_i18n( "F Y", strtotime( $month\_raw ) );
177
178
$selected = ( ! empty( $\_REQUEST\[ $month\_key \] ) ) ? selected( $\_REQUEST\[ $month\_key \], $month\_raw, false ) : "";
179
$html .= "<option value=\\"{$month\_raw}\\" {$selected}>{$month\_human\_name}</option>";
181
180
}
182
181
$html .= "</select>";
183
$html .= get\_submit\_button(\_\_("Filter", "permalink-manager"), 'button', false, false, array('id' => 'months-filter-button', 'name' => 'months-filter-button'));
182
$html .= get\_submit\_button( \_\_( "Filter", "permalink-manager" ), 'button', false, false, array( 'id' => 'months-filter-button', 'name' => 'months-filter-button' ) );
184
183
$html .= "</div>";
185
184
}
186
}
185
}
187
186
$html .= "</div>";
188
187
…
…
191
190
192
191
/\*\*
193
\* Search box
194
\*/
195
public function search\_box($text = '', $input\_id = '') {
196
$search\_query = (!empty($\_REQUEST\['s'\])) ? esc\_attr($\_REQUEST\['s'\]) : "";
197
198
$output = "<p class=\\"search-box\\">";
192
\* Display the search input field
193
\*
194
\* @return string
195
\*/
196
public function search\_box( $text = '', $input\_id = '' ) {
197
$search\_query = ( ! empty( $\_REQUEST\['s'\] ) ) ? esc\_attr( $\_REQUEST\['s'\] ) : "";
198
199
$output = "<p class=\\"search-box\\">";
199
200
$output .= "<label class=\\"screen-reader-text\\" for=\\"{$input\_id}\\">{$text}:</label>";
200
$output .= Permalink\_Manager\_Admin\_Functions::generate\_option\_field('s', array('value' => $search\_query, 'type' => 'search'));
201
$output .= get\_submit\_button($text, 'button', false, false, array('id' => 'search-submit', 'name' => 'search-submit'));
202
$output .= "</p>";
201
$output .= Permalink\_Manager\_Admin\_Functions::generate\_option\_field( 's', array( 'value' => $search\_query, 'type' => 'search' ) );
202
$output .= get\_submit\_button( $text, 'button', false, false, array( 'id' => 'search-submit', 'name' => 'search-submit' ) );
203
$output .= "</p>";
203
204
204
205
return $output;
…
…
206
207
207
208
/\*\*
208
\* Prepare the items for the table to process
209
\*/
209
\* Prepare the items for the table to process
210
\*/
210
211
public function prepare\_items() {
211
212
global $wpdb, $permalink\_manager\_options;
212
213
213
$columns \= $this->get\_columns();
214
$hidden \= $this->get\_hidden\_columns();
215
$sortable \= $this->get\_sortable\_columns();
214
$columns \= $this->get\_columns();
215
$hidden \= $this->get\_hidden\_columns();
216
$sortable \= $this->get\_sortable\_columns();
216
217
$current\_page = $this->get\_pagenum();
217
218
…
…
220
221
221
222
// SQL query parameters
222
$order \= (isset($\_REQUEST\['order'\]) && in\_array($\_REQUEST\['order'\], array('asc', 'desc'))) ? sanitize\_sql\_orderby($\_REQUEST\['order'\]) : 'desc';
223
$orderby \= (isset($\_REQUEST\['orderby'\])) ? sanitize\_sql\_orderby($\_REQUEST\['orderby'\]) : 'ID';
224
$offset \= ($current\_page - 1) \* $per\_page;
225
$search\_query = (!empty($\_REQUEST\['s'\])) ? esc\_sql($\_REQUEST\['s'\]) : "";
223
$order = ( isset( $\_REQUEST\['order'\] ) && in\_array( $\_REQUEST\['order'\], array( 'asc', 'desc' ) ) ) ? sanitize\_sql\_orderby( $\_REQUEST\['order'\] ) : 'desc';
224
$orderby = ( isset( $\_REQUEST\['orderby'\] ) ) ? sanitize\_sql\_orderby( $\_REQUEST\['orderby'\] ) : 'ID';
225
$offset = ( $current\_page - 1 ) \* $per\_page;
226
$search\_query = ( ! empty( $\_REQUEST\['s'\] ) ) ? esc\_sql( $\_REQUEST\['s'\] ) : "";
226
227
227
228
// Extra filters
228
229
$extra\_filters = $attachment\_support = '';
229
if(!empty($\_GET\['month'\])) {
230
$month = date("n", strtotime($\_GET\['month'\]));
231
$year \= date("Y", strtotime($\_GET\['month'\]));
230
if ( ! empty( $\_GET\['month'\] ) ) {
231
$month = date( "n", strtotime( $\_GET\['month'\] ) );
232
$year = date( "Y", strtotime( $\_GET\['month'\] ) );
232
233
233
234
$extra\_filters .= "AND month(post\_date) = {$month} AND year(post\_date) = {$year}";
…
…
235
236
236
237
// Support for attachments
237
if(strpos($this->displayed\_post\_types, 'attachment') !== false) {
238
if ( strpos( $this->displayed\_post\_types, 'attachment' ) !== false ) {
238
239
$attachment\_support = " OR (post\_type = 'attachment')";
239
240
}
…
…
241
242
// Grab posts from database
242
243
$sql\_parts\['start'\] = "SELECT \* FROM {$wpdb->posts} ";
243
if($search\_query) {
244
if ( $search\_query ) {
244
245
$sql\_parts\['where'\] = "WHERE (LOWER(post\_title) LIKE LOWER('%{$search\_query}%') ";
245
246
246
247
// Search in array with custom URIs
247
$found = Permalink\_Manager\_Helper\_Functions::search\_uri($search\_query, 'posts');
248
if($found) {
249
$sql\_parts\['where'\] .= sprintf("OR ID IN (%s)", implode(',', (array) $found));
248
$found = Permalink\_Manager\_Helper\_Functions::search\_uri( $search\_query, 'posts' );
249
if ( $found ) {
250
$sql\_parts\['where'\] .= sprintf( "OR ID IN (%s)", implode( ',', $found ) );
250
251
}
251
252
$sql\_parts\['where'\] .= " ) AND ((post\_status IN ($this->displayed\_post\_statuses) AND post\_type IN ($this->displayed\_post\_types)) {$attachment\_support}) {$extra\_filters} ";
…
…
255
256
256
257
// Do not display excluded posts in Bulk URI Editor
257
$excluded\_posts = (array) apply\_filters('permalink\_manager\_excluded\_post\_ids', array());
258
if(!empty($excluded\_posts)) {
259
$sql\_parts\['where'\] .= sprintf("AND ID NOT IN ('%s') ", implode("', '", $excluded\_posts));
258
$excluded\_posts = (array) apply\_filters( 'permalink\_manager\_excluded\_post\_ids', array() );
259
if ( ! empty( $excluded\_posts ) ) {
260
$sql\_parts\['where'\] .= sprintf( "AND ID NOT IN ('%s') ", implode( "', '", $excluded\_posts ) );
260
261
}
261
262
…
…
263
264
264
265
// Prepare the SQL query
265
$sql\_query = implode("", $sql\_parts);
266
$sql\_query = implode( "", $sql\_parts );
266
267
267
268
// Count items
268
$count\_query = str\_replace('SELECT \*', 'SELECT COUNT(\*)', $sql\_query);
269
$total\_items = $wpdb->get\_var($count\_query);
269
$count\_query = str\_replace( 'SELECT \*', 'SELECT COUNT(\*)', $sql\_query );
270
$total\_items = $wpdb->get\_var( $count\_query );
270
271
271
272
// Pagination support
272
$sql\_query .= sprintf(" LIMIT %d, %d", $offset, $per\_page);
273
$sql\_query .= sprintf( " LIMIT %d, %d", $offset, $per\_page );
273
274
274
275
// Get items
275
$sql\_query = apply\_filters('permalink\_manager\_filter\_uri\_editor\_query', $sql\_query, $this, $sql\_parts, $is\_taxonomy = false);
276
$all\_items = $wpdb->get\_results($sql\_query, ARRAY\_A);
276
$sql\_query = apply\_filters( 'permalink\_manager\_filter\_uri\_editor\_query', $sql\_query, $this, $sql\_parts, $is\_taxonomy = false );
277
$all\_items = $wpdb->get\_results( $sql\_query, ARRAY\_A );
277
278
278
279
// Debug SQL query
279
if(isset($\_REQUEST\['debug\_editor\_sql'\])) {
280
if ( isset( $\_REQUEST\['debug\_editor\_sql'\] ) ) {
280
281
$debug\_txt = "<textarea style=\\"width:100%;height:300px\\">{$sql\_query} \\n\\nOffset: {$offset} \\nPage: {$current\_page}\\nPer page: {$per\_page} \\nTotal: {$total\_items}</textarea>";
281
wp\_die($debug\_txt);
282
wp\_die( $debug\_txt );
282
283
}
283
284
…
…
285
286
'total\_items' => $total\_items,
286
287
'per\_page' => $per\_page
287
));
288
289
$this->\_column\_headers = array($columns, $hidden, $sortable);
290
$this->items = $all\_items;
288
) );
289
290
$this->\_column\_headers = array( $columns, $hidden, $sortable );
291
$this->items = $all\_items;
292
}
293
294
/\*\*
295
\* Define hidden columns
296
\*
297
\* @return array
298
\*/
299
public function get\_hidden\_columns() {
300
return array();
301
}
302
303
/\*\*
304
\* Sort the data
305
\*
306
\* @param mixed $a
307
\* @param mixed $b
308
\*
309
\* @return int
310
\*/
311
private function sort\_data( $a, $b ) {
312
// Set defaults
313
$orderby = ( ! empty( $\_GET\['orderby'\] ) ) ? sanitize\_sql\_orderby( $\_GET\['orderby'\] ) : 'post\_title';
314
$order = ( ! empty( $\_GET\['order'\] ) ) ? sanitize\_sql\_orderby( $\_GET\['order'\] ) : 'asc';
315
$result = strnatcasecmp( $a\[ $orderby \], $b\[ $orderby \] );
316
317
return ( $order === 'asc' ) ? $result : - $result;
291
318
}
292
319
permalink-manager/trunk/includes/views/permalink-manager-uri-editor.php
r2053970
r2833667
2
2
3
3
/\*\*
4
\* Display slug editor for Posts, Pages & Custom Post Types
5
\*/
6
class Permalink\_Manager\_Uri\_Editor extends Permalink\_Manager\_Class {
4
\* Display Bulk URI Editor
5
\*/
6
class Permalink\_Manager\_Uri\_Editor {
7
7
public $this\_section = 'uri\_editor';
8
8
9
9
public function \_\_construct() {
10
add\_filter( 'permalink\_manager\_sections', array($this, 'add\_admin\_section'), 0 );
11
add\_filter( 'screen\_settings', array($this, 'screen\_options'), 99, 2 );
12
}
13
14
public function init() {
15
global $permalink\_manager\_admin\_page;
16
17
// Show "screen options"
18
add\_action("load-{$permalink\_manager\_admin\_page}", array($this, "screen\_options"));
10
add\_filter( 'permalink\_manager\_sections', array( $this, 'add\_admin\_section' ), 0 );
11
add\_filter( 'screen\_settings', array( $this, 'screen\_options' ), 99, 2 );
19
12
}
20
13
21
14
/\*\*
22
\* Add the section to the Permalink Manager admin page
23
\*/
24
public function add\_admin\_section($admin\_sections) {
25
global $permalink\_manager\_options;
26
27
$admin\_sections\[$this->this\_section\] = array(
28
'name' => \_\_('URI editor', 'permalink-manager')
15
\* Add a new section to the Permalink Manager UI
16
\*
17
\* @param array $admin\_sections
18
\*
19
\* @return array
20
\*/
21
public function add\_admin\_section( $admin\_sections ) {
22
$admin\_sections\[ $this->this\_section \] = array(
23
'name' => \_\_( 'URI Editor', 'permalink-manager' )
29
24
);
30
25
31
26
// Display separate section for each post type
32
$post\_types = Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array('full');
33
foreach($post\_types as $post\_type\_name => $post\_type) {
27
$post\_types = Permalink\_Manager\_Helper\_Functions::get\_post\_types\_array( 'full' );
28
foreach ( $post\_types as $post\_type\_name => $post\_type ) {
34
29
// Check if post type exists
35
if(!post\_type\_exists($post\_type\_name)) { continue; }
30
if ( ! post\_type\_exists( $post\_type\_name ) ) {
31
continue;
32
}
36
33
37
$icon = (class\_exists('WooCommerce') && in\_array($post\_type\_name, array('product'))) ? "<i class=\\"woocommerce-icon woocommerce-cart\\"></i>" : "";
34
$icon = ( class\_exists( 'WooCommerce' ) && $post\_type\_name == 'product' ) ? "<i class=\\"woocommerce-icon woocommerce-cart\\"></i>" : "";
38
35
39
$admin\_sections\[$this->this\_section\]\['subsections'\]\[$post\_type\_name\] = array(
40
'name' \=> "{$icon} {$post\_type\['label'\]}",
41
'function' => array('class' => 'Permalink\_Manager\_URI\_Editor\_Post', 'method' => 'display\_admin\_section')
36
$admin\_sections\[ $this->this\_section \]\['subsections'\]\[ $post\_type\_name \] = array(
37
'name' \=> "{$icon} {$post\_type\['label'\]}",
38
'function' \=> array( 'class' => 'Permalink\_Manager\_URI\_Editor\_Post', 'method' => 'display\_admin\_section' )
42
39
);
43
40
}
44
41
45
42
// Permalink Manager Pro: Display separate section for each taxonomy
46
$taxonomies = Permalink\_Manager\_Helper\_Functions::get\_taxonomies\_array('full');
47
foreach($taxonomies as $taxonomy\_name => $taxonomy) {
43
$taxonomies = Permalink\_Manager\_Helper\_Functions::get\_taxonomies\_array( 'full' );
44
foreach ( $taxonomies as $taxonomy\_name => $taxonomy ) {
48
45
// Check if taxonomy exists
49
if(!taxonomy\_exists($taxonomy\_name)) { continue; }
46
if ( ! taxonomy\_exists( $taxonomy\_name ) ) {
47
continue;
48
}
50
49
51
50
// Get the icon
52
$icon = (class\_exists('WooCommerce') && in\_array($taxonomy\_name, array('product\_tag', 'product\_cat'))) ? "<i class=\\"woocommerce-icon woocommerce-cart\\"></i>" : "<i class=\\"dashicons dashicons-tag\\"></i>";
51
$icon = ( class\_exists( 'WooCommerce' ) && in\_array( $taxonomy\_name, array( 'product\_tag', 'product\_cat' ) ) ) ? "<i class=\\"woocommerce-icon woocommerce-cart\\"></i>" : "<i class=\\"dashicons dashicons-tag\\"></i>";
53
52
54
$admin\_sections\[$this->this\_section\]\['subsections'\]\["tax\_{$taxonomy\_name}"\] = array(
53
$admin\_sections\[ $this->this\_section \]\['subsections'\]\["tax\_{$taxonomy\_name}"\] = array(
55
54
'name' => "{$icon} {$taxonomy\['label'\]}",
56
55
'html' => Permalink\_Manager\_Admin\_Functions::pro\_text(),
57
'pro' \=> true
56
'pro' \=> true
58
57
);
59
58
}
60
59
61
60
// A little dirty hack to move wooCommerce product & taxonomies to the end of array
62
if(class\_exists('WooCommerce')) {
63
foreach(array('product', 'tax\_product\_tag', 'tax\_product\_cat') as $section\_name) {
64
if(empty($admin\_sections\[$this->this\_section\]\['subsections'\]\[$section\_name\])) { continue; }
65
$section = $admin\_sections\[$this->this\_section\]\['subsections'\]\[$section\_name\];
66
unset($admin\_sections\[$this->this\_section\]\['subsections'\]\[$section\_name\]);
67
$admin\_sections\[$this->this\_section\]\['subsections'\]\[$section\_name\] = $section;
61
if ( class\_exists( 'WooCommerce' ) ) {
62
foreach ( array( 'product', 'tax\_product\_tag', 'tax\_product\_cat' ) as $section\_name ) {
63
if ( empty( $admin\_sections\[ $this->this\_section \]\['subsections'\]\[ $section\_name \] ) ) {
64
continue;
65
}
66
$section = $admin\_sections\[ $this->this\_section \]\['subsections'\]\[ $section\_name \];
67
unset( $admin\_sections\[ $this->this\_section \]\['subsections'\]\[ $section\_name \] );
68
$admin\_sections\[ $this->this\_section \]\['subsections'\]\[ $section\_name \] = $section;
68
69
}
69
70
}
…
…
73
74
74
75
/\*\*
75
\* Add scren options
76
\* Display "Screen options"
77
\*
78
\* @param string $html
79
\* @param string $screen
80
\*
81
\* @return string
76
82
\*/
77
public function screen\_options($html, $screen) {
83
public function screen\_options( $html, $screen ) {
78
84
global $active\_section;
79
85
80
86
// Display the screen options only in "Permalink Editor"
81
if($active\_section != $this->this\_section) { return $html; }
87
if ( $active\_section != $this->this\_section ) {
88
return $html;
89
}
82
90
83
91
$button = get\_submit\_button( \_\_( 'Apply', 'permalink-manager' ), 'primary', 'screen-options-apply', false );
84
$html \= "<fieldset class=\\"permalink-manager-screen-options\\">";
92
$html \= "<fieldset class=\\"permalink-manager-screen-options\\">";
85
93
86
94
$screen\_options = array(
87
'per\_page' => array(
88
'type' => 'number',
89
'label' => \_\_('Per page', 'permalink-manager'),
90
'input\_class' => 'settings-select'
91
),
92
'post\_statuses' => array(
93
'type' => 'checkbox',
94
'label' => \_\_('Post statuses', 'permalink-manager'),
95
'choices' => get\_post\_statuses(),
96
'select\_all' => '',
97
'unselect\_all' => '',
98
),
99
/\*'group' => array(
100
'type' => 'single\_checkbox',
101
'label' => \_\_('Group children pages', 'permalink-manager'),
102
),\*/
95
'per\_page' => array(
96
'type' => 'number',
97
'label' => \_\_( 'Per page', 'permalink-manager' ),
98
'input\_class' => 'settings-select'
99
),
100
'post\_statuses' => array(
101
'type' => 'checkbox',
102
'label' => \_\_( 'Post statuses', 'permalink-manager' ),
103
'choices' => get\_post\_statuses(),
104
'select\_all' => '',
105
'unselect\_all' => '',
106
)
103
107
);
104
108
105
foreach($screen\_options as $field\_name => $field\_args) {
109
foreach ( $screen\_options as $field\_name => $field\_args ) {
106
110
$field\_args\['container'\] = 'screen-options';
107
$html .= Permalink\_Manager\_Admin\_Functions::generate\_option\_field("screen-options\[{$field\_name}\]", $field\_args);
111
$html .= Permalink\_Manager\_Admin\_Functions::generate\_option\_field( "screen-options\[{$field\_name}\]", $field\_args );
108
112
}
109
113
110
$html .= "</fieldset>{$button}";
114
$html .= sprintf( "</fieldset>%s", $button );
111
115
112
116
return $html;
permalink-manager/trunk/languages/permalink-manager-ja.po
r2796526
r2833667
4
4
"Report-Msgid-Bugs-To: \\n"
5
5
"POT-Creation-Date: 2020-11-23 20:44+0000\\n"
6
"PO-Revision-Date: 2022-10-06 19:14+0000\\n"
6
"PO-Revision-Date: 2022-12-13 23:31+0000\\n"
7
7
"Last-Translator: admin\\n"
8
8
"Language-Team: Japanese\\n"
…
…
15
15
"X-Loco-Version: 2.4.4; wp-5.5.3"
16
16
17
#: includes/views/permalink-manager-pro-addons.php:266
17
#: includes/views/permalink-manager-pro-addons.php:284
18
18
msgid ""
19
19
" Please send your remarks to <a href=\\"mailto:[email protected]\\">"
…
…
23
23
"pro</a>まで、ご意見をお送り下さい。"
24
24
25
#: includes/core/permalink-manager-third-parties.php:353
25
#: includes/core/permalink-manager-third-parties.php:367
26
26
msgid "\\"Custom Permalinks\\" URIs were imported!"
27
27
msgstr "「カスタム パーマリンク」URIは、インポートされました!"
28
28
29
#: includes/views/permalink-manager-settings.php:233
29
#: includes/views/permalink-manager-settings.php:204
30
30
msgid "\\"Exclude content types\\" strict mode"
31
31
msgstr ""
32
32
33
#: includes/views/permalink-manager-settings.php:216
33
#: includes/views/permalink-manager-settings.php:187
34
34
msgid "\\"Primary category\\" support"
35
35
msgstr ""
36
36
37
#: includes/views/permalink-manager-pro-addons.php:189
37
#: includes/views/permalink-manager-pro-addons.php:202
38
38
msgid "\\"Stop words\\" list"
39
39
msgstr "「使用禁止の単語」リスト"
40
40
41
#: includes/core/permalink-manager-actions.php:399
41
#: includes/core/permalink-manager-actions.php:147
42
42
#, php-format
43
43
msgid "%d Custom URIs and %d Custom Redirects were removed!"
44
44
msgstr "%d カスタムURIと、%d カスタム リダイレクトは削除されました。"
45
45
46
#: includes/core/permalink-manager-actions.php:453
46
#: includes/core/permalink-manager-actions.php:533
47
47
#, php-format
48
48
msgid "%s were removed!"
49
49
msgstr "%s は削除されました!"
50
50
51
#: includes/views/permalink-manager-tools.php:97
51
#: includes/views/permalink-manager-tools.php:117
52
52
msgid "(Removed post)"
53
53
msgstr "(削除された投稿)"
54
54
55
#: includes/views/permalink-manager-tools.php:84
55
#: includes/views/permalink-manager-tools.php:105
56
56
msgid "(Removed term)"
57
57
msgstr "(削除されたターム)"
58
58
59
#: includes/views/permalink-manager-pro-addons.php:170
59
#: includes/views/permalink-manager-pro-addons.php:183
60
60
msgid "-- Use predefined words list --"
61
61
msgstr "-- 定義済みの単語リストを使用する --"
62
62
63
#: includes/views/permalink-manager-settings.php:167
63
#: includes/views/permalink-manager-settings.php:141
64
64
msgid "301 redirect"
65
65
msgstr "301 リダイレクト"
66
66
67
#: includes/views/permalink-manager-settings.php:167
67
#: includes/views/permalink-manager-settings.php:141
68
68
msgid "302 redirect"
69
69
msgstr "302 リダイレクト"
70
70
71
#: includes/core/permalink-manager-admin-functions.php:749
71
#: includes/core/permalink-manager-admin-functions.php:776
72
72
#, php-format
73
73
msgid "<a %s>Click here</a> to go to the list of updated slugs"
74
74
msgstr "更新されたスラッグのリストは、<a %s>ここをクリック</a> "
75
75
76
#: includes/core/permalink-manager-admin-functions.php:748
76
#: includes/core/permalink-manager-admin-functions.php:775
77
77
#, php-format
78
78
msgid "<strong class=\\"updated\_count\\">%d</strong> slug was updated!"
…
…
80
80
msgstr\[0\] "<strong class=\\"updated\_count\\">%d</strong> スラッグは、更新されました!"
81
81
82
#: includes/views/permalink-manager-tools.php:44
82
#: includes/views/permalink-manager-tools.php:55
83
83
msgid ""
84
84
"<strong>A MySQL backup is highly recommended before using \\"<em>Native "
…
…
87
87
"<strong>「<em>ネイティブ スラッグ</em>」モード使用される前に、MY SQLのバックアップを強く推奨します!</strong>"
88
88
89
#: includes/views/permalink-manager-settings.php:93
89
#: includes/views/permalink-manager-settings.php:88
90
90
msgid ""
91
91
"<strong>Canonical redirect allows WordPress to \\"correct\\" the requested URL "
…
…
95
95
"正規リダイレクトにより、WordPressは要求されたURLを「修正」し、訪問者を正規パーマリンクにリダイレクトできます。</strong>"
96
96
97
#: includes/core/permalink-manager-actions.php:147
97
#: includes/core/permalink-manager-actions.php:577
98
98
msgid "<strong>No post status</strong> selected!"
99
99
msgstr ""
100
100
101
#: includes/core/permalink-manager-actions.php:141
101
#: includes/core/permalink-manager-actions.php:571
102
102
msgid "<strong>No post type</strong> selected!"
103
103
msgstr ""
104
104
105
#: includes/core/permalink-manager-actions.php:116
106
#: includes/core/permalink-manager-admin-functions.php:753
105
#: includes/core/permalink-manager-actions.php:545
106
#: includes/core/permalink-manager-admin-functions.php:780
107
107
msgid "<strong>No slugs</strong> were updated!"
108
108
msgstr "スラッグは、更新されませんでした。"
109
109
110
#: includes/core/permalink-manager-actions.php:133
110
#: includes/core/permalink-manager-actions.php:563
111
111
msgid "<strong>No taxonomy</strong> selected!"
112
112
msgstr ""
113
113
114
#: includes/views/permalink-manager-settings.php:110
114
#: includes/views/permalink-manager-settings.php:101
115
115
msgid ""
116
116
"<strong>Old slug redirect is used by WordPress to provide a fallback for old "
…
…
120
120
"リダイレクトは、WordPressが古いバージョンのスラッグを変更した後の代替を提供するために使用されます。</strong>"
121
121
122
#: includes/views/permalink-manager-settings.php:43
122
#: includes/views/permalink-manager-settings.php:50
123
123
msgid ""
124
124
"<strong>Permalink Manager can automatically update the custom permalink "
…
…
128
128
"パーマリンクを自動的に更新できます。</strong>"
129
129
130
#: includes/views/permalink-manager-settings.php:54
130
#: includes/views/permalink-manager-settings.php:57
131
131
msgid ""
132
132
"<strong>Permalink Manager can use either native slugs or actual titles for "
…
…
135
135
"<strong>Permalink Managerでは、カスタム パーマリンクにネイティブ スラッグまたは実際のタイトルを使用できます。</strong>"
136
136
137
#: includes/views/permalink-manager-pro-addons.php:333
137
#: includes/views/permalink-manager-pro-addons.php:339
138
138
msgid ""
139
139
"<strong>Please use full URLs!</strong><br />For instance, <code>http:"
…
…
143
143
"com/final-target-url</code>."
144
144
145
#: includes/views/permalink-manager-pro-addons.php:315
145
#: includes/views/permalink-manager-pro-addons.php:324
146
146
#, php-format
147
147
msgid ""
…
…
152
152
"のリダイレクトを設定する場合は、<code>old-uri</code> をお使い下さい。"
153
153
154
#: includes/views/permalink-manager-settings.php:159
154
#: includes/views/permalink-manager-settings.php:135
155
155
msgid ""
156
156
"<strong>You can use Permalink Manager to force SSL or \\"www\\" prefix in "
…
…
160
160
"Managerを使って、WordPressのパーマリンク内にSSLもしくはwwwの接頭辞を強制的に付与できます。</strong>"
161
161
162
#: includes/views/permalink-manager-settings.php:66
163
msgid ""
164
"<strong>You can use this feature to either add or remove the slases from end "
165
"of WordPress permalinks.</strong>"
166
msgstr "<strong>この機能で、WordPressパーマリンクの末尾にスラッシュを追加または削除できます。</strong>"
167
168
#: includes/views/permalink-manager-pro-addons.php:310
162
#: includes/views/permalink-manager-pro-addons.php:320
169
163
msgid "Add new redirect"
170
164
msgstr "新しいリダイレクトを追加する"
171
165
172
#: includes/views/permalink-manager-pro-addons.php:175
166
#: includes/views/permalink-manager-pro-addons.php:188
173
167
msgid "Add the words from the list"
174
168
msgstr "リストから単語を追加する"
…
…
178
172
msgstr "末尾のスラッシュを追加する"
179
173
180
#: includes/views/permalink-manager-settings.php:258
174
#: includes/views/permalink-manager-settings.php:229
181
175
msgid "Administrator (edit\_theme\_options)"
182
176
msgstr "管理者 (edit\_theme\_options)"
183
177
184
178
#. Description of the plugin
185
msgid ""
186
"Advanced plugin that allows to set-up custom permalinks (bulk editors "
179
#, fuzzy
180
#| msgid ""
181
#| "Advanced plugin that allows to set-up custom permalinks (bulk editors "
182
#| "included), slugs and permastructures (WooCommerce compatible)."
183
msgid ""
184
"Advanced plugin that allows to set up custom permalinks (bulk editors "
187
185
"included), slugs and permastructures (WooCommerce compatible)."
188
186
msgstr "有償版では、スラッグやパーマ構造(WooCommerceとの互換性あり)、カスタム パーマリンク(一括編集も含む)の設定が可能です。"
189
187
190
#: includes/views/permalink-manager-settings.php:223
188
#: includes/views/permalink-manager-settings.php:194
191
189
msgid "Advanced settings"
192
190
msgstr "詳細設定"
193
191
194
#: includes/views/permalink-manager-permastructs.php:83
192
#: includes/views/permalink-manager-permastructs.php:92
195
193
#, php-format
196
194
msgid ""
…
…
202
200
"です。いくつかのタグは、特定の投稿タイプやタクソノミーでのみ使用可能ですので、ご注意下さい。"
203
201
204
#: includes/views/permalink-manager-uri-editor-post.php:174
202
#: includes/views/permalink-manager-uri-editor-post.php:173
205
203
msgid "All dates"
206
204
msgstr "全日付"
207
205
208
#: includes/views/permalink-manager-pro-addons.php:287
206
#: includes/views/permalink-manager-pro-addons.php:305
209
207
msgid ""
210
208
"All URIs specified below will redirect the visitors to the custom URI "
…
…
212
210
msgstr "以下で指定された全てのURIは、訪問者を上記の「現在のURI」フィールドで定義されたカスタムURIにリダイレクトします。"
213
211
214
#: includes/views/permalink-manager-uri-editor.php:83
212
#: includes/views/permalink-manager-uri-editor.php:91
215
213
msgid "Apply"
216
214
msgstr "適用"
217
215
218
#: includes/core/permalink-manager-pro-functions.php:247
216
#: includes/core/permalink-manager-pro-functions.php:257
219
217
msgid "Arabic"
220
218
msgstr "アラビア語"
221
219
222
#: includes/core/permalink-manager-admin-functions.php:134
220
#: includes/core/permalink-manager-admin-functions.php:136
223
221
msgid "Are you sure? This action cannot be undone!"
224
222
msgstr "本当によろしいですか?この操作は、元に戻せません!"
225
223
226
#: includes/views/permalink-manager-debug.php:69
224
#: includes/views/permalink-manager-debug.php:72
227
225
msgid "Array with external redirects"
228
226
msgstr "外部リダイレクトでの配列"
229
227
230
#: includes/views/permalink-manager-debug.php:80
228
#: includes/views/permalink-manager-debug.php:79
231
229
msgid "Array with permastructures"
232
230
msgstr "パーマ構造での配列"
233
231
234
#: includes/views/permalink-manager-debug.php:58
232
#: includes/views/permalink-manager-debug.php:65
235
233
msgid "Array with redirects"
236
234
msgstr "リダイレクトでの配列"
237
235
238
#: includes/views/permalink-manager-debug.php:91
236
#: includes/views/permalink-manager-debug.php:86
239
237
msgid "Array with settings used in this plugin."
240
238
msgstr "本プラグイン内で使用中の設定での配列"
241
239
242
#: includes/views/permalink-manager-debug.php:47
240
#: includes/views/permalink-manager-debug.php:58
243
241
msgid "Array with URIs"
244
242
msgstr "URIでの配列"
245
243
246
#: includes/views/permalink-manager-settings.php:258
244
#: includes/views/permalink-manager-settings.php:229
247
245
msgid "Author (publish\_posts)"
248
246
msgstr "投稿者 (publish\_posts)"
249
247
250
#: includes/core/permalink-manager-admin-functions.php:859
251
#: includes/core/permalink-manager-admin-functions.php:871
248
#: includes/core/permalink-manager-admin-functions.php:893
249
#: includes/core/permalink-manager-admin-functions.php:905
252
250
msgid "Auto-update \\"Current URI\\""
253
251
msgstr ""
254
252
255
#: includes/views/permalink-manager-settings.php:41
253
#: includes/views/permalink-manager-settings.php:49
256
254
msgid "Auto-update permalinks"
257
255
msgstr "パーマリンクの自動更新"
258
256
259
#: includes/core/permalink-manager-admin-functions.php:947
257
#: includes/core/permalink-manager-admin-functions.php:964
260
258
msgid "Automatic redirect for native URI enabled:"
261
259
msgstr "ネイティブURIの自動リダイレクトを有効にする:"
262
260
263
#: includes/views/permalink-manager-settings.php:263
261
#: includes/views/permalink-manager-settings.php:234
264
262
msgid "Automatically fix broken URIs"
265
263
msgstr "壊れたURIを自動的に修正する"
266
264
267
#: includes/views/permalink-manager-settings.php:210
265
#: includes/views/permalink-manager-settings.php:181
268
266
msgid "Breadcrumbs support"
269
267
msgstr "パンくずリスト サポート"
270
268
271
#: includes/core/permalink-manager-actions.php:609
269
#: includes/core/permalink-manager-actions.php:347
272
270
msgid "Broken redirects were removed successfully!"
273
271
msgstr "リンク切れリダイレクトは、無事削除されました!"
274
272
275
#: includes/views/permalink-manager-settings.php:265
273
#: includes/views/permalink-manager-settings.php:236
276
274
msgid "Bulk fix all URIs (once a day, in the background)"
277
275
msgstr "全てのURIを一括修正する(1日1回、バックグラウンド)"
278
276
279
#: includes/core/permalink-manager-admin-functions.php:172
277
#: includes/core/permalink-manager-admin-functions.php:187
280
278
msgid "Buy Permalink Manager Pro"
281
279
msgstr "Permalink Manager Proを購入"
282
280
283
#: includes/core/permalink-manager-admin-functions.php:616
281
#: includes/core/permalink-manager-admin-functions.php:634
284
282
msgid "by Maciej Bis"
285
283
msgstr "by Maciej Bis"
286
284
287
#: includes/views/permalink-manager-settings.php:90
285
#: includes/views/permalink-manager-settings.php:86
288
286
msgid "Canonical redirect"
289
287
msgstr "正規リダイレクト"
290
288
291
#: includes/core/permalink-manager-pro-functions.php:248
289
#: includes/core/permalink-manager-pro-functions.php:258
292
290
msgid "Chinese"
293
291
msgstr "中国語"
294
292
295
#: includes/core/permalink-manager-uri-functions-tax.php:520
293
#: includes/core/permalink-manager-uri-functions-tax.php:561
296
294
msgid "Clear/leave the field empty to use the default permalink."
297
295
msgstr "デフォルトのパーマリンクを使用するため、フィールドを空のままにする / クリアする"
298
296
299
#: includes/core/permalink-manager-admin-functions.php:887
297
#: includes/core/permalink-manager-admin-functions.php:921
300
298
msgid "Close: "
301
299
msgstr "閉じる:"
302
300
303
#: includes/views/permalink-manager-tools.php:120
301
#: includes/views/permalink-manager-tools.php:132
304
302
msgid "Congratulations! No duplicated URIs or Redirects found!"
305
303
msgstr "おめでとうございます!重複したURI・リダイレクトは、見つかりませんでした!"
306
304
307
#: includes/views/permalink-manager-settings.php:258
305
#: includes/views/permalink-manager-settings.php:229
308
306
msgid "Contributor (edit\_posts)"
309
307
msgstr "寄稿者 (edit\_posts)"
310
308
311
#: includes/views/permalink-manager-settings.php:250
309
#: includes/views/permalink-manager-settings.php:221
312
310
msgid "Convert accented letters"
313
311
msgstr "アクセント付き文字の変換"
314
312
315
#: includes/views/permalink-manager-uri-editor-tax.php:53
313
#: includes/views/permalink-manager-uri-editor-tax.php:59
316
314
msgid "Count"
317
315
msgstr "カウント"
318
316
319
#: includes/core/permalink-manager-pro-functions.php:566
317
#: includes/core/permalink-manager-pro-functions.php:622
320
318
msgid "Coupon Full URL"
321
319
msgstr "クーポン フル URL"
322
320
323
#: includes/core/permalink-manager-pro-functions.php:533
321
#: includes/core/permalink-manager-pro-functions.php:586
324
322
msgid "Coupon Link"
325
323
msgstr "クーポンリンク"
326
324
327
#: includes/core/permalink-manager-pro-functions.php:554
325
#: includes/core/permalink-manager-pro-functions.php:610
328
326
msgid "Coupon URI"
329
327
msgstr "クーポンURI"
330
328
331
#: includes/core/permalink-manager-uri-functions-post.php:711
332
#: includes/core/permalink-manager-uri-functions-tax.php:552
333
#: includes/core/permalink-manager-admin-functions.php:795
334
#: includes/core/permalink-manager-admin-functions.php:906
329
#: includes/core/permalink-manager-uri-functions-post.php:777
330
#: includes/core/permalink-manager-uri-functions-tax.php:594
331
#: includes/core/permalink-manager-admin-functions.php:821
332
#: includes/core/permalink-manager-admin-functions.php:939
335
333
msgid "Current URI"
336
334
msgstr "現在のURI"
337
335
338
#: includes/views/permalink-manager-tools.php:34
339
#: includes/views/permalink-manager-pro-addons.php:225
336
#: includes/views/permalink-manager-tools.php:40
337
#: includes/views/permalink-manager-pro-addons.php:241
340
338
msgid "Custom Permalinks"
341
339
msgstr "カスタム パーマリンク"
342
340
343
#: includes/core/permalink-manager-actions.php:426
341
#: includes/core/permalink-manager-actions.php:504
344
342
msgid "Custom permalinks"
345
343
msgstr "カスタム パーマリンク"
346
344
347
#: includes/core/permalink-manager-actions.php:430
345
#: includes/core/permalink-manager-actions.php:508
348
346
msgid "Custom redirects"
349
347
msgstr "カスタム リダイレクト"
350
348
351
#: includes/views/permalink-manager-tools.php:70
352
#: includes/core/permalink-manager-third-parties.php:485
353
#: includes/core/permalink-manager-third-parties.php:852
354
#: includes/core/permalink-manager-uri-functions-tax.php:519
349
#: includes/views/permalink-manager-tools.php:91
350
#: includes/core/permalink-manager-third-parties.php:534
351
#: includes/core/permalink-manager-third-parties.php:963
352
#: includes/core/permalink-manager-uri-functions-tax.php:560
355
353
msgid "Custom URI"
356
354
msgstr "カスタム URI"
357
355
358
#: includes/views/permalink-manager-tools.php:150
356
#: includes/views/permalink-manager-tools.php:167
359
357
msgid "Custom URIs"
360
358
msgstr "カスタム URI"
361
359
362
#: includes/core/permalink-manager-pro-functions.php:249
360
#: includes/core/permalink-manager-pro-functions.php:259
363
361
msgid "Danish"
364
362
msgstr "デンマーク語"
365
363
366
#: includes/views/permalink-manager-pro-addons.php:226
364
#: includes/views/permalink-manager-pro-addons.php:242
367
365
msgid "Deactivate after import"
368
366
msgstr "インポート後、非アクティブにする"
369
367
370
#: includes/views/permalink-manager-debug.php:14
368
#: includes/views/permalink-manager-debug.php:21
371
369
msgid "Debug"
372
370
msgstr "デバッグ"
373
371
374
#: includes/views/permalink-manager-debug.php:38
372
#: includes/views/permalink-manager-debug.php:53
375
373
msgid "Debug data"
376
374
msgstr "デバッグデータ"
377
375
378
#: includes/core/permalink-manager-admin-functions.php:423
376
#: includes/core/permalink-manager-admin-functions.php:437
379
377
msgid "Default permastructure"
380
378
msgstr "デフォルト パーマ構造"
381
379
382
#: includes/core/permalink-manager-admin-functions.php:936
380
#: includes/core/permalink-manager-admin-functions.php:957
383
381
msgid "Default URI"
384
382
msgstr "デフォルト URI"
385
383
386
#: includes/views/permalink-manager-settings.php:167
384
#: includes/views/permalink-manager-settings.php:141
387
385
msgid "Disable (Permalink Manager redirect functions)"
388
386
msgstr "無効(Permalink Manager リダイレクト 機能)"
389
387
390
#: includes/core/permalink-manager-admin-functions.php:861
388
#: includes/core/permalink-manager-admin-functions.php:895
391
389
msgid "Disable URI Editor"
392
390
msgstr ""
393
391
394
#: includes/views/permalink-manager-settings.php:41
395
#: includes/core/permalink-manager-admin-functions.php:873
392
#: includes/views/permalink-manager-settings.php:49
393
#: includes/core/permalink-manager-admin-functions.php:907
396
394
msgid "Disable URI Editor to disallow permalink changes"
397
395
msgstr ""
398
396
399
#: includes/core/permalink-manager-admin-functions.php:431
397
#: includes/core/permalink-manager-admin-functions.php:440
400
398
msgid "Do not automatically append the slug"
401
399
msgstr "スラッグを自動的に追加しない"
402
400
403
#: includes/core/permalink-manager-admin-functions.php:168
401
#: includes/core/permalink-manager-admin-functions.php:183
404
402
msgid "Documentation"
405
403
msgstr "ドキュメント"
406
404
407
#: includes/core/permalink-manager-admin-functions.php:863
408
#: includes/core/permalink-manager-admin-functions.php:869
405
#: includes/core/permalink-manager-admin-functions.php:897
406
#: includes/core/permalink-manager-admin-functions.php:903
409
407
msgid "Don't auto-update \\"Current URI\\""
410
408
msgstr ""
411
409
412
#: includes/core/permalink-manager-admin-functions.php:870
410
#: includes/core/permalink-manager-admin-functions.php:904
413
411
msgid ""
414
412
"Don't auto-update \\"Current URI\\" and exclude from the \\"Regenerate/reset\\" "
…
…
416
414
msgstr ""
417
415
418
#: includes/views/permalink-manager-settings.php:41
416
#: includes/views/permalink-manager-settings.php:49
419
417
msgid "Don't auto-update permalinks (default mode)"
420
418
msgstr ""
421
419
422
#: includes/core/permalink-manager-pro-functions.php:250
420
#: includes/core/permalink-manager-pro-functions.php:260
423
421
msgid "Dutch"
424
422
msgstr "オランダ語"
425
423
426
#: includes/views/permalink-manager-pro-addons.php:203
424
#: includes/views/permalink-manager-pro-addons.php:216
427
425
msgid ""
428
426
"Each of the words can be removed and any new words can be added to the list. "
…
…
430
428
msgstr "各単語は、リストへ追加/削除できます。また、定義済みのリスト(21の言語)も使用可能です。"
431
429
432
#: includes/views/permalink-manager-uri-editor-tax.php:100
433
#: includes/views/permalink-manager-uri-editor-post.php:120
434
#: includes/views/permalink-manager-uri-editor-post.php:120
430
#: includes/views/permalink-manager-uri-editor-tax.php:103
431
#: includes/views/permalink-manager-uri-editor-post.php:131
432
#: includes/views/permalink-manager-uri-editor-post.php:131
435
433
msgid "Edit"
436
434
msgstr "編集"
437
435
438
#: includes/views/permalink-manager-tools.php:94
436
#: includes/views/permalink-manager-tools.php:114
439
437
msgid "Edit post"
440
438
msgstr "投稿の編集"
441
439
442
#: includes/views/permalink-manager-tools.php:81
440
#: includes/views/permalink-manager-tools.php:102
443
441
msgid "Edit term"
444
442
msgstr "タームの編集"
445
443
446
#: includes/views/permalink-manager-settings.php:258
444
#: includes/views/permalink-manager-settings.php:229
447
445
msgid "Editor (publish\_pages)"
448
446
msgstr "編集者 (publish\_pages)"
449
447
450
#: includes/views/permalink-manager-pro-addons.php:183
448
#: includes/views/permalink-manager-pro-addons.php:196
451
449
msgid "Enable \\"stop words\\""
452
450
msgstr "「使用禁止の単語」を有効にする"
453
451
454
#: includes/views/permalink-manager-settings.php:267
452
#: includes/views/permalink-manager-settings.php:237
455
453
msgid ""
456
454
"Enable this option if you would like to automatically remove redundant "
…
…
458
456
msgstr "冗長なパーマリンクと重複したリダイレクトを自動的に削除したい場合は、このオプションを有効にします。"
459
457
460
#: includes/core/permalink-manager-pro-functions.php:251
458
#: includes/core/permalink-manager-pro-functions.php:261
461
459
msgid "English"
462
460
msgstr "英語"
463
461
464
#: includes/views/permalink-manager-settings.php:151
462
#: includes/views/permalink-manager-settings.php:129
465
463
msgid ""
466
464
"Example: <em>https://example.com/product/old-product-url/<strong>?discount-"
…
…
469
467
msgstr ""
470
468
471
#: includes/views/permalink-manager-settings.php:72
469
#: includes/views/permalink-manager-settings.php:68
472
470
#| msgid "Excluded content types"
473
471
msgid "Exclude content types"
474
472
msgstr "除外する投稿タイプ"
475
473
476
#: includes/views/permalink-manager-settings.php:78
474
#: includes/views/permalink-manager-settings.php:74
477
475
msgid "Exclude drafts"
478
476
msgstr ""
479
477
480
#: includes/core/permalink-manager-pro-functions.php:189
478
#: includes/core/permalink-manager-pro-functions.php:194
481
479
msgid ""
482
480
"Expiration date could not be downloaded at this moment. Please try again in "
…
…
484
482
msgstr "現在、有効期限の情報をダウンロードできない可能性があります。数分後に、再度お試し下さい。"
485
483
486
#: includes/core/permalink-manager-actions.php:434
484
#: includes/core/permalink-manager-actions.php:512
487
485
msgid "External redirects"
488
486
msgstr "外部のリダイレクト"
489
487
490
#: includes/views/permalink-manager-tools.php:70
488
#: includes/views/permalink-manager-tools.php:91
491
489
msgid "Extra Redirect"
492
490
msgstr "追加のリダイレクト"
493
491
494
#: includes/views/permalink-manager-settings.php:116
495
#: includes/views/permalink-manager-pro-addons.php:286
492
#: includes/views/permalink-manager-settings.php:105
493
#: includes/views/permalink-manager-pro-addons.php:305
496
494
msgid "Extra redirects (aliases)"
497
495
msgstr "追加のリダイレクト(エイリアス)"
498
496
499
#: includes/views/permalink-manager-uri-editor-post.php:183
497
#: includes/views/permalink-manager-uri-editor-post.php:182
500
498
msgid "Filter"
501
499
msgstr "フィルター"
502
500
503
#: includes/views/permalink-manager-tools.php:22
501
#: includes/views/permalink-manager-tools.php:28
504
502
msgid "Find & Replace"
505
503
msgstr "検索&置換"
506
504
507
#: includes/views/permalink-manager-tools.php:134
505
#: includes/views/permalink-manager-tools.php:151
508
506
msgid "Find ..."
509
507
msgstr "検索"
510
508
511
#: includes/views/permalink-manager-tools.php:209
509
#: includes/views/permalink-manager-tools.php:226
512
510
msgid "Find and replace"
513
511
msgstr "検索&置換"
514
512
515
#: includes/core/permalink-manager-pro-functions.php:252
513
#: includes/core/permalink-manager-pro-functions.php:262
516
514
msgid "Finnish"
517
515
msgstr "フィンランド語"
518
516
519
#: includes/views/permalink-manager-tools.php:55
517
#: includes/views/permalink-manager-tools.php:76
520
518
msgid "Fix custom permalinks & redirects"
521
519
msgstr "カスタム パーマリンク&リダイレクトを修正する"
522
520
523
#: includes/views/permalink-manager-settings.php:265
521
#: includes/views/permalink-manager-settings.php:236
524
522
msgid "Fix URIs individually (during page load)"
525
523
msgstr "個々にURLを修正する(ページ読込時)"
526
524
527
#: includes/views/permalink-manager-settings.php:238
525
#: includes/views/permalink-manager-settings.php:209
528
526
msgid "Force 404 on non-existing pagination pages"
529
527
msgstr "実在しないページネーションのページに404を強制表示する"
530
528
531
#: includes/views/permalink-manager-settings.php:156
529
#: includes/views/permalink-manager-settings.php:133
532
530
msgid "Force HTTPS/WWW"
533
531
msgstr "HTTPS/WWW 強制"
534
532
535
#: includes/core/permalink-manager-pro-functions.php:253
533
#: includes/core/permalink-manager-pro-functions.php:263
536
534
msgid "French"
537
535
msgstr "フランス語"
538
536
539
#: includes/views/permalink-manager-uri-editor-tax.php:52
540
#: includes/views/permalink-manager-uri-editor-post.php:56
537
#: includes/views/permalink-manager-uri-editor-tax.php:58
538
#: includes/views/permalink-manager-uri-editor-post.php:63
541
539
msgid "Full URI & Permalink"
542
540
msgstr "全ての URIとパーマリンク"
543
541
544
#: includes/views/permalink-manager-settings.php:33
542
#: includes/views/permalink-manager-settings.php:41
545
543
msgid "General settings"
546
544
msgstr "一般設定"
547
545
548
#: includes/core/permalink-manager-pro-functions.php:254
546
#: includes/core/permalink-manager-pro-functions.php:264
549
547
msgid "German"
550
548
msgstr "ドイツ語"
551
549
552
#: permalink-manager.php:216
553
#, php-format
554
msgid ""
555
"Get access to extra features: full taxonomy and WooCommerce support, "
556
"possibility to use custom fields inside the permalinks and more!<br />"
557
"<strong>Buy Permalink Manager Pro <a href=\\"%s\\" target=\\"\_blank\\">here</a> "
558
"and save %s using \\"%s\\" coupon code!</strong> Valid until %s!"
559
msgstr ""
560
"様々な機能へアクセス:タクソノミーとWooCommerceへのフルサポート、パーマリンク内のカスタムフィールドの使用など、盛り沢山!<br />"
561
"<strong>パーマリンク マネージャー Proの購入は<a href=\\"%s\\" target=\\"\_blank\\">コチラ</a>! %s "
562
"の割引 「%s」をご利用下さい。 </strong> %s まで!"
563
564
#: includes/views/permalink-manager-pro-addons.php:139
550
#: includes/views/permalink-manager-pro-addons.php:153
565
551
msgid "Get license information"
566
552
msgstr ""
567
553
568
#: includes/core/permalink-manager-pro-functions.php:255
554
#: includes/core/permalink-manager-pro-functions.php:265
569
555
msgid "Hebrew"
570
556
msgstr "ヘブライ語"
571
557
572
#: includes/core/permalink-manager-pro-functions.php:256
558
#: includes/core/permalink-manager-pro-functions.php:266
573
559
msgid "Hindi"
574
560
msgstr "ヒンディー語"
575
561
576
#: includes/views/permalink-manager-pro-addons.php:329
562
#: includes/views/permalink-manager-pro-addons.php:335
577
563
msgid "http://another-website.com/final-target-url"
578
564
msgstr "http://another-website.com/final-target-url"
…
…
586
572
msgstr "https://permalinkmanager.pro?utm\_source=plugin"
587
573
588
#: includes/core/permalink-manager-admin-functions.php:915
574
#: includes/core/permalink-manager-admin-functions.php:944
589
575
#| msgid ""
590
576
#| "If enabled, the 'Current URI' field will be automatically changed to "
…
…
596
582
msgstr "有効にすると、「現在のURI」項目は投稿が更新又は保存された後に、(下記に表示された)「デフォルトURI」に自動的に変更されます。"
597
583
598
#: includes/views/permalink-manager-settings.php:199
584
#: includes/views/permalink-manager-settings.php:170
599
585
msgid ""
600
586
"If disabled, the custom permalinks <strong>will not be saved</strong> for "
…
…
602
588
msgstr ""
603
589
604
#: includes/core/permalink-manager-third-parties.php:853
590
#: includes/core/permalink-manager-third-parties.php:964
605
591
#, php-format
606
592
msgid ""
…
…
611
597
"に基づいたデフォルトのパーマリンクが適用されます。"
612
598
613
#: includes/views/permalink-manager-settings.php:246
599
#: includes/views/permalink-manager-settings.php:217
614
600
msgid ""
615
601
"If enabled only alphanumeric characters, underscores and dashes will be "
…
…
617
603
msgstr "英数字のみを有効にすると、投稿とターム スラッグにて下線とダッシュの使用が許可されます。"
618
604
619
#: includes/views/permalink-manager-pro-addons.php:202
605
#: includes/views/permalink-manager-pro-addons.php:215
620
606
msgid ""
621
607
"If enabled, all selected \\"stop words\\" will be automatically removed from "
…
…
623
609
msgstr "有効にすると、選択された全ての「使用禁止の単語」はデフォルトのURIから、自動的に削除されます。"
624
610
625
#: includes/views/permalink-manager-settings.php:253
611
#: includes/views/permalink-manager-settings.php:224
626
612
msgid ""
627
613
"If enabled, all the accented letters will be replaced with their non-"
…
…
630
616
"有効にすると、全てのアクセント付きの文字が、アクセントなしの文字に置換されます。(例:Å => A, Æ => AE, Ø => O, Ć => C)"
631
617
632
#: includes/views/permalink-manager-settings.php:44
618
#: includes/views/permalink-manager-settings.php:50
633
619
msgid ""
634
620
"If enabled, Permalink Manager will always force the default custom permalink "
…
…
638
624
"パーマ構造</strong>設定に基づく)"
639
625
640
#: includes/views/permalink-manager-settings.php:206
626
#: includes/views/permalink-manager-settings.php:177
641
627
msgid ""
642
628
"If enabled, Permalink Manager will detect the additional Ultimate Member "
…
…
644
630
msgstr ""
645
631
646
#: includes/views/permalink-manager-settings.php:132
632
#: includes/views/permalink-manager-settings.php:117
647
633
#| msgid ""
648
634
#| "If enabled, Permalink Manage will save the \\"extra redirect\\" for earlier "
…
…
657
643
"パーマリンクのリダイレクトを追加します。"
658
644
659
#: includes/views/permalink-manager-settings.php:218
645
#: includes/views/permalink-manager-settings.php:189
660
646
msgid ""
661
647
"If enabled, Permalink Manager will use the \\"primary category\\" for the "
…
…
664
650
msgstr ""
665
651
666
#: includes/views/permalink-manager-settings.php:79
652
#: includes/views/permalink-manager-settings.php:75
667
653
msgid "If enabled, the custom permalinks for post drafts will not be saved."
668
654
msgstr ""
669
655
670
#: includes/views/permalink-manager-settings.php:212
656
#: includes/views/permalink-manager-settings.php:183
671
657
msgid ""
672
658
"If enabled, the HTML breadcrumbs will be filtered by Permalink Manager to "
…
…
675
661
msgstr ""
676
662
677
#: includes/views/permalink-manager-settings.php:239
663
#: includes/views/permalink-manager-settings.php:210
678
664
msgid ""
679
665
"If enabled, the non-existing pagination pages (for single posts) will return "
…
…
685
671
"システムをご利用で、なんらかの問題が生じた場合は、無効にしてください。</strong>"
686
672
687
#: includes/views/permalink-manager-settings.php:185
673
#: includes/views/permalink-manager-settings.php:156
688
674
msgid ""
689
675
"If enabled, the plugin will load the adjacent translation of post when the "
…
…
693
679
"有効にすると、本プラグインはカスタムパーマリンクを検出した際、投稿に用いた言語に近い翻訳を読み込みますが、投稿やタームに割当られた言語コードとURL内言語コードと一致しない場合は読み込みません。"
694
680
695
#: includes/views/permalink-manager-settings.php:150
681
#: includes/views/permalink-manager-settings.php:129
696
682
msgid ""
697
683
"If enabled, the query parameters will be copied to the target URL when the "
…
…
699
685
msgstr ""
700
686
701
#: includes/views/permalink-manager-settings.php:111
687
#: includes/views/permalink-manager-settings.php:101
702
688
msgid ""
703
689
"If enabled, the visitors trying to access the URL with the old slug will be "
…
…
705
691
msgstr "有効にすると、古いスラッグでURLにアクセスした訪問者を、正規パーマリンクにリダイレクトします。"
706
692
707
#: includes/views/permalink-manager-pro-addons.php:325
693
#: includes/views/permalink-manager-pro-addons.php:332
708
694
msgid ""
709
695
"If not empty, the visitors trying to access this page will be redirected to "
…
…
711
697
msgstr "空白でない場合、このページにアクセスしようと試みた訪問者は、下記のURLにリダイレクトされます。"
712
698
713
#: includes/views/permalink-manager-pro-addons.php:229
699
#: includes/views/permalink-manager-pro-addons.php:245
714
700
msgid ""
715
701
"If selected, \\"Custom Permalinks\\" plugin will be deactivated after its "
…
…
717
703
msgstr "選択すると、カスタムURIのインポート後、「カスタムパーマリンク」プラグインが無効になります。"
718
704
719
#: includes/views/permalink-manager-settings.php:234
705
#: includes/views/permalink-manager-settings.php:205
720
706
msgid ""
721
707
"If this option is enabled, any custom post types and taxonomies with the "
…
…
726
712
msgstr ""
727
713
728
#: includes/views/permalink-manager-pro-addons.php:261
714
#: includes/views/permalink-manager-pro-addons.php:279
729
715
msgid ""
730
716
"If you still did not find the answer to your question, please send us your "
…
…
735
721
"pro\\">[email protected]</a>までお送り下さい。(英語のみ)"
736
722
737
#: includes/views/permalink-manager-pro-addons.php:265
723
#: includes/views/permalink-manager-pro-addons.php:283
738
724
msgid ""
739
725
"If you would like to suggest a new functionality or leave us feedback, we "
…
…
741
727
msgstr "新たな機能の提案やフィードバックをお送り下さい。あらゆる新しいアイデアは大歓迎であり、あなたのコメントをお送り頂ければ幸いです。"
742
728
743
#: includes/core/permalink-manager-admin-functions.php:405
729
#: includes/core/permalink-manager-admin-functions.php:422
744
730
msgid ""
745
731
"If you would like to translate the permastructures and set-up different "
…
…
751
737
"セット(上記のフィールドを参照)が適用されます。"
752
738
753
#: includes/views/permalink-manager-pro-addons.php:241
739
#: includes/views/permalink-manager-pro-addons.php:257
754
740
#, php-format
755
741
msgid "Import %d URIs"
756
742
msgstr "%d URIをインポートする"
757
743
758
#: includes/views/permalink-manager-tools.php:206
759
#: includes/views/permalink-manager-tools.php:283
744
#: includes/views/permalink-manager-tools.php:223
745
#: includes/views/permalink-manager-tools.php:303
760
746
msgid "Important notices"
761
747
msgstr "重要なお知らせ"
762
748
763
#: includes/views/permalink-manager-uri-editor-post.php:89
749
#: includes/views/permalink-manager-uri-editor-post.php:97
764
750
msgid "Inherit (Attachment)"
765
751
msgstr "継承(添付)"
766
752
767
#: includes/views/permalink-manager-settings.php:52
753
#: includes/views/permalink-manager-settings.php:56
768
754
msgid "Inherit parents' slugs"
769
755
msgstr "親のスラッグを継承する"
770
756
771
#: includes/views/permalink-manager-permastructs.php:75
772
#: includes/views/permalink-manager-pro-addons.php:201
773
#: includes/views/permalink-manager-pro-addons.php:234
757
#: includes/views/permalink-manager-permastructs.php:84
758
#: includes/views/permalink-manager-pro-addons.php:214
759
#: includes/views/permalink-manager-pro-addons.php:250
774
760
msgid "Instructions"
775
761
msgstr "手順"
776
762
777
#: includes/core/permalink-manager-pro-functions.php:257
763
#: includes/core/permalink-manager-pro-functions.php:267
778
764
msgid "Italian"
779
765
msgstr "イタリア語"
780
766
781
#: includes/core/permalink-manager-pro-functions.php:258
767
#: includes/core/permalink-manager-pro-functions.php:268
782
768
msgid "Japanese"
783
769
msgstr "日本語"
784
770
785
#: includes/core/permalink-manager-pro-functions.php:259
771
#: includes/core/permalink-manager-pro-functions.php:269
786
772
msgid "Korean"
787
773
msgstr "韓国語"
788
774
789
#: includes/views/permalink-manager-pro-addons.php:126
775
#: includes/views/permalink-manager-pro-addons.php:146
790
776
msgid "Licence"
791
777
msgstr "ライセンス"
792
778
793
#: includes/views/permalink-manager-pro-addons.php:132
779
#: includes/views/permalink-manager-pro-addons.php:152
794
780
msgid "Licence key"
795
781
msgstr "ライセンスキー"
796
782
797
#: includes/views/permalink-manager-debug.php:54
783
#: includes/views/permalink-manager-debug.php:64
798
784
msgid "List of custom redirects set-up by this plugin."
799
785
msgstr "本プラグインによって設定されたカスタム リダイレクトのリスト"
800
786
801
#: includes/views/permalink-manager-tools.php:54
787
#: includes/views/permalink-manager-tools.php:75
802
788
msgid "List of duplicated permalinks"
803
789
msgstr "重複したパーマリンクのリスト"
804
790
805
#: includes/views/permalink-manager-debug.php:65
791
#: includes/views/permalink-manager-debug.php:71
806
792
msgid "List of external redirects set-up by this plugin."
807
793
msgstr "本プラグインにてセットアップされた外部リダイレクトのリスト"
808
794
809
#: includes/views/permalink-manager-debug.php:76
795
#: includes/views/permalink-manager-debug.php:78
810
796
msgid "List of permastructures set-up by this plugin."
811
797
msgstr "本プラグインにてセットアップしたパーマ構造のリスト"
812
798
813
#: includes/views/permalink-manager-debug.php:87
799
#: includes/views/permalink-manager-debug.php:85
814
800
msgid "List of plugin settings."
815
801
msgstr "プラグイン設定 リスト"
816
802
817
#: includes/views/permalink-manager-debug.php:43
803
#: includes/views/permalink-manager-debug.php:57
818
804
msgid "List of the URIs generated by this plugin."
819
805
msgstr "本プラグインで生成されたURIのリスト"
820
806
821
#: includes/core/permalink-manager-admin-functions.php:735
807
#: includes/core/permalink-manager-admin-functions.php:762
822
808
msgid "List of updated items"
823
809
msgstr "更新済みのアイテムのリスト"
…
…
827
813
msgstr "Maciej Bis"
828
814
829
#: includes/core/permalink-manager-admin-functions.php:988
815
#: includes/core/permalink-manager-admin-functions.php:998
830
816
msgid "Manage redirects"
831
817
msgstr "リダイレクトを管理"
832
818
833
#: includes/views/permalink-manager-tools.php:146
834
#: includes/views/permalink-manager-tools.php:222
819
#: includes/views/permalink-manager-tools.php:163
820
#: includes/views/permalink-manager-tools.php:242
835
821
msgid "Mode"
836
822
msgstr "モード"
837
823
838
#: includes/core/permalink-manager-admin-functions.php:926
824
#: includes/core/permalink-manager-admin-functions.php:952
839
825
msgid "Native slug"
840
826
msgstr "ネイティブ スラッグ"
841
827
842
#: includes/views/permalink-manager-tools.php:151
828
#: includes/views/permalink-manager-tools.php:168
843
829
msgid "Native slugs"
844
830
msgstr "ネイティブ スラッグ"
845
831
846
#: includes/core/permalink-manager-admin-functions.php:698
847
#: includes/core/permalink-manager-admin-functions.php:725
832
#: includes/core/permalink-manager-admin-functions.php:722
833
#: includes/core/permalink-manager-admin-functions.php:752
848
834
msgid "New Slug"
849
835
msgstr "新しいスラッグ"
850
836
851
#: includes/core/permalink-manager-admin-functions.php:701
852
#: includes/core/permalink-manager-admin-functions.php:728
837
#: includes/core/permalink-manager-admin-functions.php:725
838
#: includes/core/permalink-manager-admin-functions.php:755
853
839
msgid "New URI"
854
840
msgstr "新しいURI"
855
841
856
#: includes/views/permalink-manager-settings.php:265
842
#: includes/views/permalink-manager-settings.php:236
857
843
msgid "No"
858
844
msgstr "いいえ"
859
845
860
#: includes/core/permalink-manager-third-parties.php:356
846
#: includes/core/permalink-manager-third-parties.php:370
861
847
msgid "No \\"Custom Permalinks\\" URIs were imported!"
862
848
msgstr "「カスタム パーマリンク」 URIはインポートされませんでした!"
863
849
864
#: includes/core/permalink-manager-actions.php:401
850
#: includes/core/permalink-manager-actions.php:149
865
851
msgid "No Custom URIs or Custom Redirects were removed!"
866
852
msgstr "カスタムURIもしくはカスタム リダイレクトは、削除されませんでした!"
867
853
868
#: includes/views/permalink-manager-pro-addons.php:246
854
#: includes/views/permalink-manager-pro-addons.php:262
869
855
msgid "No custom URIs to import"
870
856
msgstr "インポートするカスタムURIはありません"
871
857
872
#: includes/views/permalink-manager-settings.php:252
858
#: includes/views/permalink-manager-settings.php:223
873
859
msgid "No, keep accented letters in the slugs"
874
860
msgstr "いいえ、スラッグにアクセント付き文字を保持します。"
875
861
876
#: includes/views/permalink-manager-settings.php:245
862
#: includes/views/permalink-manager-settings.php:216
877
863
msgid "No, keep special characters (.,|\_+) in the slugs"
878
864
msgstr "いいえ、スラッグに特殊文字(.,|\_+)を保持します。"
879
865
880
#: includes/core/permalink-manager-pro-functions.php:260
866
#: includes/core/permalink-manager-pro-functions.php:270
881
867
msgid "Norwegian"
882
868
msgstr "ノルウェー語"
883
869
884
#: includes/core/permalink-manager-admin-functions.php:697
885
#: includes/core/permalink-manager-admin-functions.php:724
870
#: includes/core/permalink-manager-admin-functions.php:721
871
#: includes/core/permalink-manager-admin-functions.php:751
886
872
msgid "Old Slug"
887
873
msgstr "古いスラッグ"
888
874
889
#: includes/views/permalink-manager-settings.php:107
875
#: includes/views/permalink-manager-settings.php:99
890
876
msgid "Old slug redirect"
891
877
msgstr "古いスラッグ リダイレクト"
892
878
893
#: includes/core/permalink-manager-admin-functions.php:700
894
#: includes/core/permalink-manager-admin-functions.php:727
879
#: includes/core/permalink-manager-admin-functions.php:724
880
#: includes/core/permalink-manager-admin-functions.php:754
895
881
msgid "Old URI"
896
882
msgstr "古いURI"
897
883
898
#: includes/views/permalink-manager-settings.php:259
884
#: includes/views/permalink-manager-settings.php:230
899
885
#, php-format
900
886
msgid ""
…
…
906
892
"コチラ</a>で確認できます。"
907
893
908
#: includes/views/permalink-manager-uri-editor.php:89
894
#: includes/views/permalink-manager-uri-editor.php:97
909
895
msgid "Per page"
910
896
msgstr "ページ毎"
911
897
912
#: includes/views/permalink-manager-tools.php:18
898
#: includes/views/permalink-manager-tools.php:24
913
899
msgid "Permalink Duplicates"
914
900
msgstr "重複したパーマリンク"
915
901
916
#: includes/core/permalink-manager-third-parties.php:848
917
#: includes/core/permalink-manager-third-parties.php:1007
918
#: includes/core/permalink-manager-gutenberg.php:38
919
#: includes/core/permalink-manager-admin-functions.php:110
920
#: includes/core/permalink-manager-admin-functions.php:110
921
#: includes/core/permalink-manager-admin-functions.php:791
922
#: includes/core/permalink-manager-admin-functions.php:882
923
#: includes/core/permalink-manager-admin-functions.php:887
924
#: includes/core/permalink-manager-admin-functions.php:888
902
#: includes/core/permalink-manager-third-parties.php:959
903
#: includes/core/permalink-manager-third-parties.php:1178
904
#: includes/core/permalink-manager-gutenberg.php:42
905
#: includes/core/permalink-manager-admin-functions.php:112
906
#: includes/core/permalink-manager-admin-functions.php:112
907
#: includes/core/permalink-manager-admin-functions.php:818
908
#: includes/core/permalink-manager-admin-functions.php:916
909
#: includes/core/permalink-manager-admin-functions.php:921
910
#: includes/core/permalink-manager-admin-functions.php:922
925
911
msgid "Permalink Manager"
926
912
msgstr "Permalink Manager"
927
913
928
#: includes/views/permalink-manager-settings.php:141
914
#: includes/views/permalink-manager-settings.php:123
929
915
#| msgid ""
930
916
#| "<strong>Permalink Manager can force the trailing slashes settings in the "
…
…
935
921
msgstr "Permalink Managerは、リダイレクトのあるカスタム パーマリンクの末尾のスラッシュ設定を強制できます。"
936
922
937
#: includes/views/permalink-manager-settings.php:169
923
#: includes/views/permalink-manager-settings.php:142
938
924
#| msgid ""
939
925
#| "<strong>Permalink Manager includes a set of hooks that allow to extend "
…
…
950
936
msgstr "Permalink Manager Pro"
951
937
952
#: includes/views/permalink-manager-settings.php:74
938
#: includes/views/permalink-manager-settings.php:70
953
939
msgid ""
954
940
"Permalink Manager will ignore and not filter the custom permalinks of all "
…
…
956
942
msgstr "Permalink Managerは、上記で選択した全ての投稿タイプとタクソノミーのカスタム パーマリンクを無視し、フィルタリングしません。"
957
943
958
#: includes/core/permalink-manager-actions.php:438
959
#: includes/core/permalink-manager-actions.php:442
960
#: includes/core/permalink-manager-admin-functions.php:430
944
#: includes/core/permalink-manager-actions.php:516
945
#: includes/core/permalink-manager-actions.php:520
946
#: includes/core/permalink-manager-admin-functions.php:440
961
947
msgid "Permastructure settings"
962
948
msgstr "パーマ構造 設定"
963
949
964
#: includes/views/permalink-manager-permastructs.php:82
950
#: includes/views/permalink-manager-permastructs.php:91
965
951
msgid "Permastructure tags"
966
952
msgstr "パーマ構造 タグ"
967
953
968
#: includes/core/permalink-manager-admin-functions.php:404
954
#: includes/core/permalink-manager-admin-functions.php:422
969
955
msgid "Permastructure translations"
970
956
msgstr "パーマ構造 翻訳"
971
957
972
#: includes/views/permalink-manager-permastructs.php:15
958
#: includes/views/permalink-manager-permastructs.php:21
973
959
msgid "Permastructures"
974
960
msgstr "パーマ構造"
975
961
976
#: includes/core/permalink-manager-pro-functions.php:261
962
#: includes/core/permalink-manager-pro-functions.php:271
977
963
msgid "Persian"
978
964
msgstr "ペルシア語"
979
965
980
#: includes/views/permalink-manager-settings.php:160
966
#: includes/views/permalink-manager-settings.php:135
981
967
msgid "Please disable it if you encounter any redirect loop issues."
982
968
msgstr "リダイレクトのループ問題が発生した場合は、このオプションを無効にして下さい。"
983
969
984
#: includes/views/permalink-manager-settings.php:192
970
#: includes/views/permalink-manager-settings.php:163
985
971
msgid ""
986
972
"Please disable this feature if the language code in the custom permalinks is "
…
…
988
974
msgstr ""
989
975
990
#: includes/views/permalink-manager-settings.php:121
976
#: includes/views/permalink-manager-settings.php:109
991
977
msgid ""
992
978
"Please enable this option if you would like to manage additional custom "
993
"redirects (aliasees) in URI Editor for individual posts & terms."
994
msgstr ""
995
996
#: includes/views/permalink-manager-settings.php:142
979
"redirects (aliases) in URI Editor for individual posts & terms."
980
msgstr ""
981
982
#: includes/views/permalink-manager-settings.php:123
997
983
msgid ""
998
984
"Please go to \\"<em>General settings -> Trailing slashes</em>\\" to choose if "
…
…
1000
986
msgstr ""
1001
987
1002
#: includes/views/permalink-manager-settings.php:67
988
#: includes/views/permalink-manager-settings.php:64
1003
989
msgid ""
1004
990
"Please go to \\"<em>Redirect settings -> Trailing slashes redirect</em>\\" to "
…
…
1006
992
msgstr ""
1007
993
1008
#: includes/views/permalink-manager-pro-addons.php:235
994
#: includes/views/permalink-manager-pro-addons.php:251
1009
995
msgid ""
1010
996
"Please note that \\"Custom Permalinks\\" (if activated) may break the behavior "
…
…
1012
998
msgstr "「カスタム パーマリンク」(有効にしている場合)により、本プラグインの動作が損なわれる場合があります。"
1013
999
1014
#: includes/views/permalink-manager-settings.php:133
1000
#: includes/views/permalink-manager-settings.php:117
1015
1001
msgid ""
1016
1002
"Please note that the new redirects will be saved only if \\"Extra redirects "
…
…
1018
1004
msgstr ""
1019
1005
1020
#: includes/core/permalink-manager-pro-functions.php:149
1006
#: includes/core/permalink-manager-pro-functions.php:161
1021
1007
#, php-format
1022
1008
msgid ""
…
…
1027
1013
"Manager Pro のアップデート&機能をご利用下さい。"
1028
1014
1029
#: includes/core/permalink-manager-pro-functions.php:262
1015
#: includes/core/permalink-manager-pro-functions.php:272
1030
1016
msgid "Polish"
1031
1017
msgstr "ポーランド語"
1032
1018
1033
#: includes/core/permalink-manager-pro-functions.php:263
1019
#: includes/core/permalink-manager-pro-functions.php:273
1034
1020
msgid "Portuguese"
1035
1021
msgstr "ポルトガル語"
1036
1022
1037
#: includes/views/permalink-manager-uri-editor-post.php:115
1023
#: includes/views/permalink-manager-uri-editor-post.php:126
1038
1024
msgid "Post status"
1039
1025
msgstr "投稿状態"
1040
1026
1041
#: includes/views/permalink-manager-uri-editor.php:94
1027
#: includes/views/permalink-manager-uri-editor.php:102
1042
1028
msgid "Post statuses"
1043
1029
msgstr "投稿状態"
1044
1030
1045
#: includes/views/permalink-manager-uri-editor-post.php:55
1031
#: includes/views/permalink-manager-uri-editor-post.php:62
1046
1032
msgid "Post title"
1047
1033
msgstr "投稿タイトル"
1048
1034
1049
#: includes/views/permalink-manager-permastructs.php:31
1050
#: includes/views/permalink-manager-tools.php:162
1051
#: includes/views/permalink-manager-tools.php:239
1052
#: includes/core/permalink-manager-admin-functions.php:261
1035
#: includes/views/permalink-manager-permastructs.php:40
1036
#: includes/views/permalink-manager-tools.php:179
1037
#: includes/views/permalink-manager-tools.php:259
1038
#: includes/core/permalink-manager-admin-functions.php:281
1053
1039
msgid "Post types"
1054
1040
msgstr "投稿タイプ"
1055
1041
1056
#: includes/views/permalink-manager-settings.php:165
1042
#: includes/views/permalink-manager-settings.php:139
1057
1043
msgid "Redirect mode"
1058
1044
msgstr "リダイレクト モード"
1059
1045
1060
#: includes/views/permalink-manager-settings.php:84
1046
#: includes/views/permalink-manager-settings.php:80
1061
1047
msgid "Redirect settings"
1062
1048
msgstr ""
1063
1049
1064
#: includes/views/permalink-manager-pro-addons.php:324
1050
#: includes/views/permalink-manager-pro-addons.php:332
1065
1051
msgid "Redirect this page to external URL"
1066
1052
msgstr "このページを外部URLにリダイレクトする"
1067
1053
1068
#: includes/views/permalink-manager-settings.php:147
1054
#: includes/views/permalink-manager-settings.php:127
1069
1055
msgid "Redirect with query parameters"
1070
1056
msgstr ""
1071
1057
1072
#: includes/views/permalink-manager-tools.php:286
1058
#: includes/views/permalink-manager-tools.php:306
1073
1059
msgid "Regenerate"
1074
1060
msgstr "再作成"
1075
1061
1076
#: includes/views/permalink-manager-tools.php:226
1062
#: includes/views/permalink-manager-tools.php:246
1077
1063
msgid "Regenerate custom permalinks"
1078
1064
msgstr "カスタム パーマリンクを再生成する"
1079
1065
1080
#: includes/views/permalink-manager-tools.php:227
1066
#: includes/views/permalink-manager-tools.php:247
1081
1067
msgid "Regenerate native slugs"
1082
1068
msgstr "ネイティブ スラッグを再生成する"
1083
1069
1084
#: includes/views/permalink-manager-tools.php:26
1070
#: includes/views/permalink-manager-tools.php:32
1085
1071
msgid "Regenerate/Reset"
1086
1072
msgstr "再作成 / リセット"
1087
1073
1088
#: includes/views/permalink-manager-pro-addons.php:137
1074
#: includes/views/permalink-manager-pro-addons.php:153
1089
1075
msgid "Reload the expiration date"
1090
1076
msgstr "有効期限を確認する"
1091
1077
1092
#: includes/views/permalink-manager-debug.php:45
1078
#: includes/views/permalink-manager-debug.php:57
1093
1079
msgid "Remove all custom permalinks"
1094
1080
msgstr "全てのカスタム パーマリンクを削除する"
1095
1081
1096
#: includes/views/permalink-manager-debug.php:56
1082
#: includes/views/permalink-manager-debug.php:64
1097
1083
msgid "Remove all custom redirects"
1098
1084
msgstr "全てのカスタム リダイレクトを削除する"
1099
1085
1100
#: includes/views/permalink-manager-debug.php:67
1086
#: includes/views/permalink-manager-debug.php:71
1101
1087
msgid "Remove all external redirects"
1102
1088
msgstr "全ての外部リダイレクトを削除する"
…
…
1106
1092
msgstr "全てのパーマ構造 設定を削除する"
1107
1093
1108
#: includes/views/permalink-manager-debug.php:89
1094
#: includes/views/permalink-manager-debug.php:85
1109
1095
msgid "Remove all plugin settings"
1110
1096
msgstr "全てのプラグイン設定を削除する"
1111
1097
1112
#: includes/views/permalink-manager-pro-addons.php:173
1098
#: includes/views/permalink-manager-pro-addons.php:186
1113
1099
msgid "Remove all words"
1114
1100
msgstr "全ての単語を削除する"
1115
1101
1116
#: includes/views/permalink-manager-tools.php:85
1117
#: includes/views/permalink-manager-tools.php:98
1102
#: includes/views/permalink-manager-tools.php:106
1103
#: includes/views/permalink-manager-tools.php:118
1118
1104
msgid "Remove broken URI"
1119
1105
msgstr "リンク切れURLを削除する"
…
…
1123
1109
msgstr "末尾のスラッシュを削除する"
1124
1110
1125
#: includes/views/permalink-manager-tools.php:140
1111
#: includes/views/permalink-manager-tools.php:157
1126
1112
msgid "Replace with ..."
1127
1113
msgstr "置換"
1128
1114
1129
#: includes/core/permalink-manager-admin-functions.php:424
1115
#: includes/core/permalink-manager-admin-functions.php:437
1130
1116
msgid "Restore default permastructure"
1131
1117
msgstr "デフォルトのパーマ構造を復元する"
1132
1118
1133
#: includes/core/permalink-manager-admin-functions.php:937
1119
#: includes/core/permalink-manager-admin-functions.php:957
1134
1120
msgid "Restore Default URI"
1135
1121
msgstr "デフォルトのURIを復元する"
1136
1122
1137
#: includes/core/permalink-manager-pro-functions.php:264
1123
#: includes/core/permalink-manager-pro-functions.php:274
1138
1124
msgid "Russian"
1139
1125
msgstr "ロシア語"
1140
1126
1141
#: includes/views/permalink-manager-pro-addons.php:293
1127
#: includes/views/permalink-manager-pro-addons.php:309
1142
1128
msgid "sample/custom-uri"
1143
1129
msgstr "sample/custom-uri"
1144
1130
1145
#: includes/views/permalink-manager-pro-addons.php:205
1131
#: includes/views/permalink-manager-pro-addons.php:218
1146
1132
msgid "Save"
1147
1133
msgstr "保存する"
1148
1134
1149
#: includes/views/permalink-manager-uri-editor-tax.php:147
1135
#: includes/views/permalink-manager-uri-editor-tax.php:140
1150
1136
#: includes/views/permalink-manager-uri-editor-post.php:150
1151
1137
msgid "Save all the URIs above"
1152
1138
msgstr "上記の全てのURIを保存する"
1153
1139
1154
#: includes/views/permalink-manager-uri-editor-tax.php:146
1140
#: includes/views/permalink-manager-uri-editor-tax.php:139
1155
1141
#: includes/views/permalink-manager-uri-editor-post.php:149
1156
1142
msgid "Save all the URIs below"
1157
1143
msgstr "以下の全てのURIを保存する"
1158
1144
1159
#: includes/views/permalink-manager-settings.php:127
1145
#: includes/views/permalink-manager-settings.php:113
1160
1146
msgid "Save old custom permalinks as extra redirects"
1161
1147
msgstr ""
1162
1148
1163
#: includes/core/permalink-manager-admin-functions.php:961
1149
#: includes/core/permalink-manager-admin-functions.php:973
1164
1150
msgid "Save permalink"
1165
1151
msgstr "パーマリンクを保存する"
1166
1152
1167
#: includes/views/permalink-manager-permastructs.php:86
1153
#: includes/views/permalink-manager-permastructs.php:95
1168
1154
msgid "Save permastructures"
1169
1155
msgstr "パーマ構造を保存する"
1170
1156
1171
#: includes/views/permalink-manager-settings.php:274
1157
#: includes/views/permalink-manager-settings.php:243
1172
1158
msgid "Save settings"
1173
1159
msgstr "設定を保存する"
1174
1160
1175
#: includes/views/permalink-manager-uri-editor-tax.php:155
1176
#: includes/views/permalink-manager-uri-editor-post.php:158
1161
#: includes/views/permalink-manager-uri-editor-tax.php:148
1162
#: includes/views/permalink-manager-uri-editor-post.php:157
1177
1163
msgid "Search"
1178
1164
msgstr "検索"
1179
1165
1180
#: includes/core/permalink-manager-admin-functions.php:284
1166
#: includes/core/permalink-manager-admin-functions.php:304
1181
1167
msgid "Select all"
1182
1168
msgstr "全てを選択する"
1183
1169
1184
#: includes/views/permalink-manager-tools.php:155
1185
#: includes/views/permalink-manager-tools.php:232
1170
#: includes/views/permalink-manager-tools.php:172
1171
#: includes/views/permalink-manager-tools.php:252
1186
1172
msgid "Select content type"
1187
1173
msgstr "コンテンツタイプを選択する"
1188
1174
1189
#: includes/views/permalink-manager-tools.php:196
1190
#: includes/views/permalink-manager-tools.php:273
1175
#: includes/views/permalink-manager-tools.php:213
1176
#: includes/views/permalink-manager-tools.php:293
1191
1177
msgid "Select IDs"
1192
1178
msgstr "IDを選択する"
1193
1179
1194
#: includes/views/permalink-manager-tools.php:187
1195
#: includes/views/permalink-manager-tools.php:264
1180
#: includes/views/permalink-manager-tools.php:204
1181
#: includes/views/permalink-manager-tools.php:284
1196
1182
msgid "Select post statuses"
1197
1183
msgstr "投稿状態を選択する"
1198
1184
1199
#: includes/views/permalink-manager-tools.php:167
1200
#: includes/views/permalink-manager-tools.php:244
1185
#: includes/views/permalink-manager-tools.php:184
1186
#: includes/views/permalink-manager-tools.php:264
1201
1187
msgid "Select post types"
1202
1188
msgstr "投稿タイプを選択する"
1203
1189
1204
#: includes/views/permalink-manager-tools.php:176
1205
#: includes/views/permalink-manager-tools.php:253
1190
#: includes/views/permalink-manager-tools.php:193
1191
#: includes/views/permalink-manager-tools.php:273
1206
1192
msgid "Select taxonomies"
1207
1193
msgstr "タクソノミーを選択する"
1208
1194
1209
#: includes/views/permalink-manager-settings.php:14
1210
#: includes/core/permalink-manager-admin-functions.php:156
1195
#: includes/views/permalink-manager-settings.php:21
1196
#: includes/core/permalink-manager-admin-functions.php:166
1211
1197
msgid "Settings"
1212
1198
msgstr "設定"
1213
1199
1214
#: includes/views/permalink-manager-settings.php:229
1200
#: includes/views/permalink-manager-settings.php:200
1215
1201
msgid "Show \\"Native slug\\" field in URI Editor"
1216
1202
msgstr ""
1217
1203
1218
#: includes/core/permalink-manager-admin-functions.php:439
1204
#: includes/core/permalink-manager-admin-functions.php:445
1219
1205
msgid "Show additional settings"
1220
1206
msgstr "追加設定を表示する"
1221
1207
1222
#: includes/core/permalink-manager-admin-functions.php:722
1208
#: includes/core/permalink-manager-admin-functions.php:729
1223
1209
msgid "Show more details"
1224
1210
msgstr "さらなる詳細を表示する"
1225
1211
1226
#: includes/core/permalink-manager-actions.php:711
1227
msgid "Sitemaps were updated!"
1228
msgstr "サイトマップは、更新されました!"
1229
1230
#: includes/views/permalink-manager-uri-editor-tax.php:95
1231
#: includes/views/permalink-manager-uri-editor-post.php:114
1212
#: includes/views/permalink-manager-uri-editor-tax.php:98
1213
#: includes/views/permalink-manager-uri-editor-post.php:125
1232
1214
msgid "Slug"
1233
1215
msgstr "スラッグ"
1234
1216
1235
#: includes/views/permalink-manager-settings.php:50
1217
#: includes/views/permalink-manager-settings.php:54
1236
1218
msgid "Slugs mode"
1237
1219
msgstr "スラッグ モード"
1238
1220
1239
#: includes/core/permalink-manager-pro-functions.php:265
1221
#: includes/core/permalink-manager-pro-functions.php:275
1240
1222
msgid "Spanish"
1241
1223
msgstr "スペイン語"
1242
1224
1243
#: includes/views/permalink-manager-tools.php:30
1225
#: includes/views/permalink-manager-tools.php:36
1244
1226
msgid "Stop Words"
1245
1227
msgstr "使用禁止の単語"
1246
1228
1247
#: includes/views/permalink-manager-settings.php:243
1229
#: includes/views/permalink-manager-settings.php:214
1248
1230
msgid "Strip special characters"
1249
1231
msgstr "特殊文字を取り除く"
1250
1232
1251
#: includes/views/permalink-manager-pro-addons.php:264
1233
#: includes/views/permalink-manager-pro-addons.php:282
1252
1234
msgid "Suggestions/feedback"
1253
1235
msgstr "ご意見 / フィードバック"
1254
1236
1255
#: includes/views/permalink-manager-pro-addons.php:106
1237
#: includes/views/permalink-manager-pro-addons.php:122
1256
1238
msgid "Support"
1257
1239
msgstr "サポート"
1258
1240
1259
#: includes/core/permalink-manager-pro-functions.php:266
1241
#: includes/core/permalink-manager-pro-functions.php:276
1260
1242
msgid "Swedish"
1261
1243
msgstr "スウェーデン語"
1262
1244
1263
#: includes/views/permalink-manager-permastructs.php:36
1264
#: includes/views/permalink-manager-tools.php:163
1265
#: includes/views/permalink-manager-tools.php:240
1266
#: includes/core/permalink-manager-admin-functions.php:261
1245
#: includes/views/permalink-manager-permastructs.php:45
1246
#: includes/views/permalink-manager-tools.php:180
1247
#: includes/views/permalink-manager-tools.php:260
1248
#: includes/core/permalink-manager-admin-functions.php:281
1267
1249
msgid "Taxonomies"
1268
1250
msgstr "タクソノミー"
1269
1251
1270
#: includes/views/permalink-manager-pro-addons.php:259
1252
#: includes/views/permalink-manager-pro-addons.php:277
1271
1253
msgid "Technical support"
1272
1254
msgstr "技術的サポート"
1273
1255
1274
#: includes/views/permalink-manager-uri-editor-tax.php:51
1256
#: includes/views/permalink-manager-uri-editor-tax.php:57
1275
1257
msgid "Term title"
1276
1258
msgstr "ターム タイトル"
1277
1259
1278
#: includes/views/permalink-manager-uri-editor-tax.php:112
1279
#: includes/views/permalink-manager-uri-editor-post.php:101
1260
#: includes/views/permalink-manager-uri-editor-tax.php:116
1261
#: includes/views/permalink-manager-uri-editor-post.php:111
1280
1262
msgid ""
1281
1263
"The above permalink will be automatically updated and is locked for editing."
1282
1264
msgstr ""
1283
1265
1284
#: includes/core/permalink-manager-admin-functions.php:899
1266
#: includes/core/permalink-manager-admin-functions.php:933
1285
1267
msgid "The custom URI cannot be edited on frontpage."
1286
1268
msgstr "カスタムURIは、フロントページでは編集不可です。"
1287
1269
1288
#: includes/core/permalink-manager-admin-functions.php:927
1270
#: includes/core/permalink-manager-admin-functions.php:952
1289
1271
msgid ""
1290
1272
"The native slug is by default automatically used in native permalinks (when "
…
…
1293
1275
"ネイティブ スラッグは、(Permalink Managerが無効になっている場合)デフォルトでは自動的にネイティブパーマリンクが使用されます。"
1294
1276
1295
#: includes/views/permalink-manager-settings.php:55
1277
#: includes/views/permalink-manager-settings.php:57
1296
1278
msgid ""
1297
1279
"The native slug is generated from the initial title after the post or term "
…
…
1299
1281
msgstr "ネイティブ スラッグは、投稿またはタームが公開された後、最初のタイトルから生成されます。"
1300
1282
1301
#: includes/core/permalink-manager-actions.php:633
1283
#: includes/core/permalink-manager-actions.php:377
1302
1284
msgid "The redirect was removed successfully!"
1303
1285
msgstr "リダイレクトは、無事削除されました!"
1304
1286
1305
#: includes/core/permalink-manager-actions.php:106
1287
#: includes/core/permalink-manager-actions.php:431
1306
1288
msgid "The settings are saved!"
1307
1289
msgstr "設定は、保存されました!"
1308
1290
1309
#: includes/core/permalink-manager-pro-functions.php:555
1291
#: includes/core/permalink-manager-pro-functions.php:611
1310
1292
msgid ""
1311
1293
"The URIs are case-insensitive, eg. <strong>BLACKFRIDAY</strong> and <strong>"
…
…
1315
1297
"blackfriday</strong>は、同じです。"
1316
1298
1317
#: includes/core/permalink-manager-admin-functions.php:902
1299
#: includes/core/permalink-manager-admin-functions.php:936
1318
1300
msgid ""
1319
1301
"The URL above is displayed in read-only mode. To enable editing, change the "
…
…
1322
1304
msgstr ""
1323
1305
1324
#: includes/views/permalink-manager-pro-addons.php:236
1306
#: includes/views/permalink-manager-pro-addons.php:252
1325
1307
msgid ""
1326
1308
"Therefore, it is recommended to disable \\"Custom Permalink\\" and import old "
…
…
1329
1311
"したがって、「カスタム パーマリンク」を無効にして、Permalink Manager Proを使用する前の古いパーマリンクのインポートを推奨します。"
1330
1312
1331
#: includes/views/permalink-manager-settings.php:176
1313
#: includes/views/permalink-manager-settings.php:147
1332
1314
msgid "Third party plugins"
1333
1315
msgstr "サードパーティー プラグイン"
1334
1316
1335
#: includes/views/permalink-manager-settings.php:94
1317
#: includes/views/permalink-manager-settings.php:88
1336
1318
msgid ""
1337
1319
"This feature will be also used to redirect (old) original permalinks to (new)"
…
…
1341
1323
"パーマリンクにリダイレクトするために使用されます。"
1342
1324
1343
#: includes/core/permalink-manager-admin-functions.php:1092
1325
#: includes/core/permalink-manager-admin-functions.php:1113
1344
1326
#, php-format
1345
1327
msgid ""
…
…
1355
1337
"このオプションは、ネイティブの設定を変更し、末尾のスラッシュを投稿・タームのパーマリンクの末尾に、追加・削除するかを制御するために使用できます。"
1356
1338
1357
#: includes/core/permalink-manager-admin-functions.php:695
1358
#: includes/core/permalink-manager-admin-functions.php:722
1339
#: includes/core/permalink-manager-admin-functions.php:719
1340
#: includes/core/permalink-manager-admin-functions.php:748
1359
1341
msgid "Title"
1360
1342
msgstr "タイトル"
1361
1343
1362
#: includes/views/permalink-manager-permastructs.php:79
1344
#: includes/views/permalink-manager-permastructs.php:88
1363
1345
#, php-format
1364
1346
msgid ""
…
…
1368
1350
msgstr ""
1369
1351
1370
#: includes/views/permalink-manager-pro-addons.php:260
1352
#: includes/views/permalink-manager-pro-addons.php:278
1371
1353
#, php-format
1372
1354
msgid ""
…
…
1378
1360
"の<strong>Knowledge Base</strong> をご利用下さい。(英語のみ)"
1379
1361
1380
#: includes/views/permalink-manager-tools.php:200
1381
#: includes/views/permalink-manager-tools.php:277
1362
#: includes/views/permalink-manager-tools.php:217
1363
#: includes/views/permalink-manager-tools.php:297
1382
1364
msgid ""
1383
1365
"To narrow the above filters you can type the post IDs (or ranges) here. Eg. "
…
…
1386
1368
"上記のフィルターに絞りこむために、ここに投稿ID(または範囲)を入力してください。例:<strong>1-8, 10, 25</strong>."
1387
1369
1388
#: includes/views/permalink-manager-pro-addons.php:262
1370
#: includes/views/permalink-manager-pro-addons.php:280
1389
1371
msgid ""
1390
1372
"To reduce the response time, please attach your licence key and if possible "
…
…
1393
1375
"ご返答までの時間を短縮するため、ライセンスキーを添付し、可能であればWebサイトのURLと問題箇所のスクリーンショットもお送り下さい。(英語のみ)"
1394
1376
1395
#: includes/views/permalink-manager-tools.php:15
1377
#: includes/views/permalink-manager-tools.php:21
1396
1378
msgid "Tools"
1397
1379
msgstr "ツール"
…
…
1401
1383
msgstr "末尾のスラッシュ"
1402
1384
1403
#: includes/views/permalink-manager-settings.php:138
1385
#: includes/views/permalink-manager-settings.php:121
1404
1386
msgid "Trailing slashes redirect"
1405
1387
msgstr "末尾のスラッシュリダイレクト"
1406
1388
1407
#: includes/core/permalink-manager-pro-functions.php:267
1389
#: includes/core/permalink-manager-pro-functions.php:277
1408
1390
msgid "Turkish"
1409
1391
msgstr "トルコ語"
1410
1392
1411
#: includes/views/permalink-manager-pro-addons.php:279
1393
#: includes/views/permalink-manager-pro-addons.php:299
1412
1394
msgid ""
1413
1395
"Turn on \\"<strong>Extra redirects (aliases)</strong>\\" in Permalink Manager "
…
…
1415
1397
msgstr ""
1416
1398
1417
#: includes/views/permalink-manager-pro-addons.php:193
1399
#: includes/views/permalink-manager-pro-addons.php:206
1418
1400
msgid "Type comma to separate the words."
1419
1401
msgstr "単語の区切りにカンマを入力下さい。"
1420
1402
1421
#: includes/views/permalink-manager-settings.php:203
1403
#: includes/views/permalink-manager-settings.php:174
1422
1404
msgid "Ultimate Member support"
1423
1405
msgstr ""
1424
1406
1425
#: includes/core/permalink-manager-admin-functions.php:285
1407
#: includes/core/permalink-manager-admin-functions.php:305
1426
1408
msgid "Unselect all"
1427
1409
msgstr "選択を全て解除する"
1428
1410
1429
#: includes/core/permalink-manager-admin-functions.php:628
1411
#: includes/core/permalink-manager-admin-functions.php:646
1430
1412
msgid "Upgrade to PRO"
1431
1413
msgstr "Pro版にアップグレード"
1432
1414
1433
#: includes/core/permalink-manager-actions.php:601
1415
#: includes/core/permalink-manager-actions.php:339
1434
1416
#, php-format
1435
1417
msgid "URI \\"%s\\" was removed successfully!"
1436
1418
msgstr "「%s」のURIは、無事削除されました!"
1437
1419
1438
#: includes/core/permalink-manager-actions.php:613
1420
#: includes/core/permalink-manager-actions.php:351
1439
1421
msgid "URI and/or custom redirects does not exist or were already removed!"
1440
1422
msgstr "URIもしくはカスタムリダイレクトは、実在しないか既に削除されています!"
1441
1423
1442
#: includes/core/permalink-manager-admin-functions.php:155
1424
#: includes/views/permalink-manager-uri-editor.php:23
1425
#: includes/core/permalink-manager-admin-functions.php:165
1443
1426
msgid "URI Editor"
1444
1427
msgstr "URIエディター"
1445
1428
1446
#: includes/views/permalink-manager-uri-editor.php:28
1447
msgid "URI editor"
1448
msgstr "URIエディター"
1449
1450
#: includes/views/permalink-manager-settings.php:257
1429
#: includes/views/permalink-manager-settings.php:228
1451
1430
msgid "URI Editor role capability"
1452
1431
msgstr "URIエディター 種類と権限"
1453
1432
1454
#: includes/core/permalink-manager-actions.php:663
1433
#: includes/core/permalink-manager-actions.php:708
1455
1434
msgid "URI is already in use, please select another one!"
1456
1435
msgstr "URIは既に使用済みです。他をお選び下さい。"
1457
1436
1458
#: includes/views/permalink-manager-settings.php:39
1459
#: includes/core/permalink-manager-admin-functions.php:914
1437
#: includes/views/permalink-manager-settings.php:47
1438
#: includes/core/permalink-manager-admin-functions.php:944
1460
1439
msgid "URI update mode"
1461
1440
msgstr ""
1462
1441
1463
#: includes/views/permalink-manager-settings.php:52
1442
#: includes/views/permalink-manager-settings.php:56
1464
1443
msgid "Use actual titles as slugs"
1465
1444
msgstr "スラッグとして実際のタイトルを使用する"
…
…
1469
1448
msgstr "デフォルトの設定を使用する"
1470
1449
1471
#: includes/core/permalink-manager-admin-functions.php:867
1450
#: includes/core/permalink-manager-admin-functions.php:901
1472
1451
#, php-format
1473
1452
msgid "Use global settings \[%s\]"
1474
1453
msgstr "グローバル設定を使用する \[%s\]"
1475
1454
1476
#: includes/views/permalink-manager-settings.php:52
1455
#: includes/views/permalink-manager-settings.php:56
1477
1456
msgid "Use native slugs"
1478
1457
msgstr "ネイティブ スラッグを使用する"
1479
1458
1480
#: includes/views/permalink-manager-tools.php:228
1459
#: includes/views/permalink-manager-tools.php:248
1481
1460
msgid "Use original URLs as custom permalinks"
1482
1461
msgstr "カスタム パーマリンクをオリジナルのURLとして使用する"
1483
1462
1484
#: includes/views/permalink-manager-settings.php:45
1463
#: includes/views/permalink-manager-settings.php:50
1485
1464
msgid ""
1486
1465
"Use the last option if you want to to customize only specific permalinks and "
…
…
1488
1467
msgstr ""
1489
1468
1490
#: includes/views/permalink-manager-settings.php:56
1469
#: includes/views/permalink-manager-settings.php:57
1491
1470
msgid ""
1492
1471
"Use this field if you would like Permalink Manager to use the actual titles "
…
…
1494
1473
msgstr "Permalink Managerで、ネイティブ スラッグの代わりに実際のタイトルを使用する場合は、このフィールドを使用します。"
1495
1474
1496
#: includes/views/permalink-manager-uri-editor-tax.php:101
1497
#: includes/views/permalink-manager-uri-editor-post.php:121
1498
#: includes/views/permalink-manager-uri-editor-post.php:121
1475
#: includes/views/permalink-manager-uri-editor-tax.php:104
1476
#: includes/views/permalink-manager-uri-editor-post.php:132
1477
#: includes/views/permalink-manager-uri-editor-post.php:132
1499
1478
msgid "View"
1500
1479
msgstr "見る"
1501
1480
1502
#: includes/views/permalink-manager-permastructs.php:46
1481
#: includes/views/permalink-manager-permastructs.php:55
1503
1482
msgid "WooCommerce"
1504
1483
msgstr "WooCommerce"
1505
1484
1506
#: includes/views/permalink-manager-settings.php:196
1485
#: includes/views/permalink-manager-settings.php:167
1507
1486
msgid "WP All Import/Export support"
1508
1487
msgstr ""
1509
1488
1510
#: includes/views/permalink-manager-settings.php:189
1489
#: includes/views/permalink-manager-settings.php:160
1511
1490
msgid "WPML compatibility functions"
1512
1491
msgstr ""
1513
1492
1514
#: includes/views/permalink-manager-settings.php:182
1493
#: includes/views/permalink-manager-settings.php:153
1515
1494
msgid "WPML/Polylang language mismatch"
1516
1495
msgstr "WPML / Polylang 言語 不一致"
1517
1496
1518
#: includes/views/permalink-manager-settings.php:245
1519
#: includes/views/permalink-manager-settings.php:252
1497
#: includes/views/permalink-manager-settings.php:216
1498
#: includes/views/permalink-manager-settings.php:223
1520
1499
msgid "Yes, use native settings"
1521
1500
msgstr "はい、ネイティブ 設定を使います。"
1522
1501
1523
#: includes/core/permalink-manager-actions.php:413
1524
#: includes/core/permalink-manager-actions.php:419
1502
#: includes/core/permalink-manager-actions.php:81
1503
#: includes/core/permalink-manager-actions.php:498
1525
1504
msgid "You are not allowed to remove Permalink Manager data!"
1526
1505
msgstr "Permalink Manager データを削除できません!"
1527
1506
1528
#: includes/views/permalink-manager-settings.php:170
1507
#: includes/views/permalink-manager-settings.php:142
1529
1508
msgid ""
1530
1509
"You can disable this feature if you do not want Permalink Manager to trigger "
…
…
1532
1511
msgstr "Permalink Managerに、追加のリダイレクト機能を一切トリガーさせないようにする場合は、この機能を無効にします。"
1533
1512
1534
#: includes/views/permalink-manager-settings.php:122
1513
#: includes/views/permalink-manager-settings.php:109
1535
1514
msgid ""
1536
1515
"You can disable this feature if you use another plugin to control the "
…
…
1538
1517
msgstr ""
1539
1518
1540
#: includes/core/permalink-manager-pro-functions.php:170
1519
#: includes/views/permalink-manager-settings.php:64
1520
#, fuzzy
1521
#| msgid ""
1522
#| "<strong>You can use this feature to either add or remove the slases from "
1523
#| "end of WordPress permalinks.</strong>"
1524
msgid ""
1525
"You can use this feature to either add or remove the slashes from end of "
1526
"WordPress permalinks."
1527
msgstr "<strong>この機能で、WordPressパーマリンクの末尾にスラッシュを追加または削除できます。</strong>"
1528
1529
#: includes/core/permalink-manager-pro-functions.php:178
1541
1530
msgid "You own a lifetime licence key."
1542
1531
msgstr "あなたは、永久ライセンスキーをお持ちです。"
1543
1532
1544
#: includes/core/permalink-manager-pro-functions.php:183
1533
#: includes/core/permalink-manager-pro-functions.php:189
1545
1534
#, php-format
1546
1535
msgid ""
…
…
1551
1540
"コチラのページ</a>にアクセスして詳細を確認して下さい。"
1552
1541
1553
#: includes/core/permalink-manager-pro-functions.php:159
1542
#: includes/core/permalink-manager-pro-functions.php:169
1554
1543
#, php-format
1555
1544
msgid ""
…
…
1559
1548
msgstr ""
1560
1549
1561
#: includes/core/permalink-manager-pro-functions.php:154
1550
#: includes/core/permalink-manager-pro-functions.php:165
1562
1551
msgid "Your Permalink Manager Pro licence key is invalid!"
1563
1552
msgstr "あなたのライセンスキーは、無効です!"
1564
1553
1565
#: includes/core/permalink-manager-pro-functions.php:164
1554
#: includes/core/permalink-manager-pro-functions.php:173
1566
1555
msgid ""
1567
1556
"Your Permalink Manager Pro license is already in use on another website and "
permalink-manager/trunk/languages/permalink-manager.pot
r2796526
r2833667
4
4
"Project-Id-Version: PACKAGE VERSION\\n"
5
5
"Report-Msgid-Bugs-To: \\n"
6
"POT-Creation-Date: 2022-10-06 19:13+0000\\n"
6
"POT-Creation-Date: 2022-12-13 23:31+0000\\n"
7
7
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
8
8
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
…
…
15
15
"X-Generator: Loco https://localise.biz/"
16
16
17
#: includes/views/permalink-manager-pro-addons.php:266
17
#: includes/views/permalink-manager-pro-addons.php:284
18
18
msgid ""
19
19
" Please send your remarks to <a href=\\"mailto:[email protected]\\">"
…
…
21
21
msgstr ""
22
22
23
#: includes/core/permalink-manager-third-parties.php:353
23
#: includes/core/permalink-manager-third-parties.php:367
24
24
msgid "\\"Custom Permalinks\\" URIs were imported!"
25
25
msgstr ""
26
26
27
#: includes/views/permalink-manager-settings.php:233
27
#: includes/views/permalink-manager-settings.php:204
28
28
msgid "\\"Exclude content types\\" strict mode"
29
29
msgstr ""
30
30
31
#: includes/views/permalink-manager-settings.php:216
31
#: includes/views/permalink-manager-settings.php:187
32
32
msgid "\\"Primary category\\" support"
33
33
msgstr ""
34
34
35
#: includes/views/permalink-manager-pro-addons.php:189
35
#: includes/views/permalink-manager-pro-addons.php:202
36
36
msgid "\\"Stop words\\" list"
37
37
msgstr ""
38
38
39
#: includes/core/permalink-manager-actions.php:399
39
#: includes/core/permalink-manager-actions.php:147
40
40
#, php-format
41
41
msgid "%d Custom URIs and %d Custom Redirects were removed!"
42
42
msgstr ""
43
43
44
#: includes/core/permalink-manager-actions.php:453
44
#: includes/core/permalink-manager-actions.php:533
45
45
#, php-format
46
46
msgid "%s were removed!"
47
47
msgstr ""
48
48
49
#: includes/views/permalink-manager-tools.php:97
49
#: includes/views/permalink-manager-tools.php:117
50
50
msgid "(Removed post)"
51
51
msgstr ""
52
52
53
#: includes/views/permalink-manager-tools.php:84
53
#: includes/views/permalink-manager-tools.php:105
54
54
msgid "(Removed term)"
55
55
msgstr ""
56
56
57
#: includes/views/permalink-manager-pro-addons.php:170
57
#: includes/views/permalink-manager-pro-addons.php:183
58
58
msgid "-- Use predefined words list --"
59
59
msgstr ""
60
60
61
#: includes/views/permalink-manager-settings.php:167
61
#: includes/views/permalink-manager-settings.php:141
62
62
msgid "301 redirect"
63
63
msgstr ""
64
64
65
#: includes/views/permalink-manager-settings.php:167
65
#: includes/views/permalink-manager-settings.php:141
66
66
msgid "302 redirect"
67
67
msgstr ""
68
68
69
#: includes/core/permalink-manager-admin-functions.php:749
69
#: includes/core/permalink-manager-admin-functions.php:776
70
70
#, php-format
71
71
msgid "<a %s>Click here</a> to go to the list of updated slugs"
72
72
msgstr ""
73
73
74
#: includes/core/permalink-manager-admin-functions.php:748
74
#: includes/core/permalink-manager-admin-functions.php:775
75
75
#, php-format
76
76
msgid "<strong class=\\"updated\_count\\">%d</strong> slug was updated!"
…
…
79
79
msgstr\[1\] ""
80
80
81
#: includes/views/permalink-manager-tools.php:44
81
#: includes/views/permalink-manager-tools.php:55
82
82
msgid ""
83
83
"<strong>A MySQL backup is highly recommended before using \\"<em>Native "
…
…
85
85
msgstr ""
86
86
87
#: includes/views/permalink-manager-settings.php:93
87
#: includes/views/permalink-manager-settings.php:88
88
88
msgid ""
89
89
"<strong>Canonical redirect allows WordPress to \\"correct\\" the requested URL "
…
…
91
91
msgstr ""
92
92
93
#: includes/core/permalink-manager-actions.php:147
93
#: includes/core/permalink-manager-actions.php:577
94
94
msgid "<strong>No post status</strong> selected!"
95
95
msgstr ""
96
96
97
#: includes/core/permalink-manager-actions.php:141
97
#: includes/core/permalink-manager-actions.php:571
98
98
msgid "<strong>No post type</strong> selected!"
99
99
msgstr ""
100
100
101
#: includes/core/permalink-manager-actions.php:116
102
#: includes/core/permalink-manager-admin-functions.php:753
101
#: includes/core/permalink-manager-actions.php:545
102
#: includes/core/permalink-manager-admin-functions.php:780
103
103
msgid "<strong>No slugs</strong> were updated!"
104
104
msgstr ""
105
105
106
#: includes/core/permalink-manager-actions.php:133
106
#: includes/core/permalink-manager-actions.php:563
107
107
msgid "<strong>No taxonomy</strong> selected!"
108
108
msgstr ""
109
109
110
#: includes/views/permalink-manager-settings.php:110
110
#: includes/views/permalink-manager-settings.php:101
111
111
msgid ""
112
112
"<strong>Old slug redirect is used by WordPress to provide a fallback for old "
…
…
114
114
msgstr ""
115
115
116
#: includes/views/permalink-manager-settings.php:43
116
#: includes/views/permalink-manager-settings.php:50
117
117
msgid ""
118
118
"<strong>Permalink Manager can automatically update the custom permalink "
…
…
120
120
msgstr ""
121
121
122
#: includes/views/permalink-manager-settings.php:54
122
#: includes/views/permalink-manager-settings.php:57
123
123
msgid ""
124
124
"<strong>Permalink Manager can use either native slugs or actual titles for "
…
…
126
126
msgstr ""
127
127
128
#: includes/views/permalink-manager-pro-addons.php:333
128
#: includes/views/permalink-manager-pro-addons.php:339
129
129
msgid ""
130
130
"<strong>Please use full URLs!</strong><br />For instance, <code>http:"
…
…
132
132
msgstr ""
133
133
134
#: includes/views/permalink-manager-pro-addons.php:315
134
#: includes/views/permalink-manager-pro-addons.php:324
135
135
#, php-format
136
136
msgid ""
…
…
139
139
msgstr ""
140
140
141
#: includes/views/permalink-manager-settings.php:159
141
#: includes/views/permalink-manager-settings.php:135
142
142
msgid ""
143
143
"<strong>You can use Permalink Manager to force SSL or \\"www\\" prefix in "
…
…
145
145
msgstr ""
146
146
147
#: includes/views/permalink-manager-settings.php:66
148
msgid ""
149
"<strong>You can use this feature to either add or remove the slases from end "
150
"of WordPress permalinks.</strong>"
151
msgstr ""
152
153
#: includes/views/permalink-manager-pro-addons.php:310
147
#: includes/views/permalink-manager-pro-addons.php:320
154
148
msgid "Add new redirect"
155
149
msgstr ""
156
150
157
#: includes/views/permalink-manager-pro-addons.php:175
151
#: includes/views/permalink-manager-pro-addons.php:188
158
152
msgid "Add the words from the list"
159
153
msgstr ""
…
…
163
157
msgstr ""
164
158
165
#: includes/views/permalink-manager-settings.php:258
159
#: includes/views/permalink-manager-settings.php:229
166
160
msgid "Administrator (edit\_theme\_options)"
167
161
msgstr ""
…
…
169
163
#. Description of the plugin
170
164
msgid ""
171
"Advanced plugin that allows to set\-up custom permalinks (bulk editors "
165
"Advanced plugin that allows to set up custom permalinks (bulk editors "
172
166
"included), slugs and permastructures (WooCommerce compatible)."
173
167
msgstr ""
174
168
175
#: includes/views/permalink-manager-settings.php:223
169
#: includes/views/permalink-manager-settings.php:194
176
170
msgid "Advanced settings"
177
171
msgstr ""
178
172
179
#: includes/views/permalink-manager-permastructs.php:83
173
#: includes/views/permalink-manager-permastructs.php:92
180
174
#, php-format
181
175
msgid ""
…
…
185
179
msgstr ""
186
180
187
#: includes/views/permalink-manager-uri-editor-post.php:174
181
#: includes/views/permalink-manager-uri-editor-post.php:173
188
182
msgid "All dates"
189
183
msgstr ""
190
184
191
#: includes/views/permalink-manager-pro-addons.php:287
185
#: includes/views/permalink-manager-pro-addons.php:305
192
186
msgid ""
193
187
"All URIs specified below will redirect the visitors to the custom URI "
…
…
195
189
msgstr ""
196
190
197
#: includes/views/permalink-manager-uri-editor.php:83
191
#: includes/views/permalink-manager-uri-editor.php:91
198
192
msgid "Apply"
199
193
msgstr ""
200
194
201
#: includes/core/permalink-manager-pro-functions.php:247
195
#: includes/core/permalink-manager-pro-functions.php:257
202
196
msgid "Arabic"
203
197
msgstr ""
204
198
205
#: includes/core/permalink-manager-admin-functions.php:134
199
#: includes/core/permalink-manager-admin-functions.php:136
206
200
msgid "Are you sure? This action cannot be undone!"
207
201
msgstr ""
208
202
209
#: includes/views/permalink-manager-debug.php:69
203
#: includes/views/permalink-manager-debug.php:72
210
204
msgid "Array with external redirects"
211
205
msgstr ""
212
206
213
#: includes/views/permalink-manager-debug.php:80
207
#: includes/views/permalink-manager-debug.php:79
214
208
msgid "Array with permastructures"
215
209
msgstr ""
216
210
211
#: includes/views/permalink-manager-debug.php:65
212
msgid "Array with redirects"
213
msgstr ""
214
215
#: includes/views/permalink-manager-debug.php:86
216
msgid "Array with settings used in this plugin."
217
msgstr ""
218
217
219
#: includes/views/permalink-manager-debug.php:58
218
msgid "Array with redirects"
219
msgstr ""
220
221
#: includes/views/permalink-manager-debug.php:91
222
msgid "Array with settings used in this plugin."
223
msgstr ""
224
225
#: includes/views/permalink-manager-debug.php:47
226
220
msgid "Array with URIs"
227
221
msgstr ""
228
222
229
#: includes/views/permalink-manager-settings.php:258
223
#: includes/views/permalink-manager-settings.php:229
230
224
msgid "Author (publish\_posts)"
231
225
msgstr ""
232
226
233
#: includes/core/permalink-manager-admin-functions.php:859
234
#: includes/core/permalink-manager-admin-functions.php:871
227
#: includes/core/permalink-manager-admin-functions.php:893
228
#: includes/core/permalink-manager-admin-functions.php:905
235
229
msgid "Auto-update \\"Current URI\\""
236
230
msgstr ""
237
231
238
#: includes/views/permalink-manager-settings.php:41
232
#: includes/views/permalink-manager-settings.php:49
239
233
msgid "Auto-update permalinks"
240
234
msgstr ""
241
235
242
#: includes/core/permalink-manager-admin-functions.php:947
236
#: includes/core/permalink-manager-admin-functions.php:964
243
237
msgid "Automatic redirect for native URI enabled:"
244
238
msgstr ""
245
239
246
#: includes/views/permalink-manager-settings.php:263
240
#: includes/views/permalink-manager-settings.php:234
247
241
msgid "Automatically fix broken URIs"
248
242
msgstr ""
249
243
250
#: includes/views/permalink-manager-settings.php:210
244
#: includes/views/permalink-manager-settings.php:181
251
245
msgid "Breadcrumbs support"
252
246
msgstr ""
253
247
254
#: includes/core/permalink-manager-actions.php:609
248
#: includes/core/permalink-manager-actions.php:347
255
249
msgid "Broken redirects were removed successfully!"
256
250
msgstr ""
257
251
258
#: includes/views/permalink-manager-settings.php:265
252
#: includes/views/permalink-manager-settings.php:236
259
253
msgid "Bulk fix all URIs (once a day, in the background)"
260
254
msgstr ""
261
255
262
#: includes/core/permalink-manager-admin-functions.php:172
256
#: includes/core/permalink-manager-admin-functions.php:187
263
257
msgid "Buy Permalink Manager Pro"
264
258
msgstr ""
265
259
266
#: includes/core/permalink-manager-admin-functions.php:616
260
#: includes/core/permalink-manager-admin-functions.php:634
267
261
msgid "by Maciej Bis"
268
262
msgstr ""
269
263
270
#: includes/views/permalink-manager-settings.php:90
264
#: includes/views/permalink-manager-settings.php:86
271
265
msgid "Canonical redirect"
272
266
msgstr ""
273
267
274
#: includes/core/permalink-manager-pro-functions.php:248
268
#: includes/core/permalink-manager-pro-functions.php:258
275
269
msgid "Chinese"
276
270
msgstr ""
277
271
278
#: includes/core/permalink-manager-uri-functions-tax.php:520
272
#: includes/core/permalink-manager-uri-functions-tax.php:561
279
273
msgid "Clear/leave the field empty to use the default permalink."
280
274
msgstr ""
281
275
282
#: includes/core/permalink-manager-admin-functions.php:887
276
#: includes/core/permalink-manager-admin-functions.php:921
283
277
msgid "Close: "
284
278
msgstr ""
285
279
286
#: includes/views/permalink-manager-tools.php:120
280
#: includes/views/permalink-manager-tools.php:132
287
281
msgid "Congratulations! No duplicated URIs or Redirects found!"
288
282
msgstr ""
289
283
290
#: includes/views/permalink-manager-settings.php:258
284
#: includes/views/permalink-manager-settings.php:229
291
285
msgid "Contributor (edit\_posts)"
292
286
msgstr ""
293
287
294
#: includes/views/permalink-manager-settings.php:250
288
#: includes/views/permalink-manager-settings.php:221
295
289
msgid "Convert accented letters"
296
290
msgstr ""
297
291
298
#: includes/views/permalink-manager-uri-editor-tax.php:53
292
#: includes/views/permalink-manager-uri-editor-tax.php:59
299
293
msgid "Count"
300
294
msgstr ""
301
295
302
#: includes/core/permalink-manager-pro-functions.php:566
296
#: includes/core/permalink-manager-pro-functions.php:622
303
297
msgid "Coupon Full URL"
304
298
msgstr ""
305
299
306
#: includes/core/permalink-manager-pro-functions.php:533
300
#: includes/core/permalink-manager-pro-functions.php:586
307
301
msgid "Coupon Link"
308
302
msgstr ""
309
303
310
#: includes/core/permalink-manager-pro-functions.php:554
304
#: includes/core/permalink-manager-pro-functions.php:610
311
305
msgid "Coupon URI"
312
306
msgstr ""
313
307
314
#: includes/core/permalink-manager-uri-functions-post.php:711
315
#: includes/core/permalink-manager-uri-functions-tax.php:552
316
#: includes/core/permalink-manager-admin-functions.php:795
317
#: includes/core/permalink-manager-admin-functions.php:906
308
#: includes/core/permalink-manager-uri-functions-post.php:777
309
#: includes/core/permalink-manager-uri-functions-tax.php:594
310
#: includes/core/permalink-manager-admin-functions.php:821
311
#: includes/core/permalink-manager-admin-functions.php:939
318
312
msgid "Current URI"
319
313
msgstr ""
320
314
321
#: includes/views/permalink-manager-tools.php:34
322
#: includes/views/permalink-manager-pro-addons.php:225
315
#: includes/views/permalink-manager-tools.php:40
316
#: includes/views/permalink-manager-pro-addons.php:241
323
317
msgid "Custom Permalinks"
324
318
msgstr ""
325
319
326
#: includes/core/permalink-manager-actions.php:426
320
#: includes/core/permalink-manager-actions.php:504
327
321
msgid "Custom permalinks"
328
322
msgstr ""
329
323
330
#: includes/core/permalink-manager-actions.php:430
324
#: includes/core/permalink-manager-actions.php:508
331
325
msgid "Custom redirects"
332
326
msgstr ""
333
327
334
#: includes/views/permalink-manager-tools.php:70
335
#: includes/core/permalink-manager-third-parties.php:485
336
#: includes/core/permalink-manager-third-parties.php:852
337
#: includes/core/permalink-manager-uri-functions-tax.php:519
328
#: includes/views/permalink-manager-tools.php:91
329
#: includes/core/permalink-manager-third-parties.php:534
330
#: includes/core/permalink-manager-third-parties.php:963
331
#: includes/core/permalink-manager-uri-functions-tax.php:560
338
332
msgid "Custom URI"
339
333
msgstr ""
340
334
341
#: includes/views/permalink-manager-tools.php:150
335
#: includes/views/permalink-manager-tools.php:167
342
336
msgid "Custom URIs"
343
337
msgstr ""
344
338
345
#: includes/core/permalink-manager-pro-functions.php:249
339
#: includes/core/permalink-manager-pro-functions.php:259
346
340
msgid "Danish"
347
341
msgstr ""
348
342
349
#: includes/views/permalink-manager-pro-addons.php:226
343
#: includes/views/permalink-manager-pro-addons.php:242
350
344
msgid "Deactivate after import"
351
345
msgstr ""
352
346
353
#: includes/views/permalink-manager-debug.php:14
347
#: includes/views/permalink-manager-debug.php:21
354
348
msgid "Debug"
355
349
msgstr ""
356
350
357
#: includes/views/permalink-manager-debug.php:38
351
#: includes/views/permalink-manager-debug.php:53
358
352
msgid "Debug data"
359
353
msgstr ""
360
354
361
#: includes/core/permalink-manager-admin-functions.php:423
355
#: includes/core/permalink-manager-admin-functions.php:437
362
356
msgid "Default permastructure"
363
357
msgstr ""
364
358
365
#: includes/core/permalink-manager-admin-functions.php:936
359
#: includes/core/permalink-manager-admin-functions.php:957
366
360
msgid "Default URI"
367
361
msgstr ""
368
362
369
#: includes/views/permalink-manager-settings.php:167
363
#: includes/views/permalink-manager-settings.php:141
370
364
msgid "Disable (Permalink Manager redirect functions)"
371
365
msgstr ""
372
366
373
#: includes/core/permalink-manager-admin-functions.php:861
367
#: includes/core/permalink-manager-admin-functions.php:895
374
368
msgid "Disable URI Editor"
375
369
msgstr ""
376
370
377
#: includes/views/permalink-manager-settings.php:41
378
#: includes/core/permalink-manager-admin-functions.php:873
371
#: includes/views/permalink-manager-settings.php:49
372
#: includes/core/permalink-manager-admin-functions.php:907
379
373
msgid "Disable URI Editor to disallow permalink changes"
380
374
msgstr ""
381
375
382
#: includes/core/permalink-manager-admin-functions.php:431
376
#: includes/core/permalink-manager-admin-functions.php:440
383
377
msgid "Do not automatically append the slug"
384
378
msgstr ""
385
379
386
#: includes/core/permalink-manager-admin-functions.php:168
380
#: includes/core/permalink-manager-admin-functions.php:183
387
381
msgid "Documentation"
388
382
msgstr ""
389
383
390
#: includes/core/permalink-manager-admin-functions.php:863
391
#: includes/core/permalink-manager-admin-functions.php:869
384
#: includes/core/permalink-manager-admin-functions.php:897
385
#: includes/core/permalink-manager-admin-functions.php:903
392
386
msgid "Don't auto-update \\"Current URI\\""
393
387
msgstr ""
394
388
395
#: includes/core/permalink-manager-admin-functions.php:870
389
#: includes/core/permalink-manager-admin-functions.php:904
396
390
msgid ""
397
391
"Don't auto-update \\"Current URI\\" and exclude from the \\"Regenerate/reset\\" "
…
…
399
393
msgstr ""
400
394
401
#: includes/views/permalink-manager-settings.php:41
395
#: includes/views/permalink-manager-settings.php:49
402
396
msgid "Don't auto-update permalinks (default mode)"
403
397
msgstr ""
404
398
405
#: includes/core/permalink-manager-pro-functions.php:250
399
#: includes/core/permalink-manager-pro-functions.php:260
406
400
msgid "Dutch"
407
401
msgstr ""
408
402
409
#: includes/views/permalink-manager-pro-addons.php:203
403
#: includes/views/permalink-manager-pro-addons.php:216
410
404
msgid ""
411
405
"Each of the words can be removed and any new words can be added to the list. "
…
…
413
407
msgstr ""
414
408
415
#: includes/views/permalink-manager-uri-editor-tax.php:100
416
#: includes/views/permalink-manager-uri-editor-post.php:120
417
#: includes/views/permalink-manager-uri-editor-post.php:120
409
#: includes/views/permalink-manager-uri-editor-tax.php:103
410
#: includes/views/permalink-manager-uri-editor-post.php:131
411
#: includes/views/permalink-manager-uri-editor-post.php:131
418
412
msgid "Edit"
419
413
msgstr ""
420
414
421
#: includes/views/permalink-manager-tools.php:94
415
#: includes/views/permalink-manager-tools.php:114
422
416
msgid "Edit post"
423
417
msgstr ""
424
418
425
#: includes/views/permalink-manager-tools.php:81
419
#: includes/views/permalink-manager-tools.php:102
426
420
msgid "Edit term"
427
421
msgstr ""
428
422
429
#: includes/views/permalink-manager-settings.php:258
423
#: includes/views/permalink-manager-settings.php:229
430
424
msgid "Editor (publish\_pages)"
431
425
msgstr ""
432
426
433
#: includes/views/permalink-manager-pro-addons.php:183
427
#: includes/views/permalink-manager-pro-addons.php:196
434
428
msgid "Enable \\"stop words\\""
435
429
msgstr ""
436
430
437
#: includes/views/permalink-manager-settings.php:267
431
#: includes/views/permalink-manager-settings.php:237
438
432
msgid ""
439
433
"Enable this option if you would like to automatically remove redundant "
…
…
441
435
msgstr ""
442
436
443
#: includes/core/permalink-manager-pro-functions.php:251
437
#: includes/core/permalink-manager-pro-functions.php:261
444
438
msgid "English"
445
439
msgstr ""
446
440
447
#: includes/views/permalink-manager-settings.php:151
441
#: includes/views/permalink-manager-settings.php:129
448
442
msgid ""
449
443
"Example: <em>https://example.com/product/old-product-url/<strong>?discount-"
…
…
452
446
msgstr ""
453
447
454
#: includes/views/permalink-manager-settings.php:72
448
#: includes/views/permalink-manager-settings.php:68
455
449
msgid "Exclude content types"
456
450
msgstr ""
457
451
458
#: includes/views/permalink-manager-settings.php:78
452
#: includes/views/permalink-manager-settings.php:74
459
453
msgid "Exclude drafts"
460
454
msgstr ""
461
455
462
#: includes/core/permalink-manager-pro-functions.php:189
456
#: includes/core/permalink-manager-pro-functions.php:194
463
457
msgid ""
464
458
"Expiration date could not be downloaded at this moment. Please try again in "
…
…
466
460
msgstr ""
467
461
468
#: includes/core/permalink-manager-actions.php:434
462
#: includes/core/permalink-manager-actions.php:512
469
463
msgid "External redirects"
470
464
msgstr ""
471
465
472
#: includes/views/permalink-manager-tools.php:70
466
#: includes/views/permalink-manager-tools.php:91
473
467
msgid "Extra Redirect"
474
468
msgstr ""
475
469
476
#: includes/views/permalink-manager-settings.php:116
477
#: includes/views/permalink-manager-pro-addons.php:286
470
#: includes/views/permalink-manager-settings.php:105
471
#: includes/views/permalink-manager-pro-addons.php:305
478
472
msgid "Extra redirects (aliases)"
479
473
msgstr ""
480
474
481
#: includes/views/permalink-manager-uri-editor-post.php:183
475
#: includes/views/permalink-manager-uri-editor-post.php:182
482
476
msgid "Filter"
483
477
msgstr ""
484
478
485
#: includes/views/permalink-manager-tools.php:22
479
#: includes/views/permalink-manager-tools.php:28
486
480
msgid "Find & Replace"
487
481
msgstr ""
488
482
489
#: includes/views/permalink-manager-tools.php:134
483
#: includes/views/permalink-manager-tools.php:151
490
484
msgid "Find ..."
491
485
msgstr ""
492
486
493
#: includes/views/permalink-manager-tools.php:209
487
#: includes/views/permalink-manager-tools.php:226
494
488
msgid "Find and replace"
495
489
msgstr ""
496
490
497
#: includes/core/permalink-manager-pro-functions.php:252
491
#: includes/core/permalink-manager-pro-functions.php:262
498
492
msgid "Finnish"
499
493
msgstr ""
500
494
501
#: includes/views/permalink-manager-tools.php:55
495
#: includes/views/permalink-manager-tools.php:76
502
496
msgid "Fix custom permalinks & redirects"
503
497
msgstr ""
504
498
505
#: includes/views/permalink-manager-settings.php:265
499
#: includes/views/permalink-manager-settings.php:236
506
500
msgid "Fix URIs individually (during page load)"
507
501
msgstr ""
508
502
509
#: includes/views/permalink-manager-settings.php:238
503
#: includes/views/permalink-manager-settings.php:209
510
504
msgid "Force 404 on non-existing pagination pages"
511
505
msgstr ""
512
506
513
#: includes/views/permalink-manager-settings.php:156
507
#: includes/views/permalink-manager-settings.php:133
514
508
msgid "Force HTTPS/WWW"
515
509
msgstr ""
516
510
517
#: includes/core/permalink-manager-pro-functions.php:253
511
#: includes/core/permalink-manager-pro-functions.php:263
518
512
msgid "French"
519
513
msgstr ""
520
514
521
#: includes/views/permalink-manager-uri-editor-tax.php:52
522
#: includes/views/permalink-manager-uri-editor-post.php:56
515
#: includes/views/permalink-manager-uri-editor-tax.php:58
516
#: includes/views/permalink-manager-uri-editor-post.php:63
523
517
msgid "Full URI & Permalink"
524
518
msgstr ""
525
519
526
#: includes/views/permalink-manager-settings.php:33
520
#: includes/views/permalink-manager-settings.php:41
527
521
msgid "General settings"
528
522
msgstr ""
529
523
530
#: includes/core/permalink-manager-pro-functions.php:254
524
#: includes/core/permalink-manager-pro-functions.php:264
531
525
msgid "German"
532
526
msgstr ""
533
527
534
#: permalink-manager.php:216
535
#, php-format
536
msgid ""
537
"Get access to extra features: full taxonomy and WooCommerce support, "
538
"possibility to use custom fields inside the permalinks and more!<br />"
539
"<strong>Buy Permalink Manager Pro <a href=\\"%s\\" target=\\"\_blank\\">here</a> "
540
"and save %s using \\"%s\\" coupon code!</strong> Valid until %s!"
541
msgstr ""
542
543
#: includes/views/permalink-manager-pro-addons.php:139
528
#: includes/views/permalink-manager-pro-addons.php:153
544
529
msgid "Get license information"
545
530
msgstr ""
546
531
547
#: includes/core/permalink-manager-pro-functions.php:255
532
#: includes/core/permalink-manager-pro-functions.php:265
548
533
msgid "Hebrew"
549
534
msgstr ""
550
535
551
#: includes/core/permalink-manager-pro-functions.php:256
536
#: includes/core/permalink-manager-pro-functions.php:266
552
537
msgid "Hindi"
553
538
msgstr ""
554
539
555
#: includes/views/permalink-manager-pro-addons.php:329
540
#: includes/views/permalink-manager-pro-addons.php:335
556
541
msgid "http://another-website.com/final-target-url"
557
542
msgstr ""
…
…
565
550
msgstr ""
566
551
567
#: includes/core/permalink-manager-admin-functions.php:915
552
#: includes/core/permalink-manager-admin-functions.php:944
568
553
msgid ""
569
554
"If 'auto-update mode' is turned on, the 'Current URI' field will be "
…
…
572
557
msgstr ""
573
558
574
#: includes/views/permalink-manager-settings.php:199
559
#: includes/views/permalink-manager-settings.php:170
575
560
msgid ""
576
561
"If disabled, the custom permalinks <strong>will not be saved</strong> for "
…
…
578
563
msgstr ""
579
564
580
#: includes/core/permalink-manager-third-parties.php:853
565
#: includes/core/permalink-manager-third-parties.php:964
581
566
#, php-format
582
567
msgid ""
…
…
585
570
msgstr ""
586
571
587
#: includes/views/permalink-manager-settings.php:246
572
#: includes/views/permalink-manager-settings.php:217
588
573
msgid ""
589
574
"If enabled only alphanumeric characters, underscores and dashes will be "
…
…
591
576
msgstr ""
592
577
593
#: includes/views/permalink-manager-pro-addons.php:202
578
#: includes/views/permalink-manager-pro-addons.php:215
594
579
msgid ""
595
580
"If enabled, all selected \\"stop words\\" will be automatically removed from "
…
…
597
582
msgstr ""
598
583
599
#: includes/views/permalink-manager-settings.php:253
584
#: includes/views/permalink-manager-settings.php:224
600
585
msgid ""
601
586
"If enabled, all the accented letters will be replaced with their non-"
…
…
603
588
msgstr ""
604
589
605
#: includes/views/permalink-manager-settings.php:44
590
#: includes/views/permalink-manager-settings.php:50
606
591
msgid ""
607
592
"If enabled, Permalink Manager will always force the default custom permalink "
…
…
609
594
msgstr ""
610
595
611
#: includes/views/permalink-manager-settings.php:206
596
#: includes/views/permalink-manager-settings.php:177
612
597
msgid ""
613
598
"If enabled, Permalink Manager will detect the additional Ultimate Member "
…
…
615
600
msgstr ""
616
601
617
#: includes/views/permalink-manager-settings.php:132
602
#: includes/views/permalink-manager-settings.php:117
618
603
msgid ""
619
604
"If enabled, Permalink Manager will save the \\"extra redirect\\" for earlier "
…
…
622
607
msgstr ""
623
608
624
#: includes/views/permalink-manager-settings.php:218
609
#: includes/views/permalink-manager-settings.php:189
625
610
msgid ""
626
611
"If enabled, Permalink Manager will use the \\"primary category\\" for the "
…
…
629
614
msgstr ""
630
615
631
#: includes/views/permalink-manager-settings.php:79
616
#: includes/views/permalink-manager-settings.php:75
632
617
msgid "If enabled, the custom permalinks for post drafts will not be saved."
633
618
msgstr ""
634
619
635
#: includes/views/permalink-manager-settings.php:212
620
#: includes/views/permalink-manager-settings.php:183
636
621
msgid ""
637
622
"If enabled, the HTML breadcrumbs will be filtered by Permalink Manager to "
…
…
640
625
msgstr ""
641
626
642
#: includes/views/permalink-manager-settings.php:239
627
#: includes/views/permalink-manager-settings.php:210
643
628
msgid ""
644
629
"If enabled, the non-existing pagination pages (for single posts) will return "
…
…
647
632
msgstr ""
648
633
649
#: includes/views/permalink-manager-settings.php:185
634
#: includes/views/permalink-manager-settings.php:156
650
635
msgid ""
651
636
"If enabled, the plugin will load the adjacent translation of post when the "
…
…
654
639
msgstr ""
655
640
656
#: includes/views/permalink-manager-settings.php:150
641
#: includes/views/permalink-manager-settings.php:129
657
642
msgid ""
658
643
"If enabled, the query parameters will be copied to the target URL when the "
…
…
660
645
msgstr ""
661
646
662
#: includes/views/permalink-manager-settings.php:111
647
#: includes/views/permalink-manager-settings.php:101
663
648
msgid ""
664
649
"If enabled, the visitors trying to access the URL with the old slug will be "
…
…
666
651
msgstr ""
667
652
668
#: includes/views/permalink-manager-pro-addons.php:325
653
#: includes/views/permalink-manager-pro-addons.php:332
669
654
msgid ""
670
655
"If not empty, the visitors trying to access this page will be redirected to "
…
…
672
657
msgstr ""
673
658
674
#: includes/views/permalink-manager-pro-addons.php:229
659
#: includes/views/permalink-manager-pro-addons.php:245
675
660
msgid ""
676
661
"If selected, \\"Custom Permalinks\\" plugin will be deactivated after its "
…
…
678
663
msgstr ""
679
664
680
#: includes/views/permalink-manager-settings.php:234
665
#: includes/views/permalink-manager-settings.php:205
681
666
msgid ""
682
667
"If this option is enabled, any custom post types and taxonomies with the "
…
…
687
672
msgstr ""
688
673
689
#: includes/views/permalink-manager-pro-addons.php:261
674
#: includes/views/permalink-manager-pro-addons.php:279
690
675
msgid ""
691
676
"If you still did not find the answer to your question, please send us your "
…
…
694
679
msgstr ""
695
680
696
#: includes/views/permalink-manager-pro-addons.php:265
681
#: includes/views/permalink-manager-pro-addons.php:283
697
682
msgid ""
698
683
"If you would like to suggest a new functionality or leave us feedback, we "
…
…
700
685
msgstr ""
701
686
702
#: includes/core/permalink-manager-admin-functions.php:405
687
#: includes/core/permalink-manager-admin-functions.php:422
703
688
msgid ""
704
689
"If you would like to translate the permastructures and set-up different "
…
…
708
693
msgstr ""
709
694
710
#: includes/views/permalink-manager-pro-addons.php:241
695
#: includes/views/permalink-manager-pro-addons.php:257
711
696
#, php-format
712
697
msgid "Import %d URIs"
713
698
msgstr ""
714
699
715
#: includes/views/permalink-manager-tools.php:206
716
#: includes/views/permalink-manager-tools.php:283
700
#: includes/views/permalink-manager-tools.php:223
701
#: includes/views/permalink-manager-tools.php:303
717
702
msgid "Important notices"
718
703
msgstr ""
719
704
720
#: includes/views/permalink-manager-uri-editor-post.php:89
705
#: includes/views/permalink-manager-uri-editor-post.php:97
721
706
msgid "Inherit (Attachment)"
722
707
msgstr ""
723
708
724
#: includes/views/permalink-manager-settings.php:52
709
#: includes/views/permalink-manager-settings.php:56
725
710
msgid "Inherit parents' slugs"
726
711
msgstr ""
727
712
728
#: includes/views/permalink-manager-permastructs.php:75
729
#: includes/views/permalink-manager-pro-addons.php:201
730
#: includes/views/permalink-manager-pro-addons.php:234
713
#: includes/views/permalink-manager-permastructs.php:84
714
#: includes/views/permalink-manager-pro-addons.php:214
715
#: includes/views/permalink-manager-pro-addons.php:250
731
716
msgid "Instructions"
732
717
msgstr ""
733
718
734
#: includes/core/permalink-manager-pro-functions.php:257
719
#: includes/core/permalink-manager-pro-functions.php:267
735
720
msgid "Italian"
736
721
msgstr ""
737
722
738
#: includes/core/permalink-manager-pro-functions.php:258
723
#: includes/core/permalink-manager-pro-functions.php:268
739
724
msgid "Japanese"
740
725
msgstr ""
741
726
742
#: includes/core/permalink-manager-pro-functions.php:259
727
#: includes/core/permalink-manager-pro-functions.php:269
743
728
msgid "Korean"
744
729
msgstr ""
745
730
746
#: includes/views/permalink-manager-pro-addons.php:126
731
#: includes/views/permalink-manager-pro-addons.php:146
747
732
msgid "Licence"
748
733
msgstr ""
749
734
750
#: includes/views/permalink-manager-pro-addons.php:132
735
#: includes/views/permalink-manager-pro-addons.php:152
751
736
msgid "Licence key"
752
737
msgstr ""
753
738
754
#: includes/views/permalink-manager-debug.php:54
739
#: includes/views/permalink-manager-debug.php:64
755
740
msgid "List of custom redirects set-up by this plugin."
756
741
msgstr ""
757
742
758
#: includes/views/permalink-manager-tools.php:54
743
#: includes/views/permalink-manager-tools.php:75
759
744
msgid "List of duplicated permalinks"
760
745
msgstr ""
761
746
762
#: includes/views/permalink-manager-debug.php:65
747
#: includes/views/permalink-manager-debug.php:71
763
748
msgid "List of external redirects set-up by this plugin."
764
749
msgstr ""
765
750
766
#: includes/views/permalink-manager-debug.php:76
751
#: includes/views/permalink-manager-debug.php:78
767
752
msgid "List of permastructures set-up by this plugin."
768
753
msgstr ""
769
754
770
#: includes/views/permalink-manager-debug.php:87
755
#: includes/views/permalink-manager-debug.php:85
771
756
msgid "List of plugin settings."
772
757
msgstr ""
773
758
774
#: includes/views/permalink-manager-debug.php:43
759
#: includes/views/permalink-manager-debug.php:57
775
760
msgid "List of the URIs generated by this plugin."
776
761
msgstr ""
777
762
778
#: includes/core/permalink-manager-admin-functions.php:735
763
#: includes/core/permalink-manager-admin-functions.php:762
779
764
msgid "List of updated items"
780
765
msgstr ""
…
…
784
769
msgstr ""
785
770
786
#: includes/core/permalink-manager-admin-functions.php:988
771
#: includes/core/permalink-manager-admin-functions.php:998
787
772
msgid "Manage redirects"
788
773
msgstr ""
789
774
790
#: includes/views/permalink-manager-tools.php:146
791
#: includes/views/permalink-manager-tools.php:222
775
#: includes/views/permalink-manager-tools.php:163
776
#: includes/views/permalink-manager-tools.php:242
792
777
msgid "Mode"
793
778
msgstr ""
794
779
795
#: includes/core/permalink-manager-admin-functions.php:926
780
#: includes/core/permalink-manager-admin-functions.php:952
796
781
msgid "Native slug"
797
782
msgstr ""
798
783
799
#: includes/views/permalink-manager-tools.php:151
784
#: includes/views/permalink-manager-tools.php:168
800
785
msgid "Native slugs"
801
786
msgstr ""
802
787
803
#: includes/core/permalink-manager-admin-functions.php:698
788
#: includes/core/permalink-manager-admin-functions.php:722
789
#: includes/core/permalink-manager-admin-functions.php:752
790
msgid "New Slug"
791
msgstr ""
792
804
793
#: includes/core/permalink-manager-admin-functions.php:725
805
msgid "New Slug"
806
msgstr ""
807
808
#: includes/core/permalink-manager-admin-functions.php:701
809
#: includes/core/permalink-manager-admin-functions.php:728
794
#: includes/core/permalink-manager-admin-functions.php:755
810
795
msgid "New URI"
811
796
msgstr ""
812
797
813
#: includes/views/permalink-manager-settings.php:265
798
#: includes/views/permalink-manager-settings.php:236
814
799
msgid "No"
815
800
msgstr ""
816
801
817
#: includes/core/permalink-manager-third-parties.php:356
802
#: includes/core/permalink-manager-third-parties.php:370
818
803
msgid "No \\"Custom Permalinks\\" URIs were imported!"
819
804
msgstr ""
820
805
821
#: includes/core/permalink-manager-actions.php:401
806
#: includes/core/permalink-manager-actions.php:149
822
807
msgid "No Custom URIs or Custom Redirects were removed!"
823
808
msgstr ""
824
809
825
#: includes/views/permalink-manager-pro-addons.php:246
810
#: includes/views/permalink-manager-pro-addons.php:262
826
811
msgid "No custom URIs to import"
827
812
msgstr ""
828
813
829
#: includes/views/permalink-manager-settings.php:252
814
#: includes/views/permalink-manager-settings.php:223
830
815
msgid "No, keep accented letters in the slugs"
831
816
msgstr ""
832
817
833
#: includes/views/permalink-manager-settings.php:245
818
#: includes/views/permalink-manager-settings.php:216
834
819
msgid "No, keep special characters (.,|\_+) in the slugs"
835
820
msgstr ""
836
821
837
#: includes/core/permalink-manager-pro-functions.php:260
822
#: includes/core/permalink-manager-pro-functions.php:270
838
823
msgid "Norwegian"
839
824
msgstr ""
840
825
841
#: includes/core/permalink-manager-admin-functions.php:697
826
#: includes/core/permalink-manager-admin-functions.php:721
827
#: includes/core/permalink-manager-admin-functions.php:751
828
msgid "Old Slug"
829
msgstr ""
830
831
#: includes/views/permalink-manager-settings.php:99
832
msgid "Old slug redirect"
833
msgstr ""
834
842
835
#: includes/core/permalink-manager-admin-functions.php:724
843
msgid "Old Slug"
844
msgstr ""
845
846
#: includes/views/permalink-manager-settings.php:107
847
msgid "Old slug redirect"
848
msgstr ""
849
850
#: includes/core/permalink-manager-admin-functions.php:700
851
#: includes/core/permalink-manager-admin-functions.php:727
836
#: includes/core/permalink-manager-admin-functions.php:754
852
837
msgid "Old URI"
853
838
msgstr ""
854
839
855
#: includes/views/permalink-manager-settings.php:259
840
#: includes/views/permalink-manager-settings.php:230
856
841
#, php-format
857
842
msgid ""
…
…
861
846
msgstr ""
862
847
863
#: includes/views/permalink-manager-uri-editor.php:89
848
#: includes/views/permalink-manager-uri-editor.php:97
864
849
msgid "Per page"
865
850
msgstr ""
866
851
867
#: includes/views/permalink-manager-tools.php:18
852
#: includes/views/permalink-manager-tools.php:24
868
853
msgid "Permalink Duplicates"
869
854
msgstr ""
870
855
871
#: includes/core/permalink-manager-third-parties.php:848
872
#: includes/core/permalink-manager-third-parties.php:1007
873
#: includes/core/permalink-manager-gutenberg.php:38
874
#: includes/core/permalink-manager-admin-functions.php:110
875
#: includes/core/permalink-manager-admin-functions.php:110
876
#: includes/core/permalink-manager-admin-functions.php:791
877
#: includes/core/permalink-manager-admin-functions.php:882
878
#: includes/core/permalink-manager-admin-functions.php:887
879
#: includes/core/permalink-manager-admin-functions.php:888
856
#: includes/core/permalink-manager-third-parties.php:959
857
#: includes/core/permalink-manager-third-parties.php:1178
858
#: includes/core/permalink-manager-gutenberg.php:42
859
#: includes/core/permalink-manager-admin-functions.php:112
860
#: includes/core/permalink-manager-admin-functions.php:112
861
#: includes/core/permalink-manager-admin-functions.php:818
862
#: includes/core/permalink-manager-admin-functions.php:916
863
#: includes/core/permalink-manager-admin-functions.php:921
864
#: includes/core/permalink-manager-admin-functions.php:922
880
865
msgid "Permalink Manager"
881
866
msgstr ""
882
867
883
#: includes/views/permalink-manager-settings.php:141
868
#: includes/views/permalink-manager-settings.php:123
884
869
msgid ""
885
870
"Permalink Manager can force the trailing slashes settings in the custom "
…
…
887
872
msgstr ""
888
873
889
#: includes/views/permalink-manager-settings.php:169
874
#: includes/views/permalink-manager-settings.php:142
890
875
msgid ""
891
876
"Permalink Manager includes a set of hooks that allow to extend the redirect "
…
…
897
882
msgstr ""
898
883
899
#: includes/views/permalink-manager-settings.php:74
884
#: includes/views/permalink-manager-settings.php:70
900
885
msgid ""
901
886
"Permalink Manager will ignore and not filter the custom permalinks of all "
…
…
903
888
msgstr ""
904
889
905
#: includes/core/permalink-manager-actions.php:438
906
#: includes/core/permalink-manager-actions.php:442
907
#: includes/core/permalink-manager-admin-functions.php:430
890
#: includes/core/permalink-manager-actions.php:516
891
#: includes/core/permalink-manager-actions.php:520
892
#: includes/core/permalink-manager-admin-functions.php:440
908
893
msgid "Permastructure settings"
909
894
msgstr ""
910
895
911
#: includes/views/permalink-manager-permastructs.php:82
896
#: includes/views/permalink-manager-permastructs.php:91
912
897
msgid "Permastructure tags"
913
898
msgstr ""
914
899
915
#: includes/core/permalink-manager-admin-functions.php:404
900
#: includes/core/permalink-manager-admin-functions.php:422
916
901
msgid "Permastructure translations"
917
902
msgstr ""
918
903
919
#: includes/views/permalink-manager-permastructs.php:15
904
#: includes/views/permalink-manager-permastructs.php:21
920
905
msgid "Permastructures"
921
906
msgstr ""
922
907
923
#: includes/core/permalink-manager-pro-functions.php:261
908
#: includes/core/permalink-manager-pro-functions.php:271
924
909
msgid "Persian"
925
910
msgstr ""
926
911
927
#: includes/views/permalink-manager-settings.php:160
912
#: includes/views/permalink-manager-settings.php:135
928
913
msgid "Please disable it if you encounter any redirect loop issues."
929
914
msgstr ""
930
915
931
#: includes/views/permalink-manager-settings.php:192
916
#: includes/views/permalink-manager-settings.php:163
932
917
msgid ""
933
918
"Please disable this feature if the language code in the custom permalinks is "
…
…
935
920
msgstr ""
936
921
937
#: includes/views/permalink-manager-settings.php:121
922
#: includes/views/permalink-manager-settings.php:109
938
923
msgid ""
939
924
"Please enable this option if you would like to manage additional custom "
940
"redirects (aliasees) in URI Editor for individual posts & terms."
941
msgstr ""
942
943
#: includes/views/permalink-manager-settings.php:142
925
"redirects (aliases) in URI Editor for individual posts & terms."
926
msgstr ""
927
928
#: includes/views/permalink-manager-settings.php:123
944
929
msgid ""
945
930
"Please go to \\"<em>General settings -> Trailing slashes</em>\\" to choose if "
…
…
947
932
msgstr ""
948
933
949
#: includes/views/permalink-manager-settings.php:67
934
#: includes/views/permalink-manager-settings.php:64
950
935
msgid ""
951
936
"Please go to \\"<em>Redirect settings -> Trailing slashes redirect</em>\\" to "
…
…
953
938
msgstr ""
954
939
955
#: includes/views/permalink-manager-pro-addons.php:235
940
#: includes/views/permalink-manager-pro-addons.php:251
956
941
msgid ""
957
942
"Please note that \\"Custom Permalinks\\" (if activated) may break the behavior "
…
…
959
944
msgstr ""
960
945
961
#: includes/views/permalink-manager-settings.php:133
946
#: includes/views/permalink-manager-settings.php:117
962
947
msgid ""
963
948
"Please note that the new redirects will be saved only if \\"Extra redirects "
…
…
965
950
msgstr ""
966
951
967
#: includes/core/permalink-manager-pro-functions.php:149
952
#: includes/core/permalink-manager-pro-functions.php:161
968
953
#, php-format
969
954
msgid ""
…
…
972
957
msgstr ""
973
958
974
#: includes/core/permalink-manager-pro-functions.php:262
959
#: includes/core/permalink-manager-pro-functions.php:272
975
960
msgid "Polish"
976
961
msgstr ""
977
962
978
#: includes/core/permalink-manager-pro-functions.php:263
963
#: includes/core/permalink-manager-pro-functions.php:273
979
964
msgid "Portuguese"
980
965
msgstr ""
981
966
982
#: includes/views/permalink-manager-uri-editor-post.php:115
967
#: includes/views/permalink-manager-uri-editor-post.php:126
983
968
msgid "Post status"
984
969
msgstr ""
985
970
986
#: includes/views/permalink-manager-uri-editor.php:94
971
#: includes/views/permalink-manager-uri-editor.php:102
987
972
msgid "Post statuses"
988
973
msgstr ""
989
974
990
#: includes/views/permalink-manager-uri-editor-post.php:55
975
#: includes/views/permalink-manager-uri-editor-post.php:62
991
976
msgid "Post title"
992
977
msgstr ""
993
978
994
#: includes/views/permalink-manager-permastructs.php:31
995
#: includes/views/permalink-manager-tools.php:162
996
#: includes/views/permalink-manager-tools.php:239
997
#: includes/core/permalink-manager-admin-functions.php:261
979
#: includes/views/permalink-manager-permastructs.php:40
980
#: includes/views/permalink-manager-tools.php:179
981
#: includes/views/permalink-manager-tools.php:259
982
#: includes/core/permalink-manager-admin-functions.php:281
998
983
msgid "Post types"
999
984
msgstr ""
1000
985
1001
#: includes/views/permalink-manager-settings.php:165
986
#: includes/views/permalink-manager-settings.php:139
1002
987
msgid "Redirect mode"
1003
988
msgstr ""
1004
989
1005
#: includes/views/permalink-manager-settings.php:84
990
#: includes/views/permalink-manager-settings.php:80
1006
991
msgid "Redirect settings"
1007
992
msgstr ""
1008
993
1009
#: includes/views/permalink-manager-pro-addons.php:324
994
#: includes/views/permalink-manager-pro-addons.php:332
1010
995
msgid "Redirect this page to external URL"
1011
996
msgstr ""
1012
997
1013
#: includes/views/permalink-manager-settings.php:147
998
#: includes/views/permalink-manager-settings.php:127
1014
999
msgid "Redirect with query parameters"
1015
1000
msgstr ""
1016
1001
1017
#: includes/views/permalink-manager-tools.php:286
1002
#: includes/views/permalink-manager-tools.php:306
1018
1003
msgid "Regenerate"
1019
1004
msgstr ""
1020
1005
1021
#: includes/views/permalink-manager-tools.php:226
1006
#: includes/views/permalink-manager-tools.php:246
1022
1007
msgid "Regenerate custom permalinks"
1023
1008
msgstr ""
1024
1009
1025
#: includes/views/permalink-manager-tools.php:227
1010
#: includes/views/permalink-manager-tools.php:247
1026
1011
msgid "Regenerate native slugs"
1027
1012
msgstr ""
1028
1013
1029
#: includes/views/permalink-manager-tools.php:26
1014
#: includes/views/permalink-manager-tools.php:32
1030
1015
msgid "Regenerate/Reset"
1031
1016
msgstr ""
1032
1017
1033
#: includes/views/permalink-manager-pro-addons.php:137
1018
#: includes/views/permalink-manager-pro-addons.php:153
1034
1019
msgid "Reload the expiration date"
1035
1020
msgstr ""
1036
1021
1037
#: includes/views/permalink-manager-debug.php:45
1022
#: includes/views/permalink-manager-debug.php:57
1038
1023
msgid "Remove all custom permalinks"
1039
1024
msgstr ""
1040
1025
1041
#: includes/views/permalink-manager-debug.php:56
1026
#: includes/views/permalink-manager-debug.php:64
1042
1027
msgid "Remove all custom redirects"
1043
1028
msgstr ""
1044
1029
1045
#: includes/views/permalink-manager-debug.php:67
1030
#: includes/views/permalink-manager-debug.php:71
1046
1031
msgid "Remove all external redirects"
1047
1032
msgstr ""
…
…
1051
1036
msgstr ""
1052
1037
1053
#: includes/views/permalink-manager-debug.php:89
1038
#: includes/views/permalink-manager-debug.php:85
1054
1039
msgid "Remove all plugin settings"
1055
1040
msgstr ""
1056
1041
1057
#: includes/views/permalink-manager-pro-addons.php:173
1042
#: includes/views/permalink-manager-pro-addons.php:186
1058
1043
msgid "Remove all words"
1059
1044
msgstr ""
1060
1045
1061
#: includes/views/permalink-manager-tools.php:85
1062
#: includes/views/permalink-manager-tools.php:98
1046
#: includes/views/permalink-manager-tools.php:106
1047
#: includes/views/permalink-manager-tools.php:118
1063
1048
msgid "Remove broken URI"
1064
1049
msgstr ""
…
…
1068
1053
msgstr ""
1069
1054
1070
#: includes/views/permalink-manager-tools.php:140
1055
#: includes/views/permalink-manager-tools.php:157
1071
1056
msgid "Replace with ..."
1072
1057
msgstr ""
1073
1058
1074
#: includes/core/permalink-manager-admin-functions.php:424
1059
#: includes/core/permalink-manager-admin-functions.php:437
1075
1060
msgid "Restore default permastructure"
1076
1061
msgstr ""
1077
1062
1078
#: includes/core/permalink-manager-admin-functions.php:937
1063
#: includes/core/permalink-manager-admin-functions.php:957
1079
1064
msgid "Restore Default URI"
1080
1065
msgstr ""
1081
1066
1082
#: includes/core/permalink-manager-pro-functions.php:264
1067
#: includes/core/permalink-manager-pro-functions.php:274
1083
1068
msgid "Russian"
1084
1069
msgstr ""
1085
1070
1086
#: includes/views/permalink-manager-pro-addons.php:293
1071
#: includes/views/permalink-manager-pro-addons.php:309
1087
1072
msgid "sample/custom-uri"
1088
1073
msgstr ""
1089
1074
1090
#: includes/views/permalink-manager-pro-addons.php:205
1075
#: includes/views/permalink-manager-pro-addons.php:218
1091
1076
msgid "Save"
1092
1077
msgstr ""
1093
1078
1094
#: includes/views/permalink-manager-uri-editor-tax.php:147
1079
#: includes/views/permalink-manager-uri-editor-tax.php:140
1095
1080
#: includes/views/permalink-manager-uri-editor-post.php:150
1096
1081
msgid "Save all the URIs above"
1097
1082
msgstr ""
1098
1083
1099
#: includes/views/permalink-manager-uri-editor-tax.php:146
1084
#: includes/views/permalink-manager-uri-editor-tax.php:139
1100
1085
#: includes/views/permalink-manager-uri-editor-post.php:149
1101
1086
msgid "Save all the URIs below"
1102
1087
msgstr ""
1103
1088
1104
#: includes/views/permalink-manager-settings.php:127
1089
#: includes/views/permalink-manager-settings.php:113
1105
1090
msgid "Save old custom permalinks as extra redirects"
1106
1091
msgstr ""
1107
1092
1108
#: includes/core/permalink-manager-admin-functions.php:961
1093
#: includes/core/permalink-manager-admin-functions.php:973
1109
1094
msgid "Save permalink"
1110
1095
msgstr ""
1111
1096
1112
#: includes/views/permalink-manager-permastructs.php:86
1097
#: includes/views/permalink-manager-permastructs.php:95
1113
1098
msgid "Save permastructures"
1114
1099
msgstr ""
1115
1100
1116
#: includes/views/permalink-manager-settings.php:274
1101
#: includes/views/permalink-manager-settings.php:243
1117
1102
msgid "Save settings"
1118
1103
msgstr ""
1119
1104
1120
#: includes/views/permalink-manager-uri-editor-tax.php:155
1121
#: includes/views/permalink-manager-uri-editor-post.php:158
1105
#: includes/views/permalink-manager-uri-editor-tax.php:148
1106
#: includes/views/permalink-manager-uri-editor-post.php:157
1122
1107
msgid "Search"
1123
1108
msgstr ""
1124
1109
1125
#: includes/core/permalink-manager-admin-functions.php:284
1110
#: includes/core/permalink-manager-admin-functions.php:304
1126
1111
msgid "Select all"
1127
1112
msgstr ""
1128
1113
1129
#: includes/views/permalink-manager-tools.php:155
1130
#: includes/views/permalink-manager-tools.php:232
1114
#: includes/views/permalink-manager-tools.php:172
1115
#: includes/views/permalink-manager-tools.php:252
1131
1116
msgid "Select content type"
1132
1117
msgstr ""
1133
1118
1134
#: includes/views/permalink-manager-tools.php:196
1119
#: includes/views/permalink-manager-tools.php:213
1120
#: includes/views/permalink-manager-tools.php:293
1121
msgid "Select IDs"
1122
msgstr ""
1123
1124
#: includes/views/permalink-manager-tools.php:204
1125
#: includes/views/permalink-manager-tools.php:284
1126
msgid "Select post statuses"
1127
msgstr ""
1128
1129
#: includes/views/permalink-manager-tools.php:184
1130
#: includes/views/permalink-manager-tools.php:264
1131
msgid "Select post types"
1132
msgstr ""
1133
1134
#: includes/views/permalink-manager-tools.php:193
1135
1135
#: includes/views/permalink-manager-tools.php:273
1136
msgid "Select IDs"
1137
msgstr ""
1138
1139
#: includes/views/permalink-manager-tools.php:187
1140
#: includes/views/permalink-manager-tools.php:264
1141
msgid "Select post statuses"
1142
msgstr ""
1143
1144
#: includes/views/permalink-manager-tools.php:167
1145
#: includes/views/permalink-manager-tools.php:244
1146
msgid "Select post types"
1147
msgstr ""
1148
1149
#: includes/views/permalink-manager-tools.php:176
1150
#: includes/views/permalink-manager-tools.php:253
1151
1136
msgid "Select taxonomies"
1152
1137
msgstr ""
1153
1138
1154
#: includes/views/permalink-manager-settings.php:14
1155
#: includes/core/permalink-manager-admin-functions.php:156
1139
#: includes/views/permalink-manager-settings.php:21
1140
#: includes/core/permalink-manager-admin-functions.php:166
1156
1141
msgid "Settings"
1157
1142
msgstr ""
1158
1143
1159
#: includes/views/permalink-manager-settings.php:229
1144
#: includes/views/permalink-manager-settings.php:200
1160
1145
msgid "Show \\"Native slug\\" field in URI Editor"
1161
1146
msgstr ""
1162
1147
1163
#: includes/core/permalink-manager-admin-functions.php:439
1148
#: includes/core/permalink-manager-admin-functions.php:445
1164
1149
msgid "Show additional settings"
1165
1150
msgstr ""
1166
1151
1167
#: includes/core/permalink-manager-admin-functions.php:722
1152
#: includes/core/permalink-manager-admin-functions.php:729
1168
1153
msgid "Show more details"
1169
1154
msgstr ""
1170
1155
1171
#: includes/core/permalink-manager-actions.php:711
1172
msgid "Sitemaps were updated!"
1173
msgstr ""
1174
1175
#: includes/views/permalink-manager-uri-editor-tax.php:95
1176
#: includes/views/permalink-manager-uri-editor-post.php:114
1156
#: includes/views/permalink-manager-uri-editor-tax.php:98
1157
#: includes/views/permalink-manager-uri-editor-post.php:125
1177
1158
msgid "Slug"
1178
1159
msgstr ""
1179
1160
1180
#: includes/views/permalink-manager-settings.php:50
1161
#: includes/views/permalink-manager-settings.php:54
1181
1162
msgid "Slugs mode"
1182
1163
msgstr ""
1183
1164
1184
#: includes/core/permalink-manager-pro-functions.php:265
1165
#: includes/core/permalink-manager-pro-functions.php:275
1185
1166
msgid "Spanish"
1186
1167
msgstr ""
1187
1168
1188
#: includes/views/permalink-manager-tools.php:30
1169
#: includes/views/permalink-manager-tools.php:36
1189
1170
msgid "Stop Words"
1190
1171
msgstr ""
1191
1172
1192
#: includes/views/permalink-manager-settings.php:243
1173
#: includes/views/permalink-manager-settings.php:214
1193
1174
msgid "Strip special characters"
1194
1175
msgstr ""
1195
1176
1196
#: includes/views/permalink-manager-pro-addons.php:264
1177
#: includes/views/permalink-manager-pro-addons.php:282
1197
1178
msgid "Suggestions/feedback"
1198
1179
msgstr ""
1199
1180
1200
#: includes/views/permalink-manager-pro-addons.php:106
1181
#: includes/views/permalink-manager-pro-addons.php:122
1201
1182
msgid "Support"
1202
1183
msgstr ""
1203
1184
1204
#: includes/core/permalink-manager-pro-functions.php:266
1185
#: includes/core/permalink-manager-pro-functions.php:276
1205
1186
msgid "Swedish"
1206
1187
msgstr ""
1207
1188
1208
#: includes/views/permalink-manager-permastructs.php:36
1209
#: includes/views/permalink-manager-tools.php:163
1210
#: includes/views/permalink-manager-tools.php:240
1211
#: includes/core/permalink-manager-admin-functions.php:261
1189
#: includes/views/permalink-manager-permastructs.php:45
1190
#: includes/views/permalink-manager-tools.php:180
1191
#: includes/views/permalink-manager-tools.php:260
1192
#: includes/core/permalink-manager-admin-functions.php:281
1212
1193
msgid "Taxonomies"
1213
1194
msgstr ""
1214
1195
1215
#: includes/views/permalink-manager-pro-addons.php:259
1196
#: includes/views/permalink-manager-pro-addons.php:277
1216
1197
msgid "Technical support"
1217
1198
msgstr ""
1218
1199
1219
#: includes/views/permalink-manager-uri-editor-tax.php:51
1200
#: includes/views/permalink-manager-uri-editor-tax.php:57
1220
1201
msgid "Term title"
1221
1202
msgstr ""
1222
1203
1223
#: includes/views/permalink-manager-uri-editor-tax.php:112
1224
#: includes/views/permalink-manager-uri-editor-post.php:101
1204
#: includes/views/permalink-manager-uri-editor-tax.php:116
1205
#: includes/views/permalink-manager-uri-editor-post.php:111
1225
1206
msgid ""
1226
1207
"The above permalink will be automatically updated and is locked for editing."
1227
1208
msgstr ""
1228
1209
1229
#: includes/core/permalink-manager-admin-functions.php:899
1210
#: includes/core/permalink-manager-admin-functions.php:933
1230
1211
msgid "The custom URI cannot be edited on frontpage."
1231
1212
msgstr ""
1232
1213
1233
#: includes/core/permalink-manager-admin-functions.php:927
1214
#: includes/core/permalink-manager-admin-functions.php:952
1234
1215
msgid ""
1235
1216
"The native slug is by default automatically used in native permalinks (when "
…
…
1237
1218
msgstr ""
1238
1219
1239
#: includes/views/permalink-manager-settings.php:55
1220
#: includes/views/permalink-manager-settings.php:57
1240
1221
msgid ""
1241
1222
"The native slug is generated from the initial title after the post or term "
…
…
1243
1224
msgstr ""
1244
1225
1245
#: includes/core/permalink-manager-actions.php:633
1226
#: includes/core/permalink-manager-actions.php:377
1246
1227
msgid "The redirect was removed successfully!"
1247
1228
msgstr ""
1248
1229
1249
#: includes/core/permalink-manager-actions.php:106
1230
#: includes/core/permalink-manager-actions.php:431
1250
1231
msgid "The settings are saved!"
1251
1232
msgstr ""
1252
1233
1253
#: includes/core/permalink-manager-pro-functions.php:555
1234
#: includes/core/permalink-manager-pro-functions.php:611
1254
1235
msgid ""
1255
1236
"The URIs are case-insensitive, eg. <strong>BLACKFRIDAY</strong> and <strong>"
…
…
1257
1238
msgstr ""
1258
1239
1259
#: includes/core/permalink-manager-admin-functions.php:902
1240
#: includes/core/permalink-manager-admin-functions.php:936
1260
1241
msgid ""
1261
1242
"The URL above is displayed in read-only mode. To enable editing, change the "
…
…
1264
1245
msgstr ""
1265
1246
1266
#: includes/views/permalink-manager-pro-addons.php:236
1247
#: includes/views/permalink-manager-pro-addons.php:252
1267
1248
msgid ""
1268
1249
"Therefore, it is recommended to disable \\"Custom Permalink\\" and import old "
…
…
1270
1251
msgstr ""
1271
1252
1272
#: includes/views/permalink-manager-settings.php:176
1253
#: includes/views/permalink-manager-settings.php:147
1273
1254
msgid "Third party plugins"
1274
1255
msgstr ""
1275
1256
1276
#: includes/views/permalink-manager-settings.php:94
1257
#: includes/views/permalink-manager-settings.php:88
1277
1258
msgid ""
1278
1259
"This feature will be also used to redirect (old) original permalinks to (new)"
…
…
1280
1261
msgstr ""
1281
1262
1282
#: includes/core/permalink-manager-admin-functions.php:1092
1263
#: includes/core/permalink-manager-admin-functions.php:1113
1283
1264
#, php-format
1284
1265
msgid ""
…
…
1293
1274
msgstr ""
1294
1275
1295
#: includes/core/permalink-manager-admin-functions.php:695
1296
#: includes/core/permalink-manager-admin-functions.php:722
1276
#: includes/core/permalink-manager-admin-functions.php:719
1277
#: includes/core/permalink-manager-admin-functions.php:748
1297
1278
msgid "Title"
1298
1279
msgstr ""
1299
1280
1300
#: includes/views/permalink-manager-permastructs.php:79
1281
#: includes/views/permalink-manager-permastructs.php:88
1301
1282
#, php-format
1302
1283
msgid ""
…
…
1306
1287
msgstr ""
1307
1288
1308
#: includes/views/permalink-manager-pro-addons.php:260
1289
#: includes/views/permalink-manager-pro-addons.php:278
1309
1290
#, php-format
1310
1291
msgid ""
…
…
1314
1295
msgstr ""
1315
1296
1316
#: includes/views/permalink-manager-tools.php:200
1317
#: includes/views/permalink-manager-tools.php:277
1297
#: includes/views/permalink-manager-tools.php:217
1298
#: includes/views/permalink-manager-tools.php:297
1318
1299
msgid ""
1319
1300
"To narrow the above filters you can type the post IDs (or ranges) here. Eg. "
…
…
1321
1302
msgstr ""
1322
1303
1323
#: includes/views/permalink-manager-pro-addons.php:262
1304
#: includes/views/permalink-manager-pro-addons.php:280
1324
1305
msgid ""
1325
1306
"To reduce the response time, please attach your licence key and if possible "
…
…
1327
1308
msgstr ""
1328
1309
1329
#: includes/views/permalink-manager-tools.php:15
1310
#: includes/views/permalink-manager-tools.php:21
1330
1311
msgid "Tools"
1331
1312
msgstr ""
…
…
1335
1316
msgstr ""
1336
1317
1337
#: includes/views/permalink-manager-settings.php:138
1318
#: includes/views/permalink-manager-settings.php:121
1338
1319
msgid "Trailing slashes redirect"
1339
1320
msgstr ""
1340
1321
1341
#: includes/core/permalink-manager-pro-functions.php:267
1322
#: includes/core/permalink-manager-pro-functions.php:277
1342
1323
msgid "Turkish"
1343
1324
msgstr ""
1344
1325
1345
#: includes/views/permalink-manager-pro-addons.php:279
1326
#: includes/views/permalink-manager-pro-addons.php:299
1346
1327
msgid ""
1347
1328
"Turn on \\"<strong>Extra redirects (aliases)</strong>\\" in Permalink Manager "
…
…
1349
1330
msgstr ""
1350
1331
1351
#: includes/views/permalink-manager-pro-addons.php:193
1332
#: includes/views/permalink-manager-pro-addons.php:206
1352
1333
msgid "Type comma to separate the words."
1353
1334
msgstr ""
1354
1335
1355
#: includes/views/permalink-manager-settings.php:203
1336
#: includes/views/permalink-manager-settings.php:174
1356
1337
msgid "Ultimate Member support"
1357
1338
msgstr ""
1358
1339
1359
#: includes/core/permalink-manager-admin-functions.php:285
1340
#: includes/core/permalink-manager-admin-functions.php:305
1360
1341
msgid "Unselect all"
1361
1342
msgstr ""
1362
1343
1363
#: includes/core/permalink-manager-admin-functions.php:628
1344
#: includes/core/permalink-manager-admin-functions.php:646
1364
1345
msgid "Upgrade to PRO"
1365
1346
msgstr ""
1366
1347
1367
#: includes/core/permalink-manager-actions.php:601
1348
#: includes/core/permalink-manager-actions.php:339
1368
1349
#, php-format
1369
1350
msgid "URI \\"%s\\" was removed successfully!"
1370
1351
msgstr ""
1371
1352
1372
#: includes/core/permalink-manager-actions.php:613
1353
#: includes/core/permalink-manager-actions.php:351
1373
1354
msgid "URI and/or custom redirects does not exist or were already removed!"
1374
1355
msgstr ""
1375
1356
1376
#: includes/core/permalink-manager-admin-functions.php:155
1357
#: includes/views/permalink-manager-uri-editor.php:23
1358
#: includes/core/permalink-manager-admin-functions.php:165
1377
1359
msgid "URI Editor"
1378
1360
msgstr ""
1379
1361
1380
#: includes/views/permalink-manager-uri-editor.php:28
1381
msgid "URI editor"
1382
msgstr ""
1383
1384
#: includes/views/permalink-manager-settings.php:257
1362
#: includes/views/permalink-manager-settings.php:228
1385
1363
msgid "URI Editor role capability"
1386
1364
msgstr ""
1387
1365
1388
#: includes/core/permalink-manager-actions.php:663
1366
#: includes/core/permalink-manager-actions.php:708
1389
1367
msgid "URI is already in use, please select another one!"
1390
1368
msgstr ""
1391
1369
1392
#: includes/views/permalink-manager-settings.php:39
1393
#: includes/core/permalink-manager-admin-functions.php:914
1370
#: includes/views/permalink-manager-settings.php:47
1371
#: includes/core/permalink-manager-admin-functions.php:944
1394
1372
msgid "URI update mode"
1395
1373
msgstr ""
1396
1374
1397
#: includes/views/permalink-manager-settings.php:52
1375
#: includes/views/permalink-manager-settings.php:56
1398
1376
msgid "Use actual titles as slugs"
1399
1377
msgstr ""
…
…
1403
1381
msgstr ""
1404
1382
1405
#: includes/core/permalink-manager-admin-functions.php:867
1383
#: includes/core/permalink-manager-admin-functions.php:901
1406
1384
#, php-format
1407
1385
msgid "Use global settings \[%s\]"
1408
1386
msgstr ""
1409
1387
1410
#: includes/views/permalink-manager-settings.php:52
1388
#: includes/views/permalink-manager-settings.php:56
1411
1389
msgid "Use native slugs"
1412
1390
msgstr ""
1413
1391
1414
#: includes/views/permalink-manager-tools.php:228
1392
#: includes/views/permalink-manager-tools.php:248
1415
1393
msgid "Use original URLs as custom permalinks"
1416
1394
msgstr ""
1417
1395
1418
#: includes/views/permalink-manager-settings.php:45
1396
#: includes/views/permalink-manager-settings.php:50
1419
1397
msgid ""
1420
1398
"Use the last option if you want to to customize only specific permalinks and "
…
…
1422
1400
msgstr ""
1423
1401
1424
#: includes/views/permalink-manager-settings.php:56
1402
#: includes/views/permalink-manager-settings.php:57
1425
1403
msgid ""
1426
1404
"Use this field if you would like Permalink Manager to use the actual titles "
…
…
1428
1406
msgstr ""
1429
1407
1430
#: includes/views/permalink-manager-uri-editor-tax.php:101
1431
#: includes/views/permalink-manager-uri-editor-post.php:121
1432
#: includes/views/permalink-manager-uri-editor-post.php:121
1408
#: includes/views/permalink-manager-uri-editor-tax.php:104
1409
#: includes/views/permalink-manager-uri-editor-post.php:132
1410
#: includes/views/permalink-manager-uri-editor-post.php:132
1433
1411
msgid "View"
1434
1412
msgstr ""
1435
1413
1436
#: includes/views/permalink-manager-permastructs.php:46
1414
#: includes/views/permalink-manager-permastructs.php:55
1437
1415
msgid "WooCommerce"
1438
1416
msgstr ""
1439
1417
1440
#: includes/views/permalink-manager-settings.php:196
1418
#: includes/views/permalink-manager-settings.php:167
1441
1419
msgid "WP All Import/Export support"
1442
1420
msgstr ""
1443
1421
1444
#: includes/views/permalink-manager-settings.php:189
1422
#: includes/views/permalink-manager-settings.php:160
1445
1423
msgid "WPML compatibility functions"
1446
1424
msgstr ""
1447
1425
1448
#: includes/views/permalink-manager-settings.php:182
1426
#: includes/views/permalink-manager-settings.php:153
1449
1427
msgid "WPML/Polylang language mismatch"
1450
1428
msgstr ""
1451
1429
1452
#: includes/views/permalink-manager-settings.php:245
1453
#: includes/views/permalink-manager-settings.php:252
1430
#: includes/views/permalink-manager-settings.php:216
1431
#: includes/views/permalink-manager-settings.php:223
1454
1432
msgid "Yes, use native settings"
1455
1433
msgstr ""
1456
1434
1457
#: includes/core/permalink-manager-actions.php:413
1458
#: includes/core/permalink-manager-actions.php:419
1435
#: includes/core/permalink-manager-actions.php:81
1436
#: includes/core/permalink-manager-actions.php:498
1459
1437
msgid "You are not allowed to remove Permalink Manager data!"
1460
1438
msgstr ""
1461
1439
1462
#: includes/views/permalink-manager-settings.php:170
1440
#: includes/views/permalink-manager-settings.php:142
1463
1441
msgid ""
1464
1442
"You can disable this feature if you do not want Permalink Manager to trigger "
…
…
1466
1444
msgstr ""
1467
1445
1468
#: includes/views/permalink-manager-settings.php:122
1446
#: includes/views/permalink-manager-settings.php:109
1469
1447
msgid ""
1470
1448
"You can disable this feature if you use another plugin to control the "
…
…
1472
1450
msgstr ""
1473
1451
1474
#: includes/core/permalink-manager-pro-functions.php:170
1452
#: includes/views/permalink-manager-settings.php:64
1453
msgid ""
1454
"You can use this feature to either add or remove the slashes from end of "
1455
"WordPress permalinks."
1456
msgstr ""
1457
1458
#: includes/core/permalink-manager-pro-functions.php:178
1475
1459
msgid "You own a lifetime licence key."
1476
1460
msgstr ""
1477
1461
1478
#: includes/core/permalink-manager-pro-functions.php:183
1462
#: includes/core/permalink-manager-pro-functions.php:189
1479
1463
#, php-format
1480
1464
msgid ""
…
…
1483
1467
msgstr ""
1484
1468
1485
#: includes/core/permalink-manager-pro-functions.php:159
1469
#: includes/core/permalink-manager-pro-functions.php:169
1486
1470
#, php-format
1487
1471
msgid ""
…
…
1491
1475
msgstr ""
1492
1476
1493
#: includes/core/permalink-manager-pro-functions.php:154
1477
#: includes/core/permalink-manager-pro-functions.php:165
1494
1478
msgid "Your Permalink Manager Pro licence key is invalid!"
1495
1479
msgstr ""
1496
1480
1497
#: includes/core/permalink-manager-pro-functions.php:164
1481
#: includes/core/permalink-manager-pro-functions.php:173
1498
1482
msgid ""
1499
1483
"Your Permalink Manager Pro license is already in use on another website and "
permalink-manager/trunk/permalink-manager.php
r2818533
r2833667
2
2
3
3
/\*\*
4
\* Plugin Name: Permalink Manager Lite
5
\* Plugin URI: https://permalinkmanager.pro?utm\_source=plugin
6
\* Description: Advanced plugin that allows to set-up custom permalinks (bulk editors included), slugs and permastructures (WooCommerce compatible).
7
\* Version: 2.2.20.3
8
\* Author: Maciej Bis
9
\* Author URI: http://maciejbis.net/
10
\* License: GPL-2.0+
11
\* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
12
\* Text Domain: permalink-manager
13
\* Domain Path: /languages
14
\* WC requires at least: 3.0.0
15
\* WC tested up to: 7.1.0
16
\*/
17
18
// If this file is called directly or plugin is already defined, abort.
19
if (!defined('WPINC')) {
4
\* Plugin Name: Permalink Manager Lite
5
\* Plugin URI: https://permalinkmanager.pro?utm\_source=plugin
6
\* Description: Advanced plugin that allows to set up custom permalinks (bulk editors included), slugs and permastructures (WooCommerce compatible).
7
\* Version: 2.3.0
8
\* Author: Maciej Bis
9
\* Author URI: http://maciejbis.net/
10
\* License: GPL-2.0+
11
\* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
12
\* Text Domain: permalink-manager
13
\* Domain Path: /languages
14
\* WC requires at least: 3.0.0
15
\* WC tested up to: 7.1.1
16
\*/
17
18
// If this file is called directly or plugin is already defined, abort
19
if ( ! defined( 'WPINC' ) ) {
20
20
die;
21
21
}
22
22
23
if(!class\_exists('Permalink\_Manager\_Class')) {
23
if ( ! class\_exists( 'Permalink\_Manager\_Class' ) ) {
24
24
25
25
// Define the directories used to load plugin files.
26
26
define( 'PERMALINK\_MANAGER\_PLUGIN\_NAME', 'Permalink Manager' );
27
27
define( 'PERMALINK\_MANAGER\_PLUGIN\_SLUG', 'permalink-manager' );
28
define( 'PERMALINK\_MANAGER\_VERSION', '2.2.20.3' );
28
define( 'PERMALINK\_MANAGER\_VERSION', '2.3.0' );
29
29
define( 'PERMALINK\_MANAGER\_FILE', \_\_FILE\_\_ );
30
define( 'PERMALINK\_MANAGER\_DIR', untrailingslashit(dirname(\_\_FILE\_\_)) );
31
define( 'PERMALINK\_MANAGER\_BASENAME', plugin\_basename(\_\_FILE\_\_));
32
define( 'PERMALINK\_MANAGER\_URL', untrailingslashit( plugins\_url('', \_\_FILE\_\_) ) );
33
define( 'PERMALINK\_MANAGER\_WEBSITE', 'http://permalinkmanager.pro?utm\_source=plugin' );
34
define( 'PERMALINK\_MANAGER\_DONATE', 'https://www.paypal.me/Bismit' );
35
30
define( 'PERMALINK\_MANAGER\_DIR', untrailingslashit( dirname( \_\_FILE\_\_ ) ) );
31
define( 'PERMALINK\_MANAGER\_BASENAME', plugin\_basename( \_\_FILE\_\_ ) );
32
define( 'PERMALINK\_MANAGER\_URL', untrailingslashit( plugins\_url( '', \_\_FILE\_\_ ) ) );
33
define( 'PERMALINK\_MANAGER\_WEBSITE', 'https://permalinkmanager.pro?utm\_source=plugin' );
34
35
/\*\*
36
\* The base class responsible for loading the plugin data as well as any plugin subclasses and additional functions
37
\*/
36
38
class Permalink\_Manager\_Class {
37
39
38
public $permalink\_manager\_options\_page, $permalink\_manager\_options;
39
public $sections, $functions, $permalink\_manager\_before\_sections\_html, $permalink\_manager\_after\_sections\_html;
40
41
/\*\*
42
\* Get options from DB, load subclasses & hooks
43
\*/
40
public $permalink\_manager\_options;
41
public $sections, $functions;
42
43
/\*\*
44
\* Get options from DB, load subclasses & hooks
45
\*/
44
46
public function \_\_construct() {
45
$this->include\_subclassess();
47
$this->include\_subclasses();
46
48
$this->register\_init\_hooks();
47
49
}
48
50
49
51
/\*\*
50
\* Include back-end classess and set their instances
51
\*/
52
function include\_subclassess() {
53
// WP\_List\_Table needed for post types & taxnomies editors
54
if( ! class\_exists( 'WP\_List\_Table' ) ) {
52
\* Include back-end classes and set their instances
53
\*/
54
function include\_subclasses() {
55
// WP\_List\_Table needed for post types & taxonomies editors
56
if ( ! class\_exists( 'WP\_List\_Table' ) ) {
55
57
require\_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
56
58
}
57
59
58
60
$classes = array(
59
'core' \=> array(
60
'helper-functions' \=> 'Permalink\_Manager\_Helper\_Functions',
61
'uri-functions' \=> 'Permalink\_Manager\_URI\_Functions',
61
'core' \=> array(
62
'helper-functions' \=> 'Permalink\_Manager\_Helper\_Functions',
63
'uri-functions' \=> 'Permalink\_Manager\_URI\_Functions',
62
64
'uri-functions-post' => 'Permalink\_Manager\_URI\_Functions\_Post',
63
'uri-functions-tax' \=> 'Permalink\_Manager\_URI\_Functions\_Tax',
64
'admin-functions' \=> 'Permalink\_Manager\_Admin\_Functions',
65
'actions' \=> 'Permalink\_Manager\_Actions',
66
'third-parties' \=> 'Permalink\_Manager\_Third\_Parties',
67
'language-plugins' \=> 'Permalink\_Manager\_Language\_Plugins',
68
'core-functions' \=> 'Permalink\_Manager\_Core\_Functions',
69
'gutenberg' \=> 'Permalink\_Manager\_Gutenberg',
70
'debug' \=> 'Permalink\_Manager\_Debug\_Functions',
71
'pro-functions' \=> 'Permalink\_Manager\_Pro\_Functions'
65
'uri-functions-tax' \=> 'Permalink\_Manager\_URI\_Functions\_Tax',
66
'admin-functions' \=> 'Permalink\_Manager\_Admin\_Functions',
67
'actions' \=> 'Permalink\_Manager\_Actions',
68
'third-parties' \=> 'Permalink\_Manager\_Third\_Parties',
69
'language-plugins' \=> 'Permalink\_Manager\_Language\_Plugins',
70
'core-functions' \=> 'Permalink\_Manager\_Core\_Functions',
71
'gutenberg' \=> 'Permalink\_Manager\_Gutenberg',
72
'debug' \=> 'Permalink\_Manager\_Debug\_Functions',
73
'pro-functions' \=> 'Permalink\_Manager\_Pro\_Functions'
72
74
),
73
75
'views' => array(
74
'uri-editor' \=> 'Permalink\_Manager\_Uri\_Editor',
75
'tools' \=> 'Permalink\_Manager\_Tools',
76
'permastructs' \=> 'Permalink\_Manager\_Permastructs',
77
'settings' \=> 'Permalink\_Manager\_Settings',
78
'debug' \=> 'Permalink\_Manager\_Debug',
79
'pro-addons' \=> 'Permalink\_Manager\_Pro\_Addons',
80
'help' \=> 'Permalink\_Manager\_Help',
81
'uri-editor-tax' \=> false,
76
'uri-editor' \=> 'Permalink\_Manager\_Uri\_Editor',
77
'tools' \=> 'Permalink\_Manager\_Tools',
78
'permastructs' \=> 'Permalink\_Manager\_Permastructs',
79
'settings' \=> 'Permalink\_Manager\_Settings',
80
'debug' \=> 'Permalink\_Manager\_Debug',
81
'pro-addons' \=> 'Permalink\_Manager\_Pro\_Addons',
82
'help' \=> 'Permalink\_Manager\_Help',
83
'uri-editor-tax' \=> false,
82
84
'uri-editor-post' => false
83
85
)
…
…
85
87
86
88
// Load classes and set-up their instances
87
foreach($classes as $class\_type => $classes\_array) {
88
foreach($classes\_array as $class => $class\_name) {
89
foreach ( $classes as $class\_type => $classes\_array ) {
90
foreach ( $classes\_array as $class => $class\_name ) {
89
91
$filename = PERMALINK\_MANAGER\_DIR . "/includes/{$class\_type}/permalink-manager-{$class}.php";
90
92
91
if(file\_exists($filename)) {
93
if ( file\_exists( $filename ) ) {
92
94
require\_once $filename;
93
if($class\_name) { $this->functions\[$class\] = new $class\_name(); }
95
if ( $class\_name ) {
96
$this->functions\[ $class \] = new $class\_name();
97
}
94
98
}
95
99
}
…
…
98
102
99
103
/\*\*
100
\* Register general hooks
101
\*/
104
\* Register general hooks
105
\*/
102
106
public function register\_init\_hooks() {
103
107
// Localize plugin
104
add\_action( 'init', array($this, 'localize\_me'), 1 );
108
add\_action( 'init', array( $this, 'localize\_me' ), 1 );
105
109
106
110
// Support deprecated hooks
107
add\_action( 'plugins\_loaded', array($this, 'deprecated\_hooks'), 9 );
111
add\_action( 'plugins\_loaded', array( $this, 'deprecated\_hooks' ), 9 );
108
112
109
113
// Deactivate free version if Permalink Manager Pro is activated
110
add\_action( 'plugins\_loaded', array($this, 'is\_pro\_activated'), 9 );
114
add\_action( 'plugins\_loaded', array( $this, 'is\_pro\_activated' ), 9 );
111
115
112
116
// Load globals & options
113
add\_action( 'plugins\_loaded', array($this, 'get\_options\_and\_globals'), 9 );
117
add\_action( 'plugins\_loaded', array( $this, 'get\_options\_and\_globals' ), 9 );
114
118
115
119
// Legacy support
116
add\_action( 'init', array($this, 'legacy\_support'), 2 );
120
add\_action( 'init', array( $this, 'legacy\_support' ), 2 );
117
121
118
122
// Default settings & alerts
119
add\_filter( 'permalink\_manager\_options', array($this, 'default\_settings'), 1 );
120
add\_filter( 'permalink\_manager\_alerts', array($this, 'default\_alerts'), 1 );
121
}
122
123
/\*\*
124
\* Localize this plugin
125
\*/
123
add\_filter( 'permalink\_manager\_options', array( $this, 'default\_settings' ), 1 );
124
add\_filter( 'permalink\_manager\_alerts', array( $this, 'default\_alerts' ), 1 );
125
}
126
127
/\*\*
128
\* Localize this plugin
129
\*/
126
130
function localize\_me() {
127
load\_plugin\_textdomain( 'permalink-manager', false, basename(dirname(\_\_FILE\_\_)) . "/languages" );
128
}
129
130
/\*\*
131
\* Get options values & set global
132
\*/
131
load\_plugin\_textdomain( 'permalink-manager', false, basename( dirname( \_\_FILE\_\_ ) ) . "/languages" );
132
}
133
134
/\*\*
135
\* Get options values & set global variables
136
\*/
133
137
public function get\_options\_and\_globals() {
134
138
// 1. Globals with data stored in DB
135
139
global $permalink\_manager\_options, $permalink\_manager\_uris, $permalink\_manager\_permastructs, $permalink\_manager\_redirects, $permalink\_manager\_external\_redirects;
136
140
137
$this->permalink\_manager\_options = $permalink\_manager\_options = (array) apply\_filters('permalink\_manager\_options', get\_option('permalink-manager', array()));
138
$this->permalink\_manager\_uris = $permalink\_manager\_uris = (array) apply\_filters('permalink\_manager\_uris', get\_option('permalink-manager-uris', array()));
139
$this->permalink\_manager\_permastructs = $permalink\_manager\_permastructs = (array) apply\_filters('permalink\_manager\_permastructs', get\_option('permalink-manager-permastructs', array()));
140
$this->permalink\_manager\_redirects = $permalink\_manager\_redirects = (array) apply\_filters('permalink\_manager\_redirects', get\_option('permalink-manager-redirects', array()));
141
$this->permalink\_manager\_external\_redirects = $permalink\_manager\_external\_redirects = (array) apply\_filters('permalink\_manager\_external\_redirects', get\_option('permalink-manager-external-redirects', array()));
141
$permalink\_manager\_options = (array) apply\_filters( 'permalink\_manager\_options', get\_option( 'permalink-manager', array() ) );
142
$permalink\_manager\_uris = (array) apply\_filters( 'permalink\_manager\_uris', get\_option( 'permalink-manager-uris', array() ) );
143
$permalink\_manager\_permastructs = (array) apply\_filters( 'permalink\_manager\_permastructs', get\_option( 'permalink-manager-permastructs', array() ) );
144
$permalink\_manager\_redirects = (array) apply\_filters( 'permalink\_manager\_redirects', get\_option( 'permalink-manager-redirects', array() ) );
145
$permalink\_manager\_external\_redirects = (array) apply\_filters( 'permalink\_manager\_external\_redirects', get\_option( 'permalink-manager-external-redirects', array() ) );
142
146
143
147
// 2. Globals used to display additional content (eg. alerts)
144
148
global $permalink\_manager\_alerts, $permalink\_manager\_before\_sections\_html, $permalink\_manager\_after\_sections\_html;
145
149
146
$this->permalink\_manager\_alerts = $permalink\_manager\_alerts = apply\_filters('permalink\_manager\_alerts', array());
147
$this->permalink\_manager\_before\_sections\_html = $permalink\_manager\_before\_sections\_html = apply\_filters('permalink\_manager\_before\_sections', '');
148
$this->permalink\_manager\_after\_sections\_html = $permalink\_manager\_after\_sections\_html = apply\_filters('permalink\_manager\_after\_sections', '');
149
}
150
151
/\*\*
152
\* Set the initial/default settings (including "Screen Options")
153
\*/
154
public function default\_settings($settings) {
155
$default\_settings = apply\_filters('permalink\_manager\_default\_options', array(
150
$permalink\_manager\_alerts = apply\_filters( 'permalink\_manager\_alerts', array() );
151
$permalink\_manager\_before\_sections\_html = apply\_filters( 'permalink\_manager\_before\_sections', '' );
152
$permalink\_manager\_after\_sections\_html = apply\_filters( 'permalink\_manager\_after\_sections', '' );
153
}
154
155
/\*\*
156
\* Set the initial/default settings (including "Screen Options")
157
\*
158
\* @param array $settings
159
\*
160
\* @return array
161
\*/
162
public function default\_settings( $settings ) {
163
$default\_settings = apply\_filters( 'permalink\_manager\_default\_options', array(
156
164
'screen-options' => array(
157
'per\_page' \=> 20,
158
'post\_statuses' => array('publish'),
159
'group' \=> false,
165
'per\_page' \=> 20,
166
'post\_statuses' => array( 'publish' ),
167
'group' => false
160
168
),
161
'general' \=> array(
162
'auto\_update\_uris' \=> 0,
163
'show\_native\_slug\_field' \=> 0,
164
'pagination\_redirect' \=> 0,
165
'sslwww\_redirect' \=> 0,
166
'canonical\_redirect' \=> 1,
167
'old\_slug\_redirect' \=> 0,
168
'setup\_redirects' \=> 0,
169
'redirect' \=> '301',
170
'extra\_redirects' \=> 1,
171
'copy\_query\_redirect' \=> 1,
172
'trailing\_slashes' \=> 0,
173
'trailing\_slash\_redirect' \=> 0,
174
'auto\_fix\_duplicates' \=> 0,
175
'fix\_language\_mismatch' \=> 1,
176
'wpml\_support' \=> 1,
177
'pmxi\_support' \=> 1,
178
'um\_support' \=> 1,
179
'yoast\_breadcrumbs' \=> 0,
180
'primary\_category' \=> 1,
181
'force\_custom\_slugs' \=> 0,
169
'general' \=> array(
170
'auto\_update\_uris' \=> 0,
171
'show\_native\_slug\_field' \=> 0,
172
'pagination\_redirect' \=> 0,
173
'sslwww\_redirect' \=> 0,
174
'canonical\_redirect' \=> 1,
175
'old\_slug\_redirect' \=> 0,
176
'setup\_redirects' \=> 0,
177
'redirect' \=> '301',
178
'extra\_redirects' \=> 1,
179
'copy\_query\_redirect' \=> 1,
180
'trailing\_slashes' \=> 0,
181
'trailing\_slash\_redirect' \=> 0,
182
'auto\_fix\_duplicates' \=> 0,
183
'fix\_language\_mismatch' \=> 1,
184
'wpml\_support' \=> 1,
185
'pmxi\_support' \=> 1,
186
'um\_support' \=> 1,
187
'yoast\_breadcrumbs' \=> 0,
188
'primary\_category' \=> 1,
189
'force\_custom\_slugs' \=> 0,
182
190
'disable\_slug\_sanitization' => 0,
183
'keep\_accents' \=> 0,
184
'partial\_disable' \=> array(
185
'post\_types' => array('attachment', 'tribe\_events', 'e-landing-page')
191
'keep\_accents' \=> 0,
192
'partial\_disable' \=> array(
193
'post\_types' => array( 'attachment', 'tribe\_events', 'e-landing-page' )
186
194
),
187
'partial\_disable\_strict' \=> 1,
188
'ignore\_drafts' \=> 1,
189
'edit\_uris\_cap' \=> 'publish\_posts',
195
'partial\_disable\_strict' \=> 1,
196
'ignore\_drafts' \=> 1,
197
'edit\_uris\_cap' => 'publish\_posts'
190
198
),
191
'licence' \=> array()
192
));
199
'licence' \=> array()
200
) );
193
201
194
202
// Check if settings array is empty
195
$settings\_empty = empty($settings);
203
$settings\_empty = empty( $settings );
196
204
197
205
// Apply the default settings (if empty values) in all settings sections
198
foreach($default\_settings as $group\_name => $fields) {
199
foreach($fields as $field\_name => $field) {
200
if($settings\_empty || (!isset($settings\[$group\_name\]\[$field\_name\]) && strpos($field\_name, 'partial\_disable') === false)) {
201
$settings\[$group\_name\]\[$field\_name\] = $field;
206
foreach ( $default\_settings as $group\_name => $fields ) {
207
foreach ( $fields as $field\_name => $field ) {
208
if ( $settings\_empty || ( ! isset( $settings\[ $group\_name \]\[ $field\_name \] ) && strpos( $field\_name, 'partial\_disable' ) === false ) ) {
209
$settings\[ $group\_name \]\[ $field\_name \] = $field;
202
210
}
203
211
}
…
…
208
216
209
217
/\*\*
210
\* Set the initial/default admin notices
211
\*/
212
public function default\_alerts($alerts) {
213
$default\_alerts = apply\_filters('permalink\_manager\_default\_alerts', array(
214
'jan21' => array(
215
'txt' => sprintf(
216
\_\_("Get access to extra features: full taxonomy and WooCommerce support, possibility to use custom fields inside the permalinks and more!<br /><strong>Buy Permalink Manager Pro <a href=\\"%s\\" target=\\"\_blank\\">here</a> and save %s using \\"%s\\" coupon code!</strong> Valid until %s!", "permalink-manager"),
217
PERMALINK\_MANAGER\_WEBSITE . "&utm\_campaign=discount\_code",
218
'20%',
219
'NEWYEAR21',
220
'09.01'
221
),
222
'type' => 'notice-info',
223
'show' => 'pro\_hide',
218
\* Set the initial/default admin notices
219
\*
220
\* @param array $alerts
221
\*
222
\* @return array
223
\*/
224
public function default\_alerts( $alerts ) {
225
$default\_alerts = apply\_filters( 'permalink\_manager\_default\_alerts', array(
226
'sample-alert' => array(
227
'txt' => '',
228
'type' => 'notice-info',
229
'show' => 'pro\_hide',
224
230
'plugin\_only' => true,
225
'until' \=> '2021-01-09'
231
'until' \=> '2021-01-09'
226
232
)
227
));
233
) );
228
234
229
235
// Apply the default settings (if empty values) in all settings sections
…
…
232
238
233
239
/\*\*
234
\* Temporary hook
240
\* Make sure that the Permalink Manager options stored in DB match the new structure
235
241
\*/
236
242
function legacy\_support() {
237
243
global $permalink\_manager\_permastructs, $permalink\_manager\_options;
238
244
239
if(isset($permalink\_manager\_options\['base-editor'\])) {
245
if ( isset( $permalink\_manager\_options\['base-editor'\] ) ) {
240
246
$new\_options\['post\_types'\] = $permalink\_manager\_options\['base-editor'\];
241
update\_option('permalink-manager-permastructs', $new\_options);
242
}
243
else if(empty($permalink\_manager\_permastructs\['post\_types'\]) && empty($permalink\_manager\_permastructs\['taxonomies'\]) && count($permalink\_manager\_permastructs) > 0) {
247
update\_option( 'permalink-manager-permastructs', $new\_options );
248
} else if ( empty( $permalink\_manager\_permastructs\['post\_types'\] ) && empty( $permalink\_manager\_permastructs\['taxonomies'\] ) && count( $permalink\_manager\_permastructs ) > 0 ) {
244
249
$new\_options\['post\_types'\] = $permalink\_manager\_permastructs;
245
update\_option('permalink-manager-permastructs', $new\_options);
250
update\_option( 'permalink-manager-permastructs', $new\_options );
246
251
}
247
252
248
253
// Adjust options structure
249
if(!empty($permalink\_manager\_options\['miscellaneous'\])) {
254
if ( ! empty( $permalink\_manager\_options\['miscellaneous'\] ) ) {
255
$permalink\_manager\_unfiltered\_options = $permalink\_manager\_options;
256
250
257
// Combine general & miscellaneous options
251
$permalink\_manager\_unfiltered\_options\['general'\] = array\_merge($permalink\_manager\_unfiltered\_options\['general'\], $permalink\_manager\_unfiltered\_options\['miscellaneous'\]);
258
$permalink\_manager\_unfiltered\_options\['general'\] = array\_merge( $permalink\_manager\_unfiltered\_options\['general'\], $permalink\_manager\_unfiltered\_options\['miscellaneous'\] );
252
259
253
260
// Move licence key to different section
254
$permalink\_manager\_unfiltered\_options\['licence'\]\['licence\_key'\] = (!empty($permalink\_manager\_unfiltered\_options\['miscellaneous'\]\['license\_key'\])) ? $permalink\_manager\_unfiltered\_options\['miscellaneous'\]\['license\_key'\] : "";
261
$permalink\_manager\_unfiltered\_options\['licence'\]\['licence\_key'\] = ( ! empty( $permalink\_manager\_unfiltered\_options\['miscellaneous'\]\['license\_key'\] ) ) ? $permalink\_manager\_unfiltered\_options\['miscellaneous'\]\['license\_key'\] : "";
255
262
}
256
263
257
264
// Separate "Trailing slashes" & "Trailing slashes redirect" setting fields
258
if(!empty($permalink\_manager\_options\['general'\]\['trailing\_slashes'\]) && $permalink\_manager\_options\['general'\]\['trailing\_slashes'\] >= 10) {
259
$permalink\_manager\_unfiltered\_options = (!empty($permalink\_manager\_unfiltered\_options)) ? $permalink\_manager\_unfiltered\_options : $permalink\_manager\_options;
265
if ( ! empty( $permalink\_manager\_options\['general'\]\['trailing\_slashes'\] ) && $permalink\_manager\_options\['general'\]\['trailing\_slashes'\] >= 10 ) {
266
$permalink\_manager\_unfiltered\_options = ( ! empty( $permalink\_manager\_unfiltered\_options ) ) ? $permalink\_manager\_unfiltered\_options : $permalink\_manager\_options;
260
267
261
268
$permalink\_manager\_unfiltered\_options\['general'\]\['trailing\_slashes\_redirect'\] = 1;
262
$permalink\_manager\_unfiltered\_options\['general'\]\['trailing\_slashes'\] \= ($permalink\_manager\_options\['general'\]\['trailing\_slashes'\] == 10) ? 1 : 2;
263
}
264
265
// Adjust WP All Import suport mode
266
if(isset($permalink\_manager\_options\['general'\]\['pmxi\_import\_support'\])) {
267
$permalink\_manager\_unfiltered\_options = (!empty($permalink\_manager\_unfiltered\_options)) ? $permalink\_manager\_unfiltered\_options : $permalink\_manager\_options;
268
269
$permalink\_manager\_unfiltered\_options\['general'\]\['pmxi\_support'\] = (empty($permalink\_manager\_options\['general'\]\['pmxi\_import\_support'\])) ? 1 : 0;
270
unset($permalink\_manager\_unfiltered\_options\['general'\]\['pmxi\_import\_support'\]);
269
$permalink\_manager\_unfiltered\_options\['general'\]\['trailing\_slashes'\] = ( $permalink\_manager\_options\['general'\]\['trailing\_slashes'\] == 10 ) ? 1 : 2;
270
}
271
272
// Adjust WP All Import support mode
273
if ( isset( $permalink\_manager\_options\['general'\]\['pmxi\_import\_support'\] ) ) {
274
$permalink\_manager\_unfiltered\_options = ( ! empty( $permalink\_manager\_unfiltered\_options ) ) ? $permalink\_manager\_unfiltered\_options : $permalink\_manager\_options;
275
276
$permalink\_manager\_unfiltered\_options\['general'\]\['pmxi\_support'\] = ( empty( $permalink\_manager\_options\['general'\]\['pmxi\_import\_support'\] ) ) ? 1 : 0;
277
unset( $permalink\_manager\_unfiltered\_options\['general'\]\['pmxi\_import\_support'\] );
271
278
}
272
279
273
280
// Save the settings in database
274
if(!empty($permalink\_manager\_unfiltered\_options)) {
275
update\_option('permalink-manager', $permalink\_manager\_unfiltered\_options);
281
if ( ! empty( $permalink\_manager\_unfiltered\_options ) ) {
282
update\_option( 'permalink-manager', $permalink\_manager\_unfiltered\_options );
276
283
}
277
284
278
285
// Remove obsolete 'permalink-manager-alerts' from wp\_options table
279
if(get\_option('permalink-manager-alerts')) {
280
delete\_option('permalink-manager-alerts');
281
}
282
}
283
284
/\*\*
285
\* Support deprecated hooks
286
\*/
287
function deprecated\_hooks\_list($filters = true) {
288
$deprecated\_filters = array(
289
'permalink\_manager\_default\_options' => 'permalink-manager-default-options',
290
'permalink\_manager\_options' => 'permalink-manager-options',
291
'permalink\_manager\_uris' => 'permalink-manager-uris',
292
'permalink\_manager\_alerts' => 'permalink-manager-alerts',
293
'permalink\_manager\_redirects' => 'permalink-manager-redirects',
286
if ( get\_option( 'permalink-manager-alerts' ) ) {
287
delete\_option( 'permalink-manager-alerts' );
288
}
289
}
290
291
/\*\*
292
\* Return the array of deprecated hooks
293
\*
294
\* @return array
295
\*/
296
function deprecated\_hooks\_list() {
297
return array(
298
'permalink\_manager\_default\_options' => 'permalink-manager-default-options',
299
'permalink\_manager\_options' => 'permalink-manager-options',
300
'permalink\_manager\_uris' => 'permalink-manager-uris',
301
'permalink\_manager\_redirects' => 'permalink-manager-redirects',
294
302
'permalink\_manager\_external\_redirects' => 'permalink-manager-external-redirects',
295
'permalink\_manager\_permastructs' \=> 'permalink-manager-permastructs',
296
297
'permalink\_manager\_alerts' \=> 'permalink-manager-alerts',
303
'permalink\_manager\_permastructs' \=> 'permalink-manager-permastructs',
304
305
'permalink\_manager\_alerts' \=> 'permalink-manager-alerts',
298
306
'permalink\_manager\_before\_sections' => 'permalink-manager-before-sections',
299
'permalink\_manager\_sections' \=> 'permalink-manager-sections',
300
'permalink\_manager\_after\_sections' \=> 'permalink-manager-after-sections',
301
302
'permalink\_manager\_field\_args' \=> 'permalink-manager-field-args',
307
'permalink\_manager\_sections' \=> 'permalink-manager-sections',
308
'permalink\_manager\_after\_sections' \=> 'permalink-manager-after-sections',
309
310
'permalink\_manager\_field\_args' \=> 'permalink-manager-field-args',
303
311
'permalink\_manager\_field\_output' => 'permalink-manager-field-output',
304
312
305
'permalink\_manager\_deep\_uri\_detect' \=> 'permalink-manager-deep-uri-detect',
306
'permalink\_manager\_detect\_uri' \=> 'permalink-manager-detect-uri',
313
'permalink\_manager\_deep\_uri\_detect' \=> 'permalink-manager-deep-uri-detect',
314
'permalink\_manager\_detect\_uri' \=> 'permalink-manager-detect-uri',
307
315
'permalink\_manager\_detected\_element\_id' => 'permalink-manager-detected-initial-id',
308
'permalink\_manager\_detected\_term\_id' \=> 'permalink-manager-detected-term-id',
309
'permalink\_manager\_detected\_post\_id' \=> 'permalink-manager-detected-post-id',
310
311
'permalink\_manager\_primary\_term' \=> 'permalink-manager-primary-term',
312
'permalink\_manager\_disabled\_post\_types' \=> 'permalink-manager-disabled-post-types',
313
'permalink\_manager\_disabled\_taxonomies' \=> 'permalink-manager-disabled-taxonomies',
314
'permalink\_manager\_endpoints' \=> 'permalink-manager-endpoints',
316
'permalink\_manager\_detected\_term\_id' \=> 'permalink-manager-detected-term-id',
317
'permalink\_manager\_detected\_post\_id' \=> 'permalink-manager-detected-post-id',
318
319
'permalink\_manager\_primary\_term' \=> 'permalink-manager-primary-term',
320
'permalink\_manager\_disabled\_post\_types' \=> 'permalink-manager-disabled-post-types',
321
'permalink\_manager\_disabled\_taxonomies' \=> 'permalink-manager-disabled-taxonomies',
322
'permalink\_manager\_endpoints' \=> 'permalink-manager-endpoints',
315
323
'permalink\_manager\_filter\_permalink\_base' => 'permalink\_manager-filter-permalink-base',
316
'permalink\_manager\_force\_lowercase\_uris' \=> 'permalink-manager-force-lowercase-uris',
324
'permalink\_manager\_force\_lowercase\_uris' \=> 'permalink-manager-force-lowercase-uris',
317
325
318
326
'permalink\_manager\_uri\_editor\_extra\_info' => 'permalink-manager-uri-editor-extra-info',
319
'permalink\_manager\_debug\_fields' \=> 'permalink-manager-debug-fields',
320
'permalink\_manager\_permastructs\_fields' \=> 'permalink-manager-permastructs-fields',
321
'permalink\_manager\_settings\_fields' \=> 'permalink-manager-settings-fields',
322
'permalink\_manager\_tools\_fields' \=> 'permalink-manager-tools-fields',
323
324
'permalink\_manager\_uri\_editor\_columns' \=> 'permalink-manager-uri-editor-columns',
327
'permalink\_manager\_debug\_fields' \=> 'permalink-manager-debug-fields',
328
'permalink\_manager\_permastructs\_fields' \=> 'permalink-manager-permastructs-fields',
329
'permalink\_manager\_settings\_fields' \=> 'permalink-manager-settings-fields',
330
'permalink\_manager\_tools\_fields' \=> 'permalink-manager-tools-fields',
331
332
'permalink\_manager\_uri\_editor\_columns' \=> 'permalink-manager-uri-editor-columns',
325
333
'permalink\_manager\_uri\_editor\_column\_content' => 'permalink-manager-uri-editor-column-content',
326
334
327
335
'permalink\_manager\_redirect\_shop\_archive' => 'permalink-manager-redirect-shop-archive'
328
336
);
329
330
return ($filters) ? $deprecated\_filters : array();
331
}
332
337
}
338
339
/\*\*
340
\* Map the deprecated hooks to their relevant equivalents.
341
\*/
333
342
function deprecated\_hooks() {
334
$deprecated\_filters = (array) $this->deprecated\_hooks\_list(true);
335
foreach($deprecated\_filters as $new => $old) {
336
add\_filter($new, array($this, 'deprecated\_hooks\_mapping'), -1000, 8);
337
}
338
}
339
340
function deprecated\_hooks\_mapping($data) {
341
$deprecated\_filters = $this->deprecated\_hooks\_list(true);
342
$filter = current\_filter();
343
344
if(isset($deprecated\_filters\[$filter\])) {
345
if(has\_filter($deprecated\_filters\[$filter\])) {
343
$deprecated\_filters = $this->deprecated\_hooks\_list();
344
foreach ( $deprecated\_filters as $new => $old ) {
345
add\_filter( $new, array( $this, 'deprecated\_hooks\_mapping' ), - 1000, 8 );
346
}
347
}
348
349
/\*\*
350
\* Apply the deprecated filters to the relevant hooks
351
\*
352
\* @param mixed $data
353
\*
354
\* @return mixed
355
\*/
356
function deprecated\_hooks\_mapping( $data ) {
357
$deprecated\_filters = $this->deprecated\_hooks\_list();
358
$filter = current\_filter();
359
360
if ( isset( $deprecated\_filters\[ $filter \] ) ) {
361
if ( has\_filter( $deprecated\_filters\[ $filter \] ) ) {
346
362
$args = func\_get\_args();
347
$data = apply\_filters\_ref\_array($deprecated\_filters\[$filter\], $args);
363
$data = apply\_filters\_ref\_array( $deprecated\_filters\[ $filter \], $args );
348
364
}
349
365
}
…
…
356
372
\*/
357
373
function is\_pro\_activated() {
358
if(function\_exists('is\_plugin\_active') && is\_plugin\_active('permalink-manager/permalink-manager.php') && is\_plugin\_active('permalink-manager-pro/permalink-manager.php')) {
359
deactivate\_plugins('permalink-manager/permalink-manager.php');
374
if ( function\_exists( 'is\_plugin\_active' ) && is\_plugin\_active( 'permalink-manager/permalink-manager.php' ) && is\_plugin\_active( 'permalink-manager-pro/permalink-manager.php' ) ) {
375
deactivate\_plugins( 'permalink-manager/permalink-manager.php' );
360
376
}
361
377
}
…
…
364
380
365
381
/\*\*
366
\* Begins execution of the plugin.
367
\*/
382
\* Begins execution of the plugin
383
\*/
368
384
function run\_permalink\_manager() {
369
385
global $permalink\_manager;
370
386
371
387
// Do not run when Elementor is opened
372
if((!empty($\_REQUEST\['action'\]) && strpos($\_REQUEST\['action'\], 'elementor') !== false) || isset($\_REQUEST\['elementor-preview'\])) { return; }
388
if ( ( ! empty( $\_REQUEST\['action'\] ) && strpos( $\_REQUEST\['action'\], 'elementor' ) !== false ) || isset( $\_REQUEST\['elementor-preview'\] ) ) {
389
return;
390
}
373
391
374
392
$permalink\_manager = new Permalink\_Manager\_Class();