• Resolved eorsavik

    (@eorsavik)


    Hi,

    1> Is there any hook in WordPress that is called every time when a user visit an website ? Whether it is home page or any other page, that hook must be called.

    2> Is there any way to know which page user is accessing and what his ip address ?

    Thanks !!!

Viewing 6 replies - 1 through 6 (of 6 total)
  • You could try the ‘wp‘ action. That will be run on every page load.

    Your web server will have the visitors IP address under $_SERVER [‘REMOTE_ADDR’];

    Moderator bcworkz

    (@bcworkz)

    Is there any way to know which page user is accessing

    The requested URL is also in the $_SERVER array. There will also be data on the request from get_queried_object(), but at the time “wp” action fires, the queried object has not been established yet. You’d need a later hook, or glean the requested data through the “request” filter.

    Thread Starter eorsavik

    (@eorsavik)

    I am using ‘body_class’ filter hook to retrieve the IP information of users visited. Although sometime it is called multiple times for single request, it still works for my purpose.

    Also I need to get the page details which the user has visited. $_SERVER doesn’t contain that information. Any idea ?

    Thanks !!!

    You can find everything that is contained on $_SERVER on it’s page.

    When you say this:

    Also I need to get the page details which the user has visited

    Do you mean the page that the user is currently on, the referring page (last page visited), or a page or pages that a user has visited before the current page view?

    Moderator bcworkz

    (@bcworkz)

    it is called multiple times for single request

    That happens more often than most people realize. For callbacks where it’s important they only run once per request, a callback can remove itself from the call stack after one pass with remove_action() or remove_filter().

    Thread Starter eorsavik

    (@eorsavik)

    @catacaustic

    I am using this code for URI display and looks like it works fine :

    $parts = parse_url( home_url() );
    $current_uri = "{$parts['scheme']}://{$parts['host']}" . add_query_arg( NULL, NULL );

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WordPress hook that is called when an user visit an website’ is closed to new replies.