WordPress.org

Make WordPress Core

Ticket #10337: 10337.10.patch

File 10337.10.patch, 1.6 KB (added by Viper007Bond, 10 years ago)

On theme switch, delete all oEmbed caches for all posts as different themes have different widths.

  • wp-includes/media.php

     
    932932
    933933                // After a post is saved, cache oEmbed items via AJAX
    934934                add_action( 'edit_form_advanced', array(&$this, 'maybe_run_ajax_cache') );
     935
     936                // On theme switch, dump all oEmbed caches (since the theme width can change)
     937                add_action( 'switch_theme', array(&$this, 'delete_all_oembed_caches') );
    935938        }
    936939
    937940        /**
     
    10971100        }
    10981101
    10991102        /**
    1100          * Delete all oEmbed caches.
     1103         * Delete all oEmbed caches for a post.
    11011104         *
    11021105         * @param int $post_ID Post ID to delete the caches for.
    11031106         */
     
    11121115        }
    11131116
    11141117        /**
     1118         * Delete all oEmbed caches for all posts.
     1119         */
     1120        function delete_all_oembed_caches() {
     1121                // Based on delete_post_meta_by_key()
     1122                global $wpdb;
     1123                $post_ids = $wpdb->get_col( "SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key LIKE '_oembed_%'" );
     1124                if ( $post_ids ) {
     1125                        $postmetaids = $wpdb->get_col( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key LIKE '_oembed_%'" );
     1126                        $in = implode( ',', array_fill( 1, count($postmetaids), '%d' ) );
     1127                        do_action( 'delete_postmeta', $postmetaids );
     1128                        $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_id IN($in)", $postmetaids ) );
     1129                        do_action( 'deleted_postmeta', $postmetaids );
     1130                        foreach ( $post_ids as $post_id )
     1131                                wp_cache_delete( $post_id, 'post_meta' );
     1132                        return true;
     1133                }
     1134                return false;
     1135        }
     1136
     1137        /**
    11151138         * Triggers a caching of all oEmbed results.
    11161139         *
    11171140         * @param int $post_ID Post ID to do the caching for.