| 1 |
<?php |
| 2 |
/** |
| 3 |
* The plugin settings. |
| 4 |
* |
| 5 |
* @since 1.4.0 |
| 6 |
* |
| 7 |
* @package woo-additional-terms |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace Woo_Additional_Terms\Settings; |
| 11 |
|
| 12 |
use WC_Settings_Page; |
| 13 |
use Woo_Additional_Terms\Helper; |
| 14 |
|
| 15 |
/** |
| 16 |
* Class Settings. |
| 17 |
*/ |
| 18 |
class Settings extends WC_Settings_Page { |
| 19 |
|
| 20 |
/** |
| 21 |
* Setup settings class. |
| 22 |
* |
| 23 |
* @since 1.4.0 |
| 24 |
* |
| 25 |
* @return void |
| 26 |
*/ |
| 27 |
public function __construct() { |
| 28 |
|
| 29 |
$this->assign(); |
| 30 |
$this->setup(); |
| 31 |
$this->enqueue(); |
| 32 |
|
| 33 |
parent::__construct(); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Assign the settings properties. |
| 38 |
* |
| 39 |
* @since 1.4.0 |
| 40 |
* |
| 41 |
* @return void |
| 42 |
*/ |
| 43 |
private function assign() { |
| 44 |
|
| 45 |
$this->id = sanitize_key( woo_additional_terms()->get_slug() ); |
| 46 |
$this->label = _x( 'Additional Terms', 'settings tab label', 'woo-additional-terms' ); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Setup hooks and filters. |
| 51 |
* |
| 52 |
* @since 1.4.0 |
| 53 |
* |
| 54 |
* @return void |
| 55 |
*/ |
| 56 |
public function setup() { |
| 57 |
|
| 58 |
add_filter( 'admin_body_class', array( $this, 'add_body_class' ) ); |
| 59 |
add_action( "woocommerce_settings_{$this->id}", array( $this, 'sidebar' ) ); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Add plugin specific class to body. |
| 64 |
* |
| 65 |
* @since 1.4.0 |
| 66 |
* |
| 67 |
* @param string $classes Classes to be added to the body element. |
| 68 |
* |
| 69 |
* @return string |
| 70 |
*/ |
| 71 |
public function add_body_class( $classes ) { |
| 72 |
|
| 73 |
// Bail early if the current page is not the settings page. |
| 74 |
if ( ! Helper\Settings::is_page() ) { |
| 75 |
return $classes; |
| 76 |
} |
| 77 |
|
| 78 |
$classes .= sprintf( ' %s-page', sanitize_html_class( $this->id ) ); |
| 79 |
|
| 80 |
return $classes; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Display the sidebar. |
| 85 |
* |
| 86 |
* @since 1.4.0 |
| 87 |
* |
| 88 |
* @return void |
| 89 |
*/ |
| 90 |
public function sidebar() { |
| 91 |
|
| 92 |
woo_additional_terms()->service( 'template_manager' )->echo_template( |
| 93 |
'sidebar/sidebar.php' |
| 94 |
); |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Enqueue the settings assets. |
| 99 |
* |
| 100 |
* @since 1.4.0 |
| 101 |
* |
| 102 |
* @return void |
| 103 |
*/ |
| 104 |
private function enqueue() { |
| 105 |
|
| 106 |
// Bail early if the current page is not the settings page. |
| 107 |
if ( ! Helper\Settings::is_page() ) { |
| 108 |
return; |
| 109 |
} |
| 110 |
|
| 111 |
// Enqueue the settings assets. |
| 112 |
wp_enqueue_style( 'woo-additional-terms-admin' ); |
| 113 |
wp_enqueue_script( 'woo-additional-terms-admin' ); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Get own sections. |
| 118 |
* |
| 119 |
* @since 1.6.0 |
| 120 |
* |
| 121 |
* @return array |
| 122 |
*/ |
| 123 |
protected function get_own_sections() { |
| 124 |
|
| 125 |
return array( |
| 126 |
'' => _x( 'General', 'settings tab', 'woo-additional-terms' ), |
| 127 |
); |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Get settings array. |
| 132 |
* |
| 133 |
* @since 1.4.0 |
| 134 |
* |
| 135 |
* @return array |
| 136 |
*/ |
| 137 |
protected function get_settings_for_default_section() { |
| 138 |
|
| 139 |
return woo_additional_terms()->service( 'settings_general' )->get_fields(); |
| 140 |
} |
| 141 |
} |
| 142 |
|