write_post

Definition:
function write_post() {}

Calls wp_write_post() and handles the errors.

Source code

function write_post() {

	$result = wp_write_post();

	if ( is_wp_error( $result ) )

		wp_die( $result->get_error_message() );

	else

		return $result;

}

4279

wp_write_post

Definition:
function wp_write_post() {}

Creates a new post from the "Write Post" form using $_POST information.

Source code

function wp_write_post() {

	global $user_ID;





	if ( isset($_POST['post_type']) )

		$ptype = get_post_type_object($_POST['post_type']);

	else

		$ptype = get_post_type_object('post');



	if ( !current_user_can( $ptype->cap->edit_posts ) ) {

		if ( 'page' == $ptype->name )

			return new WP_Error( 'edit_pages', __( 'You are not allowed to create pages on this site.' ) );

		else

			return new WP_Error( 'edit_posts', __( 'You are not allowed to create posts or drafts on this site.' ) );

	}



	$_POST['post_mime_type'] = '';



	// Clear out any data in internal vars.

	unset( $_POST['filter'] );



	// Check for autosave collisions

	// Does this need to be updated? ~ Mark

	$temp_id = false;

	if ( isset($_POST['temp_ID']) ) {

		$temp_id = (int) $_POST['temp_ID'];

		if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )

			$draft_ids = array();

		foreach ( $draft_ids as $temp => $real )

			if ( time() + $temp > 86400 ) // 1 day: $temp is equal to -1 * time( then )

				unset($draft_ids[$temp]);



		if ( isset($draft_ids[$temp_id]) ) { // Edit, don't write

			$_POST['post_ID'] = $draft_ids[$temp_id];

			unset($_POST['temp_ID']);

			update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );

			return edit_post();

		}

	}



	// Edit don't write if we have a post id.

	if ( isset( $_POST['ID'] ) ) {

		$_POST['post_ID'] = $_POST['ID'];

		unset ( $_POST['ID'] );

	}

	if ( isset( $_POST['post_ID'] ) ) {

		return edit_post();

	}



	$translated = _wp_translate_postdata( false );

	if ( is_wp_error($translated) )

		return $translated;



	if ( isset($_POST['visibility']) ) {

		switch ( $_POST['visibility'] ) {

			case 'public' :

				$_POST['post_password'] = '';

				break;

			case 'password' :

				unset( $_POST['sticky'] );

				break;

			case 'private' :

				$_POST['post_status'] = 'private';

				$_POST['post_password'] = '';

				unset( $_POST['sticky'] );

				break;

		}

	}



	// Create the post.

	$post_ID = wp_insert_post( $_POST );

	if ( is_wp_error( $post_ID ) )

		return $post_ID;



	if ( empty($post_ID) )

		return 0;



	add_meta( $post_ID );



	add_post_meta( $post_ID, '_edit_last', $GLOBALS['current_user']->ID );



	// Reunite any orphaned attachments with their parent

	// Does this need to be udpated? ~ Mark

	if ( !$draft_ids = get_user_option( 'autosave_draft_ids' ) )

		$draft_ids = array();

	if ( $draft_temp_id = (int) array_search( $post_ID, $draft_ids ) )

		_relocate_children( $draft_temp_id, $post_ID );

	if ( $temp_id && $temp_id != $draft_temp_id )

		_relocate_children( $temp_id, $post_ID );



	// Update autosave collision detection

	if ( $temp_id ) {

		$draft_ids[$temp_id] = $post_ID;

		update_user_option( $user_ID, 'autosave_draft_ids', $draft_ids );

	}



	// Now that we have an ID we can fix any attachment anchor hrefs

	_fix_attachment_links( $post_ID );



	wp_set_post_lock( $post_ID, $GLOBALS['current_user']->ID );



	return $post_ID;

}

4277

wp_widget_rss_process

Definition:
function wp_widget_rss_process( $widget_rss, $check_feed = true ) {}

Process RSS feed widget data and optionally retrieve feed items.
The feed widget can not have more than 20 items or it will reset back to the default, which is 10.

Parameters

  • array $widget_rss: RSS widget feed data. Expects unescaped data.
  • bool $check_feed: Optional, default is true. Whether to check feed for errors.

Source code

function wp_widget_rss_process( $widget_rss, $check_feed = true ) {

	$items = (int) $widget_rss['items'];

	if ( $items < 1 || 20 < $items )

		$items = 10;

	$url           = esc_url_raw(strip_tags( $widget_rss['url'] ));

	$title         = trim(strip_tags( $widget_rss['title'] ));

	$show_summary  = isset($widget_rss['show_summary']) ? (int) $widget_rss['show_summary'] : 0;

	$show_author   = isset($widget_rss['show_author']) ? (int) $widget_rss['show_author'] :0;

	$show_date     = isset($widget_rss['show_date']) ? (int) $widget_rss['show_date'] : 0;



	if ( $check_feed ) {

		$rss = fetch_feed($url);

		$error = false;

		$link = '';

		if ( is_wp_error($rss) ) {

			$error = $rss->get_error_message();

		} else {

			$link = esc_url(strip_tags($rss->get_permalink()));

			while ( stristr($link, 'http') != $link )

				$link = substr($link, 1);



			$rss->__destruct();

			unset($rss);

		}

	}



	return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );

}

4275

wp_widget_rss_output

Definition:
function wp_widget_rss_output( $rss, $args = array() {}

Display the RSS entries in a list.

Parameters

  • string|array|object $rss: RSS url.
  • array $args: Widget arguments.

Source code

function wp_widget_rss_output( $rss, $args = array() ) {

	if ( is_string( $rss ) ) {

		$rss = fetch_feed($rss);

	} elseif ( is_array($rss) && isset($rss['url']) ) {

		$args = $rss;

		$rss = fetch_feed($rss['url']);

	} elseif ( !is_object($rss) ) {

		return;

	}



	if ( is_wp_error($rss) ) {

		if ( is_admin() || current_user_can('manage_options') )

			echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';

		return;

	}



	$default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0 );

	$args = wp_parse_args( $args, $default_args );

	extract( $args, EXTR_SKIP );



	$items = (int) $items;

	if ( $items < 1 || 20 < $items )

		$items = 10;

	$show_summary  = (int) $show_summary;

	$show_author   = (int) $show_author;

	$show_date     = (int) $show_date;



	if ( !$rss->get_item_quantity() ) {

		echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>';

		$rss->__destruct();

		unset($rss);

		return;

	}



	echo '<ul>';

	foreach ( $rss->get_items(0, $items) as $item ) {

		$link = $item->get_link();

		while ( stristr($link, 'http') != $link )

			$link = substr($link, 1);

		$link = esc_url(strip_tags($link));

		$title = esc_attr(strip_tags($item->get_title()));

		if ( empty($title) )

			$title = __('Untitled');



		$desc = str_replace( array("\n", "\r"), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) );

		$desc = wp_html_excerpt( $desc, 360 );



		// Append ellipsis. Change existing [...] to [&hellip;].

		if ( '[...]' == substr( $desc, -5 ) )

			$desc = substr( $desc, 0, -5 ) . '[&hellip;]';

		elseif ( '[&hellip;]' != substr( $desc, -10 ) )

			$desc .= ' [&hellip;]';



		$desc = esc_html( $desc );



		if ( $show_summary ) {

			$summary = "<div class='rssSummary'>$desc</div>";

		} else {

			$summary = '';

		}



		$date = '';

		if ( $show_date ) {

			$date = $item->get_date( 'U' );



			if ( $date ) {

				$date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>';

			}

		}



		$author = '';

		if ( $show_author ) {

			$author = $item->get_author();

			if ( is_object($author) ) {

				$author = $author->get_name();

				$author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>';

			}

		}



		if ( $link == '' ) {

			echo "<li>$title{$date}{$summary}{$author}</li>";

4273

wp_widget_rss_form

Definition:
function wp_widget_rss_form( $args, $inputs = null ) {}

Display RSS widget options form.
The options for what fields are displayed for the RSS form are all booleans and are as follows: ‘url’, ‘title’, ‘items’, ‘show_summary’, ‘show_author’, ‘show_date’.

Parameters

  • array|string $args: Values for input fields.
  • array $inputs: Override default display options.

Source code

function wp_widget_rss_form( $args, $inputs = null ) {



	$default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );

	$inputs = wp_parse_args( $inputs, $default_inputs );

	extract( $args );

	extract( $inputs, EXTR_SKIP);



	$number = esc_attr( $number );

	$title  = esc_attr( $title );

	$url    = esc_url( $url );

	$items  = (int) $items;

	if ( $items < 1 || 20 < $items )

		$items  = 10;

	$show_summary   = (int) $show_summary;

	$show_author    = (int) $show_author;

	$show_date      = (int) $show_date;



	if ( !empty($error) )

		echo '<p class="widget-error"><strong>' . sprintf( __('RSS Error: %s'), $error) . '</strong></p>';



	if ( $inputs['url'] ) :

?>

	<p><label for="rss-url-<?php echo $number; ?>"><?php _e('Enter the RSS feed URL here:'); ?></label>

	<input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" /></p>

<?php endif; if ( $inputs['title'] ) : ?>

	<p><label for="rss-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?></label>

	<input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" /></p>

<?php endif; if ( $inputs['items'] ) : ?>

	<p><label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?></label>

	<select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]">

<?php

		for ( $i = 1; $i <= 20; ++$i )

			echo "<option value='$i' " . ( $items == $i ? "selected='selected'" : '' ) . ">$i</option>";

?>

	</select></p>

<?php endif; if ( $inputs['show_summary'] ) : ?>

	<p><input id="rss-show-summary-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_summary]" type="checkbox" value="1" <?php if ( $show_summary ) echo 'checked="checked"'; ?>/>

	<label for="rss-show-summary-<?php echo $number; ?>"><?php _e('Display item content?'); ?></label></p>

<?php endif; if ( $inputs['show_author'] ) : ?>

	<p><input id="rss-show-author-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_author]" type="checkbox" value="1" <?php if ( $show_author ) echo 'checked="checked"'; ?>/>

	<label for="rss-show-author-<?php echo $number; ?>"><?php _e('Display item author if available?'); ?></label></p>

<?php endif; if ( $inputs['show_date'] ) : ?>

	<p><input id="rss-show-date-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_date]" type="checkbox" value="1" <?php if ( $show_date ) echo 'checked="checked"'; ?>/>

	<label for="rss-show-date-<?php echo $number; ?>"><?php _e('Display item date?'); ?></label></p>

<?php

	endif;

	foreach ( array_keys($default_inputs) as $input ) :

		if ( 'hidden' === $inputs[$input] ) :

			$id = str_replace( '_', '-', $input );

?>

	<input type="hidden" id="rss-<?php echo $id; ?>-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][<?php echo $input; ?>]" value="<?php echo $$input; ?>" />

<?php

		endif;

	endforeach;

}

4271