public function header_image_filter($url) { // Bail out now if not in post (is_single or is_page) or blog (is_home) if (!is_single() && !is_page() && !is_home()) { return $url; } // Get current post ID (if on blog, then checks current posts page for it's ID) if (is_home()) { $post_id = get_option('page_for_posts'); } else { $post_id = get_the_ID(); } // Get attachment ID $attachment_id = Custom_Image_Meta_Box::get_attachment_id($post_id, $this->name_underscores); // Generate new URL if (is_numeric($attachment_id)) { $url = Custom_Image_Meta_Box::get_attachment_src($attachment_id); } return $url; }
/** * Extra fields * * @author Ryan Hellyer <*****@*****.**> * @since 1.0 */ public function extra_fields() { $tag_ID = absint($_GET['tag_ID']); $attachment_id = get_term_meta($tag_ID, 'taxonomy-header-image', true); // We need to cater for legacy URL's as well as the newer attachment ID's if (is_numeric($attachment_id)) { $url = Custom_Image_Meta_Box::get_attachment_src($attachment_id); $title = Custom_Image_Meta_Box::get_attachment_title($attachment_id); } else { // Falling back to taxonomy meta plugin functionality $attachment_id = get_metadata('taxonomy', $tag_ID, 'taxonomy-header-image', true); if (is_numeric($attachment_id)) { $url = Custom_Image_Meta_Box::get_attachment_src($attachment_id); $title = Custom_Image_Meta_Box::get_attachment_title($attachment_id); } elseif (is_string($attachment_id)) { $url = $attachment_id; // The attachment ID is actually the URL $title = ''; // We don't know the title since it's an attachment } } ?> <tr valign="top"> <th scope="row"><?php echo esc_html($this->upload_header_image); ?> </th> <td> <div id="unique-header" class="postbox " > <div class="inside"> <p class="hide-if-no-js"> <a title="<?php echo esc_attr($this->set_custom_image); ?> " href="javascript:;" id="<?php echo esc_attr('set-' . $this->name . '-thumbnail'); ?> " class="set-custom-meta-image-thumbnail"><?php echo esc_html($this->set_custom_image); ?> </a> </p> <div id="<?php echo esc_attr($this->name . '-container'); ?> " class="custom-meta-image-container hidden"> <img src="<?php echo esc_url($url); ?> " alt="<?php echo esc_attr($title); ?> " title="<?php echo esc_attr($title); ?> " /> </div><!-- #<?php esc_attr($this->name . '-image-container'); ?> --> <p class="hide-if-no-js hidden"> <a title="<?php echo esc_attr($this->remove_custom_image); ?> " href="javascript:;" id="<?php echo esc_attr('remove-' . $this->name . '-thumbnail'); ?> " class="remove-custom-meta-image-thumbnail"><?php echo esc_html($this->remove_custom_image); ?> </a> </p><!-- .hide-if-no-js --> <p id="<?php echo esc_attr($this->name . '-info'); ?> " class="custom-meta-image-info"> <input type="hidden" id="<?php echo esc_attr($this->name . '-id'); ?> " class="custom-meta-image-id" name="<?php echo esc_attr($this->name . '-id'); ?> " value="<?php echo esc_attr($attachment_id); ?> " /> </p><!-- #<?php echo esc_attr($this->name . '-image-info'); ?> --> <?php wp_nonce_field($this->name, $this->name . '-nonce'); ?> </div> </div> </td> </tr> <?php }