Skip to content

Commit

Permalink
Automatically convert old XPath scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Jan 10, 2025
1 parent d01b96e commit d7d0ae8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion plugins/optimization-detective/class-od-element.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ class OD_Element implements ArrayAccess, JsonSerializable {
* @param OD_URL_Metric $url_metric URL Metric.
*/
public function __construct( array $data, OD_URL_Metric $url_metric ) {
$this->data = $data;
$this->data = $data;

// Convert old XPath scheme.
$xpath = preg_replace(
'#^/\*\[1\]\[self::HTML\]/\*\[2\]\[self::BODY\]/\*\[\d+\]\[self::([a-zA-Z0-9:_-]+)\]#',
'/HTML/BODY/$1',
$this->data['xpath']
);
if ( is_string( $xpath ) && '' !== $xpath ) {
$this->data['xpath'] = $xpath;
}

$this->url_metric = $url_metric;
}

Expand Down

0 comments on commit d7d0ae8

Please sign in to comment.