Advertisements

wp_post_mime_type_where

Definition:
function wp_post_mime_type_where($post_mime_types, $table_alias = '') {}

Convert MIME types into SQL.

Parameters

  • string|array $post_mime_types: List of mime types or comma separated string of mime types.
  • string $table_alias: Optional. Specify a table alias, if needed.

Return values

returns:The SQL AND clause for mime searching.

Source code

function wp_post_mime_type_where($post_mime_types, $table_alias = '') {

	$where = '';

	$wildcards = array('', '%', '%/%');

	if ( is_string($post_mime_types) )

		$post_mime_types = array_map('trim', explode(',', $post_mime_types));

	foreach ( (array) $post_mime_types as $mime_type ) {

		$mime_type = preg_replace('/\s/', '', $mime_type);

		$slashpos = strpos($mime_type, '/');

		if ( false !== $slashpos ) {

			$mime_group = preg_replace('/[^-*.a-zA-Z0-9]/', '', substr($mime_type, 0, $slashpos));

			$mime_subgroup = preg_replace('/[^-*.+a-zA-Z0-9]/', '', substr($mime_type, $slashpos + 1));

			if ( empty($mime_subgroup) )

				$mime_subgroup = '*';

			else

				$mime_subgroup = str_replace('/', '', $mime_subgroup);

			$mime_pattern = "$mime_group/$mime_subgroup";

		} else {

			$mime_pattern = preg_replace('/[^-*.a-zA-Z0-9]/', '', $mime_type);

			if ( false === strpos($mime_pattern, '*') )

				$mime_pattern .= '/*';

		}



		$mime_pattern = preg_replace('/\*+/', '%', $mime_pattern);



		if ( in_array( $mime_type, $wildcards ) )

			return '';



		if ( false !== strpos($mime_pattern, '%') )

			$wheres[] = empty($table_alias) ? "post_mime_type LIKE '$mime_pattern'" : "$table_alias.post_mime_type LIKE '$mime_pattern'";

		else

			$wheres[] = empty($table_alias) ? "post_mime_type = '$mime_pattern'" : "$table_alias.post_mime_type = '$mime_pattern'";

	}

	if ( !empty($wheres) )

		$where = ' AND (' . join(' OR ', $wheres) . ') ';

	return $where;

}

3989

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: