Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created January 19, 2019 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/4db5125401af9143c843debeae27e765 to your computer and use it in GitHub Desktop.
Save billerickson/4db5125401af9143c843debeae27e765 to your computer and use it in GitHub Desktop.
<?php
/**
* Add Delete Link to Display Posts Shortcode plugin
* @see https://displayposts.com/2019/01/19/add-delete-post-link-if-user-has-permission-to-edit-content/
*/
function be_dps_delete_link( $output, $atts, $image, $title, $date, $excerpt, $inner_wrapper, $content, $class, $author, $category_display_text ) {
if( empty( $atts['include_delete'] ) || true !== filter_var( $atts['include_delete'], FILTER_VALIDATE_BOOLEAN ) )
return $output;
if( ! current_user_can( 'edit_post', get_the_ID() ) )
return $output;
$delete_button = ' <a class="delete-post" href="' . get_delete_post_link( get_the_ID() ) . '">Delete</a>';
$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $date . $author . $category_display_text . $excerpt . $content . $delete_button . '</' . $inner_wrapper . '>';
return $output;
}
add_filter( 'display_posts_shortcode_output', 'be_dps_delete_link', 10, 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment