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

Bug :: Pagination Var Translation Breaks Cache Clearing #607

Closed
jaswrks opened this issue Nov 10, 2015 · 8 comments
Closed

Bug :: Pagination Var Translation Breaks Cache Clearing #607

jaswrks opened this issue Nov 10, 2015 · 8 comments
Assignees
Labels
Milestone

Comments

@jaswrks
Copy link

jaswrks commented Nov 10, 2015

A user writes...

I've run into a bug with my setup. The Auto Clear feature fails to clear "paged pages" (e.g. the second page of the Home Page). I have identified the problem and am looking for a solution which doesn't involve editing core files.

Usually wordpress is set up like this (and everything works fine):
http://domain.com
http://domain.com/page/2

However I have translated the pagination_base into german, so it looks like this:
http://domain.com
http://domain.com/seite/2

Now in this case the second page fails to auto-clear.

I solved this issue by editing line 131 of "CachePathConsts.php" in /src/includes/closures/Shared

from

const CACHE_PATH_REGEX_DEFAULT_SUFFIX_FRAG = '(?:\/index)?(?:\.|\/(?:page\/[0-9]+|comment\-page\-[0-9]+)[.\/])';

to

const CACHE_PATH_REGEX_DEFAULT_SUFFIX_FRAG = '(?:\/index)?(?:\.|\/(?:seite\/[0-9]+|comment\-seite\-[0-9]+)[.\/])';

Is there a setting or filter I can use to change this constant instead?

@jaswrks
Copy link
Author

jaswrks commented Nov 12, 2015

@jaswrks
Copy link
Author

jaswrks commented Nov 12, 2015

@jaswrks
Copy link
Author

jaswrks commented Nov 12, 2015

Next Actions (Step 1 of 2)

  • New feature branch in the websharks/zencache-pro repo.

  • After this line add the following:

    /*
    * Cache-path suffix frag (regex).
    *
    * @since 15xxxx Enhancing translation support.
    *
    * @param string $regex_suffix_frag Existing regex suffix frag?
    *
    * @return string Cache-path suffix frag (regex).
    */
    $self->cachePathRegexSuffixFrag = function ($regex_suffix_frag = CACHE_PATH_REGEX_DEFAULT_SUFFIX_FRAG) use ($self) {
        if ($regex_suffix_frag === CACHE_PATH_REGEX_DEFAULT_SUFFIX_FRAG) {
            return $self->cachePathRegexDefaultSuffixFrag();
        }
        return (string) $regex_suffix_frag;
    };
    
    /*
    * Default cache-path suffix frag (regex).
    *
    * @since 15xxxx Enhancing translation support.
    *
    * @return string Default cache-path suffix frag (regex).
    */
    $self->cachePathRegexDefaultSuffixFrag = function () use ($self) {
        if ($self->isPlugin() && !empty($GLOBALS['wp_rewrite'])){
            $pagination_base          = $GLOBALS['wp_rewrite']->pagination_base;
            $comments_pagination_base = $GLOBALS['wp_rewrite']->comments_pagination_base;
            return '(?:\/index)?(?:\.|\/(?:'.preg_quote($pagination_base, '/').'\/[0-9]+|'.preg_quote($comments_pagination_base, '/').'\-[0-9]+)[.\/])';
        } else {
            return '(?:\/index)?(?:\.|\/(?:page\/[0-9]+|comment\-page\-[0-9]+)[.\/])';
        }
    };
  • Submit PR.

@jaswrks
Copy link
Author

jaswrks commented Nov 12, 2015

Next Actions (Step 2 of 2)

  • New feature branch in the websharks/zencache-pro repo.

  • Replace this line with the following:

    const CACHE_PATH_REGEX_DEFAULT_SUFFIX_FRAG = null;
  • In this file find all occurrences of:

    $regex_suffix_frag = (string) $regex_suffix_frag;

    Find occurrences where the function that you find it in accepts the parameter $regex_suffix_frag = CACHE_PATH_REGEX_DEFAULT_SUFFIX_FRAG. One such case is found here.

    Change:

    $regex_suffix_frag = (string) $regex_suffix_frag;

    to:

    $regex_suffix_frag = $self->cachePathRegexSuffixFrag($regex_suffix_frag);
  • Submit PR.

@jaswrks
Copy link
Author

jaswrks commented Nov 12, 2015

Assigning this to @renzms :-)

@shazzygh
Copy link

Hey,
user who sent the original request here. Thanks for working on this!

Just wanted to note that I'm using $GLOBALS['wp_rewrite']->pagination_base = 'seite'; to do the translation job as well (not sure if it's the only way, but the most popular for sure).

@raamdev
Copy link
Contributor

raamdev commented Nov 27, 2015

Next Pro Release Changelog:

  • Bug Fix: Fixed a bug with clearing cache files for paginated pages where the pagination_base had been changed from the default page to something else (e.g., a translated string). The WP Rewrite API is now used to include pagination_base and comments_pagination_base when building paths to cache files to determine which cache files should be cleared. Props @renzms. See Issue #607.

@raamdev raamdev closed this as completed Nov 27, 2015
@wpsharks wpsharks locked and limited conversation to collaborators Dec 21, 2015
@raamdev
Copy link
Contributor

raamdev commented Dec 21, 2015

ZenCache Pro v151220 has been released and includes changes worked on as part of this GitHub Issue. See the release announcement for further details.


This issue will now be locked to further updates. If you have something to add related to this GitHub Issue, please open a new GitHub Issue and reference this one (#607).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants