/includes/admin/settings/class-wc-settings-integrations.php

  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.  
  11. if ( ! defined( 'ABSPATH' ) ) { 
  12. exit; // Exit if accessed directly 
  13.  
  14. if ( ! class_exists( 'WC_Settings_Integrations', false ) ) : 
  15.  
  16. /** 
  17. * WC_Settings_Integrations. 
  18. */ 
  19. class WC_Settings_Integrations extends WC_Settings_Page { 
  20.  
  21. /** 
  22. * Constructor. 
  23. */ 
  24. public function __construct() { 
  25.  
  26. $this->id = 'integration'; 
  27. $this->label = __( 'Integration', 'woocommerce' ); 
  28.  
  29. if ( isset( WC()->integrations ) && WC()->integrations->get_integrations() ) { 
  30. add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 ); 
  31. add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) ); 
  32. add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) ); 
  33. add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) ); 
  34.  
  35. /** 
  36. * Get sections. 
  37. * 
  38. * @return array 
  39. */ 
  40. public function get_sections() { 
  41. global $current_section; 
  42.  
  43. $sections = array(); 
  44.  
  45. if ( ! defined( 'WC_INSTALLING' ) ) { 
  46. $integrations = WC()->integrations->get_integrations(); 
  47.  
  48. if ( ! $current_section && ! empty( $integrations ) ) { 
  49. $current_section = current( $integrations )->id; 
  50.  
  51. if ( sizeof( $integrations ) > 1 ) { 
  52. foreach ( $integrations as $integration ) { 
  53. $title = empty( $integration->method_title ) ? ucfirst( $integration->id ) : $integration->method_title; 
  54. $sections[ strtolower( $integration->id ) ] = esc_html( $title ); 
  55.  
  56. return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections ); 
  57.  
  58. /** 
  59. * Output the settings. 
  60. */ 
  61. public function output() { 
  62. global $current_section; 
  63.  
  64. $integrations = WC()->integrations->get_integrations(); 
  65.  
  66. if ( isset( $integrations[ $current_section ] ) ) 
  67. $integrations[ $current_section ]->admin_options(); 
  68.  
  69. endif; 
  70.  
  71. return new WC_Settings_Integrations(); 
.