Skip to content
Romain DORR edited this page May 4, 2018 · 4 revisions

How to use this theme with WordPress?

In folder inc/ are all the necessary files to integrate a WordPress theme easily.

Folders presentation:

  • async/: contains JS / CSS files that load asynchronously
  • services/: contains all the dedicated services
  • tools/: contains all services used as tools

Each service contains a feature !

To load the services, just have this code in functions.php who will load all basic services.

/**
* Autoload all the things \o/
*/
require_once 'autoload.php';
/**
* Load all services
*/
add_action( 'after_setup_theme', function () {
// Boot the service, at after_setup_theme
\BEA\Theme\Framework\Framework::get_container()->boot_services();
}, 20 );

Anatomy of a Service

A class Service must extend 3 functions to work:

<?php
namespace BEA\Theme\Framework\Services;
use BEA\Theme\Framework\Service;
use BEA\Theme\Framework\Service_Container;
/**
* Class Menu
*
* @package BEA\Theme\Framework
*/
class Menu implements Service {
/**
* @param Service_Container $container
*/
public function register( Service_Container $container ) {}
/**
* @param Service_Container $container
*/
public function boot( Service_Container $container ) {
}
/**
* @return string
*/
public function get_service_name() {
return 'menu';
}
}
  • register(): actions when service is register, example: load others things needed by the service
  • boot(): actions when service is load/boot, example: add_action(), add_filter()
  • get_service_name(): needed to return the service name, to get it later

To register a new custom service, change the add_action() in functions.php to load extra services:

add_action( 'after_setup_theme', function () {
// Boot the service, at after_setup_theme
$container = \BEA\Theme\Framework\Framework::get_container();
// Add custom services
$container->register_service( \BEA\Theme\Framework\Services\Silo::class );
$container->register_service( \BEA\Theme\Framework\Services\WooCommerce::class );
// Boot all !
$container->boot_services();
}, 20 );

Services utilities

  • ACF Service: Contains functions to load simply ACF fields and register theme options page, block theme activation if ACF doesn't active
  • Assets Service: Load all styles CSS and scripts JS
  • Assets CSS Async Service: Allow to load styles CSS in async
  • Assets JS Async Service: Allow to load scripts JS in async
  • Favicons Service: Load all favicons in header
  • Menu Service: Declare your menus in this service
  • Sidebar Service: Declare your sidebars in this service
  • SVG Service: Load SVG icons in footer, contains functions to display SVG tag
  • Theme Service: Load theme supports, i18n

You can register all new custom services you needed!

Clone this wiki locally