_wp_translate_postdata

Definition:
function _wp_translate_postdata( $update = false, $post_data = null ) {}

Rename $_POST data from form names to DB post columns.
Manipulates $_POST directly.

Parameters

  • bool $update: Are we updating a pre-existing post?
  • array $post_data: Array of post data. Defaults to the contents of $_POST.

Return values

returns:WP_Error on failure, true on success.

Source code

function _wp_translate_postdata( $update = false, $post_data = null ) {



	if ( empty($post_data) )

		$post_data = &$_POST;



	if ( $update )

		$post_data['ID'] = (int) $post_data['post_ID'];



	if ( isset( $post_data['content'] ) )

		$post_data['post_content'] = $post_data['content'];



	if ( isset( $post_data['excerpt'] ) )

		$post_data['post_excerpt'] = $post_data['excerpt'];



	if ( isset( $post_data['parent_id'] ) )

		$post_data['post_parent'] = (int) $post_data['parent_id'];



	if ( isset($post_data['trackback_url']) )

		$post_data['to_ping'] = $post_data['trackback_url'];



	if ( !isset($post_data['user_ID']) )

		$post_data['user_ID'] = $GLOBALS['user_ID'];



	if (!empty ( $post_data['post_author_override'] ) ) {

		$post_data['post_author'] = (int) $post_data['post_author_override'];

	} else {

		if (!empty ( $post_data['post_author'] ) ) {

			$post_data['post_author'] = (int) $post_data['post_author'];

		} else {

			$post_data['post_author'] = (int) $post_data['user_ID'];

		}

	}



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

	if ( isset($post_data['user_ID']) && ($post_data['post_author'] != $post_data['user_ID']) ) {

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

			if ( 'page' == $post_data['post_type'] ) {

				return new WP_Error( 'edit_others_pages', $update ?

					__( 'You are not allowed to edit pages as this user.' ) :

					__( 'You are not allowed to create pages as this user.' )

				);

			} else {

				return new WP_Error( 'edit_others_posts', $update ?

					__( 'You are not allowed to edit posts as this user.' ) :

					__( 'You are not allowed to post as this user.' )

				);

			}

		}

	}



	// What to do based on which button they pressed

	if ( isset($post_data['saveasdraft']) && '' != $post_data['saveasdraft'] )

		$post_data['post_status'] = 'draft';

	if ( isset($post_data['saveasprivate']) && '' != $post_data['saveasprivate'] )

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

	if ( isset($post_data['publish']) && ( '' != $post_data['publish'] ) && ( !isset($post_data['post_status']) || $post_data['post_status'] != 'private' ) )

		$post_data['post_status'] = 'publish';

	if ( isset($post_data['advanced']) && '' != $post_data['advanced'] )

		$post_data['post_status'] = 'draft';

	if ( isset($post_data['pending']) && '' != $post_data['pending'] )

		$post_data['post_status'] = 'pending';



	if ( isset( $post_data['ID'] ) )

		$post_id = $post_data['ID'];

	else

		$post_id = false;

	$previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false;



	// Posts 'submitted for approval' present are submitted to $_POST the same as if they were being published.

	// Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.

	if ( isset($post_data['post_status']) && ('publish' == $post_data['post_status'] && !current_user_can( $ptype->cap->publish_posts )) )

		if ( $previous_status != 'publish' || !current_user_can( 'edit_post', $post_id ) )

			$post_data['post_status'] = 'pending';



	if ( ! isset($post_data['post_status']) )

		$post_data['post_status'] = $previous_status;



	if (!isset( $post_data['comment_status'] ))

		$post_data['comment_status'] = 'closed';



	if (!isset( $post_data['ping_status'] ))

		$post_data['ping_status'] = 'closed';



	foreach ( array('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {

		if ( !empty( $post_data['hidden_' . $timeunit] ) && $post_data['hidden_' . $timeunit] != $post_data[$timeunit] ) {

			$post_data['edit_date'] = '1';

			break;

		}

	}



	if ( !empty( $post_data['edit_date'] ) ) {

		$aa = $post_data['aa'];

		$mm = $post_data['mm'];

		$jj = $post_data['jj'];

		$hh = $post_data['hh'];

		$mn = $post_data['mn'];

		$ss = $post_data['ss'];

		$aa = ($aa <= 0 ) ? date('Y') : $aa;

		$mm = ($mm <= 0 ) ? date('n') : $mm;

		$jj = ($jj > 31 ) ? 31 : $jj;

		$jj = ($jj <= 0 ) ? date('j') : $jj;

		$hh = ($hh > 23 ) ? $hh -24 : $hh;

		$mn = ($mn > 59 ) ? $mn -60 : $mn;

		$ss = ($ss > 59 ) ? $ss -60 : $ss;

		$post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );

		$post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );

	}



	return $post_data;

}

4419

_wp_timezone_choice_usort_callback

Definition:
function _wp_timezone_choice_usort_callback( $a, $b ) {}

Parameters

  • unknown_type $a
  • unknown_type $b

Source code

function _wp_timezone_choice_usort_callback( $a, $b ) {

	// Don't use translated versions of Etc

	if ( 'Etc' === $a['continent'] && 'Etc' === $b['continent'] ) {

		// Make the order of these more like the old dropdown

		if ( 'GMT+' === substr( $a['city'], 0, 4 ) && 'GMT+' === substr( $b['city'], 0, 4 ) ) {

			return -1 * ( strnatcasecmp( $a['city'], $b['city'] ) );

		}

		if ( 'UTC' === $a['city'] ) {

			if ( 'GMT+' === substr( $b['city'], 0, 4 ) ) {

				return 1;

			}

			return -1;

		}

		if ( 'UTC' === $b['city'] ) {

			if ( 'GMT+' === substr( $a['city'], 0, 4 ) ) {

				return -1;

			}

			return 1;

		}

		return strnatcasecmp( $a['city'], $b['city'] );

	}

	if ( $a['t_continent'] == $b['t_continent'] ) {

		if ( $a['t_city'] == $b['t_city'] ) {

			return strnatcasecmp( $a['t_subcity'], $b['t_subcity'] );

		}

		return strnatcasecmp( $a['t_city'], $b['t_city'] );

	} else {

		// Force Etc to the bottom of the list

		if ( 'Etc' === $a['continent'] ) {

			return 1;

		}

		if ( 'Etc' === $b['continent'] ) {

			return -1;

		}

		return strnatcasecmp( $a['t_continent'], $b['t_continent'] );

	}

}

4417

_wp_specialchars

Definition:
function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {}

Converts a number of special characters into their HTML entities.
Specifically deals with: &, <, >, ", and ‘.

Parameters

  • string $string: The text which is to be encoded.
  • mixed $quote_style: Optional. Converts double quotes if set to ENT_COMPAT, both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. Also compatible with old values; converting single quotes if set to ‘single’, double if set to ‘double’ or both if otherwise set. Default is ENT_NOQUOTES.
  • string $charset: Optional. The character encoding of the string. Default is false.
  • boolean $double_encode: Optional. Whether to encode existing html entities. Default is false.

Return values

returns:The encoded text with HTML entities.

Source code

function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {

	$string = (string) $string;



	if ( 0 === strlen( $string ) )

		return '';



	// Don't bother if there are no specialchars - saves some processing

	if ( ! preg_match( '/[&<>"\']/', $string ) )

		return $string;



	// Account for the previous behaviour of the function when the $quote_style is not an accepted value

	if ( empty( $quote_style ) )

		$quote_style = ENT_NOQUOTES;

	elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) )

		$quote_style = ENT_QUOTES;



	// Store the site charset as a static to avoid multiple calls to wp_load_alloptions()

	if ( ! $charset ) {

		static $_charset;

		if ( ! isset( $_charset ) ) {

			$alloptions = wp_load_alloptions();

			$_charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : '';

		}

		$charset = $_charset;

	}



	if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) )

		$charset = 'UTF-8';



	$_quote_style = $quote_style;



	if ( $quote_style === 'double' ) {

		$quote_style = ENT_COMPAT;

		$_quote_style = ENT_COMPAT;

	} elseif ( $quote_style === 'single' ) {

		$quote_style = ENT_NOQUOTES;

	}



	// Handle double encoding ourselves

	if ( $double_encode ) {

		$string = @htmlspecialchars( $string, $quote_style, $charset );

	} else {

		// Decode &amp; into &

		$string = wp_specialchars_decode( $string, $_quote_style );



		// Guarantee every &entity; is valid or re-encode the &

		$string = wp_kses_normalize_entities( $string );



		// Now re-encode everything except &entity;

		$string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE );



		for ( $i = 0; $i < count( $string ); $i += 2 )

			$string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset );



		$string = implode( '', $string );

	}



	// Backwards compatibility

	if ( 'single' === $_quote_style )

		$string = str_replace( "'", ''', $string );



	return $string;

}

4415

_wp_relative_upload_path

Definition:
function _wp_relative_upload_path( $path ) {}

Return relative path to an uploaded file.
The path is relative to the current upload dir.

Parameters

  • string $path: Full path to the file

Return values

returns:relative path on success, unchanged path on failure.

Defined filters

  • _wp_relative_upload_path
    apply_filters( '_wp_relative_upload_path', $new_path, $path )

Source code

function _wp_relative_upload_path( $path ) {

	$new_path = $path;



	if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) {

		if ( 0 === strpos($new_path, $uploads['basedir']) ) {

				$new_path = str_replace($uploads['basedir'], '', $new_path);

				$new_path = ltrim($new_path, '/');

		}

	}



	return apply_filters( '_wp_relative_upload_path', $new_path, $path );

}

4413

_wp_put_post_revision

Definition:
function _wp_put_post_revision( $post = null, $autosave = false ) {}

Inserts post data into the posts table as a post revision.

Parameters

  • int|object|array $post: Post ID, post object OR post array.
  • bool $autosave: Optional. Is the revision an autosave?

Return values

returns:Null or 0 if error, new revision ID if success.

Defined actions

  • _wp_put_post_revision
    do_action( '_wp_put_post_revision', $revision_id );

Source code

function _wp_put_post_revision( $post = null, $autosave = false ) {

	if ( is_object($post) )

		$post = get_object_vars( $post );

	elseif ( !is_array($post) )

		$post = get_post($post, ARRAY_A);

	if ( !$post || empty($post['ID']) )

		return;



	if ( isset($post['post_type']) && 'revision' == $post['post_type'] )

		return new WP_Error( 'post_type', __( 'Cannot create a revision of a revision' ) );



	$post = _wp_post_revision_fields( $post, $autosave );

	$post = add_magic_quotes($post); //since data is from db



	$revision_id = wp_insert_post( $post );

	if ( is_wp_error($revision_id) )

		return $revision_id;



	if ( $revision_id )

		do_action( '_wp_put_post_revision', $revision_id );

	return $revision_id;

}

4411