0

I am currently building a plugin that is requiring two other plugins in order to work -- Paid Memberships Pro and Advanced Custom Fields. It works fine with requiring Advanced Custom Fields but completely ignores the second conditional for Paid Memberships Pro. Any idea why this is happening?

    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 }
2

check if the plugins are active and display a warning at the top of the page if there not: 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 }

Take a look at the PHP operators maybe?

http://php.net/manual/en/language.operators.php

http://php.net/manual/en/language.operators.logical.php

  • Already did that, as I said it looks to see if Advanced Custom Fields is active but completely ignores Paid Memberships Pro. Could this be an issue with conditional logic? – Zach Russell Oct 5 '14 at 18:49
  • edited it try that? – vimes1984 Oct 5 '14 at 18:56
  • Worked like a charm, thanks! Would I keep adding 'or' pipes to require more plugins then (3+)? Just curious. – Zach Russell Oct 5 '14 at 19:00
  • well yeah you would again read through the operators on the php page it'll help I can also higly recommend the oreily php programming book helped me loads when starting – vimes1984 Oct 5 '14 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.