$count){ preg_match('/^.{0,' . $count . '}(?:.*?)\b/siu', $text, $matches); $text = $matches[0]; }else{ $wrapText = ''; } return $text . $wrapText; } function hex2rgb($hex) { $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)); } $rgb = array($r, $g, $b); return implode(",", $rgb); // returns the rgb values separated by commas //return $rgb; // returns an array with the rgb values } function custom_trim_excerpt($length, $ending) { global $post; $explicit_excerpt = $post->post_excerpt; if ( '' == $explicit_excerpt ) { $text = get_the_content(''); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); } else { $text = apply_filters('the_content', $explicit_excerpt); } $text = strip_shortcodes( $text ); // optional $text = strip_tags($text); $excerpt_length = $length; $words = explode(' ', $text, $excerpt_length + 1); if (count($words)> $excerpt_length) { array_pop($words); array_push($words, $ending); $text = implode(' ', $words); $text = apply_filters('the_excerpt',$text); } return $text; } function my_highlight_tags($cloud) { global $wpdb; $tags = single_tag_title('', false); $tags_array = explode(" + ", $tags); foreach ($tags_array as $tag_name) { $tag_id = $wpdb->get_var("SELECT term_id FROM $wpdb->terms WHERE name = '".$tag_name."'"); $cloud = str_replace( "tag-link-$tag_id", "tag-link-$tag_id current", $cloud); } return $cloud; } add_filter( 'wp_tag_cloud', 'my_highlight_tags' ); function filter_ptags_on_images($content){ return preg_replace('/

\s*()?\s*()\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content); } add_filter('the_content', 'filter_ptags_on_images'); /** * Like get_template_part() put lets you pass args to the template file * Args are available in the tempalte as $template_args array * @param string filepart * @param mixed wp_args style argument list */ function hm_get_template_part( $file, $template_args = array(), $cache_args = array() ) { $template_args = wp_parse_args( $template_args ); $cache_args = wp_parse_args( $cache_args ); if ( $cache_args ) { foreach ( $template_args as $key => $value ) { if ( is_scalar( $value ) || is_array( $value ) ) { $cache_args[$key] = $value; } else if ( is_object( $value ) && method_exists( $value, 'get_id' ) ) { $cache_args[$key] = call_user_func( 'get_id', $value ); } } if ( ( $cache = wp_cache_get( $file, serialize( $cache_args ) ) ) !== false ) { if ( ! empty( $template_args['return'] ) ) return $cache; echo $cache; return; } } $file_handle = $file; do_action( 'start_operation', 'hm_template_part::' . $file_handle ); if ( file_exists( get_stylesheet_directory() . '/' . $file . '.php' ) ) $file = get_stylesheet_directory() . '/' . $file . '.php'; elseif ( file_exists( get_template_directory() . '/' . $file . '.php' ) ) $file = get_template_directory() . '/' . $file . '.php'; ob_start(); $return = require( $file ); $data = ob_get_clean(); do_action( 'end_operation', 'hm_template_part::' . $file_handle ); if ( $cache_args ) { wp_cache_set( $file, $data, serialize( $cache_args ), 3600 ); } if ( ! empty( $template_args['return'] ) ) if ( $return === false ) return false; else return $data; echo $data; } function set_event_columns($columns) { $columns = array( 'cb' => '', 'title' => 'Title', 'start_date' => 'Start Date', 'end_date' => 'End Date', ); return $columns; } function event_custom_columns($column) { global $post; if( $column == 'start_date' ) { $date = get_field('start_date'); $d = new DateTime($date); echo $d->format('F j, Y'); } elseif ( $column == 'end_date' ) { $date = get_field('end_date'); $d = new DateTime($date); echo $d->format('F j, Y'); } } function event_sortable_columns( $columns ) { $columns['start_date'] = 'start_date'; return $columns; } add_filter("manage_event_posts_columns", "set_event_columns"); add_action("manage_event_posts_custom_column", "event_custom_columns"); add_filter( 'manage_edit-event_sortable_columns', 'event_sortable_columns' ); add_action( 'pre_get_posts', 'event_column_orderby' ); function event_column_orderby( $query ) { if( ! is_admin() ) return; $orderby = $query->get( 'orderby'); if( 'start_date' == $orderby ) { $query->set('meta_key','start_date'); $query->set('orderby','meta_value_num'); } } // Expire events if ($expireTransient = get_transient($post->ID) === false) { set_transient($post->ID, 'set for 1 minutes', 1 * MINUTE_IN_SECONDS ); //$today = date('Y-m-d H:i:s', current_time('timestamp', 0)); $today = date('Ymd'); $args = array( 'post_type' => 'event', 'posts_per_page' => -1, 'post_status' => 'publish', 'meta_query' => array( array( 'key' => 'end_date', 'value' => $today, 'compare' => '<=' ) ) ); $posts = get_posts($args); foreach( $posts as $post ) { if(get_field('end_date', $post->ID)) { $postdata = array( 'ID' => $post->ID, 'post_status' => 'draft' ); wp_update_post($postdata); } } }