• 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

57.5
/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
        }
4✔
52

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

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

72
                $this->bust_myyoast_addon_information_cache();
4✔
73
                $this->owned_addons = $this->get_owned_addons();
4✔
74

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

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

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

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

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

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

132
                return $owned_addons;
4✔
133
        }
134

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