@@ -791,7 +791,7 @@ private function matching_schema( $recipe ): ?array {
791791 $ items = self ::recipe_items ( $ post_content , 'body ' );
792792
793793 foreach ( $ items as $ item ) {
794- if ( self ::is_recipe_item_for_recipe_html ( $ item, $ recipe ) ) {
794+ if ( self ::is_allowed_recipe_item ( $ item ) ) {
795795 return $ item ;
796796 }
797797 }
@@ -815,7 +815,7 @@ private function matching_schema( $recipe ): ?array {
815815 $ items = self ::recipe_items ( $ html , 'head ' );
816816
817817 foreach ( $ items as $ item ) {
818- if ( self ::is_recipe_item_for_recipe_html ( $ item, $ recipe ) ) {
818+ if ( self ::is_allowed_recipe_item ( $ item ) ) {
819819 return $ item ;
820820 }
821821 }
@@ -901,19 +901,17 @@ private static function recipe_items_in_graph( array $carry, array $json ) {
901901 }
902902
903903 /**
904- * Best-guess if the given schema item is for the given recipe HTML.
904+ * Confirm that the given schema item can be used for recipe HTML.
905905 *
906- * @param array $schema The schema item to check.
907- * @param string $html The recipe HTML to check.
908- * @return bool True if the schema item is for the recipe HTML, false otherwise.
906+ * @param array $schema The schema item to check.
907+ * @return bool
909908 */
910- private static function is_recipe_item_for_recipe_html ( array $ schema , string $ html ) {
909+ private static function is_allowed_recipe_item ( array $ schema ) {
910+ // This method used to confirm that the schema 'name' appeared in the HTML, but this was found to be too restrictive.
911911 return (
912912 isset ( $ schema ['name ' ] )
913913 && is_string ( $ schema ['name ' ] )
914914 && strlen ( $ schema ['name ' ] ) > 0
915- // The recipe HTML would have the name of any recipe JSON-LD items found within it, so strip tags to avoid false positives.
916- && str_contains ( wp_strip_all_tags ( $ html ), $ schema ['name ' ] )
917915 );
918916 }
919917
0 commit comments