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rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Internal / Admin / Orders / PostsRedirectionController.php
woocommerce / src / Internal / Admin / Orders Last commit date
MetaBoxes 2 months ago COTRedirectionController.php 1 year ago Edit.php 1 year ago EditLock.php 1 year ago ListTable.php 4 weeks ago PageController.php 9 months ago PostsRedirectionController.php 9 months ago
PostsRedirectionController.php
229 lines
1 <?php
2 namespace Automattic\WooCommerce\Internal\Admin\Orders;
3
4 use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
5 use Automattic\WooCommerce\Utilities\OrderUtil;
6
7 /**
8 * When {@see OrdersTableDataStore} is in use, this class takes care of redirecting admins from CPT-based URLs
9 * to the new ones.
10 */
11 class PostsRedirectionController {
12
13 /**
14 * Instance of the PageController class.
15 *
16 * @var PageController
17 */
18 private $page_controller;
19
20 /**
21 * Constructor.
22 *
23 * @param PageController $page_controller Page controller instance. Used to generate links/URLs.
24 */
25 public function __construct( PageController $page_controller ) {
26 $this->page_controller = $page_controller;
27
28 if ( ! wc_get_container()->get( CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled() ) {
29 return;
30 }
31
32 add_action(
33 'admin_menu',
34 function () {
35 $this->maybe_update_menu_items();
36 },
37 9999
38 );
39
40 add_action(
41 'load-edit.php',
42 function() {
43 $this->maybe_redirect_to_orders_page();
44 }
45 );
46
47 add_action(
48 'load-post-new.php',
49 function() {
50 $this->maybe_redirect_to_new_order_page();
51 }
52 );
53
54 add_action(
55 'load-post.php',
56 function() {
57 $this->maybe_redirect_to_edit_order_page();
58 }
59 );
60 }
61
62 /**
63 * If needed, performs a redirection to the main orders page.
64 *
65 * @return void
66 */
67 private function maybe_redirect_to_orders_page(): void {
68 $post_type = $_GET['post_type'] ?? ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
69
70 if ( ! $post_type || ! in_array( $post_type, wc_get_order_types( 'admin-menu' ), true ) ) {
71 return;
72 }
73
74 // Respect query args, except for 'post_type'.
75 $query_args = wp_unslash( $_GET );
76 $action = $query_args['action'] ?? '';
77 $posts = $query_args['post'] ?? array();
78 unset( $query_args['post_type'], $query_args['post'], $query_args['_wpnonce'], $query_args['_wp_http_referer'], $query_args['action'] );
79
80 // Remap 'post_status' arg.
81 if ( isset( $query_args['post_status'] ) ) {
82 $query_args['status'] = $query_args['post_status'];
83 unset( $query_args['post_status'] );
84 }
85
86 $new_url = $this->page_controller->get_base_page_url( $post_type );
87 $new_url = add_query_arg( $query_args, $new_url );
88
89 // Handle bulk actions.
90 if ( $action && in_array( $action, array( 'trash', 'untrash', 'delete', 'mark_processing', 'mark_on-hold', 'mark_completed', 'mark_cancelled' ), true ) ) {
91 check_admin_referer( 'bulk-posts' );
92
93 $new_url = add_query_arg(
94 array(
95 'action' => $action,
96 'id' => $posts,
97 '_wp_http_referer' => $this->page_controller->get_orders_url(),
98 '_wpnonce' => wp_create_nonce( 'bulk-orders' ),
99 ),
100 $new_url
101 );
102 }
103
104 wp_safe_redirect( $new_url, 301 );
105 exit;
106 }
107
108 /**
109 * If needed, performs a redirection to the new order page.
110 *
111 * @return void
112 */
113 private function maybe_redirect_to_new_order_page(): void {
114 $post_type = $_GET['post_type'] ?? ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
115
116 if ( ! $post_type || ! in_array( $post_type, wc_get_order_types( 'admin-menu' ), true ) ) {
117 return;
118 }
119
120 // Respect query args, except for 'post_type'.
121 $query_args = wp_unslash( $_GET );
122 unset( $query_args['post_type'] );
123
124 $new_url = $this->page_controller->get_new_page_url( $post_type );
125 $new_url = add_query_arg( $query_args, $new_url );
126
127 wp_safe_redirect( $new_url, 301 );
128 exit;
129 }
130
131 /**
132 * If needed, performs a redirection to the edit order page.
133 *
134 * @return void
135 */
136 private function maybe_redirect_to_edit_order_page(): void {
137 $post_id = absint( $_GET['post'] ?? 0 );
138 if ( ! $post_id ) {
139 return;
140 }
141
142 $redirect_from_types = wc_get_order_types( 'admin-menu' );
143 $redirect_from_types[] = 'shop_order_placehold';
144
145 $post_type = get_post_type( $post_id );
146 $order_type = $post_type ? $post_type : OrderUtil::get_order_type( $post_id );
147 if ( ! in_array( $order_type, $redirect_from_types, true ) || ! isset( $_GET['action'] ) ) {
148 return;
149 }
150
151 // Respect query args, except for 'post'.
152 $query_args = wp_unslash( $_GET );
153 $action = $query_args['action'];
154 unset( $query_args['post'], $query_args['_wpnonce'], $query_args['_wp_http_referer'], $query_args['action'] );
155
156 $new_url = '';
157
158 switch ( $action ) {
159 case 'edit':
160 $new_url = $this->page_controller->get_edit_url( $post_id );
161 break;
162
163 case 'trash':
164 case 'untrash':
165 case 'delete':
166 // Re-generate nonce if validation passes.
167 check_admin_referer( $action . '-post_' . $post_id );
168
169 $new_url = add_query_arg(
170 array(
171 'action' => $action,
172 'order' => array( $post_id ),
173 '_wp_http_referer' => $this->page_controller->get_orders_url(),
174 '_wpnonce' => wp_create_nonce( 'bulk-orders' ),
175 ),
176 $this->page_controller->get_orders_url()
177 );
178
179 break;
180
181 default:
182 break;
183 }
184
185 if ( ! $new_url ) {
186 return;
187 }
188
189 $new_url = add_query_arg( $query_args, $new_url );
190
191 wp_safe_redirect( $new_url, 301 );
192 exit;
193 }
194
195 /**
196 * Rewrites legacy post type menu items to point to the HPOS orders page when the main WooCommerce menu is not visible.
197 *
198 * @since 10.3.0
199 */
200 private function maybe_update_menu_items(): void {
201 global $pagenow, $submenu;
202
203 // Do not conflict with CPT > HPOS redirection.
204 if ( 'edit.php' === $pagenow && in_array( $_GET['post_type'] ?? '', wc_get_order_types( 'admin-menu' ), true ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
205 return;
206 }
207
208 if ( \WC_Admin_Menus::can_view_woocommerce_menu_item() ) {
209 return;
210 }
211
212 $post_types = array_filter( array_map( 'get_post_type_object', wc_get_order_types( 'admin-menu' ) ) );
213 foreach ( $post_types as $post_type ) {
214 if ( ! current_user_can( $post_type->cap->edit_posts ) || ! isset( $submenu[ 'edit.php?post_type=' . $post_type->name ] ) ) {
215 continue;
216 }
217
218 $post_type_menu = &$submenu[ 'edit.php?post_type=' . $post_type->name ];
219 $menu_indexes = array_flip( array_map( fn( $x ) => $x[2], $post_type_menu ) );
220
221 // Rewrite URL for the legacy menu item.
222 $post_type_menu[ $menu_indexes[ 'edit.php?post_type=' . $post_type->name ] ][2] = $this->page_controller->get_base_page_url( $post_type->name );
223
224 // Hide the legacy "Add New" menu item.
225 unset( $post_type_menu[ $menu_indexes[ "post-new.php?post_type={$post_type->name}" ] ] );
226 }
227 }
228 }
229