• Resolved taijj

    (@taijj)


    Hi,

    I’m using ajax to load the content of one page into another page. Unfortunately Youtube videos in the loaded content won’t be blocked by Complianz. Is there a way to delay or rerun the scripts that analyze a page’s content and put the placeholders in place?

    Regards,
    T

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Rogier Lankhorst

    (@rogierlankhorst)

    @taijj, Apparently the tool bypasses the normal WordPress hooks. An example of an integration we have for such a situation is the Content Views plugin:

    function cmplz_content_views_cookieblocker($html){
    	return COMPLIANZ::$cookie_blocker->replace_tags($html);
    }
    add_filter( 'pt_cv_view_html', 'cmplz_content_views_cookieblocker' );

    We need a filter like the pt_cv_view_html filter. If it filters the outputted ajax loaded html, this will block the content.

    In addition you need to enabled “block ajax loaded content” in the general settings. Which sets the placeholders on ajax load.

    What plugin do you use for this?

    Thread Starter taijj

    (@taijj)

    Hi @rogierlankhorst ,

    Thanks for the reply! I’m not using any plugin. I wrote the script, that uses ajax, myself and it’s part of my custom theme. If you get the impression that WordPress stuff is bypassed… that’s probably because it is.

    I’m not an experienced WordPress Dev, and made something like this for the first time.
    Here’s what I’m doing with ajax:

    Javascript

    
    function loadContent(id)
        {
            var data = { action: "tnet_load_post_content", pageId: id };
            useAjax(data, onContentLoaded); // Ajax call
        }
    
        function onContentLoaded(response)
        {
            var data = JSON.parse(response); // parse response
    
            contentContainer.html(data[0]); // Add parsed html to dedicated container
    
            // Do more stuff that WordPress does by default, but not for
            // HTML that was loaded in later with ajax
            addMissingStyles(data[1]);
            addMissingScripts();
            addProjectListeners();
            updateTabs();
            updateLanguageButtons();
            updateBackButtons();
            scrollToTop();
        }
    

    php

    //Load page into another page
        add_action( 'wp_ajax_tnet_load_post_content', 'tnet_load_post_content' );
        add_action( 'wp_ajax_nopriv_tnet_load_post_content', 'tnet_load_post_content' );
    
        function tnet_load_post_content() {
    
            $id = $_POST['pageId'];
            $meta = get_post_meta( $id, 'panels_data', true );
    
            if( class_exists( 'SiteOrigin_Panels' ) && $meta )
            {
                $renderer = SiteOrigin_Panels::renderer();
                $content = $renderer->render( $id );
                $css = $renderer->generate_css( $id );
            }
            else
            {
                $css = '';
                $content = apply_filters( 'the_content', get_page($id)->post_content );
            }
    
            echo json_encode(array($content, $css));
            die(); //<- will add a 0 in response, if not called!
        }

    If you got the time or need more details, I’ve even written a post about this topic here

    Any help would be greatly appreciated!

    Regards,
    T

    • This reply was modified 2 years, 4 months ago by taijj.
    Plugin Contributor Rogier Lankhorst

    (@rogierlankhorst)

    Hi @taijj,

    If you add something like this within the code:

    $content = COMPLIANZ::$cookie_blocker->replace_tags($content);

    It should work.

    Thread Starter taijj

    (@taijj)

    Thank you @rogierlankhorst, that is exactly what I needed! Works like a charm! ??

    You’re awesome! Thank you!

    Regards,
    T

    • This reply was modified 2 years, 4 months ago by taijj.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Rerunning Placeholder Scripts’ is closed to new replies.