Mixed results with is_page() WordPress function, when using either $this, or self

49 views Asked by At

I'm trying to understand something. I inherited an old Wordpress plugin, and I'm chewing my way through converting it from PHP5 -> PHP8.

I came across this check, which caused an error when executing:

Notice: Accessing static property PropertySearch::$listing_details_template_name as non static

I found online that this can be fixed, by using self instead of $this to access a static member. However, when I pass the self version to the is_page Wordpress function, it returns false, where-as when I pas the $this version, it returns true.

When I view the value of both self::$listing_details_template_name and $this->listing_details_template_name they contain the exact same string.

One thing I've noticed through debugging, is that upon entering the is_page function, the $page variable is NULL when using $this->listing_details_template_name, and contains the template name when using self::$listing_details_template_name, and since $page is NOT NULL, this passes the function, and returns false.

Here's a quick demo of what I'm talking about.

Ultimately, I'm trying to find out why this is happening, and what I can do to circumvent the original error, and or this new issue I'm faced with.

is_page(): https://wp-kama.com/function/is_page

global $wp_query;

    if (is_page(self::$listing_details_template_name)) {
        echo nl2br ("[DEBUG] - self2 = " . self::$listing_details_template_name . " \r\n");
    }

    if (is_page($this->listing_details_template_name)) {
        echo nl2br ("[DEBUG] - this2 = " . self::$listing_details_template_name . " \r\n");
    }

[EDIT] - For the time being, I've added this to the query.php file of WordPress.

    if ($page = 'property-search-single-property-details-template.php') {
        $page = NULL;
    }

However, this is just a bandaid so I can continue debugging. I would love a solution that does NOT involve me modifying the core WordPress files. Or at the very least, some further understanding of why this is happening.

0

There are 0 answers