PluginProbe
BeyondWords – AI audio for publishers / 4.5.1
BeyondWords – AI audio for publishers v4.5.1
7.2.0 7.1.0 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 All 44 releases
speechkit / src / Component / Settings / ApiKey / ApiKey.php

ApiKey.php in BeyondWords – AI audio for publishers 4.5.1, at src/Component/Settings/ApiKey/ApiKey.php

113 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 /**
6 * Setting: API Key
7 *
8 * @package Beyondwords\Wordpress
9 * @author Stuart McAlpine <[email protected]>
10 * @since 3.0.0
11 */
12
13 namespace Beyondwords\Wordpress\Component\Settings\ApiKey;
14
15 /**
16 * ApiKey setup
17 *
18 * @since 3.0.0
19 */
20 class ApiKey
21 {
22 /**
23 * Init.
24 *
25 * @since 4.0.0
26 */
27 public function init()
28 {
29 add_action('admin_init', array($this, 'registerSetting'));
30 add_action('admin_init', array($this, 'addSettingsField'));
31 }
32
33 /**
34 * Init setting.
35 *
36 * @since 3.0.0
37 *
38 * @return void
39 */
40 public function registerSetting()
41 {
42 register_setting(
43 'beyondwords',
44 'beyondwords_api_key',
45 [
46 'default' => '',
47 'sanitize_callback' => array($this, 'sanitize'),
48 ]
49 );
50 }
51
52 /**
53 * Init setting.
54 *
55 * @since 3.0.0
56 *
57 * @return void
58 */
59 public function addSettingsField()
60 {
61 add_settings_field(
62 'beyondwords-api-key',
63 __('BeyondWords API key', 'speechkit'),
64 array($this, 'render'),
65 'beyondwords',
66 'basic'
67 );
68 }
69
70 /**
71 * Render setting field.
72 *
73 * @since 3.0.0
74 *
75 * @return void
76 **/
77 public function render()
78 {
79 $api_key = get_option('beyondwords_api_key');
80 ?>
81 <input
82 type="text"
83 name="beyondwords_api_key"
84 value="<?php echo esc_attr($api_key); ?>"
85 size="50"
86 />
87 <?php
88 }
89
90 /**
91 * Sanitise the setting value.
92 *
93 * @since 3.0.0
94 * @param array $value The submitted value.
95 *
96 * @return void
97 **/
98 public function sanitize($value)
99 {
100 $errors = get_transient('beyondwords_settings_errors', []);
101
102 if (empty($value)) {
103 $errors['Settings/ApiKey'] = __(
104 'Please enter the BeyondWords API key. This can be found in your project settings.',
105 'speechkit'
106 );
107 set_transient('beyondwords_settings_errors', $errors);
108 }
109
110 return $value;
111 }
112 }
113