| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
/** |
| 6 |
* Setting: Text highlighting |
| 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\PlaybackControls; |
| 14 |
|
| 15 |
use Beyondwords\Wordpress\Component\Settings\Sync; |
| 16 |
|
| 17 |
/** |
| 18 |
* PlaybackControls |
| 19 |
* |
| 20 |
* @since 5.0.0 |
| 21 |
*/ |
| 22 |
defined('ABSPATH') || exit; |
| 23 |
|
| 24 |
class PlaybackControls |
| 25 |
{ |
| 26 |
/** |
| 27 |
* Option name. |
| 28 |
*/ |
| 29 |
public const OPTION_NAME = 'beyondwords_player_skip_button_style'; |
| 30 |
|
| 31 |
/** |
| 32 |
* Player Settings docs URL. |
| 33 |
* |
| 34 |
* @var string |
| 35 |
*/ |
| 36 |
public const PLAYER_SETTINGS_DOCS_URL = 'https://github.com/beyondwords-io/player/blob/main/doc/player-settings.md'; |
| 37 |
|
| 38 |
/** |
| 39 |
* Init. |
| 40 |
* |
| 41 |
* @since 5.0.0 |
| 42 |
* @since 6.0.0 Make static. |
| 43 |
*/ |
| 44 |
public static function init() |
| 45 |
{ |
| 46 |
add_action('admin_init', [self::class, 'addSetting']); |
| 47 |
add_action('pre_update_option_' . self::OPTION_NAME, function ($value) { |
| 48 |
Sync::syncOptionToDashboard(self::OPTION_NAME); |
| 49 |
return $value; |
| 50 |
}); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Init setting. |
| 55 |
* |
| 56 |
* @since 5.0.0 |
| 57 |
* @since 6.0.0 Make static. |
| 58 |
* |
| 59 |
* @return void |
| 60 |
*/ |
| 61 |
public static function addSetting() |
| 62 |
{ |
| 63 |
register_setting( |
| 64 |
'beyondwords_player_settings', |
| 65 |
self::OPTION_NAME, |
| 66 |
[ |
| 67 |
'default' => '', |
| 68 |
] |
| 69 |
); |
| 70 |
|
| 71 |
add_settings_field( |
| 72 |
'beyondwords-player-skip-button-style', |
| 73 |
__('Skip button style', 'speechkit'), |
| 74 |
[self::class, 'render'], |
| 75 |
'beyondwords_player', |
| 76 |
'playback-controls' |
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Render setting field. |
| 82 |
* |
| 83 |
* @since 5.0.0 |
| 84 |
* @since 6.0.0 Make static. |
| 85 |
* |
| 86 |
* @return void |
| 87 |
**/ |
| 88 |
public static function render() |
| 89 |
{ |
| 90 |
$current = get_option(self::OPTION_NAME); |
| 91 |
?> |
| 92 |
<div class="beyondwords-setting__player-skip-button-style"> |
| 93 |
<input |
| 94 |
type="text" |
| 95 |
name="<?php echo esc_attr(self::OPTION_NAME) ?>" |
| 96 |
placeholder="auto" |
| 97 |
value="<?php echo esc_attr($current); ?>" |
| 98 |
size="20" |
| 99 |
/> |
| 100 |
<p class="description" style="max-width: 740px;"> |
| 101 |
<?php |
| 102 |
echo wp_kses_post(__('The style of skip buttons to show in the player.', 'speechkit')) . " "; |
| 103 |
echo wp_kses_post(__('Possible values are <code>auto</code>, <code>segments</code>, <code>seconds</code> or <code>audios</code>.', 'speechkit')) . " "; // phpcs:ignore Generic.Files.LineLength.TooLong |
| 104 |
echo wp_kses_post(__('You can specify the number of seconds to skip, e.g. <code>seconds-15</code> or <code>seconds-15-30</code>.', 'speechkit')) . " "; // phpcs:ignore Generic.Files.LineLength.TooLong |
| 105 |
?> |
| 106 |
</p> |
| 107 |
<p class="description" style="max-width: 740px;"> |
| 108 |
<?php |
| 109 |
printf( |
| 110 |
/* translators: %s is replaced with the link to the Player Settings docs */ |
| 111 |
esc_html__('Refer to the %s docs for more details.', 'speechkit'), |
| 112 |
sprintf( |
| 113 |
'<a href="%s" target="_blank" rel="nofollow">%s</a>', |
| 114 |
esc_url(PlaybackControls::PLAYER_SETTINGS_DOCS_URL), |
| 115 |
esc_html__('Player Settings', 'speechkit') |
| 116 |
) |
| 117 |
); |
| 118 |
?> |
| 119 |
</p> |
| 120 |
</div> |
| 121 |
<?php |
| 122 |
} |
| 123 |
} |
| 124 |
|