At first, you’re calling a WordPress function directly inside a new instance of your class which can lead to a null wp_query state which produces a log when calling your code.
To fix this you should move the call to a place somewhere like the init
hook, like this:
class Something() {
public function __construct() {
add_action('init', [$this, 'my_func']);
}
public function my_func() {
if ( is_single() ) {
require_once( '/lib/control.php' );
}
}
}
new Something();
Your function will be run after the WordPress initialization is ended and before any headers so, the global $wp_query
instance now knows what’s happening.
If the above solution didn’t work for you, You can also try these:
- Move your call inside the
single.php
file of your theme. (easy, messy) -
Double check if your
single.php
file had been wrapped with a loop. -
Try to replace
is_single
method with$wp_query->is_single()
and see what happens. (don’t forget to addglobal $wp_query
at the first line of your function)