• Resolved peter8nss

    (@peter8nss)


    When using the Content Control Query Monitor display I get error:

    Warning: Attempt to read property "post_title" on null in /var/www/html/wp-content/plugins/content-control/classes/QueryMonitor/Output.php on line 219 Warning: Attempt to read property "post_type" on null in /var/www/html/wp-content/plugins/content-control/classes/QueryMonitor/Output.php on line 220 

    I think the problem is that user_can_view_content can be called with post_id null. So get_post( $post_id ) in “output_post_restrictions” will return null in these cases. Hence, the warning message.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter peter8nss

    (@peter8nss)

    Similar error for post_type on the following line.

    Thread Starter peter8nss

    (@peter8nss)

    Furthermore, I don’t think all the post_ids that are passed are actually post ids. Some are term_ids, so the title lookup is getting the title of a post with the same id as that term.

    Thread Starter peter8nss

    (@peter8nss)

    Those which are term_ids are probably identified by context=terms so something like the following code in the “output_post_restrictions” might help

    			if ( 'terms' === $post_data['context'] ) {
    $term = get_term( $post_id );
    $name = $term->name;
    $type = 'TERM';
    } else {
    $post = get_post( $post_id );
    $name = $post->post_title;
    $type = $post->post_type;
    }

    Then use $name and $type in place of $post->post_title/type respectively.

    Thread Starter peter8nss

    (@peter8nss)

    For terms it might help to indicate the taxonomy they come from, e.g.

    $type = 'TERM/' . $term->taxonomy;
    Thread Starter peter8nss

    (@peter8nss)

    Column titles might also need revising to be more generic, e.g. ID, Title/Name, Type

    Plugin Author Daniel Iser

    (@danieliser)

    @peter8nss – Do you happen to know how you triggered this? I have QM on 100% of the time during development and haven’t come across this, there must be a conflict or config set that were are not testing against.

    Furthermore, I don’t think all the post_ids that are passed are actually post ids. Some are term_ids, so the title lookup is getting the title of a post with the same id as that term.

    Very possible, the QM integration was added before TermQuery processing was added. I’ll have to rework that a bit to ensure we keep term & post lists separate.

    For terms it might help to indicate the taxonomy they come from, e.g.

    Column titles might also need revising to be more generic, e.g. ID, Title/Name, Type

    Excellent ideas.

    Thread Starter peter8nss

    (@peter8nss)

    I think my original assumption about the problem coming from null post_id values was incorrect. I think all the cases I saw were actually term_id values. And if you pass a term_id to get_post and there isn’t a post with the same id, then it returns null. Hence, the PHP warnings.

    You will only see it if the page you are viewing involves a query and that term_ids from that query don’t have posts with the same ids.

    I’ve been running with my suggested code changes to “output_post_restrictions” and that clears the PHP warnings.

    Plugin Author Daniel Iser

    (@danieliser)

    @peter8nss – Super helpful thanks. Will get this patched.

    Plugin Author Daniel Iser

    (@danieliser)

    @peter8nss – I added your simple change proposed above for now, but I think in a near future version we will completely separate how we handle terms, specifically adding internal get_term methods and separating those concerns into separate specific handlers.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Query Monitor PHP warning’ is closed to new replies.