29

GitHub - Luc45/ModernWordPressWebsite: Modern WordPress Website (MWW) brings a M...

 5 years ago
source link: https://github.com/Luc45/ModernWordPressWebsite
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

README.md

687474703a2f2f6465762e6c7563617362757374616d616e74652e636f6d2e62722f6d77772d6c6f676f2e737667

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.

  • MVC in WordPress.
  • Simple route engine with native WordPress functions.
  • Modern, yet simple PHP.
  • PSR-4 Autoloading.
  • Integrated with Acceptance, Functional, Integration and Unit tests (Thanks to Luca Tume, from 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 method index on 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');
    }
}

Here, we are including the header, the home page content and the footer 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 create a model for it) 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.

To-dos

  • Throw custom Exceptions throughout the framework and app
  • Refactor RouteConditional
  • Write unit tests

License

The Modern WordPress Website is licensed under the MIT license.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK