Exemplo n.º 1
0
/**
 * Custom page title for Achievements pages
 *
 * @param string $title Optional. The title (not used).
 * @param string $sep Optional, default is '»'. How to separate each part within the page title.
 * @param string $seplocation Optional. Direction to display title, 'right'.
 * @return string The title
 * @since Achievements (3.0)
 */
function dpa_title($title = '', $sep = '»', $seplocation = '')
{
    $new_title = array();
    // Achievement archive
    if (dpa_is_achievement_archive()) {
        $new_title['text'] = dpa_get_achievement_archive_title();
        // Single achievement page
    } elseif (dpa_is_single_achievement()) {
        $new_title['text'] = dpa_get_achievement_title();
        $new_title['format'] = esc_attr__('Achievement: %s', 'achievements');
    }
    $new_title = apply_filters('dpa_raw_title_array', $new_title);
    $new_title = dpa_parse_args($new_title, array('format' => '%s', 'text' => $title), 'title');
    // Get the formatted raw title
    $new_title = sprintf($new_title['format'], $new_title['text']);
    $new_title = apply_filters('dpa_raw_title', $new_title, $sep, $seplocation);
    // Compare new title with original title
    if ($new_title === $title) {
        return $title;
    }
    // Temporary separator for accurate flipping, if necessary
    $t_sep = '%WP_TITILE_SEP%';
    $prefix = '';
    if (!empty($new_title)) {
        $prefix = " {$sep} ";
    }
    // Separate on right, so reverse the order
    if ('right' === $seplocation) {
        $new_title_array = explode($t_sep, $new_title);
        $new_title_array = array_reverse($new_title_array);
        $new_title = implode(" {$sep} ", $new_title_array) . $prefix;
        // Separate on left, do not reverse
    } else {
        $new_title_array = explode($t_sep, $new_title);
        $new_title = $prefix . implode(" {$sep} ", $new_title_array);
    }
    // Filter and return
    return apply_filters('dpa_title', $new_title, $sep, $seplocation);
}
Exemplo n.º 2
0
/**
 * Output the achievement archive title
 *
 * @param string $title Optional. Default text to use as title
 * @since Achievements (3.0)
 */
function dpa_achievement_archive_title($title = '')
{
    echo esc_html(dpa_get_achievement_archive_title($title));
}
Exemplo n.º 3
0
/**
 * Reset main query vars and filter 'the_content' to output an Achievements template part as needed.
 *
 * @param string $template Optional
 * @since Achievements (3.0)
 */
function dpa_template_include_theme_compat($template = '')
{
    // Bail if a root template was already found. This prevents unintended recursive filtering of 'the_content'.
    if (dpa_is_template_included()) {
        return $template;
    }
    // Bail if shortcodes are unset somehow
    if (!is_a(achievements()->shortcodes, 'DPA_Shortcodes')) {
        return $template;
    }
    // Achievements archive
    if (dpa_is_achievement_archive()) {
        // Page exists where this archive should be
        $page = dpa_get_page_by_path(dpa_get_root_slug());
        // Should we replace the content...
        if (empty($page->post_content)) {
            $new_content = achievements()->shortcodes->display_achievements_index();
            // ...or use the existing page content?
        } else {
            $new_content = apply_filters('the_content', $page->post_content);
        }
        // Should we replace the title...
        if (empty($page->post_title)) {
            $new_title = dpa_get_achievement_archive_title();
            // ...or use the existing page title?
        } else {
            $new_title = apply_filters('the_title', $page->post_title);
        }
        dpa_theme_compat_reset_post(array('comment_status' => 'closed', 'ID' => !empty($page->ID) ? $page->ID : 0, 'is_archive' => true, 'post_author' => 0, 'post_content' => $new_content, 'post_date' => 0, 'post_status' => 'publish', 'post_title' => $new_title, 'post_type' => dpa_get_achievement_post_type()));
        // Single Achievement
    } elseif (dpa_is_single_achievement()) {
        dpa_theme_compat_reset_post(array('comment_status' => 'closed', 'ID' => dpa_get_achievement_id(), 'is_single' => true, 'post_author' => dpa_get_achievement_author_id(), 'post_content' => achievements()->shortcodes->display_achievement(array('id' => dpa_get_achievement_id())), 'post_date' => 0, 'post_status' => 'publish', 'post_title' => dpa_get_achievement_title(), 'post_type' => dpa_get_achievement_post_type()));
        // Single user's achievements template
    } elseif (dpa_is_single_user_achievements()) {
        dpa_theme_compat_reset_post(array('comment_status' => 'closed', 'ID' => 0, 'is_archive' => true, 'post_author' => 0, 'post_content' => achievements()->shortcodes->display_user_achievements(), 'post_date' => 0, 'post_status' => 'publish', 'post_title' => sprintf(_x("%s's achievements", 'possesive noun', 'achievements'), get_the_author_meta('display_name', dpa_get_displayed_user_id())), 'post_type' => dpa_get_achievement_post_type()));
    }
    /**
     * Bail if the template already matches an Achievements template. This includes
     * archive-* and single-* WordPress post_type matches (allowing themes to use the
     * expected format) as well as all other Achievements-specific template files.
     */
    if (dpa_is_template_included()) {
        return $template;
        /**
         * If we are relying on Achievements' built-in theme compatibility to load
         * the proper content, we need to intercept the_content, replace the
         * output, and display ours instead.
         *
         * To do this, we first remove all filters from 'the_content' and hook
         * our own function into it, which runs a series of checks to determine
         * the context, and then uses the built in shortcodes to output the
         * correct results from inside an output buffer.
         *
         * Uses dpa_get_theme_compat_templates() to provide fall-backs that
         * should be coded without superfluous mark-up and logic (prev/next
         * navigation, comments, date/time, etc...)
         * 
         * Hook into the 'dpa_get_achievements_template' to override the array of
         * possible templates, or 'dpa_achievements_template' to override the result.
         */
    } elseif (dpa_is_theme_compat_active()) {
        dpa_remove_all_filters('the_content');
        $template = dpa_get_theme_compat_templates();
    }
    return apply_filters('dpa_template_include_theme_compat', $template);
}