Skip to content

Commit 663e0a1

Browse files
author
Guido W. Pettinari
committed
✨ Filters idearia_settings_api_filter_fields and sections
1 parent 8ad9f13 commit 663e0a1

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ExampleSettingsPage extends SettingsPage
5858

5959
protected $slug = 'example-settings-page';
6060

61-
public function getSections()
61+
protected function getSections()
6262
{
6363
return array(
6464
array(
@@ -72,7 +72,7 @@ class ExampleSettingsPage extends SettingsPage
7272
);
7373
}
7474

75-
public function getFields()
75+
protected function getFields()
7676
{
7777
return array(
7878
'wedevs_basics' => array(

src/SettingsPage.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public function __construct() {
7474
*/
7575
private function set_write_capabilities() {
7676
$sections = $this->getSections();
77+
$sections = apply_filters( 'idearia_settings_api_filter_sections', $sections, $this->slug, $this );
7778
$sections_ids = array_column( $sections, 'id' );
7879
foreach ( $sections_ids as $option_page ) {
7980
add_filter(
@@ -89,11 +90,15 @@ function( $cap ) {
8990
* Callback che registra tutti i nostri settings usando l'API
9091
*/
9192
public function admin_init() {
92-
$this->api->set_sections( $this->getSections() );
93-
// Se non siamo sulla pagina specifica della sezione,
93+
$sections = $this->getSections();
94+
$sections = apply_filters( 'idearia_settings_api_filter_sections', $sections, $this->slug, $this );
95+
$this->api->set_sections( $sections );
96+
// Se non siamo sulla pagina specifica della sezione,
9497
// non serve calcolare tutti i campi
9598
if ( ( $_GET[ 'page' ] ?? '' ) === $this->slug ) {
96-
$this->api->set_fields( $this->getFields() );
99+
$fields = $this->getFields();
100+
$fields = apply_filters( 'idearia_settings_api_filter_fields', $fields, $this->slug, $this );
101+
$this->api->set_fields( $fields );
97102
}
98103
$this->api->admin_init();
99104
}

0 commit comments

Comments
 (0)