Skip to content

obrunopolo/wp-zeus-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WP Zeus Framework

Some stuff have been changed, and I got no time to update docs. Updates coming soon.

The framework for WP plugin creators.

Features:

  • PSR-4 - No more annoying require frenzy.
  • Use composer to install and manage PHP dependencies.
  • Use TypeScript or JavaScript to create front end scripts, and npm to install packages and extend functionalities.
  • Enjoy webpack optimized build for production.

Pre requisites

  • A Wordpress installation
  • Composer installed
  • Node.JS and npm installed (LTS recommended)

Task list

  • Project startup documentation
  • Developing guidelines documentation
  • JavaScript/TypeScript development documentation
  • Custom post types implementation + Documentation
  • wp-json API implementation + Documentation
  • React usage documentation
  • Sass (.scss) support + documentation
  • wp-config.php setup
  • Production deploy documentation
  • Composer usage documentation
  • i18n support
  • Hooks documentation

Quick start

  1. Clone this repository into plugins folder of a development machine, and cd into lib folder.
# @wp-content/plugins
git clone https://github.com/obrunopolo/wp-zeus-framework.git ./zeus-framework
cd zeus-framework/lib
  1. Install dependencies and run first build:
npm run update-dev
  1. Start creating

Project structure

After first project build, the main plugin folder has 4 subfolders:

  • includes: contains standalone .php files, such as the Functions and Constants files. Also holds the JavaScript files that are actually loaded into the view.
  • lib: contains development files. This folder could be omitted in production environments. Holds the JavaScript/TypeScript source files and is the place for running terminal commands.
  • src: the PHP source code, and the root of Zeus namespace. Holds the PSR-4 compliant code, and should be responsible for most of the plugin functionality.
  • vendor: contains the autoload file and the installed PHP dependencies, generated by composer.

Development guidelines

The project is intended to be flexible to the developer, but also suggests usage of MVC architecture and reinforces OOP.

Creating simple functionality

To encapsulate functionalities, we must have a Controller class that has a defined scope. For this example, let's say we need to add a greeting to the current user, when logged in, in the single post page, before the post content.

This could be achieved if we had a User controller, using the filter the_content, like this:

  • src/Controllers/User.php
<?php

namespace Zeus\Controllers;

use Zeus\Framework\Contracts\Controller;
use Zeus\Framework\Contracts\Singleton;

class User extends Singleton implements Controller
{



    function filterPostContent($content) {
        $greeting = "";
        if (is_user_logged_in()) {
            $user = wp_get_current_user();
            $greeting = "<p>Hello, {$user->first_name}</p>";
        }
        return $greeting . $content;
    }

    public function run()
    {
        add_filter("the_content", [$this, "filterPostContent"]);
    }
}

Then, add the new controller to the main App class:

  • src/App.php
<?php

namespace Zeus;

use Zeus\Controllers\User;

class App
{
    // {{...}}

    /** @var User */
    public $user;

    // {{...}}

    public function run()
    {

        // Instantiate controllers here
        // {{...}}
        $this->user = User::getInstance();
        // {{...}}
    }
}

Now you should see the greeting, if logged in.

Continue creating

About

The framework for WP plugin creators

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages