Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme Templates: Fix display issues of Offline & Day of Event templates across themes #316

Merged
merged 5 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions public_html/wp-content/mu-plugins/theme-templates/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,9 @@

defined( 'WPINC' ) || die();

add_filter( 'theme_page_templates', __NAMESPACE__ . '\register_page_templates' );
add_filter( 'template_include', __NAMESPACE__ . '\set_page_template_locations' );
add_filter( 'template_include', __NAMESPACE__ . '\inject_offline_template', 20 ); // After others because being offline transcends other templates.
add_filter( 'wp_offline_error_precache_entry', __NAMESPACE__ . '\add_offline_template_cachebuster' );

/**
* Add new templates to the Page Template dropdown in the editor.
*
* @param array $templates
*
* @return array
*/
function register_page_templates( $templates ) {
/*
* Remove CampSite 2017's Day of template, since it's redundant, and having multiple templates in the menu
* would be confusing.
*/
if ( isset( $templates['templates/page-day-of.php'] ) ) {
unset( $templates['templates/page-day-of.php'] );
}

$templates['day-of-event'] = __( 'Day of Event', 'wordcamporg' );

natsort( $templates );
return $templates;
}

/**
* Tell WP where to load the templates from.
*
* @param string $template_path
*
* @return string
*/
function set_page_template_locations( $template_path ) {
global $post;

if ( ! $post instanceof WP_Post ) {
return $template_path;
}

switch ( $post->_wp_page_template ) {
case 'day-of-event':
$template_path = __DIR__ . '/templates/day-of-event.php';
break;
}

return $template_path;
}

/**
* Inject the offline template when the service worker pre-caches the response to offline requests.
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,68 @@

namespace WordCamp\Theme_Templates;

get_header();

$offline_page = get_offline_content();
?>

<main id="main" class="site-main">
<section class="error-offline">
<header class="page-header">
<h1 class="page-title">
<?php echo wp_kses_post( $offline_page['title'] ); ?>
</h1>
</header>

<div class="page-content">
<?php echo wp_kses_post( $offline_page['content'] ); ?>
</div>
</section>
</main>
$site_description = get_bloginfo( 'description' );
?><!DOCTYPE html>

<?php
<html class="no-js" <?php language_attributes(); ?>>

<head>

<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1.0" >

<link rel="profile" href="https://gmpg.org/xfn/11">

<?php wp_head(); ?>
<style>
.offline-container {
margin: 5vh auto;
padding: 2em;
max-width: 46em;
}
.theme-twentyfourteen .offline-container {
padding-top: 1px; /* Prevents margin collapse. */
background: white;
}
.theme-twentyfifteen:before { /* Remove the sidebar background– there is no sidebar. */
display: none;
}
.theme-twentyfifteen .offline-container,
.theme-twentysixteen .offline-container {
background: white;
}
.theme-twentytwenty section {
padding-top: 0;
}
</style>

</head>

<body <?php body_class( array( 'theme-' . get_template(), 'page-offline' ) ); ?>>
<div class="offline-container">
<header>
<h1>
<?php echo esc_html( get_bloginfo( 'name' ) ); ?>
</h1>
<?php if ( $site_description ) : ?>
<p><?php echo esc_html( $site_description ); ?></p>
<?php endif; ?>
</header>
<main>
<section>
<header>
<h2>
<?php echo wp_kses_post( $offline_page['title'] ); ?>
</h2>
</header>

get_footer();
<div>
<?php echo wp_kses_post( $offline_page['content'] ); ?>
</div>
</section>
</main>
</div>
<?php wp_footer(); ?>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,6 @@ protected function get_stub_pages( $wordcamp, $meta ) {
'content' => $this->get_stub_content( 'page', 'day-of-event', $wordcamp ),
'status' => 'draft',
'type' => 'page',
'meta' => array(
'_wp_page_template' => 'day-of-event', // Set the page template.
),
),
);

Expand Down