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

Yoast / wordpress-seo / 9ba411c8f4cd28cabbea84da6395c4aaf8f8dfe8

26 Feb 2025 03:35PM UTC coverage: 48.259% (-2.5%) from 50.712%
9ba411c8f4cd28cabbea84da6395c4aaf8f8dfe8

Pull #22077

github

web-flow
Merge 885d4d03b into 6b3a2490c
Pull Request #22077: Drop compatibility with PHP 7.2 and 7.3

16636 of 34472 relevant lines covered (48.26%)

5.17 hits per line

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

0.0
/src/integrations/admin/unsupported-php-version-notice.php
1
<?php
2

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

5
use WPSEO_Shortlinker;
6
use Yoast\WHIPv2\Exceptions\InvalidType;
7
use Yoast\WHIPv2\Exceptions\InvalidVersionComparisonString;
8
use Yoast\WHIPv2\Interfaces\Message;
9
use Yoast\WHIPv2\MessageDismisser;
10
use Yoast\WHIPv2\MessageFormatter;
11
use Yoast\WHIPv2\Presenters\WPMessagePresenter;
12
use Yoast\WHIPv2\RequirementsChecker;
13
use Yoast\WHIPv2\VersionRequirement;
14
use Yoast\WHIPv2\WPDismissOption;
15
use Yoast\WP\SEO\Conditionals\Yoast_Admin_And_Dashboard_Conditional;
16
use Yoast\WP\SEO\Integrations\Integration_Interface;
17

18
/**
19
 * Class Unsupported_PHP_Version_Notice.
20
 *
21
 * @package Yoast\WP\SEO\Integrations\Admin
22
 */
23
class Unsupported_PHP_Version_Notice implements Integration_Interface, Message {
24

25
        /**
26
         * Returns the conditionals based on which this integration should be active.
27
         *
28
         * @return array<string> The array of conditionals.
29
         */
30
        public static function get_conditionals() {
×
31
                return [
32
                        Yoast_Admin_And_Dashboard_Conditional::class,
×
33
                ];
34
        }
35

36
        /**
37
         * Register hooks.
38
         *
39
         * @return void
40
         */
41
        public function register_hooks() {
×
42
                \add_action( 'admin_init', [ $this, 'check_php_version' ] );
×
43
        }
×
44

45
        /**
46
         * Checks the current PHP version.
47
         *
48
         * @return void
49
         */
50
        public function check_php_version() {
×
51
                // If the user isn't an admin, don't display anything.
52
                if ( ! $this->has_right_capabilities() ) {
×
53
                        return;
×
54
                }
55

56
                if ( ! $this->on_dashboard_page( $GLOBALS['pagenow'] ) ) {
×
57
                        return;
×
58
                }
59

60
                // Checks if the user is running at least PHP 7.2.
61
                if ( $this->is_supported_php_version_installed() === false ) {
×
62
                        $this->show_unsupported_php_message();
×
63
                }
64
        }
×
65

66
        /**
67
         * Composes the body of the message to display.
68
         *
69
         * @return string The message to display.
70
         */
71
        public function body() {
×
72
                $message   = [];
×
73
                $message[] = MessageFormatter::strongParagraph( \__( 'Upgrade your PHP version', 'wordpress-seo' ) ) . '<br />';
×
74
                $message[] = MessageFormatter::paragraph(
×
75
                        \sprintf(
×
76
                                /* translators: 1: Yoast SEO, 2: Yoast SEO Premium */
77
                                \__(
×
78
                                        'By November 1st, 2024, we’ll update the minimum PHP requirement for %1$s, %2$s and all our add-ons to PHP 7.4. This, to ensure we can keep delivering state of the art features.',
×
79
                                        'wordpress-seo'
×
80
                                ),
81
                                'Yoast SEO',
×
82
                                'Yoast SEO Premium'
×
83
                        )
84
                ) . '<br />';
×
85
                $message[] = MessageFormatter::strongParagraph( \__( 'Can’t upgrade yourself? Ask your host!', 'wordpress-seo' ) ) . '<br />';
×
86
                $message[] = MessageFormatter::paragraph(
×
87
                        \sprintf(
×
88
                        /* translators: 1: Link tag to WordPress Hosts page on Yoast.com; 2: Link closing tag */
89
                                \__(
×
90
                                        'Upgrading your PHP version is something your hosting provider can help you out with. If they can’t upgrade your PHP version, we advise you to consider %1$sswitching to a hosting provider%2$s that can provide the security and features a modern host should provide.',
×
91
                                        'wordpress-seo'
×
92
                                ),
93
                                '<a href="' . WPSEO_Shortlinker::get( 'https://yoast.com/wordpress-hosting/' ) . '">',
×
94
                                '</a>'
×
95
                        )
96
                ) . '<br />';
×
97

98
                return \implode( \PHP_EOL, $message );
×
99
        }
100

101
        /**
102
         * Checks if the current user has the right capabilities.
103
         *
104
         * @return bool True when user has right capabilities.
105
         */
106
        protected function has_right_capabilities() {
×
107
                return \current_user_can( 'wpseo_manage_options' );
×
108
        }
109

110
        /**
111
         * Whether we are on the admin dashboard page or in the Yoast dashboard page.
112
         *
113
         * We need to have the notice in the main admin otherwise the dismissal mechanism won't work.
114
         *
115
         * @param string $current_page The current page.
116
         *
117
         * @return bool True if current page is the index.php.
118
         */
119
        protected function on_dashboard_page( $current_page ) {
×
120
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Date is not processed or saved.
121
                if ( $current_page === 'admin.php' && isset( $_GET['page'] ) && \sanitize_text_field( \wp_unslash( $_GET['page'] ) ) === 'wpseo_dashboard' ) {
×
122
                        return true;
×
123
                }
124

125
                return ( $current_page === 'index.php' );
×
126
        }
127

128
        /**
129
         * Checks if the installed php version is supported.
130
         *
131
         * @codeCoverageIgnore
132
         *
133
         * @return bool True when the php version is support.
134
         */
135
        protected function is_supported_php_version_installed() {
136
                try {
137
                        $checker = new RequirementsChecker( [ 'php' => \PHP_VERSION ] );
138

139
                        $checker->addRequirement( VersionRequirement::fromCompareString( 'php', '>=7.4' ) );
140
                        $checker->check();
141

142
                        return $checker->hasMessages() === false;
143
                }
144
                catch ( InvalidVersionComparisonString $e ) {
145
                        return true;
146
                }
147
                catch ( InvalidType $e ) {
148
                        return true;
149
                }
150
        }
151

152
        /**
153
         * Creates a new message to display regarding the usage of PHP 7.3 (or lower).
154
         *
155
         * @codeCoverageIgnore
156
         *
157
         * @return void
158
         */
159
        protected function show_unsupported_php_message() {
160
                $presenter = new WPMessagePresenter(
161
                        $this,
162
                        new MessageDismisser( \time(), ( \WEEK_IN_SECONDS * 4 ), new WPDismissOption() ),
163
                        \__( 'Remind me again in 4 weeks.', 'wordpress-seo' )
164
                );
165
                $presenter->registerHooks();
166
        }
167
}
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