Making WordPress.org


Ignore:
Timestamp:
11/22/2022 03:39:56 AM (3 years ago)
Author:
dd32
Message:

Theme Previewer: Add support for the 'template' starter content field, this should be stored as postmeta.

See https://wordpress.slack.com/archives/C02RP4Y3K/p1669087439194519

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wp-themes.com/public_html/wp-content/mu-plugins/pub/starter-content.php

    r10870 r12263  
    125125        $this->filter_nav_menus();
    126126        $this->filter_post_thumbnails();
     127        $this->filter_page_template();
    127128        $this->filter_sidebars();
    128129        $this->filter_theme_mods();
     
    174175    public function filter_posts() {
    175176        add_filter( 'posts_pre_query', array( $this, 'filter_page_query' ), 10, 2 );
     177    }
     178
     179    public function filter_page_template() {
     180
     181        add_filter(
     182            'get_post_metadata',
     183            function( $value, $post_id, $meta_key ) {
     184                if ( '_wp_page_template' !== $meta_key ) {
     185                    return $value;
     186                }
     187
     188                $post_data = $this->find_data_by_id( $post_id );
     189
     190                return $post_data['template'] ?? $value;
     191            },
     192            10,
     193            3
     194        );
    176195    }
    177196
Note: See TracChangeset for help on using the changeset viewer.