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

Yoast / wordpress-seo / 5066322038

pending completion
5066322038

push

github

GitHub
Merge pull request #20316 from Yoast/JRF/ghactions-run-more-selectively

2550 of 29012 relevant lines covered (8.79%)

0.32 hits per line

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

0.0
/src/integrations/front-end/crawl-cleanup-basic.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\Helpers\Options_Helper;
7
use Yoast\WP\SEO\Integrations\Integration_Interface;
8

9
/**
10
 * Class Crawl_Cleanup_Basic.
11
 */
12
class Crawl_Cleanup_Basic implements Integration_Interface {
13

14
        /**
15
         * The options helper.
16
         *
17
         * @var Options_Helper
18
         */
19
        private $options_helper;
20

21
        /**
22
         * Crawl Cleanup Basic integration constructor.
23
         *
24
         * @param Options_Helper $options_helper The option helper.
25
         */
26
        public function __construct( Options_Helper $options_helper ) {
27
                $this->options_helper = $options_helper;
×
28
        }
29

30
        /**
31
         * Initializes the integration.
32
         *
33
         * This is the place to register hooks and filters.
34
         *
35
         * @return void
36
         */
37
        public function register_hooks() {
38
                // Remove HTTP headers we don't want.
39
                \add_action( 'wp', [ $this, 'clean_headers' ], 0 );
×
40

41
                if ( $this->is_true( 'remove_shortlinks' ) ) {
×
42
                        // Remove shortlinks.
43
                        \remove_action( 'wp_head', 'wp_shortlink_wp_head' );
×
44
                        \remove_action( 'template_redirect', 'wp_shortlink_header', 11 );
×
45
                }
46

47
                if ( $this->is_true( 'remove_rest_api_links' ) ) {
×
48
                        // Remove REST API links.
49
                        \remove_action( 'wp_head', 'rest_output_link_wp_head' );
×
50
                        \remove_action( 'template_redirect', 'rest_output_link_header', 11 );
×
51
                }
52

53
                if ( $this->is_true( 'remove_rsd_wlw_links' ) ) {
×
54
                        // Remove RSD and WLW Manifest links.
55
                        \remove_action( 'wp_head', 'rsd_link' );
×
56
                        \remove_action( 'xmlrpc_rsd_apis', 'rest_output_rsd' );
×
57
                        \remove_action( 'wp_head', 'wlwmanifest_link' );
×
58
                }
59

60
                if ( $this->is_true( 'remove_oembed_links' ) ) {
×
61
                        // Remove JSON+XML oEmbed links.
62
                        \remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
×
63
                }
64

65
                if ( $this->is_true( 'remove_generator' ) ) {
×
66
                        \remove_action( 'wp_head', 'wp_generator' );
×
67
                }
68

69
                if ( $this->is_true( 'remove_emoji_scripts' ) ) {
×
70
                        // Remove emoji scripts and additional stuff they cause.
71
                        \remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
×
72
                        \remove_action( 'wp_print_styles', 'print_emoji_styles' );
×
73
                        \remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
×
74
                        \remove_action( 'admin_print_styles', 'print_emoji_styles' );
×
75
                        \add_filter( 'wp_resource_hints', [ $this, 'resource_hints_plain_cleanup' ], 1 );
×
76
                }
77
        }
78

79
        /**
80
         * Returns the conditionals based in which this loadable should be active.
81
         *
82
         * @return array The array of conditionals.
83
         */
84
        public static function get_conditionals() {
85
                return [ Front_End_Conditional::class ];
×
86
        }
87

88
        /**
89
         * Removes X-Pingback and X-Powered-By headers as they're unneeded.
90
         */
91
        public function clean_headers() {
92
                if ( \headers_sent() ) {
×
93
                        return;
×
94
                }
95

96
                if ( $this->is_true( 'remove_powered_by_header' ) ) {
×
97
                        \header_remove( 'X-Powered-By' );
×
98
                }
99
                if ( $this->is_true( 'remove_pingback_header' ) ) {
×
100
                        \header_remove( 'X-Pingback' );
×
101
                }
102
        }
103

104
        /**
105
         * Remove the core s.w.org hint as it's only used for emoji stuff we don't use.
106
         *
107
         * @param array $hints The hints we're adding to.
108
         *
109
         * @return array
110
         */
111
        public function resource_hints_plain_cleanup( $hints ) {
112
                foreach ( $hints as $key => $hint ) {
×
113
                        if ( \strpos( $hint, '//s.w.org' ) !== false ) {
×
114
                                unset( $hints[ $key ] );
×
115
                        }
116
                }
117

118
                return $hints;
×
119
        }
120

121
        /**
122
         * Checks if the value of an option is set to true.
123
         *
124
         * @param string $option_name The option name.
125
         *
126
         * @return bool
127
         */
128
        private function is_true( $option_name ) {
129
                return $this->options_helper->get( $option_name ) === true;
×
130
        }
131
}
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