← All changes
|
modules/mcp/abilities/build-composition/xml-parser.php
+46
-0
4.3.0-beta1
→
4.3.2
View file →
| @@ -92,5 +92,51 @@ | ||
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | return $descendants; |
| 95 | 95 | } |
| 96 | + | |
| 97 | + public function collect_duplicate_configuration_id_errors( \DOMDocument $dom ): array { | |
| 98 | + $counts = []; | |
| 99 | + | |
| 100 | + foreach ( $this->iterate_all_descendants( $dom ) as $node ) { | |
| 101 | + $configuration_id = $this->get_configuration_id( $node ); | |
| 102 | + if ( null === $configuration_id || '' === $configuration_id ) { | |
| 103 | + continue; | |
| 104 | + } | |
| 105 | + | |
| 106 | + if ( ! isset( $counts[ $configuration_id ] ) ) { | |
| 107 | + $counts[ $configuration_id ] = 0; | |
| 108 | + } | |
| 109 | + | |
| 110 | + $counts[ $configuration_id ]++; | |
| 111 | + } | |
| 112 | + | |
| 113 | + $errors = []; | |
| 114 | + foreach ( $counts as $configuration_id => $count ) { | |
| 115 | + if ( $count <= 1 ) { | |
| 116 | + continue; | |
| 117 | + } | |
| 118 | + | |
| 119 | + $errors[] = sprintf( | |
| 120 | + /* translators: %s: duplicate configuration-id value */ | |
| 121 | + __( 'Duplicate configuration-id "%s". Each element must have a unique configuration-id.', 'elementor' ), | |
| 122 | + $configuration_id | |
| 123 | + ); | |
| 124 | + } | |
| 125 | + | |
| 126 | + return $errors; | |
| 127 | + } | |
| 128 | + | |
| 129 | + public function validate_unique_configuration_ids( \DOMDocument $dom ): ?\WP_Error { | |
| 130 | + $errors = $this->collect_duplicate_configuration_id_errors( $dom ); | |
| 131 | + | |
| 132 | + if ( empty( $errors ) ) { | |
| 133 | + return null; | |
| 134 | + } | |
| 135 | + | |
| 136 | + return new \WP_Error( | |
| 137 | + 'elementor_duplicate_configuration_id', | |
| 138 | + implode( ' ', $errors ), | |
| 139 | + [ 'status' => \WP_Http::BAD_REQUEST ] | |
| 140 | + ); | |
| 141 | + } | |
| 96 | 142 | } |