PluginProbe ʕ •ᴥ•ʔ
Permalink Manager Lite / 2.4.3.3
Permalink Manager Lite v2.4.3.3
2.5.4 2.5.3.4 2.2.18 2.2.19.2 2.2.19.3 2.2.19.3.1 2.2.2 2.2.20 2.2.20.1 2.2.20.3 2.2.4 2.2.5 2.2.6 2.2.7.2 2.2.7.3 2.2.7.5 2.2.7.6 2.2.8.4 2.2.8.5 2.2.8.6 2.2.8.7 2.2.8.9 2.2.9.1 2.2.9.2 2.2.9.2.1 2.2.9.3 2.2.9.4 2.2.9.6 2.2.9.7 2.2.9.9 2.3.0 2.3.1.1 2.4.0 2.4.1 2.4.1.2 2.4.1.3 2.4.1.4 2.4.1.5 2.4.1.6 2.4.2 2.4.2.1 2.4.3 2.4.3.1 2.4.3.2 2.4.3.3 2.4.3.4 2.4.4 2.4.4.1 2.4.4.2 2.4.4.3 2.5.0 2.5.1 2.5.1.1 2.5.1.2 2.5.1.3 2.5.1.4 2.5.2 2.5.2.1 2.5.2.2 2.5.2.3 2.5.2.4 2.5.3 2.5.3.1 2.5.3.2 2.5.3.3 trunk 0.2 0.3 0.3.1 0.3.2 0.3.3 0.3.4 0.4 0.4.1 0.4.2 0.4.3 0.4.4 0.4.6 0.4.7 0.4.8 0.4.9 0.5.3 0.5.4 1.0.0 1.0.1 1.0.4 1.1.0 1.1.1 1.1.2 1.11.6.3 2.0.0 2.0.3 2.0.4 2.0.4.3 2.0.5.1 2.0.5.2 2.0.5.3 2.0.5.3.1 2.0.5.4 2.0.5.4a 2.0.5.5 2.0.5.6 2.0.5.6.1 2.0.5.7 2.0.5.9a 2.0.6.2.1 2.0.6.2a 2.0.6.3 2.1.0 2.1.1 2.1.2.4 2.2.0 2.2.1.1 2.2.1.2 2.2.11 2.2.12 2.2.13.1 2.2.14 2.2.15.1 2.2.16 2.2.17
permalink-manager / includes / integrations / permalink-manager-third-parties.php
permalink-manager / includes / integrations Last commit date
permalink-manager-language-plugins.php 2 years ago permalink-manager-seo-plugins.php 2 years ago permalink-manager-third-parties.php 2 years ago permalink-manager-woocommerce.php 2 years ago
permalink-manager-third-parties.php
1141 lines
1 <?php
2
3 /**
4 * Third parties integration
5 */
6 class Permalink_Manager_Third_Parties {
7
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
13 /**
14 * Add support for 3rd party plugins using their hooks
15 */
16 function init_hooks() {
17 global $permalink_manager_options;
18
19 // Stop redirect
20 add_action( 'wp', array( $this, 'stop_redirect' ), 2 );
21
22 // 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 // AMP for WP
29 if ( defined( 'AMPFORWP_AMP_QUERY_VAR' ) ) {
30 add_filter( 'permalink_manager_filter_query', array( $this, 'detect_amp_for_wp' ), 5 );
31 }
32
33 // Theme My Login
34 if ( class_exists( 'Theme_My_Login' ) ) {
35 add_action( 'wp', array( $this, 'tml_ignore_custom_permalinks' ), 10 );
36 }
37
38 // Revisionize
39 if ( defined( 'REVISIONIZE_ROOT' ) ) {
40 add_action( 'revisionize_after_create_revision', array( $this, 'revisionize_keep_post_uri' ), 9, 2 );
41 add_action( 'revisionize_before_publish', array( $this, 'revisionize_clone_uri' ), 9, 2 );
42 }
43
44 // WP All Import
45 if ( class_exists( 'PMXI_Plugin' ) && ( ! empty( $permalink_manager_options['general']['pmxi_support'] ) ) ) {
46 add_action( 'pmxi_extend_options_featured', array( $this, 'wpaiextra_uri_display' ), 9, 2 );
47 add_filter( 'pmxi_options_options', array( $this, 'wpai_api_options' ) );
48 add_filter( 'pmxi_addons', array( $this, 'wpai_api_register' ) );
49 add_filter( 'wp_all_import_addon_parse', array( $this, 'wpai_api_parse' ) );
50 add_filter( 'wp_all_import_addon_import', array( $this, 'wpai_api_import' ) );
51
52 add_action( 'pmxi_saved_post', array( $this, 'wpai_save_redirects' ) );
53
54 add_action( 'pmxi_after_xml_import', array( $this, 'wpai_schedule_regenerate_uris_after_xml_import' ), 10, 1 );
55 add_action( 'wpai_regenerate_uris_after_import_event', array( $this, 'wpai_regenerate_uris_after_import' ), 10, 1 );
56 }
57
58 // WP All Export
59 if ( class_exists( 'PMXE_Plugin' ) && ( ! empty( $permalink_manager_options['general']['pmxi_support'] ) ) ) {
60 add_filter( 'wp_all_export_available_sections', array( $this, 'wpae_custom_uri_section' ), 9 );
61 add_filter( 'wp_all_export_available_data', array( $this, 'wpae_custom_uri_section_fields' ), 9 );
62 add_filter( 'wp_all_export_csv_rows', array( $this, 'wpae_export_custom_uri' ), 10, 2 );
63 }
64
65 // Duplicate Post
66 if ( defined( 'DUPLICATE_POST_CURRENT_VERSION' ) ) {
67 add_action( 'dp_duplicate_post', array( $this, 'duplicate_custom_uri' ), 100, 2 );
68 add_action( 'dp_duplicate_page', array( $this, 'duplicate_custom_uri' ), 100, 2 );
69 }
70
71 // My Listing by 27collective
72 if ( class_exists( '\MyListing\Post_Types' ) ) {
73 add_filter( 'permalink_manager_filter_default_post_uri', array( $this, 'ml_listing_custom_fields' ), 5, 5 );
74 add_action( 'mylisting/submission/save-listing-data', array( $this, 'ml_set_listing_uri' ), 100 );
75 add_filter( 'permalink_manager_filter_query', array( $this, 'ml_detect_archives' ), 1, 2 );
76 }
77
78 // bbPress
79 if ( class_exists( 'bbPress' ) && function_exists( 'bbp_get_edit_slug' ) ) {
80 add_filter( 'permalink_manager_endpoints', array( $this, 'bbpress_endpoints' ), 9 );
81 add_action( 'wp', array( $this, 'bbpress_detect_endpoints' ), 0 );
82 }
83
84 // Dokan
85 if ( class_exists( 'WeDevs_Dokan' ) ) {
86 add_action( 'wp', array( $this, 'dokan_detect_endpoints' ), 999 );
87 add_filter( 'permalink_manager_endpoints', array( $this, 'dokan_endpoints' ) );
88 }
89
90 // GeoDirectory
91 if ( class_exists( 'GeoDirectory' ) ) {
92 add_filter( 'permalink_manager_filter_default_post_uri', array( $this, 'geodir_custom_fields' ), 5, 5 );
93 }
94
95 // BasePress
96 if ( class_exists( 'Basepress' ) ) {
97 add_filter( 'permalink_manager_filter_query', array( $this, 'kb_adjust_query' ), 5, 5 );
98 }
99
100 // Ultimate Member
101 if ( class_exists( 'UM' ) && ! ( empty( $permalink_manager_options['general']['um_support'] ) ) ) {
102 add_filter( 'permalink_manager_detect_uri', array( $this, 'um_detect_extra_pages' ), 20 );
103 }
104
105 // LearnPress
106 if ( class_exists( 'LearnPress' ) ) {
107 add_filter( 'permalink_manager_excluded_post_ids', array( $this, 'learnpress_exclude_pages' ) );
108 }
109
110 // Google Site Kit
111 if ( class_exists( '\Google\Site_Kit\Plugin' ) ) {
112 add_filter( 'request', array( $this, 'googlesitekit_fix_request' ), 10, 1 );
113 }
114 }
115
116 /**
117 * Some hooks must be called shortly after all the plugins are loaded
118 */
119 public function init_early_hooks() {
120 // WP Store Locator
121 if ( class_exists( 'WPSL_CSV' ) ) {
122 add_action( 'added_post_meta', array( $this, 'wpsl_regenerate_after_import' ), 10, 4 );
123 add_action( 'updated_post_meta', array( $this, 'wpsl_regenerate_after_import' ), 10, 4 );
124 }
125 }
126
127 /**
128 * Stop canonical redirect if specific query variables are set
129 */
130 public static function stop_redirect() {
131 global $wp_query, $post;
132
133 if ( ! empty( $wp_query->query ) ) {
134 $query_vars = $wp_query->query;
135
136 // WordPress Photo Seller Plugin
137 if ( ! empty( $query_vars['image_id'] ) && ! empty( $query_vars['gallery_id'] ) ) {
138 $wp_query->query_vars['do_not_redirect'] = 1;
139 } // Ultimate Member
140 else if ( ! empty( $query_vars['um_user'] ) || ! empty( $query_vars['um_tab'] ) || ( ! empty( $query_vars['provider'] ) && ! empty( $query_vars['state'] ) ) ) {
141 $wp_query->query_vars['do_not_redirect'] = 1;
142 } // Mailster
143 else if ( ! empty( $query_vars['_mailster_page'] ) ) {
144 $wp_query->query_vars['do_not_redirect'] = 1;
145 } // WP Route
146 else if ( ! empty( $query_vars['WP_Route'] ) ) {
147 $wp_query->query_vars['do_not_redirect'] = 1;
148 } // WooCommerce Wishlist
149 else if ( ! empty( $query_vars['wishlist-action'] ) ) {
150 $wp_query->query_vars['do_not_redirect'] = 1;
151 } // UserPro
152 else if ( ! empty( $query_vars['up_username'] ) ) {
153 $wp_query->query_vars['do_not_redirect'] = 1;
154 } // The Events Calendar
155 else if ( ! empty( $query_vars['eventDisplay'] ) ) {
156 $wp_query->query_vars['do_not_redirect'] = 1;
157 } // Groundhogg
158 else if ( class_exists( '\Groundhogg\Plugin' ) && ! empty( $query_vars['subpage'] ) ) {
159 $wp_query->query_vars['do_not_redirect'] = 1;
160 } // MyListing theme
161 else if ( ! empty( $query_vars['explore_tab'] ) || ! empty( $query_vars['explore_region'] ) || ! empty( $_POST['submit_job'] ) ) {
162 $wp_query->query_vars['do_not_redirect'] = 1;
163 } // GeoDirectory
164 else if ( function_exists( 'geodir_location_page_id' ) && ! empty( $post->ID ) && geodir_location_page_id() == $post->ID ) {
165 $wp_query->query_vars['do_not_redirect'] = 1;
166 } // RankMath Pro
167 else if ( isset( $query_vars['schema-preview'] ) ) {
168 $wp_query->query_vars['do_not_redirect'] = 1;
169 } // Theme.co - Pro Theme
170 else if ( ! empty( $_POST['_cs_nonce'] ) ) {
171 $wp_query->query_vars['do_not_redirect'] = 1;
172 } // Tutor LMS
173 else if ( ! empty( $query_vars['tutor_dashboard_page'] ) ) {
174 $wp_query->query_vars['do_not_redirect'] = 1;
175 } // AMP
176 else if ( function_exists( 'amp_get_slug' ) && array_key_exists( amp_get_slug(), $query_vars ) ) {
177 $wp_query->query_vars['do_not_redirect'] = 1;
178 }
179
180 // LearnPress
181 if ( ! empty( $query_vars['view'] ) && ! empty( $query_vars['page_id'] ) ) {
182 $wp_query->query_vars['do_not_redirect'] = 1;
183 }
184 }
185
186 // WPForo
187 if ( defined( 'WPFORO_VERSION' ) ) {
188 $forum_page_id = get_option( 'wpforo_pageid' );
189
190 if ( ! empty( $forum_page_id ) && ! empty( $post->ID ) && $forum_page_id == $post->ID ) {
191 $wp_query->query_vars['do_not_redirect'] = 1;
192 }
193 }
194 }
195
196 /**
197 * AMP hooks (support for older versions)
198 *
199 * @param array $uri_parts
200 * @param string $request_url
201 *
202 * @return array
203 */
204 function detect_amp( $uri_parts, $request_url ) {
205 global $amp_enabled;
206
207 if ( defined( 'AMP_QUERY_VAR' ) ) {
208 $amp_query_var = AMP_QUERY_VAR;
209
210 // Check if AMP should be triggered
211 preg_match( "/^(.+?)\/({$amp_query_var})?\/?$/i", $uri_parts['uri'], $regex_parts );
212 if ( ! empty( $regex_parts[2] ) ) {
213 $uri_parts['uri'] = $regex_parts[1];
214 $amp_enabled = true;
215 }
216 }
217
218 return $uri_parts;
219 }
220
221 /**
222 * AMP hooks
223 *
224 * @param array $query
225 *
226 * @return array
227 */
228 function enable_amp( $query ) {
229 global $amp_enabled;
230
231 if ( ! empty( $amp_enabled ) && defined( 'AMP_QUERY_VAR' ) ) {
232 $query[ AMP_QUERY_VAR ] = 1;
233 }
234
235 return $query;
236 }
237
238 /**
239 * AMP for WP hooks (support for older versions)
240 *
241 * @param array $query
242 *
243 * @return array
244 */
245 function detect_amp_for_wp( $query ) {
246 global $wp_rewrite, $pm_query;
247
248 if ( defined( 'AMPFORWP_AMP_QUERY_VAR' ) ) {
249 $amp_endpoint = AMPFORWP_AMP_QUERY_VAR;
250 $paged_endpoint = $wp_rewrite->pagination_base;
251
252 if ( ! empty( $pm_query['endpoint'] ) && strpos( $pm_query['endpoint_value'], "{$paged_endpoint}/" ) !== false ) {
253 $paged_val = preg_replace( "/({$paged_endpoint}\/)([\d]+)/", '$2', $pm_query['endpoint_value'] );
254
255 if ( ! empty( $paged_val ) ) {
256 $query[ $amp_endpoint ] = 1;
257 $query['paged'] = $paged_val;
258 }
259 }
260 }
261
262 return $query;
263 }
264
265 /**
266 * Parse Custom Permalinks import
267 */
268 public static function custom_permalinks_uris() {
269 global $wpdb;
270
271 $custom_permalinks_uris = array();
272
273 // List tags/categories
274 $table = get_option( 'custom_permalink_table' );
275 if ( $table && is_array( $table ) ) {
276 foreach ( $table as $permalink => $info ) {
277 $custom_permalinks_uris[] = array(
278 'id' => "tax-" . $info['id'],
279 'uri' => trim( $permalink, "/" )
280 );
281 }
282 }
283
284 // List posts/pages
285 $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 != '';";
286 $posts = $wpdb->get_results( $query );
287 foreach ( $posts as $post ) {
288 $custom_permalinks_uris[] = array(
289 'id' => $post->ID,
290 'uri' => trim( $post->meta_value, "/" ),
291 );
292 }
293
294 return $custom_permalinks_uris;
295 }
296
297 /**
298 * Import the URIs from the Custom Permalinks plugin.
299 */
300 static public function import_custom_permalinks_uris() {
301 global $permalink_manager_before_sections_html;
302
303 $custom_permalinks_plugin = 'custom-permalinks/custom-permalinks.php';
304
305 if ( is_plugin_active( $custom_permalinks_plugin ) && ! empty( $_POST['disable_custom_permalinks'] ) ) {
306 deactivate_plugins( $custom_permalinks_plugin );
307 }
308
309 // Get a list of imported URIs
310 $custom_permalinks_uris = self::custom_permalinks_uris();
311
312 if ( ! empty( $custom_permalinks_uris ) && count( $custom_permalinks_uris ) > 0 ) {
313 foreach ( $custom_permalinks_uris as $item ) {
314 $item_uri = $item['uri'];
315
316 // Decode custom permalink if contains percent-encoded characters
317 if ( preg_match( '/%[0-9A-F]{2}/i', $item_uri ) ) {
318 $item_uri = urldecode( $item_uri );
319 }
320
321 Permalink_Manager_URI_Functions::save_single_uri( $item['id'], $item_uri, false, false );
322 }
323
324 $permalink_manager_before_sections_html .= Permalink_Manager_UI_Elements::get_alert_message( __( '"Custom Permalinks" URIs were imported!', 'permalink-manager' ), 'updated' );
325 Permalink_Manager_URI_Functions::save_all_uris();
326 } else {
327 $permalink_manager_before_sections_html .= Permalink_Manager_UI_Elements::get_alert_message( __( 'No "Custom Permalinks" URIs were imported!', 'permalink-manager' ), 'error' );
328 }
329 }
330
331 /**
332 * Do not use custom permalinks if any action is triggered inside Theme My Login plugin
333 */
334 function tml_ignore_custom_permalinks() {
335 global $wp, $permalink_manager_ignore_permalink_filters;
336
337 if ( isset( $wp->query_vars['action'] ) || ! empty( $_GET['redirect_to'] ) ) {
338 $permalink_manager_ignore_permalink_filters = true;
339
340 // Allow the canonical redirect (if blocked earlier by Permalink Manager)
341 if ( ! empty( $wp_query->query_vars['do_not_redirect'] ) ) {
342 $wp_query->query_vars['do_not_redirect'] = 0;
343 }
344 }
345 }
346
347 /**
348 * Copy the custom URI from original post and apply it to the new temp. revision post (Revisionize)
349 *
350 * @param int $old_id
351 * @param int $new_id
352 */
353 function revisionize_keep_post_uri( $old_id, $new_id ) {
354 $old_uri = Permalink_Manager_URI_Functions::get_single_uri( $old_id, false, true );
355
356 if ( ! empty( $old_uri ) ) {
357 Permalink_Manager_URI_Functions::save_single_uri( $new_id, $old_uri, false, true );
358 }
359 }
360
361 /**
362 * Copy the custom URI from revision post and apply it to the original post
363 *
364 * @param int $old_id
365 * @param int $new_id
366 */
367 function revisionize_clone_uri( $old_id, $new_id ) {
368 $new_uri = Permalink_Manager_URI_Functions::get_single_uri( $new_id, false, true );
369
370 if ( ! empty( $new_uri ) ) {
371 Permalink_Manager_URI_Functions::save_single_uri( $old_id, $new_uri, false, true );
372 Permalink_Manager_URI_Functions::remove_single_uri( $new_id, false, true );
373 }
374 }
375
376 /**
377 * Add a new section to the WP All Import interface
378 *
379 * @param string $content_type The type of content being imported
380 * @param array $current_values An array of the current values for the post
381 */
382 function wpaiextra_uri_display( $content_type, $current_values ) {
383 // Check if post type is supported
384 if ( $content_type !== 'taxonomies' && Permalink_Manager_Helper_Functions::is_post_type_disabled( $content_type ) ) {
385 return;
386 }
387
388 // Get custom URI format
389 $custom_uri = ( ! empty( $current_values['custom_uri'] ) ) ? sanitize_text_field( $current_values['custom_uri'] ) : "";
390
391 $html = '<div class="wpallimport-collapsed closed wpallimport-section">';
392 $html .= '<div class="wpallimport-content-section">';
393 $html .= sprintf( '<div class="wpallimport-collapsed-header"><h3>%s</h3></div>', __( 'Permalink Manager', 'permalink-manager' ) );
394 $html .= '<div class="wpallimport-collapsed-content">';
395
396 $html .= '<div class="template_input">';
397 $html .= Permalink_Manager_UI_Elements::generate_option_field( 'custom_uri', array( 'extra_atts' => 'style="width:100%; line-height: 25px;"', 'placeholder' => __( 'Custom URI', 'permalink-manager' ), 'value' => $custom_uri ) );
398 $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( '&section=permastructs' ) ) );
399 $html .= '</div>';
400
401 $html .= '</div>';
402 $html .= '</div>';
403 $html .= '</div>';
404
405 echo $html;
406 }
407
408 /**
409 * Add a new field to the list of WP All Import options
410 *
411 * @param array $all_options The array of all options that are currently set
412 *
413 * @return array The array of all options plus the custom_uri option
414 */
415 function wpai_api_options( $all_options ) {
416 return $all_options + array( 'custom_uri' => null );
417 }
418
419 /**
420 * Add Permalink Manager plugin to the WP All Import API
421 *
422 * @param array $addons
423 *
424 * @return array
425 */
426 function wpai_api_register( $addons ) {
427 if ( empty( $addons[ PERMALINK_MANAGER_PLUGIN_SLUG ] ) ) {
428 $addons[ PERMALINK_MANAGER_PLUGIN_SLUG ] = 1;
429 }
430
431 return $addons;
432 }
433
434 /**
435 * Register function that parses Permalink Manager plugin data in WP All Import API data feed
436 *
437 * @param array $functions
438 *
439 * @return array
440 */
441 function wpai_api_parse( $functions ) {
442 $functions[ PERMALINK_MANAGER_PLUGIN_SLUG ] = array( $this, 'wpai_api_parse_function' );
443
444 return $functions;
445 }
446
447 /**
448 * Register function that saves Permalink Manager plugin data extracted from WP All Import API data feed
449 *
450 * @param array $functions
451 *
452 * @return array
453 */
454 function wpai_api_import( $functions ) {
455 $functions[ PERMALINK_MANAGER_PLUGIN_SLUG ] = array( $this, 'wpai_api_import_function' );
456
457 return $functions;
458 }
459
460 /**
461 * Parse Permalink Manager plugin data in WP All Import API data feed
462 *
463 * @param array $data
464 *
465 * @return array
466 */
467 function wpai_api_parse_function( $data ) {
468 extract( $data );
469
470 $data = array(); // parsed data
471 $option_name = 'custom_uri';
472
473 if ( ! empty( $import->options[ $option_name ] ) && class_exists( 'XmlImportParser' ) ) {
474 $cxpath = $xpath_prefix . $import->xpath;
475 $tmp_files = array();
476
477 if ( isset( $import->options[ $option_name ] ) && $import->options[ $option_name ] != '' ) {
478 if ( $import->options[ $option_name ] == "xpath" ) {
479 $data[ $option_name ] = XmlImportParser::factory( $xml, $cxpath, (string) $import->options['xpaths'][ $option_name ], $file )->parse();
480 } else {
481 $data[ $option_name ] = XmlImportParser::factory( $xml, $cxpath, (string) $import->options[ $option_name ], $file )->parse();
482 }
483
484 $tmp_files[] = $file;
485 } else {
486 $data[ $option_name ] = array_fill( 0, $count, "" );
487 }
488
489 foreach ( $tmp_files as $file ) {
490 unlink( $file );
491 }
492 }
493
494 return $data;
495 }
496
497 /**
498 * Save the Permalink Manager plugin data extracted from WP All Import API data feed
499 *
500 * @param array $importData
501 * @param array $parsedData
502 */
503 function wpai_api_import_function( $importData, $parsedData ) {
504 // Check if the array with $parsedData is not empty
505 if ( empty( $parsedData ) || empty( $importData['post_type'] ) ) {
506 return;
507 }
508
509 // Check if the imported elements are terms
510 if ( $importData['post_type'] == 'taxonomies' ) {
511 $is_term = true;
512 } else if ( Permalink_Manager_Helper_Functions::is_post_type_disabled( $importData['post_type'] ) ) {
513 return;
514 }
515
516 // Get the parsed custom URI
517 $index = ( isset( $importData['i'] ) ) ? $importData['i'] : false;
518 $pid = ( ! empty( $importData['pid'] ) ) ? (int) $importData['pid'] : false;
519
520 if ( isset( $index ) && ! empty( $pid ) && ! empty( $parsedData['custom_uri'][ $index ] ) ) {
521 $new_uri = Permalink_Manager_Helper_Functions::sanitize_title( $parsedData['custom_uri'][ $index ] );
522
523 if ( ! empty( $new_uri ) ) {
524 if ( ! empty( $is_term ) ) {
525 $default_uri = Permalink_Manager_URI_Functions_Tax::get_default_term_uri( $pid );
526 $native_uri = Permalink_Manager_URI_Functions_Tax::get_default_term_uri( $pid, true );
527 $custom_uri = Permalink_Manager_URI_Functions_Tax::get_term_uri( $pid, false, true );
528 $old_uri = ( ! empty( $custom_uri ) ) ? $custom_uri : $native_uri;
529
530 if ( $new_uri !== $old_uri ) {
531 Permalink_Manager_URI_Functions::save_single_uri( $pid, $new_uri, true, true );
532 do_action( 'permalink_manager_updated_term_uri', $pid, $new_uri, $old_uri, $native_uri, $default_uri, $single_update = true, $uri_saved = true );
533 }
534 } else {
535 $default_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri( $pid );
536 $native_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri( $pid, true );
537 $custom_uri = Permalink_Manager_URI_Functions_Post::get_post_uri( $pid, false, true );
538 $old_uri = ( ! empty( $custom_uri ) ) ? $custom_uri : $native_uri;
539
540 if ( $new_uri !== $old_uri ) {
541 Permalink_Manager_URI_Functions::save_single_uri( $pid, $new_uri, false, true );
542 do_action( 'permalink_manager_updated_post_uri', $pid, $new_uri, $old_uri, $native_uri, $default_uri, $single_update = true, $uri_saved = true );
543 }
544 }
545 }
546 }
547 }
548
549 /**
550 * Copy the external redirect from the "external_redirect" custom field to the data model used by Permalink Manager Pro
551 *
552 * @param int $pid The post ID of the post being imported.
553 */
554 function wpai_save_redirects( $pid ) {
555 $external_url = get_post_meta( $pid, '_external_redirect', true );
556 $external_url = ( empty( $external_url ) ) ? get_post_meta( $pid, 'external_redirect', true ) : $external_url;
557
558 if ( $external_url && class_exists( 'Permalink_Manager_Pro_Functions' ) ) {
559 Permalink_Manager_Pro_Functions::save_external_redirect( $external_url, $pid );
560 }
561 }
562
563 /**
564 * 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
565 *
566 * @param int $import_id The ID of the import.
567 */
568 function wpai_schedule_regenerate_uris_after_xml_import( $import_id ) {
569 global $wpdb;
570
571 $post_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}pmxi_posts WHERE import_id = {$import_id}" );
572 $chunks = array_chunk( $post_ids, 200 );
573
574 // Schedule URI regenerate and split into bulks
575 foreach ( $chunks as $i => $chunk ) {
576 wp_schedule_single_event( time() + ( $i * 30 ), 'wpai_regenerate_uris_after_import_event', array( $chunk ) );
577 }
578 }
579
580 /**
581 * Regenerate the custom permalinks for all imported posts
582 *
583 * @param array $post_ids An array of post IDs that were just imported.
584 */
585 function wpai_regenerate_uris_after_import( $post_ids ) {
586 global $permalink_manager_uris;
587
588 if ( ! is_array( $post_ids ) ) {
589 return;
590 }
591
592 foreach ( $post_ids as $id ) {
593 if ( ! empty( $permalink_manager_uris[ $id ] ) ) {
594 continue;
595 }
596
597 $post_object = get_post( $id );
598
599 // Check if post is allowed
600 if ( empty( $post_object->post_type ) || Permalink_Manager_Helper_Functions::is_post_excluded( $post_object, true ) ) {
601 continue;
602 }
603
604 $default_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri( $id );
605 Permalink_Manager_URI_Functions::save_single_uri( $id, $default_uri );
606 }
607
608 Permalink_Manager_URI_Functions::save_all_uris();
609 }
610
611 /**
612 * Add a new section to the WP All Export interface
613 *
614 * @param array $sections
615 *
616 * @return array
617 */
618 function wpae_custom_uri_section( $sections ) {
619 if ( is_array( $sections ) ) {
620 $sections['permalink_manager'] = array(
621 'title' => __( 'Permalink Manager', 'permalink-manager' ),
622 'content' => 'permalink_manager_fields'
623 );
624 }
625
626 return $sections;
627 }
628
629 /**
630 * Add a new field to the "Permalink Manager" section of the WP All Export interface
631 *
632 * @param array $fields The fields to be displayed in the section.
633 *
634 * @return array
635 */
636 function wpae_custom_uri_section_fields( $fields ) {
637 if ( is_array( $fields ) ) {
638 $fields['permalink_manager_fields'] = array(
639 array(
640 'label' => 'custom_uri',
641 'name' => 'Custom URI',
642 'type' => 'custom_uri'
643 )
644 );
645 }
646
647 return $fields;
648 }
649
650 /**
651 * Add a new column to the export file with the custom permalink for each post/term
652 *
653 * @param array $articles The array of articles to be exported.
654 * @param array $options an array of options for the export.
655 *
656 * @return array
657 */
658 function wpae_export_custom_uri( $articles, $options ) {
659 if ( ( ! empty( $options['selected_post_type'] ) && $options['selected_post_type'] == 'taxonomies' ) || ! empty( $options['is_taxonomy_export'] ) ) {
660 $is_term = true;
661 } else {
662 $is_term = false;
663 }
664
665 foreach ( $articles as &$article ) {
666 if ( ! empty( $article['id'] ) ) {
667 $item_id = $article['id'];
668 } else if ( ! empty( $article['ID'] ) ) {
669 $item_id = $article['ID'];
670 } else if ( ! empty( $article['Term ID'] ) ) {
671 $item_id = $article['Term ID'];
672 } else {
673 continue;
674 }
675
676 if ( ! empty( $is_term ) ) {
677 $article['Custom URI'] = Permalink_Manager_URI_Functions_Tax::get_term_uri( $item_id );
678 } else {
679 $article['Custom URI'] = Permalink_Manager_URI_Functions_Post::get_post_uri( $item_id );
680 }
681 }
682
683 return $articles;
684 }
685
686 /**
687 * 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
688 *
689 * @param int $new_post_id The ID of the newly created post.
690 * @param WP_Post $old_post The post object of the original post.
691 */
692 function duplicate_custom_uri( $new_post_id, $old_post ) {
693 global $permalink_manager_uris;
694
695 $duplicate_post_blacklist = get_option( 'duplicate_post_blacklist', false );
696 $duplicate_custom_uri_bool = ( ! empty( $duplicate_post_blacklist ) && strpos( $duplicate_post_blacklist, 'custom_uri' ) !== false ) ? false : true;
697
698 if ( ! empty( $old_post->ID ) && $duplicate_custom_uri_bool ) {
699 $old_post_id = $old_post->ID;
700
701 // Clone custom permalink (if set for cloned post/page)
702 if ( ! empty( $permalink_manager_uris[ $old_post_id ] ) ) {
703 $old_post_uri = $permalink_manager_uris[ $old_post_id ];
704 $new_post_uri = preg_replace( '/(.+?)(\.[^\.]+$|$)/', '$1-2$2', $old_post_uri );
705
706 Permalink_Manager_URI_Functions::save_single_uri( $new_post_id, $new_post_uri, false, true );
707 }
708 }
709 }
710
711 /**
712 * Replace in the default permalink format the unique permastructure tags available for My Listing theme
713 *
714 * @param string $default_uri The default permalink for the element.
715 * @param string $native_slug The native slug of the post type.
716 * @param WP_Post $element The post object.
717 * @param string $slug The slug of the post type.
718 * @param bool $native_uri
719 *
720 * @return string
721 */
722 public function ml_listing_custom_fields( $default_uri, $native_slug, $element, $slug, $native_uri ) {
723 // Use only for "listing" post type & custom permalink
724 if ( empty( $element->post_type ) || $element->post_type !== 'job_listing' ) {
725 return $default_uri;
726 }
727
728 // A1. Listing type
729 if ( strpos( $default_uri, '%listing-type%' ) !== false || strpos( $default_uri, '%listing_type%' ) !== false ) {
730 if ( class_exists( 'MyListing\Src\Listing' ) ) {
731 $listing_type_post = MyListing\Src\Listing::get( $element );
732 $listing_type = ( is_object( $listing_type_post ) && ! empty( $listing_type_post->type ) ) ? $listing_type_post->type->get_permalink_name() : '';
733 } else {
734 $listing_type_slug = get_post_meta( $element->ID, '_case27_listing_type', true );
735 $listing_type_post = get_page_by_path( $listing_type_slug, OBJECT, 'case27_listing_type' );
736
737 if ( ! empty( $listing_type_post ) ) {
738 $listing_type_post_settings = get_post_meta( $listing_type_post->ID, 'case27_listing_type_settings_page', true );
739 $listing_type_post_settings = ( is_serialized( $listing_type_post_settings ) ) ? unserialize( $listing_type_post_settings ) : array();
740
741 $listing_type = ( ! empty( $listing_type_post_settings['permalink'] ) ) ? $listing_type_post_settings['permalink'] : $listing_type_post->post_name;
742 }
743 }
744
745 if ( ! empty( $listing_type ) ) {
746 $default_uri = str_replace( array( '%listing-type%', '%listing_type%' ), Permalink_Manager_Helper_Functions::sanitize_title( $listing_type, true ), $default_uri );
747 }
748 }
749
750 // A2. Listing type (slug)
751 if ( strpos( $default_uri, '%listing-type-slug%' ) !== false || strpos( $default_uri, '%listing_type_slug%' ) !== false || strpos( $default_uri, '%case27_listing_type%' ) !== false ) {
752 $listing_type = get_post_meta( $element->ID, '_case27_listing_type', true );
753
754 if ( ! empty( $listing_type ) ) {
755 $listing_type = Permalink_Manager_Helper_Functions::sanitize_title( $listing_type, true );
756 $default_uri = str_replace( array( '%listing-type-slug%', '%listing_type_slug%', '%case27_listing_type%' ), $listing_type, $default_uri );
757 }
758 }
759
760 // B. Listing location
761 if ( strpos( $default_uri, '%listing-location%' ) !== false || strpos( $default_uri, '%listing_location%' ) !== false ) {
762 $listing_location = get_post_meta( $element->ID, '_job_location', true );
763
764 if ( ! empty( $listing_location ) ) {
765 $listing_location = Permalink_Manager_Helper_Functions::sanitize_title( $listing_location, true );
766 $default_uri = str_replace( array( '%listing-location%', '%listing_location%' ), $listing_location, $default_uri );
767 }
768 }
769
770 // C. Listing region
771 if ( strpos( $default_uri, '%listing-region%' ) !== false || strpos( $default_uri, '%listing_region%' ) !== false ) {
772 $listing_region_terms = wp_get_object_terms( $element->ID, 'region' );
773 $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 ) : "";
774
775 if ( ! empty( $listing_region_term ) ) {
776 $listing_region = Permalink_Manager_Helper_Functions::get_term_full_slug( $listing_region_term, $listing_region_terms, 2 );
777 $listing_region = Permalink_Manager_Helper_Functions::sanitize_title( $listing_region, true );
778
779 $default_uri = str_replace( array( '%listing-region%', '%listing_region%' ), $listing_region, $default_uri );
780 }
781 }
782
783 // D. Listing category
784 if ( strpos( $default_uri, '%listing-category%' ) !== false || strpos( $default_uri, '%listing_category%' ) !== false ) {
785 $listing_category_terms = wp_get_object_terms( $element->ID, 'job_listing_category' );
786 $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 ) : "";
787
788 if ( ! empty( $listing_category_term ) ) {
789 $listing_category = Permalink_Manager_Helper_Functions::get_term_full_slug( $listing_category_term, $listing_category_terms, 2 );
790 $listing_category = Permalink_Manager_Helper_Functions::sanitize_title( $listing_category, true );
791
792 $default_uri = str_replace( array( '%listing-category%', '%listing_category%' ), $listing_category, $default_uri );
793 }
794 }
795
796 return $default_uri;
797 }
798
799 /**
800 * Set the default custom permalink for the listing item when it is created
801 *
802 * @param int $post_id
803 */
804 function ml_set_listing_uri( $post_id ) {
805 $default_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri( $post_id );
806
807 if ( $default_uri ) {
808 Permalink_Manager_URI_Functions::save_single_uri( $post_id, $default_uri, false, true );
809 }
810 }
811
812 /**
813 * If the user is on a MyListing archive page submitting a job, redirect the user to the Explore Listings page
814 *
815 * @param array $query The query object.
816 * @param array $old_query The original query array.
817 *
818 * @return array The new query array is being returned if the explore_tab property is present. Otherwise, the original query is returned.
819 */
820 function ml_detect_archives( $query, $old_query ) {
821 if ( function_exists( 'mylisting_custom_taxonomies' ) && empty( $_POST['submit_job'] ) ) {
822 $explore_page_id = get_option( 'options_general_explore_listings_page', false );
823 if ( empty( $explore_page_id ) ) {
824 return $query;
825 }
826
827 // Set-up new query array variable
828 $new_query = array(
829 "page_id" => $explore_page_id
830 );
831
832 // Check if any custom MyListing taxonomy was detected
833 $ml_taxonomies = mylisting_custom_taxonomies();
834
835 if ( ! empty( $ml_taxonomies ) && is_array( $ml_taxonomies ) ) {
836 $ml_taxonomies = array_keys( $ml_taxonomies );
837
838 foreach ( $ml_taxonomies as $taxonomy ) {
839 if ( ! empty( $query[ $taxonomy ] ) && empty( $_GET[ $taxonomy ] ) ) {
840 $new_query["explore_tab"] = $taxonomy;
841 $new_query["explore_{$taxonomy}"] = $query['term'];
842 }
843 }
844 }
845
846 // Check if any MyListing query var was detected
847 $ml_query_vars = array(
848 'explore_tag' => 'tags',
849 'explore_region' => 'regions',
850 'explore_category' => 'categories'
851 );
852
853 foreach ( $ml_query_vars as $query_var => $explore_tab ) {
854 if ( ! empty( $old_query[ $query_var ] ) && empty( $_GET[ $query_var ] ) ) {
855 $new_query[ $query_var ] = $old_query[ $query_var ];
856 $new_query["explore_tab"] = $explore_tab;
857 }
858 }
859 }
860
861 return ( ! empty( $new_query["explore_tab"] ) ) ? $new_query : $query;
862 }
863
864 /**
865 * Add the bbPress endpoints to the list of endpoints that are supported by the plugin
866 *
867 * @param string $endpoints
868 * @param bool $all Whether to return all endpoints or just the bbPress ones
869 *
870 * @return string|array
871 */
872 function bbpress_endpoints( $endpoints, $all = true ) {
873 $bbpress_endpoints = array();
874 $bbpress_endpoints[] = bbp_get_edit_slug();
875
876 return ( $all ) ? $endpoints . "|" . implode( "|", $bbpress_endpoints ) : $bbpress_endpoints;
877 }
878
879 /**
880 * If the query contains the edit endpoint, then set the appropriate bbPress query variable
881 */
882 function bbpress_detect_endpoints() {
883 global $wp_query;
884
885 if ( ! empty( $wp_query->query ) ) {
886 $edit_endpoint = bbp_get_edit_slug();
887
888 if ( isset( $wp_query->query[ $edit_endpoint ] ) ) {
889 if ( isset( $wp_query->query['forum'] ) ) {
890 $wp_query->bbp_is_forum_edit = true;
891 } else if ( isset( $wp_query->query['topic'] ) ) {
892 $wp_query->bbp_is_topic_edit = true;
893 } else if ( isset( $wp_query->query['reply'] ) ) {
894 $wp_query->bbp_is_reply_edit = true;
895 }
896 }
897 }
898 }
899
900 /**
901 * Add the endpoint "edit" used by Dokan to the endpoints array supported by Permalink Manager
902 *
903 * @param string $endpoints
904 *
905 * @return string
906 */
907 function dokan_endpoints( $endpoints ) {
908 return "{$endpoints}|edit|edit-account";
909 }
910
911 /**
912 * Check if the current page is a Dokan page, and if so, adjust the query variables to disable the canonical redirect
913 */
914 function dokan_detect_endpoints() {
915 global $post, $wp_query, $wp, $pm_query;
916
917 // Check if Dokan is activated
918 if ( ! function_exists( 'dokan_get_option' ) || is_admin() || empty( $pm_query['id'] ) ) {
919 return;
920 }
921
922 // Get Dokan dashboard page id
923 $dashboard_page = dokan_get_option( 'dashboard', 'dokan_pages' );
924
925 // Stop the redirect
926 if ( ! empty( $dashboard_page ) && ! empty( $post->ID ) && ( $post->ID == $dashboard_page ) ) {
927 $wp_query->query_vars['do_not_redirect'] = 1;
928
929 // Detect Dokan shortcode
930 if ( empty( $pm_query['endpoint'] ) ) {
931 $wp->query_vars['page'] = 1;
932 } else if ( isset( $wp->query_vars['page'] ) ) {
933 unset( $wp->query_vars['page'] );
934 }
935 }
936
937 // Support "Edit Product" pages
938 if ( isset( $wp_query->query_vars['edit'] ) ) {
939 $wp_query->query_vars['edit'] = 1;
940 $wp_query->query_vars['do_not_redirect'] = 1;
941 }
942 }
943
944 /**
945 * Replace in the default permalink format the unique permastructure tags available for GeoDirectory plugin
946 *
947 * @param string $default_uri The default permalink for the element.
948 * @param string $native_slug The native slug of the post type.
949 * @param WP_Post $element The post object.
950 * @param string $slug The slug of the post type.
951 * @param bool $native_uri
952 *
953 * @return string
954 */
955 public function geodir_custom_fields( $default_uri, $native_slug, $element, $slug, $native_uri ) {
956 // Use only for GeoDirectory post types & custom permalinks
957 if ( empty( $element->post_type ) || ( strpos( $element->post_type, 'gd_' ) === false ) || $native_uri || ! function_exists( 'geodir_get_post_info' ) ) {
958 return $default_uri;
959 }
960
961 // Get place info
962 $place_data = geodir_get_post_info( $element->ID );
963
964 // A. Category
965 if ( strpos( $default_uri, '%category%' ) !== false ) {
966 $place_category_terms = wp_get_object_terms( $element->ID, 'gd_placecategory' );
967 $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 ) : "";
968
969 if ( ! empty( $place_category_term ) && is_a( $place_category_term, 'WP_Term' ) ) {
970 $place_category = Permalink_Manager_Helper_Functions::get_term_full_slug( $place_category_term, '', 2 );
971 $place_category = Permalink_Manager_Helper_Functions::sanitize_title( $place_category, true );
972
973 $default_uri = str_replace( '%category%', $place_category, $default_uri );
974 }
975 }
976
977 // B. Country
978 if ( strpos( $default_uri, '%country%' ) !== false && ! empty( $place_data->country ) ) {
979 $place_country = Permalink_Manager_Helper_Functions::sanitize_title( $place_data->country, true );
980 $default_uri = str_replace( '%country%', $place_country, $default_uri );
981 }
982
983 // C. Region
984 if ( strpos( $default_uri, '%region%' ) !== false && ! empty( $place_data->region ) ) {
985 $place_region = Permalink_Manager_Helper_Functions::sanitize_title( $place_data->region, true );
986 $default_uri = str_replace( '%region%', $place_region, $default_uri );
987 }
988
989 // D. City
990 if ( strpos( $default_uri, '%city%' ) !== false && ! empty( $place_data->city ) ) {
991 $place_city = Permalink_Manager_Helper_Functions::sanitize_title( $place_data->city, true );
992 $default_uri = str_replace( '%city%', $place_city, $default_uri );
993 }
994
995 return $default_uri;
996 }
997
998 /**
999 * Adjust the query if BasePress page is detected
1000 *
1001 * @param array $query The query object.
1002 * @param array $old_query The original query array.
1003 * @param array $uri_parts An array of the URI parts.
1004 * @param array $pm_query
1005 * @param string $content_type
1006 *
1007 * @return array
1008 */
1009 function kb_adjust_query( $query, $old_query, $uri_parts, $pm_query, $content_type ) {
1010 $knowledgebase_options = get_option( 'basepress_settings' );
1011 $knowledgebase_page = ( ! empty( $knowledgebase_options['entry_page'] ) ) ? $knowledgebase_options['entry_page'] : '';
1012
1013 // A. Knowledgebase category
1014 if ( isset( $query['knowledgebase_cat'] ) && ! empty( $pm_query['id'] ) ) {
1015 $kb_category = $query['knowledgebase_cat'];
1016
1017 $query = array(
1018 'post_type' => 'knowledgebase',
1019 'knowledgebase_items' => $kb_category
1020 );
1021
1022 // Disable the canonical redirect function included in BasePress
1023 add_filter( 'basepress_canonical_redirect', '__return_false' );
1024 } // B. Knowledgebase main page
1025 else if ( ! empty( $knowledgebase_page ) && ! empty( $pm_query['id'] ) && $pm_query['id'] == $knowledgebase_page ) {
1026 $query = array(
1027 'page_id' => $knowledgebase_page
1028 );
1029 }
1030
1031 return $query;
1032 }
1033
1034 /**
1035 * Detect the extra pages created by Ultimate Member plugin
1036 *
1037 * @param array $uri_parts
1038 *
1039 * @return array
1040 */
1041 public function um_detect_extra_pages( $uri_parts ) {
1042 global $permalink_manager_uris;
1043
1044 if ( ! function_exists( 'UM' ) ) {
1045 return $uri_parts;
1046 }
1047
1048 $request_url = trim( "{$uri_parts['uri']}/{$uri_parts['endpoint_value']}", "/" );
1049 $um_pages = array(
1050 'user' => 'um_user',
1051 'account' => 'um_tab',
1052 );
1053
1054 // Detect UM permalinks
1055 foreach ( $um_pages as $um_page => $query_var ) {
1056 $um_page_id = UM()->config()->permalinks[ $um_page ];
1057 // Support for WPML/Polylang
1058 $um_page_id = ( ! empty( $uri_parts['lang'] ) ) ? apply_filters( 'wpml_object_id', $um_page_id, 'page', true, $uri_parts['lang'] ) : $um_page_id;
1059
1060 if ( ! empty( $um_page_id ) && ! empty( $permalink_manager_uris[ $um_page_id ] ) ) {
1061 $user_page_uri = preg_quote( $permalink_manager_uris[ $um_page_id ], '/' );
1062 preg_match( "/^({$user_page_uri})\/([^\/]+)?$/", $request_url, $parts );
1063
1064 if ( ! empty( $parts[2] ) ) {
1065 $uri_parts['uri'] = $parts[1];
1066 $uri_parts['endpoint'] = $query_var;
1067 $uri_parts['endpoint_value'] = Permalink_Manager_Helper_Functions::sanitize_title( $parts[2], null, null, false );
1068 }
1069 }
1070 }
1071
1072 return $uri_parts;
1073 }
1074
1075 /**
1076 * Excluding the LearnPress pages from Permalink Manager
1077 *
1078 * @param array $excluded_ids
1079 *
1080 * @return array
1081 */
1082 function learnpress_exclude_pages( $excluded_ids ) {
1083 if ( is_array( $excluded_ids ) && function_exists( 'learn_press_get_page_id' ) ) {
1084 $learnpress_pages = array( 'profile', 'courses', 'checkout', 'become_a_teacher' );
1085
1086 foreach ( $learnpress_pages as $page ) {
1087 $learnpress_page_id = learn_press_get_page_id( $page );
1088
1089 if ( empty( $learnpress_page_id ) || in_array( $learnpress_page_id, $excluded_ids ) ) {
1090 continue;
1091 }
1092
1093 $excluded_ids[] = $learnpress_page_id;
1094 }
1095 }
1096
1097 return $excluded_ids;
1098 }
1099
1100 /**
1101 * Regenerate the default permalink for the post after the custom permalink is imported by Store Locator - CSV Manager
1102 *
1103 * @param int $meta_id The ID of the metadata entry.
1104 * @param int $post_id The ID of the post that the metadata is for.
1105 * @param string $meta_key The meta key of the metadata being updated.
1106 * @param mixed $meta_value The value of the meta key.
1107 */
1108 public function wpsl_regenerate_after_import( $meta_id, $post_id, $meta_key, $meta_value ) {
1109 if ( strpos( $meta_key, 'wpsl_' ) !== false && isset( $_POST['wpsl_csv_import_nonce'] ) ) {
1110 $default_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri( $post_id );
1111
1112 if ( $default_uri ) {
1113 Permalink_Manager_URI_Functions::save_single_uri( $post_id, $default_uri, false, true );
1114 }
1115 }
1116 }
1117
1118 /**
1119 * Support custom permalinks in query functions used by Google Site Kit plugin
1120 *
1121 * @param $request
1122 *
1123 * @return array
1124 */
1125 function googlesitekit_fix_request( $request ) {
1126 if ( ! empty( $_GET['permaLink'] ) && ! empty( $_GET['page'] ) && $_GET['page'] === 'googlesitekit-dashboard' ) {
1127 global $pm_query;
1128
1129 $old_url = trim( esc_url_raw( $_GET['permaLink'] ), '/' );
1130 $new_query = Permalink_Manager_Core_Functions::detect_post( array(), $old_url );
1131
1132 if ( ! empty( $new_query ) && ! empty( $pm_query['id'] ) ) {
1133 $request = $new_query;
1134 }
1135 }
1136
1137 return $request;
1138 }
1139
1140 }
1141