'; } } add_action( 'wp_head', 'arrival_pingback_header' ); /** * Adds async/defer attributes to enqueued / registered scripts. * * If #12009 lands in WordPress, this function can no-op since it would be handled in core. * * @link https://core.trac.wordpress.org/ticket/12009 * @param string $tag The script tag. * @param string $handle The script handle. * @return array */ function arrival_filter_script_loader_tag( $tag, $handle ) { foreach ( array( 'async', 'defer' ) as $attr ) { if ( ! wp_scripts()->get_data( $handle, $attr ) ) { continue; } // Prevent adding attribute when already added in #12009. if ( ! preg_match( ":\s$attr(=|>|\s):", $tag ) ) { $tag = preg_replace( ':(?=>):', " $attr", $tag, 1 ); } // Only allow async or defer, not both. break; } return $tag; } add_filter( 'script_loader_tag', 'arrival_filter_script_loader_tag', 10, 2 ); /** * Generate preload markup for stylesheets. * * @param object $wp_styles Registered styles. * @param string $handle The style handle. */ function arrival_get_preload_stylesheet_uri( $wp_styles, $handle ) { $preload_uri = $wp_styles->registered[ $handle ]->src . '?ver=' . $wp_styles->registered[ $handle ]->ver; return $preload_uri; } /** * Adds preload for in-body stylesheets depending on what templates are being used. * Disabled when AMP is active as AMP injects the stylesheets inline. * * @link https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content */ function arrival_add_body_style() { // If AMP is active, do nothing. if ( arrival_is_amp() ) { return; } // Get registered styles. $wp_styles = wp_styles(); $preloads = array(); // Preload content.css. $preloads['arrival-content'] = arrival_get_preload_stylesheet_uri( $wp_styles, 'arrival-content' ); // Preload comments.css. if ( ! post_password_required() && is_singular() && ( comments_open() || get_comments_number() ) ) { $preloads['arrival-comments'] = arrival_get_preload_stylesheet_uri( $wp_styles, 'arrival-comments' ); } // Preload front-page.css. global $template; if ( 'front-page.php' === basename( $template ) ) { $preloads['arrival-front-page'] = arrival_get_preload_stylesheet_uri( $wp_styles, 'arrival-front-page' ); } // Output the preload markup in
. foreach ( $preloads as $handle => $src ) { echo ''; echo "\n"; } } add_action( 'wp_head', 'arrival_add_body_style' ); /** * Add dropdown symbol to nav menu items with children. * * Adds the dropdown markup after the menu link element, * before the submenu. * * Javascript converts the symbol to a toggle button. * * @TODO: * - This doesn't work for the page menu because it * doesn't have a similar filter. So the dropdown symbol * is only being added for page menus if JS is enabled. * Create a ticket to add to core? * * @param string $item_output The menu item's starting HTML output. * @param WP_Post $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param stdClass $args An object of wp_nav_menu() arguments. * @return string Modified nav menu HTML. */ function arrival_add_primary_menu_dropdown_symbol( $item_output, $item, $depth, $args ) { // Add the dropdown for items that have children. if ( ! empty( $item->classes ) && in_array( 'menu-item-has-children', $item->classes ) ) { return $item_output . ''; } return $item_output; } add_filter( 'walker_nav_menu_start_el', 'arrival_add_primary_menu_dropdown_symbol', 10, 4 ); /** * Filters the HTML attributes applied to a menu item's anchor element. * * Checks if the menu item is the current menu * item and adds the aria "current" attribute. * * @param array $atts The HTML attributes applied to the menu item's `` element. * @param WP_Post $item The current menu item. * @return array Modified HTML attributes */ function arrival_add_nav_menu_aria_current( $atts, $item ) { /* * First, check if "current" is set, * which means the item is a nav menu item. * * Otherwise, it's a post item so check * if the item is the current post. */ if ( isset( $item->current ) ) { if ( $item->current ) { $atts['aria-current'] = 'page'; } } else if ( ! empty( $item->ID ) ) { global $post; if ( ! empty( $post->ID ) && $post->ID == $item->ID ) { $atts['aria-current'] = 'page'; } } return $atts; } add_filter( 'nav_menu_link_attributes', 'arrival_add_nav_menu_aria_current', 10, 2 ); add_filter( 'page_menu_link_attributes', 'arrival_add_nav_menu_aria_current', 10, 2 ); /** * Social icons for the theme * */ add_action('arrival_social_icons','arrival_social_icons'); if( ! function_exists('arrival_social_icons')){ function arrival_social_icons(){ $default = arrival_get_default_theme_options(); $arrival_icons_value = get_theme_mod('arrival_social_icons'); $arrival_icons = json_decode($arrival_icons_value); $social_icons_new_tab = get_theme_mod( 'arrival_social_icons_new_tab',$default['arrival_social_icons_new_tab'] ); $target = '_self'; if( $social_icons_new_tab ){ $target = '_blank'; } ?> (', ' ', $links); $links = str_replace(')', '', $links); return $links; } /** * Strip whitespace in dynamic style * @package Arrival * @since 1.0.1 */ if( !function_exists('arrival_css_strip_whitespace') ){ function arrival_css_strip_whitespace($css){ $replace = array( "#/\*.*?\*/#s" => "", // Strip C style comments. "#\s\s+#" => " ", // Strip excess whitespace. ); $search = array_keys($replace); $css = preg_replace($search, $replace, $css); $replace = array( ": " => ":", "; " => ";", " {" => "{", " }" => "}", ", " => ",", "{ " => "{", ";}" => "}", // Strip optional semicolons. ",\n" => ",", // Don't wrap multiple selectors. "\n}" => "}", // Don't wrap closing braces. //"} " => "}\n", // Put each rule on it's own line. ); $search = array_keys($replace); $css = str_replace($search, $replace, $css); return trim($css); } } /** * Function for excerpt length */ if( ! function_exists( 'arrival_get_excerpt_content' ) ): function arrival_get_excerpt_content( $limit ) { $content = get_the_content(); $striped_contents = strip_shortcodes( $content ); $striped_content = strip_tags( $striped_contents ); $limit_content = mb_substr( $striped_content, 0 , absint($limit) ); return ''.$limit_content.'
'; } endif; /** * Numeric post navigation for archive pages * */ if( ! function_exists('arrival_numeric_posts_nav')){ function arrival_numeric_posts_nav() { if( is_singular() ) return; global $wp_query; /** Stop execution if there's only 1 page */ if( $wp_query->max_num_pages <= 1 ) return; $paged = get_query_var( 'paged' ) ? absint( 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; } echo '' . "\n"; } } /** * Get media attachment id from url */ if ( ! function_exists( 'arrival_get_attachment_id_from_url' ) ): function arrival_get_attachment_id_from_url( $attachment_url ) { global $wpdb; $attachment_id = false; // If there is no url, return. if ( '' == $attachment_url ) return; // Get the upload directory paths $upload_dir_paths = wp_upload_dir(); // Make sure the upload path base directory exists in the attachment URL, to verify that we're working with a media library image if ( false !== strpos( $attachment_url, $upload_dir_paths['baseurl'] ) ) { // If this is the URL of an auto-generated thumbnail, get the URL of the original image $attachment_url = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $attachment_url ); // Remove the upload path base directory from the attachment URL $attachment_url = str_replace( $upload_dir_paths['baseurl'] . '/', '', $attachment_url ); // Finally, run a custom database query to get the attachment ID from the modified attachment URL $attachment_id = $wpdb->get_var( $wpdb->prepare( "SELECT wposts.ID FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '_wp_attached_file' AND wpostmeta.meta_value = %s AND wposts.post_type = 'attachment'", $attachment_url ) ); } return $attachment_id; } endif; /** * Post-format control * @since 1.0.1 */ if( ! function_exists('arrival_post_format_display')){ function arrival_post_format_display(){ global $post; $defaults = arrival_get_default_theme_options(); $_blog_layout = get_theme_mod('arrival_blog_layout',$defaults['arrival_blog_layout']); $post_id = $post->ID; $post_format = get_post_format( $post_id ); $img_size = 'arrival-blog-list-thumb'; if( $_blog_layout == 'masonry-layout' ){ $img_size = 'arrival-blog-masonry-thumb'; } if( 'audio' == $post_format ){ $audio_url_value = get_post_meta( $post->ID, 'post_embed_audio_url', true ); echo wp_oembed_get(esc_url($audio_url_value)); }elseif( 'video' == $post_format ){ $video_url_value = get_post_meta( $post->ID, 'post_embed_video_url', true ); echo wp_oembed_get(esc_url($video_url_value)); }elseif( 'gallery' == $post_format ){ $post_gallery_images = get_post_meta( $post->ID, 'post_images', true ); if( $post_gallery_images ){ foreach( $post_gallery_images as $post_gallery_image ){ $img_id = arrival_get_attachment_id_from_url($post_gallery_image); $thumb_img = wp_get_attachment_image_src( $img_id, $img_size, true ); $image_alt = get_post_meta( $img_id, '_wp_attachment_image_alt', true ); ?>