set( 'lang', $lang ); }, 999 ); } // WPML. if ( defined( 'ICL_SITEPRESS_VERSION' ) ) { add_filter( 'wpml_current_language', function () use ( $lang ) { return $lang; }, 999 ); } } } } if ( ! function_exists( 'csco_set_ajax_locale' ) ) { /** * Set proper locale for AJAX requests */ function csco_set_ajax_locale() { // Check Nonce. wp_verify_nonce( null ); if ( isset( $_REQUEST['current_locale'] ) && $_REQUEST['current_locale'] ) { // Input var ok. $locale = sanitize_text_field( $_REQUEST['current_locale'] ); // Input var ok. // Force set locale for this request. add_filter( 'locale', function () use ( $locale ) { return $locale; }, 999 ); // Reload text domain with correct locale. if ( function_exists( 'switch_to_locale' ) ) { switch_to_locale( $locale ); } // For Loco Translate compatibility. if ( class_exists( 'Loco_Locale' ) ) { $loco_locale = Loco_Locale::parse( $locale ); if ( $loco_locale ) { apply_filters( 'loco_current_locale', $loco_locale ); } } // Reload theme textdomain. load_theme_textdomain( 'revision', get_template_directory() . '/languages' ); } } } if ( ! function_exists( 'csco_get_theme_data' ) ) { /** * Get data about the theme. * * @param mixed $name The name of param. */ function csco_get_theme_data( $name ) { $theme = wp_get_theme( get_template() ); return $theme->get( $name ); } } if ( ! function_exists( 'csco_encode_data' ) ) { /** * Encode data * * @param mixed $content The content. * @param string $secret_key The key. * @return string */ function csco_encode_data( $content, $secret_key = 'revision' ) { $content = wp_json_encode( $content ); return call_user_func( sprintf( 'base64_%s', 'encode' ), $content ); } } if ( ! function_exists( 'csco_decode_data' ) ) { /** * Decode data * * @param string $content The content. * @param string $secret_key The key. * @return string */ function csco_decode_data( $content, $secret_key = 'revision' ) { $content = call_user_func( sprintf( 'base64_%s', 'decode' ), $content ); return json_decode( $content, true ); } } if ( ! function_exists( 'csco_hex2rgba' ) ) { /** * Convert hex to rgb. * * @param mixed $hex Color. * @param bool $format Format. */ function csco_hex2rgba( $hex, $format = true ) { $hex = trim( $hex, ' #' ); $size = strlen( $hex ); if ( 3 === $size || 4 === $size ) { $parts = str_split( $hex, 1 ); $hex = ''; foreach ( $parts as $row ) { $hex .= $row . $row; } } $dec = hexdec( $hex ); $rgb = array(); if ( 3 === $size || 6 === $size ) { $rgb['red'] = 0xFF & ( $dec >> 0x10 ); $rgb['green'] = 0xFF & ( $dec >> 0x8 ); $rgb['blue'] = 0xFF & $dec; $output = implode( ',', $rgb ); if ( $format ) { $output = sprintf( 'rgba(%s, 1)', $output ); } return $output; } elseif ( 5 === $size || 8 === $size ) { $rgb['red'] = 0xFF & ( $dec >> 0x16 ); $rgb['green'] = 0xFF & ( $dec >> 0x10 ); $rgb['blue'] = 0xFF & ( $dec >> 0x8 ); $output = implode( ',', $rgb ); if ( $format ) { $alpha = 0xFF & $dec; $output = sprintf( 'rgba(%s, %s)', $output, round( ( $alpha / ( 255 / 100 ) ) / 100, 2 ) ); } return $output; } } } if ( ! function_exists( 'csco_rgba2hex' ) ) { /** * Convert rgba to hex. * * @param mixed $color Color. */ function csco_rgba2hex( $color ) { if ( isset( $color[0] ) && '#' === $color[0] ) { return $color; } $rgba = array(); if ( preg_match_all( '#\((([^()]+|(?R))*)\)#', $color, $matches ) ) { $rgba = explode( ',', implode( ' ', $matches[1] ) ); } else { $rgba = explode( ',', $color ); } $rr = dechex( $rgba['0'] ); $gg = dechex( $rgba['1'] ); $bb = dechex( $rgba['2'] ); if ( array_key_exists( '3', $rgba ) ) { $aa = dechex( $rgba['3'] * 255 ); return strtoupper( "#$aa$rr$gg$bb" ); } else { return strtoupper( "#$rr$gg$bb" ); } } } if ( ! function_exists( 'csco_get_round_number' ) ) { /** * Get rounded number. * * @param int $number Input number. * @param int $min_value Minimum value to round number. * @param int $decimal How may decimals shall be in the rounded number. */ function csco_get_round_number( $number, $min_value = 1000, $decimal = 1 ) { if ( $number < $min_value ) { return number_format_i18n( $number ); } $alphabets = array( 1000000000 => esc_html__( 'B', 'revision' ), 1000000 => esc_html__( 'M', 'revision' ), 1000 => esc_html__( 'K', 'revision' ), ); foreach ( $alphabets as $key => $value ) { if ( $number >= $key ) { return number_format_i18n( round( $number / $key, $decimal ), $decimal ) . $value; } } } } if ( ! function_exists( 'csco_the_round_number' ) ) { /** * Echo rounded number. * * @param int $number Input number. * @param int $min_value Minimum value to round number. * @param int $decimal How may decimals shall be in the rounded number. */ function csco_the_round_number( $number, $min_value = 1000, $decimal = 1 ) { echo esc_html( csco_get_round_number( $number, $min_value, $decimal ) ); } } if ( ! function_exists( 'csco_str_truncate' ) ) { /** * Truncates string with specified length * * @param string $string Text string. * @param int $length Letters length. * @param string $etc End truncate. * @param bool $break_words Break words or not. * @return string */ function csco_str_truncate( $string, $length = 80, $etc = '…', $break_words = false ) { if ( 0 === $length ) { return ''; } if ( function_exists( 'mb_strlen' ) ) { // MultiBite string functions. if ( mb_strlen( $string ) > $length ) { $length -= min( $length, mb_strlen( $etc ) ); if ( ! $break_words ) { $string = preg_replace( '/\s+?(\S+)?$/', '', mb_substr( $string, 0, $length + 1 ) ); } return mb_substr( $string, 0, $length ) . $etc; } } else { // Default string functions. if ( strlen( $string ) > $length ) { $length -= min( $length, strlen( $etc ) ); if ( ! $break_words ) { $string = preg_replace( '/\s+?(\S+)?$/', '', substr( $string, 0, $length + 1 ) ); } return substr( $string, 0, $length ) . $etc; } } return $string; } } if ( ! function_exists( 'csco_convert_retina_link' ) ) { /** * Convert retina link. * * @param array $dirname Dirname. * @param string $filename Original filename. * @param string $extension File extension. * * @return string Converted URL with the '@2x' suffix. */ function csco_convert_retina_link( $dirname, $filename, $extension ) { $filename_parts = explode( '-', $filename ); $last_part = end( $filename_parts ); if ( is_numeric( $last_part ) ) { array_pop( $filename_parts ); } $filename = implode( '-', $filename_parts ); $filename = $filename . '@2x'; if ( is_numeric( $last_part ) ) { $filename = $filename . '-' . $last_part; } $new_url = $dirname . '/' . $filename . '.' . $extension; return $new_url; } } if ( ! function_exists( 'csco_get_retina_image' ) ) { /** * Get retina image. * * @param int $attachment_id Image attachment ID. * @param array $attr Attributes for the image markup. Default empty. * @param string $type The tag of type. */ function csco_get_retina_image( $attachment_id, $attr = array(), $type = 'img' ) { $attachment_url = wp_get_attachment_url( $attachment_id ); // Retina image. $attached_file = get_attached_file( $attachment_id ); if ( $attached_file ) { $uriinfo = pathinfo( $attachment_url ); $pathinfo = pathinfo( $attached_file ); $retina_uri = sprintf( '%s/%s@2x.%s', $uriinfo['dirname'], $uriinfo['filename'], $uriinfo['extension'] ); $retina_file = sprintf( '%s/%s@2x.%s', $pathinfo['dirname'], $pathinfo['filename'], $pathinfo['extension'] ); if ( file_exists( $retina_file ) ) { $attr['srcset'] = sprintf( '%s 1x, %s 2x', $attachment_url, $retina_uri ); } else { $retina_uri = csco_convert_retina_link( $uriinfo['dirname'], $uriinfo['filename'], $uriinfo['extension'] ); $retina_file = csco_convert_retina_link( $pathinfo['dirname'], $pathinfo['filename'], $pathinfo['extension'] ); if ( file_exists( $retina_file ) ) { $attr['srcset'] = sprintf( '%s 1x, %s 2x', $attachment_url, $retina_uri ); } } } // Sizes. if ( 'amp-img' === $type || 'logo' === $type ) { $data = wp_get_attachment_image_src( $attachment_id, 'full' ); if ( isset( $data[1] ) ) { $attr['width'] = $data[1]; } if ( isset( $data[2] ) ) { $attr['height'] = $data[2]; } // Calc max height and set new width depending on proportion. if ( isset( $attr['width'] ) && isset( $attr['height'] ) ) { /** * The csco_amp_navbar_height hook. * * @since 1.0.0 */ if ( 'amp-img' === $type ) { $max_height = apply_filters( 'csco_amp_navbar_height', 88 ) - 20; } elseif ( 'logo' === $type ) { $header_height = get_theme_mod( 'header_height', 88 ); $header_height = (int) $header_height; $max_height = $header_height - 20; } if ( $max_height > 0 && $attr['height'] > $max_height ) { $attr['width'] = $attr['width'] / $attr['height'] * $max_height; $attr['height'] = $max_height; } } if ( 'logo' === $type ) { $type = 'img'; } } // Attr. $output = __return_null(); foreach ( $attr as $name => $value ) { $output .= sprintf( ' %s="%s" ', esc_attr( $name ), esc_attr( $value ) ); } // Image output. call_user_func( 'printf', '<%1$s src="%2$s" %3$s>', esc_attr( $type ), esc_url( $attachment_url ), $output ); } } if ( ! function_exists( 'csco_offcanvas_exists' ) ) { /** * Check if offcanvas exists. */ function csco_offcanvas_exists() { $locations = get_nav_menu_locations(); if ( isset( $locations['primary'] ) || isset( $locations['mobile'] ) || is_active_sidebar( 'sidebar-offcanvas' ) ) { return true; } } } if ( ! function_exists( 'csco_site_content_class' ) ) { /** * Display the classes for the cs-site-content element. * * @param array $class Classes to add to the class list. */ function csco_site_content_class( $class = array() ) { $class[] = 'cs-site-content'; /** * The csco_site_content_class hook. * * @since 1.0.0 */ $class = apply_filters( 'csco_site_content_class', $class ); // Separates classes with a single space, collates classes. printf( 'class="%s"', esc_attr( join( ' ', $class ) ) ); } } if ( ! function_exists( 'csco_site_submenu_class' ) ) { /** * Display the classes for the site-submenu element. * * @param array $class Classes to add to the class list. */ function csco_site_submenu_class( $class = array() ) { $class[] = 'cs-site-submenu'; /** * The csco_site_submenu_class hook. * * @since 1.0.0 */ $class = apply_filters( 'csco_site_submenu_class', $class ); // Separates classes with a single space, collates classes. printf( 'class="%s"', esc_attr( join( ' ', $class ) ) ); } } if ( ! function_exists( 'csco_site_scheme_data' ) ) { /** * Get site scheme data */ function csco_site_scheme_data() { // Get options. $color_scheme = get_theme_mod( 'color_scheme', 'system' ); // Field. User’s system preference. $color_toggle = get_theme_mod( 'color_scheme_toggle', true ); // Field. Enable dark/light mode toggle. // Set site scheme. $site_scheme = __return_empty_string(); switch ( $color_scheme ) { case 'dark': $site_scheme = 'dark'; break; case 'light': $site_scheme = 'light'; break; case 'system': $site_scheme = 'auto'; break; } if ( $color_toggle ) { if ( isset( $_COOKIE['_color_schema'] ) && 'light' === $_COOKIE['_color_schema'] ) { $site_scheme = 'light'; } if ( isset( $_COOKIE['_color_schema'] ) && 'dark' === $_COOKIE['_color_schema'] ) { $site_scheme = 'dark'; } } return $site_scheme; } } if ( ! function_exists( 'csco_get_the_excerpt' ) ) { /** * Filters the number of words in an excerpt. */ function csco_get_the_excerpt_length() { return 5000; } /** * Get excerpt of post. * * @param int $length Letters length. * @param string $etc End truncate. * @param bool $break_words Break words or not. */ function csco_get_the_excerpt( $length = 80, $etc = '…', $break_words = false ) { add_filter( 'excerpt_length', 'csco_get_the_excerpt_length' ); $excerpt = get_the_excerpt(); call_user_func( 'remove_filter', 'excerpt_length', 'csco_get_the_excerpt_length' ); return csco_str_truncate( $excerpt, $length, $etc, $break_words ); } } if ( ! function_exists( 'csco_get_archive_location' ) ) { /** * Returns Archive Location. */ function csco_get_archive_location() { global $wp_query; if ( isset( $wp_query->query_vars['csco_query']['location'] ) ) { return $wp_query->query_vars['csco_query']['location']; } if ( is_home() ) { return 'home'; } else { return 'archive'; } } } if ( ! function_exists( 'csco_get_archive_option' ) ) { /** * Returns Archive Option Name. * * @param string $option_name The customize option name. */ function csco_get_archive_option( $option_name ) { return csco_get_archive_location() . '_' . $option_name; } } if ( ! function_exists( 'csco_get_archive_options' ) ) { /** * Returns Archive Options. */ function csco_get_archive_options() { $options = array( 'location' => csco_get_archive_location(), 'meta' => csco_get_archive_option( 'post_meta' ), 'layout' => get_theme_mod( csco_get_archive_option( 'layout' ), 'list' ), 'columns' => get_theme_mod( csco_get_archive_option( 'columns_desktop' ), 2 ), 'image_orientation' => get_theme_mod( csco_get_archive_option( 'image_orientation' ), 'landscape-16-9' ), 'image_size' => get_theme_mod( csco_get_archive_option( 'image_size' ), 'csco-thumbnail' ), 'summary_type' => get_theme_mod( csco_get_archive_option( 'summary' ), 'summary' ), 'excerpt' => get_theme_mod( csco_get_archive_option( 'excerpt' ), true ), 'discover_more' => get_theme_mod( csco_get_archive_option( 'discover_more' ), true ), ); /** * The csco_get_archive_options hook. * * @since 1.0.0 */ $options = apply_filters( 'csco_get_archive_options', $options ); return $options; } } if ( ! function_exists( 'csco_get_page_preview' ) ) { /** * Returns Page Preview. */ function csco_get_page_preview() { if ( is_home() ) { /** * The csco_page_media_preview hook. * * @since 1.0.0 */ return apply_filters( 'csco_page_media_preview', get_theme_mod( 'home_media_preview', 'cropped' ) ); } if ( is_singular( array( 'post', 'page' ) ) ) { $post_type = get_post_type( get_queried_object_id() ); /** * The csco_page_media_preview hook. * * @since 1.0.0 */ return apply_filters( 'csco_page_media_preview', get_theme_mod( $post_type . '_media_preview', 'cropped' ) ); } if ( is_archive() ) { /** * The csco_page_media_preview hook. * * @since 1.0.0 */ return apply_filters( 'csco_page_media_preview', get_theme_mod( 'archive_media_preview', 'cropped' ) ); } if ( is_404() ) { /** * The csco_page_media_preview hook. * * @since 1.0.0 */ return apply_filters( 'csco_page_media_preview', 'cropped' ); } /** * The csco_page_media_preview hook. * * @since 1.0.0 */ return apply_filters( 'csco_page_media_preview', 'cropped' ); } } if ( ! function_exists( 'csco_get_page_sidebar' ) ) { /** * Returns Page Sidebar: right, left or disabled. * * @param int $post_id The ID of post. * @param string $layout The layout of post. */ function csco_get_page_sidebar( $post_id = false, $layout = false ) { /** * The csco_sidebar hook. * * @since 1.0.0 */ $location = apply_filters( 'csco_sidebar', 'sidebar-main' ); if ( ! is_active_sidebar( $location ) ) { return 'disabled'; } $home_id = false; if ( 'page' === get_option( 'show_on_front', 'posts' ) ) { $page_on_front = get_option( 'page_on_front' ); if ( $post_id && intval( $post_id ) === intval( $page_on_front ) ) { $home_id = $post_id; } } if ( is_home() || $home_id ) { $show_on_front = get_option( 'show_on_front', 'posts' ); if ( 'posts' === $show_on_front ) { return apply_filters( 'csco_page_sidebar', get_theme_mod( 'home_sidebar', 'right' ) ); } if ( 'page' === $show_on_front ) { $home_id = $home_id ? $home_id : get_queried_object_id(); // Get layout for the blog posts page. if ( ! $layout ) { $layout = get_post_meta( $home_id, 'csco_singular_sidebar', true ); } if ( ! $layout || 'default' === $layout ) { return apply_filters( 'csco_page_sidebar', get_theme_mod( 'page_sidebar', 'disabled' ) ); } return apply_filters( 'csco_page_sidebar', $layout ); } } if ( is_singular( array( 'post', 'page' ) ) || $post_id ) { $post_id = $post_id ? $post_id : get_queried_object_id(); // Get layout for current post. if ( ! $layout ) { $layout = get_post_meta( $post_id, 'csco_singular_sidebar', true ); } if ( ! $layout || 'default' === $layout ) { $post_type = get_post_type( $post_id ); return apply_filters( 'csco_page_sidebar', get_theme_mod( $post_type . '_sidebar', 'right' ) ); } return apply_filters( 'csco_page_sidebar', $layout ); } if ( is_archive() ) { return apply_filters( 'csco_page_sidebar', get_theme_mod( 'archive_sidebar', 'right' ) ); } if ( is_search() ) { return apply_filters( 'csco_page_sidebar', 'disabled' ); } if ( is_404() ) { return apply_filters( 'csco_page_sidebar', 'disabled' ); } return apply_filters( 'csco_page_sidebar', 'disabled' ); } } if ( ! function_exists( 'csco_get_page_header_type' ) ) { /** * Returns Page Header */ function csco_get_page_header_type() { $allow = array( 'none', 'standard', 'split', 'overlay', 'title' ); if ( is_singular( array( 'post', 'page' ) ) ) { $page_header_type = get_post_meta( get_queried_object_id(), 'csco_page_header_type', true ); if ( ! in_array( $page_header_type, $allow, true ) || 'default' === $page_header_type ) { $post_type = get_post_type( get_queried_object_id() ); /** * The csco_page_header_type hook. * * @since 1.0.0 */ return apply_filters( 'csco_page_header_type', get_theme_mod( $post_type . '_header_type', 'standard' ) ); } /** * The csco_page_header_type hook. * * @since 1.0.0 */ return apply_filters( 'csco_page_header_type', $page_header_type ); } /** * The csco_page_header_type hook. * * @since 1.0.0 */ return apply_filters( 'csco_page_header_type', 'standard' ); } } if ( ! function_exists( 'csco_post_views_enabled' ) ) { /** * Check post views module. * * @return string Type. */ function csco_post_views_enabled() { // Post Views Counter. if ( class_exists( 'Post_Views_Counter' ) ) { return 'post_views'; } } } if ( ! function_exists( 'csco_get_page_id_by_title' ) ) { /** * Get page id by title * * @param string $title Page title. */ function csco_get_page_id_by_title( $title ) { $query = new WP_Query(); $pages = $query->query( array( 'post_type' => 'page', 'title' => $title, ) ); if ( $pages ) { foreach ( $pages as $find_page ) { return $find_page->ID; } } } } if ( ! function_exists( 'csco_breadcrumbs' ) ) { /** * SEO Breadcrumbs */ function csco_breadcrumbs() { if ( csco_doing_request() ) { return; } ob_start(); $wrap_before = ''; if ( function_exists( 'yoast_breadcrumb' ) ) { yoast_breadcrumb( '' ); } elseif ( function_exists( 'rank_math_the_breadcrumbs' ) ) { $args = array( 'wrap_before' => $wrap_before, 'wrap_after' => $wrap_after, ); rank_math_the_breadcrumbs( $args ); } elseif ( function_exists( 'aioseo_breadcrumbs' ) ) { $breadcrumbs = str_replace( '
', $wrap_before, aioseo_breadcrumbs( false ) ); echo wp_kses_post( $breadcrumbs ); } $output_breadcrumbs = ob_get_clean(); /** * The csco_breadcrumbs hook. * * @since 1.0.0 */ $output_breadcrumbs = apply_filters( 'csco_breadcrumbs', $output_breadcrumbs ); $header_type = csco_get_page_header_type(); call_user_func( 'printf', '%s', $output_breadcrumbs ); } } if ( ! function_exists( 'csco_get_available_image_sizes' ) ) { /** * Get the available image sizes */ function csco_get_available_image_sizes() { $wais = & $GLOBALS['_wp_additional_image_sizes']; $sizes = array(); $image_sizes = get_intermediate_image_sizes(); if ( is_array( $image_sizes ) && $image_sizes ) { foreach ( $image_sizes as $size ) { if ( in_array( $size, array( 'thumbnail', 'medium', 'medium_large', 'large' ), true ) ) { $sizes[ $size ] = array( 'width' => get_option( "{$size}_size_w" ), 'height' => get_option( "{$size}_size_h" ), 'crop' => (bool) get_option( "{$size}_crop" ), ); } elseif ( isset( $wais[ $size ] ) ) { $sizes[ $size ] = array( 'width' => $wais[ $size ]['width'], 'height' => $wais[ $size ]['height'], 'crop' => $wais[ $size ]['crop'], ); } // Size registered, but has 0 width and height. if ( 0 === (int) $sizes[ $size ]['width'] && 0 === (int) $sizes[ $size ]['height'] ) { unset( $sizes[ $size ] ); } } } return $sizes; } } if ( ! function_exists( 'csco_get_image_size' ) ) { /** * Gets the data of a specific image size. * * @param string $size Name of the size. */ function csco_get_image_size( $size ) { if ( ! is_string( $size ) ) { return; } $sizes = csco_get_available_image_sizes(); return isset( $sizes[ $size ] ) ? $sizes[ $size ] : false; } } if ( ! function_exists( 'csco_get_list_available_image_sizes' ) ) { /** * Get the list available image sizes */ function csco_get_list_available_image_sizes() { $image_sizes = wp_cache_get( 'csco_available_image_sizes' ); if ( empty( $image_sizes ) ) { $image_sizes = array(); $intermediate_image_sizes = get_intermediate_image_sizes(); foreach ( $intermediate_image_sizes as $size ) { $image_sizes[ $size ] = $size; $data = csco_get_image_size( $size ); if ( isset( $data['width'] ) || isset( $data['height'] ) ) { $width = '~'; $height = '~'; if ( isset( $data['width'] ) && $data['width'] ) { $width = $data['width'] . 'px'; } if ( isset( $data['height'] ) && $data['height'] ) { $height = $data['height'] . 'px'; } $image_sizes[ $size ] .= sprintf( ' [%s, %s]', $width, $height ); } } wp_cache_set( 'csco_available_image_sizes', $image_sizes ); } return $image_sizes; } } if ( ! function_exists( 'csco_get_hero_query_args' ) ) { /** * Get query arguments for the hero section. */ function csco_get_hero_query_args() { $args = array( 'post_type' => 'post', 'posts_per_page' => 4, 'ignore_sticky_posts' => true, ); $max_count = get_theme_mod( 'home_hero_max_count', 3 ); switch ( get_theme_mod( 'home_hero_layout', 'hero-type-1' ) ) { case 'hero-type-2': if ( ! empty( $max_count ) ) { $args['posts_per_page'] = $max_count; } break; } $hero_filter_posts = get_theme_mod( 'home_hero_filter_posts' ); $hero_posts = ! empty( $hero_filter_posts ) ? explode( ',', $hero_filter_posts ) : array(); if ( ! empty( $hero_posts ) ) { $args['post__in'] = $hero_posts; $args['orderby'] = 'post__in'; } $hero_filter_tags = get_theme_mod( 'home_hero_filter_tags' ); $hero_tags = ! empty( $hero_filter_tags ) ? explode( ',', $hero_filter_tags ) : array(); if ( ! empty( $hero_tags ) ) { $args['tax_query'] = array( array( 'taxonomy' => 'post_tag', 'field' => 'slug', 'terms' => $hero_tags, ), ); } $hero_filter_categories = get_theme_mod( 'home_hero_filter_categories' ); $hero_categories = ! empty( $hero_filter_categories ) ? explode( ',', $hero_filter_categories ) : array(); if ( ! empty( $hero_categories ) ) { $args['tax_query'] = array( array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => $hero_categories, ), ); } return apply_filters( 'csco_get_hero_query_args', $args ); } } if ( ! function_exists( 'csco_user_social_links' ) ) { /** * User Social URLs */ function csco_user_social_links() { $options = array( 'facebook' => array( 'key' => 'facebook', 'icon' => '', ), 'twitter' => array( 'key' => 'twitter', 'prepend' => 'https://twitter.com/', 'icon' => '', ), 'instagram' => array( 'key' => 'instagram', 'icon' => '', ), 'linkedin' => array( 'key' => 'linkedin', 'icon' => '', ), 'myspace' => array( 'key' => 'myspace', 'icon' => '', ), 'pinterest' => array( 'key' => 'pinterest', 'icon' => '', ), 'youtube' => array( 'key' => 'youtube', 'icon' => '', ), 'soundcloud' => array( 'key' => 'soundcloud', 'icon' => '', ), 'tumblr' => array( 'key' => 'tumblr', 'icon' => '', ), 'wikipedia' => array( 'key' => 'wikipedia', 'icon' => '', ), ); $output = array(); foreach ( $options as $social => $settings ) { $url = get_user_meta( get_the_author_meta( 'ID' ), $settings['key'], true ); if ( 'twitter' === $social && $url ) { $url = sprintf( 'https://twitter.com/%s/', $url ); } if ( $url && ! empty( $settings['icon'] ) ) { $output[] = '' . $settings['icon'] . '' . $social . ''; } } if ( ! empty( $output ) ) { call_user_func( 'printf', '%s', '' ); } } } if ( ! function_exists( 'csco_get_read_next_post_ids' ) ) { /** * Retrieve read next posts. * * Will retrive the newer posts from the current category, * if the limit is not reached it will add older posts from current category, * if the limit still not reached it will add posts from other categories. * * @param int $limit Optional. Number of posts to return. * @param int $read_next_posts Optional. Post sorting. */ function csco_get_read_next_post_ids( $limit = 4, $read_next_posts = 'after' ) { $post_ids = array(); $current_post_id = get_the_ID(); $exclude_post_ids = array( $current_post_id ); $current_post_categories = wp_get_post_categories( $current_post_id, array( 'fields' => 'ids' ) ); $order = 'ASC'; $date_query_param = 'after'; if ( 'before' === $read_next_posts ) { $order = 'DESC'; $date_query_param = 'before'; } if ( 'new' === $read_next_posts ) { $order = 'DESC'; $date_query_param = 'after'; } $args = array( 'post_type' => 'post', 'posts_per_page' => $limit, 'post_status' => 'publish', 'orderby' => 'date', 'order' => $order, 'date_query' => array( $date_query_param => get_the_time( 'Y-m-d H:i:s', $current_post_id ), ), 'ignore_sticky_posts' => true, 'cat' => $current_post_categories, ); $next_posts_query = new WP_Query( $args ); if ( $next_posts_query->have_posts() ) { $post_ids = wp_list_pluck( $next_posts_query->posts, 'ID' ); $exclude_post_ids = array_merge( $exclude_post_ids, $post_ids ); } $posts_count = count( $post_ids ); if ( $posts_count < $limit ) { $posts_to_fetch = $limit - $posts_count; $category = get_the_category( $current_post_id ); if ( isset( $category[0] ) ) { $category_id = $category[0]->term_id; $args_category = array( 'post_type' => 'post', 'posts_per_page' => $posts_to_fetch, 'cat' => $category_id, 'post_status' => 'publish', 'orderby' => 'date', 'order' => $order, 'ignore_sticky_posts' => true, 'cat' => $current_post_categories, 'post__not_in' => $exclude_post_ids, ); $category_query = new WP_Query( $args_category ); if ( $category_query->have_posts() ) { $category_post_ids = wp_list_pluck( $category_query->posts, 'ID' ); $post_ids = array_merge( $post_ids, $category_post_ids ); $exclude_post_ids = array_merge( $exclude_post_ids, $post_ids ); } } } $posts_count = count( $post_ids ); if ( $posts_count < $limit ) { $posts_to_fetch = $limit - $posts_count; $args_additional = array( 'post_type' => 'post', 'posts_per_page' => $posts_to_fetch, 'post_status' => 'publish', 'orderby' => 'date', 'ignore_sticky_posts' => true, 'post__not_in' => $exclude_post_ids, ); $additional_posts_query = new WP_Query( $args_additional ); if ( $additional_posts_query->have_posts() ) { $additional_post_ids = wp_list_pluck( $additional_posts_query->posts, 'ID' ); $post_ids = array_merge( $post_ids, $additional_post_ids ); } } wp_reset_postdata(); return $post_ids; } } if ( ! function_exists( 'csco_calculate_post_reading_time' ) ) { /** * Calculate Post Reading Time in Minutes * * @param int $post_id The post ID. */ function csco_calculate_post_reading_time( $post_id = null ) { if ( ! $post_id ) { $post_id = get_the_ID(); } $post_content = get_post_field( 'post_content', $post_id ); $strip_shortcodes = strip_shortcodes( $post_content ); $strip_tags = wp_strip_all_tags( $strip_shortcodes ); $str = preg_replace( '/[[:punct:]]/', '', $strip_tags ); $str = preg_replace( '/[\s]+/', ' ', $str ); $word_count = count( (array) array_filter( (array) explode( ' ', $str ) ) ); $reading_time = intval( ceil( $word_count / 265 ) ); // Filter for Reading Time. if ( function_exists( 'iconv_strlen' ) ) { $reading_time = apply_filters( 'csco_calculate_reading_time', $reading_time, iconv_strlen( $strip_tags ) ); } else { $reading_time = apply_filters( 'csco_calculate_reading_time', $reading_time, mb_strlen( $strip_tags ) ); } return $reading_time; } } if ( ! function_exists( 'csco_get_post_reading_time' ) ) { /** * Get Post Reading Time from Post Meta * * @param int $post_id The post ID. */ function csco_get_post_reading_time( $post_id = null ) { if ( ! $post_id ) { $post_id = get_the_ID(); } // Get existing post meta. $reading_time = get_post_meta( $post_id, '_csco_reading_time', true ); // Calculate and save reading time, if there's no existing post meta. if ( ! $reading_time ) { $reading_time = csco_calculate_post_reading_time( $post_id ); update_post_meta( $post_id, '_csco_reading_time', $reading_time ); } return $reading_time; } } if ( ! function_exists( 'csco_detect_color_scheme' ) ) { /** * Detect color scheme. * * @param mixed $color Color. * @param int $level Detect level. */ function csco_detect_color_scheme( $color, $level = 190 ) { // Trim color. $color = trim( $color ); // Excludes. if ( in_array( $color, array( '#0e131a' ), true ) ) { return 'dark'; } // Set alpha channel. $alpha = 1; $rgba = array( 255, 255, 255 ); // If HEX format. if ( isset( $color[0] ) && '#' === $color[0] ) { // Remove '#' from start. $color = str_replace( '#', '', trim( $color ) ); if ( 3 === strlen( $color ) ) { $color = $color[0] . $color[0] . $color[1] . $color[1] . $color[2] . $color[2]; } $rgba[0] = hexdec( substr( $color, 0, 2 ) ); $rgba[1] = hexdec( substr( $color, 2, 2 ) ); $rgba[2] = hexdec( substr( $color, 4, 2 ) ); } elseif ( preg_match_all( '#\((([^()]+|(?R))*)\)#', $color, $color_reg ) ) { // Convert RGB or RGBA. $rgba = explode( ',', implode( ' ', $color_reg[1] ) ); if ( array_key_exists( '3', $rgba ) ) { $alpha = (float) $rgba['3']; } } // Apply alpha channel. foreach ( $rgba as $key => $channel ) { $rgba[ $key ] = str_pad( $channel + ceil( ( 255 - $channel ) * ( 1 - $alpha ) ), 2, '0', STR_PAD_LEFT ); } // Set default scheme. $scheme = 'light'; // Get brightness. $brightness = ( ( $rgba[0] * 299 ) + ( $rgba[1] * 587 ) + ( $rgba[2] * 114 ) ) / 1000; // If color gray. if ( $rgba[0] === $rgba[1] && $rgba[1] === $rgba[2] ) { if ( $brightness < $level ) { $scheme = 'dark'; } } elseif ( $brightness < $level ) { $scheme = 'inverse'; } return $scheme; } } if ( ! function_exists( 'csco_color_scheme' ) ) { /** * Output color scheme. * * @param mixed $light Light color. * @param mixed $dark Dark color. */ function csco_color_scheme( $light, $dark = '' ) { $data = csco_site_scheme_data(); $site_scheme = csco_site_scheme_data(); if ( 'auto' === $site_scheme ) { return sprintf( 'data-scheme="auto" data-l="%s" data-d="%s"', csco_detect_color_scheme( $light ), csco_detect_color_scheme( $dark ) ); } if ( 'dark' === $site_scheme ) { $scheme = csco_detect_color_scheme( $dark ); } else { $scheme = csco_detect_color_scheme( $light ); } return sprintf( 'data-scheme="%s"', $scheme ); } } if ( ! function_exists( 'csco_header_scheme_attr' ) ) { /** * Get Site Header scheme attribute * * @param bool $is_echo Optional. Whether to echo or return the classes. Default true for echo. */ function csco_header_scheme_attr( $is_echo = false ) { $scheme = csco_color_scheme( get_theme_mod( 'color_header_background', '#FFFFFF' ), get_theme_mod( 'color_header_background_is_dark', '#161616' ) ); $scheme_attr = apply_filters( 'csco_header_scheme_attr', $scheme ); if ( $is_echo ) { echo wp_kses( $scheme_attr, 'csco' ); } else { return $scheme_attr; } } } if ( ! function_exists( 'csco_header_attr' ) ) { /** * Get Site Header attributes */ function csco_header_attr() { $attributes = csco_header_scheme_attr(); echo wp_kses( apply_filters( 'csco_header_attr', $attributes ), 'csco' ); } } if ( ! function_exists( 'csco_footer_scheme_attr' ) ) { /** * Get Site Footer scheme attribute * * @param bool $is_echo Optional. Whether to echo or return the classes. Default false for echo. */ function csco_footer_scheme_attr( $is_echo = false ) { $scheme = csco_color_scheme( get_theme_mod( 'color_footer_background', '#FFFFFF' ), get_theme_mod( 'color_footer_background_dark', '#161616' ) ); $scheme_attr = apply_filters( 'csco_footer_scheme_attr', $scheme ); if ( $is_echo ) { echo wp_kses( $scheme_attr, 'csco' ); } else { return $scheme_attr; } } } if ( ! function_exists( 'csco_footer_attr' ) ) { /** * Get Site Footer attributes */ function csco_footer_attr() { $attributes = csco_footer_scheme_attr(); echo wp_kses( apply_filters( 'csco_footer_attr', $attributes ), 'csco' ); } } if ( ! function_exists( 'csco_offcanvas_scheme_attr' ) ) { /** * Get Site Offcanvas scheme attribute * * @param bool $is_echo Optional. Whether to echo or return the classes. Default true for echo. */ function csco_offcanvas_scheme_attr( $is_echo = false ) { $scheme = csco_color_scheme( get_theme_mod( 'color_offcanvas_background', '#FFFFFF' ), get_theme_mod( 'color_offcanvas_background_is_dark', '#161616' ) ); $scheme_attr = apply_filters( 'csco_offcanvas_scheme_attr', $scheme ); if ( $is_echo ) { echo wp_kses( $scheme_attr, 'csco' ); } else { return $scheme_attr; } } } if ( ! function_exists( 'csco_offcanvas_attr' ) ) { /** * Get Site Offcanvas attributes */ function csco_offcanvas_attr() { $attributes = csco_offcanvas_scheme_attr(); echo wp_kses( apply_filters( 'csco_offcanvas_attr', $attributes ), 'csco' ); } } /** * Add Fields to User Profile. * * @param object $user The user details. */ function add_csco_user_profile_fields( $user ) { ?>

comment_post_ID ); $is_by_post_author = ( $comment->user_id === $post_author_id ); $has_children = ! empty( $args['has_children'] ); $comment_author_id = $comment->user_id; ?> < id="comment-">
0 ) { // If the user has authored posts, use the author link. ?>
comment_approved ) { ?>
$depth, 'max_depth' => $args['max_depth'], ) ) ); ?>