Нет описания

class-wc-settings-integrations.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * WooCommerce Integration Settings
  4. *
  5. * @package WooCommerce\Admin
  6. * @version 2.1.0
  7. */
  8. use Automattic\Jetpack\Constants;
  9. defined( 'ABSPATH' ) || exit;
  10. if ( ! class_exists( 'WC_Settings_Integrations', false ) ) :
  11. /**
  12. * WC_Settings_Integrations.
  13. */
  14. class WC_Settings_Integrations extends WC_Settings_Page {
  15. /**
  16. * Constructor.
  17. */
  18. public function __construct() {
  19. $this->id = 'integration';
  20. $this->label = __( 'Integration', 'woocommerce' );
  21. if ( isset( WC()->integrations ) && WC()->integrations->get_integrations() ) {
  22. parent::__construct();
  23. }
  24. }
  25. /**
  26. * Get own sections.
  27. *
  28. * @return array
  29. */
  30. protected function get_own_sections() {
  31. global $current_section;
  32. $sections = array();
  33. if ( ! $this->wc_is_installing() ) {
  34. $integrations = $this->get_integrations();
  35. if ( ! $current_section && ! empty( $integrations ) ) {
  36. $current_section = current( $integrations )->id;
  37. }
  38. if ( count( $integrations ) > 1 ) {
  39. foreach ( $integrations as $integration ) {
  40. $title = empty( $integration->method_title ) ? ucfirst( $integration->id ) : $integration->method_title;
  41. $sections[ strtolower( $integration->id ) ] = esc_html( $title );
  42. }
  43. }
  44. }
  45. return $sections;
  46. }
  47. /**
  48. * Is WC_INSTALLING constant defined?
  49. * This method exists to ease unit testing.
  50. *
  51. * @return bool True is the WC_INSTALLING constant is defined.
  52. */
  53. protected function wc_is_installing() {
  54. return Constants::is_defined( 'WC_INSTALLING' );
  55. }
  56. /**
  57. * Get the currently available integrations.
  58. * This method exists to ease unit testing.
  59. *
  60. * @return array Currently available integrations.
  61. */
  62. protected function get_integrations() {
  63. return WC()->integrations->get_integrations();
  64. }
  65. /**
  66. * Output the settings.
  67. */
  68. public function output() {
  69. global $current_section;
  70. $integrations = $this->get_integrations();
  71. if ( isset( $integrations[ $current_section ] ) ) {
  72. $integrations[ $current_section ]->admin_options();
  73. }
  74. }
  75. }
  76. endif;
  77. return new WC_Settings_Integrations();