PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.3
Elementor Website Builder – more than just a page builder v4.3.3
4.3.3 4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 All 456 releases
← All changes | modules/mcp/abilities/build-composition/xml-parser.php +18 -2 4.3.1 → 4.3.3 View file →
@@ -21,18 +21,34 @@
21 21 libxml_clear_errors();
22 22 libxml_use_internal_errors( $previous );
23 23
24 24 if ( ! $loaded ) {
25 - $message = $errors ? $errors[0]->message : 'Unknown XML error.';
25 + $message = $errors ? $this->describe_libxml_error( trim( $errors[0]->message ) ) : 'Unknown XML error.';
26 26 return new \WP_Error(
27 27 'invalid_xml',
28 28 /* translators: %s: XML parse error message */
29 - sprintf( __( 'Failed to parse xml_structure: %s', 'elementor' ), trim( $message ) ),
29 + sprintf( __( 'Failed to parse xml_structure: %s', 'elementor' ), $message ),
30 30 [ 'status' => \WP_Http::BAD_REQUEST ]
31 31 );
32 32 }
33 33
34 34 return $dom;
35 + }
36 +
37 + private function describe_libxml_error( string $message ): string {
38 + $root = preg_quote( self::COMPOSITION_ROOT_TAG, '/' );
39 +
40 + if ( preg_match( '/tag mismatch: ' . $root . ' line \d+ and (\S+)$/', $message, $matches ) ) {
41 + /* translators: %s: XML tag name */
42 + return sprintf( __( 'Closing tag </%s> has no matching opening tag.', 'elementor' ), $matches[1] );
43 + }
44 +
45 + if ( preg_match( '/tag mismatch: (\S+) line \d+ and ' . $root . '$/', $message, $matches ) ) {
46 + /* translators: %s: XML tag name */
47 + return sprintf( __( 'Element <%s> is not closed.', 'elementor' ), $matches[1] );
48 + }
49 +
50 + return $message;
35 51 }
36 52
37 53 public function get_root( \DOMDocument $dom ): ?\DOMElement {
38 54 return $dom->documentElement ?? null; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DOMDocument API.