get_attachment_link

Definition:
function get_attachment_link($id = false) {}

Retrieve permalink for attachment.
This can be used in the WordPress Loop or outside of it.

Parameters

  • int $id: Optional. Post ID.

Defined filters

  • attachment_link
    apply_filters('attachment_link', $link, $id)

Source code

function get_attachment_link($id = false) {

	global $post, $wp_rewrite;



	$link = false;



	if ( ! $id)

		$id = (int) $post->ID;



	$object = get_post($id);

	if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) {

		$parent = get_post($object->post_parent);

		if ( 'page' == $parent->post_type )

			$parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front

		else

			$parentlink = get_permalink( $object->post_parent );



		if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') )

			$name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker

		else

			$name = $object->post_name;



		if ( strpos($parentlink, '?') === false )

			$link = user_trailingslashit( trailingslashit($parentlink) . $name );

	}



	if ( ! $link )

		$link = home_url( "/?attachment_id=$id" );



	return apply_filters('attachment_link', $link, $id);

}

1160

get_attachment_innerHTML

Definition:
function get_attachment_innerHTML($id = 0, $fullsize = false, $max_dims = false) {}

Retrieve HTML content of image element.

Parameters

  • int $id: Optional. Post ID.
  • bool $fullsize: Optional, default to false. Whether to have full size image.
  • array $max_dims: Optional. Dimensions of image.

Defined filters

  • attachment_innerHTML
    apply_filters('attachment_innerHTML', $innerHTML, $post->ID)

Source code

function get_attachment_innerHTML($id = 0, $fullsize = false, $max_dims = false) {

	_deprecated_function( __FUNCTION__, '2.5', 'wp_get_attachment_image()' );

	$id = (int) $id;

	if ( !$post = & get_post($id) )

		return false;



	if ( $innerHTML = get_attachment_icon($post->ID, $fullsize, $max_dims))

		return $innerHTML;





	$innerHTML = esc_attr($post->post_title);



	return apply_filters('attachment_innerHTML', $innerHTML, $post->ID);

}

1158

get_attachment_icon_src

Definition:
function get_attachment_icon_src( $id = 0, $fullsize = false ) {}

Retrieve icon URL and Path.

Parameters

  • int $id: Optional. Post ID.
  • bool $fullsize: Optional, default to false. Whether to have full image.

Return values

returns:Icon URL and full path to file, respectively.

Defined filters

  • icon_dir
    apply_filters( 'icon_dir', get_template_directory()

Source code

function get_attachment_icon_src( $id = 0, $fullsize = false ) {

	_deprecated_function( __FUNCTION__, '2.5', 'wp_get_attachment_image_src()' );

	$id = (int) $id;

	if ( !$post = & get_post($id) )

		return false;



	$file = get_attached_file( $post->ID );



	if ( !$fullsize && $src = wp_get_attachment_thumb_url( $post->ID ) ) {

		// We have a thumbnail desired, specified and existing



		$src_file = basename($src);

		$class = 'attachmentthumb';

	} elseif ( wp_attachment_is_image( $post->ID ) ) {

		// We have an image without a thumbnail



		$src = wp_get_attachment_url( $post->ID );

		$src_file = & $file;

		$class = 'attachmentimage';

	} elseif ( $src = wp_mime_type_icon( $post->ID ) ) {

		// No thumb, no image. We'll look for a mime-related icon instead.



		$icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' );

		$src_file = $icon_dir . '/' . basename($src);

	}



	if ( !isset($src) || !$src )

		return false;



	return array($src, $src_file);

}

1156

get_attachment_icon

Definition:
function get_attachment_icon( $id = 0, $fullsize = false, $max_dims = false ) {}

Retrieve HTML content of icon attachment image element.

Parameters

  • int $id: Optional. Post ID.
  • bool $fullsize: Optional, default to false. Whether to have full size image.
  • array $max_dims: Optional. Dimensions of image.

Return values

returns:HTML content.

Defined filters

  • attachment_max_dims
    apply_filters('attachment_max_dims', $max_dims)

Source code

function get_attachment_icon( $id = 0, $fullsize = false, $max_dims = false ) {

	_deprecated_function( __FUNCTION__, '2.5', 'wp_get_attachment_image()' );

	$id = (int) $id;

	if ( !$post = & get_post($id) )

		return false;



	if ( !$src = get_attachment_icon_src( $post->ID, $fullsize ) )

		return false;



	list($src, $src_file) = $src;



	// Do we need to constrain the image?

	if ( ($max_dims = apply_filters('attachment_max_dims', $max_dims)) && file_exists($src_file) ) {



		$imagesize = getimagesize($src_file);



		if (($imagesize[0] > $max_dims[0]) || $imagesize[1] > $max_dims[1] ) {

			$actual_aspect = $imagesize[0] / $imagesize[1];

			$desired_aspect = $max_dims[0] / $max_dims[1];



			if ( $actual_aspect >= $desired_aspect ) {

				$height = $actual_aspect * $max_dims[0];

				$constraint = "width='{$max_dims[0]}' ";

				$post->iconsize = array($max_dims[0], $height);

			} else {

				$width = $max_dims[1] / $actual_aspect;

				$constraint = "height='{$max_dims[1]}' ";

				$post->iconsize = array($width, $max_dims[1]);

			}

		} else {

1154

get_attachment_fields_to_edit

Definition:
function get_attachment_fields_to_edit($post, $errors = null) {}

Parameters

  • unknown_type $post
  • unknown_type $errors

Defined filters

  • attachment_fields_to_edit
    apply_filters('attachment_fields_to_edit', $form_fields, $post)

Source code

function get_attachment_fields_to_edit($post, $errors = null) {

	if ( is_int($post) )

		$post =& get_post($post);

	if ( is_array($post) )

		$post = (object) $post;



	$image_url = wp_get_attachment_url($post->ID);



	$edit_post = sanitize_post($post, 'edit');







	$form_fields = array(

		'post_title'   => array(

			'label'      => __('Title'),

			'value'      => $edit_post->post_title

		),

		'image_alt'   => array(),

		'post_excerpt' => array(

			'label'      => __('Caption'),

			'value'      => $edit_post->post_excerpt

		),

		'post_content' => array(

			'label'      => __('Description'),

			'value'      => $edit_post->post_content,

			'input'      => 'textarea'

		),

		'url'          => array(

			'label'      => __('Link URL'),

			'input'      => 'html',

			'html'       => image_link_input_fields($post, get_option('image_default_link_type')),

			'helps'      => __('Enter a link URL or click above for presets.')

		),

		'menu_order'   => array(

			'label'      => __('Order'),

			'value'      => $edit_post->menu_order

		),

		'image_url'	=> array(

			'label'      => __('File URL'),

			'input'      => 'html',

			'html'       => "<input type='text' class='text urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr($image_url) . "' /><br />",

			'value'      => wp_get_attachment_url($post->ID),

			'helps'      => __('Location of the uploaded file.')

		)

	);



	foreach ( get_attachment_taxonomies($post) as $taxonomy ) {

		$t = (array) get_taxonomy($taxonomy);

		if ( ! $t['public'] )

			continue;

		if ( empty($t['label']) )

			$t['label'] = $taxonomy;

		if ( empty($t['args']) )

			$t['args'] = array();



		$terms = get_object_term_cache($post->ID, $taxonomy);

		if ( empty($terms) )

			$terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);



		$values = array();



		foreach ( $terms as $term )

			$values[] = $term->name;

		$t['value'] = join(', ', $values);



		$form_fields[$taxonomy] = $t;

	}



	// Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default

	// The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )

	$form_fields = array_merge_recursive($form_fields, (array) $errors);



	$form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);



	return $form_fields;

}

1152