Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save paulmiller3000/7351882a2bb225157e2b661466f9edae to your computer and use it in GitHub Desktop.
Save paulmiller3000/7351882a2bb225157e2b661466f9edae to your computer and use it in GitHub Desktop.
<?php
/**
* Extends the WC_Settings_Page class
*
* @link https://paulmiller3000.com
* @since 1.0.0
*
* @package P3k_Galactica
* @subpackage P3k_Galactica/admin
*
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'P3k_Galactica_WC_Settings' ) ) {
/**
* Settings class
*
* @since 1.0.0
*/
class P3k_Galactica_WC_Settings extends WC_Settings_Page {
/**
* Constructor
* @since 1.0
*/
public function __construct() {
$this->id = 'p3k-galactica';
$this->label = __( 'Galactica', 'p3k-galactica' );
// Define all hooks instead of inheriting from parent
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) );
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Get sections.
*
* @return array
*/
public function get_sections() {
$sections = array(
'' => __( 'Settings', 'p3k-galactica' ),
'log' => __( 'Log', 'p3k-galactica' )
);
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
}
/**
* Get settings array
*
* @return array
*/
public function get_settings() {
global $current_section;
$prefix = 'p3k_galactica_';
switch ($current_section) {
case 'log':
$settings = array(
array()
);
break;
default:
$settings = array(
array()
);
}
return apply_filters( 'woocommerce_get_settings_' . $this->id, $settings, $current_section );
}
/**
* Output the settings
*/
public function output() {
$settings = $this->get_settings();
WC_Admin_Settings::output_fields( $settings );
}
/**
* Save settings
*
* @since 1.0
*/
public function save() {
$settings = $this->get_settings();
WC_Admin_Settings::save_fields( $settings );
}
}
}
return new P3k_Galactica_WC_Settings();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment