• Hi,

    This is the code from WooCommerce documentation: (https://docs.woocommerce.com/document/create-a-plugin/)

    /**
     * Check if WooCommerce is active
     **/
    if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
        // Put your plugin code here
    }

    I understand what this code does, but I can not understand why call to apply_filters(…) is required? Just using get_option( ‘active_plugins’ ) and then looking through it seem enough.

    Thanks,
    Rudolf

    • This topic was modified 5 years, 4 months ago by rudolfl.
Viewing 1 replies (of 1 total)
  • I prefer to use:

    
    if( class_exists( 'WooCommerce' ) ) {
        // Put your plugin code here
    }
    

    That way it also works if WooCommerce is installed in a different directory. E.g. when I switch between two instances of WooCommerce during testing, like plugins/woocommerce-3.5.2 or plugins/woocommerce-2.6.14

Viewing 1 replies (of 1 total)
  • The topic ‘What does this code do?’ is closed to new replies.