user_can_create_draft

Definition:
function user_can_create_draft($user_id, $blog_id = 1, $category_id = 'None') {}

Whether user can create a post.

Parameters

  • int $user_id
  • int $blog_id: Not Used
  • int $category_id: Not Used

Source code

function user_can_create_draft($user_id, $blog_id = 1, $category_id = 'None') {

	_deprecated_function( __FUNCTION__, '2.0', 'current_user_can()' );



	$author_data = get_userdata($user_id);

	return ($author_data->user_level >= 1);

}

3279

user_can_access_admin_page

Definition:
function user_can_access_admin_page() {}

Source code

function user_can_access_admin_page() {

	global $pagenow;

	global $menu;

	global $submenu;

	global $_wp_menu_nopriv;

	global $_wp_submenu_nopriv;

	global $plugin_page;

	global $_registered_pages;



	$parent = get_admin_page_parent();



	if ( !isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$parent][$pagenow] ) )

		return false;



	if ( isset( $plugin_page ) ) {

		if ( isset( $_wp_submenu_nopriv[$parent][$plugin_page] ) )

			return false;



		$hookname = get_plugin_page_hookname($plugin_page, $parent);



		if ( !isset($_registered_pages[$hookname]) )

			return false;

	}



	if ( empty( $parent) ) {

		if ( isset( $_wp_menu_nopriv[$pagenow] ) )

			return false;

		if ( isset( $_wp_submenu_nopriv[$pagenow][$pagenow] ) )

			return false;

		if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$pagenow][$plugin_page] ) )

			return false;

		if ( isset( $plugin_page ) && isset( $_wp_menu_nopriv[$plugin_page] ) )

			return false;

		foreach (array_keys( $_wp_submenu_nopriv ) as $key ) {

			if ( isset( $_wp_submenu_nopriv[$key][$pagenow] ) )

				return false;

			if ( isset( $plugin_page ) && isset( $_wp_submenu_nopriv[$key][$plugin_page] ) )

			return false;

		}

		return true;

	}



	if ( isset( $plugin_page ) && ( $plugin_page == $parent ) && isset( $_wp_menu_nopriv[$plugin_page] ) )

		return false;



	if ( isset( $submenu[$parent] ) ) {

		foreach ( $submenu[$parent] as $submenu_array ) {

			if ( isset( $plugin_page ) && ( $submenu_array[2] == $plugin_page ) ) {

				if ( current_user_can( $submenu_array[1] ))

					return true;

				else

					return false;

			} else if ( $submenu_array[2] == $pagenow ) {

				if ( current_user_can( $submenu_array[1] ))

					return true;

				else

					return false;

			}

		}

	}



	foreach ( $menu as $menu_array ) {

		if ( $menu_array[2] == $parent) {

			if ( current_user_can( $menu_array[1] ))

				return true;

			else

				return false;

		}

	}



	return true;

}

3277

username_exists

Definition:
function username_exists( $username ) {}

Checks whether the given username exists.

Parameters

  • string $username: Username.

Return values

returns:The user’s ID on success, and null on failure.

Source code

function username_exists( $username ) {

	if ( $user = get_userdatabylogin( $username ) ) {

		return $user->ID;

	} else {

		return null;

	}

}

3273

url_to_postid

Definition:
function url_to_postid($url) {}

Examine a url and try to determine the post ID it represents.
Checks are supposedly from the hosted site blog.

Parameters

  • string $url: Permalink to check.

Return values

returns:Post ID, or 0 on failure.

Defined filters

  • url_to_postid
    apply_filters('url_to_postid', $url)

Source code

function url_to_postid($url) {

	global $wp_rewrite;



	$url = apply_filters('url_to_postid', $url);



	// First, check to see if there is a 'p=N' or 'page_id=N' to match against

	if ( preg_match('#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values) )	{

		$id = absint($values[2]);

		if ( $id )

			return $id;

	}



	// Check to see if we are using rewrite rules

	$rewrite = $wp_rewrite->wp_rewrite_rules();



	// Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options

	if ( empty($rewrite) )

		return 0;



	// Get rid of the #anchor

	$url_split = explode('#', $url);

	$url = $url_split[0];



	// Get rid of URL ?query=string

	$url_split = explode('?', $url);

	$url = $url_split[0];



	// Add 'www.' if it is absent and should be there

	if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') )

		$url = str_replace('://', '://www.', $url);



	// Strip 'www.' if it is present and shouldn't be

	if ( false === strpos(home_url(), '://www.') )

		$url = str_replace('://www.', '://', $url);



	// Strip 'index.php/' if we're not using path info permalinks

	if ( !$wp_rewrite->using_index_permalinks() )

		$url = str_replace('index.php/', '', $url);



	if ( false !== strpos($url, home_url()) ) {

		// Chop off http://domain.com

		$url = str_replace(home_url(), '', $url);

	} else {

		// Chop off /path/to/blog

		$home_path = parse_url(home_url());

		$home_path = isset( $home_path['path'] ) ? $home_path['path'] : '' ;

		$url = str_replace($home_path, '', $url);

	}



	// Trim leading and lagging slashes

	$url = trim($url, '/');



	$request = $url;



	// Look for matches.

	$request_match = $request;

	foreach ( (array)$rewrite as $match => $query) {



		// If the requesting file is the anchor of the match, prepend it

		// to the path info.

		if ( !empty($url) && ($url != $request) && (strpos($match, $url) === 0) )

			$request_match = $url . '/' . $request;



		if ( preg_match("!^$match!", $request_match, $matches) ) {



			if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {

				// this is a verbose page match, lets check to be sure about it

				if ( ! get_page_by_path( $matches[ $varmatch[1] ] ) )

					continue;

			}



			// Got a match.

			// Trim the query of everything up to the '?'.

			$query = preg_replace("!^.+\?!", '', $query);



			// Substitute the substring matches into the query.

			$query = addslashes(WP_MatchesMapRegex::apply($query, $matches));



			// Filter out non-public query vars

			global $wp;

			parse_str($query, $query_vars);

			$query = array();

			foreach ( (array) $query_vars as $key => $value ) {

				if ( in_array($key, $wp->public_query_vars) )

					$query[$key] = $value;

			}



			// Do the query

			$query = new WP_Query($query);

			if ( !empty($query->posts) && $query->is_singular )

				return $query->post->ID;

			else

				return 0;

		}

	}

	return 0;

}

3271