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

cmplz_manage_consent_html filter can't be used with variables in parenthesis #431

Open
mkalamarz opened this issue Nov 27, 2024 · 0 comments

Comments

@mkalamarz
Copy link

I wanted to make a simple modification to how "Manage consent" element is structured. Instead of overwriting the whole manage-consent.php file I've used the cmplz_manage_consent_html filter present in your code. But it is in fact unusable because of how the "variable" replacement code is placed before the content can be filtered.

To be more specific. Here is the code that replaces all "variables" denoted by curly brackets.

foreach ( $cookie_settings as $fieldname => $value ) {
if ( isset( $value['text'] ) ) {
$value = $value['text'];
}
if ( is_array( $value ) ) {
continue;
}
if ( $fieldname !== 'logo' ) {
$value = nl2br( $value );
}
$temp_banner_html = str_replace( '{' . $fieldname . '}', $value, $temp_banner_html );
$temp_manage_consent_html = str_replace( '{' . $fieldname . '}', $value, $temp_manage_consent_html );
}

And some lines later is the part that lets me overwite the html of this element

echo $comment .
'<div id="cmplz-cookiebanner-container">' . apply_filters( "cmplz_banner_html", $banner_html ) . '</div>
<div id="cmplz-manage-consent" data-nosnippet="true">' . apply_filters( "cmplz_manage_consent_html", $manage_consent_html ) . '</div>';

So I can't use the "variables" in the HTML fed to the cmplz_manage_consent_html as they will not get properly replaced by the first mentioned chunk of code.

To fix this:
First, change

$temp_manage_consent_html = $manage_consent_template;
to $temp_manage_consent_html = apply_filters( "cmplz_manage_consent_html", $manage_consent_html );

Second, change the apply_filters( "cmplz_manage_consent_html", $manage_consent_html ) in

<div id="cmplz-manage-consent" data-nosnippet="true">' . apply_filters( "cmplz_manage_consent_html", $manage_consent_html ) . '</div>';
to $manage_consent_html as at this step you simply use what you have.

PS The same can be said and done about the cmplz_banner_html filter.

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

No branches or pull requests

1 participant