media_handle_sideload

Definition:
function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array() {}

This handles a sideloaded file in the same way as an uploaded file is handled by media_handle_upload()

Parameters

  • array $file_array: Array similar to a $_FILES upload array
  • int $post_id: The post ID the media is associated with
  • string $desc: Description of the sideloaded file
  • array $post_data: allows you to overwrite some of the attachment

Return values

returns:ID of the attachment or a WP_Error on failure

Source code

function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {

	$overrides = array('test_form'=>false);



	$file = wp_handle_sideload($file_array, $overrides);

	if ( isset($file['error']) )

		return new WP_Error( 'upload_error', $file['error'] );



	$url = $file['url'];

	$type = $file['type'];

	$file = $file['file'];

	$title = preg_replace('/\.[^.]+$/', '', basename($file));

	$content = '';



	// use image exif/iptc data for title and caption defaults if possible

	if ( $image_meta = @wp_read_image_metadata($file) ) {

		if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) )

			$title = $image_meta['title'];

		if ( trim( $image_meta['caption'] ) )

			$content = $image_meta['caption'];

	}



	$title = isset($desc) ? $desc : '';



	// Construct the attachment array

	$attachment = array_merge( array(

		'post_mime_type' => $type,

		'guid' => $url,

		'post_parent' => $post_id,

		'post_title' => $title,

		'post_content' => $content,

	), $post_data );



	// This should never be set as it would then overwrite an existing attachment.

	if ( isset( $attachment['ID'] ) )

		unset( $attachment['ID'] );



	// Save the attachment metadata

	$id = wp_insert_attachment($attachment, $file, $post_id);

	if ( !is_wp_error($id) )

		wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );



	return $id;

}

2349

media_buttons

Definition:
function media_buttons() {}

Parameters

  • $editor_id

Defined filters

  • media_buttons_context
    apply_filters('media_buttons_context', __('Upload/Insert %s')

Source code

function media_buttons() {

	$do_image = $do_audio = $do_video = true;

	if ( is_multisite() ) {

		$media_buttons = get_site_option( 'mu_media_buttons' );

		if ( empty($media_buttons['image']) )

			$do_image = false;

		if ( empty($media_buttons['audio']) )

			$do_audio = false;

		if ( empty($media_buttons['video']) )

			$do_video = false;

	}

	$out = '';



	if ( $do_image )

		$out .= _media_button(__('Add an Image'), 'images/media-button-image.gif?ver=20100531', 'image');

	if ( $do_video )

		$out .= _media_button(__('Add Video'), 'images/media-button-video.gif?ver=20100531', 'video');

	if ( $do_audio )

		$out .= _media_button(__('Add Audio'), 'images/media-button-music.gif?ver=20100531', 'audio');



	$out .= _media_button(__('Add Media'), 'images/media-button-other.gif?ver=20100531', 'media');



	$context = apply_filters('media_buttons_context', __('Upload/Insert %s'));



	printf($context, $out);

}

2347

mce_put_file

Definition:
function mce_put_file( $path, $content ) {}

Parameters

  • $path
  • $content

Source code

function mce_put_file( $path, $content ) {

	if ( function_exists('file_put_contents') )

		return @file_put_contents( $path, $content );



	$newfile = false;

	$fp = @fopen( $path, 'wb' );

	if ($fp) {

		$newfile = fwrite( $fp, $content );

		fclose($fp);

	}

	return $newfile;

}

2345

mce_escape

Definition:
function mce_escape($text) {}

Parameters

  • $text

Source code

function mce_escape($text) {

	return esc_js($text);

}

2343

mb_substr

Definition:
function mb_substr($str, $start, $len = '', $encoding="UTF-8"){

Parameters

  • $str
  • $start
  • $len
  • $encoding

Source code

	function mb_substr($str, $start, $len = '', $encoding="UTF-8"){

		$limit = strlen($str);



		for ($s = 0; $start > 0;--$start) {// found the real start

			if ($s >= $limit)

				break;



			if ($str[$s] <= "\x7F")

				++$s;

			else {

				++$s; // skip length



				while ($str[$s] >= "\x80" && $str[$s] <= "\xBF")

					++$s;

			}

		}



		if ($len == '')

			return substr($str, $s);

		else

			for ($e = $s; $len > 0; --$len) {//found the real end

				if ($e >= $limit)

					break;



				if ($str[$e] <= "\x7F")

					++$e;

				else {

					++$e;//skip length



					while ($str[$e] >= "\x80" && $str[$e] <= "\xBF" && $e < $limit)

						++$e;

				}

			}



		return substr($str, $s, $e - $s);

	}

2341