/** * Sets a post thumbnail. * * @since 3.1.0 * * @param int|object $post Post ID or object where thumbnail should be attached. * @param int $thumbnail_id Thumbnail to attach. * @return bool True on success, false on failure. */ function set_post_thumbnail($post, $thumbnail_id) { $post = get_post($post); $thumbnail_id = absint($thumbnail_id); if ($post && $thumbnail_id && get_post($thumbnail_id)) { $thumbnail_html = nxt_get_attachment_image($thumbnail_id, 'thumbnail'); if (!empty($thumbnail_html)) { update_post_meta($post->ID, '_thumbnail_id', $thumbnail_id); return true; } } return false; }
/** * Retrieve Post Thumbnail. * * @since 2.9.0 * * @param int $post_id Optional. Post ID. * @param string $size Optional. Image size. Defaults to 'thumbnail'. * @param string|array $attr Optional. Query string or array of attributes. */ function get_the_post_thumbnail($post_id = null, $size = 'post-thumbnail', $attr = '') { $post_id = null === $post_id ? get_the_ID() : $post_id; $post_thumbnail_id = get_post_thumbnail_id($post_id); $size = apply_filters('post_thumbnail_size', $size); if ($post_thumbnail_id) { do_action('begin_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size); // for "Just In Time" filtering of all of nxt_get_attachment_image()'s filters if (in_the_loop()) { update_post_thumbnail_cache(); } $html = nxt_get_attachment_image($post_thumbnail_id, $size, false, $attr); do_action('end_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size); } else { $html = ''; } return apply_filters('post_thumbnail_html', $html, $post_id, $post_thumbnail_id, $size, $attr); }
?> </a></h2> <p class="date"> <?php the_date(); ?> <span class="post-utility alignright"><?php edit_post_link(__('Edit this entry', 'buddypress')); ?> </span> </p> <div class="entry"> <?php echo nxt_get_attachment_image($post->ID, 'large', false, array('class' => 'size-large aligncenter')); ?> <div class="entry-caption"><?php if (!empty($post->post_excerpt)) { the_excerpt(); } ?> </div> <?php the_content(); ?> </div> <p class="postmetadata"> <?php
function display_rows() { global $post, $id; add_filter('the_title', 'esc_html'); $alt = ''; while (have_posts()) { the_post(); $user_can_edit = current_user_can('edit_post', $post->ID); if ($this->is_trash && $post->post_status != 'trash' || !$this->is_trash && $post->post_status == 'trash') { continue; } $alt = 'alternate' == $alt ? '' : 'alternate'; $post_owner = get_current_user_id() == $post->post_author ? 'self' : 'other'; $att_title = _draft_or_post_title(); ?> <tr id='post-<?php echo $id; ?> ' class='<?php echo trim($alt . ' author-' . $post_owner . ' status-' . $post->post_status); ?> ' valign="top"> <?php list($columns, $hidden) = $this->get_column_info(); foreach ($columns as $column_name => $column_display_name) { $class = "class='{$column_name} column-{$column_name}'"; $style = ''; if (in_array($column_name, $hidden)) { $style = ' style="display:none;"'; } $attributes = $class . $style; switch ($column_name) { case 'cb': ?> <th scope="row" class="check-column"> <?php if ($user_can_edit) { ?> <input type="checkbox" name="media[]" value="<?php the_ID(); ?> " /> <?php } ?> </th> <?php break; case 'icon': $attributes = 'class="column-icon media-icon"' . $style; ?> <td <?php echo $attributes; ?> ><?php if ($thumb = nxt_get_attachment_image($post->ID, array(80, 60), true)) { if ($this->is_trash || !$user_can_edit) { echo $thumb; } else { ?> <a href="<?php echo get_edit_post_link($post->ID, true); ?> " title="<?php echo esc_attr(sprintf(__('Edit “%s”'), $att_title)); ?> "> <?php echo $thumb; ?> </a> <?php } } ?> </td> <?php break; case 'title': ?> <td <?php echo $attributes; ?> ><strong> <?php if ($this->is_trash || !$user_can_edit) { echo $att_title; } else { ?> <a href="<?php echo get_edit_post_link($post->ID, true); ?> " title="<?php echo esc_attr(sprintf(__('Edit “%s”'), $att_title)); ?> "> <?php echo $att_title; ?> </a> <?php } _media_states($post); ?> </strong> <p> <?php if (preg_match('/^.*?\\.(\\w+)$/', get_attached_file($post->ID), $matches)) { echo esc_html(strtoupper($matches[1])); } else { echo strtoupper(str_replace('image/', '', get_post_mime_type())); } ?> </p> <?php echo $this->row_actions($this->_get_row_actions($post, $att_title)); ?> </td> <?php break; case 'author': ?> <td <?php echo $attributes; ?> ><?php the_author(); ?> </td> <?php break; case 'tags': ?> <td <?php echo $attributes; ?> ><?php $tags = get_the_tags(); if (!empty($tags)) { $out = array(); foreach ($tags as $c) { $out[] = "<a href='edit.php?tag={$c->slug}'> " . esc_html(sanitize_term_field('name', $c->name, $c->term_id, 'post_tag', 'display')) . "</a>"; } echo join(', ', $out); } else { _e('No Tags'); } ?> </td> <?php break; case 'desc': ?> <td <?php echo $attributes; ?> ><?php echo has_excerpt() ? $post->post_excerpt : ''; ?> </td> <?php break; case 'date': if ('0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name) { $t_time = $h_time = __('Unpublished'); } else { $t_time = get_the_time(__('Y/m/d g:i:s A')); $m_time = $post->post_date; $time = get_post_time('G', true, $post, false); if (abs($t_diff = time() - $time) < 86400) { if ($t_diff < 0) { $h_time = sprintf(__('%s from now'), human_time_diff($time)); } else { $h_time = sprintf(__('%s ago'), human_time_diff($time)); } } else { $h_time = mysql2date(__('Y/m/d'), $m_time); } } ?> <td <?php echo $attributes; ?> ><?php echo $h_time; ?> </td> <?php break; case 'parent': if ($post->post_parent > 0) { if (get_post($post->post_parent)) { $title = _draft_or_post_title($post->post_parent); } ?> <td <?php echo $attributes; ?> ><strong> <?php if (current_user_can('edit_post', $post->post_parent)) { ?> <a href="<?php echo get_edit_post_link($post->post_parent); ?> "> <?php echo $title; ?> </a> <?php } else { echo $title; } ?> </strong>, <?php echo get_the_time(__('Y/m/d')); ?> </td> <?php } else { ?> <td <?php echo $attributes; ?> ><?php _e('(Unattached)'); ?> <br /> <?php if ($user_can_edit) { ?> <a class="hide-if-no-js" onclick="findPosts.open( 'media[]','<?php echo $post->ID; ?> ' ); return false;" href="#the-list"> <?php _e('Attach'); ?> </a> <?php } ?> </td> <?php } break; case 'comments': $attributes = 'class="comments column-comments num"' . $style; ?> <td <?php echo $attributes; ?> > <div class="post-com-count-wrapper"> <?php $pending_comments = get_pending_comments_num($post->ID); $this->comments_bubble($post->ID, $pending_comments); ?> </div> </td> <?php break; default: ?> <td <?php echo $attributes; ?> > <?php do_action('manage_media_custom_column', $column_name, $id); ?> </td> <?php break; } } ?> </tr> <?php } }
/** * Retrieve an attachment page link using an image or icon, if possible. * * @since 2.5.0 * @uses apply_filters() Calls 'nxt_get_attachment_link' filter on HTML content with same parameters as function. * * @param int $id Optional. Post ID. * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. * @param bool $permalink Optional, default is false. Whether to add permalink to image. * @param bool $icon Optional, default is false. Whether to include icon. * @param string $text Optional, default is false. If string, then will be link text. * @return string HTML content. */ function nxt_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false) { $id = intval($id); $_post =& get_post($id); if (empty($_post) || 'attachment' != $_post->post_type || !($url = nxt_get_attachment_url($_post->ID))) { return __('Missing Attachment'); } if ($permalink) { $url = get_attachment_link($_post->ID); } $post_title = esc_attr($_post->post_title); if ($text) { $link_text = esc_attr($text); } elseif ($size && 'none' != $size) { $link_text = nxt_get_attachment_image($id, $size, $icon); } else { $link_text = ''; } if (trim($link_text) == '') { $link_text = $_post->post_title; } return apply_filters('nxt_get_attachment_link', "<a href='{$url}' title='{$post_title}'>{$link_text}</a>", $id, $size, $permalink, $icon, $text); }
function column_response($comment) { global $post; if (isset($this->pending_count[$post->ID])) { $pending_comments = $this->pending_count[$post->ID]; } else { $_pending_count_temp = get_pending_comments_num(array($post->ID)); $pending_comments = $this->pending_count[$post->ID] = $_pending_count_temp[$post->ID]; } if (current_user_can('edit_post', $post->ID)) { $post_link = "<a href='" . get_edit_post_link($post->ID) . "'>"; $post_link .= get_the_title($post->ID) . '</a>'; } else { $post_link = get_the_title($post->ID); } echo '<div class="response-links"><span class="post-com-count-wrapper">'; echo $post_link . '<br />'; $this->comments_bubble($post->ID, $pending_comments); echo '</span> '; $post_type_object = get_post_type_object($post->post_type); echo "<a href='" . get_permalink($post->ID) . "'>" . $post_type_object->labels->view_item . '</a>'; echo '</div>'; if ('attachment' == $post->post_type && ($thumb = nxt_get_attachment_image($post->ID, array(80, 60), true))) { echo $thumb; } }
/** * {@internal Missing Short Description}} * * @since 2.0.0 * * @param unknown_type $id * @return unknown */ function the_attachment_links($id = false) { $id = (int) $id; $post =& get_post($id); if ($post->post_type != 'attachment') { return false; } $icon = nxt_get_attachment_image($post->ID, 'thumbnail', true); $attachment_data = nxt_get_attachment_metadata($id); $thumb = isset($attachment_data['thumb']); ?> <form id="the-attachment-links"> <table> <col /> <col class="widefat" /> <tr> <th scope="row"><?php _e('URL'); ?> </th> <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><?php echo esc_textarea(nxt_get_attachment_url()); ?> </textarea></td> </tr> <?php if ($icon) { ?> <tr> <th scope="row"><?php $thumb ? _e('Thumbnail linked to file') : _e('Image linked to file'); ?> </th> <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo nxt_get_attachment_url(); ?> "><?php echo $icon; ?> </a></textarea></td> </tr> <tr> <th scope="row"><?php $thumb ? _e('Thumbnail linked to page') : _e('Image linked to page'); ?> </th> <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID); ?> " rel="attachment nxt-att-<?php echo $post->ID; ?> "><?php echo $icon; ?> </a></textarea></td> </tr> <?php } else { ?> <tr> <th scope="row"><?php _e('Link to file'); ?> </th> <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo nxt_get_attachment_url(); ?> " class="attachmentlink"><?php echo basename(nxt_get_attachment_url()); ?> </a></textarea></td> </tr> <tr> <th scope="row"><?php _e('Link to page'); ?> </th> <td><textarea rows="1" cols="40" type="text" class="attachmentlinks" readonly="readonly"><a href="<?php echo get_attachment_link($post->ID); ?> " rel="attachment nxt-att-<?php echo $post->ID; ?> "><?php the_title(); ?> </a></textarea></td> </tr> <?php } ?> </table> </form> <?php }
/** * Output HTML for the post thumbnail meta-box. * * @since 2.9.0 * * @param int $thumbnail_id ID of the attachment used for thumbnail * @return string html */ function _nxt_post_thumbnail_html($thumbnail_id = NULL) { global $content_width, $_nxt_additional_image_sizes, $post_ID; $set_thumbnail_link = '<p class="hide-if-no-js"><a title="' . esc_attr__('Set featured image') . '" href="' . esc_url(get_upload_iframe_src('image')) . '" id="set-post-thumbnail" class="thickbox">%s</a></p>'; $content = sprintf($set_thumbnail_link, esc_html__('Set featured image')); if ($thumbnail_id && get_post($thumbnail_id)) { $old_content_width = $content_width; $content_width = 266; if (!isset($_nxt_additional_image_sizes['post-thumbnail'])) { $thumbnail_html = nxt_get_attachment_image($thumbnail_id, array($content_width, $content_width)); } else { $thumbnail_html = nxt_get_attachment_image($thumbnail_id, 'post-thumbnail'); } if (!empty($thumbnail_html)) { $ajax_nonce = nxt_create_nonce("set_post_thumbnail-{$post_ID}"); $content = sprintf($set_thumbnail_link, $thumbnail_html); $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="nxtRemoveThumbnail(\'' . $ajax_nonce . '\');return false;">' . esc_html__('Remove featured image') . '</a></p>'; } $content_width = $old_content_width; } return apply_filters('admin_post_thumbnail_html', $content); }