PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
← All changes | modules/sitemaps/sitemap-buffer-image-xmlwriter.php +85 -0 16.2-beta → 16.3 View file →
@@ -1,0 +1,85 @@
1 +<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 +/**
3 + * XMLWriter implementation of the image sitemap buffer.
4 + *
5 + * @since 14.6
6 + * @package automattic/jetpack
7 + */
8 +
9 +if ( ! defined( 'ABSPATH' ) ) {
10 + exit( 0 );
11 +}
12 +
13 +/**
14 + * A buffer for constructing sitemap image xml files using XMLWriter.
15 + *
16 + * @since 14.6
17 + */
18 +class Jetpack_Sitemap_Buffer_Image_XMLWriter extends Jetpack_Sitemap_Buffer_XMLWriter {
19 + /**
20 + * Initialize the buffer with required headers (no root element here).
21 + */
22 + protected function initialize_buffer() {
23 + // Add generator comment
24 + $this->writer->writeComment( "generator='jetpack-" . JETPACK__VERSION . "'" );
25 + $this->writer->writeComment( 'Jetpack_Sitemap_Buffer_Image_XMLWriter' );
26 +
27 + // Add stylesheet
28 + $this->writer->writePi(
29 + 'xml-stylesheet',
30 + 'type="text/xsl" href="' . $this->finder->construct_sitemap_url( 'image-sitemap.xsl' ) . '"'
31 + );
32 + }
33 +
34 + /**
35 + * Start the root element and write its namespaces.
36 + */
37 + protected function start_root() {
38 + $this->writer->startElement( 'urlset' );
39 +
40 + /**
41 + * Filter the XML namespaces included in image sitemaps.
42 + *
43 + * @module sitemaps
44 + *
45 + * @since 4.8.0
46 + *
47 + * @param array $namespaces Associative array with namespaces and namespace URIs.
48 + */
49 + $namespaces = apply_filters(
50 + 'jetpack_sitemap_image_ns',
51 + array(
52 + 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
53 + 'xsi:schemaLocation' => 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd',
54 + 'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9',
55 + 'xmlns:image' => 'http://www.google.com/schemas/sitemap-image/1.1',
56 + )
57 + );
58 +
59 + foreach ( $namespaces as $name => $value ) {
60 + $this->writer->writeAttribute( $name, $value );
61 + }
62 + }
63 +
64 + /**
65 + * Append a URL entry with image information to the sitemap.
66 + *
67 + * @param array $array The URL item to append.
68 + */
69 + protected function append_item( $array ) {
70 + if ( ! isset( $array['url'] ) || ! is_array( $array['url'] ) ) {
71 + return;
72 + }
73 +
74 + if ( isset( $array['url']['image:image'] ) ) {
75 + if ( empty( $array['url']['image:image']['image:title'] ) ) {
76 + unset( $array['url']['image:image']['image:title'] );
77 + }
78 + if ( empty( $array['url']['image:image']['image:caption'] ) ) {
79 + unset( $array['url']['image:image']['image:caption'] );
80 + }
81 + }
82 +
83 + $this->array_to_xml( $array );
84 + }
85 +}