Created
February 17, 2019 17:17
-
-
Save Musilda/3b472f47b64985362afa49d58a31dfe1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class WC_Settings_Tab_Demo { | |
/** | |
* Bootstraps the class and hooks required actions & filters. | |
* | |
*/ | |
public static function init() { | |
add_filter( 'woocommerce_settings_tabs_array', __CLASS__ . '::add_settings_tab', 50 ); | |
add_action( 'woocommerce_settings_tabs_settings_tab_demo', __CLASS__ . '::settings_tab' ); | |
add_action( 'woocommerce_update_options_settings_tab_demo', __CLASS__ . '::update_settings' ); | |
} | |
/** | |
* Add a new settings tab to the WooCommerce settings tabs array. | |
* | |
* @param array $settings_tabs Array of WooCommerce setting tabs & their labels, excluding the Subscription tab. | |
* @return array $settings_tabs Array of WooCommerce setting tabs & their labels, including the Subscription tab. | |
*/ | |
public static function add_settings_tab( $settings_tabs ) { | |
$settings_tabs['settings_tab_demo'] = __( 'Settings Demo Tab', 'woocommerce-settings-tab-demo' ); | |
return $settings_tabs; | |
} | |
/** | |
* Uses the WooCommerce admin fields API to output settings via the @see woocommerce_admin_fields() function. | |
* | |
* @uses woocommerce_admin_fields() | |
* @uses self::get_settings() | |
*/ | |
public static function settings_tab() { | |
woocommerce_admin_fields( self::get_settings() ); | |
} | |
/** | |
* Uses the WooCommerce options API to save settings via the @see woocommerce_update_options() function. | |
* | |
* @uses woocommerce_update_options() | |
* @uses self::get_settings() | |
*/ | |
public static function update_settings() { | |
woocommerce_update_options( self::get_settings() ); | |
} | |
/** | |
* Get all the settings for this plugin for @see woocommerce_admin_fields() function. | |
* | |
* @return array Array of settings for @see woocommerce_admin_fields() function. | |
*/ | |
public static function get_settings() { | |
$settings = array( | |
'section_title' => array( | |
'name' => __( 'Section Title', 'woocommerce-settings-tab-demo' ), | |
'type' => 'title', | |
'desc' => '', | |
'id' => 'wc_settings_tab_demo_section_title' | |
), | |
'title' => array( | |
'name' => __( 'Title', 'woocommerce-settings-tab-demo' ), | |
'type' => 'text', | |
'desc' => __( 'This is some helper text', 'woocommerce-settings-tab-demo' ), | |
'id' => 'wc_settings_tab_demo_title' | |
), | |
'description' => array( | |
'name' => __( 'Description', 'woocommerce-settings-tab-demo' ), | |
'type' => 'textarea', | |
'desc' => __( 'This is a paragraph describing the setting. Lorem ipsum yadda yadda yadda. Lorem ipsum yadda yadda yadda. Lorem ipsum yadda yadda yadda. Lorem ipsum yadda yadda yadda.', 'woocommerce-settings-tab-demo' ), | |
'id' => 'wc_settings_tab_demo_description' | |
), | |
'section_end' => array( | |
'type' => 'sectionend', | |
'id' => 'wc_settings_tab_demo_section_end' | |
) | |
); | |
return apply_filters( 'wc_settings_tab_demo_settings', $settings ); | |
} | |
} | |
WC_Settings_Tab_Demo::init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment