Home>Support>Using hooks to rewrite css

Using hooks to rewrite css

By EdwardN, 10 years ago. Last reply by EdwardN, 10 years ago.
Notice: This thread is over two years old; the information may be outdated. Please consider creating a new thread if you require free support. If you have an active SiteOrigin Premium license, you can email our premium support desk at [email protected].

Hi,

I am trying to understand how to use hooks and filters in Page Builder. In this example I am putting the following code in the functions.php file of my theme.

function solus_siteorigin_panels_css_object($css, $panels_data, $post_id){
    $css->add_row_css($post_id,$panels_data,'', array(
        'margin-left' =>'-10px',
        'margin-right' =>'-10px',
    ));
}
add_filter('siteorigin_panels_css_object','solus_siteorigin_panels_css_object', 10, 3);

this causes a php error:

PHP Warning: Invalid argument supplied for foreach() in /Solus/_web/Solus/wp-content/plugins/siteorigin-panels/siteorigin-panels.php on line 919
PHP Fatal error: Call to a member function get_css() on a non-object in /Solus/wp-content/plugins/siteorigin-panels/siteorigin-panels.php on line 753

I must be missing something – or am i?

Thanks in advance.

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 10 years, 18 days ago EdwardN

    Looking at the source I think I see the solution to the first error – $panels_data is an array, so I need to set css for each panel.

    function solus_siteorigin_panels_css_object($css, $panels_data, $post_id){
        foreach ( $panels_data['grids'] as $gi => $grid ) {
            return $css->add_row_css($post_id, $gi, '', array(
                'margin-left' => '-10px',
                'margin-right' => '-10px'
            ));
        };
    };
    add_filter('siteorigin_panels_css_object','solus_siteorigin_panels_css_object', 10, 3);
    

    Not sure why I am still getting the second error though.

    PHP Fatal error: Call to a member function get_css() on a non-object in /Solus/wp-content/plugins/siteorigin-panels/siteorigin-panels.php on line 753

  2. 10 years, 18 days ago EdwardN

    Never mind I fixed it:

    function solus_siteorigin_panels_css_object($css, $panels_data, $post_id){
        foreach ( $panels_data['grids'] as $gi => $grid ) {
            $css->add_row_css($post_id, $gi, '', array(
                'margin-left' => '-10px',
                'margin-right' => '-10px'
            ));
        };
        return $css;
    };
    add_filter('siteorigin_panels_css_object','solus_siteorigin_panels_css_object', 10, 3);
    

    Thats pretty cool thanks.

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More