PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.5
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / integrations / admin / redirects-page-integration.php

redirects-page-integration.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.5, at src/integrations/admin/redirects-page-integration.php

165 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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\Premium_Inactive_Conditional;
8 use Yoast\WP\SEO\Helpers\Current_Page_Helper;
9 use Yoast\WP\SEO\Helpers\User_Helper;
10 use Yoast\WP\SEO\Integrations\Integration_Interface;
11 use Yoast\WP\SEO\Introductions\Infrastructure\Wistia_Embed_Permission_Repository;
12
13 /**
14 * Redirects_Page_Integration class.
15 */
16 class Redirects_Page_Integration implements Integration_Interface {
17
18 /**
19 * The page identifier.
20 */
21 public const PAGE = 'wpseo_redirects';
22
23 /**
24 * The current page helper.
25 *
26 * @var Current_Page_Helper
27 */
28 private $current_page_helper;
29
30 /**
31 * The user helper.
32 *
33 * @var User_Helper
34 */
35 private $user_helper;
36
37 /**
38 * The Wistia embed permission repository.
39 *
40 * @var Wistia_Embed_Permission_Repository
41 */
42 private $wistia_embed_permission_repository;
43
44 /**
45 * Constructor.
46 *
47 * @param Current_Page_Helper $current_page_helper The current page helper.
48 * @param User_Helper $user_helper The user helper.
49 * @param Wistia_Embed_Permission_Repository $wistia_embed_permission_repository The Wistia embed permission
50 * repository.
51 */
52 public function __construct(
53 Current_Page_Helper $current_page_helper,
54 User_Helper $user_helper,
55 Wistia_Embed_Permission_Repository $wistia_embed_permission_repository
56 ) {
57 $this->current_page_helper = $current_page_helper;
58 $this->user_helper = $user_helper;
59 $this->wistia_embed_permission_repository = $wistia_embed_permission_repository;
60 }
61
62 /**
63 * Sets up the hooks.
64 *
65 * @return void
66 */
67 public function register_hooks() {
68 \add_filter( 'wpseo_submenu_pages', [ $this, 'add_submenu_page' ], 9 );
69 if ( $this->current_page_helper->get_current_yoast_seo_page() === self::PAGE ) {
70 \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
71 \add_action( 'in_admin_header', [ $this, 'remove_notices' ], \PHP_INT_MAX );
72 }
73 }
74
75 /**
76 * Returns the conditionals based on which this loadable should be active.
77 *
78 * In this case: only when on an admin page and Premium is not active.
79 *
80 * @return array The conditionals.
81 */
82 public static function get_conditionals() {
83 return [
84 Admin_Conditional::class,
85 Premium_Inactive_Conditional::class,
86 ];
87 }
88
89 /**
90 * Adds the redirects submenu page.
91 *
92 * @param array $submenu_pages The Yoast SEO submenu pages.
93 *
94 * @return array The filtered submenu pages.
95 */
96 public function add_submenu_page( $submenu_pages ) {
97 $submenu_pages[] = [
98 'wpseo_dashboard',
99 '',
100 \__( 'Redirects', 'wordpress-seo' ) . ' <span class="yoast-badge yoast-premium-badge"></span>',
101 'edit_others_posts',
102 self::PAGE,
103 [ $this, 'display' ],
104 ];
105
106 return $submenu_pages;
107 }
108
109 /**
110 * Enqueue assets on the redirects page.
111 *
112 * @return void
113 */
114 public function enqueue_assets() {
115 $asset_manager = new WPSEO_Admin_Asset_Manager();
116 $asset_manager->enqueue_script( 'redirects' );
117 $asset_manager->enqueue_style( 'redirects' );
118 $user_id = $this->user_helper->get_current_user_id();
119 $asset_manager->localize_script(
120 'redirects',
121 'wpseoScriptData',
122 [
123 'preferences' => [
124 'isRtl' => \is_rtl(),
125 'isComingFromToolsPage' => $this->is_coming_from_tools_page(),
126 ],
127 'linkParams' => \YoastSEO()->helpers->short_link->get_query_params(),
128 'pluginUrl' => \plugins_url( '', \WPSEO_FILE ),
129 'wistiaEmbedPermission' => $this->wistia_embed_permission_repository->get_value_for_user( $user_id ),
130 ],
131 );
132 }
133
134 /**
135 * Displays the redirects page.
136 *
137 * @return void
138 */
139 public function display() {
140 require \WPSEO_PATH . 'admin/pages/redirects.php';
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 * Checks whether the user is coming from the tools page.
157 *
158 * @return bool
159 */
160 public function is_coming_from_tools_page() {
161 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reason: We are simply checking against a set value.
162 return isset( $_GET['from_tools'] ) && $_GET['from_tools'] === '1';
163 }
164 }
165