Settings.php
1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace Favorites\Config;
use Favorites\Config\SettingsRepository;
use Favorites\Entities\PostType\PostTypeRepository;
use Favorites\Helpers;
/**
* Plugin Settings
*/
class Settings
{
/**
* Plugin Name
*/
private $plugin_name;
/**
* Settings Repository
*/
private $settings_repo;
/**
* Post Type Repository
*/
private $post_type_repo;
public function __construct()
{
$this->settings_repo = new SettingsRepository;
$this->post_type_repo = new PostTypeRepository;
$this->setName();
add_action( 'admin_init', [$this, 'registerSettings']);
add_action( 'admin_menu', [$this, 'registerSettingsPage']);
}
/**
* Set the plugin name
*/
private function setName()
{
global $favorites_name;
$this->plugin_name = $favorites_name;
}
/**
* Register the settings page
*/
public function registerSettingsPage()
{
add_options_page(
$this->plugin_name . ' ' . __('Settings', 'favorites'),
$this->plugin_name,
'manage_options',
'simple-favorites',
[$this, 'settingsPage']
);
}
/**
* Display the Settings Page
*/
public function settingsPage()
{
$tab = ( isset($_GET['tab']) ) ? sanitize_text_field($_GET['tab']) : 'general';
include( Helpers::view('settings/settings') );
}
/**
* Register the settings
*/
public function registerSettings()
{
register_setting( 'simple-favorites-general', 'simplefavorites_dependencies' );
register_setting( 'simple-favorites-general', 'simplefavorites_cache_enabled' );
register_setting( 'simple-favorites-general', 'simplefavorites_dev_mode');
register_setting( 'simple-favorites-users', 'simplefavorites_users' );
register_setting( 'simple-favorites-display', 'simplefavorites_display' );
}
}