<?php
/**
* Created by PhpStorm.
* User: Avi Levkovich
* Date: 09/11/2017
* Time: 10:58
*/
namespace factory;
class site {
private static $instance;
protected $site;
protected $design;
/**
* site constructor.
*/
private function __construct() {
if ( is_multisite() ) {
$this->site = get_site();
} else {
$this->site = array_map( function ( $show ) {
return get_bloginfo( $show );
}, array(
'url',
'wpurl',
'description',
'rdf_url',
'rss_url',
'rss2_url',
'atom_url',
'comments_atom_url',
'comments_rss2_url',
'pingback_url',
'stylesheet_url',
'stylesheet_directory',
'template_directory',
'template_url',
'admin_email',
'charset',
'html_type',
'version',
'language',
'text_direction',
'name',
) );
}
}
public static function get_instance() {
if ( ! self::$instance ) {
self::$instance = new static();
}
return self::$instance;
}
public function build() {
if ( is_object( $this->site ) ) {
$design = $this->site->design();
} else {
$design = apply_filters( 'site_design', '' );
if ( ! $design ) {
$design = 'default_design';
}
}
$class = sprintf( '\design\%s', $design );
if(class_exists($class)) {
$this->design = new $class();
}
return $this;
}
public function render() {
if ( is_object( $this->design ) ) {
$this->design->header();
$this->design->body();
$this->design->footer();
} else {
get_header();
echo apply_filters( 'get_body', '' );
get_footer();
}
}
public function enqueue() {
add_filter( 'css_enqueues', array( $this->design, 'css' ) );
add_filter( 'js_enqueues', array( $this->design, 'js' ) );
}
/**
* @return mixed
*/
public function getDesign() {
return $this->site->design();
}
}
all you need is to create a new object under the namespace of "design" wchich has the methods header + body + footer, and write in index.php: (\factory\site())->build()->render();
if you don't create a class, you can use the default WP header and footer, and inject the body of the site into the filter 'get_body'. again with (\factory\site())->build()->render();
if you don't create a class, you can use the default WP header and footer, and inject the body of the site into the filter 'get_body'. again with (\factory\site())->build()->render();
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.