您可以检查它们添加了哪些选项(查看源代码),然后只需编写如下函数:
/*
Plugin Name: Mother of all plugins
Plugin URI: http://wordpress.org/extend/plugins/
Description: Offers the <code>$all_plugin_options;</code> var to access all predefined plugin options
Author: Franz Josef Kaiser
Author URI: http://say-hello-code.com
Version: 0.1
License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
// Template Tag
function get_all_plugin_options()
{
// First we call the class
$class = new MotherOfAllPlugins;
$data = $class->predefined_plugin_options()
return $data;
}
if ( ! class_exists(\'MotherOfAllPlugins\') )
{
class MotherOfAllPlugins
{
protected $plugin_options;
public function __construct( $plugin_options )
{
// defaults
$default_options = array(
\'plugin_a\' => array(
\'deprecated\' => \'\'
,\'name\' => \'value\'
,\'key\' => \'value\'
)
,\'plugin_b\' => array(
\'deprecated\' => \'\'
,\'name\' => \'value\'
,\'key\' => \'value\'
)
);
// Now overwrite the
$this->plugin_options = array_merge( $default_options, $plugin_options );
add_action( \'init\', \'predefined_plugin_options\' );
}
function predefined_plugin_options()
{
// Set the flag if we have already done this
// _EDIT #1:_ This sets an option in the wp_options table containing TRUE if your plugin predef options are already present in the DB
if ( !get_option( \'predef_plugins_setup\' ) === TRUE )
add_option( \'predef_plugins_setup\', TRUE );
if ( !get_option( \'predef_plugins_setup\' ) === TRUE )
{
// Add the options for the plugins
foreach ( $plugin_options as $plugin => $options )
{
add_option( $plugin, $options, $options[\'deprecated\'], \'yes\' );
}
}
// _EDIT #2:_ return the initial array for use in a global
return $plugin_options
}
} // END Class MotherOfAllPlugins
} // endif;
要在主题中获取插件选项,请执行以下操作:
// Now we take the return value & add it into global scope for further useage.
// This way we can access all options easily without a call to the DB.
// You can now access these values from anywhere in your theme.
$all_plugin_options = get_all_plugin_options();
请注意,真正添加选项的方式与插件的方式完全相同。否则就没用了。