prep_atom_text_construct

The timeline below displays how wordpress function prep_atom_text_construct has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Determines the type of a string of data with the data formatted.
 *
 * 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.
 *
 * @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1
 *
 * @since 2.5.0
 *
 * @param string $data Input string.
 * @return array array(type, value)
 */
function prep_atom_text_construct($data)
{
    if (!str_contains($data, '<') && !str_contains($data, '&')) {
        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 (!str_contains($data, '<')) {
            return array('text', $data);
        } else {
            $data = "<div xmlns='http://www.w3.org/1999/xhtml'>{$data}</div>";
            return array('xhtml', $data);
        }
    }
    if (!str_contains($data, ']]>')) {
        return array('html', "<![CDATA[{$data}]]>");
    } else {
        return array('html', htmlspecialchars($data));
    }
}

WordPress Version: 6.1

/**
 * Determines the type of a string of data with the data formatted.
 *
 * 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.
 *
 * @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1
 *
 * @since 2.5.0
 *
 * @param string $data Input string.
 * @return array array(type, value)
 */
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));
    }
}

WordPress Version: 5.5

/**
 * Determine the type of a string of data with the data formatted.
 *
 * 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.
 *
 * @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1
 *
 * @since 2.5.0
 *
 * @param string $data Input string
 * @return array array(type, value)
 */
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));
    }
}

WordPress Version: 4.7

/**
 * Determine the type of a string of data with the data formatted.
 *
 * 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.
 *
 * @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1
 *
 * @since 2.5.0
 *
 * @param string $data Input string
 * @return array array(type, value)
 */
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);
    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));
    }
}

WordPress Version: 4.3

/**
 * Determine the type of a string of data with the data formatted.
 *
 * 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.
 *
 * @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1
 *
 * @since 2.5.0
 *
 * @param string $data Input string
 * @return array array(type, value)
 */
function prep_atom_text_construct($data)
{
    if (strpos($data, '<') === false && strpos($data, '&') === false) {
        return array('text', $data);
    }
    $parser = xml_parser_create();
    xml_parse($parser, '<div>' . $data . '</div>', true);
    $code = xml_get_error_code($parser);
    xml_parser_free($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));
    }
}

WordPress Version: 3.9

/**
 * Determine the type of a string of data with the data formatted.
 *
 * 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.
 *
 * @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1
 *
 * @since 2.5.0
 *
 * @param string $data Input string
 * @return array array(type, value)
 */
function prep_atom_text_construct($data)
{
    if (strpos($data, '<') === false && strpos($data, '&') === false) {
        return array('text', $data);
    }
    $parser = xml_parser_create();
    xml_parse($parser, '<div>' . $data . '</div>', true);
    $code = xml_get_error_code($parser);
    xml_parser_free($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));
    }
}

WordPress Version: 3.7

/**
 * Determine the type of a string of data with the data formatted.
 *
 * 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.
 *
 * @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1
 *
 * @package WordPress
 * @subpackage Feed
 * @since 2.5
 *
 * @param string $data Input string
 * @return array array(type, value)
 */
function prep_atom_text_construct($data)
{
    if (strpos($data, '<') === false && strpos($data, '&') === false) {
        return array('text', $data);
    }
    $parser = xml_parser_create();
    xml_parse($parser, '<div>' . $data . '</div>', true);
    $code = xml_get_error_code($parser);
    xml_parser_free($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));
    }
}