Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#26660 closed defect (bug) (fixed)

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

Reported by: kwight's profile 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 11 years 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 11 years ago.

Download all attachments as: .zip

Change History (15)

#1 @Frank Klein
11 years 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.

#2 @MikeHansenMe
11 years 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' );

#3 @lancewillett
11 years ago

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

@MikeHansenMe
11 years ago

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

#4 @MikeHansenMe
11 years ago

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

#5 @MikeHansenMe
11 years ago

  • Keywords needs-testing added

@obenland
11 years ago

#6 @obenland
11 years 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.

#7 follow-up: @kwight
11 years 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.

#8 in reply to: ↑ 7 @obenland
11 years 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.

#9 @nacin
11 years ago

  • Milestone changed from 3.8.1 to 3.8.2

#10 @lancewillett
11 years ago

  • Keywords needs-testing commit added

#11 @lancewillett
11 years 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.

#12 @lancewillett
11 years ago

  • Keywords fixed-major added; needs-testing removed

#13 @nacin
11 years 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.