-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcaxton-main.php
102 lines (83 loc) · 2.64 KB
/
caxton-main.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
94
95
96
97
98
99
100
101
102
<?php
/**
* Caxton - Gutenberg pro main class
* @static string $token Plugin token
* @static string $file Plugin __FILE__
* @static string $url Plugin root dir url
* @static string $path Plugin root dir path
* @static string $version Plugin version
*/
class Caxton {
/** @var Caxton Instance */
private static $_instance = null;
/** @var string Token */
public static $token;
/** @var string Version */
public static $version;
/** @var string Plugin main __FILE__ */
public static $file;
/** @var string Plugin directory url */
public static $url;
/** @var string Plugin directory path */
public static $path;
/** @var Caxton_Admin Instance */
public $admin;
/** @var Caxton_Public Instance */
public $public;
/**
* Return class instance
* @param string $file Plugin path
* @return Caxton instance
*/
public static function instance( $file = '' ) {
if ( null == self::$_instance ) {
self::$_instance = new self( $file );
}
return self::$_instance;
}
/**
* Constructor function.
* @param string $file __FILE__ of the main plugin
* @access private
* @since 0.1.0
*/
private function __construct( $file ) {
self::$token = 'caxton';
self::$file = $file;
self::$url = plugin_dir_url( $file );
self::$path = plugin_dir_path( $file );
self::$version = CAXTON_VERSION;
$this->init();
}
public function init() {
$this->_admin(); //Initiate admin
$this->_public(); //Initiate public
}
/**
* Initiates admin class and adds admin hooks
*/
private function _admin() {
//Instantiating admin class
$this->admin = Caxton_Admin::instance();
//Enqueue admin end JS and CSS
add_action( 'admin_init', array( $this->admin, 'admin_init' ), 5 );
add_action( 'admin_menu', array( $this->admin, 'admin_menu' ), 5 );
add_action( 'enqueue_block_editor_assets', array( $this->admin, 'enqueue' ), 5 );
add_action( 'wp_ajax_caxton_save_blocks', array( $this->admin, 'caxton_save_blocks' ), 5 );
add_action( 'save_post', array( $this->admin, 'save_post' ), 5 );
add_action( 'block_categories_all', array( $this->admin, 'block_categories' ), 5 );
add_action( 'rest_api_init', array( $this->admin, 'rest_api_init' ) );
add_action( 'wp_ajax_caxton_posts', array( $this->admin, 'posts' ) );
}
/**
* Initiates public class and adds public hooks
*/
private function _public() {
//Instantiating public class
$this->public = Caxton_Public::instance();
//Enqueue front end JS and CSS
add_action( 'wp_enqueue_scripts', array( $this->public, 'enqueue' ) );
add_action( 'init', array( $this->public, 'register_blocks' ) );
add_action( 'init', array( $this->public, 'register_scripts' ) );
}
}