forked from origgami/CMB2-grid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cmb2GridPluginLoad.php
158 lines (127 loc) · 4.53 KB
/
Cmb2GridPluginLoad.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
namespace Cmb2Grid;
if ( ! defined( 'CMB2GRID_DIR' ) ) {
define( 'CMB2GRID_DIR', trailingslashit( dirname( __FILE__ ) ) );
}
if ( ! class_exists( '\Cmb2Grid\Cmb2GridPlugin' ) ) {
require_once dirname( __FILE__ ) . '/DesignPatterns/Singleton.php';
class Cmb2GridPlugin extends DesignPatterns\Singleton {
const VERSION = '1.0';
protected function __construct() {
spl_autoload_register( array( $this, 'auto_load' ) );
add_action( 'admin_head', array( $this, 'wpHead' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
//$this->test();
}
private function test() {
new Test\Test();
}
/**
* Auto load our class files.
*
* @param string $class Class name.
*
* @return void
*/
public function auto_load( $class ) {
static $prefix;
static $base_dir;
static $sep;
static $length;
if ( ! isset( $prefix, $base_dir, $sep ) ) {
// Project-specific namespace prefix.
$prefix = __NAMESPACE__ . '\\';
// Base directory for the namespace prefix.
$base_dir = plugin_dir_path( __FILE__ ); // Has trailing slash.
// Set directory separator.
$sep = '/';
if ( defined( 'DIRECTORY_SEPARATOR' ) ) {
$sep = DIRECTORY_SEPARATOR;
}
$length = strlen( $prefix );
}
// Does the class use the namespace prefix?
if ( strncmp( $prefix, $class, $length ) !== 0 ) {
// No, move to the next registered autoloader.
return;
}
// Get the relative class name.
$relative_class = substr( $class, $length );
/*
* Add the base directory, replace namespace separators with directory
* separators in the relative class name and append with .php.
*/
$file = $base_dir . str_replace( '\\', $sep, $relative_class ) . '.php';
// If the file exists, require it.
if ( file_exists( $file ) ) {
require_once $file;
}
}
public function admin_enqueue_scripts() {
$suffix = ( ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min' );
wp_enqueue_style( 'cmb2_grid_bootstrap_light', $this->url( 'assets/css/bootstrap' . $suffix . '.css' ), null, self::VERSION );
}
public function wpHead() {
?>
<style>
.cmb2GridRow .cmb-row{border:none !important;padding:0 !important}
.cmb2GridRow .cmb-th label:after{border:none !important}
.cmb2GridRow .cmb-th{width:100% !important}
.cmb2GridRow .cmb-td{width:100% !important}
.cmb2GridRow input[type="text"], .cmb2GridRow textarea, .cmb2GridRow select{width:100%}
.cmb2GridRow .cmb-repeat-group-wrap{max-width:100% !important;}
.cmb2GridRow .cmb-group-title{margin:0 !important;}
.cmb2GridRow .cmb-repeat-group-wrap .cmb-row .cmbhandle, .cmb2GridRow .postbox-container .cmb-row .cmbhandle{right:0 !important}
.cmb2GridRow .cmb-type-group .cmb-remove-field-row{padding-bottom: 1.8em !important;padding-top: 1.8em !important;}
.cmb2GridRow .cmb-td.cmb-nested{padding-left: 15px;padding-right: 15px;}
</style>
<?php
}
// Based on CMB2_Utils url() method.
public function url( $path = '' ) {
if ( isset( $this->url ) ) {
return $this->url . $path;
}
if ( 'WIN' === strtoupper( substr( PHP_OS, 0, 3 ) ) ) {
// Windows
$content_dir = str_replace( '/', DIRECTORY_SEPARATOR, WP_CONTENT_DIR );
$content_url = str_replace( $content_dir, WP_CONTENT_URL, CMB2GRID_DIR );
$cmb2_url = str_replace( DIRECTORY_SEPARATOR, '/', $content_url );
} else {
$cmb2_url = str_replace(
array( WP_CONTENT_DIR, WP_PLUGIN_DIR ),
array( WP_CONTENT_URL, WP_PLUGIN_URL ),
CMB2GRID_DIR
);
}
/**
* Filter the CMB location url.
*
* @param string $cmb2_url Currently registered url.
*/
$this->url = trailingslashit( apply_filters( 'cmb2_meta_box_url', set_url_scheme( $cmb2_url ), CMB2_VERSION ) );
return $this->url . $path;
}
}
}
/* Instantiate the class on plugins_loaded. */
// wp_installing() function was introduced in WP 4.4.
if ( ( function_exists( 'wp_installing' ) && wp_installing() === false ) || ( ! function_exists( 'wp_installing' ) && ( ! defined( 'WP_INSTALLING' ) || WP_INSTALLING === false ) ) ) {
add_action( 'plugins_loaded', '\\' . __NAMESPACE__ . '\init' );
}
if ( ! function_exists( '\Cmb2Grid\init' ) ) {
/**
* Initialize the class only if CMB2 is detected.
*
* @return void
*/
function init() {
if ( defined( 'CMB2_LOADED' ) ) {
if ( ! defined( 'CMB2GRID_DIR' ) ) {
define( 'CMB2GRID_DIR', trailingslashit( dirname( __FILE__ ) ) );
}
Cmb2GridPlugin::getInstance();
}
}
}
add_action( 'cmb2_init', '\Cmb2Grid\init' );