From 0a6cb4da47ecfc18d8570031e62b522628dd8301 Mon Sep 17 00:00:00 2001 From: Erik van der Bas Date: Tue, 21 May 2024 09:35:50 +0200 Subject: [PATCH] feat: rework of PHP files. (#152) * feat: rework of PHP files. * chore: update namespace * fix: don't provide post again * Remove $dirname since we only use the default location now. * chore: remove unneeded get_post(s) calls --- 404.php | 15 ++++++------ archive.php | 50 ++++++++++++++++++------------------- author.php | 26 ++++++++++++-------- functions.php | 17 +++++++------ index.php | 29 ++++++++++++---------- page.php | 22 ++++++----------- search.php | 20 +++++++-------- single.php | 23 +++++++++-------- src/StarterSite.php | 60 ++++++++++++++++++++++++++------------------- 9 files changed, 136 insertions(+), 126 deletions(-) diff --git a/404.php b/404.php index e56dea257..869be1374 100644 --- a/404.php +++ b/404.php @@ -1,13 +1,12 @@ $title, +]); -Timber::render( $templates, $context ); +Timber::render($templates, $context); diff --git a/author.php b/author.php index 22935423a..2d63a05a5 100644 --- a/author.php +++ b/author.php @@ -1,21 +1,27 @@ query_vars['author'] ) ) { - $author = Timber::get_user( $wp_query->query_vars['author'] ); - $context['author'] = $author; - $context['title'] = 'Author Archives: ' . $author->name(); +$title = false; +if (isset($wp_query->query_vars['author'])) { + $author = Timber::get_user($wp_query->query_vars['author']); + $title = 'Author Archives: ' . $author->name(); } -Timber::render( array( 'author.twig', 'archive.twig' ), $context ); + +$context = Timber::context([ + 'title' => $title, + 'author' => $author, +]); + +Timber::render(array('author.twig', 'archive.twig'), $context); diff --git a/functions.php b/functions.php index 43cddcbec..1cae0e0a9 100644 --- a/functions.php +++ b/functions.php @@ -1,17 +1,20 @@ 'bar', +]); + +Timber::render($templates, $context); diff --git a/page.php b/page.php index 256fb9d11..e0612797a 100644 --- a/page.php +++ b/page.php @@ -1,4 +1,5 @@ post_name . '.twig', 'page.twig' ), $context ); +Timber::render(array('page-' . $post->post_name . '.twig', 'page.twig'), $context); diff --git a/search.php b/search.php index 069b3aae7..61f28f7e1 100644 --- a/search.php +++ b/search.php @@ -1,18 +1,16 @@ 'Search results for ' . get_search_query(), +]); -Timber::render( $templates, $context ); +Timber::render($templates, $context); diff --git a/single.php b/single.php index e47be9045..531fb1c3a 100644 --- a/single.php +++ b/single.php @@ -1,20 +1,19 @@ ID ) ) { - Timber::render( 'single-password.twig', $context ); +if (post_password_required($post->ID)) { + Timber::render('single-password.twig', $context); } else { - Timber::render( array( 'single-' . $timber_post->ID . '.twig', 'single-' . $timber_post->post_type . '.twig', 'single-' . $timber_post->slug . '.twig', 'single.twig' ), $context ); + Timber::render(array('single-' . $post->ID . '.twig', 'single-' . $post->post_type . '.twig', 'single-' . $post->slug . '.twig', 'single.twig'), $context); } diff --git a/src/StarterSite.php b/src/StarterSite.php index 9e4c9141d..3d83669a0 100644 --- a/src/StarterSite.php +++ b/src/StarterSite.php @@ -1,19 +1,24 @@ tag in the document head, and expect WordPress to * provide it for us. */ - add_theme_support( 'title-tag' ); + add_theme_support('title-tag'); /* * Enable support for Post Thumbnails on posts and pages. * * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ */ - add_theme_support( 'post-thumbnails' ); + add_theme_support('post-thumbnails'); /* * Switch default core markup for search form, comment form, and comments @@ -98,7 +105,7 @@ public function theme_supports() { ) ); - add_theme_support( 'menus' ); + add_theme_support('menus'); } /** @@ -106,7 +113,8 @@ public function theme_supports() { * * @param string $text being 'foo', then returned 'foo bar!'. */ - public function myfoo( $text ) { + public function myfoo($text) + { $text .= ' bar!'; return $text; } @@ -116,14 +124,15 @@ public function myfoo( $text ) { * * @param Twig\Environment $twig get extension. */ - public function add_to_twig( $twig ) { + public function add_to_twig($twig) + { /** * Required when you want to use Twig’s template_from_string. * @link https://twig.symfony.com/doc/3.x/functions/template_from_string.html */ // $twig->addExtension( new Twig\Extension\StringLoaderExtension() ); - $twig->addFilter( new Twig\TwigFilter( 'myfoo', [ $this, 'myfoo' ] ) ); + $twig->addFilter(new \Twig\TwigFilter('myfoo', [$this, 'myfoo'])); return $twig; } @@ -137,9 +146,10 @@ public function add_to_twig( $twig ) { * * @return array */ - function update_twig_environment_options( $options ) { - // $options['autoescape'] = true; + function update_twig_environment_options($options) + { + // $options['autoescape'] = true; - return $options; + return $options; } }