Pilot-in / PiloPress

The most advanced WordPress Page Builder using Advanced Custom Fields & TailwindCSS
https://www.pilopress.com
63 stars 11 forks source link

PIP_Pattern - doesn't retrieve correct `pattern_post_id` in other than default language when logged out #203

Closed barnemax-pilotin closed 2 years ago

barnemax-pilotin commented 2 years ago

Describe the bug The Site Template id in default language is pip_pattern and let's say translated in english is pip_pattern_en_GB

The id retrieved is always the default language.

To Reproduce Multilangual website, logged out

Expected behavior To get the values from the translated version of the Site Template

Slack conversation about it: https://pilodev.slack.com/archives/D9G2V3MGA/p1649682470683449

Fixes 1) Works right away but is not the cleanest :

Before this line in the constructor : https://github.com/Pilot-in/PiloPress/blob/068f8d1734d460d861de4a071e3efd6b8dbedbef/includes/classes/pattern/class-pattern.php#L34

add_action( 'init', array( $this, 'multilingual_pattern_post_id' ) );

        /**
         * Change the pattern_post_id on front end to be able to get different language versions of patterns
         */
        public function multilingual_pattern_post_id() {

            // The problem is only front end
            if ( is_admin() ) {
                return;
            }

            // Append current language to post id
            $dl = acf_get_setting( 'default_language' );
            $cl = acf_get_setting( 'current_language' );

            // Add Language
            if ( $cl && $cl !== $dl ) {
                $this->pattern_post_id .= '_' . $cl;
            }
        }

2) Cleanest but needs to be tested furthermore (Konrad's recommandations) :

Change init for acf/init here : https://github.com/Pilot-in/PiloPress/blob/master/includes/classes/pattern/class-pattern.php#L34

And for both

https://github.com/Pilot-in/PiloPress/blob/master/includes/classes/pattern/class-flexible-header.php#L268 and https://github.com/Pilot-in/PiloPress/blob/master/includes/classes/pattern/class-flexible-header.php#L268

stocking the $pip_pattern->pattern_post_id in a var and apply acf_get_valid_post_id() to it

2022-04-11_15h06_48