Edit File by line
/home/barbar84/www/wp-admin/includes
File: media.php
wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
[500] Fix | Delete
}
[501] Fix | Delete
[502] Fix | Delete
return $attachment_id;
[503] Fix | Delete
}
[504] Fix | Delete
[505] Fix | Delete
/**
[506] Fix | Delete
* Outputs the iframe to display the media upload page.
[507] Fix | Delete
*
[508] Fix | Delete
* @since 2.5.0
[509] Fix | Delete
* @since 5.3.0 Formalized the existing and already documented `...$args` parameter
[510] Fix | Delete
* by adding it to the function signature.
[511] Fix | Delete
*
[512] Fix | Delete
* @global int $body_id
[513] Fix | Delete
*
[514] Fix | Delete
* @param callable $content_func Function that outputs the content.
[515] Fix | Delete
* @param mixed ...$args Optional additional parameters to pass to the callback function when it's called.
[516] Fix | Delete
*/
[517] Fix | Delete
function wp_iframe( $content_func, ...$args ) {
[518] Fix | Delete
_wp_admin_html_begin();
[519] Fix | Delete
?>
[520] Fix | Delete
<title><?php bloginfo( 'name' ); ?> &rsaquo; <?php _e( 'Uploads' ); ?> &#8212; <?php _e( 'WordPress' ); ?></title>
[521] Fix | Delete
<?php
[522] Fix | Delete
[523] Fix | Delete
wp_enqueue_style( 'colors' );
[524] Fix | Delete
// Check callback name for 'media'.
[525] Fix | Delete
if (
[526] Fix | Delete
( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) ) ||
[527] Fix | Delete
( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) )
[528] Fix | Delete
) {
[529] Fix | Delete
wp_enqueue_style( 'deprecated-media' );
[530] Fix | Delete
}
[531] Fix | Delete
[532] Fix | Delete
?>
[533] Fix | Delete
<script type="text/javascript">
[534] Fix | Delete
addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
[535] Fix | Delete
var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',
[536] Fix | Delete
isRtl = <?php echo (int) is_rtl(); ?>;
[537] Fix | Delete
</script>
[538] Fix | Delete
<?php
[539] Fix | Delete
/** This action is documented in wp-admin/admin-header.php */
[540] Fix | Delete
do_action( 'admin_enqueue_scripts', 'media-upload-popup' );
[541] Fix | Delete
[542] Fix | Delete
/**
[543] Fix | Delete
* Fires when admin styles enqueued for the legacy (pre-3.5.0) media upload popup are printed.
[544] Fix | Delete
*
[545] Fix | Delete
* @since 2.9.0
[546] Fix | Delete
*/
[547] Fix | Delete
do_action( 'admin_print_styles-media-upload-popup' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
[548] Fix | Delete
[549] Fix | Delete
/** This action is documented in wp-admin/admin-header.php */
[550] Fix | Delete
do_action( 'admin_print_styles' );
[551] Fix | Delete
[552] Fix | Delete
/**
[553] Fix | Delete
* Fires when admin scripts enqueued for the legacy (pre-3.5.0) media upload popup are printed.
[554] Fix | Delete
*
[555] Fix | Delete
* @since 2.9.0
[556] Fix | Delete
*/
[557] Fix | Delete
do_action( 'admin_print_scripts-media-upload-popup' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
[558] Fix | Delete
[559] Fix | Delete
/** This action is documented in wp-admin/admin-header.php */
[560] Fix | Delete
do_action( 'admin_print_scripts' );
[561] Fix | Delete
[562] Fix | Delete
/**
[563] Fix | Delete
* Fires when scripts enqueued for the admin header for the legacy (pre-3.5.0)
[564] Fix | Delete
* media upload popup are printed.
[565] Fix | Delete
*
[566] Fix | Delete
* @since 2.9.0
[567] Fix | Delete
*/
[568] Fix | Delete
do_action( 'admin_head-media-upload-popup' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
[569] Fix | Delete
[570] Fix | Delete
/** This action is documented in wp-admin/admin-header.php */
[571] Fix | Delete
do_action( 'admin_head' );
[572] Fix | Delete
[573] Fix | Delete
if ( is_string( $content_func ) ) {
[574] Fix | Delete
/**
[575] Fix | Delete
* Fires in the admin header for each specific form tab in the legacy
[576] Fix | Delete
* (pre-3.5.0) media upload popup.
[577] Fix | Delete
*
[578] Fix | Delete
* The dynamic portion of the hook, `$content_func`, refers to the form
[579] Fix | Delete
* callback for the media upload type. Possible values include
[580] Fix | Delete
* 'media_upload_type_form', 'media_upload_type_url_form', and
[581] Fix | Delete
* 'media_upload_library_form'.
[582] Fix | Delete
*
[583] Fix | Delete
* @since 2.5.0
[584] Fix | Delete
*/
[585] Fix | Delete
do_action( "admin_head_{$content_func}" );
[586] Fix | Delete
}
[587] Fix | Delete
[588] Fix | Delete
$body_id_attr = '';
[589] Fix | Delete
[590] Fix | Delete
if ( isset( $GLOBALS['body_id'] ) ) {
[591] Fix | Delete
$body_id_attr = ' id="' . $GLOBALS['body_id'] . '"';
[592] Fix | Delete
}
[593] Fix | Delete
[594] Fix | Delete
?>
[595] Fix | Delete
</head>
[596] Fix | Delete
<body<?php echo $body_id_attr; ?> class="wp-core-ui no-js">
[597] Fix | Delete
<script type="text/javascript">
[598] Fix | Delete
document.body.className = document.body.className.replace('no-js', 'js');
[599] Fix | Delete
</script>
[600] Fix | Delete
<?php
[601] Fix | Delete
[602] Fix | Delete
call_user_func_array( $content_func, $args );
[603] Fix | Delete
[604] Fix | Delete
/** This action is documented in wp-admin/admin-footer.php */
[605] Fix | Delete
do_action( 'admin_print_footer_scripts' );
[606] Fix | Delete
[607] Fix | Delete
?>
[608] Fix | Delete
<script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
[609] Fix | Delete
</body>
[610] Fix | Delete
</html>
[611] Fix | Delete
<?php
[612] Fix | Delete
}
[613] Fix | Delete
[614] Fix | Delete
/**
[615] Fix | Delete
* Adds the media button to the editor
[616] Fix | Delete
*
[617] Fix | Delete
* @since 2.5.0
[618] Fix | Delete
*
[619] Fix | Delete
* @global int $post_ID
[620] Fix | Delete
*
[621] Fix | Delete
* @param string $editor_id
[622] Fix | Delete
*/
[623] Fix | Delete
function media_buttons( $editor_id = 'content' ) {
[624] Fix | Delete
static $instance = 0;
[625] Fix | Delete
$instance++;
[626] Fix | Delete
[627] Fix | Delete
$post = get_post();
[628] Fix | Delete
[629] Fix | Delete
if ( ! $post && ! empty( $GLOBALS['post_ID'] ) ) {
[630] Fix | Delete
$post = $GLOBALS['post_ID'];
[631] Fix | Delete
}
[632] Fix | Delete
[633] Fix | Delete
wp_enqueue_media( array( 'post' => $post ) );
[634] Fix | Delete
[635] Fix | Delete
$img = '<span class="wp-media-buttons-icon"></span> ';
[636] Fix | Delete
[637] Fix | Delete
$id_attribute = 1 === $instance ? ' id="insert-media-button"' : '';
[638] Fix | Delete
[639] Fix | Delete
printf(
[640] Fix | Delete
'<button type="button"%s class="button insert-media add_media" data-editor="%s">%s</button>',
[641] Fix | Delete
$id_attribute,
[642] Fix | Delete
esc_attr( $editor_id ),
[643] Fix | Delete
$img . __( 'Add Media' )
[644] Fix | Delete
);
[645] Fix | Delete
[646] Fix | Delete
/**
[647] Fix | Delete
* Filters the legacy (pre-3.5.0) media buttons.
[648] Fix | Delete
*
[649] Fix | Delete
* Use {@see 'media_buttons'} action instead.
[650] Fix | Delete
*
[651] Fix | Delete
* @since 2.5.0
[652] Fix | Delete
* @deprecated 3.5.0 Use {@see 'media_buttons'} action instead.
[653] Fix | Delete
*
[654] Fix | Delete
* @param string $string Media buttons context. Default empty.
[655] Fix | Delete
*/
[656] Fix | Delete
$legacy_filter = apply_filters_deprecated( 'media_buttons_context', array( '' ), '3.5.0', 'media_buttons' );
[657] Fix | Delete
[658] Fix | Delete
if ( $legacy_filter ) {
[659] Fix | Delete
// #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
[660] Fix | Delete
if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) ) {
[661] Fix | Delete
$legacy_filter .= '</a>';
[662] Fix | Delete
}
[663] Fix | Delete
echo $legacy_filter;
[664] Fix | Delete
}
[665] Fix | Delete
}
[666] Fix | Delete
[667] Fix | Delete
/**
[668] Fix | Delete
* @global int $post_ID
[669] Fix | Delete
* @param string $type
[670] Fix | Delete
* @param int $post_id
[671] Fix | Delete
* @param string $tab
[672] Fix | Delete
* @return string
[673] Fix | Delete
*/
[674] Fix | Delete
function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) {
[675] Fix | Delete
global $post_ID;
[676] Fix | Delete
[677] Fix | Delete
if ( empty( $post_id ) ) {
[678] Fix | Delete
$post_id = $post_ID;
[679] Fix | Delete
}
[680] Fix | Delete
[681] Fix | Delete
$upload_iframe_src = add_query_arg( 'post_id', (int) $post_id, admin_url( 'media-upload.php' ) );
[682] Fix | Delete
[683] Fix | Delete
if ( $type && 'media' !== $type ) {
[684] Fix | Delete
$upload_iframe_src = add_query_arg( 'type', $type, $upload_iframe_src );
[685] Fix | Delete
}
[686] Fix | Delete
[687] Fix | Delete
if ( ! empty( $tab ) ) {
[688] Fix | Delete
$upload_iframe_src = add_query_arg( 'tab', $tab, $upload_iframe_src );
[689] Fix | Delete
}
[690] Fix | Delete
[691] Fix | Delete
/**
[692] Fix | Delete
* Filters the upload iframe source URL for a specific media type.
[693] Fix | Delete
*
[694] Fix | Delete
* The dynamic portion of the hook name, `$type`, refers to the type
[695] Fix | Delete
* of media uploaded.
[696] Fix | Delete
*
[697] Fix | Delete
* @since 3.0.0
[698] Fix | Delete
*
[699] Fix | Delete
* @param string $upload_iframe_src The upload iframe source URL by type.
[700] Fix | Delete
*/
[701] Fix | Delete
$upload_iframe_src = apply_filters( "{$type}_upload_iframe_src", $upload_iframe_src );
[702] Fix | Delete
[703] Fix | Delete
return add_query_arg( 'TB_iframe', true, $upload_iframe_src );
[704] Fix | Delete
}
[705] Fix | Delete
[706] Fix | Delete
/**
[707] Fix | Delete
* Handles form submissions for the legacy media uploader.
[708] Fix | Delete
*
[709] Fix | Delete
* @since 2.5.0
[710] Fix | Delete
*
[711] Fix | Delete
* @return mixed void|object WP_Error on failure
[712] Fix | Delete
*/
[713] Fix | Delete
function media_upload_form_handler() {
[714] Fix | Delete
check_admin_referer( 'media-form' );
[715] Fix | Delete
[716] Fix | Delete
$errors = null;
[717] Fix | Delete
[718] Fix | Delete
if ( isset( $_POST['send'] ) ) {
[719] Fix | Delete
$keys = array_keys( $_POST['send'] );
[720] Fix | Delete
$send_id = (int) reset( $keys );
[721] Fix | Delete
}
[722] Fix | Delete
[723] Fix | Delete
if ( ! empty( $_POST['attachments'] ) ) {
[724] Fix | Delete
foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
[725] Fix | Delete
$post = get_post( $attachment_id, ARRAY_A );
[726] Fix | Delete
$_post = $post;
[727] Fix | Delete
[728] Fix | Delete
if ( ! current_user_can( 'edit_post', $attachment_id ) ) {
[729] Fix | Delete
continue;
[730] Fix | Delete
}
[731] Fix | Delete
[732] Fix | Delete
if ( isset( $attachment['post_content'] ) ) {
[733] Fix | Delete
$post['post_content'] = $attachment['post_content'];
[734] Fix | Delete
}
[735] Fix | Delete
[736] Fix | Delete
if ( isset( $attachment['post_title'] ) ) {
[737] Fix | Delete
$post['post_title'] = $attachment['post_title'];
[738] Fix | Delete
}
[739] Fix | Delete
[740] Fix | Delete
if ( isset( $attachment['post_excerpt'] ) ) {
[741] Fix | Delete
$post['post_excerpt'] = $attachment['post_excerpt'];
[742] Fix | Delete
}
[743] Fix | Delete
[744] Fix | Delete
if ( isset( $attachment['menu_order'] ) ) {
[745] Fix | Delete
$post['menu_order'] = $attachment['menu_order'];
[746] Fix | Delete
}
[747] Fix | Delete
[748] Fix | Delete
if ( isset( $send_id ) && $attachment_id == $send_id ) {
[749] Fix | Delete
if ( isset( $attachment['post_parent'] ) ) {
[750] Fix | Delete
$post['post_parent'] = $attachment['post_parent'];
[751] Fix | Delete
}
[752] Fix | Delete
}
[753] Fix | Delete
[754] Fix | Delete
/**
[755] Fix | Delete
* Filters the attachment fields to be saved.
[756] Fix | Delete
*
[757] Fix | Delete
* @since 2.5.0
[758] Fix | Delete
*
[759] Fix | Delete
* @see wp_get_attachment_metadata()
[760] Fix | Delete
*
[761] Fix | Delete
* @param array $post An array of post data.
[762] Fix | Delete
* @param array $attachment An array of attachment metadata.
[763] Fix | Delete
*/
[764] Fix | Delete
$post = apply_filters( 'attachment_fields_to_save', $post, $attachment );
[765] Fix | Delete
[766] Fix | Delete
if ( isset( $attachment['image_alt'] ) ) {
[767] Fix | Delete
$image_alt = wp_unslash( $attachment['image_alt'] );
[768] Fix | Delete
[769] Fix | Delete
if ( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) !== $image_alt ) {
[770] Fix | Delete
$image_alt = wp_strip_all_tags( $image_alt, true );
[771] Fix | Delete
[772] Fix | Delete
// update_post_meta() expects slashed.
[773] Fix | Delete
update_post_meta( $attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
[774] Fix | Delete
}
[775] Fix | Delete
}
[776] Fix | Delete
[777] Fix | Delete
if ( isset( $post['errors'] ) ) {
[778] Fix | Delete
$errors[ $attachment_id ] = $post['errors'];
[779] Fix | Delete
unset( $post['errors'] );
[780] Fix | Delete
}
[781] Fix | Delete
[782] Fix | Delete
if ( $post != $_post ) {
[783] Fix | Delete
wp_update_post( $post );
[784] Fix | Delete
}
[785] Fix | Delete
[786] Fix | Delete
foreach ( get_attachment_taxonomies( $post ) as $t ) {
[787] Fix | Delete
if ( isset( $attachment[ $t ] ) ) {
[788] Fix | Delete
wp_set_object_terms( $attachment_id, array_map( 'trim', preg_split( '/,+/', $attachment[ $t ] ) ), $t, false );
[789] Fix | Delete
}
[790] Fix | Delete
}
[791] Fix | Delete
}
[792] Fix | Delete
}
[793] Fix | Delete
[794] Fix | Delete
if ( isset( $_POST['insert-gallery'] ) || isset( $_POST['update-gallery'] ) ) {
[795] Fix | Delete
?>
[796] Fix | Delete
<script type="text/javascript">
[797] Fix | Delete
var win = window.dialogArguments || opener || parent || top;
[798] Fix | Delete
win.tb_remove();
[799] Fix | Delete
</script>
[800] Fix | Delete
<?php
[801] Fix | Delete
[802] Fix | Delete
exit;
[803] Fix | Delete
}
[804] Fix | Delete
[805] Fix | Delete
if ( isset( $send_id ) ) {
[806] Fix | Delete
$attachment = wp_unslash( $_POST['attachments'][ $send_id ] );
[807] Fix | Delete
$html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
[808] Fix | Delete
[809] Fix | Delete
if ( ! empty( $attachment['url'] ) ) {
[810] Fix | Delete
$rel = '';
[811] Fix | Delete
[812] Fix | Delete
if ( strpos( $attachment['url'], 'attachment_id' ) || get_attachment_link( $send_id ) == $attachment['url'] ) {
[813] Fix | Delete
$rel = " rel='attachment wp-att-" . esc_attr( $send_id ) . "'";
[814] Fix | Delete
}
[815] Fix | Delete
[816] Fix | Delete
$html = "<a href='{$attachment['url']}'$rel>$html</a>";
[817] Fix | Delete
}
[818] Fix | Delete
[819] Fix | Delete
/**
[820] Fix | Delete
* Filters the HTML markup for a media item sent to the editor.
[821] Fix | Delete
*
[822] Fix | Delete
* @since 2.5.0
[823] Fix | Delete
*
[824] Fix | Delete
* @see wp_get_attachment_metadata()
[825] Fix | Delete
*
[826] Fix | Delete
* @param string $html HTML markup for a media item sent to the editor.
[827] Fix | Delete
* @param int $send_id The first key from the $_POST['send'] data.
[828] Fix | Delete
* @param array $attachment Array of attachment metadata.
[829] Fix | Delete
*/
[830] Fix | Delete
$html = apply_filters( 'media_send_to_editor', $html, $send_id, $attachment );
[831] Fix | Delete
[832] Fix | Delete
return media_send_to_editor( $html );
[833] Fix | Delete
}
[834] Fix | Delete
[835] Fix | Delete
return $errors;
[836] Fix | Delete
}
[837] Fix | Delete
[838] Fix | Delete
/**
[839] Fix | Delete
* Handles the process of uploading media.
[840] Fix | Delete
*
[841] Fix | Delete
* @since 2.5.0
[842] Fix | Delete
*
[843] Fix | Delete
* @return null|string
[844] Fix | Delete
*/
[845] Fix | Delete
function wp_media_upload_handler() {
[846] Fix | Delete
$errors = array();
[847] Fix | Delete
$id = 0;
[848] Fix | Delete
[849] Fix | Delete
if ( isset( $_POST['html-upload'] ) && ! empty( $_FILES ) ) {
[850] Fix | Delete
check_admin_referer( 'media-form' );
[851] Fix | Delete
// Upload File button was clicked.
[852] Fix | Delete
$id = media_handle_upload( 'async-upload', $_REQUEST['post_id'] );
[853] Fix | Delete
unset( $_FILES );
[854] Fix | Delete
[855] Fix | Delete
if ( is_wp_error( $id ) ) {
[856] Fix | Delete
$errors['upload_error'] = $id;
[857] Fix | Delete
$id = false;
[858] Fix | Delete
}
[859] Fix | Delete
}
[860] Fix | Delete
[861] Fix | Delete
if ( ! empty( $_POST['insertonlybutton'] ) ) {
[862] Fix | Delete
$src = $_POST['src'];
[863] Fix | Delete
[864] Fix | Delete
if ( ! empty( $src ) && ! strpos( $src, '://' ) ) {
[865] Fix | Delete
$src = "http://$src";
[866] Fix | Delete
}
[867] Fix | Delete
[868] Fix | Delete
if ( isset( $_POST['media_type'] ) && 'image' !== $_POST['media_type'] ) {
[869] Fix | Delete
$title = esc_html( wp_unslash( $_POST['title'] ) );
[870] Fix | Delete
if ( empty( $title ) ) {
[871] Fix | Delete
$title = esc_html( wp_basename( $src ) );
[872] Fix | Delete
}
[873] Fix | Delete
[874] Fix | Delete
if ( $title && $src ) {
[875] Fix | Delete
$html = "<a href='" . esc_url( $src ) . "'>$title</a>";
[876] Fix | Delete
}
[877] Fix | Delete
[878] Fix | Delete
$type = 'file';
[879] Fix | Delete
$ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src );
[880] Fix | Delete
[881] Fix | Delete
if ( $ext ) {
[882] Fix | Delete
$ext_type = wp_ext2type( $ext );
[883] Fix | Delete
if ( 'audio' === $ext_type || 'video' === $ext_type ) {
[884] Fix | Delete
$type = $ext_type;
[885] Fix | Delete
}
[886] Fix | Delete
}
[887] Fix | Delete
[888] Fix | Delete
/**
[889] Fix | Delete
* Filters the URL sent to the editor for a specific media type.
[890] Fix | Delete
*
[891] Fix | Delete
* The dynamic portion of the hook name, `$type`, refers to the type
[892] Fix | Delete
* of media being sent.
[893] Fix | Delete
*
[894] Fix | Delete
* @since 3.3.0
[895] Fix | Delete
*
[896] Fix | Delete
* @param string $html HTML markup sent to the editor.
[897] Fix | Delete
* @param string $src Media source URL.
[898] Fix | Delete
* @param string $title Media title.
[899] Fix | Delete
*/
[900] Fix | Delete
$html = apply_filters( "{$type}_send_to_editor_url", $html, esc_url_raw( $src ), $title );
[901] Fix | Delete
} else {
[902] Fix | Delete
$align = '';
[903] Fix | Delete
$alt = esc_attr( wp_unslash( $_POST['alt'] ) );
[904] Fix | Delete
[905] Fix | Delete
if ( isset( $_POST['align'] ) ) {
[906] Fix | Delete
$align = esc_attr( wp_unslash( $_POST['align'] ) );
[907] Fix | Delete
$class = " class='align$align'";
[908] Fix | Delete
}
[909] Fix | Delete
[910] Fix | Delete
if ( ! empty( $src ) ) {
[911] Fix | Delete
$html = "<img src='" . esc_url( $src ) . "' alt='$alt'$class />";
[912] Fix | Delete
}
[913] Fix | Delete
[914] Fix | Delete
/**
[915] Fix | Delete
* Filters the image URL sent to the editor.
[916] Fix | Delete
*
[917] Fix | Delete
* @since 2.8.0
[918] Fix | Delete
*
[919] Fix | Delete
* @param string $html HTML markup sent to the editor for an image.
[920] Fix | Delete
* @param string $src Image source URL.
[921] Fix | Delete
* @param string $alt Image alternate, or alt, text.
[922] Fix | Delete
* @param string $align The image alignment. Default 'alignnone'. Possible values include
[923] Fix | Delete
* 'alignleft', 'aligncenter', 'alignright', 'alignnone'.
[924] Fix | Delete
*/
[925] Fix | Delete
$html = apply_filters( 'image_send_to_editor_url', $html, esc_url_raw( $src ), $alt, $align );
[926] Fix | Delete
}
[927] Fix | Delete
[928] Fix | Delete
return media_send_to_editor( $html );
[929] Fix | Delete
}
[930] Fix | Delete
[931] Fix | Delete
if ( isset( $_POST['save'] ) ) {
[932] Fix | Delete
$errors['upload_notice'] = __( 'Saved.' );
[933] Fix | Delete
wp_enqueue_script( 'admin-gallery' );
[934] Fix | Delete
[935] Fix | Delete
return wp_iframe( 'media_upload_gallery_form', $errors );
[936] Fix | Delete
[937] Fix | Delete
} elseif ( ! empty( $_POST ) ) {
[938] Fix | Delete
$return = media_upload_form_handler();
[939] Fix | Delete
[940] Fix | Delete
if ( is_string( $return ) ) {
[941] Fix | Delete
return $return;
[942] Fix | Delete
}
[943] Fix | Delete
[944] Fix | Delete
if ( is_array( $return ) ) {
[945] Fix | Delete
$errors = $return;
[946] Fix | Delete
}
[947] Fix | Delete
}
[948] Fix | Delete
[949] Fix | Delete
if ( isset( $_GET['tab'] ) && 'type_url' === $_GET['tab'] ) {
[950] Fix | Delete
$type = 'image';
[951] Fix | Delete
[952] Fix | Delete
if ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'video', 'audio', 'file' ), true ) ) {
[953] Fix | Delete
$type = $_GET['type'];
[954] Fix | Delete
}
[955] Fix | Delete
[956] Fix | Delete
return wp_iframe( 'media_upload_type_url_form', $type, $errors, $id );
[957] Fix | Delete
}
[958] Fix | Delete
[959] Fix | Delete
return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
[960] Fix | Delete
}
[961] Fix | Delete
[962] Fix | Delete
/**
[963] Fix | Delete
* Downloads an image from the specified URL, saves it as an attachment, and optionally attaches it to a post.
[964] Fix | Delete
*
[965] Fix | Delete
* @since 2.6.0
[966] Fix | Delete
* @since 4.2.0 Introduced the `$return` parameter.
[967] Fix | Delete
* @since 4.8.0 Introduced the 'id' option for the `$return` parameter.
[968] Fix | Delete
* @since 5.3.0 The `$post_id` parameter was made optional.
[969] Fix | Delete
* @since 5.4.0 The original URL of the attachment is stored in the `_source_url`
[970] Fix | Delete
* post meta value.
[971] Fix | Delete
*
[972] Fix | Delete
* @param string $file The URL of the image to download.
[973] Fix | Delete
* @param int $post_id Optional. The post ID the media is to be associated with.
[974] Fix | Delete
* @param string $desc Optional. Description of the image.
[975] Fix | Delete
* @param string $return Optional. Accepts 'html' (image tag html) or 'src' (URL),
[976] Fix | Delete
* or 'id' (attachment ID). Default 'html'.
[977] Fix | Delete
* @return string|int|WP_Error Populated HTML img tag, attachment ID, or attachment source
[978] Fix | Delete
* on success, WP_Error object otherwise.
[979] Fix | Delete
*/
[980] Fix | Delete
function media_sideload_image( $file, $post_id = 0, $desc = null, $return = 'html' ) {
[981] Fix | Delete
if ( ! empty( $file ) ) {
[982] Fix | Delete
[983] Fix | Delete
$allowed_extensions = array( 'jpg', 'jpeg', 'jpe', 'png', 'gif' );
[984] Fix | Delete
[985] Fix | Delete
/**
[986] Fix | Delete
* Filters the list of allowed file extensions when sideloading an image from a URL.
[987] Fix | Delete
*
[988] Fix | Delete
* The default allowed extensions are:
[989] Fix | Delete
*
[990] Fix | Delete
* - `jpg`
[991] Fix | Delete
* - `jpeg`
[992] Fix | Delete
* - `jpe`
[993] Fix | Delete
* - `png`
[994] Fix | Delete
* - `gif`
[995] Fix | Delete
*
[996] Fix | Delete
* @since 5.6.0
[997] Fix | Delete
*
[998] Fix | Delete
* @param string[] $allowed_extensions Array of allowed file extensions.
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function