Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Woocommerce compatibility #14

Closed
wants to merge 1 commit into from

Conversation

Camilo517
Copy link

No description provided.

@@ -71,6 +71,10 @@ function quicklink_enqueue_scripts() {

// Do not preload wp-content items (like downloads).
preg_quote( wp_parse_url( content_url(), PHP_URL_PATH ), '/' ),

// Do not preload woocommerce items.
preg_quote(!is_woocommerce() && !is_cart() && !is_checkout() && !is_account_page() && !is_product() && !is_product_category() && !is_shop(), '/' ),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work as is because these functions won't be defined unless WooCommerce is active.

Also, the ignores here takes a list of URL strings. But the value being passed into preg_quote() will end up being a boolean, so it's not going to work.

So what is needed is:

  1. Check if WooCommerce is active (such as via function_exists( 'is_woocommerce' ).
  2. Obtain URL patterns for the various WooCommerce templates, such as cart page, checkout page, product page, etc.
  3. Add each pattern to the list of ignores.

Additionally, I don't think this should be done directly here. Instead, the patterns should be added in a separate WooCommerce-specific filter:

add_filter( 'quicklink_options', function( $options ) {
    if ( function_exists( 'is_woocommerce' ) ) {
        $options['ignores'][] = '...';
        $options['ignores'][] = '...';
        $options['ignores'][] = '...';
    }
    return $options;
} );

This could be in a separate file entirely, like plugin-compat/woocommerce.php so make it scalable for wider compatibility in the ecosystem.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works for me
Sorry, I'm not an expert on php. It is clear that your solution is a better way

@Luehrsen Luehrsen mentioned this pull request Mar 20, 2019
@Luehrsen Luehrsen closed this Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants