0

I was asked to fix a wordpress based site and I don't get what's going on with it.

The (custom) theme has a page-home.php that is the Home page.

Whatever edits I make to this file, if I refresh the page logged in wp-admin (so, I'm an admin), the change is seen, but logged out (anonymous - as the site is intended to be used) it's still the old content.

I did the following:

  • downloaded all site locally, opened all *.php files, and searched for duplicate similar homepage sites, just in case a different one is served for anonymous browsing - no duplicate files
  • searched for keywords like is_admin, is_user_logged_in, didn't find such logic
  • went through this post to get what the order of execution is in WP. Helped a bit but didn't help me solve the problem
  • hardcoded things in header.php file -> result only displayed while logged in.

I don't know how else to find out why I keep getting old page.

I assume wordpress is rendering some pages, but why doesn't use the latest changes if anonymous? How to fix this?

12
  • Really sounds like you're using a caching plugin of some kind. Are you sure you're not? WP Super Cache? W3 Total Cache? WP Rocket? Litespeed Cache? Jun 20, 2018 at 13:21
  • Either I'm not using or it doesn't contain cache or rocket in title: No plugins found for “cache”. I just gave a quick scan over all active plugins (eyeballing them) and none of them seem related to caching...
    – Adelin
    Jun 20, 2018 at 13:23
  • @JacobPeattie I just see now that W3 Total Cache was installed. I see a w3tc-config folder. But the plugin doesn't appear in the plugins folder
    – Adelin
    Jun 20, 2018 at 13:39
  • 2
    If you can't see a caching solution, the next step is to check your wp-content dir for a cache-folder & your .htaccess for any caching rules which may exist without a plugin. The text may also be modified by a js-script (food for thought)
    – admcfajn
    Jun 20, 2018 at 13:39
  • 1
    Yes. Caching is typically configured to be turned off for logged-in users. Jun 20, 2018 at 14:06

2 Answers 2

0

If you have wp-cli installed : https://wp-cli.org/ You can try a wp cache type command from the root of your folder.

If you get Unknown it's a plugin issue or a mu-plugin issue I think.

If it's Default, there is no WP cache plugin (I'm not really sure about that but 90% sure).

After that you may grep for 'WP_CACHE' from the root of your project.

grep -Ri 'WP_CACHE' *

You'll be able to delete this constant and remove the cache folder. Things going to work. (I hope for you)

0
0

So I deleted cache folders, I removed plenty plugins, edited .htaccess files, etc and still didn't work.

I figured, if cache issues are lost after login, and since this site is designed to be used anonymously - well then log a fake user in.

  1. I created a user anonuser with subscriber role
  2. I added in functions.php this code to auto login (source):

    function auto_login() {
      $loginusername = 'anonuser';
      if (!is_user_logged_in()) { 
        //get user's ID
        $user = get_user_by('login', $loginusername);
        $user_id = $user->ID;
        wp_set_current_user($user_id, $loginusername);
        wp_set_auth_cookie($user_id);
        do_action('wp_login', $loginusername);
        show_admin_bar(false);
        exit;
      }
    }
    add_action('wp', 'auto_login');
    
  3. Lastly, just in case someone visits wp-admin manually, log them out and show the login page (source):

    add_action( 'init', 'my_custom_dashboard_access_handler');
    
    function my_custom_dashboard_access_handler() {
    
      // Check if the current page is an admin page
      // && and ensure that this is not an ajax call
      if ( is_admin() && !( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
    
        //Get all capabilities of the current user
        $user = get_userdata( get_current_user_id() );
        $caps = ( is_object( $user) ) ? array_keys($user->allcaps) : array();
    
        //All capabilities/roles listed here are not able to see the dashboard
        $block_access_to = array('subscriber', 'contributor', 'my-custom-role', 'my-custom-capability');
    
        if(array_intersect($block_access_to, $caps)) {
          wp_logout();
          wp_redirect( wp_login_url() );
          exit;
        }
      }
    }
    
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.