bb_get_post_edit_link
The BuddyPress bb get post edit link function.
Description
bb_get_post_edit_link( (null) $args = null );
Parameters (1)
- 0. $args — Optional. (null) =>
null
- The args.
Usage
if ( !function_exists( 'bb_get_post_edit_link' ) ) { require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-template.php'; } // The args. $args = null; // NOTICE! Understand what this does before running. $result = bb_get_post_edit_link($args);
Defined (1)
The function is defined in the following location(s).
- /bp-forums/bbpress/bb-includes/functions.bb-template.php
- function bb_get_post_edit_link( $args = null )
- {
- $defaults = array(
- 'post_id' => 0,
- 'before' => '',
- 'after' => '',
- 'text' => __( 'Edit' )
- );
- if ( is_numeric( $args ) ) {
- $args = array( 'post_id' => $args );
- }
- $args = wp_parse_args( $args, $defaults );
- $bb_post = bb_get_post( get_post_id( $args['post_id'] ) );
- if ( bb_current_user_can( 'edit_post', $bb_post->post_id ) ) {
- $uri = bb_get_uri( 'edit.php', array( 'id' => $bb_post->post_id ) );
- // Make sure that the last tag in $before gets a class (if it's there)
- if ( preg_match( '/.*(<[^>]+>)[^<]*/', $args['before'], $_node ) ) {
- if ( preg_match( '/class=(\'|")(.*)\1/U', $_node[1], $_class ) ) {
- $args['before'] = str_replace( $_class[0], 'class=' . $_class[1] . 'before-post-edit-link ' . $_class[2] . $_class[1], $args['before'] );
- } else {
- $args['before'] = preg_replace( '/(.*)<([a-z0-9_-]+)(\s?)([^>]*)>([^<]*)/i', '$1<$2 class="before-post-edit-link"$3$4>$5', $args['before'], 1 );
- }
- }
- $r = $args['before'] . '<a class="post-edit-link" href="' . esc_attr( apply_filters( 'post_edit_uri', $uri, $bb_post->post_id, $args ) ) . '">' . esc_html( $args['text'] ) . '</a>' . $args['after'];
- return apply_filters( 'bb_get_post_edit_link', $r, $bb_post->post_id, $args );
- }
- }