Pesky WordPress bugs, this is how we take care of them.
It’s all about isolating the problem, some keyword searching, and a smattering of luck. This post just for my own reference.
I’m helping my friend Mariana Funes with a collection of sites in her WordPress Multisite at http://marianafun.es (note she is using my WP-Dimension theme for a landing domain page).
Another site in her fleet uses a premium theme that she is fond of; but one her course sites a few of her protected posts where just ignoring the built in WordPress functionality that provides it. I tried the regular stuff, flicking off plugins, deleting cache and cookies. No change.
Then I tried swapping the theme; and boom! It worked. So now I know it’s a theme issue.
But what in a theme would make it not provide built in WordPress core code for password protected posts? These searches did not get me much closer:
- wordpress protected post not working
- wordpress password protected page still visible
- wordpress password protected page not asking for password
In sifting through the results for the third search I hit on something that seemed on track from StackExchange:
Ended up discovering that the template needed the content() function in it for the password prompt to appear. For those that are in my situation and need to password protect content or PHP scripts in a whole template, this works http://wordpress.org/support/topic/346373
The link did not work, but in combing through the theme’s templates, I saw in content-single.php
that the way the posts content was being displayed was a bit different than normal:
echo apply_filters('the_content', $post->post_content);
which I think applies a few more text checks (?). I tested by commenting out this line and replacing with:
the_content();
and Boom! Now we were getting the proper display, not seeing the content, but instead:
But how to fix? Ideally I would go make a child theme that would have the replacement for this file. That’s the clean way. But for a short term and quicker fix, I did What You Should Not Do, edited the theme file, replacing the original line with:
if ( post_password_required() ) { the_content(); } else { echo apply_filters('the_content', $post->post_content); }
It seems to work. I left a comment on the theme author’s site in Theme Forest, it seems like something they should fix, with more awareness of any implications of my hack.
But who would have known that password protection was tied to the way WordPress content is rendered? Now I do. You too, my odd reader who made it to the bottom of this post. Hi.
Featured Image: Pixabay image by TambiraPhotography shared into the public domain using Creative Commons CC0.
Nice catch and fix. Read till the end because it’s fun to read these kinds of posts! 🙂