Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
80.00% covered (warning)
80.00%
8 / 10
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Jetpack_Sitemap_Buffer_Master_XMLWriter
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
3 / 3
5
100.00% covered (success)
100.00%
1 / 1
 initialize_buffer
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 start_root
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 append_item
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2/**
3 * XMLWriter implementation of the master sitemap buffer.
4 *
5 * @since 14.6
6 * @package automattic/jetpack
7 */
8
9if ( ! defined( 'ABSPATH' ) ) {
10    exit( 0 );
11}
12
13/**
14 * A buffer for constructing master sitemap xml files using XMLWriter.
15 *
16 * @since 14.6
17 */
18class Jetpack_Sitemap_Buffer_Master_XMLWriter extends Jetpack_Sitemap_Buffer_XMLWriter {
19
20    /**
21     * Initialize the buffer with required headers (no root element here).
22     */
23    protected function initialize_buffer() {
24        // Add generator comment
25        $this->writer->writeComment( "generator='jetpack-" . JETPACK__VERSION . "'" );
26        $this->writer->writeComment( 'Jetpack_Sitemap_Buffer_Master_XMLWriter' );
27
28        // Add stylesheet
29        foreach ( Jetpack_Sitemap_Stylist::sitemap_stylesheet_urls() as $url ) {
30            $this->writer->writePi( 'xml-stylesheet', 'type="text/css" href="' . esc_xml( $url ) . '"' );
31        }
32    }
33
34    /**
35     * Start the root element and write its namespaces.
36     */
37    protected function start_root() {
38        $this->writer->startElement( 'sitemapindex' );
39        $this->writer->writeAttribute( 'xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9' );
40    }
41
42    /**
43     * Append a sitemap entry to the master sitemap.
44     *
45     * @param array $array The sitemap item to append.
46     */
47    protected function append_item( $array ) {
48        if ( ! empty( $array['sitemap'] ) ) {
49            $this->array_to_xml( $array );
50        }
51    }
52}