Skip to content

Instantly share code, notes, and snippets.

@frankhn
Last active July 31, 2020 19:20
Show Gist options
  • Save frankhn/b878c1a4925ef11cb0fd92fc6688d3ad to your computer and use it in GitHub Desktop.
Save frankhn/b878c1a4925ef11cb0fd92fc6688d3ad to your computer and use it in GitHub Desktop.
*.xml
*.json
vendor
*.bk

This is a simple WordPress Theme 🙂

To complete this test you need to modify the file 'class-theme-utils.php' so that it produces the output (header & footer content only!) as seen in this image -> output screenshot

IMPORTANT RULES BEFORE COMPLETING THIS TEST

  • You can only modify the file 'class-theme-utils.php'
  • No hard coded strings EXCEPT for the text inside the header to complete "Hey {your name}"
  • You CANNOT use JavaScript or CSS for this test

WHAT TO DO :

  • Complete the function get_text() inside 'class-theme-utils.php' file
    • It has to return same text 'This is Kapp Theme' inside the class 'Theme_Core'
    • No hard coded strings allowed. i.e you CANNOT do return 'This is Kapp Theme';
    • NOTE : If someone changes the text inside the class 'Theme_Core' in the method 'text()' it must also reflect in the footer and header of the website.
  • Add your name inside the HEADER right after the text 'Hey' e.g 'Hey Chris'
  • Inside the FOOTER : add the version of the theme right next to 'This is Kapp Theme' Text. (to produce a text like 'This is Kapp Theme Version 1.0.0' )
    • You must use the text returned by the method get_theme_version() inside the file 'class-theme-utils.php' in order to get the current theme version

Have fun 😎

<?php
class Theme_Core {
private static $_instance = null;
public function __construct() {
add_action( 'init', array( $this, 'assets' ) );
}
/**
* ------------------------------------------------------------------
* Enqeue styles
* ------------------------------------------------------------------
*
* @return void
*/
public function assets() {
wp_enqueue_style( 'kapp-main-style', get_stylesheet_uri(), array(), false );
}
/**
* ------------------------------------------------------------------
* Get the theme's instance
* ------------------------------------------------------------------
*
* @return Theme_Core
*/
public static function instance() {
if ( null !== self::$_instance ) {
return self::$_instance;
}
return self::init();
}
/**
* ------------------------------------------------------------------
* Instantiate
* ------------------------------------------------------------------
*
* @return Theme_Core
*/
final public static function init() {
return self::$_instance = new self();
}
/**
* ------------------------------------------------------------------
* The text
* ------------------------------------------------------------------
*
* @return void
*/
protected function text() {
return apply_filters( 'text-message', 'This is Kapp Theme' );
}
}
<?php
class Theme_Utils extends Theme_Core {
public function __construct() {
}
public function get_text($text='This is Kapp Theme') {
// COMPLETE THIS FUNCTION TO RETURN THE TEXT 'This is Kapp Theme' inside Theme_Core class
return $text;
}
/**
* ------------------------------------------------------------------
* Get current theme version
* ------------------------------------------------------------------
*
* @return string
*/
public function get_theme_version() {
return esc_html__( 'Version ', 'kapp-theme-text' ) . wp_get_theme()->Version;
}
/**
* ------------------------------------------------------------------
* Class instance
* ------------------------------------------------------------------
*
* @return Theme_Utils
*/
public static function instance() {
return new self();
}
/**
* ------------------------------------------------------------------
* Greeting message
* ------------------------------------------------------------------
*
* @return void
*/
public function greeting() {
#--------------------------------------------------------------#
return $this->get_text(); // This line should not be changed
}
/**
* ------------------------------------------------------------------
* Returns the text used inside the footer
* ------------------------------------------------------------------
*
* @return void
*/
public function footer_text() {
#--------------------------------------------------------------#
return $this->get_text(); // This line should not be changed
}
}
<?php
define( 'THEMEPATH', get_template_directory() );
require THEMEPATH . '/class-theme-core.php';
require THEMEPATH . '/class-theme-utils.php';
// Initiate theme instance
Theme_Core::init();
<!DOCTYPE html>
<html <?php language_attributes(); ?> dir="ltr">
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<header>
<h1><?php esc_html_e( 'KAPP', 'kapp-test-theme' ); ?></h1>
<?php echo Theme_Utils::instance()->greeting(); ?>
<p>
<?php
echo esc_html_e( 'Hey ' );
do_action( 'user-greeting' );
?>
</p>
</header>
<?php
// --------------------------------------------------------------------------------------#
/**
* ----------------------------------
* DEFAULT TEMPLATE FILE
*
* @author Kapp Studio
* @version 1.0
* @package Kapp WP Theme
* --------------------------------
* */
// --------------------------------------------------------------------------------------#
get_header();
?>
<main id="main" class="page-wrapper">
<div id="content">
<h1><?php esc_html_e( 'Recent Posts', 'kapp-theme-test' ); ?></h1>
<?php while ( have_posts() ) : ?>
<?php
the_post();
echo '<div class="single-post">';
the_title( '<h3>', '</h3>' );
the_content();
echo '</div>';
?>
<?php endwhile; ?>
</div>
</main>
<?php get_footer(); ?>
/*
Theme Name: Kapp Test Theme
Theme URI: https://kapp.rw
Author: Kapp
Author URI: https://kapp.rw
Description: Test
Version: 1.0.0
License: GNU General Public License version 3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Text Domain: kapp
*/
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');
body {
font-family: Roboto, Georgia, serif, Helvetica, sans-serif;
padding: 0;
margin:0;
font-size: 14px;
line-height: 18px;
}
body p {
color:#757575
}
header, footer {
padding:20px 0;
border:1px solid rgb(23, 168, 23);
text-align: center;
}
header {
background-color: #bbffc6;
}
header h1 {
color:#00a1e6;
font-weight: 600;
}
#content {
max-width: 1024px;
margin:35px auto;
border-radius: 10px;
padding: 100px;
background-color: rgba(240, 240, 240, 0.9);
}
.single-post {
margin-bottom: 10px;
border-bottom: 1px dashed #333;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment