Wp-calypso: Settings: Related Posts settings are incorrect in Calypso if you previously set in wp-admin

Created on 18 Nov 2015  路  9Comments  路  Source: Automattic/wp-calypso

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:

image

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

image

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.

Site Settings [Type] Bug

Most helpful comment

Confirmed this is still an issue

All 9 comments

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:

  1. Somehow add the options for related posts to DB during a new site creation with some defaults. Idk how I would do this but I think this is the best solution because even though the related posts is a plugin in WPcom, every WPcom site has it enabled since its creation. The downside is that this will apply only to newly created sites.
  2. Copy-paste the same defaults of related posts from wp-admin to Calypso so it says the same thing. I don't like this because there is no relationship between these two and there should be. The upside is that this will apply to all sites, whether created a year ago or now.

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.

Was this page helpful?
0 / 5 - 0 ratings