How to fix WP Hide Post Plugin Parameter 2 to wp_hide_post_Public reference expected error?

WP Hide PostWP Hide Post is a free WordPress plugin that enables WordPress to hide posts or pages you don’t want to be included in your WordPress feed. While the posts and pages will remain visible to the public, you will have the option to prevent it from appearing in any of your post feeds.

The functionality of the plugin is cool, unfortunately, it hasn’t been updated for quite a while. Last known update at the time of this posting was August 20, 2017. That can be a problem since WordPress or the programming language behind WordPress are being updated from time to time, and any changes made may cause the plugin to stop working.

As of WordPress 5.1, the plugin continues to work, however, if PHP is upgraded to v. 7.1, the plugin will trigger an error similar to the one below:

Warning: Parameter 2 to wp_hide_post_Public::query_posts_join() expected to be a reference, value given in /../wp-includes/class-wp-hook.php on line 286

By the way, this issue can be found in WP Hide Post 2.0.11 or below.

While it seems like WordPress’ class-wp-hook.php on line 286 is the problem, it is not. It is just where the plugin is hooked. The error means that while the plugin is calling the hook class, it seems to be throwing a reference that is not well accepted by PHP 7.1.

To fix the error, you can simply disable the plugin, but of course, this will also make the Hide Post function stop from working. Another way is to rewrite the plugin’s problematic code, but in order to do this, you have to trace where the function query_posts_join is located in WP Hide Post’s modules as indicated in the error. It says there that parameter 2 to wp_hide_post_Public::query_posts_join() should be a reference but it seems parameter 2 is not accepted as a valid reference as per PHP 7.1’s standard. Since class-wp-hook is the one running the function in WordPress, the error in the plugin’s function will also be reflected by WordPress’ module, thus, you get a class-wp-hook.php error.

To save you guys the problem locating where the problem code can be found, you can find it in WP Hide Posts Plugins public/class-wp-hide-post-public.php or /wp-content/plugins/wp-hide-post/public/class-wp-hide-post-public.php in your WordPress folder. You need to edit the PHP file and there are three ways do this:

1. via your hosts’ Cpanel File Manager and browsing the folders until you get to class-wp-hide-post-public.php file.
2. via FTP.
3. via WordPress’ plugin editor — Plugins/Plugin Editor and selecting WP Hide Post/public/class-wp-hide-post-public.php for editing.

Open class-wp-hide-post-public.php and search for query_posts_join. In v. 2.0.11, it should be on line 318. Notice &$wp_query? That’s parameter 2… remove & and save the file.

It seems PHP 7.1 doesn’t accept & in front of variables in functions anymore and it wasn’t as lenient as before.

Change

public function query_posts_join($join, &$wp_query)

to

public function query_posts_join($join, $wp_query)

Removing & and saving the file should fix the problem. Now, all you have to do is refresh your website. If you’re using a caching plugin, you may need to purge your cache. You may also have to clean your browser cache.

Follow me at:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.