wp_save_image_file

Definition:
function wp_save_image_file($filename, $image, $mime_type, $post_id) {}

Parameters

  • $filename
  • $image
  • $mime_type
  • $post_id

Defined filters

  • image_save_pre
    apply_filters('image_save_pre', $image, $post_id)
  • wp_save_image_file
    apply_filters('wp_save_image_file', null, $filename, $image, $mime_type, $post_id)
  • jpeg_quality
    apply_filters( 'jpeg_quality', 90, 'edit_image' )

Source code

function wp_save_image_file($filename, $image, $mime_type, $post_id) {

	$image = apply_filters('image_save_pre', $image, $post_id);

	$saved = apply_filters('wp_save_image_file', null, $filename, $image, $mime_type, $post_id);

	if ( null !== $saved )

		return $saved;



	switch ( $mime_type ) {

		case 'image/jpeg':

			return imagejpeg( $image, $filename, apply_filters( 'jpeg_quality', 90, 'edit_image' ) );

		case 'image/png':

			return imagepng($image, $filename);

		case 'image/gif':

			return imagegif($image, $filename);

		default:

			return false;

	}

}

4079

wp_save_image

Definition:
function wp_save_image($post_id) {}

Parameters

  • $post_id

Defined filters

  • admin_memory_limit
    apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT )

Source code

function wp_save_image($post_id) {

	$return = new stdClass;

	$success = $delete = $scaled = $nocrop = false;

	$post = get_post($post_id);

	@ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );

	$img = load_image_to_edit($post_id, $post->post_mime_type);



	if ( !is_resource($img) ) {

		$return->error = esc_js( __('Unable to create new image.') );

		return $return;

	}



	$fwidth = !empty($_REQUEST['fwidth']) ? intval($_REQUEST['fwidth']) : 0;

	$fheight = !empty($_REQUEST['fheight']) ? intval($_REQUEST['fheight']) : 0;

	$target = !empty($_REQUEST['target']) ? preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['target']) : '';

	$scale = !empty($_REQUEST['do']) && 'scale' == $_REQUEST['do'];



	if ( $scale && $fwidth > 0 && $fheight > 0 ) {

		$sX = imagesx($img);

		$sY = imagesy($img);



		// check if it has roughly the same w / h ratio

		$diff = round($sX / $sY, 2) - round($fwidth / $fheight, 2);

		if ( -0.1 < $diff && $diff < 0.1 ) {

			// scale the full size image

			$dst = wp_imagecreatetruecolor($fwidth, $fheight);

			if ( imagecopyresampled( $dst, $img, 0, 0, 0, 0, $fwidth, $fheight, $sX, $sY ) ) {

				imagedestroy($img);

				$img = $dst;

				$scaled = true;

			}

		}



		if ( !$scaled ) {

			$return->error = esc_js( __('Error while saving the scaled image. Please reload the page and try again.') );

			return $return;

		}

	} elseif ( !empty($_REQUEST['history']) ) {

		$changes = json_decode( stripslashes($_REQUEST['history']) );

		if ( $changes )

			$img = image_edit_apply_changes($img, $changes);

	} else {

		$return->error = esc_js( __('Nothing to save, the image has not changed.') );

		return $return;

	}



	$meta = wp_get_attachment_metadata($post_id);

	$backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true );



	if ( !is_array($meta) ) {

		$return->error = esc_js( __('Image data does not exist. Please re-upload the image.') );

		return $return;

	}



	if ( !is_array($backup_sizes) )

		$backup_sizes = array();



	// generate new filename

	$path = get_attached_file($post_id);

	$path_parts = pathinfo( $path );

	$filename = $path_parts['filename'];

	$suffix = time() . rand(100, 999);



	if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE &&

		isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $path_parts['basename'] ) {



		if ( 'thumbnail' == $target )

			$new_path = "{$path_parts['dirname']}/{$filename}-temp.{$path_parts['extension']}";

4077

wp_sanitize_redirect

Definition:
function wp_sanitize_redirect($location) {}

Sanitizes a URL for use in a redirect.

Parameters

  • $location

Return values

returns:redirect-sanitized URL

Source code

function wp_sanitize_redirect($location) {

	$location = preg_replace('|[^a-z0-9-~+_.?#=&;,/:%!]|i', '', $location);

	$location = wp_kses_no_null($location);



	// remove %0d and %0a from location

	$strip = array('%0d', '%0a', '%0D', '%0A');

	$location = _deep_replace($strip, $location);

	return $location;

}

4075

wp_salt

Definition:
function wp_salt($scheme = 'auth') {}

Get salt to add to hashes to help prevent attacks.
The secret key is located in two places: the database in case the secret key isn’t defined in the second place, which is in the wp-config.php file. If you are going to set the secret key, then you must do so in the wp-config.php file.

Parameters

  • string $scheme: Authentication scheme

Return values

returns:Salt value

Defined filters

  • salt
    apply_filters('salt', $secret_key . $salt, $scheme)

Source code

function wp_salt($scheme = 'auth') {

	global $wp_default_secret_key;

	$secret_key = '';

	if ( defined('SECRET_KEY') && ('' != SECRET_KEY) && ( $wp_default_secret_key != SECRET_KEY) )

		$secret_key = SECRET_KEY;



	if ( 'auth' == $scheme ) {

		if ( defined('AUTH_KEY') && ('' != AUTH_KEY) && ( $wp_default_secret_key != AUTH_KEY) )

			$secret_key = AUTH_KEY;



		if ( defined('AUTH_SALT') && ('' != AUTH_SALT) && ( $wp_default_secret_key != AUTH_SALT) ) {

			$salt = AUTH_SALT;

		} elseif ( defined('SECRET_SALT') && ('' != SECRET_SALT) && ( $wp_default_secret_key != SECRET_SALT) ) {

			$salt = SECRET_SALT;

		} else {

			$salt = get_site_option('auth_salt');

			if ( empty($salt) ) {

				$salt = wp_generate_password( 64, true, true );

				update_site_option('auth_salt', $salt);

			}

		}

	} elseif ( 'secure_auth' == $scheme ) {

		if ( defined('SECURE_AUTH_KEY') && ('' != SECURE_AUTH_KEY) && ( $wp_default_secret_key != SECURE_AUTH_KEY) )

			$secret_key = SECURE_AUTH_KEY;



		if ( defined('SECURE_AUTH_SALT') && ('' != SECURE_AUTH_SALT) && ( $wp_default_secret_key != SECURE_AUTH_SALT) ) {

			$salt = SECURE_AUTH_SALT;

		} else {

			$salt = get_site_option('secure_auth_salt');

			if ( empty($salt) ) {

				$salt = wp_generate_password( 64, true, true );

				update_site_option('secure_auth_salt', $salt);

			}

		}

	} elseif ( 'logged_in' == $scheme ) {

		if ( defined('LOGGED_IN_KEY') && ('' != LOGGED_IN_KEY) && ( $wp_default_secret_key != LOGGED_IN_KEY) )

			$secret_key = LOGGED_IN_KEY;



		if ( defined('LOGGED_IN_SALT') && ('' != LOGGED_IN_SALT) && ( $wp_default_secret_key != LOGGED_IN_SALT) ) {

			$salt = LOGGED_IN_SALT;

		} else {

			$salt = get_site_option('logged_in_salt');

			if ( empty($salt) ) {

				$salt = wp_generate_password( 64, true, true );

				update_site_option('logged_in_salt', $salt);

			}

		}

	} elseif ( 'nonce' == $scheme ) {

		if ( defined('NONCE_KEY') && ('' != NONCE_KEY) && ( $wp_default_secret_key != NONCE_KEY) )

			$secret_key = NONCE_KEY;



		if ( defined('NONCE_SALT') && ('' != NONCE_SALT) && ( $wp_default_secret_key != NONCE_SALT) ) {

			$salt = NONCE_SALT;

		} else {

			$salt = get_site_option('nonce_salt');

			if ( empty($salt) ) {

				$salt = wp_generate_password( 64, true, true );

				update_site_option('nonce_salt', $salt);

			}

		}

	} else {

		// ensure each auth scheme has its own unique salt

		$salt = hash_hmac('md5', $scheme, $secret_key);

	}



	return apply_filters('salt', $secret_key . $salt, $scheme);

}

4073

wp_safe_redirect

Definition:
function wp_safe_redirect($location, $status = 302) {}

Performs a safe (local) redirect, using wp_redirect().
Checks whether the $location is using an allowed host, if it has an absolute path. A plugin can therefore set or remove allowed host(s) to or from the list.

Parameters

  • $location
  • $status

Return values

returns:Does not return anything

Source code

function wp_safe_redirect($location, $status = 302) {



	// Need to look at the URL the way it will end up in wp_redirect()

	$location = wp_sanitize_redirect($location);



	$location = wp_validate_redirect($location, admin_url());



	wp_redirect($location, $status);

}

4071