tafadias / ModernWordPressWebsite

Modern WordPress Website (MWW) is a modern way of building WordPress websites.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About Modern WordPress Website

Modern WordPress Website (MWW) is a modern way of building WordPress websites.
Simple, unopiniated and powerful, it's a great skeleton to bootstrap a new WordPress project.

  • True MVC experience in WordPress.
  • Simple route engine with native WordPress functions.
  • Modern, yet simple PHP.
  • PSR-4 Autoloading.
  • Only 20 files and 15kb in size (Approximately).
  • Installs as a mu-plugin

Modern WordPress Website (MWW) is great for experienced PHP developers using WordPress, and for intermediate developers who want to take their skills to the next level.

Building a Small Project

Click to watch on YouTube

(Click to watch on YouTube)

Building a Small Project (Português PT-BR)

Click to watch on YouTube

(Click to watch on YouTube)

Installation

Despite being a Theme in practical terms, Modern WordPress Website is installed as a mu-plugin. This way we intercept WordPress requests at an earlier stage and have more control over the application.

To get started, simply follow these steps in a clean WordPress installation:

  • Create wp-content/mu-plugins folder.
  • Run git clone https://github.com/Luc45/ModernWordPressWebsite . inside mu-plugins folder.
  • Run composer update inside the recently created mu-plugins/mww/ folder to generate the autoload files.
  • (Recommended) You will not need your theme anymore, you can create an empty theme with just index.php, style.css and functions.php. Download empty theme.

Now it's up to you to create awesome stuff!

How it works

MWW brings a true MVC experience to WordPress. It is installed as a mu-plugin. With it, you don't need a theme.

Even though MWW is powerful, it's also very simple. The src folder, which contains the logic of MWW contains only 8 files.

The heart of MWW is the routing system. It works like this:

/**
 * Routes the request to the appropriate Controller
 */
public function routeRequest()
{
    add_filter('template_include', function () {
        ob_start();

        if (is_front_page()) {
            $page = new HomeController;
        } else {
            $page = new NotFoundController;
        }

        $page->output();

        echo ob_get_clean();
        return false;
    });
}

We perform checks using native WordPress functions such as is_front_page() to load the appropriate controller, then we call the method output() on it. Let's take a look at HomeController output method:

// HomeController
public function output()
{
    $this->template->include('partials.header');
    $this->template->include('pages.home');
    $this->template->include('partials.footer');
}

We are loading a header, the home page content and the footer.

What if we want to show Posts on our Home page?

Well, we can do just this:

// HomeController
public function output()
{
    $posts = get_posts();

    $this->template->include('partials.header');
    $this->template->include('pages.home', ['posts' => $posts);
    $this->template->include('partials.footer');
}

Then, we have a variable in our home view with all the posts. Let's use it:

// views/pages/home.php
foreach ($posts as $post) {
    echo $post->post_title;
}

You see? We could easily separate the logic, we don't need to use get_posts() in our view, we can do it in the Controller (or create a model class) and pass it digested to the view. This way, it is easier for our application to grow organized.

Contributing

To contribute to Modern WordPress Website, you can open an issue with your suggestion and if approved, do a pull-request. Please follow PSR-2 code-styling standards and remind about the unopiniated and simple philosophy of Modern WordPress Theme.

License

The Modern WordPress Website is licensed under the MIT license.

Hire me

Hire Me!
My name is Lucas Bustamante, creator of Modern WordPress Website.
Hire me at lucasfbustamante@gmail.com

About

Modern WordPress Website (MWW) is a modern way of building WordPress websites.


Languages

Language:PHP 97.9%Language:Hack 1.6%Language:JavaScript 0.5%