• smoothdev

    (@smoothg23)


    First off, thank you for providing this plugin for FREE. It has definitely solved problems for me on standard WordPress installations.

    I’ve just discovered that it’s not working correctly for checkout pages on sub-sites on a multi-site installation of WordPress.

    The issue seems to resolve around the following conditional check:

    File: recaptcha-woo.php - Line: 239
    if( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) 
    {
       ....
       ....
    }

    The reason why this does not work on the sub-sites is because in my particular instance woocommerce has been Network Activated (not locally activated). Only locally activated plugins are returned when using:

    apply_filters( 'active_plugins', get_option( 'active_plugins' )

    I’ve temporarily “disabled” this conditional check on my website, but know this will re-instate on next update so I wanted to request the additional of a fix for your next update.

    Basically, you’ll need to create a function that gathers a list of all active plugins for each site like this:

    function get_all_networked_and_local_active_plugins()
    {
    // Get all the sites in the network
    $sites = get_sites();
    
    // Create an array to store network-activated plugins
    $network_activated_plugins = array();
    
    foreach ($sites as $site) {
        // Switch to the site context
        switch_to_blog($site->blog_id);
    
        // Get the active plugins for the current site
        $active_plugins = get_option('active_plugins');
    
        // Merge the current site's active plugins into the network-activated plugins array
        $network_activated_plugins = array_merge($network_activated_plugins, $active_plugins);
    
        // Restore the original site context
        restore_current_blog();
    }
    
    // Now $network_activated_plugins contains a list of network-activated plugins
    return $network_activated_plugins;
    }

    … and then perhaps your conditional could look like:

    // Get all active plugins
    $all_active_plugins = get_all_networked_and_local_active_plugins();
    
    // Check if woocommerce is active
    if( in_array( 'woocommerce/woocommerce.php', $all_active_plugins ) )
    {
       ...
       ...
    }

    This code has not been tested, but just wanted to share what could be a “solution” to help shape the next version of your useful plugin.

    Thanks.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Recaptcha not appearing on Multi-Site (sub-sites) checkout.’ is closed to new replies.