Edit File by line
/home/barbar84/www/wp-admin/includes
File: media.php
return $form_fields;
[1500] Fix | Delete
}
[1501] Fix | Delete
[1502] Fix | Delete
/**
[1503] Fix | Delete
* Retrieve HTML for media items of post gallery.
[1504] Fix | Delete
*
[1505] Fix | Delete
* The HTML markup retrieved will be created for the progress of SWF Upload
[1506] Fix | Delete
* component. Will also create link for showing and hiding the form to modify
[1507] Fix | Delete
* the image attachment.
[1508] Fix | Delete
*
[1509] Fix | Delete
* @since 2.5.0
[1510] Fix | Delete
*
[1511] Fix | Delete
* @global WP_Query $wp_the_query WordPress Query object.
[1512] Fix | Delete
*
[1513] Fix | Delete
* @param int $post_id Optional. Post ID.
[1514] Fix | Delete
* @param array $errors Errors for attachment, if any.
[1515] Fix | Delete
* @return string
[1516] Fix | Delete
*/
[1517] Fix | Delete
function get_media_items( $post_id, $errors ) {
[1518] Fix | Delete
$attachments = array();
[1519] Fix | Delete
[1520] Fix | Delete
if ( $post_id ) {
[1521] Fix | Delete
$post = get_post( $post_id );
[1522] Fix | Delete
[1523] Fix | Delete
if ( $post && 'attachment' === $post->post_type ) {
[1524] Fix | Delete
$attachments = array( $post->ID => $post );
[1525] Fix | Delete
} else {
[1526] Fix | Delete
$attachments = get_children(
[1527] Fix | Delete
array(
[1528] Fix | Delete
'post_parent' => $post_id,
[1529] Fix | Delete
'post_type' => 'attachment',
[1530] Fix | Delete
'orderby' => 'menu_order ASC, ID',
[1531] Fix | Delete
'order' => 'DESC',
[1532] Fix | Delete
)
[1533] Fix | Delete
);
[1534] Fix | Delete
}
[1535] Fix | Delete
} else {
[1536] Fix | Delete
if ( is_array( $GLOBALS['wp_the_query']->posts ) ) {
[1537] Fix | Delete
foreach ( $GLOBALS['wp_the_query']->posts as $attachment ) {
[1538] Fix | Delete
$attachments[ $attachment->ID ] = $attachment;
[1539] Fix | Delete
}
[1540] Fix | Delete
}
[1541] Fix | Delete
}
[1542] Fix | Delete
[1543] Fix | Delete
$output = '';
[1544] Fix | Delete
foreach ( (array) $attachments as $id => $attachment ) {
[1545] Fix | Delete
if ( 'trash' === $attachment->post_status ) {
[1546] Fix | Delete
continue;
[1547] Fix | Delete
}
[1548] Fix | Delete
[1549] Fix | Delete
$item = get_media_item( $id, array( 'errors' => isset( $errors[ $id ] ) ? $errors[ $id ] : null ) );
[1550] Fix | Delete
[1551] Fix | Delete
if ( $item ) {
[1552] Fix | Delete
$output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-$id' class='hidden'></div><div class='filename hidden'></div>$item\n</div>";
[1553] Fix | Delete
}
[1554] Fix | Delete
}
[1555] Fix | Delete
[1556] Fix | Delete
return $output;
[1557] Fix | Delete
}
[1558] Fix | Delete
[1559] Fix | Delete
/**
[1560] Fix | Delete
* Retrieve HTML form for modifying the image attachment.
[1561] Fix | Delete
*
[1562] Fix | Delete
* @since 2.5.0
[1563] Fix | Delete
*
[1564] Fix | Delete
* @global string $redir_tab
[1565] Fix | Delete
*
[1566] Fix | Delete
* @param int $attachment_id Attachment ID for modification.
[1567] Fix | Delete
* @param string|array $args Optional. Override defaults.
[1568] Fix | Delete
* @return string HTML form for attachment.
[1569] Fix | Delete
*/
[1570] Fix | Delete
function get_media_item( $attachment_id, $args = null ) {
[1571] Fix | Delete
global $redir_tab;
[1572] Fix | Delete
[1573] Fix | Delete
$thumb_url = false;
[1574] Fix | Delete
$attachment_id = (int) $attachment_id;
[1575] Fix | Delete
[1576] Fix | Delete
if ( $attachment_id ) {
[1577] Fix | Delete
$thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true );
[1578] Fix | Delete
[1579] Fix | Delete
if ( $thumb_url ) {
[1580] Fix | Delete
$thumb_url = $thumb_url[0];
[1581] Fix | Delete
}
[1582] Fix | Delete
}
[1583] Fix | Delete
[1584] Fix | Delete
$post = get_post( $attachment_id );
[1585] Fix | Delete
$current_post_id = ! empty( $_GET['post_id'] ) ? (int) $_GET['post_id'] : 0;
[1586] Fix | Delete
[1587] Fix | Delete
$default_args = array(
[1588] Fix | Delete
'errors' => null,
[1589] Fix | Delete
'send' => $current_post_id ? post_type_supports( get_post_type( $current_post_id ), 'editor' ) : true,
[1590] Fix | Delete
'delete' => true,
[1591] Fix | Delete
'toggle' => true,
[1592] Fix | Delete
'show_title' => true,
[1593] Fix | Delete
);
[1594] Fix | Delete
[1595] Fix | Delete
$parsed_args = wp_parse_args( $args, $default_args );
[1596] Fix | Delete
[1597] Fix | Delete
/**
[1598] Fix | Delete
* Filters the arguments used to retrieve an image for the edit image form.
[1599] Fix | Delete
*
[1600] Fix | Delete
* @since 3.1.0
[1601] Fix | Delete
*
[1602] Fix | Delete
* @see get_media_item
[1603] Fix | Delete
*
[1604] Fix | Delete
* @param array $parsed_args An array of arguments.
[1605] Fix | Delete
*/
[1606] Fix | Delete
$parsed_args = apply_filters( 'get_media_item_args', $parsed_args );
[1607] Fix | Delete
[1608] Fix | Delete
$toggle_on = __( 'Show' );
[1609] Fix | Delete
$toggle_off = __( 'Hide' );
[1610] Fix | Delete
[1611] Fix | Delete
$file = get_attached_file( $post->ID );
[1612] Fix | Delete
$filename = esc_html( wp_basename( $file ) );
[1613] Fix | Delete
$title = esc_attr( $post->post_title );
[1614] Fix | Delete
[1615] Fix | Delete
$post_mime_types = get_post_mime_types();
[1616] Fix | Delete
$keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) );
[1617] Fix | Delete
$type = reset( $keys );
[1618] Fix | Delete
$type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
[1619] Fix | Delete
[1620] Fix | Delete
$form_fields = get_attachment_fields_to_edit( $post, $parsed_args['errors'] );
[1621] Fix | Delete
[1622] Fix | Delete
if ( $parsed_args['toggle'] ) {
[1623] Fix | Delete
$class = empty( $parsed_args['errors'] ) ? 'startclosed' : 'startopen';
[1624] Fix | Delete
$toggle_links = "
[1625] Fix | Delete
<a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
[1626] Fix | Delete
<a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
[1627] Fix | Delete
} else {
[1628] Fix | Delete
$class = '';
[1629] Fix | Delete
$toggle_links = '';
[1630] Fix | Delete
}
[1631] Fix | Delete
[1632] Fix | Delete
$display_title = ( ! empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case.
[1633] Fix | Delete
$display_title = $parsed_args['show_title'] ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '&hellip;' ) . '</span></div>' : '';
[1634] Fix | Delete
[1635] Fix | Delete
$gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' === $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' === $redir_tab ) );
[1636] Fix | Delete
$order = '';
[1637] Fix | Delete
[1638] Fix | Delete
foreach ( $form_fields as $key => $val ) {
[1639] Fix | Delete
if ( 'menu_order' === $key ) {
[1640] Fix | Delete
if ( $gallery ) {
[1641] Fix | Delete
$order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' /></div>";
[1642] Fix | Delete
} else {
[1643] Fix | Delete
$order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />";
[1644] Fix | Delete
}
[1645] Fix | Delete
[1646] Fix | Delete
unset( $form_fields['menu_order'] );
[1647] Fix | Delete
break;
[1648] Fix | Delete
}
[1649] Fix | Delete
}
[1650] Fix | Delete
[1651] Fix | Delete
$media_dims = '';
[1652] Fix | Delete
$meta = wp_get_attachment_metadata( $post->ID );
[1653] Fix | Delete
[1654] Fix | Delete
if ( isset( $meta['width'], $meta['height'] ) ) {
[1655] Fix | Delete
$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
[1656] Fix | Delete
}
[1657] Fix | Delete
[1658] Fix | Delete
/**
[1659] Fix | Delete
* Filters the media metadata.
[1660] Fix | Delete
*
[1661] Fix | Delete
* @since 2.5.0
[1662] Fix | Delete
*
[1663] Fix | Delete
* @param string $media_dims The HTML markup containing the media dimensions.
[1664] Fix | Delete
* @param WP_Post $post The WP_Post attachment object.
[1665] Fix | Delete
*/
[1666] Fix | Delete
$media_dims = apply_filters( 'media_meta', $media_dims, $post );
[1667] Fix | Delete
[1668] Fix | Delete
$image_edit_button = '';
[1669] Fix | Delete
[1670] Fix | Delete
if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
[1671] Fix | Delete
$nonce = wp_create_nonce( "image_editor-$post->ID" );
[1672] Fix | Delete
$image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>";
[1673] Fix | Delete
}
[1674] Fix | Delete
[1675] Fix | Delete
$attachment_url = get_permalink( $attachment_id );
[1676] Fix | Delete
[1677] Fix | Delete
$item = "
[1678] Fix | Delete
$type_html
[1679] Fix | Delete
$toggle_links
[1680] Fix | Delete
$order
[1681] Fix | Delete
$display_title
[1682] Fix | Delete
<table class='slidetoggle describe $class'>
[1683] Fix | Delete
<thead class='media-item-info' id='media-head-$post->ID'>
[1684] Fix | Delete
<tr>
[1685] Fix | Delete
<td class='A1B1' id='thumbnail-head-$post->ID'>
[1686] Fix | Delete
<p><a href='$attachment_url' target='_blank'><img class='thumbnail' src='$thumb_url' alt='' /></a></p>
[1687] Fix | Delete
<p>$image_edit_button</p>
[1688] Fix | Delete
</td>
[1689] Fix | Delete
<td>
[1690] Fix | Delete
<p><strong>" . __( 'File name:' ) . "</strong> $filename</p>
[1691] Fix | Delete
<p><strong>" . __( 'File type:' ) . "</strong> $post->post_mime_type</p>
[1692] Fix | Delete
<p><strong>" . __( 'Upload date:' ) . '</strong> ' . mysql2date( __( 'F j, Y' ), $post->post_date ) . '</p>';
[1693] Fix | Delete
[1694] Fix | Delete
if ( ! empty( $media_dims ) ) {
[1695] Fix | Delete
$item .= '<p><strong>' . __( 'Dimensions:' ) . "</strong> $media_dims</p>\n";
[1696] Fix | Delete
}
[1697] Fix | Delete
[1698] Fix | Delete
$item .= "</td></tr>\n";
[1699] Fix | Delete
[1700] Fix | Delete
$item .= "
[1701] Fix | Delete
</thead>
[1702] Fix | Delete
<tbody>
[1703] Fix | Delete
<tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr>\n
[1704] Fix | Delete
<tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n
[1705] Fix | Delete
<tr><td colspan='2'><p class='media-types media-types-required-info'>" .
[1706] Fix | Delete
/* translators: %s: Asterisk symbol (*). */
[1707] Fix | Delete
sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) .
[1708] Fix | Delete
"</p></td></tr>\n";
[1709] Fix | Delete
[1710] Fix | Delete
$defaults = array(
[1711] Fix | Delete
'input' => 'text',
[1712] Fix | Delete
'required' => false,
[1713] Fix | Delete
'value' => '',
[1714] Fix | Delete
'extra_rows' => array(),
[1715] Fix | Delete
);
[1716] Fix | Delete
[1717] Fix | Delete
if ( $parsed_args['send'] ) {
[1718] Fix | Delete
$parsed_args['send'] = get_submit_button( __( 'Insert into Post' ), '', "send[$attachment_id]", false );
[1719] Fix | Delete
}
[1720] Fix | Delete
[1721] Fix | Delete
$delete = empty( $parsed_args['delete'] ) ? '' : $parsed_args['delete'];
[1722] Fix | Delete
if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) {
[1723] Fix | Delete
if ( ! EMPTY_TRASH_DAYS ) {
[1724] Fix | Delete
$delete = "<a href='" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete-permanently'>" . __( 'Delete Permanently' ) . '</a>';
[1725] Fix | Delete
} elseif ( ! MEDIA_TRASH ) {
[1726] Fix | Delete
$delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a>
[1727] Fix | Delete
<div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'>" .
[1728] Fix | Delete
/* translators: %s: File name. */
[1729] Fix | Delete
'<p>' . sprintf( __( 'You are about to delete %s.' ), '<strong>' . $filename . '</strong>' ) . "</p>
[1730] Fix | Delete
<a href='" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a>
[1731] Fix | Delete
<a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . '</a>
[1732] Fix | Delete
</div>';
[1733] Fix | Delete
} else {
[1734] Fix | Delete
$delete = "<a href='" . wp_nonce_url( "post.php?action=trash&amp;post=$attachment_id", 'trash-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Move to Trash' ) . "</a>
[1735] Fix | Delete
<a href='" . wp_nonce_url( "post.php?action=untrash&amp;post=$attachment_id", 'untrash-post_' . $attachment_id ) . "' id='undo[$attachment_id]' class='undo hidden'>" . __( 'Undo' ) . '</a>';
[1736] Fix | Delete
}
[1737] Fix | Delete
} else {
[1738] Fix | Delete
$delete = '';
[1739] Fix | Delete
}
[1740] Fix | Delete
[1741] Fix | Delete
$thumbnail = '';
[1742] Fix | Delete
$calling_post_id = 0;
[1743] Fix | Delete
[1744] Fix | Delete
if ( isset( $_GET['post_id'] ) ) {
[1745] Fix | Delete
$calling_post_id = absint( $_GET['post_id'] );
[1746] Fix | Delete
} elseif ( isset( $_POST ) && count( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set.
[1747] Fix | Delete
$calling_post_id = $post->post_parent;
[1748] Fix | Delete
}
[1749] Fix | Delete
[1750] Fix | Delete
if ( 'image' === $type && $calling_post_id
[1751] Fix | Delete
&& current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) )
[1752] Fix | Delete
&& post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' )
[1753] Fix | Delete
&& get_post_thumbnail_id( $calling_post_id ) != $attachment_id
[1754] Fix | Delete
) {
[1755] Fix | Delete
[1756] Fix | Delete
$calling_post = get_post( $calling_post_id );
[1757] Fix | Delete
$calling_post_type_object = get_post_type_object( $calling_post->post_type );
[1758] Fix | Delete
[1759] Fix | Delete
$ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" );
[1760] Fix | Delete
$thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html( $calling_post_type_object->labels->use_featured_image ) . '</a>';
[1761] Fix | Delete
}
[1762] Fix | Delete
[1763] Fix | Delete
if ( ( $parsed_args['send'] || $thumbnail || $delete ) && ! isset( $form_fields['buttons'] ) ) {
[1764] Fix | Delete
$form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>" . $parsed_args['send'] . " $thumbnail $delete</td></tr>\n" );
[1765] Fix | Delete
}
[1766] Fix | Delete
[1767] Fix | Delete
$hidden_fields = array();
[1768] Fix | Delete
[1769] Fix | Delete
foreach ( $form_fields as $id => $field ) {
[1770] Fix | Delete
if ( '_' === $id[0] ) {
[1771] Fix | Delete
continue;
[1772] Fix | Delete
}
[1773] Fix | Delete
[1774] Fix | Delete
if ( ! empty( $field['tr'] ) ) {
[1775] Fix | Delete
$item .= $field['tr'];
[1776] Fix | Delete
continue;
[1777] Fix | Delete
}
[1778] Fix | Delete
[1779] Fix | Delete
$field = array_merge( $defaults, $field );
[1780] Fix | Delete
$name = "attachments[$attachment_id][$id]";
[1781] Fix | Delete
[1782] Fix | Delete
if ( 'hidden' === $field['input'] ) {
[1783] Fix | Delete
$hidden_fields[ $name ] = $field['value'];
[1784] Fix | Delete
continue;
[1785] Fix | Delete
}
[1786] Fix | Delete
[1787] Fix | Delete
$required = $field['required'] ? '<span class="required">*</span>' : '';
[1788] Fix | Delete
$required_attr = $field['required'] ? ' required' : '';
[1789] Fix | Delete
$class = $id;
[1790] Fix | Delete
$class .= $field['required'] ? ' form-required' : '';
[1791] Fix | Delete
[1792] Fix | Delete
$item .= "\t\t<tr class='$class'>\n\t\t\t<th scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}{$required}</span><br class='clear' /></label></th>\n\t\t\t<td class='field'>";
[1793] Fix | Delete
[1794] Fix | Delete
if ( ! empty( $field[ $field['input'] ] ) ) {
[1795] Fix | Delete
$item .= $field[ $field['input'] ];
[1796] Fix | Delete
} elseif ( 'textarea' === $field['input'] ) {
[1797] Fix | Delete
if ( 'post_content' === $id && user_can_richedit() ) {
[1798] Fix | Delete
// Sanitize_post() skips the post_content when user_can_richedit.
[1799] Fix | Delete
$field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
[1800] Fix | Delete
}
[1801] Fix | Delete
// Post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit().
[1802] Fix | Delete
$item .= "<textarea id='$name' name='$name'{$required_attr}>" . $field['value'] . '</textarea>';
[1803] Fix | Delete
} else {
[1804] Fix | Delete
$item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "'{$required_attr} />";
[1805] Fix | Delete
}
[1806] Fix | Delete
[1807] Fix | Delete
if ( ! empty( $field['helps'] ) ) {
[1808] Fix | Delete
$item .= "<p class='help'>" . implode( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
[1809] Fix | Delete
}
[1810] Fix | Delete
$item .= "</td>\n\t\t</tr>\n";
[1811] Fix | Delete
[1812] Fix | Delete
$extra_rows = array();
[1813] Fix | Delete
[1814] Fix | Delete
if ( ! empty( $field['errors'] ) ) {
[1815] Fix | Delete
foreach ( array_unique( (array) $field['errors'] ) as $error ) {
[1816] Fix | Delete
$extra_rows['error'][] = $error;
[1817] Fix | Delete
}
[1818] Fix | Delete
}
[1819] Fix | Delete
[1820] Fix | Delete
if ( ! empty( $field['extra_rows'] ) ) {
[1821] Fix | Delete
foreach ( $field['extra_rows'] as $class => $rows ) {
[1822] Fix | Delete
foreach ( (array) $rows as $html ) {
[1823] Fix | Delete
$extra_rows[ $class ][] = $html;
[1824] Fix | Delete
}
[1825] Fix | Delete
}
[1826] Fix | Delete
}
[1827] Fix | Delete
[1828] Fix | Delete
foreach ( $extra_rows as $class => $rows ) {
[1829] Fix | Delete
foreach ( $rows as $html ) {
[1830] Fix | Delete
$item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
[1831] Fix | Delete
}
[1832] Fix | Delete
}
[1833] Fix | Delete
}
[1834] Fix | Delete
[1835] Fix | Delete
if ( ! empty( $form_fields['_final'] ) ) {
[1836] Fix | Delete
$item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
[1837] Fix | Delete
}
[1838] Fix | Delete
[1839] Fix | Delete
$item .= "\t</tbody>\n";
[1840] Fix | Delete
$item .= "\t</table>\n";
[1841] Fix | Delete
[1842] Fix | Delete
foreach ( $hidden_fields as $name => $value ) {
[1843] Fix | Delete
$item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n";
[1844] Fix | Delete
}
[1845] Fix | Delete
[1846] Fix | Delete
if ( $post->post_parent < 1 && isset( $_REQUEST['post_id'] ) ) {
[1847] Fix | Delete
$parent = (int) $_REQUEST['post_id'];
[1848] Fix | Delete
$parent_name = "attachments[$attachment_id][post_parent]";
[1849] Fix | Delete
$item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='$parent' />\n";
[1850] Fix | Delete
}
[1851] Fix | Delete
[1852] Fix | Delete
return $item;
[1853] Fix | Delete
}
[1854] Fix | Delete
[1855] Fix | Delete
/**
[1856] Fix | Delete
* @since 3.5.0
[1857] Fix | Delete
*
[1858] Fix | Delete
* @param int $attachment_id
[1859] Fix | Delete
* @param array $args
[1860] Fix | Delete
* @return array
[1861] Fix | Delete
*/
[1862] Fix | Delete
function get_compat_media_markup( $attachment_id, $args = null ) {
[1863] Fix | Delete
$post = get_post( $attachment_id );
[1864] Fix | Delete
[1865] Fix | Delete
$default_args = array(
[1866] Fix | Delete
'errors' => null,
[1867] Fix | Delete
'in_modal' => false,
[1868] Fix | Delete
);
[1869] Fix | Delete
[1870] Fix | Delete
$user_can_edit = current_user_can( 'edit_post', $attachment_id );
[1871] Fix | Delete
[1872] Fix | Delete
$args = wp_parse_args( $args, $default_args );
[1873] Fix | Delete
[1874] Fix | Delete
/** This filter is documented in wp-admin/includes/media.php */
[1875] Fix | Delete
$args = apply_filters( 'get_media_item_args', $args );
[1876] Fix | Delete
[1877] Fix | Delete
$form_fields = array();
[1878] Fix | Delete
[1879] Fix | Delete
if ( $args['in_modal'] ) {
[1880] Fix | Delete
foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) {
[1881] Fix | Delete
$t = (array) get_taxonomy( $taxonomy );
[1882] Fix | Delete
[1883] Fix | Delete
if ( ! $t['public'] || ! $t['show_ui'] ) {
[1884] Fix | Delete
continue;
[1885] Fix | Delete
}
[1886] Fix | Delete
[1887] Fix | Delete
if ( empty( $t['label'] ) ) {
[1888] Fix | Delete
$t['label'] = $taxonomy;
[1889] Fix | Delete
}
[1890] Fix | Delete
[1891] Fix | Delete
if ( empty( $t['args'] ) ) {
[1892] Fix | Delete
$t['args'] = array();
[1893] Fix | Delete
}
[1894] Fix | Delete
[1895] Fix | Delete
$terms = get_object_term_cache( $post->ID, $taxonomy );
[1896] Fix | Delete
[1897] Fix | Delete
if ( false === $terms ) {
[1898] Fix | Delete
$terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] );
[1899] Fix | Delete
}
[1900] Fix | Delete
[1901] Fix | Delete
$values = array();
[1902] Fix | Delete
[1903] Fix | Delete
foreach ( $terms as $term ) {
[1904] Fix | Delete
$values[] = $term->slug;
[1905] Fix | Delete
}
[1906] Fix | Delete
[1907] Fix | Delete
$t['value'] = implode( ', ', $values );
[1908] Fix | Delete
$t['taxonomy'] = true;
[1909] Fix | Delete
[1910] Fix | Delete
$form_fields[ $taxonomy ] = $t;
[1911] Fix | Delete
}
[1912] Fix | Delete
}
[1913] Fix | Delete
[1914] Fix | Delete
/*
[1915] Fix | Delete
* Merge default fields with their errors, so any key passed with the error
[1916] Fix | Delete
* (e.g. 'error', 'helps', 'value') will replace the default.
[1917] Fix | Delete
* The recursive merge is easily traversed with array casting:
[1918] Fix | Delete
* foreach ( (array) $things as $thing )
[1919] Fix | Delete
*/
[1920] Fix | Delete
$form_fields = array_merge_recursive( $form_fields, (array) $args['errors'] );
[1921] Fix | Delete
[1922] Fix | Delete
/** This filter is documented in wp-admin/includes/media.php */
[1923] Fix | Delete
$form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
[1924] Fix | Delete
[1925] Fix | Delete
unset(
[1926] Fix | Delete
$form_fields['image-size'],
[1927] Fix | Delete
$form_fields['align'],
[1928] Fix | Delete
$form_fields['image_alt'],
[1929] Fix | Delete
$form_fields['post_title'],
[1930] Fix | Delete
$form_fields['post_excerpt'],
[1931] Fix | Delete
$form_fields['post_content'],
[1932] Fix | Delete
$form_fields['url'],
[1933] Fix | Delete
$form_fields['menu_order'],
[1934] Fix | Delete
$form_fields['image_url']
[1935] Fix | Delete
);
[1936] Fix | Delete
[1937] Fix | Delete
/** This filter is documented in wp-admin/includes/media.php */
[1938] Fix | Delete
$media_meta = apply_filters( 'media_meta', '', $post );
[1939] Fix | Delete
[1940] Fix | Delete
$defaults = array(
[1941] Fix | Delete
'input' => 'text',
[1942] Fix | Delete
'required' => false,
[1943] Fix | Delete
'value' => '',
[1944] Fix | Delete
'extra_rows' => array(),
[1945] Fix | Delete
'show_in_edit' => true,
[1946] Fix | Delete
'show_in_modal' => true,
[1947] Fix | Delete
);
[1948] Fix | Delete
[1949] Fix | Delete
$hidden_fields = array();
[1950] Fix | Delete
[1951] Fix | Delete
$item = '';
[1952] Fix | Delete
[1953] Fix | Delete
foreach ( $form_fields as $id => $field ) {
[1954] Fix | Delete
if ( '_' === $id[0] ) {
[1955] Fix | Delete
continue;
[1956] Fix | Delete
}
[1957] Fix | Delete
[1958] Fix | Delete
$name = "attachments[$attachment_id][$id]";
[1959] Fix | Delete
$id_attr = "attachments-$attachment_id-$id";
[1960] Fix | Delete
[1961] Fix | Delete
if ( ! empty( $field['tr'] ) ) {
[1962] Fix | Delete
$item .= $field['tr'];
[1963] Fix | Delete
continue;
[1964] Fix | Delete
}
[1965] Fix | Delete
[1966] Fix | Delete
$field = array_merge( $defaults, $field );
[1967] Fix | Delete
[1968] Fix | Delete
if ( ( ! $field['show_in_edit'] && ! $args['in_modal'] ) || ( ! $field['show_in_modal'] && $args['in_modal'] ) ) {
[1969] Fix | Delete
continue;
[1970] Fix | Delete
}
[1971] Fix | Delete
[1972] Fix | Delete
if ( 'hidden' === $field['input'] ) {
[1973] Fix | Delete
$hidden_fields[ $name ] = $field['value'];
[1974] Fix | Delete
continue;
[1975] Fix | Delete
}
[1976] Fix | Delete
[1977] Fix | Delete
$readonly = ! $user_can_edit && ! empty( $field['taxonomy'] ) ? " readonly='readonly' " : '';
[1978] Fix | Delete
$required = $field['required'] ? '<span class="required">*</span>' : '';
[1979] Fix | Delete
$required_attr = $field['required'] ? ' required' : '';
[1980] Fix | Delete
$class = 'compat-field-' . $id;
[1981] Fix | Delete
$class .= $field['required'] ? ' form-required' : '';
[1982] Fix | Delete
[1983] Fix | Delete
$item .= "\t\t<tr class='$class'>";
[1984] Fix | Delete
$item .= "\t\t\t<th scope='row' class='label'><label for='$id_attr'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>";
[1985] Fix | Delete
$item .= "</th>\n\t\t\t<td class='field'>";
[1986] Fix | Delete
[1987] Fix | Delete
if ( ! empty( $field[ $field['input'] ] ) ) {
[1988] Fix | Delete
$item .= $field[ $field['input'] ];
[1989] Fix | Delete
} elseif ( 'textarea' === $field['input'] ) {
[1990] Fix | Delete
if ( 'post_content' === $id && user_can_richedit() ) {
[1991] Fix | Delete
// sanitize_post() skips the post_content when user_can_richedit.
[1992] Fix | Delete
$field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
[1993] Fix | Delete
}
[1994] Fix | Delete
$item .= "<textarea id='$id_attr' name='$name'{$required_attr}>" . $field['value'] . '</textarea>';
[1995] Fix | Delete
} else {
[1996] Fix | Delete
$item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $readonly{$required_attr} />";
[1997] Fix | Delete
}
[1998] Fix | Delete
[1999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function