Esempio n. 1
0
/**
 * Output skip-to-content link markup for screen readers.
 *
 * @since  1.0.0
 * @access public
 * @param  string $target The target for the link.
 * @param  array  $args A list of arguments to control the output of the skip link.
 * @return string
 */
function carelib_get_skip_link($target, $args = array())
{
    $defaults = apply_filters("{$GLOBALS['carelib_prefix']}_skip_link_defaults", array('attr' => 'skip-link', 'text' => sprintf(esc_html__('Skip to %s (Press enter)', 'carelib'), $target), 'before' => '', 'after' => ''), $target);
    $args = wp_parse_args($args, $defaults);
    // Bail if required args have been removed via a filter.
    if (!isset($args['attr'], $args['text'])) {
        return false;
    }
    $html = '';
    $html .= isset($args['before']) ? $args['before'] : '';
    $html .= sprintf('<div %s><a class="button screen-reader-text" href="#%s">%s</a></div><!-- .skip-link -->', carelib_get_attr($args['attr'], $target), esc_attr($target), $args['text']);
    $html .= isset($args['after']) ? $args['after'] : '';
    return apply_filters("{$GLOBALS['carelib_prefix']}_skip_link", $html, $target, $args);
}
Esempio n. 2
0
/**
 * Output the 404 entry title.
 *
 * @since  1.0.0
 * @access public
 * @return string The 404 entry title.
 */
function carelib_get_404_entry_title()
{
    $text = apply_filters("{$GLOBALS['carelib_prefix']}_404_entry_title", __('Oops! That page can&rsquo;t be found.', 'carelib'));
    return sprintf('<h1 %s>%s</h1>', carelib_get_attr('entry-title'), esc_attr($text));
}
Esempio n. 3
0
/**
 * Helper function to build a next and previous post navigation element on
 * single entries. This takes care of all the annoying formatting which usually
 * would need to be done within a template.
 *
 * I originally wanted to use the new get_the_post_navigation tag for this;
 * however, it's lacking a lot of the flexibility provided by using the old
 * template tags directly. Until WordPress core gets its act together, I guess
 * I'll just have to duplicate code for no good reason.
 *
 * @since  1.0.0
 * @access public
 * @param  array $args Empty array if no arguments.
 * @return string
 */
function carelib_get_post_navigation($args = array())
{
    if (is_attachment() || !is_singular()) {
        return;
    }
    $name = _carelib_get_post_type_name(get_queried_object());
    $defaults = apply_filters("{$GLOBALS['carelib_prefix']}_post_navigation_defaults", array('post_types' => array(), 'prev_format' => '<span class="nav-previous">%link</span>', 'next_format' => '<span class="nav-next">%link</span>', 'prev_text' => __('Previous', 'carelib') . esc_html($name), 'next_text' => __('Next', 'carelib') . esc_html($name), 'in_same_term' => false, 'excluded_terms' => '', 'taxonomy' => 'category'));
    $args = wp_parse_args($args, $defaults);
    $types = (array) $args['post_types'];
    // Bail if we're not on a single entry. All post types except pages are allowed by default.
    if (!is_singular($types) || !in_array('page', $types, true) && is_page()) {
        return false;
    }
    $required = isset($args['prev_format'], $args['prev_text'], $args['next_format'], $args['next_text'], $args['in_same_term'], $args['excluded_terms'], $args['taxonomy']);
    // Bail if required args have been removed via a filter.
    if (!$required) {
        return false;
    }
    $links = '';
    // Previous post link. Can be filtered via WP Core's previous_post_link filter.
    $links .= get_adjacent_post_link($args['prev_format'], $args['prev_text'], $args['in_same_term'], $args['excluded_terms'], true, $args['taxonomy']);
    // Next post link. Can be filtered via WP Core's next_post_link filter.
    $links .= get_adjacent_post_link($args['next_format'], $args['next_text'], $args['in_same_term'], $args['excluded_terms'], false, $args['taxonomy']);
    // Bail if we don't have any posts to link to.
    if (empty($links)) {
        return false;
    }
    return sprintf('<nav %s>%s</nav><!-- .nav-single -->', carelib_get_attr('nav', 'single'), $links);
}
Esempio n. 4
0
/**
 * Return a formatted <img> string.
 *
 * @since  1.0.0
 * @access protected
 * @param  array $args Arguments for how to load and display the image.
 * @param  array $image Array of image attributes ($image, $classes, $alt, $caption).
 * @return string $image Formatted image markup.
 */
function _carelib_image_format_image_html($args, $image)
{
    if (isset($image['post_thumbnail_id'])) {
        do_action('begin_fetch_post_thumbnail_html', $args['post_id'], $image['post_thumbnail_id'], $args['size']);
    }
    $attr = _carelib_image_get_default_attr($args, $image);
    if (!empty($args['image_attr'])) {
        $attr = array_merge($attr, $args['image_attr']);
    }
    $html = sprintf('<img %s />', carelib_get_attr('image', '', $attr));
    if (isset($image['post_thumbnail_id'])) {
        do_action('end_fetch_post_thumbnail_html', $args['post_id'], $image['post_thumbnail_id'], $args['size']);
    }
    return _carelib_image_maybe_add_link_wrapper($html, $args);
}
Esempio n. 5
0
/**
 * Helper function to build a newer/older or paginated navigation element within
 * a loop of multiple entries. This takes care of all the annoying formatting
 * which usually would need to be done within a template.
 *
 * @since  1.0.0
 * @access public
 * @param  array $args An optional list of options.
 * @return string
 */
function carelib_get_posts_navigation($args = array())
{
    global $wp_query;
    // Return early if we're on a singular post or we only have one page.
    if (is_singular() || 1 === $wp_query->max_num_pages) {
        return;
    }
    $defaults = apply_filters("{$GLOBALS['carelib_prefix']}_posts_navigation_defaults", array('nav_type' => 'pagination', 'prev_link_text' => __('Newer Posts', 'carelib'), 'next_link_text' => __('Older Posts', 'carelib'), 'prev_text' => sprintf('<span class="screen-reader-text">%s</span>', __('Previous Page', 'carelib')), 'next_text' => sprintf('<span class="screen-reader-text">%s</span>', __('Next Page', 'carelib'))));
    $args = wp_parse_args($args, $defaults);
    if (function_exists('the_posts_pagination') && 'pagination' === $args['nav_type']) {
        $output = get_the_posts_pagination($args);
    } else {
        $output = '<nav ' . carelib_get_attr('nav', 'archive') . '>';
        $output .= sprintf('<span class="nav-previous">%s</span>', get_previous_posts_link($args['prev_link_text']));
        $output .= sprintf('<span class="nav-next">%s</span>', get_next_posts_link($args['next_link_text']));
        $output .= '</nav><!-- .nav-archive -->';
    }
    return apply_filters("{$GLOBALS['carelib_prefix']}_posts_navigation", $output, $args);
}