• 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

89.13
/src/integrations/admin/deactivated-premium-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\Non_Multisite_Conditional;
8
use Yoast\WP\SEO\Helpers\Options_Helper;
9
use Yoast\WP\SEO\Integrations\Integration_Interface;
10
use Yoast\WP\SEO\Presenters\Admin\Notice_Presenter;
11

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

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

24
        /**
25
         * The admin asset manager.
26
         *
27
         * @var WPSEO_Admin_Asset_Manager
28
         */
29
        private $admin_asset_manager;
30

31
        /**
32
         * {@inheritDoc}
33
         */
34
        public static function get_conditionals() {
2✔
35
                return [ Admin_Conditional::class, Non_Multisite_Conditional::class ];
2✔
36
        }
37

38
        /**
39
         * First_Time_Configuration_Notice_Integration constructor.
40
         *
41
         * @param Options_Helper            $options_helper      The options helper.
42
         * @param WPSEO_Admin_Asset_Manager $admin_asset_manager The admin asset manager.
43
         */
44
        public function __construct(
×
45
                Options_Helper $options_helper,
46
                WPSEO_Admin_Asset_Manager $admin_asset_manager
47
        ) {
48
                $this->options_helper      = $options_helper;
×
49
                $this->admin_asset_manager = $admin_asset_manager;
×
50
        }
51

52
        /**
53
         * {@inheritDoc}
54
         */
55
        public function register_hooks() {
2✔
56
                \add_action( 'admin_notices', [ $this, 'premium_deactivated_notice' ] );
2✔
57
                \add_action( 'wp_ajax_dismiss_premium_deactivated_notice', [ $this, 'dismiss_premium_deactivated_notice' ] );
2✔
58
        }
1✔
59

60
        /**
61
         * Shows a notice if premium is installed but not activated.
62
         *
63
         * @return void
64
         */
65
        public function premium_deactivated_notice() {
10✔
66
                global $pagenow;
10✔
67
                if ( $pagenow === 'update.php' ) {
10✔
68
                        return;
2✔
69
                }
70

71
                if ( $this->options_helper->get( 'dismiss_premium_deactivated_notice', false ) === true ) {
8✔
72
                        return;
2✔
73
                }
74

75
                $premium_file = 'wordpress-seo-premium/wp-seo-premium.php';
6✔
76

77
                if ( ! \current_user_can( 'activate_plugin', $premium_file ) ) {
6✔
78
                        return;
2✔
79
                }
80

81
                if ( $this->premium_is_installed_not_activated( $premium_file ) ) {
4✔
82
                        $this->admin_asset_manager->enqueue_style( 'monorepo' );
2✔
83

84
                        $content = \sprintf(
2✔
85
                                /* translators: 1: Yoast SEO Premium 2: Link start tag to activate premium, 3: Link closing tag. */
86
                                \__( 'You\'ve installed %1$s but it\'s not activated yet. %2$sActivate %1$s now!%3$s', 'wordpress-seo' ),
2✔
87
                                'Yoast SEO Premium',
2✔
88
                                '<a href="' . \esc_url(
2✔
89
                                        \wp_nonce_url(
2✔
90
                                                \self_admin_url( 'plugins.php?action=activate&plugin=' . $premium_file ),
2✔
91
                                                'activate-plugin_' . $premium_file
2✔
92
                                        )
1✔
93
                                ) . '">',
2✔
94
                                '</a>'
2✔
95
                        );
1✔
96
            // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped above.
97
                        echo new Notice_Presenter(
2✔
98
                                /* translators: 1: Yoast SEO Premium */
99
                                \sprintf( \__( 'Activate %1$s!', 'wordpress-seo' ), 'Yoast SEO Premium' ),
2✔
100
                                $content,
2✔
101
                                'support-team.svg',
2✔
102
                                null,
2✔
103
                                true,
2✔
104
                                'yoast-premium-deactivated-notice'
2✔
105
                        );
1✔
106
            // phpcs:enable
107

108
                        // Enable permanently dismissing the notice.
109
                        echo "<script>
2✔
110
                function dismiss_premium_deactivated_notice(){
111
                    var data = {
112
                    'action': 'dismiss_premium_deactivated_notice',
113
                    };
114

115
                    jQuery.post( ajaxurl, data, function( response ) {
116
                        jQuery( '#yoast-premium-deactivated-notice' ).hide();
117
                    });
118
                }
119

120
                jQuery( document ).ready( function() {
121
                    jQuery( 'body' ).on( 'click', '#yoast-premium-deactivated-notice .notice-dismiss', function() {
122
                        dismiss_premium_deactivated_notice();
123
                    } );
124
                } );
125
            </script>";
1✔
126
                }
127
        }
2✔
128

129
        /**
130
         * Dismisses the premium deactivated notice.
131
         *
132
         * @return bool
133
         */
134
        public function dismiss_premium_deactivated_notice() {
2✔
135
                return $this->options_helper->set( 'dismiss_premium_deactivated_notice', true );
2✔
136
        }
137

138
        /**
139
         * Returns whether or not premium is installed and not activated.
140
         *
141
         * @param string $premium_file The premium file.
142
         *
143
         * @return bool Whether or not premium is installed and not activated.
144
         */
145
        protected function premium_is_installed_not_activated( $premium_file ) {
×
146
                return (
147
                        ! \defined( 'WPSEO_PREMIUM_FILE' )
×
148
                        && \file_exists( \WP_PLUGIN_DIR . '/' . $premium_file )
149
                );
150
        }
151
}
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