説明なし

class-wc-admin-customize.php 2.5KB

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