";
$element = '';
$close = '';
if ( ! empty( $wrap ) ) {
$el = isset( $wrap['element'] ) ? $wrap['element'] : 'p';
$class = '';
$id = '';
if ( isset( $wrap['class'] ) && '' !== $wrap['class'] ) {
$class = ' class="' . $wrap['class'] . '"';
}
if ( isset( $wrap['id'] ) && '' !== $wrap['id'] ) {
$id = ' id="' . $wrap['id'] . '"';
}
$element = "<$el$class$id>";
$close = "$el>";
}
$options = '';
$attributes = '';
$return = '';
if ( 'text' === $type || 'url' === $type || 'email' === $type ) {
$base_atts = array(
'size' => '30',
);
} else {
$base_atts = $atts;
}
$value = ableplayer_get_settings( $name );
$value = ( 'generator' === $context && ! is_string( $value ) ) ? '' : $value;
$atts = array_merge( $base_atts, $atts );
if ( is_array( $atts ) && ! empty( $atts ) ) {
foreach ( $atts as $key => $val ) {
$attributes .= " $key='" . esc_attr( $val ) . "'";
}
}
if ( 'checkbox' !== $type ) {
if ( is_array( $default ) ) {
$hold = '';
} else {
$hold = $default;
}
$value = ( '' !== $value ) ? esc_attr( wp_unslash( $value ) ) : $hold;
} else {
$value = ( ! empty( $value ) ) ? (array) $value : $default;
}
switch ( $type ) {
case 'text':
case 'url':
case 'email':
case 'number':
if ( $note ) {
$note = sprintf( str_replace( '%', '', $note ), "$value" );
$note = "$help_icon$note";
$aria = " aria-describedby='$id-note'";
} else {
$note = '';
$aria = '';
}
$note_top = ( 'top' === $position ) ? $note : '';
$note_bottom = ( 'bottom' === $position ) ? $note : '';
$return = "$element $note_top $close $note_bottom";
break;
case 'hidden':
$return = "";
break;
case 'textarea':
if ( $note ) {
$note = sprintf( $note, "$value" );
$note = "$help_icon$note";
$aria = " aria-describedby='$id-note'";
} else {
$note = '';
$aria = '';
}
$return = "$element
$close$note";
break;
case 'checkbox-single':
$checked = checked( 'true', ableplayer_get_settings( $name ), false );
if ( $note ) {
$note = "$help_icon" . sprintf( $note, "$value" ) . '';
$aria = " aria-describedby='$id-note'";
} else {
$note = '';
$aria = '';
}
$return = "$element $close$note";
break;
case 'checkbox':
case 'radio':
if ( $note ) {
$note = sprintf( $note, "$value" );
$note = "$help_icon$note";
$aria = " aria-describedby='$id-note'";
} else {
$note = '';
$aria = '';
}
$att_name = $name;
if ( 'checkbox' === $type ) {
$att_name = $name . '[]';
}
if ( is_array( $label ) ) {
foreach ( $label as $k => $v ) {
if ( 'radio' === $type ) {
$checked = ( $k === $value ) ? ' checked="checked"' : '';
} else {
$checked = ( in_array( $k, $value, true ) ) ? ' checked="checked"' : '';
}
$options .= "
$value" );
$note = "$help_icon$note";
$aria = " aria-describedby='$id-note'";
} else {
$note = '';
$aria = '';
}
if ( is_array( $default ) ) {
foreach ( $default as $k => $v ) {
$checked = ( (string) $k === (string) $value ) ? ' selected="selected"' : '';
$options .= "";
}
}
$return = "
$element
$options
$close
$note";
break;
}
if ( true === $echo ) {
echo wp_kses( $return, ableplayer_kses_elements() );
} else {
return $return;
}
}
/**
* Save a group of Able Player settings.
*
* @param array $settings An array of settings.
*
* @return bool
*/
function ableplayer_update_options( $settings ) {
if ( empty( $settings ) ) {
return false;
}
$defaults = ableplayer_default_settings();
$options = get_option( 'ableplayer_settings' );
if ( ! is_array( $options ) ) {
$options = $defaults;
}
$settings = array_merge( $options, $settings );
return update_option( 'ableplayer_settings', $settings );
}
/**
* Update Able Player settings.
*
* @param array $post POST data.
*/
function ableplayer_update_settings( $post ) {
$settings = array();
$replace_video = ( ! empty( $post['replace_video'] ) && 'on' === $post['replace_video'] ) ? 'true' : 'false';
$replace_audio = ( ! empty( $post['replace_audio'] ) && 'on' === $post['replace_audio'] ) ? 'true' : 'false';
$exclude_class = ( ! empty( $post['exclude_class'] ) ) ? sanitize_text_field( $post['exclude_class'] ) : '';
$replace_playlists = ( ! empty( $post['replace_playlists'] ) && 'on' === $post['replace_playlists'] ) ? 'true' : 'false';
$disable_elements = ( ! empty( $post['disable_elements'] ) && 'on' === $post['disable_elements'] ) ? 'true' : 'false';
$youtube_nocookie = ( ! empty( $post['youtube_nocookie'] ) && 'on' === $post['youtube_nocookie'] ) ? 'true' : 'false';
$play_inline = ( ! empty( $post['play_inline'] ) && 'on' === $post['play_inline'] ) ? 'true' : 'false';
$render_transcript = ( ! empty( $post['render_transcript'] ) && 'on' === $post['render_transcript'] ) ? 'true' : 'false';
$hide_controls = ( ! empty( $post['hide_controls'] ) && 'on' === $post['hide_controls'] ) ? 'true' : 'false';
$default_speed = ( isset( $post['default_speed'] ) ) ? $post['default_speed'] : 'animals';
$seek_interval = ( isset( $post['seek_interval'] ) && $post['seek_interval'] > 5 ) ? absint( $post['seek_interval'] ) : '';
$default_heading = ( isset( $post['default_heading'] ) && 'auto' !== $post['default_heading'] ) ? absint( $post['default_heading'] ) : 'auto';
$vimeo = ( ! empty( $post['vimeo'] ) && 'on' === $post['vimeo'] ) ? 'true' : 'false';
$settings['replace_video'] = $replace_video;
$settings['replace_audio'] = $replace_audio;
$settings['exclude_class'] = $exclude_class;
$settings['replace_playlists'] = $replace_playlists;
$settings['disable_elements'] = $disable_elements;
$settings['youtube_nocookie'] = $youtube_nocookie;
$settings['seek_interval'] = $seek_interval;
$settings['play_inline'] = $play_inline;
$settings['render_transcript'] = $render_transcript;
$settings['hide_controls'] = $hide_controls;
$settings['default_speed'] = $default_speed;
$settings['default_heading'] = $default_heading;
$settings['vimeo'] = $vimeo;
ableplayer_update_options( $settings );
}
/**
* Build Able Player settings form.
*/
function ableplayer_settings_form() {
if ( ! empty( $_POST ) ) {
$nonce = $_REQUEST['_wpnonce'];
if ( ! wp_verify_nonce( $nonce, 'ableplayer-nonce' ) ) {
wp_die( 'Able Player: Security check failed' );
}
$post = map_deep( $_POST, 'sanitize_textarea_field' );
if ( isset( $post['ableplayer_settings'] ) ) {
ableplayer_update_settings( $post );
wp_admin_notice(
__( 'Able Player Default Settings saved', 'ableplayer' ),
array(
'type' => 'success',
)
);
}
}
?>