Skip to content

Commit

Permalink
Find META tag with HTML Tag Processor instead of RegExp
Browse files Browse the repository at this point in the history
  • Loading branch information
dmsnell committed Oct 25, 2023
1 parent 4580d14 commit bb0245c
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -797,14 +797,21 @@ public function update_data( $request ) {
case 'pinterest':
case 'yandex':
case 'facebook':
$grouped_options_current = (array) get_option( 'verification_services_codes' );
$grouped_options = $grouped_options_current;
$grouped_options_current = (array) get_option( 'verification_services_codes' );
$grouped_options = $grouped_options_current;
$grouped_options[ $option ] = $value;

// Extracts the content attribute from the HTML meta tag if needed.
if ( preg_match( '#.*<meta name="(?:[^"]+)" content="([^"]+)" />.*#i', $value, $matches ) ) {
$grouped_options[ $option ] = $matches[1];
} else {
$grouped_options[ $option ] = $value;
$processor = new WP_HTML_Tag_Processor( $value );
while ( $processor->next_tag() ) {
if ( 'META' === $processor->get_tag() && null !== $processor->get_attribute( 'name' ) ) {
$grouped_options[ $option ] = $processor->get_attribute( 'content' );
break;
}

if ( 'BODY' === $processor->get_tag() ) {
break;
}
}

// If option value was the same, consider it done.
Expand Down

0 comments on commit bb0245c

Please sign in to comment.