wp_check_password

Definition:
function wp_check_password($password, $hash, $user_id = '') {}

Checks the plaintext password against the encrypted Password.
Maintains compatibility between old version and the new cookie authentication protocol using PHPass library. The $hash parameter is the encrypted password and the function compares the plain text password when encrypted similarly against the already encrypted password to see if they match.

Parameters

  • string $password: Plaintext user’s password
  • string $hash: Hash of the user’s password to check against.
  • $user_id

Return values

returns:False, if the $password does not match the hashed password

Defined filters

  • check_password
    apply_filters('check_password', $check, $password, $hash, $user_id)
  • check_password
    apply_filters('check_password', $check, $password, $hash, $user_id)

Source code

function wp_check_password($password, $hash, $user_id = '') {

	global $wp_hasher;



	// If the hash is still md5...

	if ( strlen($hash) <= 32 ) {

		$check = ( $hash == md5($password) );

		if ( $check && $user_id ) {

			// Rehash using new hash.

			wp_set_password($password, $user_id);

			$hash = wp_hash_password($password);

		}



		return apply_filters('check_password', $check, $password, $hash, $user_id);

	}



	// If the stored hash is longer than an MD5, presume the

	// new style phpass portable hash.

	if ( empty($wp_hasher) ) {

		require_once( ABSPATH . 'wp-includes/class-phpass.php');

		// By default, use the portable hash from phpass

		$wp_hasher = new PasswordHash(8, TRUE);

	}



	$check = $wp_hasher->CheckPassword($password, $hash);



	return apply_filters('check_password', $check, $password, $hash, $user_id);

}

3469

wp_check_mysql_version

Definition:
function wp_check_mysql_version() {}

Source code

function wp_check_mysql_version() {

	global $wpdb;

	$result = $wpdb->check_database_version();

	if ( is_wp_error( $result ) )

		die( $result->get_error_message() );

}

3467

wp_check_invalid_utf8

Definition:
function wp_check_invalid_utf8( $string, $strip = false ) {}

Checks for invalid UTF8 in a string.

Parameters

  • string $string: The text which is to be checked.
  • boolean $strip: Optional. Whether to attempt to strip out invalid UTF8. Default is false.

Return values

returns:The checked text.

Source code

function wp_check_invalid_utf8( $string, $strip = false ) {

	$string = (string) $string;



	if ( 0 === strlen( $string ) ) {

		return '';

	}



	// Store the site charset as a static to avoid multiple calls to get_option()

	static $is_utf8;

	if ( !isset( $is_utf8 ) ) {

		$is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) );

	}

	if ( !$is_utf8 ) {

		return $string;

	}



	// Check for support for utf8 in the installed PCRE library once and store the result in a static

	static $utf8_pcre;

	if ( !isset( $utf8_pcre ) ) {

		$utf8_pcre = @preg_match( '/^./u', 'a' );

	}

	// We can't demand utf8 in the PCRE installation, so just return the string in those cases

	if ( !$utf8_pcre ) {

		return $string;

	}



	// preg_match fails when it encounters invalid UTF8 in $string

	if ( 1 === @preg_match( '/^./us', $string ) ) {

		return $string;

	}



	// Attempt to strip the bad chars if requested (not recommended)

	if ( $strip && function_exists( 'iconv' ) ) {

		return iconv( 'utf-8', 'utf-8', $string );

	}



	return '';

}

3465

wp_check_for_changed_slugs

Definition:
function wp_check_for_changed_slugs($post_id, $post, $post_before) {}

Checked for changed slugs for published post objects and save the old slug.
The function is used when a post object of any type is updated, by comparing the current and previous post objects.

Parameters

  • int $post_id: Post ID.
  • object $post: The Post Object
  • object $post_before: The Previous Post Object

Return values

returns:Same as $post_id

Source code

function wp_check_for_changed_slugs($post_id, $post, $post_before) {

	// dont bother if it hasnt changed

	if ( $post->post_name == $post_before->post_name )

		return;



	// we're only concerned with published, non-hierarchical objects

	if ( $post->post_status != 'publish' || is_post_type_hierarchical( $post->post_type ) )

		return;



	$old_slugs = (array) get_post_meta($post_id, '_wp_old_slug');



	// if we haven't added this old slug before, add it now

	if ( !empty( $post_before->post_name ) && !in_array($post_before->post_name, $old_slugs) )

		add_post_meta($post_id, '_wp_old_slug', $post_before->post_name);



	// if the new slug was used previously, delete it from the list

	if ( in_array($post->post_name, $old_slugs) )

		delete_post_meta($post_id, '_wp_old_slug', $post->post_name);

}

3463

wp_check_filetype_and_ext

Definition:
function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {}

Attempt to determine the real file type of a file.
If unable to, the file name extension will be used to determine type.

Parameters

  • string $file: Full path to the image.
  • string $filename: The filename of the image (may differ from $file due to $file being in a tmp directory)
  • array $mimes: Optional. Key is the file extension with value as the mime type.

Return values

returns:Values for the extension, MIME, and either a corrected filename or false if original $filename is valid

Defined filters

  • getimagesize_mimes_to_exts
    apply_filters( 'getimagesize_mimes_to_exts', array(

    'image/jpeg' => 'jpg',

    'image/png' => 'png',

    'image/gif' => 'gif',

    'image/bmp' => 'bmp',

    'image/tiff' => 'tif',

    )

  • wp_check_filetype_and_ext
    apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' )

Source code

function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {



	$proper_filename = false;



	// Do basic extension validation and MIME mapping

	$wp_filetype = wp_check_filetype( $filename, $mimes );

	extract( $wp_filetype );



	// We can't do any further validation without a file to work with

	if ( ! file_exists( $file ) )

		return compact( 'ext', 'type', 'proper_filename' );



	// We're able to validate images using GD

	if ( $type && 0 === strpos( $type, 'image/' ) && function_exists('getimagesize') ) {



		// Attempt to figure out what type of image it actually is

		$imgstats = @getimagesize( $file );



		// If getimagesize() knows what kind of image it really is and if the real MIME doesn't match the claimed MIME

		if ( !empty($imgstats['mime']) && $imgstats['mime'] != $type ) {

			// This is a simplified array of MIMEs that getimagesize() can detect and their extensions

			// You shouldn't need to use this filter, but it's here just in case

			$mime_to_ext = apply_filters( 'getimagesize_mimes_to_exts', array(

				'image/jpeg' => 'jpg',

				'image/png'  => 'png',

				'image/gif'  => 'gif',

				'image/bmp'  => 'bmp',

				'image/tiff' => 'tif',

			) );



			// Replace whatever is after the last period in the filename with the correct extension

			if ( ! empty( $mime_to_ext[ $imgstats['mime'] ] ) ) {

				$filename_parts = explode( '.', $filename );

				array_pop( $filename_parts );

				$filename_parts[] = $mime_to_ext[ $imgstats['mime'] ];

				$new_filename = implode( '.', $filename_parts );



				if ( $new_filename != $filename )

					$proper_filename = $new_filename; // Mark that it changed



				// Redefine the extension / MIME

				$wp_filetype = wp_check_filetype( $new_filename, $mimes );

				extract( $wp_filetype );

			}

		}

	}



	// Let plugins try and validate other types of files

	// Should return an array in the style of array( 'ext' => $ext, 'type' => $type, 'proper_filename' => $proper_filename )

	return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes );

}

3461