helper
4 months ago
importers
1 month ago
list-tables
1 month ago
marketplace-suggestions
1 year ago
meta-boxes
1 month ago
notes
4 months ago
plugin-updates
2 years ago
reports
1 month ago
settings
1 month ago
views
1 month ago
class-wc-admin-addons.php
10 months ago
class-wc-admin-api-keys-table-list.php
3 years ago
class-wc-admin-api-keys.php
1 month ago
class-wc-admin-assets.php
1 month ago
class-wc-admin-attributes.php
1 month ago
class-wc-admin-brands.php
1 month ago
class-wc-admin-customize.php
6 years ago
class-wc-admin-dashboard-setup.php
1 month ago
class-wc-admin-dashboard.php
1 month ago
class-wc-admin-duplicate-product.php
1 month ago
class-wc-admin-exporters.php
1 year ago
class-wc-admin-help.php
2 years ago
class-wc-admin-importers.php
1 year ago
class-wc-admin-log-table-list.php
6 months ago
class-wc-admin-marketplace-promotions.php
1 month ago
class-wc-admin-menus.php
1 month ago
class-wc-admin-meta-boxes.php
2 months ago
class-wc-admin-notices.php
1 month ago
class-wc-admin-permalink-settings.php
5 years ago
class-wc-admin-pointers.php
3 years ago
class-wc-admin-post-types.php
1 month ago
class-wc-admin-profile.php
1 year ago
class-wc-admin-reports.php
6 months ago
class-wc-admin-settings.php
1 month ago
class-wc-admin-setup-wizard.php
2 months ago
class-wc-admin-status.php
1 year ago
class-wc-admin-taxonomies.php
2 months ago
class-wc-admin-upload-downloadable-product.php
2 years ago
class-wc-admin-webhooks-table-list.php
2 months ago
class-wc-admin-webhooks.php
1 month ago
class-wc-admin.php
5 months ago
wc-admin-functions.php
1 month ago
wc-meta-box-functions.php
1 year ago
woocommerce-legacy-reports.php
1 year ago
class-wc-admin-menus.php
577 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Setup menus in WP admin. |
| 4 | * |
| 5 | * @package WooCommerce\Admin |
| 6 | * @version 2.5.0 |
| 7 | */ |
| 8 | |
| 9 | use Automattic\WooCommerce\Internal\Admin\Marketplace; |
| 10 | use Automattic\WooCommerce\Internal\Admin\Orders\COTRedirectionController; |
| 11 | use Automattic\WooCommerce\Internal\Admin\Orders\PageController as Custom_Orders_PageController; |
| 12 | use Automattic\WooCommerce\Internal\Admin\Logging\PageController as LoggingPageController; |
| 13 | use Automattic\WooCommerce\Internal\Admin\Logging\FileV2\{ FileListTable, SearchListTable }; |
| 14 | use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController; |
| 15 | |
| 16 | defined( 'ABSPATH' ) || exit; |
| 17 | |
| 18 | if ( class_exists( 'WC_Admin_Menus', false ) ) { |
| 19 | return new WC_Admin_Menus(); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * WC_Admin_Menus Class. |
| 24 | */ |
| 25 | class WC_Admin_Menus { |
| 26 | |
| 27 | /** |
| 28 | * The CSS classes used to hide the submenu items in navigation. |
| 29 | * |
| 30 | * @var string |
| 31 | */ |
| 32 | const HIDE_CSS_CLASS = 'hide-if-js'; |
| 33 | |
| 34 | /** |
| 35 | * Hook in tabs. |
| 36 | */ |
| 37 | public function __construct() { |
| 38 | // Add menus. |
| 39 | add_action( 'admin_menu', array( $this, 'menu_highlight' ) ); |
| 40 | add_action( 'admin_menu', array( $this, 'menu_order_count' ) ); |
| 41 | add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 ); |
| 42 | add_action( 'admin_menu', array( $this, 'orders_menu' ), 9 ); |
| 43 | add_action( 'admin_menu', array( $this, 'reports_menu' ), 20 ); |
| 44 | add_action( 'admin_menu', array( $this, 'settings_menu' ), 50 ); |
| 45 | add_action( 'admin_menu', array( $this, 'status_menu' ), 60 ); |
| 46 | |
| 47 | /** |
| 48 | * Controls whether we add a submenu item for the WooCommerce Addons page. |
| 49 | * Woo Express uses this filter. |
| 50 | * |
| 51 | * @since 8.2.1 |
| 52 | * |
| 53 | * @param bool $show_addons_page If the addons page should be included. |
| 54 | */ |
| 55 | if ( apply_filters( 'woocommerce_show_addons_page', true ) ) { |
| 56 | $container = wc_get_container(); |
| 57 | $container->get( Marketplace::class ); |
| 58 | |
| 59 | add_action( 'admin_menu', array( $this, 'addons_my_subscriptions' ), 70 ); |
| 60 | } |
| 61 | |
| 62 | add_filter( 'menu_order', array( $this, 'menu_order' ) ); |
| 63 | add_filter( 'custom_menu_order', array( $this, 'custom_menu_order' ) ); |
| 64 | add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 10, 3 ); |
| 65 | |
| 66 | // Add endpoints custom URLs in Appearance > Menus > Pages. |
| 67 | add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) ); |
| 68 | |
| 69 | // Admin bar menus. |
| 70 | if ( apply_filters( 'woocommerce_show_admin_bar_visit_store', true ) ) { |
| 71 | add_action( 'admin_bar_menu', array( $this, 'admin_bar_menus' ), 31 ); |
| 72 | } |
| 73 | |
| 74 | // Handle saving settings earlier than load-{page} hook to avoid race conditions in conditional menus. |
| 75 | add_action( 'wp_loaded', array( $this, 'save_settings' ) ); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Add menu items. |
| 80 | * |
| 81 | * @return void |
| 82 | */ |
| 83 | public function admin_menu() { |
| 84 | global $menu, $admin_page_hooks; |
| 85 | |
| 86 | $woocommerce_icon = 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDg1LjkgNDcuNiI+CjxwYXRoIGZpbGw9IiNhMmFhYjIiIGQ9Ik03Ny40LDAuMWMtNC4zLDAtNy4xLDEuNC05LjYsNi4xTDU2LjQsMjcuN1Y4LjZjMC01LjctMi43LTguNS03LjctOC41cy03LjEsMS43LTkuNiw2LjVMMjguMywyNy43VjguOAoJYzAtNi4xLTIuNS04LjctOC42LTguN0g3LjNDMi42LDAuMSwwLDIuMywwLDYuM3MyLjUsNi40LDcuMSw2LjRoNS4xdjI0LjFjMCw2LjgsNC42LDEwLjgsMTEuMiwxMC44UzMzLDQ1LDM2LjMsMzguOWw3LjItMTMuNXYxMS40CgljMCw2LjcsNC40LDEwLjgsMTEuMSwxMC44czkuMi0yLjMsMTMtOC43bDE2LjYtMjhjMy42LTYuMSwxLjEtMTAuOC02LjktMTAuOEM3Ny4zLDAuMSw3Ny4zLDAuMSw3Ny40LDAuMXoiLz4KPC9zdmc+Cg=='; |
| 87 | |
| 88 | if ( self::can_view_woocommerce_menu_item() ) { |
| 89 | $menu[] = array( '', 'read', 'separator-woocommerce', '', 'wp-menu-separator woocommerce' ); // WPCS: override ok. |
| 90 | } |
| 91 | |
| 92 | add_menu_page( __( 'WooCommerce', 'woocommerce' ), __( 'WooCommerce', 'woocommerce' ), 'edit_others_shop_orders', 'woocommerce', null, $woocommerce_icon, '55.5' ); |
| 93 | |
| 94 | // Work around https://github.com/woocommerce/woocommerce/issues/35677 (and related https://core.trac.wordpress.org/ticket/18857). |
| 95 | // Translating the menu item breaks screen IDs and page hooks, so we force the hookname to be untranslated. |
| 96 | $admin_page_hooks['woocommerce'] = 'woocommerce'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 97 | |
| 98 | add_submenu_page( 'edit.php?post_type=product', __( 'Attributes', 'woocommerce' ), __( 'Attributes', 'woocommerce' ), 'manage_product_terms', 'product_attributes', array( $this, 'attributes_page' ) ); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Add menu item. |
| 103 | * |
| 104 | * @return void |
| 105 | */ |
| 106 | public function reports_menu() { |
| 107 | if ( self::can_view_woocommerce_menu_item() ) { |
| 108 | add_submenu_page( 'woocommerce', __( 'Reports', 'woocommerce' ), __( 'Reports', 'woocommerce' ), 'view_woocommerce_reports', 'wc-reports', array( $this, 'reports_page' ) ); |
| 109 | } else { |
| 110 | add_menu_page( __( 'Sales reports', 'woocommerce' ), __( 'Sales reports', 'woocommerce' ), 'view_woocommerce_reports', 'wc-reports', array( $this, 'reports_page' ), 'dashicons-chart-bar', '55.6' ); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Add menu item. |
| 116 | * |
| 117 | * @return void |
| 118 | */ |
| 119 | public function settings_menu() { |
| 120 | $settings_page = add_submenu_page( |
| 121 | 'woocommerce', |
| 122 | __( 'WooCommerce settings', 'woocommerce' ), |
| 123 | __( 'Settings', 'woocommerce' ), |
| 124 | 'manage_woocommerce', |
| 125 | 'wc-settings', |
| 126 | array( $this, 'settings_page' ) |
| 127 | ); |
| 128 | |
| 129 | add_action( 'load-' . $settings_page, array( $this, 'settings_page_init' ) ); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Check if the user can access the top-level WooCommerce item. |
| 134 | * |
| 135 | * @return bool |
| 136 | */ |
| 137 | public static function can_view_woocommerce_menu_item() { |
| 138 | return current_user_can( 'edit_others_shop_orders' ); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Loads gateways and shipping methods into memory for use within settings. |
| 143 | * |
| 144 | * @return void |
| 145 | */ |
| 146 | public function settings_page_init() { |
| 147 | WC()->payment_gateways(); |
| 148 | WC()->shipping(); |
| 149 | |
| 150 | // Include settings pages. |
| 151 | WC_Admin_Settings::get_settings_pages(); |
| 152 | |
| 153 | // Add any posted messages. |
| 154 | if ( ! empty( $_GET['wc_error'] ) ) { // WPCS: input var okay, CSRF ok. |
| 155 | WC_Admin_Settings::add_error( wp_kses_post( wp_unslash( $_GET['wc_error'] ) ) ); // WPCS: input var okay, CSRF ok. |
| 156 | } |
| 157 | |
| 158 | if ( ! empty( $_GET['wc_message'] ) ) { // WPCS: input var okay, CSRF ok. |
| 159 | WC_Admin_Settings::add_message( wp_kses_post( wp_unslash( $_GET['wc_message'] ) ) ); // WPCS: input var okay, CSRF ok. |
| 160 | } |
| 161 | |
| 162 | do_action( 'woocommerce_settings_page_init' ); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Handle saving of settings. |
| 167 | * |
| 168 | * @return void |
| 169 | */ |
| 170 | public function save_settings() { |
| 171 | global $current_tab, $current_section; |
| 172 | |
| 173 | // We should only save on the settings page. |
| 174 | if ( ! is_wc_admin_settings_page() ) { |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | // Include settings pages. |
| 179 | WC_Admin_Settings::get_settings_pages(); |
| 180 | |
| 181 | // Get current tab/section. |
| 182 | $current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( wp_unslash( $_GET['tab'] ) ); // WPCS: input var okay, CSRF ok. |
| 183 | $current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( wp_unslash( $_REQUEST['section'] ) ); // WPCS: input var okay, CSRF ok. |
| 184 | |
| 185 | // Save settings if data has been posted. |
| 186 | if ( '' !== $current_section && apply_filters( "woocommerce_save_settings_{$current_tab}_{$current_section}", ! empty( $_POST['save'] ) ) ) { // WPCS: input var okay, CSRF ok. |
| 187 | WC_Admin_Settings::save(); |
| 188 | } elseif ( '' === $current_section && apply_filters( "woocommerce_save_settings_{$current_tab}", ! empty( $_POST['save'] ) ) ) { // WPCS: input var okay, CSRF ok. |
| 189 | WC_Admin_Settings::save(); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Add menu item. |
| 195 | * |
| 196 | * @return void |
| 197 | */ |
| 198 | public function status_menu() { |
| 199 | $status_page = add_submenu_page( 'woocommerce', __( 'WooCommerce status', 'woocommerce' ), __( 'Status', 'woocommerce' ), 'manage_woocommerce', 'wc-status', array( $this, 'status_page' ) ); |
| 200 | |
| 201 | add_action( |
| 202 | 'load-' . $status_page, |
| 203 | function () { |
| 204 | if ( 'logs' === filter_input( INPUT_GET, 'tab' ) ) { |
| 205 | // Initialize the logging page controller early so that it can hook into things. |
| 206 | wc_get_container()->get( LoggingPageController::class ); |
| 207 | } |
| 208 | }, |
| 209 | 1 |
| 210 | ); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Addons menu item. |
| 215 | * |
| 216 | * @deprecated 10.5.0 The marketplace feature is now always enabled. Use the Extensions menu instead. |
| 217 | * |
| 218 | * @return void |
| 219 | */ |
| 220 | public function addons_menu() { |
| 221 | wc_deprecated_function( __METHOD__, '10.5.0' ); |
| 222 | |
| 223 | $count_html = WC_Helper_Updater::get_updates_count_html(); |
| 224 | /* translators: %s: extensions count */ |
| 225 | $menu_title = sprintf( __( 'Extensions %s', 'woocommerce' ), $count_html ); |
| 226 | add_submenu_page( 'woocommerce', __( 'WooCommerce extensions', 'woocommerce' ), $menu_title, 'manage_woocommerce', 'wc-addons', array( $this, 'addons_page' ) ); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Registers the wc-addons page within the WooCommerce menu. |
| 231 | * Temporary measure till we convert the whole page to React. |
| 232 | * |
| 233 | * @return void |
| 234 | */ |
| 235 | public function addons_my_subscriptions() { |
| 236 | add_submenu_page( 'woocommerce', __( 'WooCommerce extensions', 'woocommerce' ), null, 'manage_woocommerce', 'wc-addons', array( $this, 'addons_page' ) ); |
| 237 | // Temporarily hide the submenu item we've just added. |
| 238 | $this->hide_submenu_page( 'woocommerce', 'wc-addons' ); |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * Highlights the correct top level admin menu item for post type add screens. |
| 243 | * |
| 244 | * @return void |
| 245 | */ |
| 246 | public function menu_highlight() { |
| 247 | global $parent_file, $submenu_file, $post_type; |
| 248 | |
| 249 | switch ( $post_type ) { |
| 250 | case 'shop_order': |
| 251 | case 'shop_coupon': |
| 252 | $parent_file = 'woocommerce'; // WPCS: override ok. |
| 253 | break; |
| 254 | case 'product': |
| 255 | $screen = get_current_screen(); |
| 256 | if ( $screen && taxonomy_is_product_attribute( $screen->taxonomy ) ) { |
| 257 | $submenu_file = 'product_attributes'; // WPCS: override ok. |
| 258 | $parent_file = 'edit.php?post_type=product'; // WPCS: override ok. |
| 259 | } |
| 260 | break; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Adds the order processing count to the menu. |
| 266 | * |
| 267 | * @return void |
| 268 | */ |
| 269 | public function menu_order_count() { |
| 270 | global $submenu; |
| 271 | |
| 272 | if ( isset( $submenu['woocommerce'] ) ) { |
| 273 | // Remove 'WooCommerce' sub menu item. |
| 274 | unset( $submenu['woocommerce'][0] ); |
| 275 | |
| 276 | // Add count if user has access. |
| 277 | if ( apply_filters( 'woocommerce_include_processing_order_count_in_menu', true ) && current_user_can( 'edit_others_shop_orders' ) ) { |
| 278 | $order_count = apply_filters( 'woocommerce_menu_order_count', wc_processing_order_count() ); |
| 279 | |
| 280 | if ( $order_count ) { |
| 281 | foreach ( $submenu['woocommerce'] as $key => $menu_item ) { |
| 282 | if ( 0 === strpos( $menu_item[0], _x( 'Orders', 'Admin menu name', 'woocommerce' ) ) ) { |
| 283 | $submenu['woocommerce'][ $key ][0] .= ' <span class="menu-counter count-' . esc_attr( $order_count ) . '"><span class="processing-count">' . number_format_i18n( $order_count ) . '</span></span>'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 284 | break; |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Reorder the WC menu items in admin. |
| 294 | * |
| 295 | * @param int $menu_order Menu order. |
| 296 | * @return array |
| 297 | */ |
| 298 | public function menu_order( $menu_order ) { |
| 299 | // Initialize our custom order array. |
| 300 | $woocommerce_menu_order = array(); |
| 301 | |
| 302 | // Get the index of our custom separator. |
| 303 | $woocommerce_separator = array_search( 'separator-woocommerce', $menu_order, true ); |
| 304 | |
| 305 | // Get index of product menu. |
| 306 | $woocommerce_product = array_search( 'edit.php?post_type=product', $menu_order, true ); |
| 307 | |
| 308 | // Loop through menu order and do some rearranging. |
| 309 | foreach ( $menu_order as $index => $item ) { |
| 310 | |
| 311 | if ( 'woocommerce' === $item ) { |
| 312 | $woocommerce_menu_order[] = 'separator-woocommerce'; |
| 313 | $woocommerce_menu_order[] = $item; |
| 314 | $woocommerce_menu_order[] = 'edit.php?post_type=product'; |
| 315 | unset( $menu_order[ $woocommerce_separator ] ); |
| 316 | unset( $menu_order[ $woocommerce_product ] ); |
| 317 | } elseif ( ! in_array( $item, array( 'separator-woocommerce' ), true ) ) { |
| 318 | $woocommerce_menu_order[] = $item; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | // Return order. |
| 323 | return $woocommerce_menu_order; |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * Custom menu order. |
| 328 | * |
| 329 | * @param bool $enabled Whether custom menu ordering is already enabled. |
| 330 | * @return bool |
| 331 | */ |
| 332 | public function custom_menu_order( $enabled ) { |
| 333 | return $enabled || self::can_view_woocommerce_menu_item(); |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * Validate screen options on update. |
| 338 | * |
| 339 | * @param bool|int $status Screen option value. Default false to skip. |
| 340 | * @param string $option The option name. |
| 341 | * @param int $value The number of rows to use. |
| 342 | * @return bool|int |
| 343 | */ |
| 344 | public function set_screen_option( $status, $option, $value ) { |
| 345 | $screen_options = array( |
| 346 | 'woocommerce_keys_per_page', |
| 347 | 'woocommerce_webhooks_per_page', |
| 348 | FileListTable::PER_PAGE_USER_OPTION_KEY, |
| 349 | SearchListTable::PER_PAGE_USER_OPTION_KEY, |
| 350 | WC_Admin_Log_Table_List::PER_PAGE_USER_OPTION_KEY, |
| 351 | ); |
| 352 | |
| 353 | if ( in_array( $option, $screen_options, true ) ) { |
| 354 | return $value; |
| 355 | } |
| 356 | |
| 357 | return $status; |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * Init the reports page. |
| 362 | * |
| 363 | * @return void |
| 364 | */ |
| 365 | public function reports_page() { |
| 366 | WC_Admin_Reports::output(); |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Init the settings page. |
| 371 | * |
| 372 | * @return void |
| 373 | */ |
| 374 | public function settings_page() { |
| 375 | WC_Admin_Settings::output(); |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Init the attributes page. |
| 380 | * |
| 381 | * @return void |
| 382 | */ |
| 383 | public function attributes_page() { |
| 384 | WC_Admin_Attributes::output(); |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * Init the status page. |
| 389 | * |
| 390 | * @return void |
| 391 | */ |
| 392 | public function status_page() { |
| 393 | WC_Admin_Status::output(); |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * Init the addons page. |
| 398 | * |
| 399 | * @return void |
| 400 | */ |
| 401 | public function addons_page() { |
| 402 | WC_Admin_Addons::handle_legacy_marketplace_redirects(); |
| 403 | } |
| 404 | |
| 405 | /** |
| 406 | * Link to the order admin list table from the main WooCommerce menu. |
| 407 | * |
| 408 | * @return void |
| 409 | */ |
| 410 | public function orders_menu(): void { |
| 411 | if ( wc_get_container()->get( CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled() ) { |
| 412 | wc_get_container()->get( Custom_Orders_PageController::class )->setup(); |
| 413 | } else { |
| 414 | wc_get_container()->get( COTRedirectionController::class )->setup(); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | /** |
| 419 | * Add custom nav meta box. |
| 420 | * |
| 421 | * Adapted from http://www.johnmorrisonline.com/how-to-add-a-fully-functional-custom-meta-box-to-wordpress-navigation-menus/. |
| 422 | * |
| 423 | * @return void |
| 424 | */ |
| 425 | public function add_nav_menu_meta_boxes() { |
| 426 | add_meta_box( 'woocommerce_endpoints_nav_link', __( 'WooCommerce endpoints', 'woocommerce' ), array( $this, 'nav_menu_links' ), 'nav-menus', 'side', 'low' ); |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * Output menu links. |
| 431 | * |
| 432 | * @return void |
| 433 | */ |
| 434 | public function nav_menu_links() { |
| 435 | // Get items from account menu. |
| 436 | $endpoints = wc_get_account_menu_items(); |
| 437 | |
| 438 | // Remove dashboard item. |
| 439 | if ( isset( $endpoints['dashboard'] ) ) { |
| 440 | unset( $endpoints['dashboard'] ); |
| 441 | } |
| 442 | |
| 443 | // Include missing lost password endpoint, if set in WooCommerce > Settings > Advanced > Account endpoints. |
| 444 | if ( ! empty( get_option( 'woocommerce_myaccount_lost_password_endpoint' ) ) ) { |
| 445 | $endpoints['lost-password'] = __( 'Lost password', 'woocommerce' ); |
| 446 | } |
| 447 | |
| 448 | $endpoints = apply_filters( 'woocommerce_custom_nav_menu_items', $endpoints ); |
| 449 | |
| 450 | ?> |
| 451 | <div id="posttype-woocommerce-endpoints" class="posttypediv"> |
| 452 | <div id="tabs-panel-woocommerce-endpoints" class="tabs-panel tabs-panel-active"> |
| 453 | <ul id="woocommerce-endpoints-checklist" class="categorychecklist form-no-clear"> |
| 454 | <?php |
| 455 | $i = -1; |
| 456 | foreach ( $endpoints as $key => $value ) : |
| 457 | ?> |
| 458 | <li> |
| 459 | <label class="menu-item-title"> |
| 460 | <input type="checkbox" class="menu-item-checkbox" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-object-id]" value="<?php echo esc_attr( $i ); ?>" /> <?php echo esc_html( $value ); ?> |
| 461 | </label> |
| 462 | <input type="hidden" class="menu-item-type" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-type]" value="custom" /> |
| 463 | <input type="hidden" class="menu-item-title" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-title]" value="<?php echo esc_attr( $value ); ?>" /> |
| 464 | <input type="hidden" class="menu-item-url" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-url]" value="<?php echo esc_url( wc_get_account_endpoint_url( $key ) ); ?>" /> |
| 465 | <input type="hidden" class="menu-item-classes" name="menu-item[<?php echo esc_attr( $i ); ?>][menu-item-classes]" /> |
| 466 | </li> |
| 467 | <?php |
| 468 | --$i; |
| 469 | endforeach; |
| 470 | ?> |
| 471 | </ul> |
| 472 | </div> |
| 473 | <p class="button-controls" data-items-type="posttype-woocommerce-endpoints"> |
| 474 | <span class="list-controls"> |
| 475 | <label> |
| 476 | <input type="checkbox" class="select-all" /> |
| 477 | <?php esc_html_e( 'Select all', 'woocommerce' ); ?> |
| 478 | </label> |
| 479 | </span> |
| 480 | <span class="add-to-menu"> |
| 481 | <button type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to menu', 'woocommerce' ); ?>" name="add-post-type-menu-item" id="submit-posttype-woocommerce-endpoints"><?php esc_html_e( 'Add to menu', 'woocommerce' ); ?></button> |
| 482 | <span class="spinner"></span> |
| 483 | </span> |
| 484 | </p> |
| 485 | </div> |
| 486 | <?php |
| 487 | } |
| 488 | |
| 489 | /** |
| 490 | * Add the "Visit Store" link in admin bar main menu. |
| 491 | * |
| 492 | * @since 2.4.0 |
| 493 | * @param WP_Admin_Bar $wp_admin_bar Admin bar instance. |
| 494 | * @return void |
| 495 | */ |
| 496 | public function admin_bar_menus( $wp_admin_bar ) { |
| 497 | if ( ! is_admin() || ! is_admin_bar_showing() ) { |
| 498 | return; |
| 499 | } |
| 500 | |
| 501 | // Show only when the user is a member of this site, or they're a super admin. |
| 502 | if ( ! is_user_member_of_blog() && ! is_super_admin() ) { |
| 503 | return; |
| 504 | } |
| 505 | |
| 506 | // Don't display when shop page is the same of the page on front. |
| 507 | if ( intval( get_option( 'page_on_front' ) ) === wc_get_page_id( 'shop' ) ) { |
| 508 | return; |
| 509 | } |
| 510 | |
| 511 | // Add an option to visit the store. |
| 512 | $wp_admin_bar->add_node( |
| 513 | array( |
| 514 | 'parent' => 'site-name', |
| 515 | 'id' => 'view-store', |
| 516 | 'title' => __( 'Visit Store', 'woocommerce' ), |
| 517 | 'href' => wc_get_page_permalink( 'shop' ), |
| 518 | ) |
| 519 | ); |
| 520 | } |
| 521 | |
| 522 | /** |
| 523 | * Hide the submenu page based on slug and return the item that was hidden. |
| 524 | * |
| 525 | * Borrowed from Jetpack's Base_Admin_Menu class. |
| 526 | * |
| 527 | * Instead of actually removing the submenu item, a safer approach is to hide it and filter it in the API response. |
| 528 | * In this manner we'll avoid breaking third-party plugins depending on items that no longer exist. |
| 529 | * |
| 530 | * A false|array value is returned to be consistent with remove_submenu_page() function |
| 531 | * |
| 532 | * @param string $menu_slug The parent menu slug. |
| 533 | * @param string $submenu_slug The submenu slug that should be hidden. |
| 534 | * @return false|array |
| 535 | */ |
| 536 | public function hide_submenu_page( $menu_slug, $submenu_slug ) { |
| 537 | global $submenu; |
| 538 | |
| 539 | if ( ! isset( $submenu[ $menu_slug ] ) ) { |
| 540 | return false; |
| 541 | } |
| 542 | |
| 543 | foreach ( $submenu[ $menu_slug ] as $i => $item ) { |
| 544 | if ( $submenu_slug !== $item[2] ) { |
| 545 | continue; |
| 546 | } |
| 547 | |
| 548 | $this->hide_submenu_element( $i, $menu_slug, $item ); |
| 549 | |
| 550 | return $item; |
| 551 | } |
| 552 | |
| 553 | return false; |
| 554 | } |
| 555 | |
| 556 | /** |
| 557 | * Apply the hide-if-js CSS class to a submenu item. |
| 558 | * |
| 559 | * Borrowed from Jetpack's Base_Admin_Menu class. |
| 560 | * |
| 561 | * @param int $index The position of a submenu item in the submenu array. |
| 562 | * @param string $parent_slug The parent slug. |
| 563 | * @param array $item The submenu item. |
| 564 | * @return void |
| 565 | */ |
| 566 | public function hide_submenu_element( $index, $parent_slug, $item ) { |
| 567 | global $submenu; |
| 568 | |
| 569 | $css_classes = empty( $item[4] ) ? self::HIDE_CSS_CLASS : $item[4] . ' ' . self::HIDE_CSS_CLASS; |
| 570 | |
| 571 | // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 572 | $submenu [ $parent_slug ][ $index ][4] = $css_classes; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | return new WC_Admin_Menus(); |
| 577 |