class-wc-settings-integrations.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * WooCommerce Integration Settings
  4. *
  5. * @author WooThemes
  6. * @category Admin
  7. * @package WooCommerce/Admin
  8. * @version 2.1.0
  9. */
  10. if ( ! defined( 'ABSPATH' ) ) {
  11. exit; // Exit if accessed directly
  12. }
  13. if ( ! class_exists( 'WC_Settings_Integrations', false ) ) :
  14. /**
  15. * WC_Settings_Integrations.
  16. */
  17. class WC_Settings_Integrations extends WC_Settings_Page {
  18. /**
  19. * Constructor.
  20. */
  21. public function __construct() {
  22. $this->id = 'integration';
  23. $this->label = __( 'Integration', 'woocommerce' );
  24. if ( isset( WC()->integrations ) && WC()->integrations->get_integrations() ) {
  25. parent::__construct();
  26. }
  27. }
  28. /**
  29. * Get sections.
  30. *
  31. * @return array
  32. */
  33. public function get_sections() {
  34. global $current_section;
  35. $sections = array();
  36. if ( ! defined( 'WC_INSTALLING' ) ) {
  37. $integrations = WC()->integrations->get_integrations();
  38. if ( ! $current_section && ! empty( $integrations ) ) {
  39. $current_section = current( $integrations )->id;
  40. }
  41. if ( sizeof( $integrations ) > 1 ) {
  42. foreach ( $integrations as $integration ) {
  43. $title = empty( $integration->method_title ) ? ucfirst( $integration->id ) : $integration->method_title;
  44. $sections[ strtolower( $integration->id ) ] = esc_html( $title );
  45. }
  46. }
  47. }
  48. return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
  49. }
  50. /**
  51. * Output the settings.
  52. */
  53. public function output() {
  54. global $current_section;
  55. $integrations = WC()->integrations->get_integrations();
  56. if ( isset( $integrations[ $current_section ] ) ) {
  57. $integrations[ $current_section ]->admin_options();
  58. }
  59. }
  60. }
  61. endif;
  62. return new WC_Settings_Integrations();