PluginProbe
Borderless – Addons and Templates for Elementor / 1.7.3
Borderless – Addons and Templates for Elementor v1.7.3
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 All 78 releases
borderless / includes / admin / api-settings.php

api-settings.php in Borderless – Addons and Templates for Elementor 1.7.3, at includes/admin/api-settings.php

192 lines 8.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4
5 add_action('admin_menu', 'borderless_register_settings_pages');
6 add_action('admin_init', 'borderless_register_api_settings');
7
8 function borderless_register_settings_pages() {
9 add_menu_page(
10 'Global Settings',
11 'Global Settings',
12 'manage_options',
13 'borderless-global-settings',
14 'borderless_global_settings_page_callback',
15 'dashicons-admin-generic',
16 80
17 );
18
19 add_submenu_page(
20 null,
21 'Manage OpenAI',
22 'Manage OpenAI',
23 'manage_options',
24 'borderless-manage-openai',
25 'borderless_manage_openai_page_callback'
26 );
27
28 add_submenu_page(
29 null,
30 'Manage Google Gemini',
31 'Manage Google Gemini',
32 'manage_options',
33 'borderless-manage-google',
34 'borderless_manage_google_page_callback'
35 );
36 }
37
38 function borderless_register_api_settings() {
39 register_setting('borderless_openai_settings_group', 'borderless_openai_settings', 'borderless_sanitize_settings');
40 register_setting('borderless_google_settings_group', 'borderless_google_settings', 'borderless_sanitize_settings');
41
42 add_settings_section('openai_main', 'OpenAI Configuration', '__return_false', 'borderless-openai-settings');
43 add_settings_field('openai_api_key', 'API Key', 'borderless_openai_api_key_callback', 'borderless-openai-settings', 'openai_main');
44 add_settings_field('openai_model', 'Model', 'borderless_openai_model_callback', 'borderless-openai-settings', 'openai_main');
45 add_settings_field('openai_temperature', 'Temperature', 'borderless_openai_temperature_callback', 'borderless-openai-settings', 'openai_main');
46 add_settings_field('openai_enable', 'Enable API', 'borderless_openai_enable_callback', 'borderless-openai-settings', 'openai_main');
47
48 add_settings_section('google_main', 'Google Gemini Configuration', '__return_false', 'borderless-google-settings');
49 add_settings_field('google_api_key', 'API Key', 'borderless_google_api_key_callback', 'borderless-google-settings', 'google_main');
50 add_settings_field('google_model', 'Default Model', 'borderless_google_model_callback', 'borderless-google-settings', 'google_main');
51 add_settings_field('google_temperature', 'Temperature', 'borderless_google_temperature_callback', 'borderless-google-settings', 'google_main');
52 add_settings_field('google_enable', 'Enable API', 'borderless_google_enable_callback', 'borderless-google-settings', 'google_main');
53 }
54
55 function borderless_openai_api_key_callback() {
56 $options = get_option('borderless_openai_settings');
57 echo '<input type="text" name="borderless_openai_settings[openai_api_key]" value="' . esc_attr($options['openai_api_key'] ?? '') . '" size="50">';
58 }
59
60 function borderless_openai_model_callback() {
61 $options = get_option('borderless_openai_settings');
62 $current = $options['openai_model'] ?? 'gpt-4';
63 $models = [
64 'gpt-4' => 'GPT-4',
65 'gpt-4-turbo' => 'GPT-4 Turbo',
66 'gpt-4o' => 'GPT-4o',
67 'gpt-3.5-turbo' => 'GPT-3.5 Turbo',
68 'gpt-3.5-turbo-16k' => 'GPT-3.5 Turbo 16k'
69 ];
70 echo '<select name="borderless_openai_settings[openai_model]">';
71 foreach ($models as $value => $label) {
72 $selected = selected($current, $value, false);
73 echo "<option value=\"$value\" $selected>$label</option>";
74 }
75 echo '</select>';
76 }
77
78 function borderless_openai_temperature_callback() {
79 $options = get_option('borderless_openai_settings');
80 echo '<input type="number" step="0.1" min="0" max="1" name="borderless_openai_settings[openai_temperature]" value="' . esc_attr($options['openai_temperature'] ?? '0.7') . '" size="5">';
81 }
82
83 function borderless_openai_enable_callback() {
84 $options = get_option('borderless_openai_settings');
85 $checked = !empty($options['openai_enable']) ? 'checked' : '';
86 echo '<label><input type="checkbox" name="borderless_openai_settings[openai_enable]" value="1" ' . $checked . '> Enable</label>';
87 }
88
89 function borderless_google_api_key_callback() {
90 $options = get_option('borderless_google_settings');
91 echo '<input type="text" name="borderless_google_settings[google_api_key]" value="' . esc_attr($options['google_api_key'] ?? '') . '" size="50">';
92 }
93
94 function borderless_google_model_callback() {
95 $options = get_option('borderless_google_settings');
96 echo '<input type="text" name="borderless_google_settings[google_model]" value="' . esc_attr($options['google_model'] ?? 'gemini-pro') . '" size="20">';
97 }
98
99 function borderless_google_temperature_callback() {
100 $options = get_option('borderless_google_settings');
101 echo '<input type="number" step="0.1" min="0" max="1" name="borderless_google_settings[google_temperature]" value="' . esc_attr($options['google_temperature'] ?? '0.7') . '" size="5">';
102 }
103
104 function borderless_google_enable_callback() {
105 $options = get_option('borderless_google_settings');
106 $checked = !empty($options['google_enable']) ? 'checked' : '';
107 echo '<label><input type="checkbox" name="borderless_google_settings[google_enable]" value="1" ' . $checked . '> Enable</label>';
108 }
109
110 function borderless_sanitize_settings($input) {
111 $output = [];
112 foreach ($input as $key => $value) {
113 $output[$key] = is_string($value) ? sanitize_text_field($value) : $value;
114 }
115 return $output;
116 }
117
118 function borderless_global_settings_page_callback() {
119 $openai = get_option('borderless_openai_settings');
120 $google = get_option('borderless_google_settings');
121 $active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'integrations';
122 ?>
123 <div class="wrap">
124 <h1>Global Settings</h1>
125 <h2 class="nav-tab-wrapper">
126 <a href="?page=borderless-global-settings&tab=integrations" class="nav-tab <?php echo $active_tab == 'integrations' ? 'nav-tab-active' : ''; ?>">Integrations</a>
127 <a href="#" class="nav-tab disabled">Coming Soon</a>
128 </h2>
129
130 <?php if ($active_tab == 'integrations') : ?>
131 <table class="widefat fixed striped">
132 <thead>
133 <tr>
134 <th style="width: 30%;">App</th>
135 <th style="width: 40%;">Key</th>
136 <th style="width: 30%;">Action</th>
137 </tr>
138 </thead>
139 <tbody>
140 <tr>
141 <td>OpenAI</td>
142 <td><?php echo esc_html($openai['openai_api_key'] ?? ''); ?></td>
143 <td><a href="?page=borderless-manage-openai" class="button button-primary">Manage</a></td>
144 </tr>
145 <tr>
146 <td>Google Gemini</td>
147 <td><?php echo esc_html($google['google_api_key'] ?? ''); ?></td>
148 <td><a href="?page=borderless-manage-google" class="button button-primary">Manage</a></td>
149 </tr>
150 </tbody>
151 </table>
152 <?php endif; ?>
153 </div>
154 <?php
155 }
156
157 function borderless_manage_openai_page_callback() {
158 ?>
159 <div class="wrap">
160 <h1>Manage OpenAI</h1>
161 <form method="post" action="options.php">
162 <?php
163 settings_fields('borderless_openai_settings_group');
164 do_settings_sections('borderless-openai-settings');
165 ?>
166 <p class="submit">
167 <?php submit_button('Save Changes', 'primary', 'submit', false); ?>
168 <a href="?page=borderless-global-settings&tab=integrations" class="button"> Back to Integrations</a>
169 </p>
170 </form>
171 </div>
172 <?php
173 }
174
175 function borderless_manage_google_page_callback() {
176 ?>
177 <div class="wrap">
178 <h1>Manage Google Gemini</h1>
179 <form method="post" action="options.php">
180 <?php
181 settings_fields('borderless_google_settings_group');
182 do_settings_sections('borderless-google-settings');
183 ?>
184 <p class="submit">
185 <?php submit_button('Save Changes', 'primary', 'submit', false); ?>
186 <a href="?page=borderless-global-settings&tab=integrations" class="button"> Back to Integrations</a>
187 </p>
188 </form>
189 </div>
190 <?php
191 }
192