• Resolved Pratham

    (@pratham2003)


    Hi,

    I found a case where find/replace does not work and I might have also found the cause of the bug. I’ll try to explain this with an example.

    e.g.
    postname default URI: /fruits/apples/abc
    assument ‘apple’ is a parent page of ‘abc’
    post_type: ‘fruits’

    If the following permastruct is added after the posts have been created
    permastruct: /fruits/%postname_flat%

    Find/replace of custom URI does not change any URIs (API response says ‘No slugs were updated’)
    find: ‘fruits/apples/’
    replace_with: ‘fruits/’

    The following piece of code in function get_default_post_uri incorrectly returns the default URI as /fruits/abc (even though it’s presently /fruits/apple/abc)

    $default_permastruct = Permalink_Manager_Helper_Functions::get_default_permastruct($post_type);
    if($native_uri) {
    	$permastruct = $default_permastruct;
    } else {
    	$permastruct = (isset($permalink_manager_permastructs['post_types'][$post_type])) ? $permalink_manager_permastructs['post_types'][$post_type] : $default_permastruct;
    }

    which prevents function find_and_replace from working as expected as ($old = $default_uri == $new_uri)
    Screenshot: https://i.imgur.com/oJLSHbp.png

    • This topic was modified 7 years, 8 months ago by Pratham.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi @pratham2003,

    thank you, I will take a look at this and let you know once it is fixed. I am going to release a new version of plugin on Monday/Tuesday.

    Best regards,
    Maciej

    Plugin Author Maciej Bis

    (@mbis)

    Hi again @pratham2003,

    I analyzed your case and I think that we have some misunderstanding here. Find and replace function uses the actual (current) URI as a source, not the default one.

    get_default_post_uri() function does not return the actual or current permalink, but it is used to indicate what URI should be used (based on permastructure settings) if a user creates a new post.

    Anyway, you are right but the problem is here:
    http://prntscr.com/lstexm

    If no actual custom permalink is set with my plugin, “Find and replace” should not use default custom permalink based on permastructure settings, but native permalink (as it is used before a custom permalink is set).

    Basically, this line of code:
    $old_uri = (isset($permalink_manager_uris[$row['ID']])) ? $permalink_manager_uris[$row['ID']] : $default_uri;

    should be replaced with:
    $old_uri = (isset($permalink_manager_uris[$row['ID']])) ? $permalink_manager_uris[$row['ID']] : $native_uri;

    Best regards,
    Maciej

    Thread Starter Pratham

    (@pratham2003)

    Thanks!

    Oh yes, I believe I had misunderstood the usage of get_default_post_uri() back then.
    Thanks for the additional information 🙂

    This is a good plugin compared to other alternatives I’ve used in the past.

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

The topic ‘Find-Replace not working in a certain scenario’ is closed to new replies.