Not creating same Post Type (v2.39)
-
Hi,
I’ve come across an issue where the “Duplicate Post to” link isn’t duplicating the post as the same post type (eg. if I’m duplicating a Page, it creates a Post):
See screenshots here: https://drive.google.com/drive/folders/1gt99PuKXzs-CmFPQmm-Q9uH98_V8Bhp7?usp=sharing
-
Thanks Nick. Please Save the settings (if you haven’t yet, and with the settings you want) and let me know if the issue persists.
I tried that (without changing any settings, because I didn’t want them changed) but that didn’t seem to make a difference.
Then, I tried:
- Setting the Post Type setting to “Page”,
- Saving
- Setting the Post Type setting to “Same as original”,
- Saving
- (for some reason, now Post Status setting is set to “Draft”?)
- Now “Duplicate Page to” says, “Duplicate {Post Type}”
- Change Post Status setting back to “Same as Original”
- Saving
It all appears to be working again now.
So, I guess mainly an issue with retaining the settings after the Settings page update?
-
This reply was modified 3 weeks, 2 days ago by
Nick Sinclair.
Interesting. Thanks for the testing and relaying your steps.
I’ve run a few more tests locally, but for some reason I’m not able to replicate the issue. If you get a chance to test it on one of your other sites let me know if you run into the same issue.
I’ll continue to run more tests as well. Thanks again for the help!
Just tested it on another site, this time upgrading from v2.36
Same thing happened. Same steps to reproduce, even with Post Status getting set to Draft when I didn’t tell it to.
I’ll try on a completely vanilla version of WordPress and let you know. It’s possible it’s my setup, but I can’t see how yet.
Okay, tried on a completely vanilla version (WP 6.7.1, PHP 8.0) using InstaWP.
This time, I installed an old version first (v2.37 for reference). Then, after updating to the latest version, I came across the same issues as I mentioned.
You may not be coming across it if you install it from v2.39 directly – try starting with a pre-v2.38 version and updating it instead.
Thanks again. I’ve ran a couple tests on sites that did not previously use the plugin, first installing version 2.35 and then updating to the latest version.
I do see that the default Post Status setting on the old version is “Same as Original” but I have the default in the new version set to “Draft”. So, that would make a difference if the settings where never saved prior to updating the plugin. Does this seem like this could be the issue you are seeing?
The default Post Type setting is the same between old and new plugins, though. Did you see the post type issue on the other sites you tested on well?
I do see that the default Post Status setting on the old version is “Same as Original” but I have the default in the new version set to “Draft”. So, that would make a difference if the settings where never saved prior to updating the plugin. Does this seem like this could be the issue you are seeing?
Yeah, that makes sense – I’ve never saved/changed the Settings from the default for this plugin on any site. I’ve never needed to.
I tested again with vanilla WP 6.7.1, PHP 8.0 on InstaWP installing v2.37 first.
- Install v2.37
- Noticed the default Post Status setting here is also “Draft”!
- Save default settings
- Update to v2.39
- Everything works as expected!
The default Post Type setting is the same between old and new plugins, though. Did you see the post type issue on the other sites you tested on well?
Yes it looks like the issue was happening because the settings were not set in the database already. I’m not sure if there’s a way around that or if you even want to bother trying to fix it.
I imagine a lot of people probably would never adjust the default settings though and would likely come across this issue after updating too…
Nick, thanks for confirming. The only difference in default values with the updated plugin is the post status using draft now. I think I’ll leave that as is since I believe that’s the best option to use when duplicating a post.
Unfortunately, I hadn’t been saving data about the current version being used on a site, so I have no way of knowing if someone is upgrading or installing fresh. If I did I could have checked and automatically saved the post status as ‘same’ if users were still using default values (for upgrades). I’ll be pushing a small update soon that starts tracking this so in the future I can apply necessary adjustments for existing installs on updates (if needed).
Thanks again for your time helping me work through this, I greatly appreciate it. Having limited time to work on these things, it helps to have users willing to communicate and be involved. Have a great day!
Hi,
I’m not sure if v2.40 resolved the issue, but I wanted to try an experiment anyway.
I inserted the following code into your includes/settings.php file:
add_action( 'pre_plugin_update', 'mtphr_post_duplicator_initialize_settings' );
then I ran my test again with this patch and everything seemed to work (but updated to v2.40 instead of v2.39). I didn’t need to re-save the settings in the admin area or anything like that.
The thinking was to get the plugin to save its config settings prior to updating in an attempt to “force” it to stick.
Not sure if that helps or not, just thought I’d share.
Thanks Nick – I found I had a bit of a discrepancy in my previous code. If you had never saved the settings the default post status would be “same”. But, I had a different default post status on the save function set to “draft”. So if you hit save on the settings page without any adjustments to the settings, the post status settings would be updated to “draft”.
- You must be logged in to reply to this topic.