• Resolved hughie.molloy

    (@hughiemolloy)


    I am seeing this error when trying to automatically create a new post.

    Trying to get property of non-object
    /mnt/storage/stage/www/wp-content/plugins/publish-to-apple-news/includes/apple-exporter/class-exporter-content.php – 231 – HandleError

    public function nodes() {
    // Because PHP’s DomDocument doesn’t like HTML5 tags, ignore errors.
    $dom = new \DOMDocument();
    libxml_use_internal_errors( true );
    $dom->loadHTML( ‘<?xml encoding=”utf-8″ ?>’ . $this->content() );
    libxml_clear_errors( true );

    // Find the first-level nodes of the body tag.
    return $dom->getElementsByTagName( ‘body’ )->item( 0 )->childNodes; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
    }

    While the php ignore errors comment is worrying I believe a simple change might stop this erroring out.

    return $dom->getElementsByTagName( ‘body’ )->item( 0 )->childNodes ?? [];

    This bug stops the actual insert of post, thus makes the site unworkable.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter hughie.molloy

    (@hughiemolloy)

    Here is my stack trace in my error log:

    Trying to get property of non-object
    /wp-content/plugins/publish-to-apple-news/includes/apple-exporter/class-exporter-content.php – 231 – HandleError
    /wp-content/plugins/publish-to-apple-news/includes/apple-exporter/builders/class-builder.php – 123 – nodes
    /wp-content/plugins/publish-to-apple-news/includes/apple-exporter/builders/class-components.php – 731 – content_nodes
    /wp-content/plugins/publish-to-apple-news/includes/apple-exporter/builders/class-components.php – 41 – _split_into_components
    /wp-content/plugins/publish-to-apple-news/includes/apple-exporter/builders/class-builder.php – 66 – build
    /wp-content/plugins/publish-to-apple-news/includes/apple-exporter/class-exporter.php – 243 – to_array
    /wp-content/plugins/publish-to-apple-news/includes/apple-exporter/class-exporter.php – 171 – generate_json
    /wp-content/plugins/publish-to-apple-news/admin/apple-actions/index/class-push.php – 421 – generate
    /wp-content/plugins/publish-to-apple-news/admin/apple-actions/index/class-push.php – 183 – generate_article
    /wp-content/plugins/publish-to-apple-news/admin/apple-actions/index/class-push.php – 84 – push
    /wp-content/plugins/publish-to-apple-news/admin/class-admin-apple-post-sync.php – 92 – perform
    /wp-includes/class-wp-hook.php – 288 – do_publish
    /wp-includes/class-wp-hook.php – 310 – apply_filters
    /wp-includes/plugin.php – 453 – do_action
    /wp-includes/post.php – 3640 – do_action
    REDACTED.php – 110 – wp_insert_post

    The apple news article gets made but not the wordpress post.

    My fix above does not actually work for php5 so ignore it.

    Plugin Author Kevin Fodness

    (@kevinfodness)

    Is it possible that this function is getting run with empty post content? We can add some defensive programming around this to prevent the error from popping. Tracking this via https://github.com/alleyinteractive/apple-news/issues/554

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Error get nodes of content (there may not be any)’ is closed to new replies.