/**
  * Sets up and runs the functionality for getting the attachment meta.
  *
  * @since  3.0.0
  * @access public
  * @param  array   $args
  * @return void
  */
 public function __construct($post_id)
 {
     $this->post_id = $post_id;
     $this->meta = wp_get_attachment_metadata($this->post_id);
     $this->type = hybrid_get_attachment_type($this->post_id);
     // If we have a type that's in the whitelist, run filters.
     if ($this->type && in_array($this->type, $this->allowed_types)) {
         // Run common media filters for any media type.
         $this->media_filters();
         // Run type-specific filters.
         call_user_func(array($this, "{$this->type}_filters"));
     }
 }
Exemplo n.º 2
0
/**
 * Loads a post content template based off the post type and/or the post format.  This functionality is
 * not feasible with the WordPress get_template_part() function, so we have to rely on some custom logic
 * and locate_template().
 *
 * Note that using this function assumes that you're creating a content template to handle attachments.
 * The `prepend_attachment()` filter must be removed since we're bypassing the WP template hierarchy
 * and focusing on templates specific to the content.
 *
 * @since  1.6.0
 * @access public
 * @return string
 */
function hybrid_get_content_template()
{
    // Set up an empty array and get the post type.
    $templates = array();
    $post_type = get_post_type();
    // Assume the theme developer is creating an attachment template.
    if ('attachment' === $post_type) {
        remove_filter('the_content', 'prepend_attachment');
        $type = hybrid_get_attachment_type();
        $templates[] = "content-attachment-{$type}.php";
        $templates[] = "content/attachment-{$type}.php";
    }
    // If the post type supports 'post-formats', get the template based on the format.
    if (post_type_supports($post_type, 'post-formats')) {
        // Get the post format.
        $post_format = get_post_format() ? get_post_format() : 'standard';
        // Template based off post type and post format.
        $templates[] = "content-{$post_type}-{$post_format}.php";
        $templates[] = "content/{$post_type}-{$post_format}.php";
        // Template based off the post format.
        $templates[] = "content-{$post_format}.php";
        $templates[] = "content/{$post_format}.php";
    }
    // Template based off the post type.
    $templates[] = "content-{$post_type}.php";
    $templates[] = "content/{$post_type}.php";
    // Fallback 'content.php' template.
    $templates[] = 'content.php';
    $templates[] = 'content/content.php';
    // Apply filters to the templates array.
    $templates = apply_filters('hybrid_content_template_hierarchy', $templates);
    // Locate the template.
    $template = apply_filters('hybrid_content_template', locate_template($templates), $templates);
    // If template is found, include it.
    if ($template) {
        include $template;
    }
}
Exemplo n.º 3
0
/**
 * Loads the correct function for handling attachments.  Checks the attachment mime type to call
 * correct function. Image attachments are not loaded with this function.  The functionality for them
 * should be handled by the theme's attachment or image attachment file.
 *
 * Ideally, all attachments would be appropriately handled within their templates. However, this could
 * lead to messy template files.
 *
 * @since  0.5.0
 * @access public
 * @return void
 */
function hybrid_attachment()
{
    $type = hybrid_get_attachment_type();
    $attachment = function_exists("hybrid_{$type}_attachment") ? call_user_func("hybrid_{$type}_attachment", get_post_mime_type(), wp_get_attachment_url()) : '';
    echo apply_filters('hybrid_attachment', apply_filters("hybrid_{$type}_attachment", $attachment));
}
Exemplo n.º 4
0
/**
 * Overrides the default single (singular post) template.  Post templates can be loaded using a custom
 * post template, by slug, or by ID.
 *
 * Attachment templates are handled slightly differently. Rather than look for the slug or ID, templates
 * can be loaded by attachment-$mime[0]_$mime[1].php, attachment-$mime[1].php, or attachment-$mime[0].php.
 *
 * @since  0.7.0
 * @access public
 * @param  string $template The default WordPress post template.
 * @return string $template The theme post template after all templates have been checked for.
 */
function hybrid_singular_template($template)
{
    $templates = array();
    // Get the queried post.
    $post = get_queried_object();
    // Check for a custom post template by custom field key '_wp_post_template'.
    $custom = hybrid_get_post_template(get_queried_object_id());
    if ($custom) {
        $templates[] = $custom;
    }
    // If viewing an attachment page, handle the files by mime type.
    if (is_attachment()) {
        // Split the mime_type into two distinct parts.
        $type = hybrid_get_attachment_type();
        $subtype = hybrid_get_attachment_subtype();
        if ($subtype) {
            $templates[] = "attachment-{$type}-{$subtype}.php";
            $templates[] = "attachment-{$subtype}.php";
        }
        $templates[] = "attachment-{$type}.php";
    } else {
        // Add a post name (slug) template.
        $templates[] = "{$post->post_type}-{$post->post_name}.php";
        // Add a post ID template.
        $templates[] = "{$post->post_type}-{$post->ID}.php";
    }
    // Add a template based off the post type name.
    $templates[] = "{$post->post_type}.php";
    // Allow for WP standard 'single' templates for compatibility.
    $templates[] = "single-{$post->post_type}.php";
    $templates[] = 'single.php';
    // Add a general template of singular.php.
    $templates[] = "singular.php";
    // Return the found template.
    return locate_template($templates);
}