$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wp admin - How to provide a plugin which requires CMB2 (plugin dependencies)?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp admin - How to provide a plugin which requires CMB2 (plugin dependencies)?

matteradmin18PV0评论

Every serious plugin developer probably has to deal with this problem: WordPress is not supporting composer or any dependency management by default. I have written a great plugin which I would like to put into the official repository on WordPress.

Problem is: I do not want to write all of those options pages (including network options pages) on my own - this is why I am using the CMB2 library. It is actually a well known framework used by a lot of WordPress developers in order to create options pages:

Most probably it is not a good idea to put the CMB2 library into my Plugin (which would also require constant updates). But what other option do I have? What is a good way to deal with this problem?

Every serious plugin developer probably has to deal with this problem: WordPress is not supporting composer or any dependency management by default. I have written a great plugin which I would like to put into the official repository on WordPress.

Problem is: I do not want to write all of those options pages (including network options pages) on my own - this is why I am using the CMB2 library. It is actually a well known framework used by a lot of WordPress developers in order to create options pages: https://github/CMB2/CMB2

Most probably it is not a good idea to put the CMB2 library into my Plugin (which would also require constant updates). But what other option do I have? What is a good way to deal with this problem?

Share Improve this question asked Mar 19, 2019 at 17:04 BlackbamBlackbam 57511 silver badges28 bronze badges 5
  • Have you looked into how WooCommerce extensions make sure that WooCommerce is installed and activated? – kero Commented Mar 19, 2019 at 17:19
  • Unfortunately there really isn't a good solution for this issue. Either you include the library in your plugin, and then manage the updates to the library on the plugin repo, or you write the code for the meta boxes and options pages yourself. The only other option is if you want people to use the CMB plugin and consider yours an addon for that then you could use if (!class_exists('cmb_main_class_name)){ ... on your plugin init function – mrben522 Commented Mar 19, 2019 at 17:25
  • @mrben522 Already thought about that but for normal users it will be too difficult to install CMB2 themselves (which may even be removed from the repo). – Blackbam Commented Mar 19, 2019 at 18:28
  • 1 In that case you're going to have to include the library in your plugin. It's not ideal but it's definitely not uncommon or particularly frowned upon in wordpress plugins. – mrben522 Commented Mar 19, 2019 at 18:40
  • @mrben522 Ok I see - thanks! – Blackbam Commented Mar 19, 2019 at 18:42
Add a comment  | 

1 Answer 1

Reset to default 2

On your plugin activation hook method you can check if CMB plugin is installed and/or activated.

You can check this using the following methods:

  1. is_plugin_active(): only available from within the admin pages
  2. function_exists() or class_exists(): available anywhere once they are PHP core methods

If CMB is not installed, you can throw an error message in the panel with instructions to the user on how to install it.

This article has a great explanation on how to check WordPress Plugin Dependencies.

Post a comment

comment list (0)

  1. No comments so far