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

Yoast / wordpress-seo / abba4d5bc97ae5733ba89412cc79bb357e5d7f21

22 Oct 2024 07:57AM UTC coverage: 54.556% (+0.06%) from 54.494%
abba4d5bc97ae5733ba89412cc79bb357e5d7f21

push

github

YoastBot
Bump version to 23.7 on free

7539 of 13559 branches covered (55.6%)

Branch coverage included in aggregate %.

29669 of 54642 relevant lines covered (54.3%)

41714.3 hits per line

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

67.8
/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\Conditionals\New_Dashboard_Ui_Conditional;
8
use Yoast\WP\SEO\Helpers\Options_Helper;
9
use Yoast\WP\SEO\Helpers\Product_Helper;
10
use Yoast\WP\SEO\Integrations\Integration_Interface;
11

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

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

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

31
        /**
32
         * The New Dashboard UI conditional.
33
         *
34
         * @var New_Dashboard_Ui_Conditional
35
         */
36
        private $new_dashboard_ui_conditional;
37

38
        /**
39
         * {@inheritDoc}
40
         */
41
        public static function get_conditionals() {
2✔
42
                return [ Admin_Conditional::class ];
2✔
43
        }
44

45
        /**
46
         * Installation_Success_Integration constructor.
47
         *
48
         * @param Options_Helper               $options_helper               The options helper.
49
         * @param Product_Helper               $product_helper               The product helper.
50
         * @param New_Dashboard_Ui_Conditional $new_dashboard_ui_conditional The new dashboard UI conditional.
51
         */
52
        public function __construct(
2✔
53
                Options_Helper $options_helper,
54
                Product_Helper $product_helper,
55
                New_Dashboard_Ui_Conditional $new_dashboard_ui_conditional
56
        ) {
1✔
57
                $this->options_helper               = $options_helper;
2✔
58
                $this->product_helper               = $product_helper;
2✔
59
                $this->new_dashboard_ui_conditional = $new_dashboard_ui_conditional;
2✔
60
        }
1✔
61

62
        /**
63
         * {@inheritDoc}
64
         */
65
        public function register_hooks() {
2✔
66
                \add_filter( 'admin_menu', [ $this, 'add_submenu_page' ], 9 );
2✔
67
                \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
2✔
68
                \add_action( 'admin_init', [ $this, 'maybe_redirect' ] );
2✔
69
        }
1✔
70

71
        /**
72
         * Redirects to the installation success page if an installation has just occurred.
73
         *
74
         * @return void
75
         */
76
        public function maybe_redirect() {
14✔
77
                if ( \defined( 'DOING_AJAX' ) && \DOING_AJAX ) {
14✔
78
                        return;
×
79
                }
80

81
                if ( ! $this->options_helper->get( 'should_redirect_after_install_free', false ) ) {
14✔
82
                        return;
2✔
83
                }
84
                $this->options_helper->set( 'should_redirect_after_install_free', false );
12✔
85

86
                if ( ! empty( $this->options_helper->get( 'activation_redirect_timestamp_free', 0 ) ) ) {
12✔
87
                        return;
2✔
88
                }
89
                $this->options_helper->set( 'activation_redirect_timestamp_free', \time() );
10✔
90

91
                // phpcs:ignore WordPress.Security.NonceVerification -- This is not a form.
92
                if ( isset( $_REQUEST['activate-multi'] ) && $_REQUEST['activate-multi'] === 'true' ) {
10✔
93
                        return;
2✔
94
                }
95

96
                if ( $this->product_helper->is_premium() ) {
8✔
97
                        return;
2✔
98
                }
99

100
                if ( \is_network_admin() || \is_plugin_active_for_network( \WPSEO_BASENAME ) ) {
6✔
101
                        return;
4✔
102
                }
103

104
                \wp_safe_redirect( \admin_url( 'admin.php?page=wpseo_installation_successful_free' ), 302, 'Yoast SEO' );
2✔
105
                $this->terminate_execution();
2✔
106
        }
1✔
107

108
        /**
109
         * Adds the installation success submenu page.
110
         *
111
         * @param array $submenu_pages The Yoast SEO submenu pages.
112
         *
113
         * @return array the filtered submenu pages.
114
         */
115
        public function add_submenu_page( $submenu_pages ) {
2✔
116
                \add_submenu_page(
2✔
117
                        '',
2✔
118
                        \__( 'Installation Successful', 'wordpress-seo' ),
2✔
119
                        '',
2✔
120
                        'manage_options',
2✔
121
                        'wpseo_installation_successful_free',
2✔
122
                        [ $this, 'render_page' ]
2✔
123
                );
1✔
124

125
                return $submenu_pages;
2✔
126
        }
127

128
        /**
129
         * Enqueue assets on the Installation success page.
130
         *
131
         * @return void
132
         */
133
        public function enqueue_assets() {
×
134
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Date is not processed or saved.
135
                if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'wpseo_installation_successful_free' ) {
×
136
                        return;
×
137
                }
138

139
                $asset_manager = new WPSEO_Admin_Asset_Manager();
×
140
                $asset_manager->enqueue_script( 'installation-success' );
×
141
                $asset_manager->enqueue_style( 'tailwind' );
×
142
                $asset_manager->enqueue_style( 'monorepo' );
×
143

144
                $ftc_url = ( $this->new_dashboard_ui_conditional->is_met() ) ? \esc_url( \admin_url( 'admin.php?page=wpseo_dashboard#/first-time-configuration' ) ) : \esc_url( \admin_url( 'admin.php?page=wpseo_dashboard#top#first-time-configuration' ) );
×
145

146
                $asset_manager->localize_script(
×
147
                        'installation-success',
×
148
                        'wpseoInstallationSuccess',
×
149
                        [
150
                                'pluginUrl'                 => \esc_url( \plugins_url( '', \WPSEO_FILE ) ),
×
151
                                'firstTimeConfigurationUrl' => $ftc_url,
×
152
                                'dashboardUrl'              => \esc_url( \admin_url( 'admin.php?page=wpseo_dashboard' ) ),
×
153
                        ]
154
                );
155
        }
156

157
        /**
158
         * Renders the installation success page.
159
         *
160
         * @return void
161
         */
162
        public function render_page() {
×
163
                echo '<div id="wpseo-installation-successful-free" class="yoast"></div>';
×
164
        }
165

166
        /**
167
         * Wrap the `exit` function to make unit testing easier.
168
         *
169
         * @return void
170
         */
171
        public function terminate_execution() {
×
172
                exit;
×
173
        }
174
}
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