emails
1 year ago
class-experimental-abtest.php
1 year ago
connect-existing-pages.php
3 years ago
core-functions.php
3 years ago
feature-config.php
9 months ago
page-controller-functions.php
4 years ago
wc-admin-update-functions.php
3 years ago
connect-existing-pages.php
311 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Connect existing WooCommerce pages to WooCommerce Admin. |
| 4 | * |
| 5 | * @package WooCommerce\Admin |
| 6 | */ |
| 7 | |
| 8 | use Automattic\WooCommerce\Admin\PageController; |
| 9 | use Automattic\WooCommerce\Admin\Features\Features; |
| 10 | use Automattic\WooCommerce\Utilities\OrderUtil; |
| 11 | |
| 12 | /** |
| 13 | * Returns core WC pages to connect to WC-Admin. |
| 14 | * |
| 15 | * @return array |
| 16 | */ |
| 17 | function wc_admin_get_core_pages_to_connect() { |
| 18 | $all_reports = WC_Admin_Reports::get_reports(); |
| 19 | $report_tabs = array(); |
| 20 | |
| 21 | foreach ( $all_reports as $report_id => $report_data ) { |
| 22 | $report_tabs[ $report_id ] = $report_data['title']; |
| 23 | } |
| 24 | |
| 25 | return array( |
| 26 | 'wc-addons' => array( |
| 27 | 'title' => __( 'Extensions', 'woocommerce' ), |
| 28 | 'tabs' => array(), |
| 29 | ), |
| 30 | 'wc-reports' => array( |
| 31 | 'title' => __( 'Reports', 'woocommerce' ), |
| 32 | 'tabs' => $report_tabs, |
| 33 | ), |
| 34 | 'wc-settings' => array( |
| 35 | 'title' => __( 'Settings', 'woocommerce' ), |
| 36 | 'tabs' => apply_filters( 'woocommerce_settings_tabs_array', array() ), // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment |
| 37 | ), |
| 38 | 'wc-status' => array( |
| 39 | 'title' => __( 'Status', 'woocommerce' ), |
| 40 | // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment |
| 41 | 'tabs' => apply_filters( |
| 42 | 'woocommerce_admin_status_tabs', |
| 43 | array( |
| 44 | 'status' => __( 'System status', 'woocommerce' ), |
| 45 | 'tools' => __( 'Tools', 'woocommerce' ), |
| 46 | 'logs' => __( 'Logs', 'woocommerce' ), |
| 47 | ) |
| 48 | ), |
| 49 | ), |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Filter breadcrumbs for core pages that aren't explicitly connected. |
| 55 | * |
| 56 | * @param array $breadcrumbs Breadcrumb pieces. |
| 57 | * @return array Filtered breadcrumb pieces. |
| 58 | */ |
| 59 | function wc_admin_filter_core_page_breadcrumbs( $breadcrumbs ) { |
| 60 | $screen_id = PageController::get_instance()->get_current_screen_id(); |
| 61 | $pages_to_connect = wc_admin_get_core_pages_to_connect(); |
| 62 | $woocommerce_breadcrumb = array( |
| 63 | 'admin.php?page=wc-admin', |
| 64 | __( 'WooCommerce', 'woocommerce' ), |
| 65 | ); |
| 66 | |
| 67 | foreach ( $pages_to_connect as $page_id => $page_data ) { |
| 68 | if ( preg_match( "/^woocommerce_page_{$page_id}\-/", $screen_id ) ) { |
| 69 | if ( empty( $page_data['tabs'] ) ) { |
| 70 | $new_breadcrumbs = array( |
| 71 | $woocommerce_breadcrumb, |
| 72 | $page_data['title'], |
| 73 | ); |
| 74 | } else { |
| 75 | $new_breadcrumbs = array( |
| 76 | $woocommerce_breadcrumb, |
| 77 | array( |
| 78 | add_query_arg( 'page', $page_id, 'admin.php' ), |
| 79 | $page_data['title'], |
| 80 | ), |
| 81 | ); |
| 82 | |
| 83 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 84 | if ( isset( $_GET['tab'] ) ) { |
| 85 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 86 | $current_tab = wc_clean( wp_unslash( $_GET['tab'] ) ); |
| 87 | } else { |
| 88 | $current_tab = key( $page_data['tabs'] ); |
| 89 | } |
| 90 | |
| 91 | $new_breadcrumbs[] = $page_data['tabs'][ $current_tab ]; |
| 92 | } |
| 93 | |
| 94 | return $new_breadcrumbs; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | return $breadcrumbs; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Render the WC-Admin header bar on all WooCommerce core pages. |
| 103 | * |
| 104 | * @param bool $is_connected Whether the current page is connected. |
| 105 | * @param bool $current_page The current page, if connected. |
| 106 | * @return bool Whether to connect the page. |
| 107 | */ |
| 108 | function wc_admin_connect_core_pages( $is_connected, $current_page ) { |
| 109 | if ( false === $is_connected && false === $current_page ) { |
| 110 | $screen_id = PageController::get_instance()->get_current_screen_id(); |
| 111 | $pages_to_connect = wc_admin_get_core_pages_to_connect(); |
| 112 | |
| 113 | foreach ( $pages_to_connect as $page_id => $page_data ) { |
| 114 | if ( preg_match( "/^woocommerce_page_{$page_id}\-/", $screen_id ) ) { |
| 115 | add_filter( 'woocommerce_navigation_get_breadcrumbs', 'wc_admin_filter_core_page_breadcrumbs' ); |
| 116 | |
| 117 | return true; |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | return $is_connected; |
| 123 | } |
| 124 | |
| 125 | add_filter( 'woocommerce_navigation_is_connected_page', 'wc_admin_connect_core_pages', 10, 2 ); |
| 126 | |
| 127 | $posttype_list_base = 'edit.php'; |
| 128 | |
| 129 | // WooCommerce > Orders. |
| 130 | wc_admin_connect_page( |
| 131 | array( |
| 132 | 'id' => 'woocommerce-orders', |
| 133 | 'screen_id' => 'edit-shop_order', |
| 134 | 'title' => __( 'Orders', 'woocommerce' ), |
| 135 | 'path' => add_query_arg( 'post_type', 'shop_order', $posttype_list_base ), |
| 136 | ) |
| 137 | ); |
| 138 | |
| 139 | // WooCommerce > Orders > Add New. |
| 140 | wc_admin_connect_page( |
| 141 | array( |
| 142 | 'id' => 'woocommerce-add-order', |
| 143 | 'parent' => 'woocommerce-orders', |
| 144 | 'screen_id' => 'shop_order-add', |
| 145 | 'title' => __( 'Add New', 'woocommerce' ), |
| 146 | ) |
| 147 | ); |
| 148 | |
| 149 | // WooCommerce > Orders > Edit Order. |
| 150 | wc_admin_connect_page( |
| 151 | array( |
| 152 | 'id' => 'woocommerce-edit-order', |
| 153 | 'parent' => 'woocommerce-orders', |
| 154 | 'screen_id' => 'shop_order', |
| 155 | 'title' => __( 'Edit Order', 'woocommerce' ), |
| 156 | ) |
| 157 | ); |
| 158 | |
| 159 | if ( OrderUtil::custom_orders_table_usage_is_enabled() ) { |
| 160 | // WooCommerce > Orders (COT). |
| 161 | wc_admin_connect_page( |
| 162 | array( |
| 163 | 'id' => 'woocommerce-custom-orders', |
| 164 | 'screen_id' => wc_get_page_screen_id( 'shop-order' ), |
| 165 | 'title' => __( 'Orders', 'woocommerce' ), |
| 166 | 'path' => 'admin.php?page=wc-orders', |
| 167 | ) |
| 168 | ); |
| 169 | } |
| 170 | |
| 171 | // WooCommerce > Coupons. |
| 172 | wc_admin_connect_page( |
| 173 | array( |
| 174 | 'id' => 'woocommerce-coupons', |
| 175 | 'parent' => Features::is_enabled( 'coupons' ) ? 'woocommerce-marketing' : null, |
| 176 | 'screen_id' => 'edit-shop_coupon', |
| 177 | 'title' => __( 'Coupons', 'woocommerce' ), |
| 178 | 'path' => add_query_arg( 'post_type', 'shop_coupon', $posttype_list_base ), |
| 179 | ) |
| 180 | ); |
| 181 | |
| 182 | // WooCommerce > Coupons > Add New. |
| 183 | wc_admin_connect_page( |
| 184 | array( |
| 185 | 'id' => 'woocommerce-add-coupon', |
| 186 | 'parent' => 'woocommerce-coupons', |
| 187 | 'screen_id' => 'shop_coupon-add', |
| 188 | 'title' => __( 'Add New', 'woocommerce' ), |
| 189 | ) |
| 190 | ); |
| 191 | |
| 192 | // WooCommerce > Coupons > Edit Coupon. |
| 193 | wc_admin_connect_page( |
| 194 | array( |
| 195 | 'id' => 'woocommerce-edit-coupon', |
| 196 | 'parent' => 'woocommerce-coupons', |
| 197 | 'screen_id' => 'shop_coupon', |
| 198 | 'title' => __( 'Edit Coupon', 'woocommerce' ), |
| 199 | ) |
| 200 | ); |
| 201 | |
| 202 | // WooCommerce > Products. |
| 203 | wc_admin_connect_page( |
| 204 | array( |
| 205 | 'id' => 'woocommerce-products', |
| 206 | 'screen_id' => 'edit-product', |
| 207 | 'title' => __( 'Products', 'woocommerce' ), |
| 208 | 'path' => add_query_arg( 'post_type', 'product', $posttype_list_base ), |
| 209 | ) |
| 210 | ); |
| 211 | |
| 212 | // WooCommerce > Products > Add New. |
| 213 | wc_admin_connect_page( |
| 214 | array( |
| 215 | 'id' => 'woocommerce-add-product', |
| 216 | 'parent' => 'woocommerce-products', |
| 217 | 'screen_id' => 'product-add', |
| 218 | 'title' => __( 'Add New', 'woocommerce' ), |
| 219 | ) |
| 220 | ); |
| 221 | |
| 222 | // WooCommerce > Products > Edit Order. |
| 223 | wc_admin_connect_page( |
| 224 | array( |
| 225 | 'id' => 'woocommerce-edit-product', |
| 226 | 'parent' => 'woocommerce-products', |
| 227 | 'screen_id' => 'product', |
| 228 | 'title' => __( 'Edit Product', 'woocommerce' ), |
| 229 | ) |
| 230 | ); |
| 231 | |
| 232 | // WooCommerce > Products > Import Products. |
| 233 | wc_admin_connect_page( |
| 234 | array( |
| 235 | 'id' => 'woocommerce-import-products', |
| 236 | 'parent' => 'woocommerce-products', |
| 237 | 'screen_id' => 'product_page_product_importer', |
| 238 | 'title' => __( 'Import Products', 'woocommerce' ), |
| 239 | ) |
| 240 | ); |
| 241 | |
| 242 | // WooCommerce > Products > Export Products. |
| 243 | wc_admin_connect_page( |
| 244 | array( |
| 245 | 'id' => 'woocommerce-export-products', |
| 246 | 'parent' => 'woocommerce-products', |
| 247 | 'screen_id' => 'product_page_product_exporter', |
| 248 | 'title' => __( 'Export Products', 'woocommerce' ), |
| 249 | ) |
| 250 | ); |
| 251 | |
| 252 | // WooCommerce > Products > Product categories. |
| 253 | wc_admin_connect_page( |
| 254 | array( |
| 255 | 'id' => 'woocommerce-product-categories', |
| 256 | 'parent' => 'woocommerce-products', |
| 257 | 'screen_id' => 'edit-product_cat', |
| 258 | 'title' => __( 'Product categories', 'woocommerce' ), |
| 259 | ) |
| 260 | ); |
| 261 | |
| 262 | // WooCommerce > Products > Edit category. |
| 263 | wc_admin_connect_page( |
| 264 | array( |
| 265 | 'id' => 'woocommerce-product-edit-category', |
| 266 | 'parent' => 'woocommerce-products', |
| 267 | 'screen_id' => 'product_cat', |
| 268 | 'title' => __( 'Edit category', 'woocommerce' ), |
| 269 | ) |
| 270 | ); |
| 271 | |
| 272 | // WooCommerce > Products > Product tags. |
| 273 | wc_admin_connect_page( |
| 274 | array( |
| 275 | 'id' => 'woocommerce-product-tags', |
| 276 | 'parent' => 'woocommerce-products', |
| 277 | 'screen_id' => 'edit-product_tag', |
| 278 | 'title' => __( 'Product tags', 'woocommerce' ), |
| 279 | ) |
| 280 | ); |
| 281 | |
| 282 | // WooCommerce > Products > Edit tag. |
| 283 | wc_admin_connect_page( |
| 284 | array( |
| 285 | 'id' => 'woocommerce-product-edit-tag', |
| 286 | 'parent' => 'woocommerce-products', |
| 287 | 'screen_id' => 'product_tag', |
| 288 | 'title' => __( 'Edit tag', 'woocommerce' ), |
| 289 | ) |
| 290 | ); |
| 291 | |
| 292 | // WooCommerce > Products > Attributes. |
| 293 | wc_admin_connect_page( |
| 294 | array( |
| 295 | 'id' => 'woocommerce-product-attributes', |
| 296 | 'parent' => 'woocommerce-products', |
| 297 | 'screen_id' => 'product_page_product_attributes', |
| 298 | 'title' => __( 'Attributes', 'woocommerce' ), |
| 299 | ) |
| 300 | ); |
| 301 | |
| 302 | // WooCommerce > Products > Edit attribute. |
| 303 | wc_admin_connect_page( |
| 304 | array( |
| 305 | 'id' => 'woocommerce-product-edit-attribute', |
| 306 | 'parent' => 'woocommerce-products', |
| 307 | 'screen_id' => 'product_page_product_attribute-edit', |
| 308 | 'title' => __( 'Edit attribute', 'woocommerce' ), |
| 309 | ) |
| 310 | ); |
| 311 |