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 / IncludeTitle / IncludeTitle.php

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

113 lines 2.5 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: IncludeTitle
7 *
8 * @package Beyondwords\Wordpress
9 * @author Stuart McAlpine <stu@beyondwords.io>
10 * @since 5.0.0
11 */
12
13 namespace Beyondwords\Wordpress\Component\Settings\Fields\IncludeTitle;
14
15 use Beyondwords\Wordpress\Component\Settings\Sync;
16
17 /**
18 * IncludeTitle
19 *
20 * @since 5.0.0
21 */
22 defined('ABSPATH') || exit;
23
24 class IncludeTitle
25 {
26 /**
27 * Default value.
28 *
29 * @var string
30 */
31 public const DEFAULT_VALUE = true;
32
33 /**
34 * Option name.
35 *
36 * @var string
37 */
38 public const OPTION_NAME = 'beyondwords_project_title_enabled';
39
40 /**
41 * Init.
42 *
43 * @since 5.0.0
44 * @since 6.0.0 Make static.
45 */
46 public static function init()
47 {
48 add_action('admin_init', [self::class, 'addSetting']);
49 add_action('pre_update_option_' . self::OPTION_NAME, function ($value) {
50 Sync::syncOptionToDashboard(self::OPTION_NAME);
51 return $value;
52 });
53 add_filter('option_' . self::OPTION_NAME, 'rest_sanitize_boolean');
54 }
55
56 /**
57 * Init setting.
58 *
59 * @since 5.0.0
60 * @since 6.0.0 Make static.
61 *
62 * @return void
63 */
64 public static function addSetting()
65 {
66 register_setting(
67 'beyondwords_content_settings',
68 self::OPTION_NAME,
69 [
70 'type' => 'boolean',
71 'sanitize_callback' => 'rest_sanitize_boolean',
72 'default' => self::DEFAULT_VALUE,
73 ]
74 );
75
76 add_settings_field(
77 'beyondwords-include-title',
78 __('Title', 'speechkit'),
79 [self::class, 'render'],
80 'beyondwords_content',
81 'content'
82 );
83 }
84
85 /**
86 * Render setting field.
87 *
88 * @since 5.0.0
89 * @since 6.0.0 Make static.
90 *
91 * @return void
92 **/
93 public static function render()
94 {
95 $value = get_option(self::OPTION_NAME);
96 ?>
97 <div>
98 <label>
99 <input type="hidden" name="<?php echo esc_attr(self::OPTION_NAME); ?>" value="" />
100 <input
101 type="checkbox"
102 id="<?php echo esc_attr(self::OPTION_NAME); ?>"
103 name="<?php echo esc_attr(self::OPTION_NAME); ?>"
104 value="1"
105 <?php checked($value); ?>
106 />
107 <?php esc_html_e('Include title in audio', 'speechkit'); ?>
108 </label>
109 </div>
110 <?php
111 }
112 }
113