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

Yoast / wordpress-seo / 480d45f7558361ddb9f0510021bd9bb60479cd22

14 Apr 2025 12:31PM UTC coverage: 52.454% (-2.1%) from 54.594%
480d45f7558361ddb9f0510021bd9bb60479cd22

Pull #22077

github

enricobattocchi
Update composer.lock
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

41.3
/src/integrations/admin/addon-installation/dialog-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 WPSEO_Admin_Asset_Manager;
9
use Yoast\WP\SEO\Conditionals\Addon_Installation_Conditional;
10
use Yoast\WP\SEO\Conditionals\Admin\Licenses_Page_Conditional;
11
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
12
use Yoast\WP\SEO\Integrations\Integration_Interface;
13

14
/**
15
 * Represents the Addon installation feature.
16
 */
17
class Dialog_Integration implements Integration_Interface {
18

19
        /**
20
         * The addon manager.
21
         *
22
         * @var WPSEO_Addon_Manager
23
         */
24
        protected $addon_manager;
25

26
        /**
27
         * The addons.
28
         *
29
         * @var array
30
         */
31
        protected $owned_addons;
32

33
        /**
34
         * {@inheritDoc}
35
         */
36
        public static function get_conditionals() {
×
37
                return [
×
38
                        Admin_Conditional::class,
×
39
                        Licenses_Page_Conditional::class,
×
40
                        Addon_Installation_Conditional::class,
×
41
                ];
×
42
        }
43

44
        /**
45
         * Addon_Installation constructor.
46
         *
47
         * @param WPSEO_Addon_Manager $addon_manager The addon manager.
48
         */
49
        public function __construct( WPSEO_Addon_Manager $addon_manager ) {
8✔
50
                $this->addon_manager = $addon_manager;
8✔
51
        }
52

53
        /**
54
         * Registers all hooks to WordPress.
55
         *
56
         * @return void
57
         */
58
        public function register_hooks() {
2✔
59
                \add_action( 'admin_init', [ $this, 'start_addon_installation' ] );
2✔
60
        }
61

62
        /**
63
         * Starts the addon installation flow.
64
         *
65
         * @return void
66
         */
67
        public function start_addon_installation() {
6✔
68
                // Only show the dialog when we explicitly want to see it.
69
                // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: This is not a form.
70
                if ( ! isset( $_GET['install'] ) || $_GET['install'] !== 'true' ) {
6✔
71
                        return;
2✔
72
                }
73

74
                $this->bust_myyoast_addon_information_cache();
4✔
75
                $this->owned_addons = $this->get_owned_addons();
4✔
76

77
                if ( \count( $this->owned_addons ) > 0 ) {
4✔
78
                        \add_action( 'admin_enqueue_scripts', [ $this, 'show_modal' ] );
2✔
79
                }
80
                else {
81
                        \add_action( 'admin_notices', [ $this, 'throw_no_owned_addons_warning' ] );
2✔
82
                }
83
        }
84

85
        /**
86
         * Throws a no owned addons warning.
87
         *
88
         * @return void
89
         */
90
        public function throw_no_owned_addons_warning() {
×
91
                echo '<div class="notice notice-warning"><p>'
×
92
                        . \sprintf(
×
93
                                /* translators: %1$s expands to Yoast SEO */
94
                                \esc_html__(
×
95
                                        'No %1$s plugins have been installed. You don\'t seem to own any active subscriptions.',
×
96
                                        'wordpress-seo'
×
97
                                ),
×
98
                                'Yoast SEO'
×
99
                        )
×
100
                        . '</p></div>';
×
101
        }
102

103
        /**
104
         * Shows the modal.
105
         *
106
         * @return void
107
         */
108
        public function show_modal() {
×
109
                \wp_localize_script(
×
110
                        WPSEO_Admin_Asset_Manager::PREFIX . 'addon-installation',
×
111
                        'wpseoAddonInstallationL10n',
×
112
                        [
×
113
                                'addons' => $this->owned_addons,
×
114
                                'nonce'  => \wp_create_nonce( 'wpseo_addon_installation' ),
×
115
                        ]
×
116
                );
×
117

118
                $asset_manager = new WPSEO_Admin_Asset_Manager();
×
119
                $asset_manager->enqueue_script( 'addon-installation' );
×
120
        }
121

122
        /**
123
         * Retrieves a list of owned addons for the site in MyYoast.
124
         *
125
         * @return array List of owned addons with slug as key and name as value.
126
         */
127
        protected function get_owned_addons() {
4✔
128
                $owned_addons = [];
4✔
129

130
                foreach ( $this->addon_manager->get_myyoast_site_information()->subscriptions as $addon ) {
4✔
131
                        $owned_addons[] = $addon->product->name;
2✔
132
                }
133

134
                return $owned_addons;
4✔
135
        }
136

137
        /**
138
         * Bust the site information transients to have fresh data.
139
         *
140
         * @return void
141
         */
142
        protected function bust_myyoast_addon_information_cache() {
4✔
143
                $this->addon_manager->remove_site_information_transients();
4✔
144
        }
145
}
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