The reviewer of my theme told me that flush_widget_cache() which I have used in one of my widgets is deprecated since version 4.4. I have searched for this method on codex but there is only a description that this function is deprecated and that's it.

Can anybody tell me that which method should i use instead of flush_widget_cache()?

Here is a code spinet from my widget (recent posts):

function update( $new_instance, $old_instance ) {
        $instance = $old_instance;
        $instance['title'] = strip_tags($new_instance['title']);
        $instance['number'] = (int) $new_instance['number'];
        $instance['show_date'] = (bool) $new_instance['show_date'];

        $alloptions = wp_cache_get( 'alloptions', 'options' );
        if ( isset($alloptions['widget_recent_entries']) )

        return $instance;

    function flush_widget_cache() {
        wp_cache_delete('widget_recent_posts', 'widget');


1 Answer 1


The real question is why do you want to cache anything at all. If the widget is a common "recent posts" then all the practical object caching you are doing is mostly a duplication of the caching done in `WP_query' when you query for the posts. Or in other words, the simplest solution is to remove the caching related code.


As @jami0821 pointed out in the comments, the latest version of the theme check tool removes that specific check, so you might ask the reviewer to make sure he uses the latest version. That said, there is still no reason to keep that code around.

  • I agree and I also want to add that the deprecation notice on developer.wordpress.org says "This method has been deprecated. Fragment caching was removed in favor of split queries instead."
    – Jami Gibbs
    Dec 28, 2016 at 12:47
  • Hi @jami0821, your edit is appreciated, but the deprecation notice is on the specific core classes that have that method, not for every class that inherits wp_widget. Someone needs to tell the theme review theme that there are bugs in their tools or procedure. I will let other modes to decide if it was too ranty ;) Dec 28, 2016 at 12:54
  • Good point. I also tracked down where that flag was coming from in the Theme Check plugin and it looks to be removed (for the time being) in the latest release (see Otto's PR desc).
    – Jami Gibbs
    Dec 28, 2016 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.