I wanted to disable related posts from my site, so I went to My Sites -> Settings only to find out that the setting was already off:

So, I wondered what wp-admin was saying, and lo-and-behold, it shows something different:

It seems like this is a problem on new sites that have never touched that setting before. Once I flip it between Hide/Show and back again (from either Calypso or wp-admin) then the two pages are in sync.
Confirmed this is still an issue
Confirmed this is still an issue
Right, so this happens because when you create a new site, the settings for related posts is not added to DB. Therefore, the API returns false (as WP's get_option returns false for non-existent settings). However, the wp-admin code for related posts defaults to related posts being enabled when there is no settings in DB. This creates the discrepancy between Calypso and wp-admin.
Now, how to solve this? I got a few ideas. Let me know which is the preferred one or propose yours, please:
Would be great to re-look at this again soon.
@lamosty:
Right, so this happens because when you create a new site, the settings for related posts is not added to DB. Therefore, the API returns false (as WP's get_option returns false for non-existent settings).
Is this even though related posts _are_ enabled for a site even though they aren't in the db?
If this is the case I think option 2 would be best as it applies to all sites (new and existing) and actually makes Calypso show the truth (that related posts are enabled) even though the database record doesn't exist.
If I'm understanding this correctly, I think the issue here is actually that the API endpoint is simply wrong about the status of related posts. The plugin apparently treats an undefined option as 'enabled' => true, which means that the REST API endpoint needs to also use that logic.
That's a relatively simple fix, and I've got a diff with it working, but I want to review more of the code, because it seems that for Jetpack sites and possibly some other sites the value actually does default to false. What we might want to do is to make this a function or a filter, so that the decision is made in a centralized place, rather than everything querying the relatedposts option themselves.
This should solve the issue: D6297
Pinged @alisterscott, @lezama, and @lancewillett for review on the diff.
reviewed! thanks!
Committed and deployed.
Most helpful comment
Confirmed this is still an issue