class-wc-admin-customize.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Setup customize items.
  4. *
  5. * @author WooCommerce
  6. * @category Admin
  7. * @package WooCommerce/Admin/Customize
  8. * @version 3.1.0
  9. */
  10. if ( ! defined( 'ABSPATH' ) ) {
  11. exit;
  12. }
  13. if ( ! class_exists( 'WC_Admin_Customize', false ) ) :
  14. /**
  15. * WC_Admin_Customize Class.
  16. */
  17. class WC_Admin_Customize {
  18. /**
  19. * Initialize customize actions.
  20. */
  21. public function __construct() {
  22. // Include custom items to customizer nav menu settings.
  23. add_filter( 'customize_nav_menu_available_item_types', array( $this, 'register_customize_nav_menu_item_types' ) );
  24. add_filter( 'customize_nav_menu_available_items', array( $this, 'register_customize_nav_menu_items' ), 10, 4 );
  25. }
  26. /**
  27. * Register customize new nav menu item types.
  28. * This will register WooCommerce account endpoints as a nav menu item type.
  29. *
  30. * @since 3.1.0
  31. * @param array $item_types Menu item types.
  32. * @return array
  33. */
  34. public function register_customize_nav_menu_item_types( $item_types ) {
  35. $item_types[] = array(
  36. 'title' => __( 'WooCommerce endpoints', 'woocommerce' ),
  37. 'type_label' => __( 'WooCommerce endpoint', 'woocommerce' ),
  38. 'type' => 'woocommerce_nav',
  39. 'object' => 'woocommerce_endpoint',
  40. );
  41. return $item_types;
  42. }
  43. /**
  44. * Register account endpoints to customize nav menu items.
  45. *
  46. * @since 3.1.0
  47. * @param array $items List of nav menu items.
  48. * @param string $type Nav menu type.
  49. * @param string $object Nav menu object.
  50. * @param integer $page Page number.
  51. * @return array
  52. */
  53. public function register_customize_nav_menu_items( $items = array(), $type = '', $object = '', $page = 0 ) {
  54. if ( 'woocommerce_endpoint' !== $object ) {
  55. return $items;
  56. }
  57. // Don't allow pagination since all items are loaded at once.
  58. if ( 0 < $page ) {
  59. return $items;
  60. }
  61. // Get items from account menu.
  62. $endpoints = wc_get_account_menu_items();
  63. // Remove dashboard item.
  64. if ( isset( $endpoints['dashboard'] ) ) {
  65. unset( $endpoints['dashboard'] );
  66. }
  67. // Include missing lost password.
  68. $endpoints['lost-password'] = __( 'Lost password', 'woocommerce' );
  69. $endpoints = apply_filters( 'woocommerce_custom_nav_menu_items', $endpoints );
  70. foreach ( $endpoints as $endpoint => $title ) {
  71. $items[] = array(
  72. 'id' => $endpoint,
  73. 'title' => $title,
  74. 'type_label' => __( 'Custom Link', 'woocommerce' ),
  75. 'url' => esc_url_raw( wc_get_account_endpoint_url( $endpoint ) ),
  76. );
  77. }
  78. return $items;
  79. }
  80. }
  81. endif;
  82. return new WC_Admin_Customize();