set_post_thumbnail

Definition:
function set_post_thumbnail( $post, $thumbnail_id ) {}

Sets a post thumbnail.

Parameters

  • int|object $post: Post ID or object where thumbnail should be attached.
  • int $thumbnail_id: Thumbnail to attach.

Return values

returns:True on success, false on failure.

Source code

function set_post_thumbnail( $post, $thumbnail_id ) {

	$post = get_post( $post );

	$thumbnail_id = absint( $thumbnail_id );

	if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) {

		$thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' );

		if ( ! empty( $thumbnail_html ) ) {

			update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id );

			return true;

		}

	}

	return false;

}

10273

set_post_format

Definition:
function set_post_format( $post, $format ) {}

Assign a format to a post

Parameters

  • int|object $post: The post for which to assign a format
  • string $format: A format to assign. Use an empty string or array to remove all formats from the post.

Return values

returns:WP_Error on error. Array of affected term IDs on success.

Source code

function set_post_format( $post, $format ) {

	$post = get_post($post);



	if ( empty($post) )

		return new WP_Error('invalid_post', __('Invalid post'));



	if ( !empty($format) ) {

		$format = sanitize_key($format);

		if ( 'standard' == $format || !in_array( $format, array_keys( get_post_format_slugs() ) ) )

			$format = '';

		else

			$format = 'post-format-' . $format;

	}



	return wp_set_post_terms($post->ID, $format, 'post_format');

}

10271

self_admin_url

Definition:
function self_admin_url($path = '', $scheme = 'admin') {}

Retrieve the url to the admin area for either the current blog or the network depending on context.

Parameters

  • string $path: Optional path relative to the admin url.
  • string $scheme: The scheme to use. Default is ‘admin’, which obeys force_ssl_admin() and is_ssl(). ‘http’ or ‘https’ can be passed to force those schemes.

Return values

returns:Admin url link with optional path appended.

Source code

function self_admin_url($path = '', $scheme = 'admin') {

	if ( is_network_admin() )

		return network_admin_url($path, $scheme);

	elseif ( is_user_admin() )

		return user_admin_url($path, $scheme);

	else

		return admin_url($path, $scheme);

}

10259

sanitize_title_for_query

Definition:
function sanitize_title_for_query($title) {}

Parameters

  • $title

Source code

function sanitize_title_for_query($title) {

	return sanitize_title($title, '', 'query');

}

10241

require_wp_db

Definition:
function require_wp_db() {}

Load the correct database class file.
This function is used to load the database class file either at runtime or by wp-admin/setup-config.php. We must globalize $wpdb to ensure that it is defined globally by the inline code in wp-db.php.

Source code

function require_wp_db() {

	global $wpdb;



	require_once( ABSPATH . WPINC . '/wp-db.php' );

	if ( file_exists( WP_CONTENT_DIR . '/db.php' ) )

		require_once( WP_CONTENT_DIR . '/db.php' );



	if ( isset( $wpdb ) )

		return;



	$wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );

}

10212