-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustomeralliance-reviews.php
169 lines (149 loc) · 4.3 KB
/
customeralliance-reviews.php
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/*
Plugin Name: Customer Alliance Reviews
Plugin URI: http://www.customer-alliance.com/
Description: Display customer alliance reviews on your page
Version: 0.2.0
Author: Thomas Horster
Author URI: http://thomashorster.de
License: GNU gpl 3.0
License URI: http://choosealicense.com/licenses/gpl-3.0/
Domain Path: /languages
Text Domain: ca-reviews
copyright 2015 Thomas Horster
all rights reserved
*/
defined('ABSPATH') or die('No script kiddies please!');
//add styles and so on
require_once(plugin_dir_path(__FILE__) . 'reviews/review-functions.php');
class CASettingsPage
{
/**
* Holds the values to be used in the fields callbacks
*/
private $options;
/**
* Start up
*/
public function __construct()
{
add_action('admin_menu', array($this, 'add_plugin_page'));
add_action('admin_init', array($this, 'page_init'));
add_action('init', array($this, 'load_translation'));
}
public function load_translation()
{
load_plugin_textdomain('ca-reviews', FALSE, dirname(plugin_basename(__FILE__)).'/languages/');
}
/**
* Add options page
*/
public function add_plugin_page()
{
// This page will be under "Settings"
add_options_page(
'CA-Reviews',
'CA-Reviews',
'manage_options',
'ca-settings-admin',
array($this, 'create_admin_page')
);
}
/**
* Options page callback
*/
public function create_admin_page()
{
// Set class property
$this->options = get_option('ca_reviews');
?>
<div class="wrap">
<h2>CA-Reviews</h2>
<form method="post" action="options.php">
<?php
// This prints out all hidden setting fields
settings_fields('ca_option_group');
do_settings_sections('ca-settings-admin');
submit_button();
?>
</form>
</div>
<?php
}
/**
* Register and add settings
*/
public function page_init()
{
register_setting(
'ca_option_group', // Option group
'ca_reviews', // Option name
array($this, 'sanitize') // Sanitize
);
add_settings_section(
'setting_section_id', // ID
'CA-Reviews', // Title
array($this, 'print_section_info'), // Callback
'ca-settings-admin' // Page
);
add_settings_field(
'id_key', // ID
'Hotel ID', // Title
array($this, 'id_key_callback'), // Callback
'ca-settings-admin', // Page
'setting_section_id' // Section
);
add_settings_field(
'access_key',
'Access Key',
array($this, 'access_key_callback'),
'ca-settings-admin',
'setting_section_id'
);
}
/**
* Sanitize each setting field as needed
*
* @param array $input Contains all settings fields as array keys
* @return object
*/
public function sanitize($input)
{
$new_input = array();
if (isset($input['id_key']))
$new_input['id_key'] = sanitize_text_field($input['id_key']);
if (isset($input['access_key']))
$new_input['access_key'] = sanitize_text_field($input['access_key']);
return $new_input;
}
/**
* Print the Section text
*/
public function print_section_info()
{
print 'Geben Sie bitte die zugesendeten Daten an:';
}
/**
* Get the settings option array and print one of its values
*/
public function id_key_callback()
{
printf(
'<input type="text" id="id_key" name="ca_reviews[id_key]" value="%s" />',
isset($this->options['id_key']) ? esc_attr($this->options['id_key']) : ''
);
}
/**
* Get the settings option array and print one of its values
*/
public function access_key_callback()
{
printf(
'<input type="text" id="access_key" name="ca_reviews[access_key]" value="%s" />',
isset($this->options['access_key']) ? esc_attr($this->options['access_key']) : ''
);
}
}
if (is_admin()) {
$my_settings_page = new CASettingsPage();
}