Skip to content

Commit

Permalink
Migrate to active templates
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Dec 30, 2024
1 parent 2b0264c commit 7f3f955
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 35 additions & 0 deletions lib/compat/wordpress-6.8/template-activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,38 @@ function gutenberg_set_active_template_theme( $changes, $request ) {
);
return $changes;
}

// Migrate existing "edited" templates. By existing, it means that the template
// is active.
add_action( 'init', 'gutenberg_migrate_existing_templates' );
function gutenberg_migrate_existing_templates() {
$active_templates = get_option( 'active_templates' );

if ( $active_templates ) {
return;
}

// Query all templates in the database. See `get_block_templates`.
$template_query = array(

Check warning on line 143 in lib/compat/wordpress-6.8/template-activate.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Unused variable $template_query.
'post_status' => array( 'publish' ),
'post_type' => 'wp_template',
'posts_per_page' => -1,
'no_found_rows' => true,
'lazy_load_term_meta' => false,
'tax_query' => array(
array(
'taxonomy' => 'wp_theme',
'field' => 'name',
'terms' => get_stylesheet(),
),
),
);

$active_templates = array();

foreach ( $templates as $template ) {

Check warning on line 160 in lib/compat/wordpress-6.8/template-activate.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Variable $templates is undefined.
$active_templates[ $template->post_name ] = $template->ID;
}

update_option( 'active_templates', $active_templates );
}
2 changes: 0 additions & 2 deletions packages/edit-site/src/components/page-templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ export default function PageTemplates() {
}, [ layout, activeView ] );
const [ view, setView ] = useState( defaultView );

console.log( view );

// Sync the layout from the URL to the view state.
useEffect( () => {
setView( ( currentView ) => ( {
Expand Down

0 comments on commit 7f3f955

Please sign in to comment.