: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Outputs any content into log file in theme root directory
* @param mixed $mixed Content to output
if ( !function_exists( 'herald_log' ) ):
function herald_log( $mixed ) {
if ( !function_exists( 'WP_Filesystem' ) || !WP_Filesystem() ) {
if ( is_array( $mixed ) ) {
$mixed = print_r( $mixed, 1 );
} else if ( is_object( $mixed ) ) {
$existing = $wp_filesystem->get_contents( get_parent_theme_file_path( 'log' ) );
$wp_filesystem->put_contents( get_parent_theme_file_path( 'log' ), $existing. $mixed . PHP_EOL );
* Get option value from theme options
* A wrapper function for WordPress native get_option()
* which gets an option from specific option key (set in theme options panel)
* @param string $option Name of the option
* @return mixed Specific option value or "false" (if option is not found)
if ( !function_exists( 'herald_get_option' ) ):
function herald_get_option( $option ) {
if ( empty( $herald_settings ) ) {
$herald_settings = get_option( 'herald_settings' );
if ( !isset( $herald_settings[$option] ) ) {
$herald_settings[$option] = herald_get_default_option( $option );
if ( isset( $herald_settings[$option] ) ) {
return is_array( $herald_settings[$option] ) && isset( $herald_settings[$option]['url'] ) ? $herald_settings[$option]['url'] : $herald_settings[$option];
* Get current post layout
* It checks which posts layout to display based on current template options
* @param int $i Index of the current post in loop
* @return string Layout ID
if ( !function_exists( 'herald_get_current_post_layout' ) ):
function herald_get_current_post_layout( $i ) {
$layout = 'a'; //layout a as default
$starter_limit = 0; //do not display starter layout by default
$herald_template = herald_detect_template();
if ( in_array( $herald_template, array( 'search', 'tag', 'author', 'archive' ) ) ) {
$layout = herald_get_option( $herald_template.'_layout' );
$starter_layout = herald_get_option( $herald_template.'_starter_layout' );
$starter_limit = $starter_layout != 'none' ? herald_get_option( $herald_template.'_starter_limit' ) : 0;
} else if ( $herald_template == 'category' ) {
$obj = get_queried_object();
if ( isset( $obj->term_id ) ) {
$meta = herald_get_category_meta( $obj->term_id );
$layout = $meta['layout'] == 'inherit' ? herald_get_option( $herald_template.'_layout' ) : $meta['layout'];
if ( $meta['starter_layout'] != 'inherit' ) {
$starter_layout = $meta['starter_layout'];
$starter_limit = $starter_layout != 'none' ? $meta['starter_limit'] : 0;
$starter_layout = herald_get_option( $herald_template.'_starter_layout' );
$starter_limit = $starter_layout != 'none' ? herald_get_option( $herald_template.'_starter_limit' ) : 0;
if ( !is_paged() && $starter_limit > $i ) {
* Get layout of single post
* It checks which layout to display for current single post
* @return string Layout ID
if ( !function_exists( 'herald_get_single_layout' ) ):
function herald_get_single_layout( $post_id = false ) {
$layout = herald_get_post_meta( $post_id, 'layout' );
if ( $layout == 'inherit' ) {
$layout = herald_get_option( 'single_layout' );
if ( herald_is_paginated_post() && in_array( $layout, array( 3, 6, 9 ) ) ) {
* Get position of meta bar for single post
* It checks which layout to display for current single post
* @return string Layout ID
if ( !function_exists( 'herald_get_single_meta_bar_position' ) ):
function herald_get_single_meta_bar_position() {
$layout = herald_get_post_meta( get_the_ID(), 'meta_bar_position' );
if ( $layout == 'inherit' ) {
$layout = herald_get_option( 'single_meta_bar_position' );
* It checks which layout to display for current page
* @return string Layout ID
if ( !function_exists( 'herald_get_page_layout' ) ):
function herald_get_page_layout( $post_id = false ) {
$layout = herald_get_page_meta( $post_id, 'layout' );
if ( $layout == 'inherit' ) {
$layout = herald_get_option( 'page_layout' );
* @param unknown $field specific option key
* @return mixed meta data value or set of values
if ( !function_exists( 'herald_get_post_meta' ) ):
function herald_get_post_meta( $post_id = false, $field = false ) {
if ( empty( $post_id ) ) {
'use_sidebar' => 'inherit',
'sticky_sidebar' => 'inherit',
'meta_bar_position' => 'inherit',
'sticky_bar' => 'inherit',
$meta = get_post_meta( $post_id, '_herald_meta', true );
$meta = herald_parse_args( $meta, $defaults );
if ( isset( $meta[$field] ) ) {
* @param unknown $field specific option key
* @return mixed meta data value or set of values
if ( !function_exists( 'herald_get_page_meta' ) ):
function herald_get_page_meta( $post_id = false, $field = false ) {
if ( empty( $post_id ) ) {
'use_sidebar' => 'inherit',
'sticky_sidebar' => 'inherit',
'orderby' => 'post_count',
$meta = get_post_meta( $post_id, '_herald_meta', true );
$meta = herald_parse_args( $meta, $defaults );
if ( isset( $meta[$field] ) ) {
* @param unknown $field specific option key
* @return mixed meta data value or set of values
if ( !function_exists( 'herald_get_category_meta' ) ):
function herald_get_category_meta( $cat_id = false, $field = false ) {
'use_sidebar' => 'inherit',
'sticky_sidebar' => 'inherit',
'starter_layout' => 'inherit',
'starter_limit' => herald_get_option( 'category_starter_limit' ),
'fa_layout' => 'inherit',
'color_type' => 'inherit',
'color' => herald_get_option( 'color_content_acc' ),
'ppp_num' => herald_get_option( 'category_ppp' ) == 'inherit' ? get_option( 'posts_per_page' ) : herald_get_option( 'category_ppp_num' ),
$meta = get_option( '_herald_category_'.$cat_id );
$meta = wp_parse_args( (array) $meta, $defaults );
if ( isset( $meta[$field] ) ) {
* It checks which pagination type to display based on current template options
* @return string|bool Pagination layout or false if there is no pagination
if ( !function_exists( 'herald_get_current_pagination' ) ):
function herald_get_current_pagination() {
if ( $wp_query->max_num_pages <= 1 ) {
$layout = 'numeric'; //layout numeric as default
$herald_template = herald_detect_template();
if ( in_array( $herald_template, array( 'search', 'tag', 'author', 'archive' ) ) ) {
$layout = herald_get_option( $herald_template.'_pag' );
} else if ( $herald_template == 'category' ) {
$obj = get_queried_object();
if ( isset( $obj->term_id ) ) {
$meta = herald_get_category_meta( $obj->term_id );
$layout = $meta['pag'] == 'inherit' ? herald_get_option( $herald_template.'_pag' ) : $meta['pag'];
* @param string $prev Previous link text
* @param string $next Next link text
* @return string Pagination HTML output or empty string
if ( !function_exists( 'herald_numeric_pagination' ) ):
function herald_numeric_pagination( $prev = '‹', $next = '›' ) {
global $wp_query, $wp_rewrite;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
'base' => @add_query_arg( 'paged', '%#%' ),
'total' => $wp_query->max_num_pages,
if ( $wp_rewrite->using_permalinks() )
$pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' );
if ( !empty( $wp_query->query_vars['s'] ) )
$pagination['add_args'] = array( 's' => str_replace( ' ', '+', get_query_var( 's' ) ) );
$links = paginate_links( $pagination );
return empty( $links ) ? '' : $links;
* Get author social links
* @param int $author_id ID of an author/user
* @return string HTML output of social links
if ( !function_exists( 'herald_get_author_social' ) ):
function herald_get_author_social( $author_id ) {
if ( $url = get_the_author_meta( 'url', $author_id ) ) {
$output .= '<a href="'.esc_url( $url ).'" target="_blank" class="fa fa-link"></a>';
$social = herald_get_social();
if ( !empty( $social ) ) {
foreach ( $social as $id => $name ) {
if ( $social_url = get_the_author_meta( $id, $author_id ) ) {
if ( $id == 'twitter' ) {
$pos = strpos( $social_url, '@' );
$social_url = 'https://twitter.com/'.substr( $social_url, $pos, strlen( $social_url ) );
$output .= '<a href="'.esc_url( $social_url ).'" target="_blank" class="fa fa-'.$id.'"></a>';
* @return object WP_Query
if ( !function_exists( 'herald_get_trending_posts' ) ):
function herald_get_trending_posts( $post_id = false ) {
$args['ignore_sticky_posts'] = 1;
$manual = herald_get_option( 'trending_manual' );
if ( !empty( $manual ) ) {
$manual = array_map( 'absint', explode( ",", $manual ) );
$args['posts_per_page'] = absint( count( $manual ) );
$args['orderby'] = 'post__in';
$args['post__in'] = $manual;
$args['post_type'] = array_keys( get_post_types( array( 'public' => true ) ) ); //support all existing public post types
$number_of_posts = herald_get_option('trending_slider') == true ? herald_get_option('trending_slider_post') : herald_get_option('trending_number');
$args['post_type'] = 'post';
$args['posts_per_page'] = $number_of_posts;
$args['orderby'] = herald_get_option( 'trending_order' );
if ( $args['orderby'] == 'views' && function_exists( 'ev_get_meta_key' ) ) {
$args['orderby'] = 'meta_value_num';
$args['meta_key'] = ev_get_meta_key();
} else if ( strpos( $args['orderby'], 'reviews' ) !== false && herald_is_wp_review_active() ) {
if ( strpos( $args['orderby'], 'user' ) !== false ) {
$review_type = substr( $args['orderby'], 13, strlen( $args['orderby'] ) );
$args['orderby'] = 'meta_value_num';
$args['meta_key'] = 'wp_review_user_reviews';
$args['meta_query'] = array(
'key' => 'wp_review_user_review_type',