PluginProbe
BeyondWords – AI audio for publishers / 4.0.6
BeyondWords – AI audio for publishers v4.0.6
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 / ProjectId / ProjectId.php

ProjectId.php in BeyondWords – AI audio for publishers 4.0.6, at src/Component/Settings/ProjectId/ProjectId.php

100 lines 2.0 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: Project ID
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\ProjectId;
14
15 /**
16 * ProjectId setup
17 *
18 * @since 3.0.0
19 */
20 class ProjectId
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_project_id',
42 [
43 'default' => '',
44 'sanitize_callback' => array($this, 'sanitize'),
45 ]
46 );
47
48 add_settings_field(
49 'beyondwords-project-id',
50 __('BeyondWords project ID', '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 $project_id = get_option('beyondwords_project_id');
67 ?>
68 <input
69 type="text"
70 name="beyondwords_project_id"
71 value="<?php echo esc_attr($project_id); ?>"
72 size="10"
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/ProjectId'] = __(
91 'Please enter your BeyondWords project ID. 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