get_sample_permalink_html( int|WP_Post $post, string|null $new_title = null, string|null $new_slug = null ): string
- Since
- 2.5.0
- Source
wp-admin/includes/post.php:1555
Compatibility
- WordPress
- since 2.5.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
$postint|WP_Post- Post ID or post object.
$new_titlestring|nulloptional- New title. Default null.Default:
null $new_slugstring|nulloptional- New slug. Default null.Default:
null
Return value
string- The HTML of the sample permalink slug editor.
Performance profile
How much work a call to get_sample_permalink_html() 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
- Heavy
- Scaling
- Constant
- Instructions
- 9–122
- Plugin surface
- 1 hook
- Called by
- 1
Reaches the database via get_post().
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 192.
Third-party callbacks on 'get_sample_permalink_html' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()called directly - optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()called directly - cacheobject cache
wp_cache_get()one call below get_sample_permalink_html() - serializeserialisation
maybe_unserialize()one call below get_sample_permalink_html()
Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 37 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_sample_permalink_html() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 9 | get_post() |
!$permalink && $view_link === false && get_option() | 57–71 | get_post(), get_sample_permalink(), current_user_can(), __(), get_option(), apply_filters() |
!current_user_can() && !$permalink && $view_link === false && !get_option() | 61–75 | get_post(), get_sample_permalink(), current_user_can(), __(), get_option(), current_user_can(), apply_filters() |
current_user_can() && !$permalink && $view_link === false && get_option() | 70–72 | get_post(), get_sample_permalink(), current_user_can(), get_preview_post_link(), __(), get_option(), apply_filters() |
current_user_can() && !empty($post) && !$permalink && $view_link === false && get_option() | 70–73 | get_post(), get_sample_permalink(), current_user_can(), get_permalink(), __(), get_option(), apply_filters() |
!$permalink && $view_link !== false && get_option() | 72–86 | get_post(), get_sample_permalink(), current_user_can(), __(), urldecode(), esc_url(), esc_html(), get_option(), apply_filters() |
!$permalink && $view_link === false && !get_option() && current_user_can() | 73–87 | get_post(), get_sample_permalink(), current_user_can(), __(), get_option(), current_user_can(), get_option(), __(), apply_filters() |
!$permalink && $view_link === false && !get_option() && current_user_can() | 73–87 | get_post(), get_sample_permalink(), current_user_can(), __(), get_option(), current_user_can(), get_option(), get_option(), apply_filters() |
!$permalink && $view_link === false && !get_option() | 74–76 | get_post(), get_sample_permalink(), current_user_can(), get_preview_post_link(), __(), get_option(), current_user_can(), apply_filters() |
!empty($post) && !$permalink && $view_link === false && !get_option() | 74–77 | get_post(), get_sample_permalink(), current_user_can(), get_permalink(), __(), get_option(), current_user_can(), apply_filters() |
!current_user_can() && !$permalink && $view_link !== false && !get_option() | 76–90 | get_post(), get_sample_permalink(), current_user_can(), __(), urldecode(), esc_url(), esc_html(), get_option(), current_user_can(), apply_filters() |
!$permalink && $view_link === false && !get_option() && current_user_can() | 80–94 | get_post(), get_sample_permalink(), current_user_can(), __(), get_option(), current_user_can(), get_option(), get_option(), __(), apply_filters() |
25 further outcomes, up to 122 instructions
current_user_can() && !$permalink && $view_link !== false && get_option() | 85–87 | get_post(), get_sample_permalink(), current_user_can(), get_preview_post_link(), __(), urldecode(), esc_url(), esc_html(), get_option(), apply_filters() |
current_user_can() && !empty($post) && !$permalink && $view_link !== false && get_option() | 85–88 | get_post(), get_sample_permalink(), current_user_can(), get_permalink(), __(), urldecode(), esc_url(), esc_html(), get_option(), apply_filters() |
current_user_can() && !$permalink && $view_link === false && !get_option() | 86–88 | get_post(), get_sample_permalink(), current_user_can(), get_preview_post_link(), __(), get_option(), current_user_can(), get_option(), __(), apply_filters() |
current_user_can() && !$permalink && $view_link === false && !get_option() | 86–88 | get_post(), get_sample_permalink(), current_user_can(), get_preview_post_link(), __(), get_option(), current_user_can(), get_option(), get_option(), apply_filters() |
current_user_can() && !empty($post) && !$permalink && $view_link === false && !get_option() | 86–89 | get_post(), get_sample_permalink(), current_user_can(), get_permalink(), __(), get_option(), current_user_can(), get_option(), __(), apply_filters() |
current_user_can() && !empty($post) && !$permalink && $view_link === false && !get_option() | 86–89 | get_post(), get_sample_permalink(), current_user_can(), get_permalink(), __(), get_option(), current_user_can(), get_option(), get_option(), apply_filters() |
!$permalink && $view_link !== false && !get_option() && current_user_can() | 88–102 | get_post(), get_sample_permalink(), current_user_can(), __(), urldecode(), esc_url(), esc_html(), get_option(), current_user_can(), get_option(), __(), apply_filters() |
!$permalink && $view_link !== false && !get_option() && current_user_can() | 88–102 | get_post(), get_sample_permalink(), current_user_can(), __(), urldecode(), esc_url(), esc_html(), get_option(), current_user_can(), get_option(), get_option(), apply_filters() |
!$permalink && $view_link !== false && !get_option() | 89–91 | get_post(), get_sample_permalink(), current_user_can(), get_preview_post_link(), __(), urldecode(), esc_url(), esc_html(), get_option(), current_user_can(), apply_filters() |
!empty($post) && !$permalink && $view_link !== false && !get_option() | 89–92 | get_post(), get_sample_permalink(), current_user_can(), get_permalink(), __(), urldecode(), esc_url(), esc_html(), get_option(), current_user_can(), apply_filters() |
current_user_can() && !$permalink && $view_link === false && !get_option() | 93–95 | get_post(), get_sample_permalink(), current_user_can(), get_preview_post_link(), __(), get_option(), current_user_can(), get_option(), get_option(), __(), apply_filters() |
current_user_can() && !empty($post) && !$permalink && $view_link === false && !get_option() | 93–96 | get_post(), get_sample_permalink(), current_user_can(), get_permalink(), __(), get_option(), current_user_can(), get_option(), get_option(), __(), apply_filters() |
$permalink | 93–109 | get_post(), get_sample_permalink(), current_user_can(), mb_strlen(), esc_html(), urldecode(), esc_html(), __(), esc_url(), __(), __(), esc_html(), apply_filters() |
!$permalink && $view_link !== false && !get_option() && current_user_can() | 95–109 | get_post(), get_sample_permalink(), current_user_can(), __(), urldecode(), esc_url(), esc_html(), get_option(), current_user_can(), get_option(), get_option(), __(), apply_filters() |
current_user_can() && !$permalink && $view_link !== false && !get_option() | 101–103 | get_post(), get_sample_permalink(), current_user_can(), get_preview_post_link(), __(), urldecode(), esc_url(), esc_html(), get_option(), current_user_can(), get_option(), __(), apply_filters() |
current_user_can() && !$permalink && $view_link !== false && !get_option() | 101–103 | get_post(), get_sample_permalink(), current_user_can(), get_preview_post_link(), __(), urldecode(), esc_url(), esc_html(), get_option(), current_user_can(), get_option(), get_option(), apply_filters() |
current_user_can() && !empty($post) && !$permalink && $view_link !== false && !get_option() | 101–104 | get_post(), get_sample_permalink(), current_user_can(), get_permalink(), __(), urldecode(), esc_url(), esc_html(), get_option(), current_user_can(), get_option(), __(), apply_filters() |
current_user_can() && !empty($post) && !$permalink && $view_link !== false && !get_option() | 101–104 | get_post(), get_sample_permalink(), current_user_can(), get_permalink(), __(), urldecode(), esc_url(), esc_html(), get_option(), current_user_can(), get_option(), get_option(), apply_filters() |
$permalink | 104–120 | get_post(), get_sample_permalink(), current_user_can(), mb_strlen(), mb_substr(), mb_substr(), esc_html(), urldecode(), esc_html(), __(), esc_url(), __(), __(), esc_html(), apply_filters() |
current_user_can() && $permalink | 106–110 | get_post(), get_sample_permalink(), current_user_can(), get_preview_post_link(), mb_strlen(), esc_html(), urldecode(), esc_html(), __(), esc_url(), __(), __(), esc_html(), apply_filters() |
current_user_can() && !empty($post) && $permalink | 106–111 | get_post(), get_sample_permalink(), current_user_can(), get_permalink(), mb_strlen(), esc_html(), urldecode(), esc_html(), __(), esc_url(), __(), __(), esc_html(), apply_filters() |
current_user_can() && !$permalink && $view_link !== false && !get_option() | 108–110 | get_post(), get_sample_permalink(), current_user_can(), get_preview_post_link(), __(), urldecode(), esc_url(), esc_html(), get_option(), current_user_can(), get_option(), get_option(), __(), apply_filters() |
current_user_can() && !empty($post) && !$permalink && $view_link !== false && !get_option() | 108–111 | get_post(), get_sample_permalink(), current_user_can(), get_permalink(), __(), urldecode(), esc_url(), esc_html(), get_option(), current_user_can(), get_option(), get_option(), __(), apply_filters() |
current_user_can() && $permalink | 117–121 | get_post(), get_sample_permalink(), current_user_can(), get_preview_post_link(), mb_strlen(), mb_substr(), mb_substr(), esc_html(), urldecode(), esc_html(), __(), esc_url(), __(), __(), esc_html(), apply_filters() |
current_user_can() && !empty($post) && $permalink | 117–122 | get_post(), get_sample_permalink(), current_user_can(), get_permalink(), mb_strlen(), mb_substr(), mb_substr(), esc_html(), urldecode(), esc_html(), __(), esc_url(), __(), __(), esc_html(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 192 | 9–122 | 14 | |
| 8.5 | 192 | 9–122 | 14 | |
| 8.4 | 192 | 9–122 | 14 | 14 fewer instructions than PHP 8.3 |
| 8.3 | 206 | 9–134 | 14 | |
| 8.2 | 206 | 9–134 | 14 | 2 fewer instructions than PHP 8.1 |
| 8.1 | 208 | 9–136 | 14 | |
| 7.4 | 208 | 9–136 | 14 |
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.
Hooks and filters fired · 1
One hook fires while get_sample_permalink_html() runs, in this order:
- apply_filters( get_sample_permalink_html )filterline 1627 (+72 into the body)
Filters the sample permalink HTML markup.
Uses · 13
- get_post()Retrieves post data given a post ID or post object.
- get_sample_permalink()Returns a sample permalink based on the post name.
- current_user_can()Returns whether the current user has the specified capability.
- get_preview_post_link()Retrieves the URL used for the post preview.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- __()Retrieves the translation of $text.
- esc_url()Checks and cleans a URL.
- esc_html()Escaping for HTML blocks.
- get_option()Retrieves an option value based on an option name.
- mb_strlen()Compat function to mimic mb_strlen().
- mb_substr()Compat function to mimic mb_substr().
Show all 13
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 1
- wp_ajax_sample_permalink()Handles retrieving a sample permalink via AJAX.
Source code
function get_sample_permalink_html( $post, $new_title = null, $new_slug = null ) { $post = get_post( $post ); if ( ! $post ) { return ''; } list($permalink, $post_name) = get_sample_permalink( $post->ID, $new_title, $new_slug ); $view_link = false; $preview_target = ''; if ( current_user_can( 'read_post', $post->ID ) ) { if ( 'draft' === $post->post_status || empty( $post->post_name ) ) { $view_link = get_preview_post_link( $post ); $preview_target = " target='wp-preview-{$post->ID}'"; } else { if ( 'publish' === $post->post_status || 'attachment' === $post->post_type ) { $view_link = get_permalink( $post ); } else { // Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set. $view_link = str_replace( array( '%pagename%', '%postname%' ), $post->post_name, $permalink ); } } } // Permalinks without a post/page name placeholder don't have anything to edit. if ( ! str_contains( $permalink, '%postname%' ) && ! str_contains( $permalink, '%pagename%' ) ) { $return = '<strong>' . __( 'Permalink:' ) . "</strong>\n"; if ( false !== $view_link ) { $display_link = urldecode( $view_link ); $return .= '<a id="sample-permalink" href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . esc_html( $display_link ) . "</a>\n"; } else { $return .= '<span id="sample-permalink">' . $permalink . "</span>\n"; } // Encourage a pretty permalink setting. if ( ! get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && ! ( 'page' === get_option( 'show_on_front' ) && (int) get_option( 'page_on_front' ) === $post->ID ) ) { $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small">' . __( 'Change Permalink Structure' ) . "</a></span>\n"; } } else { if ( mb_strlen( $post_name ) > 34 ) { $post_name_abridged = mb_substr( $post_name, 0, 16 ) . '…' . mb_substr( $post_name, -16 ); } else { $post_name_abridged = $post_name; } $post_name_html = '<span id="editable-post-name">' . esc_html( $post_name_abridged ) . '</span>'; $display_link = str_replace( array( '%pagename%', '%postname%' ), $post_name_html, esc_html( urldecode( $permalink ) ) ); $return = '<strong>' . __( 'Permalink:' ) . "</strong>\n"; $return .= '<span id="sample-permalink"><a href="' . esc_url( $view_link ) . '"' . $preview_target . '>' . $display_link . "</a></span>\n"; $return .= '‎'; // Fix bi-directional text display defect in RTL languages. $return .= '<span id="edit-slug-buttons"><button type="button" class="edit-slug button button-small hide-if-no-js" aria-label="' . __( 'Edit permalink' ) . '">' . __( 'Edit' ) . "</button></span>\n"; $return .= '<span id="editable-post-name-full">' . esc_html( $post_name ) . "</span>\n"; } /** * Filters the sample permalink HTML markup. * * @since 2.9.0 * @since 4.4.0 Added `$post` parameter. * * @param string $return Sample permalink HTML markup. * @param int $post_id Post ID. * @param string|null $new_title New sample permalink title. * @param string|null $new_slug New sample permalink slug. * @param WP_Post $post Post object. */ $return = apply_filters( 'get_sample_permalink_html', $return, $post->ID, $new_title, $new_slug, $post ); return $return;}Changelog
Introduced in 2.5.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 7.0.4 tag, from
src/wp-admin/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.