PluginProbe
BeyondWords – AI audio for publishers / 4.2.4
BeyondWords – AI audio for publishers v4.2.4
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 4.7.0 All 43 releases
speechkit / src / Component / Settings / ApiKey / ApiKey.php

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

100 lines 1.9 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 <stu@beyondwords.io>
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 * Constructor
24 */
25 public function __construct()
26 {
27 add_action('admin_init', array($this, 'init'));
28 }
29
30 /**
31 * Init setting.
32 *
33 * @since 3.0.0
34 *
35 * @return void
36 */
37 public function init()
38 {
39 register_setting(
40 'beyondwords',
41 'beyondwords_api_key',
42 [
43 'default' => '',
44 'sanitize_callback' => array($this, 'sanitize'),
45 ]
46 );
47
48 add_settings_field(
49 'beyondwords-api-key',
50 __('BeyondWords API key', 'speechkit'),
51 array($this, 'render'),
52 'beyondwords',
53 'basic'
54 );
55 }
56
57 /**
58 * Render setting field.
59 *
60 * @since 3.0.0
61 *
62 * @return void
63 **/
64 public function render()
65 {
66 $api_key = get_option('beyondwords_api_key');
67 ?>
68 <input
69 type="text"
70 name="beyondwords_api_key"
71 value="<?php echo esc_attr($api_key); ?>"
72 size="50"
73 />
74 <?php
75 }
76
77 /**
78 * Sanitise the setting value.
79 *
80 * @since 3.0.0
81 * @param array $value The submitted value.
82 *
83 * @return void
84 **/
85 public function sanitize($value)
86 {
87 $errors = get_transient('beyondwords_settings_errors', []);
88
89 if (empty($value)) {
90 $errors['Settings/ApiKey'] = __(
91 'Please enter the BeyondWords API key. This can be found in your project settings.',
92 'speechkit'
93 );
94 set_transient('beyondwords_settings_errors', $errors);
95 }
96
97 return $value;
98 }
99 }
100