2013-07-26 14:36:28 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WooCommerce Settings Page/Tab
|
|
|
|
*
|
2020-08-05 16:36:24 +00:00
|
|
|
* @package WooCommerce\Admin
|
2013-07-26 14:36:28 +00:00
|
|
|
* @version 2.1.0
|
|
|
|
*/
|
|
|
|
|
2014-09-20 19:55:47 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
2021-03-30 09:08:35 +00:00
|
|
|
exit; // Exit if accessed directly.
|
2014-09-20 19:55:47 +00:00
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2017-02-16 11:46:01 +00:00
|
|
|
if ( ! class_exists( 'WC_Settings_Page', false ) ) :
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2016-01-05 15:22:18 +00:00
|
|
|
/**
|
2018-03-05 18:59:17 +00:00
|
|
|
* WC_Settings_Page.
|
2016-01-05 15:22:18 +00:00
|
|
|
*/
|
2018-03-05 18:59:17 +00:00
|
|
|
abstract class WC_Settings_Page {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setting page id.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $id = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setting page label.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $label = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
|
|
|
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' ) );
|
|
|
|
}
|
2014-11-20 14:46:19 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
/**
|
|
|
|
* Get settings page ID.
|
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_id() {
|
|
|
|
return $this->id;
|
|
|
|
}
|
2016-03-28 19:04:26 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
/**
|
|
|
|
* Get settings page label.
|
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_label() {
|
|
|
|
return $this->label;
|
|
|
|
}
|
2016-03-28 19:04:26 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
/**
|
|
|
|
* Add this page to settings.
|
|
|
|
*
|
2021-03-30 09:08:35 +00:00
|
|
|
* @param array $pages The pages array to add this page to.
|
2018-03-05 18:59:17 +00:00
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function add_settings_page( $pages ) {
|
|
|
|
$pages[ $this->id ] = $this->label;
|
|
|
|
|
|
|
|
return $pages;
|
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
/**
|
|
|
|
* Get settings array.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_settings() {
|
|
|
|
return apply_filters( 'woocommerce_get_settings_' . $this->id, array() );
|
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
/**
|
|
|
|
* Get sections.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_sections() {
|
|
|
|
return apply_filters( 'woocommerce_get_sections_' . $this->id, array() );
|
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
/**
|
|
|
|
* Output sections.
|
|
|
|
*/
|
|
|
|
public function output_sections() {
|
|
|
|
global $current_section;
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
$sections = $this->get_sections();
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2021-03-30 09:08:35 +00:00
|
|
|
if ( empty( $sections ) || 1 === count( $sections ) ) {
|
2018-03-05 18:59:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
echo '<ul class="subsubsub">';
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
$array_keys = array_keys( $sections );
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
foreach ( $sections as $id => $label ) {
|
2021-03-30 09:08:35 +00:00
|
|
|
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
|
|
|
echo '<li><a href="' . admin_url( 'admin.php?page=wc-settings&tab=' . $this->id . '§ion=' . sanitize_title( $id ) ) . '" class="' . ( $current_section === $id ? 'current' : '' ) . '">' . esc_html( $label ) . '</a> ' . ( end( $array_keys ) === $id ? '' : '|' ) . ' </li>';
|
2018-03-05 18:59:17 +00:00
|
|
|
}
|
2013-08-07 14:15:53 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
echo '</ul><br class="clear" />';
|
2014-08-31 08:22:03 +00:00
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
/**
|
|
|
|
* Output the settings.
|
|
|
|
*/
|
|
|
|
public function output() {
|
|
|
|
$settings = $this->get_settings();
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
WC_Admin_Settings::output_fields( $settings );
|
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
/**
|
|
|
|
* Save settings.
|
|
|
|
*/
|
|
|
|
public function save() {
|
|
|
|
global $current_section;
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
$settings = $this->get_settings();
|
|
|
|
WC_Admin_Settings::save_fields( $settings );
|
2013-07-26 14:36:28 +00:00
|
|
|
|
2018-03-05 18:59:17 +00:00
|
|
|
if ( $current_section ) {
|
|
|
|
do_action( 'woocommerce_update_options_' . $this->id . '_' . $current_section );
|
|
|
|
}
|
2014-08-31 08:22:03 +00:00
|
|
|
}
|
2013-07-26 14:36:28 +00:00
|
|
|
}
|
|
|
|
|
2014-08-31 08:22:03 +00:00
|
|
|
endif;
|