@@ -30,6 +30,43 @@ add_action( 'plugins_loaded', array( 'Carbon_Fields\\Carbon_Fields', 'boot' ) );
30
30
add_action( 'carbon_fields_loaded', 'load_my_magic' );
31
31
```
32
32
33
+ ## Version Checking
34
+
35
+ Since it is possible that an older version of the plugin may be installed and/or loaded as a dependency in a theme or plugin, you may wish to do version checking if your code requires a newer version.
36
+
37
+ ** Quick example:**
38
+
39
+ ```
40
+ add_action( 'plugins_loaded', array( 'Carbon_Fields\\Carbon_Fields', 'boot' ) );
41
+ add_action( 'carbon_fields_loaded', 'load_my_magic' );
42
+
43
+ if(verify_dependencies(['carbon_fields' => '2.0.0'])) {
44
+ // Execute my super-awesome plugin logic
45
+ }
46
+
47
+ function verify_dependencies( $deps ) {
48
+ // Check if outdated version of Carbon Fields loaded
49
+ $error = false;
50
+
51
+ if(!defined('\\Carbon_Fields\\VERSION')) {
52
+ $error = '<strong>' . __('My Plugin Name', 'my-text-domain') . ':</strong> ' . __('A fatal error occurred while trying to load dependencies.', 'my-text-domain');
53
+ } else if( version_compare( \Carbon_Fields\VERSION, $deps['carbon_fields'], '<' ) ) {
54
+ $error = '<strong>' . __('My Plugin Name', 'my-text-domain') . '] . ':</strong> ' . __('Danger, Will Robinson! An outdated version of Carbon Fields has been loaded: ' . \Carbon_Fields\VERSION) . ' (>= ' . $deps['carbon_fields'], 'my-text-domain') . ' ' . __('required', 'my-text-domain') . ')';
55
+ }
56
+
57
+ if($error) {
58
+ add_action( 'admin_notices', function() {
59
+ $class = 'notice notice-error';
60
+ $message = __( 'Irks! An error has occurred.', 'sample-text-domain' );
61
+
62
+ printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
63
+ });
64
+ }
65
+
66
+ return !$error;
67
+ }
68
+ ```
69
+
33
70
## Frequently Asked Questions
34
71
35
72
* Q: I get a fatal error when I activate this plugin. What do I do?*
@@ -46,5 +83,5 @@ A: Install [GitHub Updater](https://github.com/afragen/github-updater).
46
83
47
84
## Changelog
48
85
49
- ** 2.0.3 (master) **
86
+ ** 2.0.3**
50
87
* Initial commit
0 commit comments