-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmb2-logic.php
65 lines (57 loc) · 1.86 KB
/
cmb2-logic.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
<?php
/**
* @wordpress-plugin
* Plugin Name: CMB2 Field Logic
* Plugin URI: https://github.com/Ardnived/cmb2-logic
* Description: A simple plugin which adds display logic for fields created by CMB2
* Version: 1.0
* Author: Devindra Payment
* Text Domain: cmb2l
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Domain Path: /languages
* GitHub Plugin URI: https://github.com/Ardnived/cmb2-logic
*/
class CMB2_Logic {
public static $directory_path = '';
public static $directory_url = '';
public static function init() {
self::$directory_path = plugin_dir_path( __FILE__ );
self::$directory_url = plugin_dir_url( __FILE__ );
add_action( 'admin_notices', array( __CLASS__, 'check_requirements' ) );
add_action( 'plugins_loaded', array( __CLASS__, 'load' ), 11 );
}
/**
* Load the plugin, if we meet requirements.
* @filter plugins_loaded
*/
public static function load() {
if ( self::meets_requirements() ) {
require_once( self::$directory_path . '/includes/class-cmb2l-main.php' );
}
}
/**
* Generate a custom error message and deactivates the plugin if we don't meet requirements
* @filter admin_notices
*/
public static function check_requirements() {
if ( ! self::meets_requirements() ) {
?>
<div id="message" class="error">
<p>
<?php printf( __( 'CMB2 Field Logic requires CMB2 to run, and has thus been <a href="%s">deactivated</a>. Please install and activate CMB2 and then reactivate this plugin.', 'ubcreg' ), admin_url( 'plugins.php' ) ); ?>
</p>
</div>
<?php
// Deactivate our plugin
deactivate_plugins( plugin_basename( __FILE__ ) );
}
}
/**
* Checks if the required plugin is installed.
*/
public static function meets_requirements() {
return defined( 'CMB2_LOADED' );
}
}
CMB2_Logic::init();