-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrs-utility-blocks.php
68 lines (57 loc) · 2.17 KB
/
rs-utility-blocks.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
<?php
/*
Plugin Name: RS Utility Blocks
Description: Adds custom blocks and utilities to the block editor, including visibility conditions and blocks to display the current user's information or current post's information, and a login form block.
Version: 1.3.5
Author: Radley Sustaire
Author URI: https://radleysustaire.com
GitHub Plugin URI: https://github.com/RadGH/RS-Utility-Blocks
*/
define( 'RS_Utility_Blocks_PATH', __DIR__ );
define( 'RS_Utility_Blocks_URL', plugin_dir_url(__FILE__) );
define( 'RS_Utility_Blocks_VERSION', '1.3.5' );
class RS_Utility_Blocks {
/**
* Checks that required plugins are loaded before continuing
*
* @return void
*/
public static function load_plugin() {
// 1. Check for required plugins
$missing_plugins = array();
if ( ! class_exists('ACF') ) {
$missing_plugins[] = 'Advanced Custom Fields Pro';
}
// Show error on the dashboard if any plugins are missing
if ( $missing_plugins ) {
self::add_admin_notice( '<strong>RS Utility Blocks:</strong> The following plugins are required: '. implode(', ', $missing_plugins) . '.', 'error' );
return;
}
// 2. Load ACF fields
require_once( RS_Utility_Blocks_PATH . '/assets/acf-fields.php' );
// 3. Load plugin files
require_once( RS_Utility_Blocks_PATH . '/includes/setup.php' );
require_once( RS_Utility_Blocks_PATH . '/includes/profile.php' );
require_once( RS_Utility_Blocks_PATH . '/includes/functions.php' );
}
/**
* Adds an admin notice to the dashboard's "admin_notices" hook.
*
* @param string $message The message to display
* @param string $type The type of notice: info, error, warning, or success. Default is "info"
* @param bool $format Whether to format the message with wpautop()
*
* @return void
*/
public static function add_admin_notice( $message, $type = 'info', $format = true ) {
add_action( 'admin_notices', function() use ( $message, $type, $format ) {
?>
<div class="notice notice-<?php echo $type; ?> rs-utility-blocks-notice">
<?php echo $format ? wpautop($message) : $message; ?>
</div>
<?php
});
}
}
// Initialize the plugin
add_action( 'plugins_loaded', array('RS_Utility_Blocks', 'load_plugin') );