wp_get_shortlink

Definition:
function wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) {}

Return a shortlink for a post, page, attachment, or blog.
This function exists to provide a shortlink tag that all themes and plugins can target. A plugin must hook in to provide the actual shortlinks. Default shortlink support is limited to providing ?p= style links for posts. Plugins can short-circuit this function via the pre_get_shortlink filter or filter the output via the get_shortlink filter.

Parameters

  • int $id: A post or blog id. Default is 0, which means the current post or blog.
  • string $context: Whether the id is a ‘blog’ id, ‘post’ id, or ‘media’ id. If ‘post’, the post_type of the post is consulted. If ‘query’, the current query is consulted to determine the id and context. Default is ‘post’.
  • bool $allow_slugs: Whether to allow post slugs in the shortlink. It is up to the plugin how and whether to honor this.

Return values

returns:A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks are not enabled.

Defined filters

  • pre_get_shortlink
    apply_filters('pre_get_shortlink', false, $id, $context, $allow_slugs)
  • get_shortlink
    apply_filters('get_shortlink', $shortlink, $id, $context, $allow_slugs)

Source code

function wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) {

	// Allow plugins to short-circuit this function.

	$shortlink = apply_filters('pre_get_shortlink', false, $id, $context, $allow_slugs);

	if ( false !== $shortlink )

		return $shortlink;



	global $wp_query;

	$post_id = 0;

	if ( 'query' == $context && is_single() ) {

		$post_id = $wp_query->get_queried_object_id();

	} elseif ( 'post' == $context ) {

		$post = get_post($id);

		$post_id = $post->ID;

	}



	$shortlink = '';



	// Return p= link for posts.

	if ( !empty($post_id) && '' != get_option('permalink_structure') ) {

		$post = get_post($post_id);

		if ( isset($post->post_type) && 'post' == $post->post_type )

			$shortlink = home_url('?p=' . $post->ID);

	}



	return apply_filters('get_shortlink', $shortlink, $id, $context, $allow_slugs);

}

3749

wp_get_schedules

Definition:
function wp_get_schedules() {}

Retrieve supported and filtered Cron recurrences.
The supported recurrences are ‘hourly’ and ‘daily’. A plugin may add more by hooking into the ‘cron_schedules’ filter. The filter accepts an array of arrays. The outer array has a key that is the name of the schedule or for example ‘weekly’. The value is an array with two keys, one is ‘interval’ and the other is ‘display’.

Defined filters

  • cron_schedules
    apply_filters( 'cron_schedules', array()

Source code

function wp_get_schedules() {

	$schedules = array(

		'hourly' => array( 'interval' => 3600, 'display' => __('Once Hourly') ),

		'twicedaily' => array( 'interval' => 43200, 'display' => __('Twice Daily') ),

		'daily' => array( 'interval' => 86400, 'display' => __('Once Daily') ),

	);

	return array_merge( apply_filters( 'cron_schedules', array() ), $schedules );

}

3747

wp_get_schedule

Definition:
function wp_get_schedule($hook, $args = array() {}

Retrieve Cron schedule for hook with arguments.

Parameters

  • string $hook: Action hook to execute when cron is run.
  • array $args: Optional. Arguments to pass to the hook’s callback function.

Return values

returns:False, if no schedule. Schedule on success.

Source code

function wp_get_schedule($hook, $args = array()) {

	$crons = _get_cron_array();

	$key = md5(serialize($args));

	if ( empty($crons) )

		return false;

	foreach ( $crons as $timestamp => $cron ) {

		if ( isset( $cron[$hook][$key] ) )

			return $cron[$hook][$key]['schedule'];

	}

	return false;

}

3745

wp_get_referer

Definition:
function wp_get_referer() {}

Retrieve referer from ‘_wp_http_referer’ or HTTP referer. If it’s the same as the current request URL, will return false.

Return values

returns:False on failure. Referer URL on success.

Source code

function wp_get_referer() {

	$ref = false;

	if ( ! empty( $_REQUEST['_wp_http_referer'] ) )

		$ref = $_REQUEST['_wp_http_referer'];

	else if ( ! empty( $_SERVER['HTTP_REFERER'] ) )

		$ref = $_SERVER['HTTP_REFERER'];



	if ( $ref && $ref !== $_SERVER['REQUEST_URI'] )

		return $ref;

	return false;

}

3743

wp_get_recent_posts

Definition:
function wp_get_recent_posts( $args = array() {}

Retrieve number of recent posts.

Parameters

  • string $deprecated: Deprecated.
  • array $args: Optional. Overrides defaults.
  • string $output: Optional.

Source code

function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) {



	if ( is_numeric( $args ) ) {

		_deprecated_argument( __FUNCTION__, '3.1', __( 'Passing an integer number of posts is deprecated. Pass an array of arguments instead.' ) );

		$args = array( 'numberposts' => absint( $args ) );

	}



	// Set default arguments

	$defaults = array(

		'numberposts' => 10, 'offset' => 0,

		'category' => 0, 'orderby' => 'post_date',

		'order' => 'DESC', 'include' => '',

		'exclude' => '', 'meta_key' => '',

		'meta_value' =>'', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private',

		'suppress_filters' => true

	);



	$r = wp_parse_args( $args, $defaults );



	$results = get_posts( $r );



	// Backward compatibility. Prior to 3.1 expected posts to be returned in array

	if ( ARRAY_A == $output ){

		foreach( $results as $key => $result ) {

			$results[$key] = get_object_vars( $result );

		}

		return $results ? $results : array();

	}



	return $results ? $results : false;



}

3741