* --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_trim_excerpt' ) ) { function mfn_trim_excerpt( $text ) { return ' […]'; } } add_filter( 'excerpt_more', 'mfn_trim_excerpt' ); /* --------------------------------------------------------------------------- * Excerpt | for Pages * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_add_excerpts_to_pages' ) ) { function mfn_add_excerpts_to_pages() { add_post_type_support( 'page', 'excerpt' ); } } add_action( 'init', 'mfn_add_excerpts_to_pages' ); /* --------------------------------------------------------------------------- * Slug | Generate * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_slug' ) ) { function mfn_slug( $string = false ){ return strtolower( trim ( preg_replace( '/[^A-Za-z0-9-]+/', '-', $string ) ) ); } } /* --------------------------------------------------------------------------- * Blog Page | Exclude category * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_exclude_category' ) ) { function mfn_exclude_category($query) { if( $exclude = trim( mfn_opts_get( 'exclude-category' ) ) ){ if( is_home() ){ $exclude = str_replace( ' ', '', $exclude ); $exclude = explode( ',', $exclude ); $exclude_ids = array(); if( is_array( $exclude ) ){ foreach( $exclude as $slug ){ $category = get_category_by_slug( $slug ); $exclude_ids[] = $category->term_id * -1; } } $exclude_ids = implode( ',', $exclude_ids ); $query->set( 'cat', $exclude_ids ); } } return $query; } } add_filter('pre_get_posts', 'mfn_exclude_category'); /* --------------------------------------------------------------------------- * SSL | Compatibility * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_ssl' ) ) { function mfn_ssl( $echo = false ){ $ssl = ''; if( is_ssl() ) $ssl = 's'; if( $echo ){ echo $ssl; } return $ssl; } } /* --------------------------------------------------------------------------- * SSL | Attachments * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_ssl_attachments' ) ) { function mfn_ssl_attachments( $url ){ if( is_ssl() ){ return str_replace( 'http://', 'https://', $url ); } return $url; } } add_filter( 'wp_get_attachment_url', 'mfn_ssl_attachments' ); /* --------------------------------------------------------------------------- * White Label | Admin Body Class * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_white_label_class' ) ) { function mfn_white_label_class( $classes ){ if( WHITE_LABEL ) $classes .= 'white-label'; return $classes; } } add_filter( 'admin_body_class', 'mfn_white_label_class' ); /* --------------------------------------------------------------------------- * Get Real Post ID * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_ID' ) ) { function mfn_ID(){ global $post; $postID = false; if( ! is_404() ){ if( function_exists( 'is_woocommerce' ) && is_woocommerce() ){ // WooCommerce $postID = woocommerce_get_page_id( 'shop' ); } elseif( is_search() ){ $postID = false; } elseif( is_tax() ){ // taxonomy-portfolio-types.php $postID = mfn_opts_get( 'portfolio-page' ); } elseif( in_array( get_post_type(), array( 'post', 'tribe_events' ) ) && ! is_singular() ){ // index.php if( get_option( 'page_for_posts' ) ){ // Setings / Reading $postID = get_option( 'page_for_posts' ); } elseif( mfn_opts_get( 'blog-page' ) ){ // Theme Options / Getting Started / Blog $postID = mfn_wpml_ID( mfn_opts_get( 'blog-page' ) ); } } else { // default $postID = get_the_ID(); } } return $postID; } } /* --------------------------------------------------------------------------- * Get Layout ID * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_layout_ID' ) ) { function mfn_layout_ID(){ $layoutID = false; if( mfn_ID() ){ if( is_single() && get_post_type() == 'post' ){ // Theme Options | Single Post $layoutID = mfn_opts_get( 'blog-single-layout' ); } elseif( is_single() && get_post_type() == 'portfolio' ) { if( get_post_meta( mfn_ID(), 'mfn-post-custom-layout', true ) ){ // Page Options | Single Portfolio $layoutID = get_post_meta( mfn_ID(), 'mfn-post-custom-layout', true ); } else { // Theme Options | Single Portfolio $layoutID = mfn_opts_get( 'portfolio-single-layout' ); } } else { // Page Options | Page $layoutID = get_post_meta( mfn_ID(), 'mfn-post-custom-layout', true ); } } return $layoutID; } } /* --------------------------------------------------------------------------- * Slider | Isset * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_slider_isset' ) ) { function mfn_slider_isset( $id = false ){ $slider = false; // Global Slider Shortcode if( is_page() && mfn_opts_get( 'slider-shortcode' ) ){ return 'global'; } if( $id || is_home() || is_category() || is_tax() || get_post_type() == 'page' || ( get_post_type( mfn_ID() ) == 'portfolio' && get_post_meta( mfn_ID(), 'mfn-post-slider-header', true ) ) ){ if( ! $id ) $id = mfn_ID(); // do NOT move it before IF if( get_post_meta( $id, 'mfn-post-slider', true ) ){ // Revolution Slider $slider = 'rev'; } elseif( get_post_meta( $id, 'mfn-post-slider-layer', true ) ) { // Layer Slider $slider = 'layer'; } elseif( get_post_meta( $id, 'mfn-post-slider-shortcode', true ) ) { // Custom Slider $slider = 'custom'; } } return $slider; } } /* --------------------------------------------------------------------------- * Slider | Get * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_slider' ) ) { function mfn_slider( $id = false ){ $slider = false; $slider_type = mfn_slider_isset( $id ); if( ! $id ) $id = mfn_ID(); // do NOT move it before IF switch ($slider_type) { case 'global': $slider = '
'; $slider .= do_shortcode( mfn_opts_get('slider-shortcode') ); $slider .= '
'; break; case 'rev': $slider = '
'; $slider .= do_shortcode('[rev_slider '. get_post_meta( $id, 'mfn-post-slider', true ) .']'); $slider .= '
'; break; case 'layer': $slider = '
'; $slider .= do_shortcode('[layerslider id="'. get_post_meta( $id, 'mfn-post-slider-layer', true ) .'"]'); $slider .= '
'; break; case 'custom': $slider = '
'; $slider .= do_shortcode( get_post_meta( $id, 'mfn-post-slider-shortcode', true ) ); $slider .= '
'; break; } return $slider; } } /* --------------------------------------------------------------------------- * WP Mobile Detect | Quick FIX: parallax on mobile * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_is_mobile' ) ) { function mfn_is_mobile(){ $mobile = wp_is_mobile(); if( mfn_opts_get( 'responsive-parallax' ) ){ $mobile = false; } return $mobile; } } /* --------------------------------------------------------------------------- * User OS * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_user_os' ) ) { function mfn_user_os(){ $os = false; $user_agent = $_SERVER['HTTP_USER_AGENT']; if( strpos( $user_agent, 'iPad;' ) || strpos( $user_agent, 'iPhone;' ) ){ $os = ' ios'; } return $os; } } /* --------------------------------------------------------------------------- * User Agent | For: Prallax - Safari detect & future use * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_user_agent' ) ) { function mfn_user_agent(){ $user_agent = $_SERVER['HTTP_USER_AGENT']; if( stripos( $user_agent, 'Chrome/') !== false ){ $user_agent = 'chrome'; } elseif( ( stripos( $user_agent, 'Safari/') !== false ) && ( stripos( $user_agent, 'Mobile/') !== false ) ){ $user_agent = 'safari mobile'; } elseif( stripos( $user_agent, 'Safari/') !== false ){ $user_agent = 'safari'; } else { // for future use $user_agent = false; } return $user_agent; } } /* --------------------------------------------------------------------------- * Paralllax | Plugin * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_parallax_plugin' ) ) { function mfn_parallax_plugin(){ $parallax = mfn_opts_get( 'parallax' ); if( $parallax == 'translate3d no-safari' ){ if( mfn_user_agent() == 'safari' ){ $parallax = 'enllax'; } else { $parallax = 'translate3d'; } } return $parallax; } } /* --------------------------------------------------------------------------- * Paralllax | Code - Section & wrapper background * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_parallax_data' ) ) { function mfn_parallax_data(){ $parallax = mfn_parallax_plugin(); if( $parallax == 'translate3d' ){ $parallax = 'data-parallax="3d"'; } elseif( $parallax == 'stellar' ){ $parallax = 'data-stellar-background-ratio="0.5"'; } else { $parallax = 'data-enllax-ratio="-0.3"'; } return $parallax; } } /* --------------------------------------------------------------------------- * Pagination for Blog and Portfolio * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_pagination' ) ) { function mfn_pagination( $query = false, $load_more = false ){ global $wp_query; $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : ( ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1 ); // default $wp_query if( ! $query ) $query = $wp_query; $translate['prev'] = mfn_opts_get('translate') ? mfn_opts_get('translate-prev','‹ Prev page') : __('Prev page','betheme'); $translate['next'] = mfn_opts_get('translate') ? mfn_opts_get('translate-next','Next page ›') : __('Next page','betheme'); $translate['load-more'] = mfn_opts_get('translate') ? mfn_opts_get('translate-load-more','Load more') : __('Load more','betheme'); $query->query_vars['paged'] > 1 ? $current = $query->query_vars['paged'] : $current = 1; if( empty( $paged ) ) $paged = 1; $prev = $paged - 1; $next = $paged + 1; $end_size = 1; $mid_size = 2; $show_all = mfn_opts_get('pagination-show-all'); $dots = false; if( ! $total = $query->max_num_pages ) $total = 1; $output = ''; if( $total > 1 ) { if( $load_more ){ // ajax load more ------------------------------------------------- if( $paged < $total ){ $output .= '
'; $output .= ''; $output .= ''; $output .= ''. $translate['load-more'] .''; $output .= ''; $output .= '
'; } } else { // default -------------------------------------------------------- $output .= '
'; $output .= '
'; if( $paged >1 ){ $output .= ''. $translate['prev'] .''; } $output .= '
'; for( $i=1; $i <= $total; $i++ ){ if ( $i == $current ){ $output .= ''. $i .''; $dots = true; } else { if ( $show_all || ( $i <= $end_size || ( $current && $i >= $current - $mid_size && $i <= $current + $mid_size ) || $i > $total - $end_size ) ){ $output .= ''. $i .''; $dots = true; } elseif ( $dots && ! $show_all ) { $output .= '...'; $dots = false; } } } $output .= '
'; if( $paged < $total ){ $output .= ''. $translate['next'] .''; } $output .= '
'; $output .= '
'."\n"; } } return $output; } } /* --------------------------------------------------------------------------- * No sidebar message for templates with sidebar * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_nosidebar' ) ) { function mfn_nosidebar(){ echo 'This template supports the sidebar\'s widgets. Add one or use Full Width layout.'; } } /* --------------------------------------------------------------------------- * New Walker Category for categories menu * --------------------------------------------------------------------------- */ if( ! class_exists( 'New_Walker_Category' ) ) { class New_Walker_Category extends Walker_Category { function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { extract($args); $cat_name = esc_attr( $category->name ); $cat_name = apply_filters( 'list_cats', $cat_name, $category ); $link = 'description) ) $link .= 'title="' . esc_attr( sprintf(__('View all posts filed under %s','betheme'), $cat_name) ) . '"'; else $link .= 'title="' . esc_attr( strip_tags( apply_filters( 'category_description', $category->description, $category ) ) ) . '"'; $link .= '>'; $link .= $cat_name; if ( !empty($show_count) ) $link .= ' (' . intval($category->count) . ')'; $link .= ''; if ( 'list' == $args['style'] ) { $output .= "\tterm_id; if ( !empty($current_category) ) { $_current_category = get_term( $current_category, $category->taxonomy ); if ( $category->term_id == $current_category ) $class .= ' current-cat'; elseif ( $category->term_id == $_current_category->parent ) $class .= ' current-cat-parent'; } $output .= ' class="' . $class . '"'; $output .= ">$link\n"; } else { $output .= "\t$link\n"; } } } } /* --------------------------------------------------------------------------- * Current page URL * --------------------------------------------------------------------------- */ if( ! function_exists( 'curPageURL' ) ) { function curPageURL(){ $pageURL = 'http'; if( is_ssl() ) $pageURL .= "s"; $pageURL .= "://"; if( $_SERVER["SERVER_PORT"] != "80" ) { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } } /* --------------------------------------------------------------------------- * Subheader | Page Title * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_page_title' ) ) { function mfn_page_title( $echo = false ){ if( is_home() ){ // Blog --------------------------------------- $title = get_the_title( mfn_ID() ); } elseif( function_exists( 'tribe_is_month' ) && ( tribe_is_event_query() || tribe_is_month() || tribe_is_event() || tribe_is_day() || tribe_is_venue() ) ){ // The Events Calendar ------------------------ $title = tribe_get_events_title(); } elseif( is_tag() ){ // Blog | Tag --------------------------------- $title = single_tag_title('', false); } elseif( is_category() ){ // Blog | Category ---------------------------- $title = single_cat_title('', false); } elseif( is_author() ){ // Blog | Author ------------------------------ $title = get_the_author(); } elseif( is_day() ){ // Blog | Day --------------------------------- $title = get_the_time('d'); } elseif( is_month() ){ // Blog | Month ------------------------------- $title = get_the_time('F'); } elseif( is_year() ){ // Blog | Year -------------------------------- $title = get_the_time('Y'); } elseif( is_single() || is_page() ){ // Single ------------------------------------- $title = get_the_title( mfn_ID() ); } elseif( get_post_taxonomies() ){ // Taxonomy ----------------------------------- $title = single_cat_title('', false); } else { // Default ------------------------------------ $title = get_the_title( mfn_ID() ); } if( $echo ) echo $title; return $title; } } /* --------------------------------------------------------------------------- * Breadcrumbs * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_breadcrumbs' ) ) { function mfn_breadcrumbs( $class = false ){ global $post; $translate['home'] = mfn_opts_get('translate') ? mfn_opts_get('translate-home','Home') : __('Home','betheme'); $homeLink = home_url(); $separator = ' '; // Plugin | bbPress ----------------------------------- if( function_exists('is_bbpress') && is_bbpress() ){ bbp_breadcrumb( array( 'before' => '', 'sep' => '', 'crumb_before' => '
  • ', 'crumb_after' => '
  • ', 'home_text' => $translate['home'], ) ); return true; } // end: bbPress ------------------------------------- // Default breadcrumbs -------------------------------- $breadcrumbs = array(); // Home prefix -------------------------------- $breadcrumbs[] = ''. $translate['home'] .''; // Blog ------------------------------------------- if( get_post_type() == 'post' ){ $blogID = false; if( get_option( 'page_for_posts' ) ){ $blogID = get_option( 'page_for_posts' ); // Setings / Reading } elseif( mfn_opts_get( 'blog-page' ) ){ $blogID = mfn_opts_get( 'blog-page' ); // Theme Options / Getting Started / Blog } // Blog Page has parent $blog_post = get_post( $blogID ); if( $blog_post->post_parent ){ $parent_id = $blog_post->post_parent; $parents = array(); while( $parent_id ) { $page = get_page( $parent_id ); $parents[] = '' . get_the_title( $page->ID ) . ''; $parent_id = $page->post_parent; } $parents = array_reverse( $parents ); $breadcrumbs = array_merge_recursive($breadcrumbs, $parents); } if( $blogID ) $breadcrumbs[] = ''. get_the_title( $blogID ) .''; } if( is_front_page() || is_home() ){ // do nothing // Plugin | Events Calendar ------------------------------------------- } elseif( function_exists( 'tribe_is_month' ) && ( tribe_is_event_query() || tribe_is_month() || tribe_is_event() || tribe_is_day() || tribe_is_venue() ) ) { if( function_exists( 'tribe_get_events_link' ) ){ $breadcrumbs[] = ''. tribe_get_events_title() .''; } // Blog | Tag ------------------------------------- } elseif( is_tag() ){ $breadcrumbs[] = '' . single_tag_title('', false) . ''; // Blog | Category -------------------------------- } elseif( is_category() ){ $cat = get_term_by('name', single_cat_title('',false), 'category'); if( $cat && $cat->parent ){ $breadcrumbs[] = get_category_parents( $cat->parent, true, $separator ); } $breadcrumbs[] = '' . single_cat_title('', false) . ''; // Blog | Author ---------------------------------- } elseif( is_author() ){ $breadcrumbs[] = '' . get_the_author() . ''; // Blog | Day ------------------------------------- } elseif( is_day() ){ $breadcrumbs[] = ''. get_the_time('Y') .''; $breadcrumbs[] = ''. get_the_time('F') .''; $breadcrumbs[] = ''. get_the_time('d') .''; // Blog | Month ----------------------------------- } elseif( is_month() ){ $breadcrumbs[] = '' . get_the_time('Y') . ''; $breadcrumbs[] = ''. get_the_time('F') .''; // Blog | Year ------------------------------------ } elseif( is_year() ){ $breadcrumbs[] = ''. get_the_time('Y') .''; // Single ----------------------------------------- } elseif( is_single() && ! is_attachment() ){ // Custom Post Type ----------------- if( get_post_type() != 'post' ){ $post_type = get_post_type_object(get_post_type()); $slug = $post_type->rewrite; $portfolio_page_id = mfn_wpml_ID( mfn_opts_get('portfolio-page') ); // Portfolio Page ------------ if( $slug['slug'] == mfn_opts_get( 'portfolio-slug', 'portfolio-item' ) && $portfolio_page_id ){ $breadcrumbs[] = ''. get_the_title( $portfolio_page_id ) .''; } // Category ---------- if( $portfolio_page_id ){ $terms = get_the_terms( get_the_ID(), 'portfolio-types' ); if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { $term = $terms[0]; $breadcrumbs[] = ''. $term->name .''; } } // Single Item -------- $breadcrumbs[] = ''. get_the_title().''; // Blog | Single -------------------- } else { $cat = get_the_category(); if( ! empty( $cat ) ){ $breadcrumbs[] = get_category_parents( $cat[0], true, $separator ); } $breadcrumbs[] = ''. get_the_title() .''; } // Taxonomy --------------------------------------- } elseif( ! is_page() && get_post_taxonomies() ){ // Portfolio ------------------------ $post_type = get_post_type_object( get_post_type() ); if( $post_type->name == 'portfolio' && $portfolio_page_id = mfn_wpml_ID( mfn_opts_get('portfolio-page') ) ) { $breadcrumbs[] = ''. get_the_title( $portfolio_page_id ) .''; } $breadcrumbs[] = '' . single_cat_title('', false) . ''; // Page with parent ------------------------------- } elseif( is_page() && $post->post_parent ){ $parent_id = $post->post_parent; $parents = array(); while( $parent_id ) { $page = get_page( $parent_id ); $parents[] = '' . get_the_title( $page->ID ) . ''; $parent_id = $page->post_parent; } $parents = array_reverse( $parents ); $breadcrumbs = array_merge_recursive($breadcrumbs, $parents); $breadcrumbs[] = ''. get_the_title( mfn_ID() ) .''; // Default ---------------------------------------- } else { $breadcrumbs[] = ''. get_the_title( mfn_ID() ) .''; } // PRINT ------------------------------------------------------------------ echo ''; } } /* --------------------------------------------------------------------------- * Hex 2 rgba * --------------------------------------------------------------------------- */ if( ! function_exists( 'hex2rgba' ) ) { function hex2rgba( $hex, $alpha = 1, $echo = false ) { $hex = str_replace("#", "", $hex); if(strlen($hex) == 3) { $r = hexdec(substr($hex,0,1).substr($hex,0,1)); $g = hexdec(substr($hex,1,1).substr($hex,1,1)); $b = hexdec(substr($hex,2,1).substr($hex,2,1)); } else { $r = hexdec(substr($hex,0,2)); $g = hexdec(substr($hex,2,2)); $b = hexdec(substr($hex,4,2)); } $rgba = 'rgba('. $r.', '. $g .', '. $b .', '. $alpha .')'; if( $echo ){ echo $rgba; return true; } return $rgba; } } /* --------------------------------------------------------------------------- * Is dark color * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_brightness' ) ) { function mfn_brightness( $hex, $tolerance = 169 ) { $hex = str_replace("#", "", $hex); $r = hexdec(substr( $hex, 0, 2 )); $g = hexdec(substr( $hex, 2, 2 )); $b = hexdec(substr( $hex, 4, 2 )); $brightness = ( ($r * 299) + ($g * 587) + ($b * 114) ) / 1000; if( $brightness > $tolerance ){ $brightness = 'light'; } else { $brightness = 'dark'; } return $brightness; } } /* --------------------------------------------------------------------------- * jPlayer HTML * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_jplayer_html' ) ) { function mfn_jplayer_html( $video_m4v, $poster = false ){ $player_id = mt_rand( 0, 999 ); $output = '
    '; $output .= ''; $output .= '
    '."\n"; return $output; } } /* --------------------------------------------------------------------------- * jPlayer * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_jplayer' ) ) { function mfn_jplayer( $postID, $sizeH = 'full' ){ // masonry square video fix if($sizeH == 'blog-masonry') $sizeH = 'blog-square'; $video_m4v = get_post_meta( $postID, 'mfn-post-video-mp4', true ); $poster = wp_get_attachment_image_src( get_post_thumbnail_id( $postID ), $sizeH ); $poster = $poster[0]; return mfn_jplayer_html( $video_m4v, $poster ); } } /* --------------------------------------------------------------------------- * Post Format * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_post_format' ) ) { function mfn_post_format( $postID ){ if( get_post_type( $postID ) == 'portfolio' && is_single( $postID ) ){ // portfolio if ( get_post_meta( get_the_ID(), 'mfn-post-video', true ) ){ // Video - embed $format = 'video'; } elseif( get_post_meta( get_the_ID(), 'mfn-post-video-mp4', true ) ){ // Video - HTML5 $format = 'video'; } else { // Image $format = false; } } else { // blog $format = get_post_format( $postID ); } return $format; } } /* --------------------------------------------------------------------------- * Attachment | GET attachment ID by URL * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_get_attachment_id_url' ) ) { function mfn_get_attachment_id_url( $image_url ){ global $wpdb; $image_url = esc_url( $image_url ); $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url )); if( isset($attachment[0]) ){ return $attachment[0]; } } } /* --------------------------------------------------------------------------- * Attachment | GET attachment data * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_get_attachment_data' ) ) { function mfn_get_attachment_data( $image, $data, $with_key = false ){ $size = $return = false; // image link used instead of image id // if( ! is_numeric( $image ) ){ // $image = mfn_get_attachment_id_url( $image ); // } if( ! is_numeric( $image ) ){ // QUICK FIX https $image_ID = mfn_get_attachment_id_url( $image ); if( ! $image_ID ){ $image = str_replace( 'https://', 'http://', $image ); $image_ID = mfn_get_attachment_id_url( $image ); } $image = $image_ID; } $meta = wp_prepare_attachment_for_js( $image ); if( is_array( $meta ) && isset( $meta[ $data ] ) ){ $return = $meta[ $data ]; // if looking for alt and it isn't specified use image title if( $data == 'alt' && ! $return ){ $return = $meta[ 'title' ]; } } if( $return && $with_key ){ $return = $data. '="'. $return .'"'; } return $return; } } /* --------------------------------------------------------------------------- * Post Thumbnail | GET post thumbnail type * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_post_thumbnail_type' ) ) { function mfn_post_thumbnail_type( $postID ){ $type = 'image'; $post_format = mfn_post_format( $postID ); if( $post_format == 'image' ){ $type = 'image'; } elseif( $post_format == 'video' && get_post_meta( $postID, 'mfn-post-video', true ) ){ $type = 'video embed'; } elseif( $post_format == 'video' && get_post_meta( $postID, 'mfn-post-video-mp4', true ) ){ $type = 'video html5'; } elseif( get_post_meta( $postID, 'mfn-post-slider', true ) || get_post_meta( $postID, 'mfn-post-slider-layer', true ) ){ $type = 'slider'; } return $type; } } /* --------------------------------------------------------------------------- * Post Thumbnail | GET post thumbnail * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_post_thumbnail' ) ) { function mfn_post_thumbnail( $postID, $type = false, $style = false, $images_only = false ){ $output = ''; // Image Size --------------------------------------------------------- if( $type == 'portfolio' ){ // Portfolio ---------------------- if( $style == 'list' ){ // Portfolio | List ---------------------- $sizeH = 'portfolio-list'; } elseif( $style == 'masonry-flat' ) { // Portfolio | Masonry Flat ---------------------- $size = get_post_meta( $postID, 'mfn-post-size', true ); if( $size == 'wide' ){ $sizeH = 'portfolio-mf-w'; } elseif( $size == 'tall' ) { $sizeH = 'portfolio-mf-t'; } else { $sizeH = 'portfolio-mf'; } } elseif( $style == 'masonry-minimal' ) { // Portfolio | Masonry Minimal ---------------------- $sizeH = 'full'; } else { // Portfolio | Default ---------------------- $sizeH = 'blog-portfolio'; } } elseif( $type == 'blog' && $style == 'photo' ){ // Blog | Photo ---------------------- $sizeH = 'blog-single'; $sizeV = 'blog-single'; } elseif( $type == 'related' ){ // Related Posts ---------------------- $sizeH = 'blog-portfolio'; } elseif( is_single( $postID ) ){ // Blog & Portfolio | Single ---------------------- $sizeH = 'blog-single'; $sizeV = 'full'; } else { // Default ---------------------- $sizeH = 'blog-portfolio'; $sizeV = 'full'; } // Link Wrap ---------------------------------------------------------- $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $postID ), 'large' ); if( is_single( $postID ) ){ // Single ----------------------------------------- $link_before = ''; $link_before .= '
    '; $link_after = '
    '; $link_after .= ''; // Single | Post if( get_post_type() == 'post' ){ // Blog | Single - Disable Image Zoom if( ! mfn_opts_get( 'blog-single-zoom' ) ){ $link_before = ''; $link_after = ''; } // Blog | Single | Structured data if( mfn_opts_get( 'mfn-seo-schema-type' ) ){ $link_before .= '
    '; $image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $postID ), 'full' ); $link_after_schema = ''; $link_after_schema .= ''; $link_after_schema .= ''; $link_after_schema .= '
    '; $link_after = $link_after_schema . $link_after; } } } elseif( $type == 'portfolio' ){ // Portfolio -------------------------------------- $external = mfn_opts_get( 'portfolio-external' ); // External Link to Project Page if( $image_links = ( get_post_meta( get_the_ID(), 'mfn-post-link', true ) ) ){ $image_links_class = 'triple'; } else { $image_links_class = 'double'; } // Image Link if( $external == 'popup' ){ // link popup $link_before = ''; $link_title = ''; } elseif( $external == 'disable' ){ // disable details $link_before = ''; $link_title = ''; } elseif( $external && $image_links ){ // link to project website $image_links_class = 'double'; $link_before = ''; $link_title = ''; } else { // link to project details $link_before = ''; $link_title = ''; } $link_before .= '
    '; $link_after = '
    '; // Hover if( mfn_opts_get( 'portfolio-hover-title' ) ){ // Hover | Title $link_after .= ''; } elseif( $external != 'disable' ) { // Hover | Icons $link_after .= ''; } } else { // Blog ------------------------------------------- $link_before = ''; $link_before .= '
    '; $link_after = '
    '; $link_after .= ''; } // Post Format -------------------------------------------------------- $post_format = mfn_post_format( $postID ); // Images Only if( $images_only ){ if( ! in_array( $post_format, array( 'quote', 'link', 'image' ) ) ){ $post_format = 'images-only'; } } switch( $post_format ){ case 'quote': case 'link': // quote - Quote - without image return false; break; case 'image': // image - Vertical Image if( has_post_thumbnail() ){ $output .= $link_before; $output .= get_the_post_thumbnail( $postID, $sizeV, array( 'class'=>'scale-with-grid' ) ); $output .= $link_after; } break; case 'video': // video - Video if( $video = get_post_meta( $postID, 'mfn-post-video', true ) ){ if( is_numeric($video) ){ // Vimeo $output .= ''."\n"; } else { // YouTube $output .= ''."\n"; } } elseif( get_post_meta( $postID, 'mfn-post-video-mp4', true ) ){ $output .= mfn_jplayer( $postID ); } break; case 'images-only': // Images Only $output .= $link_before; $output .= get_the_post_thumbnail( $postID, $sizeH, array( 'class' => 'scale-with-grid' ) ); $output .= $link_after; break; default: // standard - Text, Horizontal Image, Slider $rev_slider = get_post_meta( $postID, 'mfn-post-slider', true ); $lay_slider = get_post_meta( $postID, 'mfn-post-slider-layer', true ); if( $type != 'portfolio' && ( $rev_slider || $lay_slider ) ){ if( $rev_slider ){ // Revolution Slider $output .= do_shortcode('[rev_slider '. $rev_slider .']'); } elseif( $lay_slider ){ // Layer Slider $output .= do_shortcode('[layerslider id="'. $lay_slider .'"]'); } } elseif( has_post_thumbnail() ){ // Image $output .= $link_before; $output .= get_the_post_thumbnail( $postID, $sizeH, array( 'class'=>'scale-with-grid' ) ); $output .= $link_after; } } return $output; } } /* --------------------------------------------------------------------------- * Single Post Navigation | SET query order * --------------------------------------------------------------------------- */ // previous ---------- if( ! function_exists( 'mfn_filter_previous_post_sort' ) ) { function mfn_filter_previous_post_sort( $sort ){ if( mfn_get_portfolio_order() == 'ASC' ){ $order = 'DESC'; } else { $order = 'ASC'; } $sort = "ORDER BY p.". esc_sql( mfn_get_portfolio_orderby() ) ." ". $order ." LIMIT 1"; return $sort; } } if( ! function_exists( 'mfn_filter_previous_post_where' ) ) { function mfn_filter_previous_post_where( $where ){ global $post, $wpdb; $orderby = mfn_get_portfolio_orderby(); $where = preg_replace( "/(.*)p.post_type/", "AND p.post_type", $where ); if( mfn_get_portfolio_order() == 'ASC' ){ $where_pre = $wpdb->prepare( "WHERE p.". esc_sql( $orderby ) ." < %s", $post->$orderby ); } else { $where_pre = $wpdb->prepare( "WHERE p.". esc_sql( $orderby ) ." > %s", $post->$orderby ); } $where = $where_pre.' '.$where; return $where; } } // next ---------- if( ! function_exists( 'mfn_filter_next_post_sort' ) ) { function mfn_filter_next_post_sort( $sort ){ $sort = "ORDER BY p.". esc_sql( mfn_get_portfolio_orderby() ) ." ". esc_sql( mfn_get_portfolio_order() ) ." LIMIT 1"; return $sort; } } if( ! function_exists( 'mfn_filter_next_post_where' ) ) { function mfn_filter_next_post_where( $where ){ global $post, $wpdb; $orderby = mfn_get_portfolio_orderby(); $where = preg_replace( "/(.*)p.post_type/", "AND p.post_type", $where ); if( mfn_get_portfolio_order() == 'ASC' ){ $where_pre = $wpdb->prepare( "WHERE p.". esc_sql( $orderby ) ." > %s", $post->$orderby ); } else { $where_pre = $wpdb->prepare( "WHERE p.". esc_sql( $orderby ) ." < %s", $post->$orderby ); } $where = $where_pre.' '.$where; return $where; } } // helpers ---------- if( ! function_exists( 'mfn_get_portfolio_order' ) ) { function mfn_get_portfolio_order(){ return mfn_opts_get( 'portfolio-order', 'DESC' ); } } if( ! function_exists( 'mfn_get_portfolio_orderby' ) ) { function mfn_get_portfolio_orderby(){ $orderby = mfn_opts_get( 'portfolio-orderby', 'date' ); switch( $orderby ){ case 'title': $orderby = 'post_title'; break; case 'menu_order': $orderby = 'menu_order'; break; default: $orderby = 'post_date'; } return $orderby; } } // filters ---------- if( ! function_exists( 'mfn_post_navigation_sort' ) ) { function mfn_post_navigation_sort(){ add_filter( 'get_previous_post_sort', 'mfn_filter_previous_post_sort' ); add_filter( 'get_previous_post_where', 'mfn_filter_previous_post_where' ); add_filter( 'get_next_post_sort', 'mfn_filter_next_post_sort' ); add_filter( 'get_next_post_where', 'mfn_filter_next_post_where' ); } } /* --------------------------------------------------------------------------- * Single Post Navigation | GET header navigation * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_post_navigation_header' ) ) { function mfn_post_navigation_header( $post_prev, $post_next, $post_home, $translate = array() ){ $style = mfn_opts_get( 'prev-next-style' ); $output = '
    '; if( $style == 'minimal' ){ // minimal ----- if( $post_prev ) $output .= ''; if( $post_next ) $output .= ''; if( $post_home ) $output .= ''; } else { // default ----- $output .= ''; if( $post_home ) $output .= ''. $translate['all'] .''; } $output .= '
    '; return $output; } } /* --------------------------------------------------------------------------- * Single Post Navigation | GET sticky navigation * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_post_navigation_sticky' ) ) { function mfn_post_navigation_sticky( $post, $next_prev, $icon ){ $output = ''; if( is_object( $post ) ){ // move this DOM element with JS $output .= ''; $output .= ''; $output .= '
    '; $output .= get_the_post_thumbnail( $post->ID, 'blog-navi' ); $output .= '
    '; $output .= '
    '; $output .= '
    '. get_the_title( $post ) .'
    '; $output .= ''. get_the_date(get_option('date_format'), $post->ID) .''; $output .= '
    '; $output .= '
    '; } return $output; } } /* --------------------------------------------------------------------------- * Search | SET add custom fields to search query * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_search' ) ) { function mfn_search( $search_query ) { global $wpdb; if( is_search() && $search_query->is_main_query() && $search_query->is_search() ){ $keyword = get_search_query(); if( ! $keyword ) return false; // WooCommerce uses default search Query if( function_exists('is_woocommerce') && is_woocommerce() ){ return false; } $keyword = '%' . $wpdb->esc_like( $keyword ) . '%'; // Post Title & Post Content $post_ids_title = $wpdb->get_col( $wpdb->prepare( " SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_title LIKE '%s' ", $keyword, $keyword ) ); // Post Title & Post Content $post_ids_content = $wpdb->get_col( $wpdb->prepare( " SELECT DISTINCT ID FROM {$wpdb->posts} WHERE post_content LIKE '%s' ", $keyword, $keyword ) ); // Custom Fields $post_ids_meta = $wpdb->get_col( $wpdb->prepare( " SELECT DISTINCT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'mfn-page-items-seo' AND meta_value LIKE '%s' ", $keyword ) ); $post_ids = array_merge( $post_ids_title, $post_ids_content, $post_ids_meta ); if( ! count( $post_ids ) ) return false; $search_query->set( 's', false ); $search_query->set( 'post__in', $post_ids ); $search_query->set( 'orderby', 'post__in' ); } } } add_action( 'pre_get_posts', 'mfn_search' ); /* --------------------------------------------------------------------------- * Posts per page & pagination fix * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_option_posts_per_page' ) ) { function mfn_option_posts_per_page( $value ) { if ( is_tax( 'portfolio-types' ) ) { $posts_per_page = mfn_opts_get( 'portfolio-posts', 6, true ); } else { $posts_per_page = mfn_opts_get( 'blog-posts', 5, true ); } return $posts_per_page; } } if( ! function_exists( 'mfn_posts_per_page' ) ) { function mfn_posts_per_page() { add_filter( 'option_posts_per_page', 'mfn_option_posts_per_page' ); } } add_action( 'init', 'mfn_posts_per_page', 0 ); /* --------------------------------------------------------------------------- * Comments number with text * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_comments_number' ) ) { function mfn_comments_number() { $translate['comment'] = mfn_opts_get('translate') ? mfn_opts_get('translate-comment','comment') : __('comment','betheme'); $translate['comments'] = mfn_opts_get('translate') ? mfn_opts_get('translate-comments','comments') : __('comments','betheme'); $translate['comments-off'] = mfn_opts_get('translate') ? mfn_opts_get('translate-comments-off','comments off') : __('comments off','betheme'); $num_comments = get_comments_number(); // get_comments_number returns only a numeric value if ( comments_open() ) { if ( $num_comments != 1 ) { $comments = ''. $num_comments.' '. $translate['comments']; } else { $comments = '1 '. $translate['comment']; } } else { $comments = $translate['comments-off']; } return $comments; } } /* --------------------------------------------------------------------------- * Menu title in selected location * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_get_menu_name' ) ) { function mfn_get_menu_name($location){ if( ! has_nav_menu($location) ){ return false; } $menus = get_nav_menu_locations(); $menu_title = wp_get_nav_menu_object($menus[$location])->name; return $menu_title; } } /* --------------------------------------------------------------------------- * GET | WordPress Authors * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_get_authors' ) ) { function mfn_get_authors(){ $authors = get_users(); if( is_array($authors) ){ foreach( $authors as $ka => $author ){ $remove = true; if( in_array( 'author', $author->roles ) ) $remove = false; if( in_array( 'editor', $author->roles ) ) $remove = false; if( in_array( 'administrator', $author->roles ) ) $remove = false; if( $remove ) unset( $authors[$ka] ); } } return $authors; } } /* --------------------------------------------------------------------------- * Under Construction * --------------------------------------------------------------------------- */ if( ! function_exists('mfn_under_construction') ) { function mfn_under_construction(){ if( mfn_opts_get('construction') ){ if( isset( $_POST['_wpcf7_is_ajax_call'] ) ){ // do nothing } else { if( ! is_user_logged_in() && ! is_admin() && basename( $_SERVER['PHP_SELF']) != 'wp-login.php' && basename( $_SERVER['PHP_SELF']) != 'wp-cron.php' && basename( $_SERVER['PHP_SELF']) != 'xmlrpc.php' ){ get_template_part('under-construction'); exit(); } } } } } add_action('init', 'mfn_under_construction', 30); /* --------------------------------------------------------------------------- * Set Max Content Width * --------------------------------------------------------------------------- */ if ( ! isset( $content_width ) ) $content_width = 1200; /* --------------------------------------------------------------------------- * WPML | Date Format * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_wpml_date_format' ) ) { function mfn_wpml_date_format( $format ) { if (function_exists('icl_translate')) $format = icl_translate('Formats', $format, $format); return $format; } } add_filter('option_date_format', 'mfn_wpml_date_format'); /* --------------------------------------------------------------------------- * WPML | ID * @param type string – 'post', 'page', 'post_tag' or 'category' * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_wpml_ID' ) ) { function mfn_wpml_ID( $id, $type = 'page' ) { if( function_exists('icl_object_id') ) { return icl_object_id( $id, $type, true ); } else { return $id; } } } /* --------------------------------------------------------------------------- * WPML | Term slug * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_wpml_term_slug' ) ) { function mfn_wpml_term_slug( $slug, $type, $multi = false ){ if( function_exists( 'icl_object_id' ) ){ if( $multi ){ // multiple categories $slugs = explode( ',', $slug ); if( is_array( $slugs ) ){ foreach( $slugs as $slug_k => $slug ){ $slug = trim( $slug ); $term = get_term_by( 'slug', $slug, $type ); $term = apply_filters( 'wpml_object_id', $term->term_id, $type, true ); $slug = get_term_by( 'term_id', $term, $type )->slug; $slugs[$slug_k] = $slug; } } $slug = implode( ',', $slugs ); } else { // single category $term = get_term_by( 'slug', $slug, $type ); $term = apply_filters( 'wpml_object_id', $term->term_id, $type, true ); $slug = get_term_by( 'term_id', $term, $type )->slug; } } return $slug; } } /* --------------------------------------------------------------------------- * Schema | Auto Get Schema Type By Post Type * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_tag_schema' ) ) { function mfn_tag_schema(){ $schema = 'http'. mfn_ssl() .'://schema.org/'; // Is Woocommerce product if( function_exists( 'is_product' ) && is_product() ){ $type = false; } elseif( is_single() && get_post_type() == 'post' ) { // Single post $type = "Article"; } elseif( is_author() ) { // Author page $type = 'ProfilePage'; } elseif( is_search() ) { // Search results $type = 'SearchResultsPage'; } else { // Default $type = 'WebPage'; } if( mfn_opts_get( 'mfn-seo-schema-type' ) && $type ){ echo ' itemscope itemtype="' . $schema . $type . '"'; } return true; } } /* --------------------------------------------------------------------------- * TGM Plugin Activation * --------------------------------------------------------------------------- */ add_action( 'tgmpa_register', 'mfn_register_required_plugins' ); if( ! function_exists( 'mfn_register_required_plugins' ) ) { function mfn_register_required_plugins() { $plugins = array( // required ----------------------------- array( 'name' => 'Slider Revolution', // The plugin name. 'slug' => 'revslider', // The plugin slug (typically the folder name). 'source' => THEME_DIR .'/plugins/revslider.zip', // The plugin source. 'required' => true, // If false, the plugin is only 'recommended' instead of required. 'version' => '5.3.1.5', // E.g. 1.0.0. If set, the active plugin must be this version or higher. If the plugin version is higher than the plugin version installed, the user will be notified to update the plugin. // 'force_activation' => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch. // 'force_deactivation' => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins. // 'external_url' => '', // If set, overrides default API URL and points to an external URL. // 'is_callable' => '', // If set, this callable will be be checked for availability to determine if a plugin is active. ), array( 'name' => 'Contact Form 7', 'slug' => 'contact-form-7', 'required' => true, 'external_url' => 'https://wordpress.org/plugins/contact-form-7/', ), // recommended ----------------------------- array( 'name' => 'Duplicate Post', 'slug' => 'duplicate-post', 'required' => false, 'external_url' => 'https://wordpress.org/plugins/duplicate-post/', ), array( 'name' => 'Force Regenerate Thumbnails', 'slug' => 'force-regenerate-thumbnails', 'required' => false, 'external_url' => 'https://wordpress.org/plugins/force-regenerate-thumbnails/', ), array( 'name' => 'Layer Slider', 'slug' => 'LayerSlider', 'source' => THEME_DIR .'/plugins/layerslider.zip', 'required' => false, 'version' => '6.1.6', ), array( 'name' => 'Visual Composer', 'slug' => 'js_composer', 'source' => THEME_DIR .'/plugins/js_composer.zip', 'required' => false, 'version' => '5.0.1', ), ); $config = array( 'id' => 'mfn-be', // Unique ID for hashing notices for multiple instances of TGMPA. 'default_path' => '', // Default absolute path to bundled plugins. 'menu' => 'tgmpa-install-plugins', // Menu slug. 'parent_slug' => 'themes.php', // Parent menu slug. 'capability' => 'edit_theme_options', // Capability needed to view plugin install page, should be a capability associated with the parent menu used. 'has_notices' => true, // Show admin notices or not. 'dismissable' => true, // If false, a user cannot dismiss the nag message. 'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag. 'is_automatic' => false, // Automatically activate plugins after installation or not. 'message' => '
    '. __( 'If you are not sure about server\'s settings and limits, please activate necessary plugins ONLY', 'tgmpa' ) .'
    ', // Message to output right before the plugins table 'strings' => array( 'page_title' => __( 'Install Required Plugins', 'tgmpa' ), 'menu_title' => __( 'Install Plugins', 'tgmpa' ), 'installing' => __( 'Installing Plugin: %s', 'tgmpa' ), // %s = plugin name. 'oops' => __( 'Something went wrong with the plugin API.', 'tgmpa' ), 'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'tgmpa' ), 'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'tgmpa' ), 'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.', 'tgmpa' ), 'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.', 'tgmpa' ), 'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'tgmpa' ), 'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.', 'tgmpa' ), 'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', 'tgmpa' ), 'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.', 'tgmpa' ), 'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins', 'tgmpa' ), 'activate_link' => _n_noop( 'Begin activating plugin', 'Begin activating plugins', 'tgmpa' ), 'return' => __( 'Return to Required Plugins Installer', 'tgmpa' ), 'plugin_activated' => __( 'Plugin activated successfully.', 'tgmpa' ), 'complete' => __( 'All plugins installed and activated successfully. %s', 'tgmpa' ), // %s = dashboard link. 'nag_type' => 'updated' // Determines admin notice type - can only be 'updated', 'update-nag' or 'error'. ), ); tgmpa( $plugins, $config ); } } /** -------------------------------------------------------------------------- * DEPRECATED * --------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------- * Excerpt * @deprecated * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_excerpt' ) ) { function mfn_excerpt($post, $length = 55, $tags_to_keep = '

    ', $extra = ' [...]') { if(is_int($post)) { $post = get_post($post); } elseif(!is_object($post)) { return false; } if(has_excerpt($post->ID)) { $the_excerpt = $post->post_excerpt; return apply_filters('the_content', $the_excerpt); } else { $the_excerpt = $post->post_content; } $the_excerpt = strip_shortcodes(strip_tags($the_excerpt, $tags_to_keep)); $the_excerpt = preg_split('/\b/', $the_excerpt, $length * 2+1); $excerpt_waste = array_pop($the_excerpt); $the_excerpt = implode($the_excerpt); if( $excerpt_waste ) $the_excerpt .= $extra; return apply_filters('the_content', $the_excerpt); } } /* --------------------------------------------------------------------------- * Get Comment Excerpt * @deprecated since 12.5 * --------------------------------------------------------------------------- */ if( ! function_exists( 'mfn_get_comment_excerpt' ) ) { function mfn_get_comment_excerpt($comment_ID = 0, $num_words = 20) { $comment = get_comment( $comment_ID ); $comment_text = strip_tags($comment->comment_content); $blah = explode(' ', $comment_text); if (count($blah) > $num_words) { $k = $num_words; $use_dotdotdot = 1; } else { $k = count($blah); $use_dotdotdot = 0; } $excerpt = ''; for ($i=0; $i<$k; $i++) { $excerpt .= $blah[$i] . ' '; } $excerpt .= ($use_dotdotdot) ? '[...]' : ''; return apply_filters('get_comment_excerpt', $excerpt); } }