• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / d5c0395617268a4e44627c6847bf3faa0a6cc695

15 Apr 2025 07:12AM UTC coverage: 52.454% (-2.1%) from 54.595%
d5c0395617268a4e44627c6847bf3faa0a6cc695

push

github

web-flow
Merge pull request #22077 from Yoast/feature/drop-php-7.2-7.3

Drop compatibility with PHP 7.2 and 7.3

7826 of 13877 branches covered (56.4%)

Branch coverage included in aggregate %.

29028 of 56382 relevant lines covered (51.48%)

42273.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/integrations/front-end/schema-accessibility-feature.php
1
<?php
2

3
namespace Yoast\WP\SEO\Integrations\Front_End;
4

5
use Yoast\WP\SEO\Conditionals\Front_End_Conditional;
6
use Yoast\WP\SEO\Context\Meta_Tags_Context;
7
use Yoast\WP\SEO\Generators\Schema\Abstract_Schema_Piece;
8
use Yoast\WP\SEO\Generators\Schema\Article;
9
use Yoast\WP\SEO\Integrations\Integration_Interface;
10

11
/**
12
 * Adds the table of contents accessibility feature to the article piece with a fallback to the webpage piece.
13
 */
14
class Schema_Accessibility_Feature implements Integration_Interface {
15

16
        /**
17
         * Returns the conditionals based in which this loadable should be active.
18
         *
19
         * @return array
20
         */
21
        public static function get_conditionals() {
×
22
                return [ Front_End_Conditional::class ];
×
23
        }
24

25
        /**
26
         * Initializes the integration.
27
         *
28
         * This is the place to register hooks and filters.
29
         *
30
         * @return void
31
         */
32
        public function register_hooks() {
×
33
                \add_filter( 'wpseo_schema_webpage', [ $this, 'maybe_add_accessibility_feature' ], 10, 4 );
×
34
                \add_filter( 'wpseo_schema_article', [ $this, 'add_accessibility_feature' ], 10, 2 );
×
35
        }
36

37
        /**
38
         * Adds the accessibility feature to the webpage if there is no article.
39
         *
40
         * @param array                   $piece         The graph piece.
41
         * @param Meta_Tags_Context       $context       The context.
42
         * @param Abstract_Schema_Piece   $the_generator The current schema generator.
43
         * @param Abstract_Schema_Piece[] $generators    The schema generators.
44
         *
45
         * @return array The graph piece.
46
         */
47
        public function maybe_add_accessibility_feature( $piece, $context, $the_generator, $generators ) {
×
48
                foreach ( $generators as $generator ) {
×
49
                        if ( \is_a( $generator, Article::class ) && $generator->is_needed() ) {
×
50
                                return $piece;
×
51
                        }
52
                }
53

54
                return $this->add_accessibility_feature( $piece, $context );
×
55
        }
56

57
        /**
58
         * Adds the accessibility feature to a schema graph piece.
59
         *
60
         * @param array             $piece   The schema piece.
61
         * @param Meta_Tags_Context $context The context.
62
         *
63
         * @return array The graph piece.
64
         */
65
        public function add_accessibility_feature( $piece, $context ) {
×
66
                if ( empty( $context->blocks['yoast-seo/table-of-contents'] ) ) {
×
67
                        return $piece;
×
68
                }
69

70
                if ( isset( $piece['accessibilityFeature'] ) ) {
×
71
                        $piece['accessibilityFeature'][] = 'tableOfContents';
×
72
                }
73
                else {
74
                        $piece['accessibilityFeature'] = [
×
75
                                'tableOfContents',
×
76
                        ];
×
77
                }
78
                return $piece;
×
79
        }
80
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc