<?php
/**
 * Remove ... From Excerpt
 *
 * @since 1.0.0
 */
if (!function_exists('markup_excerpt_more')) :
    function markup_excerpt_more($more)
    {
        if (!is_admin()) {
            return '';
        }
    }
endif;
add_filter('excerpt_more', 'markup_excerpt_more');

/**
 * Filter to change excerpt lenght size
 *
 * @since 1.0.0
 */
if (!function_exists('markup_alter_excerpt')) :
    function markup_alter_excerpt($length)
    {
        if (is_admin()) {
            return $length;
        }
        global $markup_theme_options;
        // Read defensively: the global may not be populated yet on requests that
        // never load the header template.
        $excerpt_length = isset($markup_theme_options['markup-excerpt-length'])
            ? absint($markup_theme_options['markup-excerpt-length'])
            : 0;
        if (!empty($excerpt_length)) {
            return $excerpt_length;
        }
        return 50;
    }
endif;
add_filter('excerpt_length', 'markup_alter_excerpt');

/**
 * Exclude category in blog page
 *
 * @since Markup 1.0.0
 *
 * @param null
 * @return int
 */
if (!function_exists('markup_exclude_category_in_blog_page')) :
    function markup_exclude_category_in_blog_page($query)
    {
        if ($query->is_home && $query->is_main_query()) {
            $GLOBALS['markup_theme_options'] = markup_get_options_value();
            global $markup_theme_options;
            $blog_catid = esc_attr($markup_theme_options['markup-blog-exclude-category']);
            $exclude_categories = $blog_catid;
            if (!empty($exclude_categories)) {
                $cats = explode(',', $exclude_categories);
                $cats = array_filter($cats, 'is_numeric');
                $string_exclude = '';
                if (!empty($cats)) {
                    $string_exclude = '-' . implode(',-', $cats);
                    $query->set('cat', $string_exclude);
                }
            }
        }
        return $query;
    }
endif;
add_filter('pre_get_posts', 'markup_exclude_category_in_blog_page');