Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
96.92% |
63 / 65 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| WidgetStyle | |
96.92% |
63 / 65 |
|
75.00% |
3 / 4 |
5 | |
0.00% |
0 / 1 |
| init | |
60.00% |
3 / 5 |
|
0.00% |
0 / 1 |
1.06 | |||
| addSetting | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
1 | |||
| render | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
2 | |||
| getOptions | |
100.00% |
22 / 22 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * Setting: Widget style |
| 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\WidgetStyle; |
| 14 | |
| 15 | use Beyondwords\Wordpress\Component\Settings\Sync; |
| 16 | |
| 17 | /** |
| 18 | * WidgetStyle |
| 19 | * |
| 20 | * @since 5.0.0 |
| 21 | */ |
| 22 | class WidgetStyle |
| 23 | { |
| 24 | /** |
| 25 | * Option name. |
| 26 | * |
| 27 | * @since 5.0.0 |
| 28 | */ |
| 29 | public const OPTION_NAME = 'beyondwords_player_widget_style'; |
| 30 | |
| 31 | /** |
| 32 | * Constructor |
| 33 | * |
| 34 | * @since 5.0.0 |
| 35 | * @since 6.0.0 Make static. |
| 36 | */ |
| 37 | public static function init() |
| 38 | { |
| 39 | add_action('admin_init', [self::class, 'addSetting']); |
| 40 | add_action('pre_update_option_' . self::OPTION_NAME, function ($value) { |
| 41 | Sync::syncOptionToDashboard(self::OPTION_NAME); |
| 42 | return $value; |
| 43 | }); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Add setting. |
| 48 | * |
| 49 | * @since 4.5.0 |
| 50 | * @since 6.0.0 Make static. |
| 51 | * |
| 52 | * @return void |
| 53 | */ |
| 54 | public static function addSetting() |
| 55 | { |
| 56 | register_setting( |
| 57 | 'beyondwords_player_settings', |
| 58 | self::OPTION_NAME, |
| 59 | [ |
| 60 | 'default' => '', |
| 61 | ] |
| 62 | ); |
| 63 | |
| 64 | add_settings_field( |
| 65 | 'beyondwords-widget-style', |
| 66 | __('Widget style', 'speechkit'), |
| 67 | [self::class, 'render'], |
| 68 | 'beyondwords_player', |
| 69 | 'widget' |
| 70 | ); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Render setting field. |
| 75 | * |
| 76 | * @since 5.0.0 |
| 77 | * @since 6.0.0 Make static. |
| 78 | * |
| 79 | * @return void |
| 80 | **/ |
| 81 | public static function render() |
| 82 | { |
| 83 | $current = get_option(self::OPTION_NAME); |
| 84 | $options = self::getOptions(); |
| 85 | ?> |
| 86 | <div class="beyondwords-setting__player beyondwords-setting__widget-style"> |
| 87 | <select name="<?php echo esc_attr(self::OPTION_NAME) ?>"> |
| 88 | <?php |
| 89 | foreach ($options as $option) { |
| 90 | printf( |
| 91 | '<option value="%s" %s>%s</option>', |
| 92 | esc_attr($option['value']), |
| 93 | selected($option['value'], $current), |
| 94 | esc_html($option['label']) |
| 95 | ); |
| 96 | } |
| 97 | ?> |
| 98 | </select> |
| 99 | <p class="description"> |
| 100 | <?php |
| 101 | printf( |
| 102 | /* translators: %s is replaced with the "widgetStyle setting" link */ |
| 103 | esc_html__('The style of widget to display at the bottom of the page once the user scrolls past the inline player. See %s.', 'speechkit'), // phpcs:ignore Generic.Files.LineLength.TooLong |
| 104 | sprintf( |
| 105 | '<a href="https://github.com/beyondwords-io/player/blob/main/doc/player-settings.md" target="_blank" rel="nofollow">%s</a>', // phpcs:ignore Generic.Files.LineLength.TooLong |
| 106 | esc_html__('widgetStyle setting', 'speechkit') |
| 107 | ) |
| 108 | ); |
| 109 | ?> |
| 110 | </p> |
| 111 | </div> |
| 112 | <?php |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Get all options for the current component. |
| 117 | * |
| 118 | * @since 5.0.0 |
| 119 | * @since 6.0.0 Make static. |
| 120 | * |
| 121 | * @return string[] Associative array of options. |
| 122 | **/ |
| 123 | public static function getOptions() |
| 124 | { |
| 125 | return [ |
| 126 | [ |
| 127 | 'value' => 'standard', |
| 128 | 'label' => __('Standard', 'speechkit'), |
| 129 | ], |
| 130 | [ |
| 131 | 'value' => 'none', |
| 132 | 'label' => __('None', 'speechkit'), |
| 133 | ], |
| 134 | [ |
| 135 | 'value' => 'small', |
| 136 | 'label' => __('Small', 'speechkit'), |
| 137 | ], |
| 138 | [ |
| 139 | 'value' => 'large', |
| 140 | 'label' => __('Large', 'speechkit'), |
| 141 | ], |
| 142 | [ |
| 143 | 'value' => 'video', |
| 144 | 'label' => __('Video', 'speechkit'), |
| 145 | ], |
| 146 | ]; |
| 147 | } |
| 148 | } |