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

Yoast / wordpress-seo / 5066322038

pending completion
5066322038

push

github

GitHub
Merge pull request #20316 from Yoast/JRF/ghactions-run-more-selectively

2550 of 29012 relevant lines covered (8.79%)

0.32 hits per line

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

0.0
/src/integrations/academy-integration.php
1
<?php
2

3
namespace Yoast\WP\SEO\Integrations;
4

5
use WPSEO_Addon_Manager;
6
use WPSEO_Admin_Asset_Manager;
7
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
8
use Yoast\WP\SEO\Conditionals\User_Can_Manage_Wpseo_Options_Conditional;
9
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
10
use Yoast\WP\SEO\Helpers\Product_Helper;
11
use Yoast\WP\SEO\Helpers\Short_Link_Helper;
12

13
/**
14
 * Class Academy_Integration.
15
 */
16
class Academy_Integration implements Integration_Interface {
17

18
        const PAGE = 'wpseo_page_academy';
19

20
        /**
21
         * Holds the WPSEO_Admin_Asset_Manager.
22
         *
23
         * @var WPSEO_Admin_Asset_Manager
24
         */
25
        private $asset_manager;
26

27
        /**
28
         * Holds the Current_Page_Helper.
29
         *
30
         * @var Current_Page_Helper
31
         */
32
        private $current_page_helper;
33

34
        /**
35
         * Holds the Product_Helper.
36
         *
37
         * @var Product_Helper
38
         */
39
        private $product_helper;
40

41
        /**
42
         * Holds the Short_Link_Helper.
43
         *
44
         * @var Short_Link_Helper
45
         */
46
        private $shortlink_helper;
47

48
        /**
49
         * Constructs Settings_Integration.
50
         *
51
         * @param WPSEO_Admin_Asset_Manager $asset_manager       The WPSEO_Admin_Asset_Manager.
52
         * @param Current_Page_Helper       $current_page_helper The Current_Page_Helper.
53
         * @param Product_Helper            $product_helper      The Product_Helper.
54
         * @param Short_Link_Helper         $shortlink_helper    The Short_Link_Helper.
55
         */
56
        public function __construct(
57
                WPSEO_Admin_Asset_Manager $asset_manager,
58
                Current_Page_Helper $current_page_helper,
59
                Product_Helper $product_helper,
60
                Short_Link_Helper $shortlink_helper
61
        ) {
62
                $this->asset_manager       = $asset_manager;
×
63
                $this->current_page_helper = $current_page_helper;
×
64
                $this->product_helper      = $product_helper;
×
65
                $this->shortlink_helper    = $shortlink_helper;
×
66
        }
67

68
        /**
69
         * Returns the conditionals based on which this loadable should be active.
70
         *
71
         * @return array
72
         */
73
        public static function get_conditionals() {
74
                return [ Admin_Conditional::class, User_Can_Manage_Wpseo_Options_Conditional::class ];
×
75
        }
76

77
        /**
78
         * Initializes the integration.
79
         *
80
         * This is the place to register hooks and filters.
81
         *
82
         * @return void
83
         */
84
        public function register_hooks() {
85
                // Add page.
86
                \add_filter( 'wpseo_submenu_pages', [ $this, 'add_page' ] );
×
87

88
                // Are we on the settings page?
89
                if ( $this->current_page_helper->get_current_yoast_seo_page() === self::PAGE ) {
×
90
                        \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
×
91
                        \add_action( 'in_admin_header', [ $this, 'remove_notices' ], \PHP_INT_MAX );
×
92
                }
93
        }
94

95
        /**
96
         * Adds the page.
97
         *
98
         * @param array $pages The pages.
99
         *
100
         * @return array The pages.
101
         */
102
        public function add_page( $pages ) {
103
                \array_splice(
×
104
                        $pages,
×
105
                        3,
×
106
                        0,
×
107
                        [
×
108
                                [
×
109
                                        'wpseo_dashboard',
×
110
                                        '',
×
111
                                        \__( 'Academy', 'wordpress-seo' ),
×
112
                                        'wpseo_manage_options',
×
113
                                        self::PAGE,
×
114
                                        [ $this, 'display_page' ],
×
115
                                ],
×
116
                        ]
×
117
                );
×
118

119
                return $pages;
×
120
        }
121

122
        /**
123
         * Displays the page.
124
         */
125
        public function display_page() {
126
                echo '<div id="yoast-seo-academy"></div>';
×
127
        }
128

129
        /**
130
         * Enqueues the assets.
131
         *
132
         * @return void
133
         */
134
        public function enqueue_assets() {
135
                // Remove the emoji script as it is incompatible with both React and any contenteditable fields.
136
                \remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
×
137
                \wp_enqueue_media();
×
138
                $this->asset_manager->enqueue_script( 'academy' );
×
139
                $this->asset_manager->enqueue_style( 'academy' );
×
140
                $this->asset_manager->localize_script( 'academy', 'wpseoScriptData', $this->get_script_data() );
×
141
        }
142

143
        /**
144
         * Removes all current WP notices.
145
         *
146
         * @return void
147
         */
148
        public function remove_notices() {
149
                \remove_all_actions( 'admin_notices' );
×
150
                \remove_all_actions( 'user_admin_notices' );
×
151
                \remove_all_actions( 'network_admin_notices' );
×
152
                \remove_all_actions( 'all_admin_notices' );
×
153
        }
154

155
        /**
156
         * Creates the script data.
157
         *
158
         * @return array The script data.
159
         */
160
        public function get_script_data() {
161
                $addon_manager = new WPSEO_Addon_Manager();
×
162

163
                $woocommerce_seo_active = $addon_manager->is_installed( WPSEO_Addon_Manager::WOOCOMMERCE_SLUG );
×
164
                $local_seo_active       = $addon_manager->is_installed( WPSEO_Addon_Manager::LOCAL_SLUG );
×
165

166
                return [
×
167
                        'preferences' => [
×
168
                                'isPremium'      => $this->product_helper->is_premium(),
×
169
                                'isWooActive'    => $woocommerce_seo_active,
×
170
                                'isLocalActive'  => $local_seo_active,
×
171
                                'isRtl'          => \is_rtl(),
×
172
                                'pluginUrl'      => \plugins_url( '', \WPSEO_FILE ),
×
173
                                'upsellSettings' => [
×
174
                                        'actionId'     => 'load-nfd-ctb',
×
175
                                        'premiumCtbId' => 'f6a84663-465f-4cb5-8ba5-f7a6d72224b2',
×
176
                                ],
×
177
                        ],
×
178
                        'linkParams'  => $this->shortlink_helper->get_query_params(),
×
179
                ];
×
180
        }
181
}
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