classes ) ? array() : (array) $item->classes; $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) ); $class_names = ' class="' . esc_attr( $class_names ) . '"'; $output .= $indent . '
  • items function my_css_attributes_filter($var) { return is_array($var) ? array() : ''; } // Remove invalid rel attribute values in the categorylist function remove_category_rel_from_category_list($thelist) { return str_replace('rel="category tag"', 'rel="tag"', $thelist); } // Add page slug to body class, love this - Credit: Starkers Wordpress Theme function add_slug_to_body_class($classes) { global $post; if (is_home()) { $key = array_search('blog', $classes); if ($key > -1) { unset($classes[$key]); } } elseif (is_page()) { $classes[] = sanitize_html_class($post->post_name); } elseif (is_singular()) { $classes[] = sanitize_html_class($post->post_name); } return $classes; } /** * Register our sidebars and widgetized areas. * */ function herowp_widgets_init() { register_sidebar( array( 'name' => 'Sidebar', 'id' => 'sidebar', 'before_widget' => '
    ', 'after_widget' => '
    ', 'before_title' => '

    ', 'after_title' => '.

    ', ) ); register_sidebar( array( 'name' => 'First Footer Widget Area', 'id' => 'first_footer', 'before_widget' => '
    ', 'after_widget' => '
    ', 'before_title' => '

    ', 'after_title' => '.

    ', ) ); register_sidebar( array( 'name' => 'Second Footer Widget Area', 'id' => 'second_footer', 'before_widget' => '
    ', 'after_widget' => '
    ', 'before_title' => '

    ', 'after_title' => '.

    ', ) ); register_sidebar( array( 'name' => 'Third Footer Widget Area', 'id' => 'third_footer', 'before_widget' => '
    ', 'after_widget' => '
    ', 'before_title' => '

    ', 'after_title' => '.

    ', ) ); register_sidebar( array( 'name' => 'Contact Sidebar', 'id' => 'contact_sidebar', 'before_widget' => '
    ', 'after_widget' => '
    ', 'before_title' => '

    ', 'after_title' => '.

    ', ) ); } add_action( 'widgets_init', 'herowp_widgets_init' ); // Remove wp_head() injected Recent Comment styles function my_remove_recent_comments_style() { global $wp_widget_factory; remove_action('wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' )); } //set tags to same font size no matter how many times is being used add_filter( 'widget_tag_cloud_args', 'herowp_tag_cloud_same_size' ); function herowp_tag_cloud_same_size($in){ return 'smallest=12&largest=12&number=25&orderby=name&unit=px'; } //custom excerpt length function excerpt($limit) { $excerpt = explode(' ', get_the_excerpt(), $limit); if (count($excerpt)>=$limit) { array_pop($excerpt); $excerpt = implode(" ",$excerpt).'...'; } else { $excerpt = implode(" ",$excerpt); } $excerpt = preg_replace('`[[^]]*]`','',$excerpt); return $excerpt; } function content($limit) { $content = explode(' ', get_the_content(), $limit); if (count($content)>=$limit) { array_pop($content); $content = implode(" ",$content).'...'; } else { $content = implode(" ",$content); } $content = preg_replace('/[.+]/','', $content); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); return $content; } //custom excerpt length for full screen blog posts remove_filter('get_the_excerpt', 'wp_trim_excerpt'); function custom_excerpt_length($text) { global $post; if ( '' == $text ) { $text = get_the_content(''); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); $excerpt_length = 90; $words = explode(' ', $text, $excerpt_length + 1); if (count($words) > $excerpt_length) { array_pop($words); array_push($words, '...'); $text = implode(' ', $words); } } return $text; } add_filter('get_the_excerpt', 'custom_excerpt_length'); // Pagination for paged posts, Page 1, Page 2, Page 3, with Next and Previous Links function herowp_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"; } /* ******************** * Limit post excerpts. Within theme files used as * print string_limit_words(get_the_excerpt(), 20); ******************************************************************** */ function string_limit_words($string, $word_limit) { $words = explode(' ', $string, ($word_limit + 1)); if(count($words) > $word_limit) array_pop($words); return implode(' ', $words); } if ( is_admin() ) { show_admin_bar( true ); } // Remove 'text/css' from our enqueued stylesheet function myway_style_remove($tag) { return preg_replace('~\s+type=["\'][^"\']++["\']~', '', $tag); } // Remove thumbnail width and height dimensions that prevent fluid images in the_thumbnail function remove_thumbnail_dimensions( $html ) { $html = preg_replace('/(width|height)=\"\d*\"\s/', "", $html); return $html; } // Custom Gravatar in Settings > Discussion function mywaygravatar ($avatar_defaults) { $myavatar = get_template_directory_uri() . '/img/gravatar.jpg'; $avatar_defaults[$myavatar] = "Custom Gravatar"; return $avatar_defaults; } // Threaded Comments function enable_threaded_comments() { if (!is_admin()) { if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1)) { wp_enqueue_script('comment-reply'); } } } /*------------------------------------*\ Actions + Filters + ShortCodes \*------------------------------------*/ // Add Actions //add_action('init', 'myway_header_scripts'); // Add Custom Scripts to wp_head //add_action('wp_print_scripts', 'myway_conditional_scripts'); // Add Conditional Page Scripts add_action('get_header', 'enable_threaded_comments'); // Enable Threaded Comments add_action('widgets_init', 'my_remove_recent_comments_style'); // Remove inline Recent Comment Styles from wp_head() // Remove Actions remove_action('wp_head', 'feed_links_extra', 3); // Display the links to the extra feeds such as category feeds remove_action('wp_head', 'feed_links', 2); // Display the links to the general feeds: Post and Comment Feed remove_action('wp_head', 'rsd_link'); // Display the link to the Really Simple Discovery service endpoint, EditURI link remove_action('wp_head', 'wlwmanifest_link'); // Display the link to the Windows Live Writer manifest file. remove_action('wp_head', 'index_rel_link'); // Index link remove_action('wp_head', 'parent_post_rel_link', 10, 0); // Prev link remove_action('wp_head', 'start_post_rel_link', 10, 0); // Start link remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // Display relational links for the posts adjacent to the current post. remove_action('wp_head', 'wp_generator'); // Display the XHTML generator that is generated on the wp_head hook, WP version remove_action('wp_head', 'start_post_rel_link', 10, 0); remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); remove_action('wp_head', 'rel_canonical'); remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); // Add Filters add_filter('avatar_defaults', 'mywaygravatar'); // Custom Gravatar in Settings > Discussion add_filter('body_class', 'add_slug_to_body_class'); // Add slug to body class (Starkers build) add_filter('widget_text', 'do_shortcode'); // Allow shortcodes in Dynamic Sidebar add_filter('widget_text', 'shortcode_unautop'); // Remove

    tags in Dynamic Sidebars (better!) add_filter('wp_nav_menu_args', 'my_wp_nav_menu_args'); // Remove surrounding

    from WP Navigation // add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1); // Remove Navigation
  • injected classes (Commented out by default) // add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1); // Remove Navigation
  • injected ID (Commented out by default) // add_filter('page_css_class', 'my_css_attributes_filter', 100, 1); // Remove Navigation
  • Page ID's (Commented out by default) add_filter('the_category', 'remove_category_rel_from_category_list'); // Remove invalid rel attribute add_filter('the_excerpt', 'shortcode_unautop'); // Remove auto

    tags in Excerpt (Manual Excerpts only) add_filter('the_excerpt', 'do_shortcode'); // Allows Shortcodes to be executed in Excerpt (Manual Excerpts only) add_filter('style_loader_tag', 'myway_style_remove'); // Remove 'text/css' from enqueued stylesheet add_filter('post_thumbnail_html', 'remove_thumbnail_dimensions', 10); // Remove width and height dynamic attributes to thumbnails add_filter('image_send_to_editor', 'remove_thumbnail_dimensions', 10); // Remove width and height dynamic attributes to post images // Remove Filters remove_filter('the_excerpt', 'wpautop'); // Remove

    tags from Excerpt altogether // Shortcodes above would be nested like this - // [myway_shortcode_demo] [myway_shortcode_demo_2] Here's the page title! [/myway_shortcode_demo_2] [/myway_shortcode_demo] /*------------------------------------*\ ShortCode Functions \*------------------------------------*/ // Shortcode Demo with Nested Capability function myway_shortcode_demo($atts, $content = null) { return '

    ' . do_shortcode($content) . '
    '; // do_shortcode allows for nested Shortcodes } // Shortcode Demo with simple

    tag function myway_shortcode_demo_2($atts, $content = null) // Demo Heading H2 shortcode, allows for nesting within above element. Fully expandable. { return '

    ' . $content . '

    '; } /*------------------------------------*\ AqResize Functions \*------------------------------------*/ if(!class_exists('Aq_Resize')) { class Aq_Resize { /** * The singleton instance */ static private $instance = null; /** * No initialization allowed */ private function __construct() {} /** * No cloning allowed */ private function __clone() {} /** * For your custom default usage you may want to initialize an Aq_Resize object by yourself and then have own defaults */ static public function getInstance() { if(self::$instance == null) { self::$instance = new self; } return self::$instance; } /** * Run, forest. */ public function process( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) { // Validate inputs. if ( ! $url || ( ! $width && ! $height ) ) return false; // Caipt'n, ready to hook. if ( true === $upscale ) add_filter( 'image_resize_dimensions', array($this, 'aq_upscale'), 10, 6 ); // Define upload path & dir. $upload_info = wp_upload_dir(); $upload_dir = $upload_info['basedir']; $upload_url = $upload_info['baseurl']; $http_prefix = "http://"; $https_prefix = "https://"; /* if the $url scheme differs from $upload_url scheme, make them match if the schemes differe, images don't show up. */ if(!strncmp($url,$https_prefix,strlen($https_prefix))){ //if url begins with https:// make $upload_url begin with https:// as well $upload_url = str_replace($http_prefix,$https_prefix,$upload_url); } elseif(!strncmp($url,$http_prefix,strlen($http_prefix))){ //if url begins with http:// make $upload_url begin with http:// as well $upload_url = str_replace($https_prefix,$http_prefix,$upload_url); } // Check if $img_url is local. if ( false === strpos( $url, $upload_url ) ) return false; // Define path of image. $rel_path = str_replace( $upload_url, '', $url ); $img_path = $upload_dir . $rel_path; // Check if img path exists, and is an image indeed. if ( ! file_exists( $img_path ) or ! getimagesize( $img_path ) ) return false; // Get image info. $info = pathinfo( $img_path ); $ext = $info['extension']; list( $orig_w, $orig_h ) = getimagesize( $img_path ); // Get image size after cropping. $dims = image_resize_dimensions( $orig_w, $orig_h, $width, $height, $crop ); $dst_w = $dims[4]; $dst_h = $dims[5]; // Return the original image only if it exactly fits the needed measures. if ( ! $dims && ( ( ( null === $height && $orig_w == $width ) xor ( null === $width && $orig_h == $height ) ) xor ( $height == $orig_h && $width == $orig_w ) ) ) { $img_url = $url; $dst_w = $orig_w; $dst_h = $orig_h; } else { // Use this to check if cropped image already exists, so we can return that instead. $suffix = "{$dst_w}x{$dst_h}"; $dst_rel_path = str_replace( '.' . $ext, '', $rel_path ); $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}"; if ( ! $dims || ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) ) { // Can't resize, so return false saying that the action to do could not be processed as planned. return false; } // Else check if cache exists. elseif ( file_exists( $destfilename ) && getimagesize( $destfilename ) ) { $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}"; } // Else, we resize the image and return the new resized image url. else { $editor = wp_get_image_editor( $img_path ); if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) return false; $resized_file = $editor->save(); if ( ! is_wp_error( $resized_file ) ) { $resized_rel_path = str_replace( $upload_dir, '', $resized_file['path'] ); $img_url = $upload_url . $resized_rel_path; } else { return false; } } } // Okay, leave the ship. if ( true === $upscale ) remove_filter( 'image_resize_dimensions', array( $this, 'aq_upscale' ) ); // Return the output. if ( $single ) { // str return. $image = $img_url; } else { // array return. $image = array ( 0 => $img_url, 1 => $dst_w, 2 => $dst_h ); } return $image; } /** * Callback to overwrite WP computing of thumbnail measures */ function aq_upscale( $default, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) { if ( ! $crop ) return null; // Let the wordpress default function handle this. // Here is the point we allow to use larger image size than the original one. $aspect_ratio = $orig_w / $orig_h; $new_w = $dest_w; $new_h = $dest_h; if ( ! $new_w ) { $new_w = intval( $new_h * $aspect_ratio ); } if ( ! $new_h ) { $new_h = intval( $new_w / $aspect_ratio ); } $size_ratio = max( $new_w / $orig_w, $new_h / $orig_h ); $crop_w = round( $new_w / $size_ratio ); $crop_h = round( $new_h / $size_ratio ); $s_x = floor( ( $orig_w - $crop_w ) / 2 ); $s_y = floor( ( $orig_h - $crop_h ) / 2 ); return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h ); } } } if(!function_exists('aq_resize')) { /** * This is just a tiny wrapper function for the class above so that there is no * need to change any code in your own WP themes. Usage is still the same :) */ function aq_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) { $aq_resize = Aq_Resize::getInstance(); return $aq_resize->process( $url, $width, $height, $crop, $single, $upscale ); } } function title_excerpt( $length ) { $excerpt = explode( ' ', get_the_title(), $length ); if ( count( $excerpt ) >= $length ) { array_pop( $excerpt ); $excerpt = implode( " ", $excerpt ); } else { $excerpt = implode( " ", $excerpt ); } $excerpt = preg_replace( '`\[[^\]]*\]`', '', $excerpt ); return $excerpt.''; } //convert HEX to RGBA function function hex2rgba($hex, $alpha = 1) { $hex = str_replace('#', '', $hex); $r = $g = $b = 0; switch(strlen($hex)){ case 3: list($r, $g, $b) = str_split($hex); $r = hexdec($r.$r); $g = hexdec($g.$g); $b = hexdec($b.$b); break; case 6: list($r1, $r2, $g1, $g2, $b1, $b2) = str_split($hex); $r = hexdec($r1.$r2); $g = hexdec($g1.$g2); $b = hexdec($b1.$b2); break; default: break; } return 'rgba('.$r.', '.$g.', '.$b.', '.$alpha.')'; } if ( ! function_exists( 'twentytwelve_content_nav' ) ) : /** * Displays navigation to next/previous pages when applicable. * * @since Twenty Twelve 1.0 */ function twentytwelve_content_nav() { global $wp_query; if ( $wp_query->max_num_pages > 1 ) : ?> '.__( '', 'bbold-lite' ) ); ?> '.__( '', 'bbold-lite' ) ); ?> comment_type ) : case 'pingback' : case 'trackback' : ?>
  • ', '' ); ?>

    $depth, 'max_depth' => $args['max_depth'],'reply_text'=>'Reply Comment')); ?>
    post_author; */ $current_user = wp_get_current_user(); $new_post_author = $current_user->ID; /* * if post data exists, create the post duplicate */ if (isset( $post ) && $post != null) { /* * new post data array */ $args = array( 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $new_post_author, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_name' => $post->post_name, 'post_parent' => $post->post_parent, 'post_password' => $post->post_password, 'post_status' => 'draft', 'post_title' => $post->post_title, 'post_type' => $post->post_type, 'to_ping' => $post->to_ping, 'menu_order' => $post->menu_order ); /* * insert the post by wp_insert_post() function */ $new_post_id = wp_insert_post( $args ); /* * get all current post terms ad set them to the new post draft */ $taxonomies = get_object_taxonomies($post->post_type); // returns array of taxonomy names for post type, ex array("category", "post_tag"); foreach ($taxonomies as $taxonomy) { $post_terms = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'slugs')); wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false); } /* * duplicate all post meta */ $post_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id"); if (count($post_meta_infos)!=0) { $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) "; foreach ($post_meta_infos as $meta_info) { $meta_key = $meta_info->meta_key; $meta_value = addslashes($meta_info->meta_value); $sql_query_sel[]= "SELECT $new_post_id, '$meta_key', '$meta_value'"; } $sql_query.= implode(" UNION ALL ", $sql_query_sel); $wpdb->query($sql_query); } /* * finally, redirect to the edit post screen for the new draft */ wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) ); exit; } else { wp_die('Post creation failed, could not find original post: ' . $post_id); } } add_action( 'admin_action_herowp_duplicate_post_as_draft', 'herowp_duplicate_post_as_draft' ); /* * Add the duplicate link to action list for post_row_actions */ function herwowp_duplicate_post_link( $actions, $post ) { if (current_user_can('edit_posts')) { $actions['duplicate'] = 'Duplicate'; } return $actions; } add_filter( 'post_row_actions', 'herwowp_duplicate_post_link', 10, 2 ); ?>