samiahmedsiddiqui / custom-permalinks

Set custom permalinks on a per-post basis in WordPress
https://wordpress.org/plugins/custom-permalinks/
GNU General Public License v3.0
20 stars 20 forks source link

Console error: wp-json/custom-permalinks/v1/get-permalink/4556 401 (Unathorized) script-form-1.7.1.min.js?ver=5.7.2:1 #50

Closed mikehues closed 2 months ago

mikehues commented 3 years ago

Wordpress 5.7.2 Twenty Twenty-One 1.3 Custom Permalinks 1.7.1

I disabled all other plugins and created a new page. I edit the page and make a simple text change and click 'Update'. Shortly after the "Page update. View Page" message pops up at the bottom of the page, this error shows up in the console:

GET https://testsite.local//wp-json/custom-permalinks/v1/get-permalink/4556 401 (Unauthorized). script-form-1.7.1.min.js?ver=5.7.2:1 updateMetaBox | @ | script-form-1.7.1.min.js?ver=5.7.2:1 (anonymous) | @ | data.min.js?ver=9430…126df689839bb96b9:2 i | @ | data.min.js?ver=9430…126df689839bb96b9:2 . . .

The changes to the page content are successfully saved, so it doesn't pose much of a problem until you try to update the permalink. If you change the permalink and click 'Update', the same thing happens. But now, the 'View Page' links still point to the old permalink. If you click any of these links (top admin bar, Custom permalink metabox button & lower left 'page updated' popup) you get a page not found.

Please let me know if you need additional info.

thanks,

Mike

samiahmedsiddiqui commented 3 years ago

Hi @mikehues

Sorry for facing this issue. Can you please check whether this is still an issue for you or already fixed in the new version. I am not able to generate it in the new version. If you are still able to generate this issue then please let me know.

Thanks, Sami

mikehues commented 3 years ago

Hi Sami,

Sorry it took so long for me to reply. Looks like the issue is partly resolved with the new version.

updated versions: Wordpress 5.8 Twenty Twenty One 1.4 Custom Permalinks 2.0.1

When I update the custom permalink, there is no longer an error in the console. Also, the 'View Page' button link in the Custom Permalinks metabox is updated correctly. But, the view page links in the top admin bar and the bottom popup still point to the previous permalink. After playing around for a bit, here are some observations I've made.

My expectations are based on the wordpress core behavior, which is as follows:

  1. I goto example.local/mens and I change the permalink slug from 'mens' to 'foo'
  2. The 'view page' links are updated and point to example.local/foo. I click the link and the page loads at the new permalink.
  3. if I goto the old permalink (example.local/mens) I get a 'page not found'

Here's a simple example which has unexpected, but acceptable results. (This wouldn't technically require the Custom Permalinks plugin, since there is no directory structure in this url.)

  1. I goto example.local/mens and I change the permalink to example.local/foo
  2. I click one of the links that still points to example.local/mens and I'm redirected to example.local/foo
  3. if I go back to the old permalink (example.local/mens) I'm redirected to example.local/foo

So, I don't get a 'page not found', when clicking the view page links, which is good. But, the redirect was unexpected.

Here's where I start to run into trouble:

  1. I goto example.local/foo and I change the permalink to example.local/bar
  2. I click one of the links that still points to example.local/foo and I get 'page not found'
  3. if I goto the original permalink (example.local/mens) I'm redirected to example.local/bar

Here's another example with a directory structure:

  1. I goto example.local/womens/place and I change the permalink to example.local/womens/test
  2. I click one of the links that still points to example.local/womens/place and the page loads at the old permalink
  3. if I goto the new permalink (example.local/womens/test) the page loads successfully.

So, now the page is available at two different urls, which is unexpected and not ideal.

Please let me know if I can provide anymore info.

thanks,

Mike

samiahmedsiddiqui commented 3 years ago

@mikehues Thank you for detailed reply.

Here's another example with a directory structure:

  1. I goto example.local/womens/place and I change the permalink to example.local/womens/test
  2. I click one of the links that still points to example.local/womens/place and the page loads at the old permalink
  3. if I goto the new permalink (example.local/womens/test) the page loads successfully.

In this case, old permalink should redirect to the new permalink instead of serving the page. (I will check if I am able to re-produce this issue on my end).

samiahmedsiddiqui commented 3 years ago

@mikehues I have released v2.2.0 that fixes couple of issues you have pointed. Can you please test your pointed issues with the v2.2.0?

mikehues commented 3 years ago

Hi Sami,

thanks for your work on this.

I just ran the same tests with version 2.2.0

I can confirm that, upon updating the permalink, all three 'View Page' links are updated to the new permalink. So, this has fixed the issue of clicking 'view page' and getting 'page not found' or seeing the page at the old permalink. But, if I manually type in the old permalink, the page loads successfully at that url instead of redirecting to the new url.

thanks,

Mike

samiahmedsiddiqui commented 3 years ago

But, if I manually type in the old permalink, the page loads successfully at that url instead of redirecting to the new url.

@mikehues old permalink means old customized permalink or WP permalink? Also, can you please test this after deactivating all the other plugins and switching to the default theme?

If you still able to crawl the old permalink then please provide me an example.

In actual, old customized permalink should not work and throws 404. Redirect needs to be manually added or wait for the next release in which I will add redirect functionality as well.

mikehues commented 3 years ago

Hi Sami,

I did test with all other plugins disabled and using twentytwentyone theme. Old customized permalinks throw 404s as expected, but the original WP permalink still loads

I repeated this test with a directory structure:

  1. I goto example.local/womens/place and I change the permalink to example.local/womens/test
  2. All 'view page' links point to example.local/womens/test as expected <-- fixed in new version
  3. Change permalink again to example.local/womens/test-again
  4. I goto the new custom permalink - example.local/womens/test-again <-- the page loads successfully
  5. I goto the old custom permalink - example.local/womens/test <-- throws 404 as expected
  6. I goto the original WP permalink - example.local/womens/place <-- the page loads successfully. seems like it should redirect so the page is not available at two different urls

thanks,

Mike