Skip to content

Commit 720a75c

Browse files
committed
Add settings for video, audio, nocookie, speed control icon, hide controls, and heading level.
See #13
1 parent 2be6aaf commit 720a75c

File tree

3 files changed

+78
-28
lines changed

3 files changed

+78
-28
lines changed

src/ableplayer.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ function ableplayer_plugin_deactivated() {
4747
* Load styles and scripts to head.
4848
*/
4949
function ableplayer_enqueue_scripts() {
50+
$version = ABLEPLAYER_VERSION;
51+
$version = ( SCRIPT_DEBUG ) ? $version . '-' . wp_rand( 1000,9999 ) : $version;
5052
// Register/enqueue other dependencies.
51-
wp_enqueue_script( 'js-cookie', plugins_url( 'thirdparty', __FILE__ ) . '/js.cookie.js', array( 'jquery' ), ABLEPLAYER_VERSION, true );
52-
wp_enqueue_script( 'vimeo', 'https://player.vimeo.com/api/player.js', array(), ABLEPLAYER_VERSION, true );
53-
wp_register_script( 'ableplayer-video', plugins_url( 'assets', __FILE__ ) . '/js/media.js', array(), ABLEPLAYER_VERSION, true );
53+
wp_enqueue_script( 'js-cookie', plugins_url( 'thirdparty', __FILE__ ) . '/js.cookie.js', array( 'jquery' ), $version, true );
54+
wp_enqueue_script( 'vimeo', 'https://player.vimeo.com/api/player.js', array(), $version, true );
55+
wp_register_script( 'ableplayer-video', plugins_url( 'assets', __FILE__ ) . '/js/media.js', array(), $version, true );
5456
wp_localize_script(
5557
'ableplayer-video',
5658
'ableplayer',
@@ -98,24 +100,26 @@ function ableplayer_enqueue_scripts() {
98100
* @return {array}
99101
*/
100102
$dependencies = apply_filters( 'ableplayer_dependencies', $dependencies, $is_production );
101-
wp_enqueue_script( 'ableplayer', $js_dir, $dependencies, ABLEPLAYER_VERSION, true );
102-
wp_enqueue_style( 'ableplayer', $css_dir, array(), ABLEPLAYER_VERSION );
103+
wp_enqueue_script( 'ableplayer', $js_dir, $dependencies, $version, true );
104+
wp_enqueue_style( 'ableplayer', $css_dir, array(), $version );
103105
}
104106
add_action( 'wp_enqueue_scripts', 'ableplayer_enqueue_scripts' );
105107

106108
/**
107109
* Enqueue admin JS and CSS.
108110
*/
109111
function ableplayer_admin_scripts() {
110-
wp_enqueue_script( 'ableplayer-js', plugins_url( '/assets/js/admin.js', __FILE__ ), array( 'jquery' ), ABLEPLAYER_VERSION, true );
112+
$version = ABLEPLAYER_VERSION;
113+
$version = ( SCRIPT_DEBUG ) ? $version . '-' . wp_rand( 1000,9999 ) : $version;
114+
wp_enqueue_script( 'ableplayer-js', plugins_url( '/assets/js/admin.js', __FILE__ ), array( 'jquery' ), $version, true );
111115
wp_localize_script(
112116
'ableplayer-js',
113117
'ableplayer',
114118
array(
115119
'firstItem' => 'tab_settings',
116120
)
117121
);
118-
wp_enqueue_style( 'ableplayer', plugins_url( '/assets/css/admin.css', __FILE__ ), array(), ABLEPLAYER_VERSION );
122+
wp_enqueue_style( 'ableplayer', plugins_url( '/assets/css/admin.css', __FILE__ ), array(), $version );
119123
}
120124
add_action( 'admin_enqueue_scripts', 'ableplayer_admin_scripts' );
121125

src/assets/js/media.js

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,46 @@
1-
const videoEls = document.querySelectorAll( 'video, audio' );
2-
if ( videoEls ) {
3-
videoEls.forEach((el,index,listObj) => {
4-
if ( ! el.hasAttribute( 'data-able-player' ) ) {
5-
el.setAttribute( 'data-able-player', 'true' );
6-
}
7-
if ( ! el.hasAttribute( 'id' ) ) {
8-
el.setAttribute( 'id', 'able-player-id-' + index );
1+
let ableplayer_selectors = [];
2+
if ( ableplayer.settings.replace_video === 'true' ) {
3+
ableplayer_selectors.push( 'video' );
4+
}
5+
if ( ableplayer.settings.replace_audio === 'true' ) {
6+
ableplayer_selectors.push( 'audio' );
7+
}
8+
if ( 0 !== ableplayer_selectors.length ) {
9+
const mediaEls = document.querySelectorAll( ableplayer_selectors );
10+
if ( mediaEls ) {
11+
mediaEls.forEach((el,index,listObj) => {
12+
if ( ! el.hasAttribute( 'data-able-player' ) ) {
13+
el.setAttribute( 'data-able-player', 'true' );
14+
}
15+
if ( ! el.hasAttribute( 'id' ) ) {
16+
el.setAttribute( 'id', 'able-player-id-' + index );
17+
}
18+
});
19+
}
20+
}
21+
22+
const ablePlayers = document.querySelectorAll( '[data-able-player]' );
23+
if ( ablePlayers ) {
24+
ablePlayers.forEach((el,index,listObj) => {
25+
if ( 'true' === ableplayer.settings.youtube_nocookie ) {
26+
if ( ! el.hasAttribute( 'data-youtube-nocookie' ) ) {
27+
el.setAttribute( 'data-youtube-nocookie', 'true' );
28+
}
29+
}
30+
if ( 'auto' !== ableplayer.settings.default_heading ) {
31+
if ( ! el.hasAttribute( 'data-heading-level' ) ) {
32+
el.setAttribute( 'data-heading-level', ableplayer.settings.default_heading );
33+
}
34+
}
35+
if ( 'animals' !== ableplayer.settings.default_heading ) {
36+
if ( ! el.hasAttribute( 'data-speed-icons' ) ) {
37+
el.setAttribute( 'data-speed-icons', 'arrows' );
38+
}
39+
}
40+
if ( 'true' === ableplayer.settings.hide_controls ) {
41+
if ( ! el.hasAttribute( 'data-hide-controls' ) ) {
42+
el.setAttribute( 'data-hide-controls', 'true' );
43+
}
944
}
1045
});
1146
}

src/inc/settings.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
* @return array|mixed The full settings array or a specific setting value.
2222
*/
2323
function ableplayer_get_settings( $setting = '' ) {
24-
$settings = get_option( 'ableplayer_settings', array() );
25-
$settings = array_merge( $settings, ableplayer_default_settings() );
24+
$settings = get_option( 'ableplayer_settings', ableplayer_default_settings() );
25+
$settings = array_merge( ableplayer_default_settings(), $settings );
2626
if ( $setting && isset( $settings[ $setting ] ) ) {
2727
return $settings[ $setting ];
2828
}
@@ -133,7 +133,7 @@ function ableplayer_settings_field( $args = array() ) {
133133
case 'email':
134134
if ( $note ) {
135135
$note = sprintf( str_replace( '%', '', $note ), "<code>$value</code>" );
136-
$note = "<span id='$id-note' class='mc-input-description'><i class='dashicons dashicons-editor-help' aria-hidden='true'></i>$note</span>";
136+
$note = "<span id='$id-note' class='ableplayer-input-description'><i class='dashicons dashicons-editor-help' aria-hidden='true'></i>$note</span>";
137137
$aria = " aria-describedby='$id-note'";
138138
} else {
139139
$note = '';
@@ -149,7 +149,7 @@ function ableplayer_settings_field( $args = array() ) {
149149
case 'textarea':
150150
if ( $note ) {
151151
$note = sprintf( $note, "<code>$value</code>" );
152-
$note = "<span id='$id-note' class='mc-input-description'><i class='dashicons dashicons-editor-help' aria-hidden='true'></i>$note</span>";
152+
$note = "<span id='$id-note' class='ableplayer-input-description'><i class='dashicons dashicons-editor-help' aria-hidden='true'></i>$note</span>";
153153
$aria = " aria-describedby='$id-note'";
154154
} else {
155155
$note = '';
@@ -160,7 +160,7 @@ function ableplayer_settings_field( $args = array() ) {
160160
case 'checkbox-single':
161161
$checked = checked( 'true', ableplayer_get_settings( $name ), false );
162162
if ( $note ) {
163-
$note = "<div id='$id-note' class='mc-input-description'><i class='dashicons dashicons-editor-help' aria-hidden='true'></i>" . sprintf( $note, "<code>$value</code>" ) . '</div>';
163+
$note = "<div id='$id-note' class='ableplayer-input-description'><i class='dashicons dashicons-editor-help' aria-hidden='true'></i>" . sprintf( $note, "<code>$value</code>" ) . '</div>';
164164
$aria = " aria-describedby='$id-note'";
165165
} else {
166166
$note = '';
@@ -172,7 +172,7 @@ function ableplayer_settings_field( $args = array() ) {
172172
case 'radio':
173173
if ( $note ) {
174174
$note = sprintf( $note, "<code>$value</code>" );
175-
$note = "<span id='$id-note' class='mc-input-description'><i class='dashicons dashicons-editor-help' aria-hidden='true'></i>$note</span>";
175+
$note = "<span id='$id-note' class='ableplayer-input-description'><i class='dashicons dashicons-editor-help' aria-hidden='true'></i>$note</span>";
176176
$aria = " aria-describedby='$id-note'";
177177
} else {
178178
$note = '';
@@ -197,7 +197,7 @@ function ableplayer_settings_field( $args = array() ) {
197197
case 'select':
198198
if ( $note ) {
199199
$note = sprintf( $note, "<code>$value</code>" );
200-
$note = "<span id='$id-note' class='mc-input-description'><i class='dashicons dashicons-editor-help' aria-hidden='true'></i>$note</span>";
200+
$note = "<span id='$id-note' class='ableplayer-input-description'><i class='dashicons dashicons-editor-help' aria-hidden='true'></i>$note</span>";
201201
$aria = " aria-describedby='$id-note'";
202202
} else {
203203
$note = '';
@@ -237,7 +237,7 @@ function ableplayer_update_options( $settings ) {
237237
return false;
238238
}
239239
$defaults = ableplayer_default_settings();
240-
$options = get_option( 'ableplayer_settings', ableplayer_default_settings() );
240+
$options = get_option( 'ableplayer_settings' );
241241
if ( ! is_array( $options ) ) {
242242
$options = $defaults;
243243
}
@@ -256,10 +256,20 @@ function ableplayer_update_settings( $post ) {
256256
$replace_video = ( ! empty( $post['replace_video'] ) && 'on' === $post['replace_video'] ) ? 'true' : 'false';
257257
$replace_audio = ( ! empty( $post['replace_audio'] ) && 'on' === $post['replace_audio'] ) ? 'true' : 'false';
258258
$replace_playlists = ( ! empty( $post['replace_playlists'] ) && 'on' === $post['replace_playlists'] ) ? 'true' : 'false';
259+
$youtube_nocookie = ( ! empty( $post['youtube_nocookie'] ) && 'on' === $post['youtube_nocookie'] ) ? 'true' : 'false';
260+
$hide_controls = ( ! empty( $post['hide_controls'] ) && 'on' === $post['hide_controls'] ) ? 'true' : 'false';
261+
$default_speed = ( isset( $post['default_speed'] ) ) ? $post['default_speed'] : 'animals';
262+
$default_heading = ( isset( $post['default_heading'] ) ) ? $post['default_heading'] : 'auto';
263+
$default_poster = ( isset( $post['default_poster_id'] ) ) ? absint( $post['default_poster_id'] ) : '';
259264

260265
$settings['replace_video'] = $replace_video;
261266
$settings['replace_audio'] = $replace_audio;
262267
$settings['replace_playlists'] = $replace_playlists;
268+
$settings['youtube_nocookie'] = $youtube_nocookie;
269+
$settings['hide_controls'] = $hide_controls;
270+
$settings['default_speed'] = $default_speed;
271+
$settings['default_heading'] = $default_heading;
272+
$settings['default_poster'] = $default_poster;
263273

264274
ableplayer_update_options( $settings );
265275
}
@@ -376,7 +386,7 @@ function ableplayer_settings_form() {
376386
ableplayer_settings_field(
377387
array(
378388
'name' => 'hide_controls',
379-
'label' => __( 'Hide controls when not interacting with player', 'ableplayer' ),
389+
'label' => __( 'Visually hide controls during playback', 'ableplayer' ),
380390
'type' => 'checkbox-single',
381391
)
382392
);
@@ -390,10 +400,11 @@ function ableplayer_settings_form() {
390400
'label' => __( 'Default hidden heading level', 'ableplayer' ),
391401
'type' => 'select',
392402
'default' => array(
393-
'auto' => 'Automatically set',
394-
'h2' => 'H2',
395-
'h3' => 'H3',
396-
'h4' => 'H4',
403+
'auto' => __( 'Automatically set', 'ableplayer' ),
404+
'0' => __( 'No heading', 'ableplayer' ),
405+
'2' => 'H2',
406+
'3' => 'H3',
407+
'4' => 'H4',
397408
)
398409
)
399410
);

0 commit comments

Comments
 (0)