Giter Club home page Giter Club logo

modernwordpresswebsite's Introduction

About Modern WordPress Website

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

Think of it as a functions.php with an OOP architecture similar to Laravel.

First, you route WordPress conditional tags such as is_front_page() to Controllers, then you fetch/manipulate data with a model, a repository, a service provider or similar, then you load a view, passing data to it. With MWW, you don't use a theme. However, like in functions.php, you have access to all WordPress functions and plugins.

  • MVC in WordPress.
  • Modern, yet simple PHP.
  • PSR-4 Autoloading.
  • Dependency Injection Container (Thanks Luca Tume, for di52)
  • Acceptance, Functional, Integration and Unit tests (Thanks Luca Tume, for wp-browser)
  • Installs as a mu-plugin
  • MWW is in BETA state.

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.

MWW is in beta and open to contributors. Help us test and develop it!

Building a Small Project

Click to watch on YouTube

(Click to watch on YouTube)

Installation

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:

  • Run git clone https://github.com/Luc45/ModernWordPressWebsite wp-content/mu-plugins in the root folder of a clean WordPress installation
  • Run composer update in wp-content/mu-plugins/mww/
  • (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.
  • (Recommended) Set up tests by editing .env.example and renaming it to .env - Run tests with vendor/bin/codecept run

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

How it works

Even though MWW is powerful, it's also very simple. It all starts with the routes:

// routes/conditional.php
$router->add('is_front_page', ['App\Pages\Home', 'index']);

If is_front_page() is true, then call the method index() of App\Pages\Home:

// app/pages/Home.php
class Home extends Page
{
    public function index()
    {
        $this->template->include('header');
        $this->template->include('pages.home');
        $this->template->include('footer');
    }
}

In this example we are including the header, the home page content and the footer views, using template_include in the background.

That's all we need to get started!

Of course that modern applications uses a lot of dynamic data, not only static views. Here's how we can show Posts on the Home page:

// app/pages/Home.php
class Home extends Page
{
    public function index()
    {
        $this->template->include('header');
        $this->template->include('pages.home', [
            'posts' => get_posts()
        ]);
        $this->template->include('footer');
    }
}

Then, we have a variable $posts in our home view with the content of get_posts():

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

You see? This is MVC. 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 better yet, ask a Model to fetch and prepare that data, and then we pass it 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.

To-dos

  • Throw custom Exceptions throughout the framework and app
  • Refactor RouteConditional
  • Remove Assets helper class
  • Write unit tests

License

The Modern WordPress Website is licensed under the MIT license.

modernwordpresswebsite's People

Contributors

boxybird avatar luc45 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.