Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created Jan 19, 2019
Embed
What would you like to do?
<?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