prep_atom_text_construct() WordPress Function

This function is used to prepare the text for construction of an atom. It is used to convert special characters to HTML entities and to make sure that line breaks are converted to HTML breaks.

prep_atom_text_construct( string $data ) #

Determine the type of a string of data with the data formatted.


Description

Tell whether the type is text, HTML, or XHTML, per RFC 4287 section 3.1.

In the case of WordPress, text is defined as containing no markup, XHTML is defined as "well formed", and HTML as tag soup (i.e., the rest).

Container div tags are added to XHTML values, per section 3.1.1.3.


Top ↑

Parameters

$data

(string)(Required)Input string


Top ↑

Return

(array) array(type, value)


Top ↑

Source

File: wp-includes/feed.php

function prep_atom_text_construct( $data ) {
	if ( strpos( $data, '<' ) === false && strpos( $data, '&' ) === false ) {
		return array( 'text', $data );
	}

	if ( ! function_exists( 'xml_parser_create' ) ) {
		trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );

		return array( 'html', "<![CDATA[$data]]>" );
	}

	$parser = xml_parser_create();
	xml_parse( $parser, '<div>' . $data . '</div>', true );
	$code = xml_get_error_code( $parser );
	xml_parser_free( $parser );
	unset( $parser );

	if ( ! $code ) {
		if ( strpos( $data, '<' ) === false ) {
			return array( 'text', $data );
		} else {
			$data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>";
			return array( 'xhtml', $data );
		}
	}

	if ( strpos( $data, ']]>' ) === false ) {
		return array( 'html', "<![CDATA[$data]]>" );
	} else {
		return array( 'html', htmlspecialchars( $data ) );
	}
}


Top ↑

Changelog

Changelog
VersionDescription
2.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.