PHP 8 and Wordpress

When I update my PHP version to 8.0 I get the following error: Undefined constant “is_admin”.

This is used in a plugin called ‘content-views’ that allows me to sort of make indexes for externally published articles on my homepage.www.theomolenaar.nl

If I look this up in the content inspector I find:

var PT_CV_PUBLIC = {"_prefix":“pt-cv-”,“page_to_show”:“5”,"_nonce":“57505d433a”,“is_admin”:"",“is_mobile”:"",“ajaxurl”:"https://www.theomolenaar.nl/wp-admin/admin-ajax.php",“lang”:"",“loading_image_src”:"data:image… etc,

So I thought that the plugin might be the problem. I made a test site with a standard wordpress theme and the same plugin. http://test.theomolenaar.nl/ I seem to get the same code only this time it works with PHP 8.

I looked in designer but I can not change a lot in the wordpress theme I made. In Wordpress it is just a page with the plugin shortcode (twice).

So what could cause the difference ?

What version of Backlight are you using?

Backlight 4 should work through PHP 8.1; Backlight 5 is required for PHP 8.2 and beyond.

I use backlight 4

And the Backlight WP Theme works as expected without the plug-in?

Yes, but the plugin works with the standard wordpress themes such as twentytwentytwo twenty twenty, twentyseventeen.

The plugin uses this constant. If it is not used then errors go unnoticed I guess.

I have set the debug mode in Wordpress. With PHP8 I get an immediate error and no info.

However with PHP7.4 I get debug information regarding the use of is_admin in the WP theme:

Warning: Use of undefined constant is_admin - assumed ‘is_admin’ (this will throw an Error in a future version of PHP) in /mnt/web016/d0/89/51959089/htdocs/wp-content/themes/BacklightWordpressTheme/inc/theme_posts.php on line 145 Warning: Use of undefined constant is_admin - assumed ‘is_admin’ (this will throw an Error in a future version of PHP) in /mnt/web016/d0/89/51959089/htdocs/wp-content/themes/BacklightWordpressTheme/inc/theme_posts.php on line 145 Warning: Use of undefined constant is_admin - assumed ‘is_admin’ (this will throw an Error in a future version of PHP) in /mnt/web016/d0/89/51959089/htdocs/wp-content/themes/BacklightWordpressTheme/inc/theme_posts.php on line 145 Warning: Use of undefined constant is_admin - assumed ‘is_admin’ (this will throw an Error in a future version of PHP) in /mnt/web016/d0/89/51959089/htdocs/wp-content/themes/BacklightWordpressTheme/inc/theme_posts.php on line 145 Warning: Use of undefined constant is_admin - assumed ‘is_admin’ (this will throw an Error in a future version of PHP) in /mnt/web016/d0/89/51959089/htdocs/wp-content/themes/BacklightWordpressTheme/inc/theme_posts.php on line 145 Warning: Use of undefined constant is_admin - assumed ‘is_admin’ (this will throw an Error in a future version of PHP) in /mnt/web016/d0/89/51959089/htdocs/wp-content/themes/BacklightWordpressTheme/inc/theme_posts.php on line 145 Warning: Use of undefined constant is_admin - assumed ‘is_admin’ (this will throw an Error in a future version of PHP) in /mnt/web016/d0/89/51959089/htdocs/wp-content/themes/BacklightWordpressTheme/inc/theme_posts.php on line 145 Warning: Use of undefined constant is_admin - assumed ‘is_admin’ (this will throw an Error in a future version of PHP) in /mnt/web016/d0/89/51959089/htdocs/wp-content/themes/BacklightWordpressTheme/inc/theme_posts.php on line 145 Warning: Use of undefined constant is_admin - assumed ‘is_admin’ (this will throw an Error in a future version of PHP) in /mnt/web016/d0/89/51959089/htdocs/wp-content/themes/BacklightWordpressTheme/inc/theme_posts.php on line 145

Think I got it now. The purpose of the plugin is to display posts. So if I disable it no posts are displayed. Then it is just an empty page…

Hi @TheoMolenaar, this was fixed in Backlight 4 in late 2021. Can you check that you have the latest version of the modules in the Backlight Modules page? If you do, can you visit Designer > Templates, click on the name of the WP template and then click on Export Theme to Wordpress?
If that still doesn’t solve the issue, try to edit the exported file itself. Line 145 of wp-content/themes/BacklightWordpressTheme/inc/theme_posts.php should look like:

			if (is_admin()) {

(note the parentheses in is_admin(), which were missing prior to the fix)

I did that, and I do not get an error anymore. However the plugin does not work properly. Also not in PHP7.4 anymore.

The first posts do not show pictures. After the scroll they do. https://www.theomolenaar.nl/

Ok, the plugin now does not work with the first posts.The image is not shown. In both php7.4 (where they used to work) and php 8.0. If I inspect the code I see a correct path. If I copy that I get the image. Only when it does the infinite scroll on later posts it does work. However if I choose another theme then the backlight - theme (I tried a few) they work as normal. Also in the ‘content views’ preview things work as expected.

Hello Ben. I also reported the problem on the support of the plugin. They were very helpful and reported this:

Hi Theo,

We could login then fix the issue.

It was caused by the lazyload feature of the theme with the code here. (link to the theme.

To prevent if from affecting images in our views, we added this code:
https://www.theomolenaar.nl/wp-admin/admin.php?page=edit-snippet&id=5&result=added-and-activated

Code was : /* Disable lazyload of theme /
add_action( ‘pt_cv_view_process_start’, ‘cvp_theme_disable_theme_lazyload’ );
function cvp_theme_disable_theme_lazyload() {

  • remove_filter( ‘wp_get_attachment_image_attributes’, ‘mod_gallery_image_attributes’, 10);*
    }

(theme’s lazyload will continue to work outside of our views)

So I guess that the lazyload was not in the previous version. It works with the snippet but maybe it is better to disable the lazyload, since it can cause trouble.

Sounds like an issue with the plugin, not with our theme. I have no intention of disabling lazy-load of images; it’s an important script for site performance.