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

Yoast / wordpress-seo / 56db0408fe2a0dbffe1c2c6cfad9b5c2f6941e34

14 Apr 2025 12:24PM UTC coverage: 52.454% (-2.1%) from 54.594%
56db0408fe2a0dbffe1c2c6cfad9b5c2f6941e34

Pull #22077

github

enricobattocchi
Adjust carryforward in Coveralls action
Pull Request #22077: Drop compatibility with PHP 7.2 and 7.3

7827 of 13877 branches covered (56.4%)

Branch coverage included in aggregate %.

29025 of 56379 relevant lines covered (51.48%)

42277.18 hits per line

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

0.0
/src/integrations/admin/addon-installation/installation-integration.php
1
<?php
2

3
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Discussed in Tech Council, a better solution is being worked on.
4

5
namespace Yoast\WP\SEO\Integrations\Admin\Addon_Installation;
6

7
use WPSEO_Addon_Manager;
8
use Yoast\WP\SEO\Actions\Addon_Installation\Addon_Activate_Action;
9
use Yoast\WP\SEO\Actions\Addon_Installation\Addon_Install_Action;
10
use Yoast\WP\SEO\Conditionals\Addon_Installation_Conditional;
11
use Yoast\WP\SEO\Conditionals\Admin\Licenses_Page_Conditional;
12
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
13
use Yoast\WP\SEO\Exceptions\Addon_Installation\Addon_Activation_Error_Exception;
14
use Yoast\WP\SEO\Exceptions\Addon_Installation\Addon_Already_Installed_Exception;
15
use Yoast\WP\SEO\Exceptions\Addon_Installation\Addon_Installation_Error_Exception;
16
use Yoast\WP\SEO\Exceptions\Addon_Installation\User_Cannot_Activate_Plugins_Exception;
17
use Yoast\WP\SEO\Exceptions\Addon_Installation\User_Cannot_Install_Plugins_Exception;
18
use Yoast\WP\SEO\Integrations\Integration_Interface;
19

20
/**
21
 * Represents the Addon installation feature.
22
 */
23
class Installation_Integration implements Integration_Interface {
24

25
        /**
26
         * The installation action.
27
         *
28
         * @var Addon_Install_Action
29
         */
30
        protected $addon_install_action;
31

32
        /**
33
         * The activation action.
34
         *
35
         * @var Addon_Activate_Action
36
         */
37
        protected $addon_activate_action;
38

39
        /**
40
         * The addon manager.
41
         *
42
         * @var WPSEO_Addon_Manager
43
         */
44
        protected $addon_manager;
45

46
        /**
47
         * {@inheritDoc}
48
         */
49
        public static function get_conditionals() {
×
50
                return [
×
51
                        Admin_Conditional::class,
×
52
                        Licenses_Page_Conditional::class,
×
53
                        Addon_Installation_Conditional::class,
×
54
                ];
×
55
        }
56

57
        /**
58
         * Addon_Installation constructor.
59
         *
60
         * @param WPSEO_Addon_Manager   $addon_manager         The addon manager.
61
         * @param Addon_Activate_Action $addon_activate_action The addon activate action.
62
         * @param Addon_Install_Action  $addon_install_action  The addon install action.
63
         */
64
        public function __construct(
×
65
                WPSEO_Addon_Manager $addon_manager,
66
                Addon_Activate_Action $addon_activate_action,
67
                Addon_Install_Action $addon_install_action
68
        ) {
69
                $this->addon_manager         = $addon_manager;
×
70
                $this->addon_activate_action = $addon_activate_action;
×
71
                $this->addon_install_action  = $addon_install_action;
×
72
        }
73

74
        /**
75
         * Registers all hooks to WordPress.
76
         *
77
         * @return void
78
         */
79
        public function register_hooks() {
×
80
                \add_action( 'wpseo_install_and_activate_addons', [ $this, 'install_and_activate_addons' ] );
×
81
        }
82

83
        /**
84
         * Installs and activates missing addons.
85
         *
86
         * @return void
87
         */
88
        public function install_and_activate_addons() {
×
89
                if ( ! isset( $_GET['action'] ) || ! \is_string( $_GET['action'] ) ) {
×
90
                        return;
×
91
                }
92

93
                // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Reason: We are only strictly comparing action below.
94
                $action = \wp_unslash( $_GET['action'] );
×
95
                if ( $action !== 'install' ) {
×
96
                        return;
×
97
                }
98

99
                \check_admin_referer( 'wpseo_addon_installation', 'nonce' );
×
100

101
                echo '<div class="wrap yoast wpseo_table_page">';
×
102

103
                \printf(
×
104
                        '<h1 id="wpseo-title" class="yoast-h1">%s</h1>',
×
105
                        \esc_html__( 'Installing and activating addons', 'wordpress-seo' )
×
106
                );
×
107

108
                $licensed_addons = $this->addon_manager->get_myyoast_site_information()->subscriptions;
×
109

110
                foreach ( $licensed_addons as $addon ) {
×
111
                        \printf( '<p><strong>%s</strong></p>', \esc_html( $addon->product->name ) );
×
112

113
                        list( $installed, $output ) = $this->install_addon( $addon->product->slug, $addon->product->download );
×
114

115
                        if ( $installed ) {
×
116
                                $activation_output = $this->activate_addon( $addon->product->slug );
×
117

118
                                $output = \array_merge( $output, $activation_output );
×
119
                        }
120

121
                        echo '<p>';
×
122
                        echo \implode( '<br />', \array_map( 'esc_html', $output ) );
×
123
                        echo '</p>';
×
124
                }
125

126
                \printf(
×
127
                        /* translators: %1$s expands to an anchor tag to the admin premium page, %2$s expands to Yoast SEO Premium, %3$s expands to a closing anchor tag */
128
                        \esc_html__( '%1$s Continue to %2$s%3$s', 'wordpress-seo' ),
×
129
                        '<a href="' . \esc_url( \admin_url( 'admin.php?page=wpseo_licenses' ) ) . '">',
×
130
                        'Yoast SEO Premium',
×
131
                        '</a>'
×
132
                );
×
133

134
                echo '</div>';
×
135

136
                exit;
×
137
        }
138

139
        /**
140
         * Activates an addon.
141
         *
142
         * @param string $addon_slug The addon to activate.
143
         *
144
         * @return array The output of the activation.
145
         */
146
        public function activate_addon( $addon_slug ) {
×
147
                $output = [];
×
148

149
                try {
150
                        $this->addon_activate_action->activate_addon( $addon_slug );
×
151

152
                        /* Translators: %s expands to the name of the addon. */
153
                        $output[] = \__( 'Addon activated.', 'wordpress-seo' );
×
154
                } catch ( User_Cannot_Activate_Plugins_Exception $exception ) {
×
155
                        $output[] = \__( 'You are not allowed to activate plugins.', 'wordpress-seo' );
×
156
                } catch ( Addon_Activation_Error_Exception $exception ) {
×
157
                        $output[] = \sprintf(
×
158
                                /* Translators:%s expands to the error message. */
159
                                \__( 'Addon activation failed because of an error: %s.', 'wordpress-seo' ),
×
160
                                $exception->getMessage()
×
161
                        );
×
162
                }
163

164
                return $output;
×
165
        }
166

167
        /**
168
         * Installs an addon.
169
         *
170
         * @param string $addon_slug     The slug of the addon to install.
171
         * @param string $addon_download The download URL of the addon.
172
         *
173
         * @return array The installation success state and the output of the installation.
174
         */
175
        public function install_addon( $addon_slug, $addon_download ) {
×
176
                $installed = false;
×
177
                $output    = [];
×
178

179
                try {
180
                        $installed = $this->addon_install_action->install_addon( $addon_slug, $addon_download );
×
181
                } catch ( Addon_Already_Installed_Exception $exception ) {
×
182
                        /* Translators: %s expands to the name of the addon. */
183
                        $output[] = \__( 'Addon installed.', 'wordpress-seo' );
×
184

185
                        $installed = true;
×
186
                } catch ( User_Cannot_Install_Plugins_Exception $exception ) {
×
187
                        $output[] = \__( 'You are not allowed to install plugins.', 'wordpress-seo' );
×
188
                } catch ( Addon_Installation_Error_Exception $exception ) {
×
189
                        $output[] = \sprintf(
×
190
                                /* Translators: %s expands to the error message. */
191
                                \__( 'Addon installation failed because of an error: %s.', 'wordpress-seo' ),
×
192
                                $exception->getMessage()
×
193
                        );
×
194
                }
195

196
                return [ $installed, $output ];
×
197
        }
198
}
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