get_extended( string $post ): string[]
- Since
- 1.0.0
- Source
wp-includes/post.php:1048
Description
There should not be any space after the second dash and before the word 'more'. There can be text or space(s) after the word 'more', but won't be referenced.
The returned array has 'main', 'extended', and 'more_text' keys. Main has the text before the <!--more-->. The 'extended' key has the content after the <!--more--> comment. The 'more_text' key has the custom "Read More" text.
Compatibility
- WordPress
- since 1.0.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$poststring- Post content.
Return value
string[]- Extended entry info.
$mainstringContent before the more tag.$extendedstringContent after the more tag.$more_textstringCustom read more text, or empty string.
Performance profile
How much work a call to get_extended() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 23–31
- Plugin surface
- None
- Called by
- 3
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 34.
Nothing here hands control to plugin code.
3 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_extended() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!preg_match() | 23 | preg_match() |
preg_match() | 31 | preg_match(), explode() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 34 | 23–31 | 1 | |
| 8.5 | 34 | 23–31 | 1 | |
| 8.4 | 34 | 23–31 | 1 | 9 fewer instructions than PHP 8.3 |
| 8.3 | 43 | 32–40 | 1 | |
| 8.2 | 43 | 32–40 | 1 | |
| 8.1 | 43 | 32–40 | 1 | |
| 7.4 | 43 | 32–40 | 1 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Used by · 3
- wp_xmlrpc_server::_prepare_page()Prepares page data for return in an XML-RPC object.
- wp_xmlrpc_server::mw_getPost()Retrieves a post.
- wp_xmlrpc_server::mw_getRecentPosts()Retrieves list of recent posts.
Source code
function get_extended( $post ) { // Match the new style more links. if ( preg_match( '/<!--more(.*?)?-->/', $post, $matches ) ) { list($main, $extended) = explode( $matches[0], $post, 2 ); $more_text = $matches[1]; } else { $main = $post; $extended = ''; $more_text = ''; } // Leading and trailing whitespace. $main = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $main ); $extended = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $extended ); $more_text = preg_replace( '/^[\s]*(.*)[\s]*$/', '\\1', $more_text ); return array( 'main' => $main, 'extended' => $extended, 'more_text' => $more_text, );}Changelog
Introduced in 1.0.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.