get_active_languages(); } } } //Retrieve default WPML language if ( ! function_exists( 'antreas_wpml_default_language' ) ) { function antreas_wpml_default_language() { if ( antreas_wpml_active() ) { global $sitepress; return $sitepress->get_default_language(); } } } //Searches for a link inside a string. Used for post formats if ( ! function_exists( 'antreas_find_link' ) ) { function antreas_find_link( $content, $fallback ) { $link_url = ''; $link_pattern = '/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/'; $post_content = $content; if ( preg_match( $link_pattern, $post_content, $link_url ) ) { return $link_url[0]; } else { return $fallback; } } } //Retrieve page number for the current post or page if ( ! function_exists( 'antreas_current_page' ) ) { function antreas_current_page() { $current_page = 1; if ( is_front_page() ) { if ( get_query_var( 'page' ) ) { $current_page = get_query_var( 'page' ); } else { $current_page = 1; } } else { if ( get_query_var( 'paged' ) ) { $current_page = get_query_var( 'paged' ); } else { $current_page = 1; } } return $current_page; } } //Retrieve current post or taxonomy id if ( ! function_exists( 'antreas_current_id' ) ) { function antreas_current_id() { $current_id = false; if ( is_tax() || is_category() || is_tag() ) { $current_id = get_queried_object()->term_id; } else { global $post; if ( isset( $post->ID ) ) { $current_id = $post->ID; } else { $current_id = false; } } return $current_id; } } //Return true if posts should be displayed on homepage function antreas_show_posts() { $display = false; if ( ! is_front_page() || antreas_get_option( 'home_posts' ) === true ) { $display = true; } return $display; } //Return true if page title should be displayed function antreas_show_title() { $display = false; if ( ! is_front_page() ) { $display = true; } return $display; } //Add shortcode functionality to text widgets add_filter( 'widget_text', 'do_shortcode' ); //Custom function to do some cleanup on nested shortcodes //Used for columns and layout-related shortcodes if ( ! function_exists( 'antreas_do_shortcode' ) ) { function antreas_do_shortcode( $content ) { $content = do_shortcode( shortcode_unautop( $content ) ); $content = preg_replace( '#^<\/p>|^|

$|

\s*( )?\s*<\/p>#', '', $content ); return $content; } } //Changes the brighness of a HEX color if ( ! function_exists( 'antreas_alter_brightness' ) ) { function antreas_alter_brightness( $colourstr, $steps ) { $colourstr = str_replace( '#', '', $colourstr ); $rhex = substr( $colourstr, 0, 2 ); $ghex = substr( $colourstr, 2, 2 ); $bhex = substr( $colourstr, 4, 2 ); $r = hexdec( $rhex ); $g = hexdec( $ghex ); $b = hexdec( $bhex ); $r = max( 0, min( 255, $r + $steps ) ); $g = max( 0, min( 255, $g + $steps ) ); $b = max( 0, min( 255, $b + $steps ) ); $r = str_pad( dechex( $r ), 2, '0', STR_PAD_LEFT ); $g = str_pad( dechex( $g ), 2, '0', STR_PAD_LEFT ); $b = str_pad( dechex( $b ), 2, '0', STR_PAD_LEFT ); return '#' . $r . $g . $b; } } add_action( 'after_switch_theme', 'antreas_rewrite_flush' ); function antreas_rewrite_flush() { flush_rewrite_rules(); } //Sanitize boolean values function antreas_sanitize_bool( $data ) { if ( $data === true ) { return true; } return false; } // Sanitize logo dimensions function antreas_sanitize_logo_dimensions( $dimensions ) { $new_dimensions = array(); if ( isset( $dimensions['width'] ) ) { $new_dimensions['width'] = abs( floatval( $dimensions['width'] ) ); } if ( isset( $dimensions['height'] ) ) { $new_dimensions['height'] = abs( floatval( $dimensions['height'] ) ); } return $new_dimensions; } //Return the URL to the premium theme page function antreas_upgrade_link( $medium = 'customizer' ) { $url = esc_url_raw( ANTREAS_PREMIUM_URL . '?utm_source=antreas&utm_medium=' . $medium . '&utm_campaign=upsell' ); return $url; } // Gets attachment url by slug from media library. function antreas_get_attachment_url_by_slug( $slug ) { $args = array( 'post_type' => 'attachment', 'name' => sanitize_title( $slug ), 'posts_per_page' => 1, 'post_status' => 'inherit', ); $_header = get_posts( $args ); $header = $_header ? array_pop( $_header ) : null; return $header ? wp_get_attachment_url( $header->ID ) : ''; }