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

Yoast / wordpress-seo / 7004843404

27 Nov 2023 11:48AM UTC coverage: 49.206% (-0.03%) from 49.232%
7004843404

push

github

web-flow
Merge pull request #20858 from Yoast/improve-copy-in-the-ftc-57

15305 of 31104 relevant lines covered (49.21%)

4.03 hits per line

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

69.09
/src/integrations/admin/installation-success-integration.php
1
<?php
2

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

5
use WPSEO_Admin_Asset_Manager;
6
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
7
use Yoast\WP\SEO\Helpers\Options_Helper;
8
use Yoast\WP\SEO\Helpers\Product_Helper;
9
use Yoast\WP\SEO\Integrations\Integration_Interface;
10

11
/**
12
 * Installation_Success_Integration class
13
 */
14
class Installation_Success_Integration implements Integration_Interface {
15

16
        /**
17
         * The options helper.
18
         *
19
         * @var Options_Helper
20
         */
21
        protected $options_helper;
22

23
        /**
24
         * The product helper.
25
         *
26
         * @var Product_Helper
27
         */
28
        protected $product_helper;
29

30
        /**
31
         * {@inheritDoc}
32
         */
33
        public static function get_conditionals() {
2✔
34
                return [ Admin_Conditional::class ];
2✔
35
        }
36

37
        /**
38
         * Installation_Success_Integration constructor.
39
         *
40
         * @param Options_Helper $options_helper The options helper.
41
         * @param Product_Helper $product_helper The product helper.
42
         */
43
        public function __construct( Options_Helper $options_helper, Product_Helper $product_helper ) {
2✔
44
                $this->options_helper = $options_helper;
2✔
45
                $this->product_helper = $product_helper;
2✔
46
        }
1✔
47

48
        /**
49
         * {@inheritDoc}
50
         */
51
        public function register_hooks() {
2✔
52
                \add_filter( 'admin_menu', [ $this, 'add_submenu_page' ], 9 );
2✔
53
                \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
2✔
54
                \add_action( 'admin_init', [ $this, 'maybe_redirect' ] );
2✔
55
        }
1✔
56

57
        /**
58
         * Redirects to the installation success page if an installation has just occurred.
59
         *
60
         * @return void
61
         */
62
        public function maybe_redirect() {
14✔
63
                if ( \defined( 'DOING_AJAX' ) && \DOING_AJAX ) {
14✔
64
                        return;
×
65
                }
66

67
                if ( ! $this->options_helper->get( 'should_redirect_after_install_free', false ) ) {
14✔
68
                        return;
2✔
69
                }
70
                $this->options_helper->set( 'should_redirect_after_install_free', false );
12✔
71

72
                if ( ! empty( $this->options_helper->get( 'activation_redirect_timestamp_free', 0 ) ) ) {
12✔
73
                        return;
2✔
74
                }
75
                $this->options_helper->set( 'activation_redirect_timestamp_free', \time() );
10✔
76

77
                // phpcs:ignore WordPress.Security.NonceVerification -- This is not a form.
78
                if ( isset( $_REQUEST['activate-multi'] ) && $_REQUEST['activate-multi'] === 'true' ) {
10✔
79
                        return;
2✔
80
                }
81

82
                if ( $this->product_helper->is_premium() ) {
8✔
83
                        return;
2✔
84
                }
85

86
                if ( \is_network_admin() || \is_plugin_active_for_network( \WPSEO_BASENAME ) ) {
6✔
87
                        return;
4✔
88
                }
89

90
                \wp_safe_redirect( \admin_url( 'admin.php?page=wpseo_installation_successful_free' ), 302, 'Yoast SEO' );
2✔
91
                $this->terminate_execution();
2✔
92
        }
1✔
93

94
        /**
95
         * Adds the installation success submenu page.
96
         *
97
         * @param array $submenu_pages The Yoast SEO submenu pages.
98
         *
99
         * @return array the filtered submenu pages.
100
         */
101
        public function add_submenu_page( $submenu_pages ) {
2✔
102
                \add_submenu_page(
2✔
103
                        '',
2✔
104
                        \__( 'Installation Successful', 'wordpress-seo' ),
2✔
105
                        '',
2✔
106
                        'manage_options',
2✔
107
                        'wpseo_installation_successful_free',
2✔
108
                        [ $this, 'render_page' ]
2✔
109
                );
1✔
110

111
                return $submenu_pages;
2✔
112
        }
113

114
        /**
115
         * Enqueue assets on the Installation success page.
116
         */
117
        public function enqueue_assets() {
×
118
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Date is not processed or saved.
119
                if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'wpseo_installation_successful_free' ) {
×
120
                        return;
×
121
                }
122

123
                $asset_manager = new WPSEO_Admin_Asset_Manager();
×
124
                $asset_manager->enqueue_script( 'installation-success' );
×
125
                $asset_manager->enqueue_style( 'tailwind' );
×
126
                $asset_manager->enqueue_style( 'monorepo' );
×
127

128
                $asset_manager->localize_script(
×
129
                        'installation-success',
×
130
                        'wpseoInstallationSuccess',
×
131
                        [
132
                                'pluginUrl'                 => \esc_url( \plugins_url( '', \WPSEO_FILE ) ),
×
133
                                'firstTimeConfigurationUrl' => \esc_url( \admin_url( 'admin.php?page=wpseo_dashboard#top#first-time-configuration' ) ),
×
134
                        ]
135
                );
136
        }
137

138
        /**
139
         * Renders the installation success page.
140
         */
141
        public function render_page() {
×
142
                echo '<div id="wpseo-installation-successful-free" class="yoast"></div>';
×
143
        }
144

145
        /**
146
         * Wrap the `exit` function to make unit testing easier.
147
         */
148
        public function terminate_execution() {
×
149
                exit;
×
150
        }
151
}
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