<?php

use Elementor\Plugin;

function atomicslider_allow_tags( $tag = null ) {
	$tag_allowed = wp_kses_allowed_html( 'post' );

	$tag_allowed['input']  = [ 
		'class'   => [],
		'id'      => [],
		'name'    => [],
		'value'   => [],
		'checked' => [],
		'type'    => [],
	];
	$tag_allowed['select'] = [ 
		'class'    => [],
		'id'       => [],
		'name'     => [],
		'value'    => [],
		'multiple' => [],
		'type'     => [],
	];
	$tag_allowed['option'] = [ 
		'value'    => [],
		'selected' => [],
	];

	$tag_allowed['title'] = [ 
		'a'      => [ 
			'href'  => [],
			'title' => [],
			'class' => [],
		],
		'br'     => [],
		'em'     => [],
		'strong' => [],
		'hr'     => [],
	];

	$tag_allowed['text'] = [ 
		'a'      => [ 
			'href'  => [],
			'title' => [],
			'class' => [],
		],
		'br'     => [],
		'em'     => [],
		'strong' => [],
		'hr'     => [],
		'i'      => [ 
			'class' => [],
		],
		'span'   => [ 
			'class' => [],
		],
	];

	$tag_allowed['svg'] = [ 
		'svg'     => [ 
			'version'     => [],
			'xmlns'       => [],
			'viewbox'     => [],
			'xml:space'   => [],
			'xmlns:xlink' => [],
			'x'           => [],
			'y'           => [],
			'style'       => [],
		],
		'g'       => [],
		'path'    => [ 
			'class' => [],
			'd'     => [],
		],
		'ellipse' => [ 
			'class' => [],
			'cx'    => [],
			'cy'    => [],
			'rx'    => [],
			'ry'    => [],
		],
		'circle'  => [ 
			'class' => [],
			'cx'    => [],
			'cy'    => [],
			'r'     => [],
		],
		'rect'    => [ 
			'x'         => [],
			'y'         => [],
			'transform' => [],
			'height'    => [],
			'width'     => [],
			'class'     => [],
		],
		'line'    => [ 
			'class' => [],
			'x1'    => [],
			'x2'    => [],
			'y1'    => [],
			'y2'    => [],
		],
		'style'   => [],


	];

	if ( $tag == null ) {
		return $tag_allowed;
	} elseif ( is_array( $tag ) ) {
		$new_tag_allow = [];

		foreach ( $tag as $_tag ) {
			$new_tag_allow[ $_tag ] = $tag_allowed[ $_tag ];
		}

		return $new_tag_allow;
	} else {
		return isset( $tag_allowed[ $tag ] ) ? $tag_allowed[ $tag ] : [];
	}
}

/**
 * Title HTML Tags
 */
function atomicslider_title_tags() {
	$title_tags = [ 
		'h1'   => 'H1',
		'h2'   => 'H2',
		'h3'   => 'H3',
		'h4'   => 'H4',
		'h5'   => 'H5',
		'h6'   => 'H6',
		'div'  => 'div',
		'span' => 'span',
		'p'    => 'p',
	];

	return $title_tags;
}

function atomicslider_blend_options() {
	$blend_options = [ 
		'multiply'    => esc_html__( 'Multiply', 'atomic-slider' ),
		'screen'      => esc_html__( 'Screen', 'atomic-slider' ),
		'overlay'     => esc_html__( 'Overlay', 'atomic-slider' ),
		'darken'      => esc_html__( 'Darken', 'atomic-slider' ),
		'lighten'     => esc_html__( 'Lighten', 'atomic-slider' ),
		'color-dodge' => esc_html__( 'Color-Dodge', 'atomic-slider' ),
		'color-burn'  => esc_html__( 'Color-Burn', 'atomic-slider' ),
		'hard-light'  => esc_html__( 'Hard-Light', 'atomic-slider' ),
		'soft-light'  => esc_html__( 'Soft-Light', 'atomic-slider' ),
		'difference'  => esc_html__( 'Difference', 'atomic-slider' ),
		'exclusion'   => esc_html__( 'Exclusion', 'atomic-slider' ),
		'hue'         => esc_html__( 'Hue', 'atomic-slider' ),
		'saturation'  => esc_html__( 'Saturation', 'atomic-slider' ),
		'color'       => esc_html__( 'Color', 'atomic-slider' ),
		'luminosity'  => esc_html__( 'Luminosity', 'atomic-slider' ),
	];

	return $blend_options;
}

// Position
function atomicslider_navigation_position() {
	$position_options = [ 
		'top-left'      => esc_html__( 'Top Left', 'atomic-slider' ),
		'top-center'    => esc_html__( 'Top Center', 'atomic-slider' ),
		'top-right'     => esc_html__( 'Top Right', 'atomic-slider' ),
		'center'        => esc_html__( 'Center', 'atomic-slider' ),
		'center-left'   => esc_html__( 'Center Left', 'atomic-slider' ),
		'center-right'  => esc_html__( 'Center Right', 'atomic-slider' ),
		'bottom-left'   => esc_html__( 'Bottom Left', 'atomic-slider' ),
		'bottom-center' => esc_html__( 'Bottom Center', 'atomic-slider' ),
		'bottom-right'  => esc_html__( 'Bottom Right', 'atomic-slider' ),
	];

	return $position_options;
}

function atomicslider_pagination_position() {
	$position_options = [ 
		'top-left'      => esc_html__( 'Top Left', 'atomic-slider' ),
		'top-center'    => esc_html__( 'Top Center', 'atomic-slider' ),
		'top-right'     => esc_html__( 'Top Right', 'atomic-slider' ),
		'center-left'   => esc_html__( 'Center Left', 'atomic-slider' ),
		'center-right'  => esc_html__( 'Center Right', 'atomic-slider' ),
		'bottom-left'   => esc_html__( 'Bottom Left', 'atomic-slider' ),
		'bottom-center' => esc_html__( 'Bottom Center', 'atomic-slider' ),
		'bottom-right'  => esc_html__( 'Bottom Right', 'atomic-slider' ),
	];

	return $position_options;
}

function atomicslider_position() {
	$position_options = [ 
		''              => esc_html__( 'Default', 'atomic-slider' ),
		'top-left'      => esc_html__( 'Top Left', 'atomic-slider' ),
		'top-center'    => esc_html__( 'Top Center', 'atomic-slider' ),
		'top-right'     => esc_html__( 'Top Right', 'atomic-slider' ),
		'center'        => esc_html__( 'Center', 'atomic-slider' ),
		'center-left'   => esc_html__( 'Center Left', 'atomic-slider' ),
		'center-right'  => esc_html__( 'Center Right', 'atomic-slider' ),
		'bottom-left'   => esc_html__( 'Bottom Left', 'atomic-slider' ),
		'bottom-center' => esc_html__( 'Bottom Center', 'atomic-slider' ),
		'bottom-right'  => esc_html__( 'Bottom Right', 'atomic-slider' ),
	];

	return $position_options;
}

function atomicslider_button_sizes() {
	$button_sizes = [ 
		'xs' => esc_html__( 'Extra Small', 'atomic-slider' ),
		'sm' => esc_html__( 'Small', 'atomic-slider' ),
		'md' => esc_html__( 'Medium', 'atomic-slider' ),
		'lg' => esc_html__( 'Large', 'atomic-slider' ),
		'xl' => esc_html__( 'Extra Large', 'atomic-slider' ),
	];

	return $button_sizes;
}

function atomicslider_drop_position() {
	$drop_position_options = [ 
		'bottom-left'    => esc_html__( 'Bottom Left', 'atomic-slider' ),
		'bottom-center'  => esc_html__( 'Bottom Center', 'atomic-slider' ),
		'bottom-right'   => esc_html__( 'Bottom Right', 'atomic-slider' ),
		'bottom-justify' => esc_html__( 'Bottom Justify', 'atomic-slider' ),
		'top-left'       => esc_html__( 'Top Left', 'atomic-slider' ),
		'top-center'     => esc_html__( 'Top Center', 'atomic-slider' ),
		'top-right'      => esc_html__( 'Top Right', 'atomic-slider' ),
		'top-justify'    => esc_html__( 'Top Justify', 'atomic-slider' ),
		'left-top'       => esc_html__( 'Left Top', 'atomic-slider' ),
		'left-center'    => esc_html__( 'Left Center', 'atomic-slider' ),
		'left-bottom'    => esc_html__( 'Left Bottom', 'atomic-slider' ),
		'right-top'      => esc_html__( 'Right Top', 'atomic-slider' ),
		'right-center'   => esc_html__( 'Right Center', 'atomic-slider' ),
		'right-bottom'   => esc_html__( 'Right Bottom', 'atomic-slider' ),
	];

	return $drop_position_options;
}

function atomicslider_thumbnavs_position() {
	$position_options = [ 
		'top-left'      => esc_html__( 'Top Left', 'atomic-slider' ),
		'top-center'    => esc_html__( 'Top Center', 'atomic-slider' ),
		'top-right'     => esc_html__( 'Top Right', 'atomic-slider' ),
		'center-left'   => esc_html__( 'Center Left', 'atomic-slider' ),
		'center-right'  => esc_html__( 'Center Right', 'atomic-slider' ),
		'bottom-left'   => esc_html__( 'Bottom Left', 'atomic-slider' ),
		'bottom-center' => esc_html__( 'Bottom Center', 'atomic-slider' ),
		'bottom-right'  => esc_html__( 'Bottom Right', 'atomic-slider' ),
	];

	return $position_options;
}

function atomicslider_transition_options() {

	$transition_options = [ 
		''                    => esc_html__( 'None', 'atomic-slider' ),
		'fade'                => esc_html__( 'Fade', 'atomic-slider' ),
		'scale-up'            => esc_html__( 'Scale Up', 'atomic-slider' ),
		'scale-down'          => esc_html__( 'Scale Down', 'atomic-slider' ),
		'slide-top'           => esc_html__( 'Slide Top', 'atomic-slider' ),
		'slide-bottom'        => esc_html__( 'Slide Bottom', 'atomic-slider' ),
		'slide-left'          => esc_html__( 'Slide Left', 'atomic-slider' ),
		'slide-right'         => esc_html__( 'Slide Right', 'atomic-slider' ),
		'slide-top-small'     => esc_html__( 'Slide Top Small', 'atomic-slider' ),
		'slide-bottom-small'  => esc_html__( 'Slide Bottom Small', 'atomic-slider' ),
		'slide-left-small'    => esc_html__( 'Slide Left Small', 'atomic-slider' ),
		'slide-right-small'   => esc_html__( 'Slide Right Small', 'atomic-slider' ),
		'slide-top-medium'    => esc_html__( 'Slide Top Medium', 'atomic-slider' ),
		'slide-bottom-medium' => esc_html__( 'Slide Bottom Medium', 'atomic-slider' ),
		'slide-left-medium'   => esc_html__( 'Slide Left Medium', 'atomic-slider' ),
		'slide-right-medium'  => esc_html__( 'Slide Right Medium', 'atomic-slider' ),
	];

	return $transition_options;
}

/**
 * This is a svg file converter function which return a svg content
 *
 * @param string file
 * @return false content
 */
function atomicslider_svg_icon( $icon ) {

	$icon_path = ( dirname( __FILE__ ) . 'assets/images/svg/{$icon}.svg' );

	if ( ! file_exists( $icon_path ) ) {
		return false;
	}

	ob_start();

	include $icon_path;

	$svg = ob_get_clean();

	return $svg;
}

/**
 * String to ID maker for any title to relavent id
 *
 * @param  [type] string any title or string
 *
 * @return [type]         [description]
 */
function atomicslider_string_id( $string ) {
	//Lower case everything
	$string = strtolower( $string );
	//Make alphanumeric (removes all other characters)
	$string = preg_replace( "/[^a-z0-9_\s-]/", "", $string );
	//Clean up multiple dashes or whitespaces
	$string = preg_replace( "/[\s-]+/", " ", $string );
	//Convert whitespaces and underscore to dash
	$string = preg_replace( "/[\s_]/", "-", $string );

	//finally return here
	return $string;
}

function atomicslider_template_edit_link( $template_id ) {
	if ( Plugin::instance()->editor->is_edit_mode() ) {

		$final_url = add_query_arg( [ 'elementor' => '' ], get_permalink( $template_id ) );

		$output = sprintf( '<a class="asa-elementor-template-edit-link" href="%1$s" title="%2$s" target="_blank"><i class="eicon-edit"></i></a>', esc_url( $final_url ), esc_html__( 'Edit Template', 'atomic-slider' ) );

		return $output;
	}

	return false;
}


/**
 * all array css classes will output as proper space
 *
 * @param array $classes shortcode css class as array
 *
 * @return array string
 */

 function atomicslider_get_post_types( $args = [] ) {

	$post_type_args = [ 
		'show_in_nav_menus' => true,
	];

	if ( ! empty( $args['post_type'] ) ) {
		$post_type_args['name'] = $args['post_type'];
	}

	$_post_types = get_post_types( $post_type_args, 'objects' );

	$post_types = [ '0' => esc_html__( 'Select Type', 'atomic-slider' ) ];

	foreach ( $_post_types as $post_type => $object ) {
		$post_types[ $post_type ] = $object->label;
	}

	return $post_types;
}

function atomicslider_user_roles() {
	global $wp_roles;

	if ( ! isset( $wp_roles ) ) {
		$wp_roles = new WP_Roles();
	}
	$all_roles      = $wp_roles->roles;
	$editable_roles = apply_filters( 'editable_roles', $all_roles );

	$users = [ 'asa-all-users' => 'All Users' ];

	foreach ( $editable_roles as $er => $role ) {
		$users[ $er ] = $role['name'];
	}

	return $users;
}

/**
 * [atomicslider_total_comment description]
 * @param  string $comment_type [description]
 * @return [type]               [description]
 */
function atomicslider_total_comment( $comment_type = 'total' ) {
	$comments_count = wp_count_comments();

	if ( $comment_type == 'moderated' ) {
		$output = $comments_count->moderated;
	} elseif ( $comment_type == 'approved' ) {
		$output = $comments_count->approved;
	} elseif ( $comment_type == 'spam' ) {
		$output = $comments_count->spam;
	} elseif ( $comment_type == 'trash' ) {
		$output = $comments_count->trash;
	} elseif ( $comment_type = 'total' ) {
		$output = $comments_count->total_comments;
	}

	return $output;
}

/**
 * [atomicslider_total_post description]
 * @param  string $custom_post_type [description]
 * @param  string $post_status      [description]
 * @return [type]                   [description]
 */
function atomicslider_total_post( $custom_post_type = 'post', $post_status = 'publish' ) {
	$post_count = wp_count_posts( $custom_post_type );

	if ( $post_status == 'publish' ) {
		$output = $post_count->publish;
	} elseif ( $post_status == 'draft' ) {
		$output = $post_count->draft;
	} elseif ( $post_status == 'trash' ) {
		$output = $post_count->trash;
	}

	return $output;
}

/**
 * [atomicslider_total_user description]
 * @param  string $user_type [description]
 * @return [type]            [description]
 */
function atomicslider_total_user( $user_type = 'asa-all-users' ) {
	$user_count = count_users();

	if ( $user_type == 'asa-all-users' ) {
		$output = $user_count['total_users'];
	} else {
		if ( ! empty( $user_count['avail_roles'][ $user_type ] ) ) {
			$output = $user_count['avail_roles'][ $user_type ];
		} else {
			$output = 0;
		}
	}

	return $output;
}

if ( ! function_exists( 'atomicslider_array_except' ) ) {
	/**
	 * Provide access to optional objects.
	 *
	 * @param  mixed  $value
	 * @param  callable|null  $callback
	 * @return mixed
	 */
	function atomicslider_array_except( $array, $keys ) {

		$original = &$array;

		$keys = (array) $keys;

		if ( count( $keys ) === 0 ) {
			return;
		}

		foreach ( $keys as $key ) {
			// if the exact key exists in the top-level, remove it
			if ( array_key_exists( $key, $array ) ) {
				unset( $array[ $key ] );

				continue;
			}

			$parts = explode( '.', $key );

			// clean up before each pass
			$array = &$original;

			while ( count( $parts ) > 1 ) {
				$part = array_shift( $parts );

				if ( isset( $array[ $part ] ) && is_array( $array[ $part ] ) ) {
					$array = &$array[ $part ];
				} else {
					continue 2;
				}
			}

			unset( $array[ array_shift( $parts ) ] );
		}

		return $array;
	}
}

function atomicslider_get_category( $post_type ) {
	switch ( $post_type ) {
		case 'campaign':
			$taxonomy = 'campaign_category';
			break;
		case 'lightbox_library':
			$taxonomy = 'ngg_tag';
			break;
		case 'give_forms':
			$taxonomy = 'give_forms_category';
			break;
		case 'tribe_events':
			$taxonomy = 'tribe_events_cat';
			break;
		case 'product':
			$taxonomy = 'product_cat';
			break;
		default:
			$taxonomy = 'category';
			break;
	}

	$categories  = get_the_terms( get_the_ID(), $taxonomy );
	$_categories = [];
	if ( $categories ) {
		foreach ( $categories as $category ) {
			$link                         = '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . $category->name . '</a>';
			$_categories[ $category->slug ] = $link;
		}
	}
	return implode( ' ', $_categories );
}

function atomicslider_reading_time( $content, $avg_reading_speed ) {
	$total_word      = str_word_count( strip_tags( $content ) );
	$reading_minute  = floor( $total_word / $avg_reading_speed );
	$reading_seconds = floor( $total_word % $avg_reading_speed / ( $avg_reading_speed / 60 ) );
	if ( $total_word >= $avg_reading_speed ) {
		return $reading_minute . ' min ' . $reading_seconds . ' sec read';
	} else {
		return $reading_seconds . ' sec read';
	}
}

function atomicslider_post_pagination( $wp_query, $widget_id = '' ) {

	/** Stop execution if there's only 1 page */
	if ( $wp_query->max_num_pages <= 1 ) {
		return;
	}

	if ( is_front_page() ) {
		$paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;
	} else {
		$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
	}
	$max = intval( $wp_query->max_num_pages );

	/** Add current page to the array */
	if ( $paged >= 1 ) {
		$links[] = $paged;
	}

	/** Add the pages around the current page to the array */
	if ( $paged >= 3 ) {
		$links[] = $paged - 1;
		$links[] = $paged - 2;
	}

	if ( ( $paged + 2 ) <= $max ) {
		$links[] = $paged + 2;
		$links[] = $paged + 1;
	}

	printf( '<ul class="asa-pagination" data-widget-id="%s" >' . "\n", esc_attr($widget_id) );

	/** Previous Post Link */
	if ( get_previous_posts_link() ) {
		printf( '<li class="asa-pagination-previous">%s</li>' . "\n", get_previous_posts_link( '<span data-asa-pagination-previous><i class="eicon-arrow-left" aria-hidden="true"></i></span>' ) );
	}

	/** Link to first page, plus ellipses if necessary */
	if ( ! in_array( 1, $links ) ) {
		$class = 1 == $paged ? ' class="current"' : '';

		printf( '<li%s><a href="%s">%s</a></li>' . "\n", wp_kses_post($class), esc_url( get_pagenum_link( 1 ) ), '1' );

		if ( ! in_array( 2, $links ) ) {
			echo '<li class="asa-pagination-dot-dot"><span>...</span></li>';
		}
	}

	/** Link to current page, plus 2 pages in either direction if necessary */
	sort( $links );
	foreach ( (array) $links as $link ) {
		$class = $paged == $link ? ' class="asa-active"' : '';
		printf( '<li%s><a href="%s">%s</a></li>' . "\n", wp_kses_post($class), esc_url( get_pagenum_link( $link ) ), wp_kses_post($link) );
	}

	/** Link to last page, plus ellipses if necessary */
	if ( ! in_array( $max, $links ) ) {
		if ( ! in_array( $max - 1, $links ) ) {
			echo '<li class="asa-pagination-dot-dot"><span>...</span></li>' . "\n";
		}

		$class = $paged == $max ? ' class="asa-active"' : '';
		printf( '<li%s><a href="%s">%s</a></li>' . "\n", wp_kses_post($class), esc_url( get_pagenum_link( $max ) ), wp_kses_post($max) );
	}

	/** Next Post Link */
	$next_link = get_next_posts_link( '<span data-asa-pagination-next><i class="eicon-arrow-right" aria-hidden="true"></i></span>', $max );
	if ( ! $next_link ) {
		return;
	}
	echo '<li class="asa-pagination-next">' . wp_kses_post( $next_link ) . "</li>\n";

	echo '</ul>' . "\n";
}

function atomicslider_time_diff( $from, $to = '' ) {
	$diff    = human_time_diff( $from, $to );
	$replace = array(
		' hour'    => 'h',
		' hours'   => 'h',
		' day'     => 'd',
		' days'    => 'd',
		' minute'  => 'm',
		' minutes' => 'm',
		' second'  => 's',
		' seconds' => 's',
	);

	return strtr( $diff, $replace );
}

function atomicslider_post_time_diff( $format = '' ) {
	$displayAgo = esc_html__( 'ago', 'atomic-slider' );

	if ( $format == 'short' ) {
		$output = atomicslider_time_diff( strtotime( get_the_date() ), current_time( 'timestamp' ) );
	} else {
		$output = human_time_diff( strtotime( get_the_date() ), current_time( 'timestamp' ) );
	}

	$output = $output . ' ' . $displayAgo;

	return $output;
}

/**
 * @param int $limit default limit is 25 word
 * @param bool $strip_shortcode if you want to strip shortcode from excert text
 * @param string $trail trail string default is ...
 *
 * @return string return custom limited excerpt text
 */
function atomicslider_custom_excerpt( $limit = 25, $strip_shortcode = false, $trail = '' ) {

	$output = get_the_content();

	if ( $limit ) {
		$output = wp_trim_words( $output, $limit, $trail );
	}

	if ( $strip_shortcode ) {
		$output = strip_shortcodes( $output );
	}

	return wpautop( $output );
}

/**
 * @param string category name
 * @return array of category
 */
function atomicslider_get_terms( $taxonomy = 'category', $hide_empty = false ) {

	$post_options = [];

	$post_categories = get_terms( [ 
		'taxonomy'   => $taxonomy,
		'hide_empty' => $hide_empty,
	] );

	if ( is_wp_error( $post_categories ) ) {
		return $post_options;
	}

	if ( false !== $post_categories and is_array( $post_categories ) ) {
		foreach ( $post_categories as $category ) {
			$post_options[ $category->term_id ] = $category->name;
		}
	}

	return $post_options;
}

/**
 * @param string parent category name
 * @return array of parent category
 */
function atomicslider_get_only_parent_cats( $taxonomy = 'category' ) {

	$parent_categories = [ 'none' => __( 'None', 'atomic-slider' ) ];
	$args              = [ 'parent' => 0 ];
	$parent_cats       = get_terms( $taxonomy, $args );

	foreach ( $parent_cats as $parent_cat ) {
		$parent_categories[ $parent_cat->term_id ] = ucfirst( $parent_cat->name );
	}
	return $parent_categories;
}

function atomicslider_get_taxonomies() {
	$args       = array(
		'public' => true,
	);
	$output     = [ '0' => esc_html__( 'Select Type', 'atomic-slider' ) ];
	$tax_output = 'objects'; // or objects
	$taxonomies = get_taxonomies( $args, $tax_output );
	if ( $taxonomies ) {
		foreach ( $taxonomies as $taxonomy ) {
			$post_type_obj           = get_post_type_object( $taxonomy->object_type[0] );
			$output[ $taxonomy->name ] = ( $taxonomy->label ? $taxonomy->label : '' ) . ' (' . isset( $post_type_obj->label ) . ')';
		}
	}

	return $output;
}

// add socials list meta in user profile
function atomicslider_user_contact_methods( $methods, $core = false ) {

	if ( $core ) {
		$methods['email'] = __( 'Email', 'atomic-slider' );
		$methods['url']   = __( 'Website', 'atomic-slider' );
	}

	$methods['facebook']  = __( 'Facebook', 'atomic-slider' );
	$methods['twitter']   = __( 'Twitter', 'atomic-slider' );
	$methods['linkedin']  = __( 'LinkedIn', 'atomic-slider' );
	$methods['github']    = __( 'GitHub', 'atomic-slider' );
	$methods['wordpress'] = __( 'WordPress', 'atomic-slider' );
	$methods['dribbble']  = __( 'Dribbble', 'atomic-slider' );

	return $methods;
}
add_filter( 'user_contactmethods', 'atomicslider_user_contact_methods' );


/**
 * default get_option() default value check
 *
 * @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 mixed
 */
function atomicslider_option( $option, $section, $default = '' ) {

	$options = get_option( $section );

	if ( isset( $options[ $option ] ) ) {
		return $options[ $option ];
	}

	return $default;
}
function atomicslider_get_user_role( $id ) {

	$user = new WP_User( $id );

	return array_shift( $user->roles );
}

/**
 * HexColor
 */
function atomicslider_strToHex( $string, $steps = -10 ) {

	if ( empty( $string ) ) {
		return false;
	}

	$hex_output = sprintf( '%s', substr( md5( $string ), 0, 6 ) );

	// Steps should be between -255 and 255. Negative = darker, positive = lighter
	$steps = max( -255, min( 255, $steps ) );

	// Split into three parts: R, G and B
	$color_parts = str_split( $hex_output, 2 );
	$output      = '#';

	foreach ( $color_parts as $color ) {
		$color  = hexdec( $color );                                   // Convert to decimal
		$color  = max( 0, min( 255, $color + $steps ) );              // Adjust color
		$output .= str_pad( dechex( $color ), 2, '0', STR_PAD_LEFT ); // Make two char hex code
	}

	return strToUpper( $output );
}