我目前正在构建一个插件,需要另外两个插件才能工作——付费会员资格专业版和高级自定义字段。它可以很好地处理需要高级自定义字段的问题,但完全忽略了付费会员资格Pro的第二个条件。知道为什么会这样吗?
add_action( \'admin_init\', \'spp_plugin_has_parents\' );
function spp_plugin_has_parents() {
if ( is_admin() && current_user_can( \'activate_plugins\') && !is_plugin_active( \'advanced-custom-fields/acf.php\') && !is_plugin_active( \'paid-memberships-pro/paid-memberships-pro.php\' ) ) {
add_action( \'admin_notices\', \'spp_plugin_notice\' );
deactivate_plugins( plugin_basename( __FILE__) );
if ( isset( $_GET[\'activate\'] ) ) {
unset( $_GET[\'activate\'] );
}
}
}
function spp_plugin_notice() {
?><div class="error"><p>Sorry, But Sportspicks requires Advanced Custom Fields and Paid Membershps Pro to be installed and activated</p></div>
<?php }
最合适的回答,由SO网友:vimes1984 整理而成
检查插件是否处于活动状态,如果没有,则在页面顶部显示警告:http://codex.wordpress.org/Function_Reference/is_plugin_active
add_action( \'admin_init\', \'spp_plugin_has_parents\' );
function spp_plugin_has_parents() {
if ( is_admin() && current_user_can( \'activate_plugins\') && !is_plugin_active( \'advanced-custom-fields/acf.php\') || !is_plugin_active( \'paid-memberships-pro/paid-memberships-pro.php\' ) ) {
add_action( \'admin_notices\', \'spp_plugin_notice\' );
deactivate_plugins( plugin_basename( __FILE__) );
if ( isset( $_GET[\'activate\'] ) ) {
unset( $_GET[\'activate\'] );
}
}
}
function spp_plugin_notice() {
?><div class="error"><p>Sorry, But Sportspicks requires Advanced Custom Fields and Paid Membershps Pro to be installed and activated</p></div><?php }
看看PHP操作符吧?
http://php.net/manual/en/language.operators.php
http://php.net/manual/en/language.operators.logical.php