| 1 |
<?php |
| 2 |
/** |
| 3 |
* Give Settings Page/Tab |
| 4 |
* |
| 5 |
* @package Give |
| 6 |
* @subpackage Classes/Give_Settings_Addon |
| 7 |
* @copyright Copyright (c) 2016, GiveWP |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 1.8 |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; // Exit if accessed directly |
| 14 |
} |
| 15 |
|
| 16 |
if ( ! class_exists( 'Give_Settings_Addon' ) ) : |
| 17 |
|
| 18 |
/** |
| 19 |
* Give_Settings_Addon. |
| 20 |
* |
| 21 |
* @sine 1.8 |
| 22 |
*/ |
| 23 |
class Give_Settings_Addon extends Give_Settings_Page { |
| 24 |
/** |
| 25 |
* Constructor. |
| 26 |
*/ |
| 27 |
public function __construct() { |
| 28 |
$this->id = 'addons'; |
| 29 |
$this->label = esc_html__( 'Add-ons', 'give' ); |
| 30 |
|
| 31 |
parent::__construct(); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Default setting tab. |
| 36 |
* |
| 37 |
* @since 1.8 |
| 38 |
* @param $setting_tab |
| 39 |
* @return string |
| 40 |
*/ |
| 41 |
function set_default_setting_tab( $setting_tab ) { |
| 42 |
$default_tab = ''; |
| 43 |
|
| 44 |
// Set default tab to first setting tab. |
| 45 |
if ( $sections = array_keys( $this->get_sections() ) ) { |
| 46 |
$default_tab = current( $sections ); |
| 47 |
} |
| 48 |
return $default_tab; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Add this page to settings. |
| 53 |
* |
| 54 |
* @since 1.8 |
| 55 |
* @param array $pages Lst of pages. |
| 56 |
* @return array |
| 57 |
*/ |
| 58 |
public function add_settings_page( $pages ) { |
| 59 |
$sections = $this->get_sections(); |
| 60 |
|
| 61 |
// Bailout: Do not add addons setting tab if it does not contain any setting fields. |
| 62 |
if ( ! empty( $sections ) ) { |
| 63 |
$pages[ $this->id ] = $this->label; |
| 64 |
} |
| 65 |
|
| 66 |
return $pages; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Get settings array. |
| 71 |
* |
| 72 |
* @since 1.8 |
| 73 |
* @return array |
| 74 |
*/ |
| 75 |
public function get_settings() { |
| 76 |
$settings = array(); |
| 77 |
|
| 78 |
/** |
| 79 |
* Filter the addons settings. |
| 80 |
* Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8 |
| 81 |
*/ |
| 82 |
$settings = apply_filters( 'give_settings_addons', $settings ); |
| 83 |
|
| 84 |
/** |
| 85 |
* Filter the settings. |
| 86 |
* |
| 87 |
* @since 1.8 |
| 88 |
* @param array $settings |
| 89 |
*/ |
| 90 |
$settings = apply_filters( 'give_get_settings_' . $this->id, $settings ); |
| 91 |
|
| 92 |
// Output. |
| 93 |
return $settings; |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
endif; |
| 98 |
|
| 99 |
return new Give_Settings_Addon(); |
| 100 |
|