pristas-peter / wp-graphql-gutenberg

Query gutenberg blocks with wp-graphql
https://wp-graphql-gutenberg.netlify.app
GNU General Public License v3.0
299 stars 62 forks source link

Call to undefined function libxml_disable_entity_loader() with php 8 #162

Open tedc opened 1 year ago

tedc commented 1 year ago

Hi, WP Graphql Gutenberg is returning this error, if I run php 8:

Internal Sever Error - Call to undefined function libxml_disable_entity_loader()

This is a big issue, libxml_disable_entity_loader() is strongly deprecated in php 8 and my hosting provider, Kinsta, is is abandoning support for php <8.

How can I solve?

MKlblangenois commented 1 year ago

👍

I'm in the same issue, changing PHP to version 8 throw me an error and I'm the same case as @tedc, All my site on Kinsta need to be updated to PHP 8.

In my case, somes update on the plugin has solved the issue.

Trying with wp-graphql-gutenberg@3.1.1 (not tried with @3.1.2, related to #153

➡️ On vendor package voku/simple_html_dom, this issue was fixed on original repo)

# /vender/voku/simple_html_dom/src/voku/helperHtmlDomParser.php
# line 303
- $disableEntityLoader = \libxml_disable_entity_loader(true);
+ if (\PHP_VERSION_ID < 80000) {
+    $disableEntityLoader = \libxml_disable_entity_loader(true);
+ }

# line 381
- \libxml_disable_entity_loader($disableEntityLoader);
+ if (\PHP_VERSION_ID < 80000 && isset($disableEntityLoader)) {
+    \libxml_disable_entity_loader($disableEntityLoader);
+ }
# /vender/voku/simple_html_dom/src/voku/XmlDomParser.php
# line 112
- $disableEntityLoader = \libxml_disable_entity_loader(true);
+ if (\PHP_VERSION_ID < 80000) {
+    $disableEntityLoader = \libxml_disable_entity_loader(true);
+ }

# line 175
- \libxml_disable_entity_loader($disableEntityLoader);
+ if (\PHP_VERSION_ID < 80000 && isset($disableEntityLoader)) {
+    \libxml_disable_entity_loader($disableEntityLoader);
+ }

In addition of that, plugin seems to return error when loadHtml($source) have an empty $source. To solve that, I've updated this file :

# /src/Blocks/Block.php
# Line 153
if ($result->isValid()) {
+ // Avoid error if innerHTML is empty
+ if (empty($data['innerHTML'])) {
+    return [
+      'attributes' => $attributes,
+      'type' => $type
+    ];
+ }

 return [
    'attributes' => array_merge(
       self::source_attributes(HtmlDomParser::str_get_html($data['innerHTML']), $type),
    $attributes
    ),
    'type' => $type
 ];
}

I hope this helps other people the time to have a plugin update

jaredcbaum commented 1 year ago

I am running Kinsta and PHP 8.0 and am encountering the same problem. On the latest graphql Gutenberg plugin version (0.4.1), I had to SSH into the wp-graphql-gutenberg plugin and navigate to the directory wp-graphql-gutenberg-develop/vender/voku/helper/HtmlDomParser.php and delete 2 lines of code that contained libxml_disable_entity_loader.

MKlblangenois commented 1 year ago

@pristas-peter @jasonbahl any update on this issue ?

jaredcbaum commented 9 months ago

This should be considered as an alternative for those using javascript: https://github.com/wpengine/faustjs

it uses wp-graphql-content-blocks under the hood instead of wp-graphql-gutenberg