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

Yoast / wordpress-seo / 6987097851

25 Nov 2023 04:49AM UTC coverage: 49.206% (-0.1%) from 49.302%
6987097851

push

github

web-flow
Merge pull request #20878 from Yoast/JRF/ghactions-minor-tweak

GH Actions: update a few links in inline comments

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

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
        public function register_hooks() {
×
78
                \add_action( 'wpseo_install_and_activate_addons', [ $this, 'install_and_activate_addons' ] );
×
79
        }
80

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

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

97
                \check_admin_referer( 'wpseo_addon_installation', 'nonce' );
×
98

99
                echo '<div class="wrap yoast wpseo_table_page">';
×
100

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

106
                $licensed_addons = $this->addon_manager->get_myyoast_site_information()->subscriptions;
×
107

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

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

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

116
                                $output = \array_merge( $output, $activation_output );
×
117
                        }
118

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

124
                \printf(
×
125
                        /* 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 */
126
                        \esc_html__( '%1$s Continue to %2$s%3$s', 'wordpress-seo' ),
×
127
                        '<a href="' . \esc_url( \admin_url( 'admin.php?page=wpseo_licenses' ) ) . '">',
×
128
                        'Yoast SEO Premium',
×
129
                        '</a>'
×
130
                );
131

132
                echo '</div>';
×
133

134
                exit;
×
135
        }
136

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

147
                try {
148
                        $this->addon_activate_action->activate_addon( $addon_slug );
×
149

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

162
                return $output;
×
163
        }
164

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

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

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

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

© 2025 Coveralls, Inc