PluginProbe
BeyondWords – AI audio for publishers / 6.3.0
BeyondWords – AI audio for publishers v6.3.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 4.7.0 All 43 releases
speechkit / src / Component / Settings / Fields / ApiKey / ApiKey.php

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

120 lines 2.4 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\Fields\ApiKey;
14
15 use Beyondwords\Wordpress\Component\Settings\SettingsUtils;
16
17 /**
18 * ApiKey
19 *
20 * @since 3.0.0
21 */
22 defined('ABSPATH') || exit;
23
24 class ApiKey
25 {
26 /**
27 * Option name.
28 *
29 * @since 5.0.0
30 */
31 public const OPTION_NAME = 'beyondwords_api_key';
32
33 /**
34 * Init.
35 *
36 * @since 4.0.0
37 * @since 6.0.0 Make static.
38 */
39 public static function init()
40 {
41 add_action('admin_init', [self::class, 'addSetting']);
42 }
43
44 /**
45 * Init setting.
46 *
47 * @since 3.0.0
48 * @since 6.0.0 Make static.
49 *
50 * @return void
51 */
52 public static function addSetting()
53 {
54 register_setting(
55 'beyondwords_credentials_settings',
56 self::OPTION_NAME,
57 [
58 'default' => '',
59 'sanitize_callback' => [self::class, 'sanitize'],
60 ]
61 );
62
63 add_settings_field(
64 'beyondwords-api-key',
65 __('API key', 'speechkit'),
66 [self::class, 'render'],
67 'beyondwords_credentials',
68 'credentials'
69 );
70 }
71
72 /**
73 * Render setting field.
74 *
75 * @since 3.0.0
76 * @since 6.0.0 Make static.
77 *
78 * @return void
79 **/
80 public static function render()
81 {
82 $value = get_option(self::OPTION_NAME);
83 ?>
84 <input
85 type="text"
86 id="<?php echo esc_attr(self::OPTION_NAME); ?>"
87 name="<?php echo esc_attr(self::OPTION_NAME); ?>"
88 value="<?php echo esc_attr($value); ?>"
89 size="50"
90 />
91 <?php
92 }
93
94 /**
95 * Sanitise the setting value.
96 *
97 * @since 3.0.0
98 * @since 5.2.0 Remove creds validation from here.
99 * @since 6.0.0 Make static.
100 *
101 * @param array $value The submitted value.
102 *
103 * @return void
104 **/
105 public static function sanitize($value)
106 {
107 if (empty($value)) {
108 SettingsUtils::addSettingsErrorMessage(
109 __(
110 'Please enter the BeyondWords API key. This can be found in your project settings.',
111 'speechkit'
112 ),
113 'Settings/ApiKey'
114 );
115 }
116
117 return $value;
118 }
119 }
120