• WP 6.7.2, uipress lite 3.5.05, wordfence 8.0.3

    Wordfence has a Live Traffic feature that has an infinite scroll (using ajax) that repeatedly loads batches of traffic data (50 entries at a time) each time you reach the bottom of the page. With uipress enabled (and applied to users/groups), reaching the bottom of the scrollable area does nothing. I did a bunch of digging, and it appears that the wordfence JS is expecting the <html> to be the scrollable element when it comes to listening and calculating the scroll position for loading more entries.

    I was able to come up with a workaround script to attach a new scroll listener to the scrollable page content element which fixes the broken functionality for this specific case/page, but my thought would be that this is probably going to be an issue with any plugins that might use an infinite scroll in their UI.

    Let me know if you need any more info.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author markuipress

    (@markuipress)

    Hey, thanks for reporting. Would you be open to sharing your code workaround here so we can help anyone else out that is having this issue? I will see if we can get a patch in the core though.

    Thread Starter blakmarkit

    (@blakmarkit)

    @markuipress sure!

    In this case, I’m using a snippets plugin to load the JS, and I have conditions set to only load this on the Live Traffic page, inline in the admin footer. Not positive if this is the best way to do it, but it works for me.

    var observer;
    var lastContainer = null; // Store the last detected scroll container
    var loadingListings = false; // Flag to track if a request is in progress

    function attachScrollEvent() {
    var newScrollable = jQuery("#uip-id-of-the-scrollable-container");

    // Prevent re-attaching if it's the same container
    if (newScrollable.length && newScrollable[0] !== lastContainer) {
    lastContainer = newScrollable[0]; // Update last container

    console.log("New scroll container detected:", newScrollable);

    newScrollable.off("scroll").on("scroll", function () {
    var container = jQuery(this);
    var containerHeight = container.outerHeight();
    var containerScrollTop = container.scrollTop();
    var containerScrollBottom = containerScrollTop + containerHeight;
    var scrollThreshold = container[0].scrollHeight - containerHeight;

    // Add a slight buffer to trigger before exactly reaching the bottom
    var buffer = 50; // Adjust as needed

    // If no request is in progress and we're near the bottom, trigger the load
    if (!loadingListings && containerScrollBottom + buffer >= scrollThreshold) {
    console.log("Infinite scroll triggered!");
    loadingListings = true; // Set flag to true to prevent multiple requests

    WFAD.wfLiveTraffic.loadNextListings(function () {
    console.log("Next listings loaded.");
    WFAD.reverseLookupIPs();
    WFAD.avatarLookup();

    // Reset the loading flag after the request completes
    loadingListings = false;
    });
    }
    });
    }
    }

    // Debounce function to avoid excessive calls
    function debounce(func, delay) {
    var timer;
    return function () {
    clearTimeout(timer);
    timer = setTimeout(func, delay);
    };
    }

    // Observe changes and attach the scroll event
    observer = new MutationObserver(debounce(attachScrollEvent, 500));
    observer.observe(document.body, { childList: true, subtree: true });

    // Initial attachment in case the container already exists
    attachScrollEvent();
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.