檢查 BuddyPress

檢查 BuddyPress

Codex Home → BuddyPress Plugin Development → Checking For BuddyPress
Checking For BuddyPress

Because of the way that WordPress loads plugins, it』s possible that your plugin could load before or after BuddyPress. This makes it difficult to know if BuddyPress is loaded, or if your plugin has the proper functions available that it might need. If you don』t check, and assume BuddyPress is loaded, it could take an entire site down when BuddyPress is upgraded.
It』s really easy to do this. In your plugin, create a loader.php file that will check to see if BuddyPress is active, and only then load code that relies on BP:
?12345678910111213141516171819/*Plugin Name: My PluginPlugin URI: http://example.org/my-plugin/Description: My BuddyPress pluginVersion: 1.0Requires at least: WordPress 2.9.1 / BuddyPress 1.2Tested up to: WordPress 2.9.1 / BuddyPress 1.2License: GNU/GPL 2Author: Some PersonAuthor URI: http://example.org/me/*/ /* Only load code that needs BuddyPress to run once BP is loaded and initialized. */function my_plugin_init() {    require( dirname( __FILE__ ) . '/my-plugin.php' );}add_action( 'bp_include', 'my_plugin_init' ); /* If you have code that does not need BuddyPress to run, then add it here. */

發表回覆

您的電子郵箱地址不會被公開。 必填項已用 * 標註