• Resolved Fencer04

    (@fencer04)


    The plugin does put up a notification about there being a duplicate URL but the admin saves it anyway. I think this is a pretty big bug. Are there plans to resolve this or do you have any instructions on how I’m able to resolve this?

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi @fencer04,

    To be honest, this was done by design. I applied it as a “soft” alert without changing any user-entered permalinks, so the users can decide how to proceed.

    The main reason behind it is that I receive repeated support requests where users wanted to use the plugin to override native taxonomy archive URLs with custom pages built in Elementor or Beaver Builder.

    Your point makes absolute sense, so I will add a new toggle field “Force unique permalinks” in the plugin settings, so the plugin can automatically handle this (if user decides to).

    In the meantime (before new version is released), please use this code snippet as a temp. patch:

    function pm_force_unique_permalink( $new_uri, $post_id, $post = '' ) {
    global $permalink_manager_uris;

    // Determine post ID
    if ( is_a( $post, 'WP_Post' ) ) {
    $post_id = $post->ID;
    } elseif ( ! is_numeric( $post_id ) ) {
    return $new_uri;
    }

    // Copy URIs and exclude current element
    $uris = $permalink_manager_uris;
    unset( $uris[ $post_id ] );

    $uris = array_flip( $uris );

    // Prepare base + extension
    if ( ! preg_match( '/^(.+?)(?:-([\d]+))?(\.[^\.]+$|$)/', $new_uri, $parts ) ) {
    return $new_uri; // fallback if regex fails
    }

    $base = $parts[1];
    $index = empty( $parts[2] ) ? 1 : (int) $parts[2];
    $extension = $parts[3];

    $unique_uri = $new_uri;

    // Increment suffix until URI is unique
    while ( isset( $uris[ $unique_uri ] ) ) {
    $index++;
    $unique_uri = "{$base}-{$index}{$extension}";
    }

    return $unique_uri;
    }
    add_filter( 'permalink_manager_pre_update_post_uri', 'pm_force_unique_permalink', 999, 3 );
    add_filter( 'permalink_manager_filter_default_post_uri', 'pm_force_unique_permalink', 999, 3 );
    Thread Starter Fencer04

    (@fencer04)

    Thank you, that is amazing support. I’ve tested this and it appears to be working on my end. When the update is done I will remove this code.

    Plugin Author Maciej Bis

    (@mbis)

    I am happy to help πŸ™‚

    Once the new version is released, please make sure that “Force unique custom permalinks” option is enabled in the plugin settings:

    Thread Starter Fencer04

    (@fencer04)

    We have the new setting setup on our site and it is working. The only issue is that we are running WPML and are unable to have the same permalink for different lanaguges. For example:

    http://www.url.com/page
    http://www.url.com/es/page

    With the setting turned on it is forcing this instead:

    http://www.url.com/page
    http://www.url.com/es/page-2

    Can you let me know what I need to do to make sure we are able to go back to the previous structure. Each time we edit one of the translations it updates the URL and creates a redirect.

    Plugin Author Maciej Bis

    (@mbis)

    Hi @fencer04,

    The function that forces the unique permalinks ignores the language code, so it will automatically append “-2” to the slug for URLs in the different languages. I will try to adjust this in the next plugin’s release, but for now I would recommend to turn “Force unique custom permalinks” off.

    The quickest way to adjust the previous URLs is to use bulk editor – if you use “-2” as search term – you should be able to find all the affected custom permalinks:

    Thread Starter Fencer04

    (@fencer04)

    Could I turn if off and adjust the function that you provided me earlier in the meantime? If so do you know what change would need to be made?

    Plugin Author Maciej Bis

    (@mbis)

    Yes, I will try to implement the patch to the dev version in the next 1-2 hours. I will get back to you immediately after I finish and double-check it.

    Sorry for the inconvenience!

    Plugin Author Maciej Bis

    (@mbis)

    Could you try to manually overwrite the contents of:

    wp-content/plugins/permalink-manager/includes/core/permalink-manager-helper-functions.php

    file with this code?

    https://pastebin.com/raw/GPeZhMJd

    The new patched function now also should check the language code to prevent the “false positives” when the URLs includes duplicated slug but different language code, so the URL as a whole is unique.

    • This reply was modified 2 months, 2 weeks ago by Maciej Bis.
    Thread Starter Fencer04

    (@fencer04)

    Thank you, I will check on this between today and tomorrow and report back.

    Thread Starter Fencer04

    (@fencer04)

    This did not work. When I removed the “-2” from the permalink it still added it back when I saved the page.

    Plugin Author Maciej Bis

    (@mbis)

    Technically, the “-2” can be appended also if you have auto-update mode enabled + slugs mode uses the default settings (“Use WordPress slugs”).

    Could you send me the screenshot with:

    • Permastructure settings (“Tools -> Permalink Manager -> Permastructures”)
    • General settings (“Tools -> Permalink Manager -> Settings -> General settings”)

    If possible, please also record a short video showing all the steps, so I can reproduce them on my test server.

    • This reply was modified 2 months, 2 weeks ago by Maciej Bis.
    Thread Starter Fencer04

    (@fencer04)

    Here are the screenshots that you asked for. One note is that the permalink structures are the same for English and Spanish.

    Permastructures

    General Settings

    All that happened was saving the page and the -2 was added. If I edit the permalink removing the -2 it gets added back when I click update.

    Plugin Author Maciej Bis

    (@mbis)

    Thanks, everything is set-up correctly. Have you tried to check if it works for more than one specific custom permalink or for more of them?

    Troubleshooting this further can be difficult, because I am not able to reproduce this bug any longer. After I identified it and applied a fix, the Permalink_Manager_Helper_Functions::force_unique_uri() function seem to work as expected.

    I have tested it in several configurations, including both WPML and Polylang – but I think I might missing something – could you possibly record a screencast or send me extra screenshots showing step-by-step how exactly you edit the permalink?

    Thread Starter Fencer04

    (@fencer04)

    I did some more testing on my end and I believe it’s working now. I’m not sure what was wrong with my testing the first couple of times. Is this going to be implemented in a release soon or should I replace this file in my other environments?

    Plugin Author Maciej Bis

    (@mbis)

    Perfect, I am glad that it works correctly now.

    The patch will be added in the next plugin’s release.

Viewing 15 replies - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.