• Resolved David Goring

    (@dg12345)


    Can you add a filter to nsc_bar_json_with_js_function()
    class-nsc_bar_frontend.php:116

    So custom themes can add their own layout and any other overrides.

    Thanks
    David

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Support

    (@nikelschubert)

    Hi @dg12345,

    it is just released with Version 2.6.2.

    Regards
    Nikel

    Thread Starter David Goring

    (@dg12345)

    Thanks

    Although (and Sorry in advance) I just realised that while that filter is workable its not very efficient as it is already json when it gets to that filter, and would be easier to manipulate just before the json encode.

    Maybe in class-nsc_bar_banner_configs.php:38

    
        public function nsc_bar_get_banner_config_string(bool $for_display = false)
        {
            $this->nsc_bar_get_banner_config_array();
    
            $banner_config_array = apply_filters('nsc_bar_cookie_bar_config_for_display', $this->banner_config_array, $for_display);
    
            $banner_string = json_encode($banner_config_array);
    
            $validation = new nsc_bar_input_validation;
            $this->banner_config_string = $validation->nsc_bar_check_valid_json_string($banner_string);
            return $this->banner_config_string;
        }
    
    Plugin Author Support

    (@nikelschubert)

    Hi @dg12345,

    will add some additional filter within the next days. But not as you suggested:

    Dangerous Filter:
    nsc_bar_filter_banner_config_array_init
    class-nsc_bar_banner_configs.php:30

    
    public function nsc_bar_get_banner_config_array()
        {
            if (empty($this->banner_config_array)) {
                $banner_config_array = $this->initialise_banner_configs();
                $banner_config_array = apply_filters('nsc_bar_filter_banner_config_array_init', $banner_config_array);
                $this->banner_config_array = $banner_config_array;
            }
            return $this->banner_config_array;
        }

    Be carefull with this one: if your plugin/themes uses this filter it affects the settings as well and if someone updates the settings the output of your filter will be saved in the Database!

    Save Filter
    nsc_bar_filter_json_config_string_before_js
    this is a string again, so you have to decode it, this is the way if you only want to filter the output
    class-nsc_bar_frontend.php:96

    
    public function nsc_bar_json_with_js_function()
        {
            $validator = new nsc_bar_input_validation();
            $cleanedCookieTypes = $validator->esc_array_for_js($this->cookietypes);
            $popUpCloseJsFunction = '"onPopupClose": function(){location.reload();}';
            $pushToDLFunction = '"onStatusChange": function(status, chosenBefore) { var dataLayerName = "' . esc_js($this->dataLayerName) . '"; var cookieTypes = ' . json_encode($cleanedCookieTypes) . ';var cookieRootName = "' . esc_js($this->cookie_name) . '"; ' . file_get_contents(NSC_BAR_PLUGIN_DIR . "/public/onStatusChange.js") . '}';
    
            $json_config_string_with_js = $this->json_config_string;
            $json_config_string_with_js = apply_filters('nsc_bar_filter_json_config_string_before_js', $json_config_string_with_js);
    
            if (!empty($this->container)) {
                $setContainerPosition = '"container": document.querySelector("' . esc_js($this->container) . '")';

    the difference to the filter implemented before, is that it returns a valid json which you can decode.
    the old filter: nsc_bar_filter_json_config_string_with_js returns a valid JS object.

    • This reply was modified 2 years, 10 months ago by Support.
    • This reply was modified 2 years, 10 months ago by Support.
    • This reply was modified 2 years, 10 months ago by Support.
    Plugin Author Support

    (@nikelschubert)

    It is released with 2.6.3.
    Here is some documentation: https://beautiful-cookie-banner.com/documentation/filter-for-customisation/

    Thread Starter David Goring

    (@dg12345)

    would be nice to have one that doesn’t affect the saved config but it should be fine.

    Thanks,
    David

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Filter to the json config’ is closed to new replies.