forked from OpenWebconcept/plugin-openwoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat): implement setting for configuring a fileserver URL
- Loading branch information
Mike van den Hoek
committed
Jan 12, 2024
1 parent
766dec8
commit a225813
Showing
7 changed files
with
133 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
return [ | ||
'openwoo-base' => [ | ||
'id' => '_owc_openwoo_base_settings', | ||
'title' => __('OpenWOO instellingen', 'openwoo'), | ||
'object_types' => ['options-page'], | ||
'option_key' => '_owc_openwoo_base_settings', | ||
'tab_group' => 'openwoo-base', | ||
'tab_title' => __('Algemeen', 'openwoo'), | ||
'position' => 30, | ||
'icon_url' => 'dashicons-admin-settings', | ||
'fields' => [ | ||
'fileserver_title' => [ | ||
'name' => __('Fileserver', 'openwoo'), | ||
'desc' => __('Een eigen implementatie in een plug-in of thema is vereist voor het gebruik van een fileserver, deze plug-in biedt deze instellingen pagina aan waarmee je instellingen kunt gebruiken op elke gewenste plek.', 'openwoo'), | ||
'id' => 'openwoo_setting_fileserver_title', | ||
'type' => 'title', | ||
], | ||
'fileserver_url' => [ | ||
'name' => __('Fileserver URL', 'openwoo'), | ||
'desc' => __('URL met http(s)://', 'openwoo'), | ||
'id' => 'openwoo_setting_file_server_url', | ||
'type' => 'text', | ||
], | ||
], | ||
], | ||
]; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Yard\OpenWOO\Settings; | ||
|
||
class Settings | ||
{ | ||
/** | ||
* Settings defined on settings page | ||
*/ | ||
protected array $settings; | ||
|
||
public function __construct(array $settings) | ||
{ | ||
$this->settings = $settings; | ||
} | ||
|
||
public function getFileServerURL(): string | ||
{ | ||
return $this->settings['_owc_openwoo_setting_file_server_url'] ?? ''; | ||
} | ||
|
||
public static function make(): self | ||
{ | ||
$defaultSettings = [ | ||
'_owc_openwoo_setting_file_server_url' => '', | ||
]; | ||
|
||
return new static(wp_parse_args(\get_option('_owc_openwoo_base_settings'), $defaultSettings)); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace Yard\OpenWOO\Settings; | ||
|
||
use CMB2; | ||
use Yard\OpenWOO\Foundation\ServiceProvider; | ||
|
||
class SettingsServiceProvider extends ServiceProvider | ||
{ | ||
const PREFIX = '_owc_'; | ||
|
||
public function register() | ||
{ | ||
$this->plugin->loader->addAction('cmb2_admin_init', $this, 'registerSettingsPages', 10, 0); | ||
} | ||
|
||
public function registerSettingsPages(): void | ||
{ | ||
$settingsPages = $this->plugin->config->get('settings_pages'); | ||
|
||
if (! is_array($settingsPages)) { | ||
return; | ||
} | ||
|
||
foreach ($settingsPages as $page) { | ||
if (! is_array($page)) { | ||
continue; | ||
} | ||
|
||
$this->registerSettingsPage($page); | ||
} | ||
} | ||
|
||
protected function registerSettingsPage(array $page): void | ||
{ | ||
$fields = $page['fields'] ?? []; | ||
unset($page['fields']); // Fields will be added later on. | ||
|
||
$optionsPage = \new_cmb2_box($page); | ||
|
||
if (empty($fields) || ! is_array($fields)) { | ||
return; | ||
} | ||
|
||
$this->registerSettingsPageFields($optionsPage, $fields); | ||
} | ||
|
||
protected function registerSettingsPageFields(CMB2 $optionsPage, array $fields) | ||
{ | ||
foreach ($fields as $field) { | ||
if (! is_array($field)) { | ||
continue; | ||
} | ||
|
||
if (isset($field['id'])) { | ||
$field['id'] = self::PREFIX . $field['id']; | ||
} | ||
|
||
$optionsPage->add_field($field); | ||
} | ||
} | ||
} |