forked from ptz0n/wordpress-google-cse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.php
104 lines (94 loc) · 3.59 KB
/
admin.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
<?php
/**
* Admin Init
*
* @since 1.0
*
*/
function gcse_admin_init()
{
register_setting('gcse_options', 'gcse_options');
}
add_action('admin_init', 'gcse_admin_init');
/**
* Add Options Page Link to Admin
*
* @since 1.0
*
* @uses add_options_page
*
* @return void
*/
function gcse_options_page_link()
{
if (function_exists('add_options_page')) {
add_options_page(
__('Google CSE'),
__('Google CSE'),
'manage_options',
'google-cse-options',
'gcse_options_page');
}
}
add_action('admin_menu', 'gcse_options_page_link');
/**
* Options page
*
* @since 1.0
*
* @return output
*/
function gcse_options_page()
{
$options = get_option('gcse_options');
$response = gcse_request();
$errors = array(
'keyInvalid' => __('Invalid API key.'),
'invalid' => __('Invalid Custom Search Engine ID.'),
'accessNotConfigured' => __('"Custom Search API" service isn\'t enabled in the APIs Console.'));
if($response && isset($response['error'])) {
$reason = $response['error']['errors'][0]['reason'];
$error = array_key_exists($reason, $errors) ? $errors[$reason] : $reason;
}
preg_match('/^[0-9]+\.?[0-9]+/', get_bloginfo('version'), $versionCheck);
?>
<div class="wrap">
<div id="icon-options-general" class="icon32"></div>
<h2><?php _e('Google Custom Search Engine Settings'); ?></h2>
<?php if($versionCheck && $versionCheck[0] < 3.3) : ?>
<div class="error below-h2">
<p><strong><?php _e('ERROR'); ?></strong>: <?php _e('You are running a to old version of WordPress. This plugin requires at least 3.3.'); ?>
</div>
<?php endif; ?>
<?php if($error) : ?>
<div class="error below-h2">
<p><strong><?php _e('ERROR'); ?></strong>: <?php echo $error; ?></p>
</div>
<?php endif; ?>
<div class="narrow">
<form action="options.php" method="post">
<?php settings_fields('gcse_options'); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><label for="gcse_options[key]">Google API key</label></th>
<td>
<input type="text" size="50" id="gcse_options[key]" name="gcse_options[key]" value="<?php echo isset($options['key']) ? $options['key'] : ''; ?>" /><br />
<span class="description">Enable the Custom Search API and get your API key at <a href="https://code.google.com/apis/console/" title="Google APIs Console" target="_blank" />Google APIs Console</a>.</span>
</td>
</tr>
<tr valign="top">
<th scope="row"><label for="gcse_options[id]">Google Custom Search Engine</label></th>
<td>
<input type="text" size="50" id="gcse_options[id]" name="gcse_options[id]" value="<?php echo isset($options['id']) ? $options['id'] : ''; ?>" />
<span class="description">Search engine ID (CX)<br />Visit <a href="http://www.google.com/cse/">Google Custom Search Engine</a> to create or manage your existing search engines.</span>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Settings') ?>" />
</p>
</form>
</div>
</div>
<?php
}