tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
require_once AIOVG_PLUGIN_DIR . 'admin/templates/settings.php';
}
/**
* Initiate settings.
*
* @since 1.0.0
*/
public function admin_init() {
$this->tabs = $this->get_tabs();
$this->sections = $this->get_sections();
$this->fields = $this->get_fields();
// Initialize settings
$this->initialize_settings();
}
/**
* Get settings tabs.
*
* @since 1.0.0
* @return array $tabs Setting tabs array.
*/
public function get_tabs() {
$tabs = array(
'general' => __( 'General', 'all-in-one-video-gallery' ),
'display' => __( 'Display', 'all-in-one-video-gallery' ),
'advanced' => __( 'Advanced', 'all-in-one-video-gallery' )
);
return apply_filters( 'aiovg_settings_tabs', $tabs );
}
/**
* Get settings sections.
*
* @since 1.0.0
* @return array $sections Setting sections array.
*/
public function get_sections() {
$sections = array(
array(
'id' => 'aiovg_general_settings',
'title' => __( 'General Settings', 'all-in-one-video-gallery' ),
'tab' => 'general'
),
array(
'id' => 'aiovg_player_settings',
'title' => __( 'Player Settings', 'all-in-one-video-gallery' ),
'tab' => 'general'
),
array(
'id' => 'aiovg_image_settings',
'title' => __( 'Image Settings', 'all-in-one-video-gallery' ),
'tab' => 'display'
),
array(
'id' => 'aiovg_categories_settings',
'title' => __( 'Categories Page', 'all-in-one-video-gallery' ),
'tab' => 'display'
),
array(
'id' => 'aiovg_videos_settings',
'title' => __( 'Video Gallery Pages', 'all-in-one-video-gallery' ),
'tab' => 'display'
),
array(
'id' => 'aiovg_video_settings',
'title' => __( 'Single Video Page', 'all-in-one-video-gallery' ),
'tab' => 'display'
),
array(
'id' => 'aiovg_permalink_settings',
'title' => __( 'Permalink Slugs', 'all-in-one-video-gallery' ),
'description' => __( 'NOTE: Just make sure that, after updating the fields in this section, you flush the rewrite rules by visiting "Settings > Permalinks". Otherwise you\'ll still see the old links.', 'all-in-one-video-gallery' ),
'tab' => 'advanced'
),
array(
'id' => 'aiovg_socialshare_settings',
'title' => __( 'Socialshare Buttons', 'all-in-one-video-gallery' ),
'description' => __( 'Select social share buttons displayed in the single video pages.', 'all-in-one-video-gallery' ),
'tab' => 'advanced'
),
array(
'id' => 'aiovg_page_settings',
'title' => __( 'Page Settings', 'all-in-one-video-gallery' ),
'tab' => 'advanced'
)
);
return apply_filters( 'aiovg_settings_sections', $sections );
}
/**
* Get settings fields.
*
* @since 1.0.0
* @return array $fields Setting fields array.
*/
public function get_fields() {
$fields = array(
'aiovg_general_settings' => array(
array(
'name' => 'bootstrap',
'label' => __( 'Bootstrap Options', 'all-in-one-video-gallery' ),
'description' => __( 'All in One Video Gallery uses Bootstrap version 3. Disable this option if your theme already include the "Bootstrap" library files.', 'all-in-one-video-gallery' ),
'type' => 'multicheck',
'options' => array(
'css' => __( 'Include Bootstrap CSS', 'all-in-one-video-gallery' )
),
'sanitize_callback' => 'aiovg_sanitize_array'
),
array(
'name' => 'fontawesome',
'label' => __( 'Font Awesome', 'all-in-one-video-gallery' ),
'description' => __( 'Include Font Awesome. Disable this option if your theme already include the "Font Awesome" library files', 'all-in-one-video-gallery' ),
'type' => 'checkbox',
'sanitize_callback' => 'intval'
),
array(
'name' => 'delete_plugin_data',
'label' => __( 'Remove data on uninstall?', 'all-in-one-video-gallery' ),
'description' => __( 'Check this box to delete all of the plugin data( database stored content, uploaded media files, etc... ) when uninstalled', 'all-in-one-video-gallery' ),
'type' => 'checkbox',
'sanitize_callback' => 'intval'
)
),
'aiovg_player_settings' => array(
array(
'name' => 'width',
'label' => __( 'Width', 'all-in-one-video-gallery' ),
'description' => __( 'In pixels. Maximum width of the player. Leave this field empty to scale 100% of its enclosing container/html element.', 'all-in-one-video-gallery' ),
'type' => 'text',
'sanitize_callback' => 'aiovg_sanitize_int'
),
array(
'name' => 'ratio',
'label' => __( 'Ratio', 'all-in-one-video-gallery' ),
'description' => sprintf(
'%s
%s:
"56.25" - %s
"62.5" - %s
"75" - %s
"67" - %s
"100" - %s
"41.7" - %s',
__( "In percentage. 1 to 100. Calculate player's height using the ratio value entered.", 'all-in-one-video-gallery' ),
__( 'Examples', 'all-in-one-video-gallery' ),
__( 'Wide Screen TV', 'all-in-one-video-gallery' ),
__( 'Monitor Screens', 'all-in-one-video-gallery' ),
__( 'Classic TV', 'all-in-one-video-gallery' ),
__( 'Photo Camera', 'all-in-one-video-gallery' ),
__( 'Square', 'all-in-one-video-gallery' ),
__( 'Cinemascope', 'all-in-one-video-gallery' )
),
'type' => 'text',
'sanitize_callback' => 'floatval'
),
array(
'name' => 'autoplay',
'label' => __( 'Autoplay', 'all-in-one-video-gallery' ),
'description' => __( 'Check this to start playing the video as soon as it is ready', 'all-in-one-video-gallery' ),
'type' => 'checkbox',
'sanitize_callback' => 'intval'
),
array(
'name' => 'loop',
'label' => __( 'Loop', 'all-in-one-video-gallery' ),
'description' => __( 'Check this, so that the video will start over again, every time it is finished', 'all-in-one-video-gallery' ),
'type' => 'checkbox',
'sanitize_callback' => 'intval'
),
array(
'name' => 'preload',
'label' => __( 'Preload', 'all-in-one-video-gallery' ),
'description' => sprintf(
'%s
%s
%s
%s',
__( 'Specifies if and how the video should be loaded when the page loads.', 'all-in-one-video-gallery' ),
__( '"Auto" - the video should be loaded entirely when the page loads', 'all-in-one-video-gallery' ),
__( '"Metadata" - only metadata should be loaded when the page loads', 'all-in-one-video-gallery' ),
__( '"None" - the video should not be loaded when the page loads', 'all-in-one-video-gallery' )
),
'type' => 'select',
'options' => array(
'auto' => __( 'Auto', 'all-in-one-video-gallery' ),
'metadata' => __( 'Metadata', 'all-in-one-video-gallery' ),
'none' => __( 'None', 'all-in-one-video-gallery' )
),
'sanitize_callback' => 'sanitize_key'
),
array(
'name' => 'controls',
'label' => __( 'Show / Hide Player Controls', 'all-in-one-video-gallery' ),
'description' => '',
'type' => 'multicheck',
'options' => array(
'playpause' => __( 'Play / Pause', 'all-in-one-video-gallery' ),
'current' => __( 'Current Time', 'all-in-one-video-gallery' ),
'progress' => __( 'Progressbar', 'all-in-one-video-gallery' ),
'duration' => __( 'Duration', 'all-in-one-video-gallery' ),
'tracks' => __( 'Subtitles', 'all-in-one-video-gallery' ),
'volume' => __( 'Volume', 'all-in-one-video-gallery' ),
'fullscreen' => __( 'Fullscreen', 'all-in-one-video-gallery' )
),
'sanitize_callback' => 'aiovg_sanitize_array'
)
),
'aiovg_image_settings' => array(
array(
'name' => 'width',
'label' => __( 'Width', 'all-in-one-video-gallery' ),
'description' => __( 'Always 100% of its enclosing container/html element.', 'all-in-one-video-gallery' ),
'type' => 'html',
'sanitize_callback' => 'aiovg_sanitize_int'
),
array(
'name' => 'ratio',
'label' => __( 'Ratio', 'all-in-one-video-gallery' ),
'description' => __( "In percentage. 1 to 100. Calculate images's height using the ratio value entered.", 'all-in-one-video-gallery' ),
'type' => 'text',
'sanitize_callback' => 'floatval'
),
),
'aiovg_categories_settings' => array(
array(
'name' => 'columns',
'label' => __( 'Number of Columns', 'all-in-one-video-gallery' ),
'description' => __( 'Enter the number of columns you like to have in your categories page.', 'all-in-one-video-gallery' ),
'min' => 1,
'max' => 12,
'step' => '1',
'type' => 'number',
'sanitize_callback' => 'intval'
),
array(
'name' => 'orderby',
'label' => __( 'Order Categories by', 'all-in-one-video-gallery' ),
'description' => '',
'type' => 'select',
'options' => array(
'id' => __( 'ID', 'all-in-one-video-gallery' ),
'count' => __( 'Count', 'all-in-one-video-gallery' ),
'name' => __( 'Name', 'all-in-one-video-gallery' ),
'slug' => __( 'Slug', 'all-in-one-video-gallery' )
),
'sanitize_callback' => 'sanitize_key'
),
array(
'name' => 'order',
'label' => __( 'Sort Categories by', 'all-in-one-video-gallery' ),
'description' => '',
'type' => 'select',
'options' => array(
'asc' => __( 'Ascending', 'all-in-one-video-gallery' ),
'desc' => __( 'Descending', 'all-in-one-video-gallery' )
),
'sanitize_callback' => 'sanitize_key'
),
array(
'name' => 'show_description',
'label' => __( 'Show Description?', 'all-in-one-video-gallery' ),
'description' => __( 'Check this to show the categories description', 'all-in-one-video-gallery' ),
'type' => 'checkbox',
'sanitize_callback' => 'intval'
),
array(
'name' => 'show_count',
'label' => __( 'Show Videos Count?', 'all-in-one-video-gallery' ),
'description' => __( 'Check this to show the videos count next to the category name', 'all-in-one-video-gallery' ),
'type' => 'checkbox',
'sanitize_callback' => 'intval'
),
array(
'name' => 'hide_empty',
'label' => __( 'Hide Empty Categories?', 'all-in-one-video-gallery' ),
'description' => __( 'Check this to hide categories with no videos', 'all-in-one-video-gallery' ),
'type' => 'checkbox',
'sanitize_callback' => 'intval'
)
),
'aiovg_videos_settings' => array(
array(
'name' => 'template',
'label' => __( 'Select a Template', 'all-in-one-video-gallery' ),
'description' => '',
'type' => 'radio',
'options' => aiovg_get_video_templates(),
'sanitize_callback' => 'sanitize_key'
),
array(
'name' => 'columns',
'label' => __( 'Number of Columns', 'all-in-one-video-gallery' ),
'description' => __( 'Enter the number of columns you like to have in the gallery view.', 'all-in-one-video-gallery' ),
'min' => 1,
'max' => 12,
'step' => '1',
'type' => 'number',
'sanitize_callback' => 'intval'
),
array(
'name' => 'limit',
'label' => __( 'Videos per Page', 'all-in-one-video-gallery' ),
'description' => __( 'Number of videos to show per page. Use a value of "0" to show all videos.', 'all-in-one-video-gallery' ),
'type' => 'text',
'sanitize_callback' => 'intval'
),
array(
'name' => 'orderby',
'label' => __( 'Order Videos by', 'all-in-one-video-gallery' ),
'description' => '',
'type' => 'select',
'options' => array(
'title' => __( 'Title', 'all-in-one-video-gallery' ),
'date' => __( 'Date Posted', 'all-in-one-video-gallery' ),
'views' => __( 'Views Count', 'all-in-one-video-gallery' ),
'rand' => __( 'Random', 'all-in-one-video-gallery' )
),
'sanitize_callback' => 'sanitize_key'
),
array(
'name' => 'order',
'label' => __( 'Sort Videos by', 'all-in-one-video-gallery' ),
'description' => '',
'type' => 'select',
'options' => array(
'asc' => __( 'Ascending', 'all-in-one-video-gallery' ),
'desc' => __( 'Descending', 'all-in-one-video-gallery' )
),
'sanitize_callback' => 'sanitize_key'
),
array(
'name' => 'display',
'label' => __( 'Show / Hide', 'all-in-one-video-gallery' ),
'description' => '',
'type' => 'multicheck',
'options' => array(
'count' => __( 'Videos Count', 'all-in-one-video-gallery' ),
'category' => __( 'Category Name', 'all-in-one-video-gallery' ),
'date' => __( 'Date Added', 'all-in-one-video-gallery' ),
'user' => __( 'Author Name', 'all-in-one-video-gallery' ),
'views' => __( 'Views Count', 'all-in-one-video-gallery' ),
'duration' => __( 'Video Duration', 'all-in-one-video-gallery' ),
'excerpt' => __( 'Excerpt ( Short Description )', 'all-in-one-video-gallery' )
),
'sanitize_callback' => 'aiovg_sanitize_array'
),
array(
'name' => 'excerpt_length',
'label' => __( 'Excerpt Length', 'all-in-one-video-gallery' ),
'description' => __( 'Number of characters.', 'all-in-one-video-gallery' ),
'type' => 'text',
'sanitize_callback' => 'intval'
),
),
'aiovg_video_settings' => array(
array(
'name' => 'display',
'label' => __( 'Show / Hide', 'all-in-one-video-gallery' ),
'description' => '',
'type' => 'multicheck',
'options' => array(
'category' => __( 'Category Name', 'all-in-one-video-gallery' ),
'date' => __( 'Date Added', 'all-in-one-video-gallery' ),
'user' => __( 'Author Name', 'all-in-one-video-gallery' ),
'views' => __( 'Views Count', 'all-in-one-video-gallery' ),
'related' => __( 'Related Videos', 'all-in-one-video-gallery' )
),
'sanitize_callback' => 'aiovg_sanitize_array'
),
array(
'name' => 'has_comments',
'label' => __( 'Enable Comments', 'all-in-one-video-gallery' ),
'description' => __( 'Allow visitors to comment videos using the standard WordPress comment form. Comments are public', 'all-in-one-video-gallery' ),
'type' => 'checkbox',
'sanitize_callback' => 'intval'
)
),
'aiovg_permalink_settings' => array(
array(
'name' => 'video',
'label' => __( 'Video Detail Page', 'all-in-one-video-gallery' ),
'description' => __( 'Replaces the SLUG value used by custom post type "aiovg_videos".', 'all-in-one-video-gallery' ),
'type' => 'text',
'sanitize_callback' => 'sanitize_text_field'
)
),
'aiovg_socialshare_settings' => array(
array(
'name' => 'services',
'label' => __( 'Enable Services', 'all-in-one-video-gallery' ),
'description' => '',
'type' => 'multicheck',
'options' => array(
'facebook' => __( 'Facebook', 'all-in-one-video-gallery' ),
'twitter' => __( 'Twitter', 'all-in-one-video-gallery' ),
'gplus' => __( 'Google Plus', 'all-in-one-video-gallery' ),
'linkedin' => __( 'Linkedin', 'all-in-one-video-gallery' ),
'pinterest' => __( 'Pinterest', 'all-in-one-video-gallery' )
),
'sanitize_callback' => 'aiovg_sanitize_array'
)
),
'aiovg_page_settings' => array(
array(
'name' => 'category',
'label' => __( 'Single Category Page', 'all-in-one-video-gallery' ),
'description' => __( 'This is the page where the videos from a particular category is displayed. The [aiovg_category] short code must be on this page.', 'all-in-one-video-gallery' ),
'type' => 'pages',
'sanitize_callback' => 'sanitize_key'
),
array(
'name' => 'search',
'label' => __( 'Search Page', 'all-in-one-video-gallery' ),
'description' => __( 'This is the page where the search results are displayed. The [aiovg_search] short code must be on this page.', 'all-in-one-video-gallery' ),
'type' => 'pages',
'sanitize_callback' => 'sanitize_key'
),
array(
'name' => 'user_videos',
'label' => __( 'User Videos Page', 'all-in-one-video-gallery' ),
'description' => __( 'This is the page where the videos from an user is displayed. The [aiovg_user_videos] short code must be on this page.', 'all-in-one-video-gallery' ),
'type' => 'pages',
'sanitize_callback' => 'sanitize_key'
),
array(
'name' => 'player',
'label' => __( 'Player Page', 'all-in-one-video-gallery' ),
'description' => __( 'This is the page used to show the video player.', 'all-in-one-video-gallery' ),
'type' => 'pages',
'sanitize_callback' => 'sanitize_key'
)
)
);
return apply_filters( 'aiovg_settings_fields', $fields );
}
/**
* Initialize and registers the settings sections and fields to WordPress.
*
* @since 1.0.0
*/
public function initialize_settings() {
// Register settings sections & fields
foreach ( $this->sections as $section ) {
$page_hook = "aiovg_{$section['tab']}_settings";
// Sections
if ( false == get_option( $section['id'] ) ) {
add_option( $section['id'] );
}
if ( isset( $section['description'] ) && ! empty( $section['description'] ) ) {
$section['description'] = sprintf( '
%s
', $args['description'] ); } else { $description = ''; } return $description; } /** * Sanitize callback for Settings API. * * @since 1.0.0 * @param array $options The unsanitized collection of options. * @return The collection of sanitized values. */ public function sanitize_options( $options ) { if ( ! $options ) { return $options; } foreach ( $options as $option_slug => $option_value ) { $sanitize_callback = $this->get_sanitize_callback( $option_slug ); // If callback is set, call it if ( $sanitize_callback ) { $options[ $option_slug ] = call_user_func( $sanitize_callback, $option_value ); continue; } } return $options; } /** * Get sanitization callback for given option slug. * * @since 1.0.0 * @param string $slug Option slug. * @return mixed String or bool false. */ public function get_sanitize_callback( $slug = '' ) { if ( empty( $slug ) ) { return false; } // Iterate over registered fields and see if we can find proper callback foreach ( $this->fields as $section => $options ) { foreach ( $options as $option ) { if ( $option['name'] != $slug ) { continue; } // Return the callback name return isset( $option['sanitize_callback'] ) && is_callable( $option['sanitize_callback'] ) ? $option['sanitize_callback'] : false; } } return false; } /** * Get the value of a settings field * * @since 1.0.0 * @param string $option Settings field name. * @param string $section The section name this field belongs to * @param string $default Default text if it's not found. * @return string */ public function get_option( $option, $section, $default = '' ) { $options = get_option( $section ); if ( ! empty( $options[ $option ] ) ) { return $options[ $option ]; } return $default; } }