$value ) { $schema['recipeIngredient'][ $key ] = wp_strip_all_tags( (string) $value ); } } if ( isset( $data['recipe-instructions'] ) && ! empty( $data['recipe-instructions'] ) ) { foreach ( $data['recipe-instructions'] as $key => $value ) { if ( isset( $value['steps'] ) && ! empty( $value['steps'] ) ) { $schema['recipeInstructions'][ $key ]['@type'] = 'HowToStep'; $schema['recipeInstructions'][ $key ]['text'] = wp_strip_all_tags( (string) $value['steps'] ); $schema['recipeInstructions'][ $key ]['name'] = ! empty( $value['name'] ) ? wp_strip_all_tags( (string) $value['name'] ) : null; $schema['recipeInstructions'][ $key ]['url'] = ! empty( $value['url'] ) ? wp_strip_all_tags( (string) $value['url'] ) : null; if ( isset( $value['image'] ) && ! empty( $value['image'] ) ) { $schema['recipeInstructions'][ $key ]['image'] = BSF_AIOSRS_Pro_Schema_Template::get_image_schema( $value['image'], 'URL' ); } } } } if ( isset( $data['recipe-video'] ) && ! empty( $data['recipe-video'] ) ) { foreach ( $data['recipe-video'] as $key => $value ) { if ( isset( $value['video-name'] ) && ! empty( $value['video-name'] ) ) { $schema['video'][ $key ]['@type'] = 'VideoObject'; $schema['video'][ $key ]['name'] = wp_strip_all_tags( (string) $value['video-name'] ); $schema['video'][ $key ]['description'] = ! empty( $value['video-desc'] ) ? wp_strip_all_tags( (string) $value['video-desc'] ) : null; if ( isset( $value['video-image'] ) && ! empty( $value['video-image'] ) ) { $schema['video'][ $key ]['thumbnailUrl'] = BSF_AIOSRS_Pro_Schema_Template::get_image_schema( $value['video-image'], 'URL' ); } if ( isset( $value['recipe-video-content-url'] ) && ! empty( $value['recipe-video-content-url'] ) ) { $schema['video'][ $key ]['contentUrl'] = esc_url( $value['recipe-video-content-url'] ); } if ( isset( $value['recipe-video-embed-url'] ) && ! empty( $value['recipe-video-embed-url'] ) ) { $schema['video'][ $key ]['embedUrl'] = esc_url( $value['recipe-video-embed-url'] ); } $schema['video'][ $key ]['duration'] = ! empty( $value['recipe-video-duration'] ) ? wp_strip_all_tags( (string) $value['recipe-video-duration'] ) : null; // Convert uploadDate to DateTime object and set the timezone. $upload_date = new DateTime( $value['recipe-video-upload-date'] ); $upload_date->setTimezone( new DateTimeZone( $timezone_string ?: 'UTC' ) ); $schema['video'][ $key ]['uploadDate'] = $upload_date->format( 'c' ); // Use DateTime to handle timezone for 'expires' if ( isset( $value['recipe-video-expires-date'] ) && ! empty( $value['recipe-video-expires-date'] ) && is_string( $value['recipe-video-expires-date'] ) ) { $expires_date = new DateTime( $value['recipe-video-expires-date'] ); $expires_date->setTimezone( new DateTimeZone( $timezone_string ?: 'UTC' ) ); $schema['video'][ $key ]['expires'] = $expires_date->format( 'c' ); } $schema['video'][ $key ]['interactionCount'] = ! empty( $value['recipe-video-interaction-count'] ) ? wp_strip_all_tags( (string) $value['recipe-video-interaction-count'] ) : null; } } } return apply_filters( 'wp_schema_pro_schema_recipe', $schema, $data, $post ); } } }