-
Notifications
You must be signed in to change notification settings - Fork 0
/
bloc.php
93 lines (78 loc) · 2.5 KB
/
bloc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* Plugin Name: Bloc
* Plugin URI: https://github.com/lambry/bloc/
* Description: A few useful WordPress blocks and block options.
* Version: 0.1.0
* Author: Lambry
* Author URI: https://lambry.com/
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: bloc
*/
namespace Lambry\Bloc;
defined('ABSPATH') || exit;
define('BLOC_DIR', plugin_dir_path(__FILE__));
define('BLOC_URL', plugin_dir_url(__FILE__));
define('BLOC_BLOCKS_DIR', plugin_dir_path(__FILE__) . 'src/blocks/');
define('BLOC_BLOCKS_URL', plugin_dir_url(__FILE__) . 'src/blocks/');
class Bloc
{
private $editor = null;
private $frontend = null;
/**
* Setup and add actions.
*/
public function __construct()
{
$this->init();
add_action('enqueue_block_editor_assets', [$this, 'editor']);
add_action('enqueue_block_assets', [$this, 'universal']);
add_action('wp_enqueue_scripts', [$this, 'frontend']);
}
/**
* Include required files.
*/
public function init() : void
{
$this->editor = include plugin_dir_path(__FILE__) . 'build/editor/editor.asset.php';
$this->frontend = include plugin_dir_path(__FILE__) . 'build/frontend/frontend.asset.php';
$this->include('options/options', 'Options');
$this->include('blocks/grid/grid', 'Blocks\Grid');
$this->include('blocks/slider/slider', 'Blocks\Slider');
$this->include('blocks/posts/posts', 'Blocks\Posts');
}
/**
* Enqueue editor assets.
*/
public function editor() : void
{
wp_enqueue_style('bloc-editor-style', BLOC_URL . 'build/editor/editor.css', [], $this->editor['version']);
wp_enqueue_script('bloc-editor-script', BLOC_URL . 'build/editor/editor.js', $this->editor['dependencies'], $this->editor['version']);
}
/**
* Enqueue editor/frontend assets.
*/
public function universal() : void
{
wp_enqueue_style('bloc-universal-style', BLOC_URL . 'build/editor/style-editor.css', [], $this->editor['version']);
}
/**
* Enqueue frontend assets.
*/
public function frontend() : void
{
wp_enqueue_style('bloc-frontend-style', BLOC_URL . 'build/frontend/style-frontend.css', [], $this->frontend['version']);
wp_enqueue_script('bloc-frontend-script', BLOC_URL . 'build/frontend/frontend.js', [], $this->frontend['version'], true);
}
/**
* Include the file.
*/
private function include(string $file, string $class) : void
{
require_once BLOC_DIR . "src/{$file}.php";
$instance = __NAMESPACE__ . '\\' . $class;
(new $instance)->setup();
}
}
new Bloc();