WordPress.org

Make WordPress Core

Opened 4 months ago

Closed 3 weeks ago

#26660 closed defect (bug) (fixed)

Twenty Fourteen: Featured Content transients block child themes from overriding the number of FC posts

Reported by: kwight Owned by:
Milestone: 3.9 Priority: normal
Severity: normal Version: 3.9
Component: Bundled Theme Keywords: has-patch commit fixed-major
Focuses: Cc:

Description

By creating a child theme, we should be able to change the number of Featured Content posts with our own add_theme_support call and a different max_posts argument. Somehow transients are getting in the way.

To replicate:

  • create and activate a Twenty Fourteen child theme
  • define your own twentyfourteen_setup function
  • change max_posts to something other than 6 in the add_theme_support call
  • notice 6 FC posts are still returned
  • comment out L154 and L190 in the parent theme inc/featured-content.php to disable transients
  • the correct number of posts are now returned

Attachments (2)

26660.diff (562 bytes) - added by MikeHansenMe 4 months ago.
looks like we already have a function with that exact name although not sure back-compat is best place for it.
26660.2.diff (2.8 KB) - added by obenland 4 months ago.

Download all attachments as: .zip

Change History (15)

comment:1 Frank Klein4 months ago

I think that this behavior is not linked to a child theme specifically.

If the transient is set once using the original max_posts parameter, it will be used to display the featured content. Whether you create a child theme or change the value of max_postsin Twenty Fourteen itself, the transient won't be regenerated.

If you clear the transient, a new one is created with the changed parameter and everything works as expected.

comment:2 MikeHansenMe4 months ago

The transient is deleted on post_save and delete_post_tag. Something like this would solve the problem in the TwentyFourteen theme.

function twentyfourteen_switch_theme() {
	delete_transient( 'featured_content_ids' );
}
add_action( 'switch_theme', 'twentyfourteen_switch_theme' );

comment:3 lancewillett4 months ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 3.8.1

MikeHansenMe4 months ago

looks like we already have a function with that exact name although not sure back-compat is best place for it.

comment:4 MikeHansenMe4 months ago

  • Cc mdhansen@… added
  • Keywords has-patch added; needs-patch removed

comment:5 MikeHansenMe4 months ago

  • Keywords needs-testing added

obenland4 months ago

comment:6 obenland4 months ago

Deleting the transient on theme switch indeed solves the issue. We already deleted it on customizer views, so that even if you previewed the theme, the correct amount of posts would show.

There is a second bug though. Since we manually define the quantity parameter to 6, child themes were not able to increase the amount of featured posts by increasing $max_posts. They also have to manually reset the quantity setting through a filter on get_option( 'featured-content' ). We should be able to safely remove that parameter since users didn't have a possibility to change them.

comment:7 follow-up: kwight4 months ago

26660.2.diff works for me. Just noting that every time the max_posts parameter is changed in the add_theme_support call, the user will need to visit the Customizer (or switch themes) to delete the previous transient and see the new number of posts.

comment:8 in reply to: ↑ 7 obenland4 months ago

  • Keywords needs-testing removed

Replying to kwight:

Just noting that every time the max_posts parameter is changed in the add_theme_support call, the user will need to visit the Customizer (or switch themes) to delete the previous transient and see the new number of posts.

If someone changes code like that, I don't think purging the cache is too much to ask. Also, since the Customizer is the only place to change FC settings, changes are they will access it sooner rather than later.

comment:9 nacin3 months ago

  • Milestone changed from 3.8.1 to 3.8.2

comment:10 lancewillett3 months ago

  • Keywords needs-testing commit added

comment:11 lancewillett2 months ago

In 27120:

Twenty Fourteen: delete the featured_content_ids transient on theme switch to make sure child themes can override the Featured Content quantity value. Also remove quantity parameter so child themes can change the amount of featured posts with $max_posts.

Props obenland, see #26660.

comment:12 lancewillett2 months ago

  • Keywords fixed-major added; needs-testing removed

comment:13 nacin3 weeks ago

  • Milestone changed from 3.8.2 to 3.9
  • Resolution set to fixed
  • Status changed from new to closed

lancewillett and I decided that we would be leaving all bundled theme tickets for 3.9. Given the timeline (and lack of severity) we won't be doing a theme update before then.

Note: See TracTickets for help on using tickets.